Handoff: an app's answer asks the platform to serve only with the token of its own request
Jonas Templestein, 2026-11-27 07:31 UTC · c2dfd6efe9b9f92db46980969c2adb3614dea861 · parent 58f97d7
9 files changed
- M core/boundary-worker/src/stamp.test.ts
- M core/itx/src/caller.ts
- M core/itx/src/context/egress.ts
- M core/itx/src/context/rpc-stubs.ts
- M core/itx/src/request-stamps.test.ts
- M core/itx/src/serve-host.ts
- M core/lib/src/mind-ingress.ts
- M core/lib/src/sdk/auth.test.ts
- M core/lib/src/sdk/auth.ts
M core/boundary-worker/src/stamp.test.ts
@@ -88,7 +88,8 @@ expect(other.forwarded.headers.get("x-itx-principal")).toBeNull(); // no password, and what is no pair, asks nobody asked.length = 0; - for (const pair of ["ada:", "ada"]) expect(await basic(pair)).toMatchObject({ caller: "anonymous" }); + for (const pair of ["ada:", "ada"]) + expect(await basic(pair)).toMatchObject({ caller: "anonymous" }); expect(asked).toEqual([]); }); @@ -219,4 +220,105 @@ }); expect(stamped).toMatchObject({ caller: "non-member" }); expect(stamped.forwarded.headers.get("x-itx-principal")).toBeNull(); +}); + +// WHO REACHES AN APP'S HANDOFF AS A MEMBER (iterate/sdk `auth.mcpRun`, `auth.itx`): the kernel +// serves a run or a session for the member that this stamp names, and for nobody else +// (core/itx/src/serve-host.ts). So these are the ways a member's stamp must NOT come about. +const memberIdentity: TokenIdentity = { ...signedIn, member: true, method: "passkey" }; +const HOST = "https://mcp.example.com"; + +test.for<{ from: string; origin: string | null; caller: string }>([ + { + from: "a page on another host of the same mind", + origin: "https://tasks.example.com", + caller: "anonymous", + }, + { from: "another site's page", origin: "https://evil.example", caller: "anonymous" }, + { from: "the host's own page", origin: HOST, caller: "member" }, + { from: "a client that is no browser", origin: null, caller: "member" }, +])("a member's session cookie on a POST from $from stamps $caller", async ({ origin, caller }) => { + const auth = { whoIs: async () => memberIdentity } as unknown as AuthService; + const stamped = await stampedRequest( + new Request(`${HOST}/mcp`, { + method: "POST", + headers: { cookie: "__Host-iterate-session=t", ...(origin && { origin }) }, + body: "{}", + }), + { auth, route: null, config }, + ); + expect({ + caller: stamped.caller, + principal: stamped.forwarded.headers.has("x-itx-principal"), + person: stamped.forwarded.headers.has("x-itx-person"), + }).toEqual({ caller, principal: caller === "member", person: caller === "member" }); +}); + +test("a bearer is asked for this host's own origin alone: a member's token for another host, or for the mind's own /mcp, stamps nobody here", async () => { + const asked: string[] = []; + // the auth Worker answers a token for the resource it was made for, and for no other + const madeFor: Record<string, string> = { + "for-this-host": HOST, + "for-a-sibling": "https://tasks.example.com", + "for-the-mind": "https://iterate.example.com/mcp", + }; + const auth = { + whoIs: async (token: string, resource: string) => { + asked.push(resource); + return madeFor[token] === resource ? memberIdentity : null; + }, + } as unknown as AuthService; + const callers: Record<string, unknown> = {}; + for (const token of Object.keys(madeFor)) { + const stamped = await stampedRequest( + new Request(`${HOST}/mcp`, { + method: "POST", + headers: { authorization: `Bearer ${token}`, "x-itx-principal": '{"actor":"user_1"}' }, + body: "{}", + }), + { auth, route: null, config }, + ); + callers[token] = [stamped.caller, stamped.forwarded.headers.has("x-itx-principal")]; + } + expect(callers).toEqual({ + "for-this-host": ["member", true], + "for-a-sibling": ["anonymous", false], + "for-the-mind": ["anonymous", false], + }); + expect(new Set(asked)).toEqual(new Set([HOST])); +}); + +test("on the control plane's /mcp a token is asked for the mind's own MCP address: a host's token and a session cookie stamp nobody, and the boundary answers the 401 itself", async () => { + const asked: string[] = []; + const auth = { + whoIs: async (token: string, resource: string) => { + asked.push(resource); + return token === "for-the-mind" ? memberIdentity : null; + }, + } as unknown as AuthService; + const at = (headers: Record<string, string>) => + stampedRequest( + new Request("https://iterate.example.com/mcp", { method: "POST", headers, body: "{}" }), + { auth, route: "mcp", config }, + ); + const host = await at({ authorization: "Bearer for-a-host" }); + const cookie = await at({ cookie: "__Host-iterate-session=t" }); + const mind = await at({ + authorization: "Bearer for-the-mind", + cookie: "__Host-iterate-session=t", + }); + expect( + [host, cookie, mind].map((stamped) => ({ + caller: stamped.caller, + principal: stamped.forwarded.headers.has("x-itx-principal"), + status: stamped.answer?.status, + // the mind gets no cookie and no credential of the control plane's + passedOn: ["cookie", "authorization"].filter((name) => stamped.forwarded.headers.has(name)), + })), + ).toEqual([ + { caller: "anonymous", principal: false, status: 401, passedOn: [] }, + { caller: "anonymous", principal: false, status: 401, passedOn: [] }, + { caller: "member", principal: true, status: undefined, passedOn: [] }, + ]); + expect(new Set(asked)).toEqual(new Set(["https://iterate.example.com/mcp"])); });
M core/itx/src/caller.ts
@@ -58,6 +58,11 @@ // mind Worker's MCP server and by serve-host.ts, where the platform itself names the client and // the person: no other caller reaches `mcpCall` (./context/built-ins.ts `workersRoot`). mcpServer?: true; + // The token of the one request that serve-host.ts hands to the ingress row's target + // (iterate/mind-ingress `ITERATE_SERVE_TOKEN_HEADER`). Set only there. It is written on the + // Request that loaded code gets from this call (./context/rpc-stubs.ts `requestForLoadedCode`) + // and crosses no hop: a call that loaded code makes has a caller of its own, with none. + serveToken?: string; // An internal hop made through `libraryItx` (`repos`, `sandboxes`, `files`) on behalf of an // outer expression: activity tracking records the outer call alone so internal hops do not stack // duplicate pills underneath it.
M core/itx/src/context/egress.ts
@@ -1,4 +1,5 @@ import { ITERATE_CAUSE_HEADER } from "iterate/lib"; +import { ITERATE_SERVE_TOKEN_HEADER } from "iterate/mind-ingress"; import { parseCause, causeHeader, refuseActPastLimit, type Cause } from "../cause.ts"; import { itxHost } from "../host.ts"; import { FETCH_UPGRADE_RESUMABLE_HEADER } from "./fetch-upgrade.ts"; @@ -22,6 +23,8 @@ // what the host says to loaded code is for the mind's own code alone for (const name of Object.keys(itxHost().loadedCodeRequestHeaders?.() || {})) headers.delete(name); + // and so is the token of a handoff: a site that got it could ask for one in its answer + headers.delete(ITERATE_SERVE_TOKEN_HEADER); if (cause) headers.set(ITERATE_CAUSE_HEADER, causeHeader(cause, new URL(request.url).hostname)); headers.delete(FETCH_UPGRADE_RESUMABLE_HEADER); // Chromium drops User-Agent on a Request it builds, and GitHub's API refuses a request without one.
M core/itx/src/context/rpc-stubs.ts
@@ -1,5 +1,6 @@ import { failureKind } from "iterate/platform-retry"; import { codedError, errorCode, ITERATE_CAUSE_HEADER, ITX_OWN_HEADER } from "iterate/lib"; +import { ITERATE_SERVE_TOKEN_HEADER } from "iterate/mind-ingress"; import { ITERATE_STATEMENT_HEADER } from "iterate/signed"; import { ITX_EXPIRES_HEADER, @@ -645,6 +646,9 @@ }); for (const [name, value] of Object.entries(itxHost().loadedCodeRequestHeaders?.() || {})) headers.set(name, value); + // the handoff token is this call's or none: a Request that code sends on carries none + headers.delete(ITERATE_SERVE_TOKEN_HEADER); + if (caller.serveToken) headers.set(ITERATE_SERVE_TOKEN_HEADER, caller.serveToken); return new Request(request, { headers }); }
M core/itx/src/request-stamps.test.ts
@@ -26,6 +26,7 @@ import { SessionTeardown } from "./session.ts"; const CONTROL_PLANE_HOSTNAME = "x-iterate-control-plane-hostname"; +const SERVE_TOKEN = "x-iterate-serve-token"; const OWNER = { userId: "user_owner", email: "owner@example.com", @@ -398,6 +399,73 @@ expect(answer.headers.get("x-iterate-serve")).toBeNull(); }); +// ONLY THE MIND'S OWN CODE ASKS FOR A HANDOFF. An app that returns an answer from elsewhere as it +// is (a site it proxies, a worker it loads) returns that answer's headers too. Such an answer +// holds no token of this request, so the kernel serves nothing in its place, for a member too: +// no run, no session, no MCP server. The headers go on to nobody. +test.for( + ["itx", "person-itx", "mcp-run", "mcp-server"].flatMap((serve) => + ["none", "forged", "earlier"].map((token) => ({ serve, token })), + ), +)( + "an answer that asks for $serve with a token that is $token is no handoff: the member gets the answer as it is", + async ({ serve, token }) => { + const served: string[] = []; + const ask = () => + serveHostRequest({ + ctx, + request: new Request( + `https://mcp.example.org/${serve === "mcp-server" ? "mcp" : "passes-on"}`, + { + method: "POST", + headers: { "x-test-serve": serve, "x-test-token": token }, + body: "{}", + }, + ), + caller: { principal: MEMBER, grant: "grant_owner", person: OWNER }, + itxSessions: true, + mcpRun: async () => (served.push("mcp-run"), new Response("ran")), + mcpServer: async () => (served.push("mcp-server"), new Response("served")), + }); + // twice: the second answer holds the token of the first request + await (await ask()).text(); + const answer = await ask(); + expect({ + status: answer.status, + body: await answer.text(), + served, + headers: [...answer.headers.keys()].filter((name) => name.startsWith("x-iterate-")), + }).toEqual({ status: 200, body: expect.any(String), served: [], headers: [] }); + }, +); + +test("the handoff token is on the Request that the ingress hands over, and on nothing that the app sends on: not out of the stack, and not to another loaded worker", async () => { + egressedTokens.length = 0; + const answer = await serveHostRequest({ + ctx, + request: new Request("https://mcp.example.org/sends-on", { + headers: { [SERVE_TOKEN]: "a caller's own" }, + }), + caller: { principal: MEMBER }, + }); + expect({ ...((await answer.json()) as object), egressedTokens }).toEqual({ + got: expect.stringMatching(/^[0-9a-f-]{36}$/), + nextGot: "", + egressedTokens: [null], + }); +}); + +test("a fetch route's target gets no handoff token, whatever the request carried", async () => { + const answer = await serveHostRequest({ + ctx, + request: new Request("https://routed.example.org/token", { + headers: { [SERVE_TOKEN]: "a caller's own" }, + }), + caller: { principal: MEMBER }, + }); + expect(await answer.text()).toBe(""); +}); + test("a request stamped with another mind reaches a fetch route's target as that mind, with no member", async () => { const request = new Request("https://routed.example.org/post", { headers: mindStamped() }); const answer = await serveHostRequest({ ctx, request, caller: stampedCallerOf(request) }); @@ -517,6 +585,7 @@ loadedCodeRequestHeaders: () => ({ [CONTROL_PLANE_HOSTNAME]: "iterate.example.com" }), egress: async (request: Request) => { egressed.push(request.headers.get(ITERATE_CAUSE_HEADER)); + egressedTokens.push(request.headers.get(SERVE_TOKEN)); return new Response("out"); }, loader: { @@ -724,22 +793,84 @@ if (hostname === "own.example.org") return new Response("narrow: not an allowed host", { status: 403 }); if (pathname === "/act") return actOutbound(request); + // what iterate/sdk `auth` answers: what is asked, beside the token of this request + const token = request.headers.get(SERVE_TOKEN) || ""; + if (pathname === "/token") return new Response(token); + if (request.headers.has("x-test-serve")) return passedOn(request, token); + if (pathname === "/sends-on") return sendsOn(request); if (pathname === "/asks-itx") - return new Response(null, { headers: { "x-iterate-serve": "itx" } }); + return new Response(null, { headers: { "x-iterate-serve": "itx", [SERVE_TOKEN]: token } }); if (pathname === "/asks-mcp-run") { const asked = request.headers.get("x-test-message"); // a stream with no length and no end; and the request's own body, sent back as it came const message = asked === "endless" ? endlessMessage() : asked === "long" ? request.body : asked; - return new Response(message || runMessage(), { headers: { "x-iterate-serve": "mcp-run" } }); + return new Response(message || runMessage(), { + headers: { "x-iterate-serve": "mcp-run", [SERVE_TOKEN]: token }, + }); } if (pathname === "/asks-person-itx") return new Response(null, { - headers: { "x-iterate-serve": "person-itx", "x-iterate-serve-context": "/" }, + headers: { + "x-iterate-serve": "person-itx", + "x-iterate-serve-context": "/", + [SERVE_TOKEN]: token, + }, }); return Response.json( Object.fromEntries(Object.keys(FORGED).map((name) => [name, request.headers.get(name)])), ); +} + +/** The token of the last request that the app at `/passes-on` got. */ +let earlierToken = ""; + +/** AN APP THAT PASSES ON AN ANSWER IT GOT FROM ELSEWHERE, as it is: a run's message under the + * headers that ask for the handoff `x-test-serve` names, with the token that `x-test-token` + * names. None of them is this request's: the app's code never asked. */ +function passedOn(request: Request, token: string) { + const serve = request.headers.get("x-test-serve") || ""; + const sent = { none: null, forged: crypto.randomUUID(), earlier: earlierToken }[ + request.headers.get("x-test-token") || "none" + ]; + earlierToken = token; + return new Response(serve === "mcp-server" ? JSON.stringify({ target: "mcp" }) : runMessage(), { + headers: { + "x-iterate-serve": serve, + "x-iterate-serve-context": "/", + ...(sent && { [SERVE_TOKEN]: sent }), + }, + }); +} + +/** The handoff token on each Request that the host's egress got here. */ +const egressedTokens: (string | null)[] = []; + +/** An app that sends its own Request on, headers and all: out of the stack, and to another + * loaded worker, whose answer is the token it got. */ +async function sendsOn(request: Request) { + const resolver = statelessResolverFor({ + namespace, + address: DurableObjectNameCodec.address("/"), + caller: { principal: null, app: true }, + ctx, + }); + await statelessExpressionFetch( + resolver, + () => parseFetchExpression("itx.fetch"), + new Request("https://out.example/", { headers: request.headers }), + "itx.fetch", + ); + const next = await resolver.invoke([ + "itx", + "workers", + ["get", SPEC], + ["fetch", new Request("https://guestbook.example.org/token", { headers: request.headers })], + ]); + return Response.json({ + got: request.headers.get(SERVE_TOKEN), + nextGot: await (next as Response).text(), + }); } async function stampsOf(answer: unknown) {
M core/itx/src/serve-host.ts
@@ -5,6 +5,7 @@ ITERATE_SERVE_ADMITS_HEADER, ITERATE_SERVE_CONTEXT_HEADER, ITERATE_SERVE_HEADER, + ITERATE_SERVE_TOKEN_HEADER, } from "iterate/mind-ingress"; import type { Caller } from "./caller.ts"; import { @@ -134,7 +135,14 @@ : undefined; // The ingress row's target is run as the person who asks, and as a row's run // (`Caller.runsRow`): a member's request writes no row that loaded code could not write. - const answer = await resolverUnder({ ...caller, runsRow: true }).invoke(ingress, request); + // ONLY THIS REQUEST'S OWN ANSWER MAY ASK FOR A HANDOFF. The token is on the Request that the + // ingress row's target gets, and on nothing that code sends on; an answer asks (`asks`) only + // with it. So an answer that the config worker passes on from elsewhere asks for nothing. + const serveToken = crypto.randomUUID(); + const answer = await resolverUnder({ ...caller, runsRow: true, serveToken }).invoke( + ingress, + request, + ); if ( unserved && answer instanceof Response && @@ -145,12 +153,11 @@ } if (!(answer instanceof Response)) return new Response(`expression fetch: ${JSON.stringify(answer)}\n`); - const mcpServer = - args.mcpServer && - forMcpServer && - answer instanceof Response && - answer.headers.get(ITERATE_SERVE_HEADER) === "mcp-server" && - args.mcpServer; + const asks = + answer.headers.get(ITERATE_SERVE_TOKEN_HEADER) === serveToken + ? answer.headers.get(ITERATE_SERVE_HEADER) + : null; + const mcpServer = args.mcpServer && forMcpServer && asks === "mcp-server" && args.mcpServer; // Never awaited: the copy is one branch of a tee, and its cancellation settles only when the // other branch, which the config's `fetch` got, is cancelled or ends. An answer must not // wait for a sender's upload. @@ -175,9 +182,9 @@ ] as never), ); } - if (args.mcpRun && answer.headers.get(ITERATE_SERVE_HEADER) === "mcp-run") + if (args.mcpRun && asks === "mcp-run") return await mcpRunAnswer({ ...args, mcpRun: args.mcpRun }, answer); - const serve = args.itxSessions && answer.headers.get(ITERATE_SERVE_HEADER); + const serve = args.itxSessions && asks; if (serve === "itx") { await answer.body?.cancel(); return await itxSession(args); @@ -223,20 +230,20 @@ }); export type MCPServerAsked = z.infer<typeof MCPServerAsked>; +const SERVE_HEADERS = [ + ITERATE_SERVE_HEADER, + ITERATE_SERVE_TOKEN_HEADER, + ITERATE_SERVE_CONTEXT_HEADER, + ITERATE_SERVE_ADMITS_HEADER, +]; + // The headers are the platform's to act on: no answer that goes on to a browser keeps them. const withoutServeHeader = (next: (answer: Response) => Response) => (answer: Response): Response => { - if ( - !answer.headers.has(ITERATE_SERVE_HEADER) && - !answer.headers.has(ITERATE_SERVE_CONTEXT_HEADER) && - !answer.headers.has(ITERATE_SERVE_ADMITS_HEADER) - ) - return next(answer); + if (!SERVE_HEADERS.some((name) => answer.headers.has(name))) return next(answer); const headers = new Headers(answer.headers); - headers.delete(ITERATE_SERVE_HEADER); - headers.delete(ITERATE_SERVE_CONTEXT_HEADER); - headers.delete(ITERATE_SERVE_ADMITS_HEADER); + for (const name of SERVE_HEADERS) headers.delete(name); return next( new Response(answer.body, { status: answer.status,
M core/lib/src/mind-ingress.ts
@@ -19,8 +19,20 @@ * whole MCP server, whose class the answer's body names (iterate/sdk `auth.mcpServer`). An answer, never a call: the platform serves it for the * caller the boundary stamped on the request it still holds, so the config worker names no * caller. The platform drops both headers from every answer it does not honour, so they never - * reach a browser. */ + * reach a browser. + * + * ONLY THE MIND'S OWN CODE CAN ASK. The platform acts on this header only beside + * `ITERATE_SERVE_TOKEN_HEADER` with the token of this one request. So an answer that the config + * worker got from somewhere else and returns as it is (a site it proxies) asks for nothing, + * whatever headers it holds. Ask through iterate/sdk `auth`, which echoes the token. */ export const ITERATE_SERVE_HEADER = "x-iterate-serve"; + +/** THE TOKEN OF ONE HANDOFF: random for each request, on the Request that the platform hands to + * the code its ingress names, and on no other. The kernel sets it from the call's own state, + * over whatever a Request carried, and takes it off every Request that code sends on: out of + * the stack, to a sandbox's port, or to other loaded code. An answer asks the platform to serve + * in its place (`ITERATE_SERVE_HEADER`) only when it holds the same token in this header. */ +export const ITERATE_SERVE_TOKEN_HEADER = "x-iterate-serve-token"; /** The context path a `person-itx` answer names: the one context the person's socket reaches. */ export const ITERATE_SERVE_CONTEXT_HEADER = "x-iterate-serve-context";
M core/lib/src/sdk/auth.test.ts
@@ -299,17 +299,66 @@ params: { name: "run" as const, arguments: { script: "async (itx) => itx.whoami()" } }, }; const member = { "x-itx-principal": JSON.stringify({ actor: "user_1", email: "a@example.com" }) }; - const handed = auth.mcpRun(workerRequest("POST", member), message); + const handed = auth.mcpRun( + workerRequest("POST", { ...member, "x-iterate-serve-token": "token-1" }), + message, + ); expect({ status: handed.status, serve: handed.headers.get("x-iterate-serve"), + token: handed.headers.get("x-iterate-serve-token"), body: await handed.json(), - }).toEqual({ status: 200, serve: "mcp-run", body: message }); - for (const headers of [{}, byMind, { ...member, origin: "https://evil.example" }]) { - const refused = auth.mcpRun(workerRequest("POST", headers), message); + }).toEqual({ status: 200, serve: "mcp-run", token: "token-1", body: message }); + // nobody, another mind, another site's page, and a page on another host of the same mind + // (same-site, so the browser sends the session cookie) + for (const headers of [ + {}, + byMind, + { ...member, origin: "https://evil.example" }, + { ...member, origin: `https://sibling.${new URL(workerRequest("POST", {}).url).hostname}` }, + ]) { + const refused = auth.mcpRun( + workerRequest("POST", { ...headers, "x-iterate-serve-token": "token-1" }), + message, + ); expect(refused.headers.get("x-iterate-serve")).toBeNull(); + expect(refused.headers.get("x-iterate-serve-token")).toBeNull(); expect(refused.status).toBeGreaterThanOrEqual(401); } +}); + +test("each answer that asks the platform to serve echoes the token of its request, and none where the request has none", () => { + const member = { + "x-itx-principal": JSON.stringify({ actor: "user_1", email: "a@example.com" }), + "x-itx-person": JSON.stringify({ + userId: "user_1", + email: "a@example.com", + name: "a", + method: "passkey", + }), + }; + const answers = (token: Record<string, string>) => { + const request = (path: string, method = "GET") => + new Request(`https://app.example.org${path}`, { method, headers: { ...member, ...token } }); + return [ + auth.itx(request("/itx")), + auth.personItx(request("/socket"), "/agents/a"), + auth.mcpServer(request("/mcp", "POST"), { target: "mcp" })!, + ].map((answer) => [ + answer.headers.get("x-iterate-serve"), + answer.headers.get("x-iterate-serve-token"), + ]); + }; + expect(answers({ "x-iterate-serve-token": "token-1" })).toEqual([ + ["itx", "token-1"], + ["person-itx", "token-1"], + ["mcp-server", "token-1"], + ]); + expect(answers({})).toEqual([ + ["itx", null], + ["person-itx", null], + ["mcp-server", null], + ]); }); test("a mind asking for the member's itx gets the refusal, not the socket", () => {
M core/lib/src/sdk/auth.ts
@@ -17,6 +17,7 @@ ITERATE_SERVE_ADMITS_HEADER, ITERATE_SERVE_CONTEXT_HEADER, ITERATE_SERVE_HEADER, + ITERATE_SERVE_TOKEN_HEADER, } from "../mind-ingress.ts"; /** GUARDS FOR A MIND'S CONFIG WORKER, before it serves a page. Every hostname of the mind's @@ -103,6 +104,14 @@ * session cookie is `SameSite=Lax`: every hostname of the domain is same-site with every other, so * a page on another of the mind's hosts could otherwise open a socket to this app with the * visitor's cookie. */ +/** The headers of an answer that asks the platform to serve in its place: what is asked, and the + * token of the request that the platform handed over, which shows that this code asks + * (iterate/mind-ingress `ITERATE_SERVE_TOKEN_HEADER`). */ +function asks(request: Request, serve: string): Record<string, string> { + const token = request.headers.get(ITERATE_SERVE_TOKEN_HEADER); + return { [ITERATE_SERVE_HEADER]: serve, ...(token && { [ITERATE_SERVE_TOKEN_HEADER]: token }) }; +} + export const auth = { require(request: Request): Response | null { const refused = crossSiteRefusal(request); @@ -161,7 +170,7 @@ auth.require(request) || new Response("Open this path as a WebSocket: it is the page's itx.\n", { status: 426, - headers: { upgrade: "websocket", [ITERATE_SERVE_HEADER]: "itx" }, + headers: { upgrade: "websocket", ...asks(request, "itx") }, }) ); }, @@ -185,10 +194,7 @@ * _meta: call.params._meta } }); * ``` */ mcpRun(request: Request, message: McpRunMessage): Response { - return ( - auth.require(request) || - Response.json(message, { headers: { [ITERATE_SERVE_HEADER]: "mcp-run" } }) - ); + return auth.require(request) || Response.json(message, { headers: asks(request, "mcp-run") }); }, /** A SIGNED-IN PERSON'S LIVE VIEW OF ONE CONTEXT, for the page they are on: answer this from * the path the page opens its WebSocket on (a capnweb session). It answers the person guard's @@ -247,7 +253,7 @@ pathname !== "/.well-known/oauth-protected-resource/mcp" ) return null; - return Response.json(server, { headers: { [ITERATE_SERVE_HEADER]: "mcp-server" } }); + return Response.json(server, { headers: asks(request, "mcp-server") }); }, personItx( request: Request, @@ -260,7 +266,7 @@ status: 426, headers: { upgrade: "websocket", - [ITERATE_SERVE_HEADER]: "person-itx", + ...asks(request, "person-itx"), [ITERATE_SERVE_CONTEXT_HEADER]: path, ...(options.admits && { [ITERATE_SERVE_ADMITS_HEADER]: options.admits }), },