import { env, runInDurableObject, SELF } from "cloudflare:test"; import { describe, expect, it } from "vitest"; import { ADMIN, http, OWNER_PHONE, personalObject } from "./personal.ts"; const SLUG = "oauthp"; const NAMED = "oauthn"; const SPENT = "oauths"; const BASE = `https://example.test/b/${SLUG}`; const REDIRECT = "https://claude.ai/api/mcp/auth_callback"; const STRANGER = "+919000000123"; async function get(url: string): Promise { return SELF.fetch(url, { redirect: "manual" }); } async function post(url: string, body: Record, headers: Record = {}): Promise { return SELF.fetch(url, { method: "POST", redirect: "manual", headers: { "content-type": "application/x-www-form-urlencoded", ...headers }, body: new URLSearchParams(body).toString() }); } async function s256(verifier: string): Promise { const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier))); return btoa(String.fromCharCode(...digest)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); } function verifier(): string { const bytes = crypto.getRandomValues(new Uint8Array(40)); return btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); } /** The hidden fields of a page's form. */ function fields(html: string): Record { const out: Record = {}; for (const m of html.matchAll(//g)) out[m[1]!] = m[2]!.replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&"); return out; } async function register(name = "Claude", base = BASE): Promise { const res = await SELF.fetch(`${base}/oauth/register`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ client_name: name, redirect_uris: [REDIRECT], grant_types: ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:jwt-bearer"], response_types: ["code"], token_endpoint_auth_method: "client_secret_post" }), }); expect(res.status).toBe(201); return ((await res.json()) as { client_id: string }).client_id; } function query(clientId: string, challenge: string, extra: Record = {}, base = BASE): URLSearchParams { return new URLSearchParams({ client_id: clientId, redirect_uri: REDIRECT, response_type: "code", code_challenge: challenge, code_challenge_method: "S256", state: "st-1", scope: "owner", resource: `${base}/mcp`, ...extra }); } /** The whole sign-in page: phone, the fixed code, and what the last step answers. */ async function signIn(clientId: string, challenge: string, phone = OWNER_PHONE, base = BASE): Promise { const start = await get(`${base}/oauth/authorize?${query(clientId, challenge, {}, base)}`); expect(start.status).toBe(200); const sent = await post(`${base}/oauth/authorize`, { ...fields(await start.text()), phone }); const html = await sent.text(); expect(sent.status, html).toBe(200); expect(html).toContain(`Enter the code sent to ${phone}`); return post(`${base}/oauth/authorize`, { ...fields(html), code: "123456" }); } /** A code the owner's sign-in hands back, with its verifier. */ async function codeFor(clientId: string, base = BASE): Promise<{ code: string; verifier: string }> { const v = verifier(); const res = await signIn(clientId, await s256(v), OWNER_PHONE, base); expect(res.status, await res.clone().text()).toBe(302); const to = new URL(res.headers.get("location")!); expect(`${to.origin}${to.pathname}`).toBe(REDIRECT); expect(to.searchParams.get("state")).toBe("st-1"); return { code: to.searchParams.get("code")!, verifier: v }; } async function redeem(clientId: string, code: string, v: string, redirect = REDIRECT, base = BASE): Promise<{ status: number; body: Record }> { const res = await post(`${base}/oauth/token`, { grant_type: "authorization_code", client_id: clientId, code, code_verifier: v, redirect_uri: redirect, resource: `${base}/mcp` }); return { status: res.status, body: (await res.json()) as Record }; } async function toolsList(token: string): Promise { const res = await http<{ result?: { tools: unknown[] } }>(SLUG, "POST", "/mcp", { jsonrpc: "2.0", id: 1, method: "tools/list" }, { authorization: `Bearer ${token}` }); if (res.status === 200) expect(res.body.result?.tools.length).toBeGreaterThan(0); return res.status; } /** RULE (owner, 25 Oct 2026): claude.ai and Claude Desktop connect to Cotton MCP by URL alone, over OAuth on the personal object; only the owner's phone signs in. */ describe("OAuth for Cotton MCP on the personal object", () => { let clientId = ""; it("publishes both documents under the /b/ prefix, in both well-known spellings", async () => { await personalObject(SLUG); const resource = { resource: `${BASE}/mcp`, authorization_servers: [BASE], scopes_supported: ["owner"], bearer_methods_supported: ["header"] }; for (const url of [`${BASE}/.well-known/oauth-protected-resource`, `${BASE}/.well-known/oauth-protected-resource/mcp`, `https://example.test/.well-known/oauth-protected-resource/b/${SLUG}/mcp`]) { const res = await get(url); expect(res.status, url).toBe(200); expect(await res.json(), url).toMatchObject(resource); } for (const url of [`${BASE}/.well-known/oauth-authorization-server`, `https://example.test/.well-known/oauth-authorization-server/b/${SLUG}`]) { const res = await get(url); expect(res.headers.get("access-control-allow-origin")).toBe("*"); expect(await res.json(), url).toEqual({ issuer: BASE, authorization_endpoint: `${BASE}/oauth/authorize`, token_endpoint: `${BASE}/oauth/token`, registration_endpoint: `${BASE}/oauth/register`, response_types_supported: ["code"], grant_types_supported: ["authorization_code", "refresh_token"], code_challenge_methods_supported: ["S256"], token_endpoint_auth_methods_supported: ["none", "client_secret_post"], scopes_supported: ["owner"], }); } }); it("names every URL after the host on a named host", async () => { const meta = await http(NAMED, "PUT", "/v1/admin/business", { name: "Personal", kind: "personal", owner_phone: OWNER_PHONE, database_id: "22222222-2222-4222-8222-222222222222" }, ADMIN); expect(meta.status).toBe(200); const host = `https://${NAMED}.example.test`; const pr = await get(`${host}/.well-known/oauth-protected-resource/mcp`); expect(await pr.json()).toMatchObject({ resource: `${host}/mcp`, authorization_servers: [host] }); const as = (await (await get(`${host}/.well-known/oauth-authorization-server`)).json()) as Record; expect(as).toMatchObject({ issuer: host, authorization_endpoint: `${host}/oauth/authorize`, token_endpoint: `${host}/oauth/token`, registration_endpoint: `${host}/oauth/register` }); }); it("is not on a business object", async () => { await http("oauthb", "PUT", "/v1/admin/business", { name: "Studio", kind: "business" }, ADMIN); for (const path of ["/.well-known/oauth-authorization-server", "/.well-known/oauth-protected-resource/mcp"]) expect((await get(`https://example.test/b/oauthb${path}`)).status).toBe(404); expect((await SELF.fetch("https://example.test/b/oauthb/oauth/register", { method: "POST", body: "{}" })).status).toBe(404); }); it("challenges an MCP call with no token or a dead one with where to sign in", async () => { const none = await SELF.fetch(`${BASE}/mcp`, { method: "POST", body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: {} }) }); expect(none.status).toBe(401); expect(none.headers.get("www-authenticate")).toBe(`Bearer resource_metadata="https://example.test/.well-known/oauth-protected-resource/b/${SLUG}/mcp", scope="owner"`); const dead = await SELF.fetch(`${BASE}/mcp`, { method: "POST", headers: { authorization: "Bearer ctn_nope" }, body: "{}" }); expect(dead.headers.get("www-authenticate")).toMatch(/^Bearer error="invalid_token", resource_metadata="/); }); it("registers a client that asks for nothing it cannot have, and refuses an unusable redirect", async () => { const res = await SELF.fetch(`${BASE}/oauth/register`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ client_name: "Claude", redirect_uris: [REDIRECT], grant_types: ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:jwt-bearer"] }) }); expect(res.status).toBe(201); const body = (await res.json()) as Record; expect(body).toMatchObject({ client_name: "Claude", redirect_uris: [REDIRECT], token_endpoint_auth_method: "none", grant_types: ["authorization_code", "refresh_token"] }); expect(body.client_id).toMatch(/^cc_/); clientId = await register(); for (const redirect_uris of [["http://evil.example/cb"], ["https://claude.ai/cb#frag"], []]) { const bad = await SELF.fetch(`${BASE}/oauth/register`, { method: "POST", body: JSON.stringify({ redirect_uris }) }); expect(bad.status).toBe(400); expect(((await bad.json()) as { error: string }).error).toBe("invalid_redirect_uri"); } }); it("keeps no client on the object, and refuses a name that would not read as itself (ROUTES-AUDIT 14)", async () => { // STRANGER BLIND (24 Nov 2026): a named host's clients are the directory's, as the open host's are, so registering says // nothing of whether a database is there; the directory's hour limit per network holds them. await personalObject("oauthcap"); const base = "https://example.test/b/oauthcap"; const reg = (client_name: string) => SELF.fetch(`${base}/oauth/register`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ client_name, redirect_uris: [REDIRECT] }) }); for (const name of ["Claude\u202Eedualc", "Claude\u0000", "line\nbreak"]) { const bad = await reg(name); expect(bad.status, name).toBe(400); expect(((await bad.json()) as { error: string }).error).toBe("invalid_client_metadata"); } expect((await reg("Claude")).status).toBe(201); const held = await runInDurableObject(env.BUSINESS.get(env.BUSINESS.idFromName("oauthcap")), (_o, state) => state.storage.sql.exec("SELECT COUNT(*) AS n FROM rows WHERE table_id = 'oauth_client'").one().n); expect(held).toBe(0); }); it("asks for the phone on a plain page, says a bad client or redirect there, and sends anything else back", async () => { const challenge = await s256(verifier()); const start = await get(`${BASE}/oauth/authorize?${query(clientId, challenge)}`); const html = await start.text(); expect(start.headers.get("content-type")).toContain("text/html"); expect(html).toContain("Claude is asking to connect"); expect(html).toContain(`action="${BASE}/oauth/authorize"`); expect(html).toContain('name="phone"'); expect((await get(`${BASE}/oauth/authorize?${query("cc_nobody", challenge)}`)).status).toBe(400); expect((await get(`${BASE}/oauth/authorize?${query(clientId, challenge, { redirect_uri: "https://evil.example/cb" })}`)).status).toBe(400); const plain = await get(`${BASE}/oauth/authorize?${query(clientId, challenge, { code_challenge_method: "plain" })}`); expect(plain.status).toBe(302); expect(new URL(plain.headers.get("location")!).searchParams.get("error")).toBe("invalid_request"); const elsewhere = await get(`${BASE}/oauth/authorize?${query(clientId, challenge, { resource: "https://other.example/mcp" })}`); expect(new URL(elsewhere.headers.get("location")!).searchParams.get("error")).toBe("invalid_target"); }); it("sends a stranger no code at all, and refuses a wrong code", async () => { // ROUTES-AUDIT 1: the phone step itself refuses a number that is not the owner's; no challenge reaches the page. const begun = await get(`${BASE}/oauth/authorize?${query(clientId, await s256(verifier()))}`); const refused = await post(`${BASE}/oauth/authorize`, { ...fields(await begun.text()), phone: STRANGER }); expect(refused.status).toBe(403); const html = await refused.text(); expect(html).toContain("Only its owner can connect"); expect(html).not.toContain("challenge_id"); const start = await get(`${BASE}/oauth/authorize?${query(clientId, await s256(verifier()))}`); const sent = await post(`${BASE}/oauth/authorize`, { ...fields(await start.text()), phone: OWNER_PHONE }); const wrong = await post(`${BASE}/oauth/authorize`, { ...fields(await sent.text()), code: "000000" }); expect(wrong.status).toBe(401); expect(await wrong.text()).toContain("Invalid or expired code."); }); it("answers the same code form sent twice with a grant each time, and still refuses another code", async () => { // A browser can send the form twice: an autofilled code that submits, then a tap on the button. await personalObject("oauthtwice"); const base = "https://example.test/b/oauthtwice"; const client = await register("Claude", base); const v = verifier(); const start = await get(`${base}/oauth/authorize?${query(client, await s256(v), {}, base)}`); const sent = await post(`${base}/oauth/authorize`, { ...fields(await start.text()), phone: OWNER_PHONE }); const form = fields(await sent.text()); const first = await post(`${base}/oauth/authorize`, { ...form, code: "123456" }); const second = await post(`${base}/oauth/authorize`, { ...form, code: "123456" }); expect(first.status).toBe(302); expect(second.status, await second.clone().text()).toBe(302); const code = new URL(second.headers.get("location")!).searchParams.get("code")!; expect(code).not.toBe(new URL(first.headers.get("location")!).searchParams.get("code")); expect((await redeem(client, code, v, REDIRECT, base)).status).toBe(200); const other = await post(`${base}/oauth/authorize`, { ...form, code: "000000" }); expect(other.status).toBe(401); expect(await other.text()).toContain("Invalid or expired code."); }); it("spends a code on a wrong verifier, redirect or client, whatever comes after", async () => { // Its own object: the owner's phone is asked five codes an hour at most. await personalObject(SPENT); const base = `https://example.test/b/${SPENT}`; const client = await register("Claude", base); const a = await codeFor(client, base); expect(await redeem(client, a.code, verifier(), REDIRECT, base)).toEqual({ status: 400, body: { error: "invalid_grant", error_description: "authorization code is not valid" } }); expect((await redeem(client, a.code, a.verifier, REDIRECT, base)).status).toBe(400); const b = await codeFor(client, base); expect((await redeem(client, b.code, b.verifier, "https://claude.ai/other", base)).status).toBe(400); expect((await redeem(client, b.code, b.verifier, REDIRECT, base)).status).toBe(400); const c = await codeFor(client, base); const other = await register("Other", base); expect((await redeem(other, c.code, c.verifier, REDIRECT, base)).status).toBe(400); expect((await redeem(client, c.code, c.verifier, REDIRECT, base)).status).toBe(400); }); it("redeems a code once for an owner token that works at /mcp; a second redemption kills it", async () => { const { code, verifier: v } = await codeFor(clientId); const first = await redeem(clientId, code, v); expect(first.status, JSON.stringify(first.body)).toBe(200); expect(first.body).toMatchObject({ token_type: "Bearer", expires_in: 30 * 86_400, scope: "owner" }); expect(first.body.access_token).toMatch(/^ctn_11111111-1111-4111-8111-111111111111_/); expect(first.body.refresh_token).toMatch(/^ctr_/); const access = first.body.access_token as string; expect(await toolsList(access)).toBe(200); expect((await redeem(clientId, code, v)).body).toEqual({ error: "invalid_grant", error_description: "authorization code is not valid" }); expect(await toolsList(access)).toBe(401); }); it("rotates on refresh: the old pair dies, the new one works, and a replayed refresh ends the connection", async () => { const { code, verifier: v } = await codeFor(clientId); const first = (await redeem(clientId, code, v)).body as { access_token: string; refresh_token: string }; const res = await post(`${BASE}/oauth/token`, { grant_type: "refresh_token", client_id: clientId, refresh_token: first.refresh_token }); expect(res.status).toBe(200); const next = (await res.json()) as { access_token: string; refresh_token: string; token_type: string; scope: string }; expect(next).toMatchObject({ token_type: "Bearer", scope: "owner" }); expect(next.access_token).not.toBe(first.access_token); expect(next.refresh_token).not.toBe(first.refresh_token); expect(await toolsList(first.access_token)).toBe(401); expect(await toolsList(next.access_token)).toBe(200); const other = await register("Other"); expect((await post(`${BASE}/oauth/token`, { grant_type: "refresh_token", client_id: other, refresh_token: next.refresh_token })).status).toBe(400); const replay = await post(`${BASE}/oauth/token`, { grant_type: "refresh_token", client_id: clientId, refresh_token: first.refresh_token }); expect(replay.status).toBe(400); expect(((await replay.json()) as { error: string }).error).toBe("invalid_grant"); expect(await toolsList(next.access_token)).toBe(401); }); it("answers the token endpoint's refusals in OAuth's shape", async () => { expect(await (await post(`${BASE}/oauth/token`, { grant_type: "authorization_code", client_id: "cc_nobody", code: "x", code_verifier: verifier(), redirect_uri: REDIRECT })).json()).toEqual({ error: "invalid_client", error_description: "unknown client" }); expect(await (await post(`${BASE}/oauth/token`, { grant_type: "password", client_id: clientId })).json()).toMatchObject({ error: "unsupported_grant_type" }); const json = await SELF.fetch(`${BASE}/oauth/token`, { method: "POST", headers: { "content-type": "application/json" }, body: "{}" }); expect(await json.json()).toMatchObject({ error: "invalid_request" }); }); it("ADMIN KEYS 2: a new connection's key carries the narrowest useful set, a refresh carries the connection's, and the owner's device widens it", async () => { const slug = "oauth-allow"; const base = `https://example.test/b/${slug}`; const { credential } = await personalObject(slug); const client = await register("Claude", base); const { code, verifier: v } = await codeFor(client, base); const first = (await redeem(client, code, v, REDIRECT, base)).body as { access_token: string; refresh_token: string }; const names = async (token: string) => (await http<{ result: { tools: { name: string }[] } }>(slug, "POST", "/mcp", { jsonrpc: "2.0", id: 1, method: "tools/list" }, { authorization: `Bearer ${token}` })).body.result.tools.map((t) => t.name); const shown = await names(first.access_token); expect(shown).toEqual(expect.arrayContaining(["brief", "recall", "remember", "log_session"])); expect(shown).not.toContain("list_changes"); expect(shown).not.toContain("export_open_bundle"); // A device route is shut to it, scopes off as they are by default. expect((await http<{ code: string }>(slug, "GET", "/v1/sync", undefined, { authorization: `Bearer ${first.access_token}` })).body.code).toBe("key_allow"); const refreshed = (await (await post(`${base}/oauth/token`, { grant_type: "refresh_token", client_id: client, refresh_token: first.refresh_token })).json()) as { access_token: string; refresh_token: string }; expect(await names(refreshed.access_token)).not.toContain("list_changes"); // The owner's phone widens the connection: every live token of it, and the next refresh too. const row = await runInDurableObject(env.BUSINESS.get(env.BUSINESS.idFromName(slug)), (instance) => { const store = (instance as unknown as { store: { scan(t: string): Iterable<{ id: string; data: Record }> } }).store; return [...store.scan("mcp_token")].find((r) => !r.data.revoked_at && typeof r.data.connection_id === "string")!; }); const widened = await http(slug, "POST", "/v1/act", { act: "token_allow", args: { id: row.id, allow: "all" } }, { authorization: `Bearer ${credential}` }); expect(widened.status, JSON.stringify(widened.body)).toBe(200); expect(await names(refreshed.access_token)).toContain("list_changes"); const again = (await (await post(`${base}/oauth/token`, { grant_type: "refresh_token", client_id: client, refresh_token: refreshed.refresh_token })).json()) as { access_token: string }; expect(await names(again.access_token)).toContain("list_changes"); // A key never sets what a key may do (an access act, ADMIN KEYS 1b). expect((await http<{ code: string }>(slug, "POST", "/v1/act", { act: "token_allow", args: { id: row.id, allow: "all" } }, { authorization: `Bearer ${again.access_token}` })).body.code).toBe("access_act"); }); it("ADMIN KEYS 4: a revoked connection's refresh is refused, and a spent refresh token put back unspent never works again", async () => { const slug = "oauth-revoked-refresh"; const base = `https://example.test/b/${slug}`; const { credential } = await personalObject(slug); const object = env.BUSINESS.get(env.BUSINESS.idFromName(slug)); const client = await register("Claude", base); const { code, verifier: v } = await codeFor(client, base); const first = (await redeem(client, code, v, REDIRECT, base)).body as { access_token: string; refresh_token: string }; // A spent refresh token: used once, then its row put back to unspent (as an undo of that write would). const second = (await (await post(`${base}/oauth/token`, { grant_type: "refresh_token", client_id: client, refresh_token: first.refresh_token })).json()) as { access_token: string; refresh_token: string }; expect(second.access_token).toBeTruthy(); await runInDurableObject(object, (instance) => { const store = (instance as unknown as { store: { scan(t: string): Iterable<{ id: string; data: Record }> }; ctx: { storage: { sql: { exec(q: string, ...a: unknown[]): unknown } } } }).store; for (const row of store.scan("oauth_refresh")) { if (row.data.used_at) (instance as unknown as { ctx: { storage: { sql: { exec(q: string, ...a: unknown[]): unknown } } } }).ctx.storage.sql.exec("UPDATE rows SET data = json_remove(json_remove(data, '$.used_at'), '$.replaced_by') WHERE table_id = 'oauth_refresh' AND id = ?", row.id); } }); const replay = await post(`${base}/oauth/token`, { grant_type: "refresh_token", client_id: client, refresh_token: first.refresh_token }); expect((await replay.json()) as { error: string }).toMatchObject({ error: "invalid_grant" }); // The owner revokes the connection's live token on the phone: its refresh token is refused too. const live = await runInDurableObject(object, (instance) => [...(instance as unknown as { store: { scan(t: string): Iterable<{ id: string; data: Record }> } }).store.scan("mcp_token")].find((r) => typeof r.data.connection_id === "string" && !r.data.revoked_at)!); expect((await http(slug, "POST", "/v1/act", { act: "revoke_token", args: { id: live.id } }, { authorization: `Bearer ${credential}` })).status).toBe(200); const after = await post(`${base}/oauth/token`, { grant_type: "refresh_token", client_id: client, refresh_token: second.refresh_token }); expect((await after.json()) as { error: string }).toMatchObject({ error: "invalid_grant" }); }); it("AUDIT C 1: revoking a connection's key spends its refresh rows; Remove ends every connection's keys and refreshes", async () => { const slug = "oauth-end-whole"; const base = `https://example.test/b/${slug}`; const { credential } = await personalObject(slug); const object = env.BUSINESS.get(env.BUSINESS.idFromName(slug)); type Rows = { store: { scan(t: string): Iterable<{ id: string; data: Record }> } }; const rows = (table: string) => runInDurableObject(object, (instance) => [...(instance as unknown as Rows).store.scan(table)].map((r) => ({ id: r.id, data: r.data }))); const connect = async () => { const client = await register("Claude", base); const { code, verifier: v } = await codeFor(client, base); return (await redeem(client, code, v, REDIRECT, base)).body as { access_token: string; refresh_token: string }; }; await connect(); const tokensA = await rows("mcp_token"); const a = tokensA.find((r) => typeof r.data.connection_id === "string")!; expect((await http(slug, "POST", "/v1/act", { act: "revoke_token", args: { id: a.id } }, { authorization: `Bearer ${credential}` })).status).toBe(200); expect((await rows("oauth_refresh")).every((r) => r.data.used_at)).toBe(true); // A second connection, then Remove on the owner's device: its key is revoked and its refresh spent. const b = await connect(); const listed = async () => (await http(slug, "POST", "/mcp", { jsonrpc: "2.0", id: 1, method: "tools/list" }, { authorization: `Bearer ${b.access_token}` })).status; expect(await listed()).toBe(200); const removed = await http(slug, "POST", "/v1/act", { act: "assistant_remove", args: {} }, { authorization: `Bearer ${credential}` }); expect(removed.status, JSON.stringify(removed.body)).toBe(200); expect((await rows("mcp_token")).filter((r) => typeof r.data.connection_id === "string").every((r) => r.data.revoked_at)).toBe(true); expect((await rows("oauth_refresh")).every((r) => r.data.used_at)).toBe(true); expect(await listed()).toBe(401); }); it("ADMIN KEYS 3: with KEY_DEFAULT today (live, until the owner flips it) a new connection is as before allows", async () => { const slug = "oauth-allow-today"; const base = `https://example.test/b/${slug}`; await personalObject(slug); const object = env.BUSINESS.get(env.BUSINESS.idFromName(slug)); const flip = (value: string) => runInDurableObject(object, (instance) => void ((instance as unknown as { env: Record }).env.KEY_DEFAULT = value)); await flip("today"); const client = await register("Claude", base); const { code, verifier: v } = await codeFor(client, base); const first = (await redeem(client, code, v, REDIRECT, base)).body as { access_token: string; refresh_token: string }; const rows = await runInDurableObject(object, (instance) => [...(instance as unknown as { store: { scan(t: string): Iterable<{ data: Record }> } }).store.scan("mcp_token")].filter((r) => typeof r.data.connection_id === "string")); expect(rows.length).toBe(1); expect(rows[0]!.data.allow ?? null).toBeNull(); const shown = (await http<{ result: { tools: { name: string }[] } }>(slug, "POST", "/mcp", { jsonrpc: "2.0", id: 1, method: "tools/list" }, { authorization: `Bearer ${first.access_token}` })).body.result.tools.map((t) => t.name); expect(shown).toContain("list_changes"); await flip("narrow"); }); });