@benchme/site-kit 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import "@fastify/cookie";
2
2
  import { AuthError } from "./auth-service.js";
3
- import { authPages, shell } from "./html.js";
3
+ import { apiTokenOpens, authPages, shell } from "./html.js";
4
4
  const form = (req) => (req.body ?? {});
5
5
  const q = (req) => (req.query ?? {});
6
6
  /** Reads the session cookie into a user, or null. */
@@ -84,12 +84,15 @@ export function registerAuthRoutes(app, d) {
84
84
  if (!c || !c.user)
85
85
  return;
86
86
  const full = await d.auth.userForSession(req.workspaceId, req.cookies[d.cookie]);
87
- return html(reply, shell(c, "Account", authPages.account(req.prefix, { email: c.user.email, displayName: c.user.displayName, apiToken: full?.apiToken ?? null })));
87
+ return html(reply, shell(c, "Account", authPages.account(req.prefix, { email: c.user.email, displayName: c.user.displayName, apiToken: full?.apiToken ?? null }, req.doors)));
88
88
  });
89
89
  app.post("/account/token", async (req, reply) => {
90
90
  const c = await guard(req, reply);
91
91
  if (!c || !c.user)
92
92
  return;
93
+ // A token opens the REST API and the MCP server: where the workspace is served through neither, there is none to have.
94
+ if (!apiTokenOpens(req.doors))
95
+ return reply.code(404).type("text/html; charset=utf-8").send(shell(c, "Not found", "<h1>No such page</h1>"));
93
96
  await d.auth.issueApiToken(req.workspaceId, c.user.email);
94
97
  return reply.redirect(`${req.prefix}/account`, 303);
95
98
  });
@@ -1 +1 @@
1
- {"version":3,"file":"auth-routes.js","sourceRoot":"","sources":["../src/auth-routes.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AAEzB,OAAO,EAAE,SAAS,EAAoB,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAiB,MAAM,WAAW,CAAC;AAa5D,MAAM,IAAI,GAAG,CAAC,GAAmB,EAAK,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,IA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C,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1D,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,MAAM,UAAU,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The cookie a page's WebMCP bridge proves itself with. One name for every
3
+ * site: each site sets it on its own path, so a browser sends each site only
4
+ * its own.
5
+ */
6
+ export declare const BRIDGE_COOKIE = "benchme_bridge";
7
+ /** The header the bridge sends its token in, on every tool call it makes. */
8
+ export declare const BRIDGE_TOKEN_HEADER = "x-benchme-bridge";
9
+ /** The token a page embeds for the bridge cookie `cookie`: an HMAC with the gateway secret over the workspace and the cookie. */
10
+ export declare function bridgeToken(secret: string, workspaceId: string, cookie: string): string;
11
+ /**
12
+ * One request's bridge credential: the bridge cookie it carries, and the
13
+ * token a page embeds for that cookie.
14
+ *
15
+ * A page the site renders with the WebMCP door open embeds a token for the
16
+ * browser's bridge cookie (minting the cookie when the request carried none,
17
+ * so that several tabs share one), and the page's bridge sends that token back
18
+ * on every call to /mcp. A call is the page's bridge only when its token is
19
+ * the one for the cookie the same request carries. The cookie is HttpOnly, so
20
+ * neither a page's scripts nor whoever reads the page's HTML can read it:
21
+ * a token copied out of a page, or a header copied from the bridge, proves
22
+ * nothing without the cookie jar the page was served to.
23
+ */
24
+ export declare class BridgeCredential {
25
+ private readonly secret;
26
+ private readonly workspaceId;
27
+ private readonly carried;
28
+ private minted;
29
+ private constructor();
30
+ /** The credential of a request for `workspaceId`, read from its Cookie header. */
31
+ static of(secret: string, workspaceId: string, cookieHeader: string | undefined): BridgeCredential;
32
+ /** Whether `token` is the one a page embedded for the bridge cookie this request carries (compared in constant time). */
33
+ proves(token: string | undefined): boolean;
34
+ /** The token for a page rendered on this request: the carried cookie's, or that of a cookie minted for it (once per request). */
35
+ issue(): string;
36
+ /** The cookie this request minted, for its response to set; undefined when it carried one (or rendered no bridge). */
37
+ get mintedCookie(): string | undefined;
38
+ }
39
+ /**
40
+ * The Set-Cookie for a minted bridge cookie: the site's own pages only
41
+ * (`path`, the site's prefix and a slash), never readable by a page's scripts,
42
+ * never sent with a request another site starts. A session cookie: it lasts as
43
+ * long as the browser does.
44
+ */
45
+ export declare function bridgeSetCookie(value: string, path: string): string;
46
+ /** The value of cookie `name` in a Cookie header (the first, as a browser lists the most specific path first), or undefined. */
47
+ export declare function cookieValue(header: string | undefined, name: string): string | undefined;
@@ -0,0 +1,80 @@
1
+ import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
2
+ /**
3
+ * The cookie a page's WebMCP bridge proves itself with. One name for every
4
+ * site: each site sets it on its own path, so a browser sends each site only
5
+ * its own.
6
+ */
7
+ export const BRIDGE_COOKIE = "benchme_bridge";
8
+ /** The header the bridge sends its token in, on every tool call it makes. */
9
+ export const BRIDGE_TOKEN_HEADER = "x-benchme-bridge";
10
+ /** What a bridge cookie looks like as a site mints one: 128 random bits in hex. Anything else a request carries under the name is not one. */
11
+ const COOKIE_VALUE = /^[0-9a-f]{32}$/;
12
+ /** The token a page embeds for the bridge cookie `cookie`: an HMAC with the gateway secret over the workspace and the cookie. */
13
+ export function bridgeToken(secret, workspaceId, cookie) {
14
+ return createHmac("sha256", secret).update(`bridge:${workspaceId}:${cookie}`).digest("hex");
15
+ }
16
+ /**
17
+ * One request's bridge credential: the bridge cookie it carries, and the
18
+ * token a page embeds for that cookie.
19
+ *
20
+ * A page the site renders with the WebMCP door open embeds a token for the
21
+ * browser's bridge cookie (minting the cookie when the request carried none,
22
+ * so that several tabs share one), and the page's bridge sends that token back
23
+ * on every call to /mcp. A call is the page's bridge only when its token is
24
+ * the one for the cookie the same request carries. The cookie is HttpOnly, so
25
+ * neither a page's scripts nor whoever reads the page's HTML can read it:
26
+ * a token copied out of a page, or a header copied from the bridge, proves
27
+ * nothing without the cookie jar the page was served to.
28
+ */
29
+ export class BridgeCredential {
30
+ secret;
31
+ workspaceId;
32
+ carried;
33
+ minted;
34
+ constructor(secret, workspaceId, carried) {
35
+ this.secret = secret;
36
+ this.workspaceId = workspaceId;
37
+ this.carried = carried;
38
+ }
39
+ /** The credential of a request for `workspaceId`, read from its Cookie header. */
40
+ static of(secret, workspaceId, cookieHeader) {
41
+ const value = cookieValue(cookieHeader, BRIDGE_COOKIE);
42
+ return new BridgeCredential(secret, workspaceId, value !== undefined && COOKIE_VALUE.test(value) ? value : undefined);
43
+ }
44
+ /** Whether `token` is the one a page embedded for the bridge cookie this request carries (compared in constant time). */
45
+ proves(token) {
46
+ if (this.carried === undefined || !token)
47
+ return false;
48
+ const expected = Buffer.from(bridgeToken(this.secret, this.workspaceId, this.carried));
49
+ const given = Buffer.from(token);
50
+ return expected.length === given.length && timingSafeEqual(expected, given);
51
+ }
52
+ /** The token for a page rendered on this request: the carried cookie's, or that of a cookie minted for it (once per request). */
53
+ issue() {
54
+ const cookie = this.carried ?? (this.minted ??= randomBytes(16).toString("hex"));
55
+ return bridgeToken(this.secret, this.workspaceId, cookie);
56
+ }
57
+ /** The cookie this request minted, for its response to set; undefined when it carried one (or rendered no bridge). */
58
+ get mintedCookie() {
59
+ return this.minted;
60
+ }
61
+ }
62
+ /**
63
+ * The Set-Cookie for a minted bridge cookie: the site's own pages only
64
+ * (`path`, the site's prefix and a slash), never readable by a page's scripts,
65
+ * never sent with a request another site starts. A session cookie: it lasts as
66
+ * long as the browser does.
67
+ */
68
+ export function bridgeSetCookie(value, path) {
69
+ return `${BRIDGE_COOKIE}=${value}; Path=${path}; HttpOnly; SameSite=Strict`;
70
+ }
71
+ /** The value of cookie `name` in a Cookie header (the first, as a browser lists the most specific path first), or undefined. */
72
+ export function cookieValue(header, name) {
73
+ for (const pair of (header ?? "").split(";")) {
74
+ const at = pair.indexOf("=");
75
+ if (at > 0 && pair.slice(0, at).trim() === name)
76
+ return pair.slice(at + 1).trim();
77
+ }
78
+ return undefined;
79
+ }
80
+ //# sourceMappingUR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,IAAI;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACpF,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -1,23 +1,12 @@
1
+ import { type Door } from "@benchme/core";
2
+ export { DOORS, DoorSet, type Door } from "@benchme/core";
1
3
  /**
2
- * The ways into a site. A request an agent can make comes through exactly one
3
- * of them, and the change ledger names it on every entry.
4
+ * The door a request came through: what its path leads to (`doorsAt`), and,
5
+ * at the MCP server, which of its two doors. A call that proves it is a
6
+ * page's WebMCP bridge (`viaBridge`: its token is the one for the bridge
7
+ * cookie it carries) is `webmcp`; any other call to /mcp is a direct MCP
8
+ * client's. Nothing a client can write into a request without the page's
9
+ * cookie says otherwise. The paths that are no door at all (the gateway's own
10
+ * /internal/, the probes) have none.
4
11
  */
5
- export declare const DOORS: readonly ["page", "rest", "mcp", "webmcp"];
6
- export type Door = (typeof DOORS)[number];
7
- /**
8
- * Sent by the page's WebMCP bridge on every tool call it makes. A call to
9
- * /mcp that carries it came through a tool the page registered (`webmcp`); any
10
- * other call to /mcp is a direct MCP client (`mcp`). It is a label, never a
11
- * credential: both doors ask the same of a caller.
12
- */
13
- export declare const DOOR_HEADER = "x-benchme-door";
14
- export declare const WEBMCP_DOOR_VALUE = "webmcp";
15
- type Headers = Record<string, string | string[] | undefined>;
16
- /**
17
- * The door a request came through, read off the path as the app routes it and
18
- * the bridge's header: /mcp is the MCP server (the page's bridge or a client),
19
- * /api/ is REST, and anything else an agent can open is a page. The paths that
20
- * are no door at all (the gateway's own /internal/, the probes) have none.
21
- */
22
- export declare function doorOf(url: string, headers?: Headers): Door | null;
23
- export {};
12
+ export declare function doorOf(path: string, viaBridge?: boolean): Door | null;
@@ -1,30 +1,18 @@
1
+ import { doorsAt } from "@benchme/core";
2
+ export { DOORS, DoorSet } from "@benchme/core";
1
3
  /**
2
- * The ways into a site. A request an agent can make comes through exactly one
3
- * of them, and the change ledger names it on every entry.
4
+ * The door a request came through: what its path leads to (`doorsAt`), and,
5
+ * at the MCP server, which of its two doors. A call that proves it is a
6
+ * page's WebMCP bridge (`viaBridge`: its token is the one for the bridge
7
+ * cookie it carries) is `webmcp`; any other call to /mcp is a direct MCP
8
+ * client's. Nothing a client can write into a request without the page's
9
+ * cookie says otherwise. The paths that are no door at all (the gateway's own
10
+ * /internal/, the probes) have none.
4
11
  */
5
- export const DOORS = ["page", "rest", "mcp", "webmcp"];
6
- /**
7
- * Sent by the page's WebMCP bridge on every tool call it makes. A call to
8
- * /mcp that carries it came through a tool the page registered (`webmcp`); any
9
- * other call to /mcp is a direct MCP client (`mcp`). It is a label, never a
10
- * credential: both doors ask the same of a caller.
11
- */
12
- export const DOOR_HEADER = "x-benchme-door";
13
- export const WEBMCP_DOOR_VALUE = "webmcp";
14
- /**
15
- * The door a request came through, read off the path as the app routes it and
16
- * the bridge's header: /mcp is the MCP server (the page's bridge or a client),
17
- * /api/ is REST, and anything else an agent can open is a page. The paths that
18
- * are no door at all (the gateway's own /internal/, the probes) have none.
19
- */
20
- export function doorOf(url, headers = {}) {
21
- const path = url.split("?")[0] ?? "";
22
- if (path === "/healthz" || path === "/readyz" || path.startsWith("/internal/"))
23
- return null;
24
- if (path === "/mcp") {
25
- const marker = headers[DOOR_HEADER];
26
- return (Array.isArray(marker) ? marker[0] : marker) === WEBMCP_DOOR_VALUE ? "webmcp" : "mcp";
27
- }
28
- return path.startsWith("/api/") ? "rest" : "page";
12
+ export function doorOf(path, viaBridge = false) {
13
+ const doors = doorsAt(path);
14
+ if (viaBridge && doors.includes("webmcp"))
15
+ return "webmcp";
16
+ return doors.find((door) => door !== "webmcp") ?? null;
29
17
  }
30
18
  //# sourceMappingURL=door.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"door.js","sourceRoot":"","sources":["../../src/doors/door.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,M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C,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC3D,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,CAAC;AACzD,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import "@fastify/cookie";
2
- import { type Transactions } from "@benchme/core";
2
+ import type { Transactions } from "@benchme/core";
3
3
  import type { FastifyInstance } from "fastify";
4
4
  import type { AuthService } from "../auth-service.js";
5
5
  import type { Ledger } from "../ledger/ledger.js";
@@ -1,11 +1,10 @@
1
1
  import "@fastify/cookie";
2
- import { VERIFIER_SIG_HEADER, verifyVerifierHeader } from "@benchme/core";
3
2
  import { AUTH_LEDGER } from "../ledger/auth-rules.js";
4
3
  import { registerLedgerRoute } from "../ledger/ledger-route.js";
5
4
  import { ledgered } from "../ledger/ledgered.js";
6
- import { header } from "../workspace-scope.js";
5
+ import { header } from "../request-header.js";
7
6
  import { CallerScope, once } from "./caller.js";
8
- import { doorOf } from "./door.js";
7
+ import { isObserver } from "./request-door.js";
9
8
  import { CookieCarrier, McpSessionCarrier, NoCarrier, isMcpSessionId } from "./session-carrier.js";
10
9
  import { registerSignInTools } from "./sign-in-tools.js";
11
10
  import { SignInRequired } from "./sign-in.js";
@@ -24,9 +23,10 @@ export function registerDoors(app, d) {
24
23
  const { ledger } = d;
25
24
  const units = { ledger, callers, transactions: d.transactions };
26
25
  const auth = ledgered(d.auth, AUTH_LEDGER, units);
27
- // A callback hook on purpose: the rest of the request runs inside `done`, so inside the scope.
26
+ // A callback hook on purpose: the rest of the request runs inside `done`, so inside the scope. The door is the one the
27
+ // workspace scope read off the request (its route, and at /mcp the page's bridge credential).
28
28
  app.addHook("preHandler", (req, reply, done) => {
29
- const door = doorOf(req.url, req.headers);
29
+ const door = req.door;
30
30
  if (!door)
31
31
  return done();
32
32
  callers.run(callerOf(app, req, reply, door, d), done);
@@ -64,7 +64,7 @@ function callerOf(app, req, reply, door, d) {
64
64
  const session = carrierOf(app, req, reply, door, d.cookie);
65
65
  return {
66
66
  door,
67
- observer: verifyVerifierHeader(d.gatewaySecret, ws, header(req, VERIFIER_SIG_HEADER) ?? ""),
67
+ observer: isObserver(req, d.gatewaySecret),
68
68
  session,
69
69
  actor: once(async () => {
70
70
  const user = (await d.auth.userForApiToken(ws, bearer || undefined)) ?? (await d.auth.userForSession(ws, req.cookies[d.cookie])) ?? (await d.auth.userForSession(ws, session.token));
@@ -1 +1 @@
1
- {"version":3,"file":"register-doors.js","sourceRoot":"","sources":["../../src/doors/register-doors.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAqB,MAAM,eAAe,CAAC;AAG7F,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,IAAI,EAAe,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAa,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,SAAS,EAAE,cAAc,EAAuB,MAAM,sBAAsB,CAAC;AACxH,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AA2BnD;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,GAAoB,EAAE,CAAY;IAC9D,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACrB,MAAM,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AAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC/D,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,GAAG,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,MAAM,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IACpJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { type Door } from "@benchme/core";
2
+ import type { FastifyRequest } from "fastify";
3
+ import { type BridgeCredential } from "./bridge-credential.js";
4
+ /**
5
+ * The path a request was routed by: its route's own pattern, so an escape
6
+ * (`/%61pi/v1/…`, which the router decodes to the REST route) cannot pass the
7
+ * REST API off as a page; the URL's path where no route matched.
8
+ */
9
+ export declare function routedPath(req: FastifyRequest): string;
10
+ /** The door `req` came through: its route, and at /mcp whether it proves it is a page's bridge. */
11
+ export declare function requestDoor(req: FastifyRequest, bridge: BridgeCredential): Door | null;
12
+ /** The verifier reading state after the fact: its own signature, made with the gateway secret, for this workspace. */
13
+ export declare function isObserver(req: FastifyRequest, gatewaySecret: string): boolean;
14
+ /**
15
+ * Whether `req` came through a door its workspace is not served through. The
16
+ * verifier's own reads are no visitor's, so no door is closed to them: only a
17
+ * holder of the gateway secret can sign one, and the gateway itself never does.
18
+ */
19
+ export declare function isClosed(req: FastifyRequest, gatewaySecret: string): boolean;
@@ -0,0 +1,29 @@
1
+ import { VERIFIER_SIG_HEADER, verifyVerifierHeader } from "@benchme/core";
2
+ import { header } from "../request-header.js";
3
+ import { BRIDGE_TOKEN_HEADER } from "./bridge-credential.js";
4
+ import { doorOf } from "./door.js";
5
+ /**
6
+ * The path a request was routed by: its route's own pattern, so an escape
7
+ * (`/%61pi/v1/…`, which the router decodes to the REST route) cannot pass the
8
+ * REST API off as a page; the URL's path where no route matched.
9
+ */
10
+ export function routedPath(req) {
11
+ return req.routeOptions.url ?? req.url.split("?")[0] ?? "";
12
+ }
13
+ /** The door `req` came through: its route, and at /mcp whether it proves it is a page's bridge. */
14
+ export function requestDoor(req, bridge) {
15
+ return doorOf(routedPath(req), bridge.proves(header(req, BRIDGE_TOKEN_HEADER)));
16
+ }
17
+ /** The verifier reading state after the fact: its own signature, made with the gateway secret, for this workspace. */
18
+ export function isObserver(req, gatewaySecret) {
19
+ return verifyVerifierHeader(gatewaySecret, req.workspaceId, header(req, VERIFIER_SIG_HEADER) ?? "");
20
+ }
21
+ /**
22
+ * Whether `req` came through a door its workspace is not served through. The
23
+ * verifier's own reads are no visitor's, so no door is closed to them: only a
24
+ * holder of the gateway secret can sign one, and the gateway itself never does.
25
+ */
26
+ export function isClosed(req, gatewaySecret) {
27
+ return req.door !== null && !req.doors.has(req.door) && !isObserver(req, gatewaySecret);
28
+ }
29
+ //# sourceMappingURL=request-door.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-door.js","sourceRoot":"","sources":["../../src/doors/request-door.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAa,MAAM,eAAe,CAAC;AAErF,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAyB,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAmB;IAC5C,OAAO,GAAG,CAAC,YAAY,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7D,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,WAAW,CAAC,GAAmB,EAAE,MAAwB;IACvE,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,sHAAsH;AACtH,MAAM,UAAU,UAAU,CAAC,GAAmB,EAAE,aAAqB;IACnE,OAAO,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,EAAE,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC;AACtG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAmB,EAAE,aAAqB;IACjE,OAAO,GAAG,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;AAC1F,CAAC"}
package/dist/html.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { DoorSet } from "@benchme/core";
1
2
  /** Escape for HTML text and attribute values. */
2
3
  export declare function esc(s: unknown): string;
3
4
  export declare function money(cents: number): string;
@@ -26,14 +27,17 @@ export type ShellCtx = {
26
27
  };
27
28
  /** The page shell every site shares: header with nav + auth links, flash, main. */
28
29
  export declare function shell(ctx: ShellCtx, title: string, body: string): string;
30
+ /** Whether an api token opens any of the open `doors`: the account page offers one only then. */
31
+ export declare const apiTokenOpens: (doors: DoorSet) => boolean;
29
32
  /** The auth pages every site shares (signup / verify / login / account). */
30
33
  export declare const authPages: {
31
34
  signup: (p: string, error?: string) => string;
32
35
  verify: (p: string, email: string, error?: string) => string;
33
36
  login: (p: string, error?: string) => string;
37
+ /** `doors`: the request's, so the api token is offered, and named, only for the doors it opens there. */
34
38
  account: (p: string, user: {
35
39
  email: string;
36
40
  displayName: string;
37
41
  apiToken: string | null;
38
- }) => string;
42
+ }, doors: DoorSet) => string;
39
43
  };
package/dist/html.js CHANGED
@@ -26,6 +26,26 @@ export function shell(ctx, title, body) {
26
26
  <body><header><a href="${p}/"><strong>${esc(ctx.site)}</strong></a>${nav}<span class="sp"></span>${who}</header>
27
27
  <main>${ctx.flash ? `<div class="flash">${esc(ctx.flash)}</div>` : ""}${body}</main>${(ctx.scripts ?? []).join("")}</body></html>`;
28
28
  }
29
+ /**
30
+ * What an api token opens, door by door, in the account page's words. A
31
+ * workspace that is not served through a door is never told the token works
32
+ * there, and one served through neither gets no token at all.
33
+ */
34
+ const TOKEN_USES = [
35
+ { door: "rest", use: (p) => `against <code>${esc(p)}/api/v1/…</code>` },
36
+ { door: "mcp", use: (p) => `to connect an MCP client to <code>${esc(p)}/mcp</code>` },
37
+ ];
38
+ /** Whether an api token opens any of the open `doors`: the account page offers one only then. */
39
+ export const apiTokenOpens = (doors) => TOKEN_USES.some((u) => doors.has(u.door));
40
+ /** The account page's api token section, naming only the open doors; none when the token would open none. */
41
+ function apiTokenSection(p, apiToken, doors) {
42
+ const uses = TOKEN_USES.filter((u) => doors.has(u.door)).map((u) => u.use(p));
43
+ if (uses.length === 0)
44
+ return "";
45
+ return `<h2>API token</h2><p>Use it as <code>Authorization: Bearer &lt;token&gt;</code> ${uses.join(", or ")}.</p>
46
+ <p>${apiToken ? `<code>${esc(apiToken)}</code>` : "<em>none yet</em>"}</p>
47
+ <form method="post" action="${p}/account/token"><button>${apiToken ? "Rotate token" : "Create token"}</button></form>`;
48
+ }
29
49
  /** The auth pages every site shares (signup / verify / login / account). */
30
50
  export const authPages = {
31
51
  signup: (p, error) => `<h1>Create an account</h1>${error ? `<div class="flash">${esc(error)}</div>` : ""}<form class="card" method="post" action="${p}/signup">
@@ -36,9 +56,8 @@ export const authPages = {
36
56
  login: (p, error) => `<h1>Sign in</h1>${error ? `<div class="flash">${esc(error)}</div>` : ""}<form class="card" method="post" action="${p}/login">
37
57
  <label>Email</label><input name="email" type="email" required><label>Password</label><input name="password" type="password" required><button>Sign in</button></form>
38
58
  <p class="muted">No account? <a href="${p}/signup">Sign up</a>.</p>`,
39
- account: (p, user) => `<h1>Account</h1><p>${esc(user.displayName)} · ${esc(user.email)}</p>
40
- <h2>API token</h2><p>Use it as <code>Authorization: Bearer &lt;token&gt;</code> against <code>${esc(p)}/api/v1/…</code>.</p>
41
- <p>${user.apiToken ? `<code>${esc(user.apiToken)}</code>` : "<em>none yet</em>"}</p>
42
- <form method="post" action="${p}/account/token"><button>${user.apiToken ? "Rotate token" : "Create token"}</button></form>`,
59
+ /** `doors`: the request's, so the api token is offered, and named, only for the doors it opens there. */
60
+ account: (p, user, doors) => `<h1>Account</h1><p>${esc(user.displayName)} · ${esc(user.email)}</p>
61
+ ${apiTokenSection(p, user.apiToken, doors)}`,
43
62
  };
44
63
  //# sourceMappingURL=html.js.map
package/dist/html.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"html.js","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,MAAM,UAAU,GAAG,CAAC,CAAU;IAC5B,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAW,CAAC,CAAC;AACtI,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,OAAO,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AACxC,CAAC;AAoBD,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC;oBACd,MAAM;;;;;sDAK4B,MAAM;;4HAEgE,CAAC;AAE7H,mFAAmF;AACnF,MAAM,UAAU,KAAK,CAAC,GAAa,EAAE,KAAa,EAAE,IAAY;IAC9D,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC;IACrB,MA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,CAAC,cAAc,kBAAkB,CAAC;AACvH,CAAC;AAED,4EAA4E;AAC5E,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,MAAM,EAAE,CAAC,CAAS,EAAE,KAAc,EAAE,EAAE,CAAC,6BAA6B,KAAK,CAAC,CAAC,CAAC,sBAAsB,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,4CAA4C,CAAC;;qIAEnC;IACnI,MAAM,EAAE,CAAC,CAAS,EAAE,KAAa,EAAE,KAAc,EAAE,EAAE,CAAC,6BAA6B,KAAK,CAAC,CAAC,CAAC,sBAAsB,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,wCAAwC,GAAG,CAAC,KAAK,CAAC;2CACjJ,CAAC,qDAAqD,GAAG,CAAC,KAAK,CAAC,oGAAoG;IAC7M,KAAK,EAAE,CAAC,CAAS,EAAE,KAAc,EAAE,EAAE,CAAC,mBAAmB,KAAK,CAAC,CAAC,CAAC,sBAAsB,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,4CAA4C,CAAC;;wCAErH,CAAC,2BAA2B;IAClE,yGAAyG;IACzG,OAAO,EAAE,CAAC,CAAS,EAAE,IAAqE,EAAE,KAAc,EAAE,EAAE,CAC5G,sBAAsB,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;EAClE,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE;CAC3C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -6,7 +6,8 @@ export { ToolRegistry, type ToolDef } from "./tool-registry.js";
6
6
  export { toolInputJsonSchema, type JsonSchemaObject } from "./tool-schema.js";
7
7
  export { DomainError, buildMcpServer, newMcpSessionId, registerMcp, type McpDeps } from "./mcp-server.js";
8
8
  export { refusalOf, type Refusal } from "./refusal.js";
9
- export { DOORS, DOOR_HEADER, WEBMCP_DOOR_VALUE, doorOf, type Door } from "./doors/door.js";
9
+ export { DOORS, DoorSet, doorOf, type Door } from "./doors/door.js";
10
+ export { BRIDGE_COOKIE, BRIDGE_TOKEN_HEADER, BridgeCredential, bridgeToken } from "./doors/bridge-credential.js";
10
11
  export { CallerScope, once, type Caller } from "./doors/caller.js";
11
12
  export { MCP_SESSION_HEADER, registerDoors, type Doors, type DoorsDeps } from "./doors/register-doors.js";
12
13
  export { SIGN_IN_REQUIRED_CODE, SignInRequired } from "./doors/sign-in.js";
@@ -20,7 +21,7 @@ export { ledgered, untransacted, type LedgeredDeps } from "./ledger/ledgered.js"
20
21
  export { about, authStep, read, unrecorded, write, type LedgerRule, type LedgerRules, type Recorded, type Subject, type Unrecorded } from "./ledger/rules.js";
21
22
  export { LEDGER_MIGRATIONS, ledgerSql, ledgerSubjectSql, ledgerTableSql } from "./ledger/schema.js";
22
23
  export { esc, money, shell, authPages, type NavLink, type ShellCtx } from "./html.js";
23
- export { webmcpScript, WEBMCP_SCRIPT_MARKER, WEBMCP_REGISTER_GLOBAL } from "./webmcp.js";
24
+ export { bridgeScript, webmcpBridge, WEBMCP_SCRIPT_MARKER, WEBMCP_REGISTER_GLOBAL } from "./webmcp.js";
24
25
  export { registerAuthRoutes, requireSession, sessionUser, apiUser, type AuthRoutesDeps, type SessionUser } from "./auth-routes.js";
25
26
  export { SCHEMA_CONTEXT, comment, digitalDocument, offer, organization, person, place, product, question, webPage, type Availability, } from "./jsonld.js";
26
27
  export * from "./nlweb/index.js";
package/dist/index.js CHANGED
@@ -6,7 +6,8 @@ export { ToolRegistry } from "./tool-registry.js";
6
6
  export { toolInputJsonSchema } from "./tool-schema.js";
7
7
  export { DomainError, buildMcpServer, newMcpSessionId, registerMcp } from "./mcp-server.js";
8
8
  export { refusalOf } from "./refusal.js";
9
- export { DOORS, DOOR_HEADER, WEBMCP_DOOR_VALUE, doorOf } from "./doors/door.js";
9
+ export { DOORS, DoorSet, doorOf } from "./doors/door.js";
10
+ export { BRIDGE_COOKIE, BRIDGE_TOKEN_HEADER, BridgeCredential, bridgeToken } from "./doors/bridge-credential.js";
10
11
  export { CallerScope, once } from "./doors/caller.js";
11
12
  export { MCP_SESSION_HEADER, registerDoors } from "./doors/register-doors.js";
12
13
  export { SIGN_IN_REQUIRED_CODE, SignInRequired } from "./doors/sign-in.js";
@@ -20,7 +21,7 @@ export { ledgered, untransacted } from "./ledger/ledgered.js";
20
21
  export { about, authStep, read, unrecorded, write } from "./ledger/rules.js";
21
22
  export { LEDGER_MIGRATIONS, ledgerSql, ledgerSubjectSql, ledgerTableSql } from "./ledger/schema.js";
22
23
  export { esc, money, shell, authPages } from "./html.js";
23
- export { webmcpScript, WEBMCP_SCRIPT_MARKER, WEBMCP_REGISTER_GLOBAL } from "./webmcp.js";
24
+ export { bridgeScript, webmcpBridge, WEBMCP_SCRIPT_MARKER, WEBMCP_REGISTER_GLOBAL } from "./webmcp.js";
24
25
  export { registerAuthRoutes, requireSession, sessionUser, apiUser } from "./auth-routes.js";
25
26
  export { SCHEMA_CONTEXT, comment, digitalDocument, offer, organization, person, place, product, question, webPage, } from "./jsonld.js";
26
27
  export * from "./nlweb/index.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAkD,MAAM,iBAAiB,CAAC;AAC7H,OAAO,EAAE,SAAS,EAAE,WAAW,EAAqD,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAgB,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAyB,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,cAAc,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string | null;
58
58
  at: string;
59
+ door: "page" | "rest" | "mcp" | "webmcp";
59
60
  seq: number;
60
61
  app: string;
61
62
  kind: "read" | "write" | "auth";
@@ -68,12 +69,12 @@ export declare const ledgerEntrySchema: z.ZodObject<{
68
69
  type: string;
69
70
  } | null;
70
71
  action: string;
71
- door: "rest" | "page" | "mcp" | "webmcp";
72
72
  actor: string | null;
73
73
  outcome: "ok" | "refused";
74
74
  }, {
75
75
  code: string | null;
76
76
  at: string;
77
+ door: "page" | "rest" | "mcp" | "webmcp";
77
78
  seq: number;
78
79
  app: string;
79
80
  kind: "read" | "write" | "auth";
@@ -86,7 +87,6 @@ export declare const ledgerEntrySchema: z.ZodObject<{
86
87
  type: string;
87
88
  } | null;
88
89
  action: string;
89
- door: "rest" | "page" | "mcp" | "webmcp";
90
90
  actor: string | null;
91
91
  outcome: "ok" | "refused";
92
92
  }>;
@@ -138,6 +138,7 @@ export declare const ledgerPageSchema: z.ZodObject<{
138
138
  }, "strip", z.ZodTypeAny, {
139
139
  code: string | null;
140
140
  at: string;
141
+ door: "page" | "rest" | "mcp" | "webmcp";
141
142
  seq: number;
142
143
  app: string;
143
144
  kind: "read" | "write" | "auth";
@@ -150,12 +151,12 @@ export declare const ledgerPageSchema: z.ZodObject<{
150
151
  type: string;
151
152
  } | null;
152
153
  action: string;
153
- door: "rest" | "page" | "mcp" | "webmcp";
154
154
  actor: string | null;
155
155
  outcome: "ok" | "refused";
156
156
  }, {
157
157
  code: string | null;
158
158
  at: string;
159
+ door: "page" | "rest" | "mcp" | "webmcp";
159
160
  seq: number;
160
161
  app: string;
161
162
  kind: "read" | "write" | "auth";
@@ -168,7 +169,6 @@ export declare const ledgerPageSchema: z.ZodObject<{
168
169
  type: string;
169
170
  } | null;
170
171
  action: string;
171
- door: "rest" | "page" | "mcp" | "webmcp";
172
172
  actor: string | null;
173
173
  outcome: "ok" | "refused";
174
174
  }>, "many">;
@@ -177,6 +177,7 @@ export declare const ledgerPageSchema: z.ZodObject<{
177
177
  items: {
178
178
  code: string | null;
179
179
  at: string;
180
+ door: "page" | "rest" | "mcp" | "webmcp";
180
181
  seq: number;
181
182
  app: string;
182
183
  kind: "read" | "write" | "auth";
@@ -189,7 +190,6 @@ export declare const ledgerPageSchema: z.ZodObject<{
189
190
  type: string;
190
191
  } | null;
191
192
  action: string;
192
- door: "rest" | "page" | "mcp" | "webmcp";
193
193
  actor: string | null;
194
194
  outcome: "ok" | "refused";
195
195
  }[];
@@ -198,6 +198,7 @@ export declare const ledgerPageSchema: z.ZodObject<{
198
198
  items: {
199
199
  code: string | null;
200
200
  at: string;
201
+ door: "page" | "rest" | "mcp" | "webmcp";
201
202
  seq: number;
202
203
  app: string;
203
204
  kind: "read" | "write" | "auth";
@@ -210,7 +211,6 @@ export declare const ledgerPageSchema: z.ZodObject<{
210
211
  type: string;
211
212
  } | null;
212
213
  action: string;
213
- door: "rest" | "page" | "mcp" | "webmcp";
214
214
  actor: string | null;
215
215
  outcome: "ok" | "refused";
216
216
  }[];
@@ -1,6 +1,6 @@
1
1
  import { VERIFIER_SIG_HEADER, verifyVerifierHeader } from "@benchme/core";
2
2
  import { z } from "zod";
3
- import { header } from "../workspace-scope.js";
3
+ import { header } from "../request-header.js";
4
4
  /** Where the verifier reads a workspace's ledger, on the app's own address. */
5
5
  export const ledgerPath = (workspaceId) => `/internal/workspaces/${workspaceId}/ledger`;
6
6
  const query = z.object({ cursor: z.coerce.number().int().min(0).default(0), limit: z.coerce.number().int().min(1).max(1000).default(500) });
@@ -1 +1 @@
1
- {"version":3,"file":"ledger-route.js","sourceRoot":"","sources":["../../src/ledger/ledger-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAI/C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,UAAU,G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AE,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,EAAE,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC;QACpH,IAAI,CAAC,YAAY,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC,WAAW;YAAE,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;QAC5G,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QACzE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -2,7 +2,6 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
3
3
  import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
4
4
  import { randomUUID } from "node:crypto";
5
- import { doorOf } from "./doors/door.js";
6
5
  import { refusalOf } from "./refusal.js";
7
6
  export { DomainError } from "./domain-error.js";
8
7
  /** An MCP session's id, told apart at a glance from a site's own session tokens. */
@@ -63,13 +62,14 @@ export function registerMcp(app, d) {
63
62
  /**
64
63
  * One transport per request, as ever. The request that initializes gets a
65
64
  * session id to repeat; every later one is taken as it comes, with no session
66
- * held here to check it against. A page's bridge reads one JSON body.
65
+ * held here to check it against. A page's bridge (a call that proved it is
66
+ * one: `req.door`, from the workspace scope) reads one JSON body.
67
67
  */
68
68
  function sessionOptions(req) {
69
69
  const messages = Array.isArray(req.body) ? req.body : [req.body];
70
70
  return {
71
71
  sessionIdGenerator: messages.some((m) => isInitializeRequest(m)) ? newMcpSessionId : undefined,
72
- enableJsonResponse: doorOf(req.url, req.headers) === "webmcp",
72
+ enableJsonResponse: req.door === "webmcp",
73
73
  };
74
74
  }
75
75
  //# sourceMappingURL=mcp-server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAoBhD,oFAAoF;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,GAAW,EAAE,CAAC,OAAO,UAAU,EAAE,EAAE,CAAC;AAEnE,yEAAyE;AACzE,MAAM,UAAU,cAAc,CAAI,CAAa,EAAE,GAAM;IACrD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IACzE,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,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AAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,SAAS,EAAE,CAAC,CAAC;QAC1H,KAAK,CAAC,MAAM,EAAE,CAAC;QACf,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACzB,KAAK,SAAS,CAAC,KAAK,EAAE,CAAC;YACvB,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC,CAAC,CAAC;QACH,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAChC,MAAM,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,GAAmB;IACzC,MAAM,QAAQ,GAAc,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5E,OAAO;QACL,kBAAkB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS;QAC9F,kBAAkB,EAAE,GAAG,CAAC,IAAI,KAAK,QAAQ;KAC1C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { FastifyRequest } from "fastify";
2
+ /** A request header's value: the first, when a client sent it more than once. */
3
+ export declare function header(req: FastifyRequest, name: string): string | undefined;
@@ -0,0 +1,6 @@
1
+ /** A request header's value: the first, when a client sent it more than once. */
2
+ export function header(req, name) {
3
+ const v = req.headers[name];
4
+ return Array.isArray(v) ? v[0] : v;
5
+ }
6
+ //# sourceMappingURL=request-header.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-header.js","sourceRoot":"","sources":["../src/request-header.ts"],"names":[],"mappings":"AAEA,iFAAiF;AACjF,MAAM,UAAU,MAAM,CAAC,GAAmB,EAAE,IAAY;IACtD,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC"}
package/dist/webmcp.d.ts CHANGED
@@ -1,13 +1,29 @@
1
+ import type { FastifyRequest } from "fastify";
1
2
  import type { ToolRegistry } from "./tool-registry.js";
2
3
  export declare const WEBMCP_SCRIPT_MARKER = "data-webmcp=\"bridge\"";
3
4
  /** The global a late-injecting agent sidecar can call once it has installed a modelContext. */
4
5
  export declare const WEBMCP_REGISTER_GLOBAL = "__benchmeWebmcpRegister";
6
+ /**
7
+ * The page's WebMCP bridge for this request, to render before </body>; nothing
8
+ * at all when the request's workspace is not served through the WebMCP door,
9
+ * so a page then names neither the site's /mcp nor a single tool.
10
+ *
11
+ * The bridge carries a token for the browser's bridge cookie, which the site
12
+ * sets on this response when the browser holds none yet (the workspace scope
13
+ * does, see `registerWorkspaceScope`), and every tool call it makes sends the
14
+ * token back. The site counts a call to /mcp as the page's bridge only when
15
+ * the token is the one for the cookie the call carries: see
16
+ * `BridgeCredential`.
17
+ */
18
+ export declare function webmcpBridge<C>(req: FastifyRequest, tools: ToolRegistry<C>): string;
5
19
  /**
6
20
  * WebMCP tools are closures inside the page. This script registers one per
7
21
  * catalog entry and bridges `execute` to the app's own `/mcp` (JSON-RPC
8
22
  * `tools/call`), so the page surface and the MCP surface can never disagree:
9
- * both are rendered from `ToolRegistry.list()`. Every call it makes carries
10
- * the door header, so the site knows the call came through a page's tool.
23
+ * both are rendered from `ToolRegistry.list()`. Every call it makes is a
24
+ * same-origin request, so the browser sends the site's cookies with it (the
25
+ * bridge cookie and, once signed in, the session), and it sends the page's
26
+ * token in BRIDGE_TOKEN_HEADER.
11
27
  *
12
28
  * Two globals carry the API today, and a page cannot know which browser it is
13
29
  * in, so it registers on EVERY distinct one present:
@@ -30,4 +46,4 @@ export declare const WEBMCP_REGISTER_GLOBAL = "__benchmeWebmcpRegister";
30
46
  * read defensively: a non-browser runtime must be a no-op, never a
31
47
  * ReferenceError that kills the rest of the page's scripts.
32
48
  */
33
- export declare function webmcpScript<C>(tools: ToolRegistry<C>, prefix: string): string;
49
+ export declare function bridgeScript<C>(tools: ToolRegistry<C>, prefix: string, token: string): string;
package/dist/webmcp.js CHANGED
@@ -1,14 +1,33 @@
1
- import { DOOR_HEADER, WEBMCP_DOOR_VALUE } from "./doors/door.js";
1
+ import { BRIDGE_TOKEN_HEADER } from "./doors/bridge-credential.js";
2
2
  import { toolInputJsonSchema } from "./tool-schema.js";
3
3
  export const WEBMCP_SCRIPT_MARKER = 'data-webmcp="bridge"';
4
4
  /** The global a late-injecting agent sidecar can call once it has installed a modelContext. */
5
5
  export const WEBMCP_REGISTER_GLOBAL = "__benchmeWebmcpRegister";
6
+ /**
7
+ * The page's WebMCP bridge for this request, to render before </body>; nothing
8
+ * at all when the request's workspace is not served through the WebMCP door,
9
+ * so a page then names neither the site's /mcp nor a single tool.
10
+ *
11
+ * The bridge carries a token for the browser's bridge cookie, which the site
12
+ * sets on this response when the browser holds none yet (the workspace scope
13
+ * does, see `registerWorkspaceScope`), and every tool call it makes sends the
14
+ * token back. The site counts a call to /mcp as the page's bridge only when
15
+ * the token is the one for the cookie the call carries: see
16
+ * `BridgeCredential`.
17
+ */
18
+ export function webmcpBridge(req, tools) {
19
+ if (!req.bridge || !req.doors.has("webmcp"))
20
+ return "";
21
+ return bridgeScript(tools, req.prefix, req.bridge.issue());
22
+ }
6
23
  /**
7
24
  * WebMCP tools are closures inside the page. This script registers one per
8
25
  * catalog entry and bridges `execute` to the app's own `/mcp` (JSON-RPC
9
26
  * `tools/call`), so the page surface and the MCP surface can never disagree:
10
- * both are rendered from `ToolRegistry.list()`. Every call it makes carries
11
- * the door header, so the site knows the call came through a page's tool.
27
+ * both are rendered from `ToolRegistry.list()`. Every call it makes is a
28
+ * same-origin request, so the browser sends the site's cookies with it (the
29
+ * bridge cookie and, once signed in, the session), and it sends the page's
30
+ * token in BRIDGE_TOKEN_HEADER.
12
31
  *
13
32
  * Two globals carry the API today, and a page cannot know which browser it is
14
33
  * in, so it registers on EVERY distinct one present:
@@ -31,11 +50,11 @@ export const WEBMCP_REGISTER_GLOBAL = "__benchmeWebmcpRegister";
31
50
  * read defensively: a non-browser runtime must be a no-op, never a
32
51
  * ReferenceError that kills the rest of the page's scripts.
33
52
  */
34
- export function webmcpScript(tools, prefix) {
53
+ export function bridgeScript(tools, prefix, token) {
35
54
  const catalog = tools.list().map((t) => ({ name: t.name, description: t.description, inputSchema: toolInputJsonSchema(t) }));
36
- const json = JSON.stringify({ endpoint: `${prefix}/mcp`, tools: catalog }).replace(/<\//g, "<\\/");
55
+ const json = JSON.stringify({ endpoint: `${prefix}/mcp`, token, tools: catalog }).replace(/<\//g, "<\\/");
37
56
  return `<script ${WEBMCP_SCRIPT_MARKER}>(function(){var cfg=${json};var seq=0;var done=[];
38
- function call(name,args){return fetch(cfg.endpoint,{method:"POST",headers:{"content-type":"application/json","accept":"application/json, text/event-stream","${DOOR_HEADER}":"${WEBMCP_DOOR_VALUE}"},body:JSON.stringify({jsonrpc:"2.0",id:++seq,method:"tools/call",params:{name:name,arguments:args||{}}})}).then(function(r){return r.text()}).then(function(t){var line=t.split("\\n").filter(function(l){return l.indexOf("data:")===0}).pop();var body=JSON.parse(line?line.slice(5):t);var c=body.result&&body.result.content;return c&&c[0]&&c[0].text?c[0].text:JSON.stringify(body.result||body.error)})}
57
+ function call(name,args){return fetch(cfg.endpoint,{method:"POST",credentials:"same-origin",headers:{"content-type":"application/json","accept":"application/json, text/event-stream","${BRIDGE_TOKEN_HEADER}":cfg.token},body:JSON.stringify({jsonrpc:"2.0",id:++seq,method:"tools/call",params:{name:name,arguments:args||{}}})}).then(function(r){return r.text()}).then(function(t){var line=t.split("\\n").filter(function(l){return l.indexOf("data:")===0}).pop();var body=JSON.parse(line?line.slice(5):t);var c=body.result&&body.result.content;return c&&c[0]&&c[0].text?c[0].text:JSON.stringify(body.result||body.error)})}
39
58
  function contexts(){var out=[];if(typeof document!=="undefined"&&document&&document.modelContext)out.push(document.modelContext);if(typeof navigator!=="undefined"&&navigator&&navigator.modelContext&&out.indexOf(navigator.modelContext)<0)out.push(navigator.modelContext);return out.filter(function(mc){return typeof mc.registerTool==="function"})}
40
59
  function register(){contexts().forEach(function(mc){if(done.indexOf(mc)>=0)return;done.push(mc);
41
60
  cfg.tools.forEach(function(t){try{mc.registerTool({name:t.name,description:t.description,inputSchema:t.inputSchema,execute:function(a){return call(t.name,a)}})}catch(e){if(typeof console!=="undefined")console.warn("webmcp: "+t.name+" not registered: "+e)}})});return done.length>0}
@@ -1 +1 @@
1
- {"version":3,"file":"webmcp.js","sourceRoot":"","sources":["../src/webmcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAE3D,+FAA+F;AAC/F,MAAM,CAAC,MAAM,sBAAsB,GAAG,yBAAyB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,YAAY,CAAI,KAAsB,EAAE,MAAc;IACpE,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,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,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7H,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1G,OAAO,WAAW,oBAAoB,wBAAwB,IAAI;yLACqH,mBAAmB;;;;wCAIpK,sBAAsB;;kIAEoE,CAAC;AACnI,CAAC"}
@@ -1,16 +1,32 @@
1
- import type { FastifyInstance, FastifyRequest } from "fastify";
1
+ import { DoorSet, type Door } from "@benchme/core";
2
+ import type { FastifyInstance } from "fastify";
3
+ import { BridgeCredential } from "./doors/bridge-credential.js";
4
+ export { header } from "./request-header.js";
2
5
  declare module "fastify" {
3
6
  interface FastifyRequest {
4
7
  /** Bound by the gateway (signed); every tenant query is scoped by it. */
5
8
  workspaceId: string;
6
9
  /** The public path prefix the gateway stripped ("/w/<id>/<app>"), for links + cookie paths. */
7
10
  prefix: string;
11
+ /** The doors the gateway serves this request's workspace through (signed): every door when it named none. */
12
+ doors: DoorSet;
13
+ /** The door this request came through, or null for what is no door (the probes, /internal/). */
14
+ door: Door | null;
15
+ /** This request's WebMCP bridge credential; null on a path outside any workspace. */
16
+ bridge: BridgeCredential | null;
8
17
  }
9
18
  }
10
19
  /**
11
20
  * Trust the workspace ONLY from the gateway's signed header. A request without
12
21
  * it (or with a bad signature) never reaches a tenant query. Paths in
13
22
  * `unscopedPrefixes` (internal endpoints authenticated some other way) skip it.
23
+ *
24
+ * The doors come with it, signed for the same workspace (or not at all, from
25
+ * a gateway older than doors: then every door is open). A request through a
26
+ * door its workspace is not served through is told there is no such thing,
27
+ * before any handler, body parser or JSON-RPC reads it: the gateway closes the
28
+ * door by path first, and this is the second lock, the one that knows a
29
+ * page's bridge from a direct MCP client. And a page that renders its WebMCP
30
+ * bridge (`webmcpBridge`) gets the bridge cookie set on its response here.
14
31
  */
15
32
  export declare function registerWorkspaceScope(app: FastifyInstance, gatewaySecret: string, unscopedPrefixes?: readonly string[]): void;
16
- export declare function header(req: FastifyRequest, name: string): string | undefined;
@@ -1,28 +1,56 @@
1
- import { FORWARDED_PREFIX_HEADER, WORKSPACE_HEADER, WORKSPACE_SIG_HEADER, isWorkspaceId, verifyWorkspaceHeader } from "@benchme/core";
1
+ import { DOORS_HEADER, DOORS_SIG_HEADER, DoorSet, FORWARDED_PREFIX_HEADER, WORKSPACE_HEADER, WORKSPACE_SIG_HEADER, doorsFromHeaders, isWorkspaceId, verifyWorkspaceHeader, } from "@benchme/core";
2
+ import { BridgeCredential, bridgeSetCookie } from "./doors/bridge-credential.js";
3
+ import { isClosed, requestDoor } from "./doors/request-door.js";
4
+ import { header } from "./request-header.js";
5
+ export { header } from "./request-header.js";
2
6
  const UNSCOPED = new Set(["/healthz", "/readyz"]);
7
+ const notThroughGateway = (reply) => reply.code(401).send({ error: "NO_WORKSPACE", message: "requests must come through the benchme gateway" });
3
8
  /**
4
9
  * Trust the workspace ONLY from the gateway's signed header. A request without
5
10
  * it (or with a bad signature) never reaches a tenant query. Paths in
6
11
  * `unscopedPrefixes` (internal endpoints authenticated some other way) skip it.
12
+ *
13
+ * The doors come with it, signed for the same workspace (or not at all, from
14
+ * a gateway older than doors: then every door is open). A request through a
15
+ * door its workspace is not served through is told there is no such thing,
16
+ * before any handler, body parser or JSON-RPC reads it: the gateway closes the
17
+ * door by path first, and this is the second lock, the one that knows a
18
+ * page's bridge from a direct MCP client. And a page that renders its WebMCP
19
+ * bridge (`webmcpBridge`) gets the bridge cookie set on its response here.
7
20
  */
8
21
  export function registerWorkspaceScope(app, gatewaySecret, unscopedPrefixes = []) {
9
22
  app.decorateRequest("workspaceId", "");
10
23
  app.decorateRequest("prefix", "");
24
+ app.decorateRequest("doors");
25
+ app.decorateRequest("door");
26
+ app.decorateRequest("bridge");
11
27
  app.addHook("onRequest", async (req, reply) => {
28
+ req.doors = DoorSet.ALL;
29
+ req.door = null;
30
+ req.bridge = null;
12
31
  const path = req.url.split("?")[0] ?? "";
13
32
  if (UNSCOPED.has(path) || unscopedPrefixes.some((p) => path.startsWith(p)))
14
33
  return;
15
34
  const id = header(req, WORKSPACE_HEADER);
16
35
  const sig = header(req, WORKSPACE_SIG_HEADER);
17
- if (!id || !isWorkspaceId(id) || !sig || !verifyWorkspaceHeader(gatewaySecret, id, sig)) {
18
- return reply.code(401).send({ error: "NO_WORKSPACE", message: "requests must come through the benchme gateway" });
19
- }
36
+ if (!id || !isWorkspaceId(id) || !sig || !verifyWorkspaceHeader(gatewaySecret, id, sig))
37
+ return notThroughGateway(reply);
38
+ const doors = doorsFromHeaders(gatewaySecret, id, header(req, DOORS_HEADER), header(req, DOORS_SIG_HEADER));
39
+ if (!doors)
40
+ return notThroughGateway(reply);
20
41
  req.workspaceId = id;
21
42
  req.prefix = header(req, FORWARDED_PREFIX_HEADER) ?? "";
43
+ req.doors = doors;
44
+ req.bridge = BridgeCredential.of(gatewaySecret, id, header(req, "cookie"));
45
+ req.door = requestDoor(req, req.bridge);
46
+ if (isClosed(req, gatewaySecret))
47
+ return reply.code(404).send({ error: "NOT_FOUND" });
48
+ });
49
+ app.addHook("onSend", async (req, reply, payload) => {
50
+ const minted = req.bridge?.mintedCookie;
51
+ if (minted)
52
+ reply.header("set-cookie", bridgeSetCookie(minted, `${req.prefix}/`));
53
+ return payload;
22
54
  });
23
- }
24
- export function header(req, name) {
25
- const v = req.headers[name];
26
- return Array.isArray(v) ? v[0] : v;
27
55
  }
28
56
  //# sourceMappingURL=workspace-scope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-scope.js","sourceRoot":"","sources":["../src/workspace-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAYtI,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CA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AAG,EAAE,uBAAuB,CAAC,IAAI,EAAE,CAAC;QACxD,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;QAClB,GAAG,CAAC,MAAM,GAAG,gBAAgB,CAAC,EAAE,CAAC,aAAa,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC3E,GAAG,CAAC,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QACxC,IAAI,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;YAAE,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QAClD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC;QACxC,IAAI,MAAM;YAAE,KAAK,CAAC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAClF,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@benchme/site-kit",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "test": "vitest run"
17
17
  },
18
18
  "dependencies": {
19
- "@benchme/core": "0.11.0",
19
+ "@benchme/core": "0.12.0",
20
20
  "@modelcontextprotocol/sdk": "^1.12.0",
21
21
  "fastify": "^5.2.0",
22
22
  "zod": "^3.24.0",