Public: anyone can read this; the crew can change it.
MCP `passkeys`: list the caller's own passkeys, with name, when added and when last used #5746
scout/forge:scout/5479-mcp-passkeys-list-the-caller-s-own-passk → main 3 commits fork
4 files
changed +125
−10
docs/MCP.md +1
| @@ -109,6 +109,7 @@ for a tunnel and a forge that sleeps. | ||
| 109 | 109 | | `confirm_wait` | `{ app, issue, blocker }`: a person says `issue` may go ahead although `blocker` closed as dropped or split; the API's confirm action, so writers only and never the crew | yes | |
| 110 | 110 | | `hold` | `{ app, pull, why?, release?, dryRun? }`: hold a pull so no rule reviews or lands it, or let it go; a person who can write, never an agent; plans unless `dryRun: false` | yes | |
| 111 | 111 | | `app_env` | `{ repo, action, name?, value?, scope? }`: `list` an app's variable names and scopes, `set` one, or `unset` it, in `all` (default), `production` or `preview`; the API's rules and errors, an admin of the repository with an admin-scope token; a value is never read back | yes | |
| 112 | | `passkeys` | no input: your own passkeys, as /settings/passkeys lists them (id, name, created, last used); never the credential or key; a person only | | | |
| 112 | 113 | | `email_verify` | no input: send the caller a new verification email, with the API's rate limit and errors; the answer never carries the link | yes | |
| 113 | 114 | | `plan` | `{ app, issues }`: open up to 12 linked issues, all or none (see below) | yes | |
| 114 | 115 | | `prompts` | `{ repo, action, kind?, token?, at?, id? }`: list, add, run or remove an app's prompt sources (Instagram), as the `…/prompts` API does; the token goes in once and is never shown; listed only for an admin-scope token, and only the repository's admin may use it | yes | |
src/http/mcp.ts +37 −10
| @@ -191,6 +191,7 @@ import { | ||
| 191 | 191 | import { plannerDeclines } from "../crew/autonomy.ts"; |
| 192 | 192 | import { checkStale } from "../checks/stale.ts"; |
| 193 | 193 | import { checkSummary, listActiveRuns } from "../core/runs.ts"; |
| 194 | import { listPasskeys } from "../core/passkeys.ts"; | |
| 194 | 195 | import { scopeAllows } from "../core/tokens.ts"; |
| 195 | 196 | import { lastOwnerSays } from "../core/orgs.ts"; |
| 196 | 197 | import { getUserByName, getUsersByIds, type User } from "../core/users.ts"; |
| @@ -718,7 +719,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 718 | 719 | { |
| 719 | 720 | name: "tell", |
| 720 | 721 | description: |
| 721 | "Tell an app's crew what should change (first line is the title). No `repo`: kept, answers a thought id.", | |
| 722 | "Tell an app's crew what should change (first line is the title). No `repo`: kept; answers a thought id.", | |
| 722 | 723 | inputSchema: { |
| 723 | 724 | type: "object", |
| 724 | 725 | properties: { |
| @@ -856,7 +857,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 856 | 857 | { |
| 857 | 858 | name: "issue", |
| 858 | 859 | description: |
| 859 | "One issue with comments, `blockedBy`, `blocks`; a crew agent sees `untrusted: true` on text by non-writers.", | |
| 860 | "An issue with comments, `blockedBy`, `blocks`; crew agents see `untrusted: true` on non-writers' text.", | |
| 860 | 861 | inputSchema: { |
| 861 | 862 | type: "object", |
| 862 | 863 | properties: { |
| @@ -925,7 +926,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 925 | 926 | { |
| 926 | 927 | name: "pull", |
| 927 | 928 | description: |
| 928 | "Read a pull: title, state, head, base; open: `mergeable`, `conflicts`, `proposal`, `checkStale`, `check`.", | |
| 929 | "A pull: title, state, head, base; open: `mergeable`, `conflicts`, `proposal`, `checkStale`, `check`.", | |
| 929 | 930 | inputSchema: { |
| 930 | 931 | type: "object", |
| 931 | 932 | properties: { |
| @@ -1026,7 +1027,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1026 | 1027 | { |
| 1027 | 1028 | name: "variant", |
| 1028 | 1029 | description: |
| 1029 | "Like or dislike one pull among its variants; a later vote replaces it; a dislike closes it (`reason`).", | |
| 1030 | "Like or dislike one pull among its variants; a later vote replaces; a dislike closes it (`reason`).", | |
| 1030 | 1031 | inputSchema: { |
| 1031 | 1032 | type: "object", |
| 1032 | 1033 | properties: { |
| @@ -1527,7 +1528,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1527 | 1528 | { |
| 1528 | 1529 | name: "now", |
| 1529 | 1530 | description: |
| 1530 | "What the crew is doing across your apps: who, on what, since when, cost; what waits on your review.", | |
| 1531 | "What the crew is doing across your apps: who, on what, cost; what waits on your review.", | |
| 1531 | 1532 | inputSchema: { type: "object", properties: {} }, |
| 1532 | 1533 | writes: false, |
| 1533 | 1534 | run(ctx, user) { |
| @@ -1650,7 +1651,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1650 | 1651 | { |
| 1651 | 1652 | name: "audit", |
| 1652 | 1653 | description: |
| 1653 | "Who can do what in every app you can see, from each contract.json: resource × verb, yes, own or no.", | |
| 1654 | "Who can do what in every app you can see: resource × verb, yes, own or no.", | |
| 1654 | 1655 | inputSchema: { |
| 1655 | 1656 | type: "object", |
| 1656 | 1657 | properties: { |
| @@ -2013,7 +2014,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 2013 | 2014 | { |
| 2014 | 2015 | name: "decisions_by", |
| 2015 | 2016 | description: |
| 2016 | "Who decides a repository's parked hand-over cards: `me`, `decider`, `decider_tell`. No `by` reads it.", | |
| 2017 | "Who decides a repository's parked hand-over cards: `me`, `decider`, `decider_tell`; no `by` reads.", | |
| 2017 | 2018 | inputSchema: { |
| 2018 | 2019 | type: "object", |
| 2019 | 2020 | properties: { |
| @@ -2805,7 +2806,11 @@ const TOOLS: readonly Tool[] = [ | ||
| 2805 | 2806 | { |
| 2806 | 2807 | name: "propose_to_parent_forge", |
| 2807 | 2808 | description: |
| 2809 | <<<<<<< HEAD | |
| 2810 | "Offer this forge's landed change to its parent as a pull on `child/<name>/…`.", | |
| 2811 | ======= | |
| 2808 | 2812 | "Offer this forge's landed change to its parent as a pull on `child/<name>/…`; the same tip answers it.", |
| 2813 | >>>>>>> origin/main | |
| 2809 | 2814 | inputSchema: { |
| 2810 | 2815 | type: "object", |
| 2811 | 2816 | properties: { repo: REPO_ARG }, |
| @@ -3633,7 +3638,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 3633 | 3638 | { |
| 3634 | 3639 | name: "returns", |
| 3635 | 3640 | description: |
| 3636 | "What the crew's tokens bought over `days` (1–90, default 7): dollars, runs, landed, cost per change.", | |
| 3641 | "What the crew's tokens bought over `days` (1–90, default 7): dollars, runs, landed, cost each.", | |
| 3637 | 3642 | inputSchema: { |
| 3638 | 3643 | type: "object", |
| 3639 | 3644 | properties: { |
| @@ -4313,7 +4318,11 @@ const TOOLS: readonly Tool[] = [ | ||
| 4313 | 4318 | { |
| 4314 | 4319 | name: "access", |
| 4315 | 4320 | description: |
| 4321 | <<<<<<< HEAD | |
| 4322 | "Redacted log of non-browser requests to public paths, newest first, max 500. Forge admin.", | |
| 4323 | ======= | |
| 4316 | 4324 | "Outside agents' non-browser requests to public paths: redacted, newest first, max 500. Forge admin.", |
| 4325 | >>>>>>> origin/main | |
| 4317 | 4326 | inputSchema: { |
| 4318 | 4327 | type: "object", |
| 4319 | 4328 | properties: { |
| @@ -4392,7 +4401,11 @@ const TOOLS: readonly Tool[] = [ | ||
| 4392 | 4401 | { |
| 4393 | 4402 | name: "flow", |
| 4394 | 4403 | description: |
| 4404 | <<<<<<< HEAD | |
| 4405 | "Pipeline (forge admin): stage counts, `oldestWaiting`, `capacity`, bottleneck, `queue`, `reviewing`.", | |
| 4406 | ======= | |
| 4395 | 4407 | "The pipeline (forge admin): stage counts, `oldestWaiting`, `capacity`, bottleneck, `queue`, `reviewing`.", |
| 4408 | >>>>>>> origin/main | |
| 4396 | 4409 | inputSchema: { type: "object", properties: {} }, |
| 4397 | 4410 | writes: false, |
| 4398 | 4411 | run(ctx, user) { |
| @@ -4586,7 +4599,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 4586 | 4599 | { |
| 4587 | 4600 | name: "cloud_accounts", |
| 4588 | 4601 | description: |
| 4589 | "Cloud accounts (forge admin): each provider token's use, verification, write permission, calls today.", | |
| 4602 | "Cloud accounts (forge admin): each token's use, verification, write permission, calls today.", | |
| 4590 | 4603 | inputSchema: { type: "object", properties: {} }, |
| 4591 | 4604 | // A read, but marked a write so a `ro` token never lists the accounts; it |
| 4592 | 4605 | // is a forge admin's and the audit rows name every vendor call. |
| @@ -4602,7 +4615,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 4602 | 4615 | { |
| 4603 | 4616 | name: "cloud_account", |
| 4604 | 4617 | description: |
| 4605 | "Change a cloud account (admin token): `verb` attach, verify, rotate, rename, remove, allow_writes, audit.", | |
| 4618 | "Change a cloud account (admin): `verb` attach, verify, rotate, rename, remove, allow_writes, audit.", | |
| 4606 | 4619 | inputSchema: { |
| 4607 | 4620 | type: "object", |
| 4608 | 4621 | properties: { |
| @@ -4657,7 +4670,11 @@ const TOOLS: readonly Tool[] = [ | ||
| 4657 | 4670 | { |
| 4658 | 4671 | name: "quotas", |
| 4659 | 4672 | description: |
| 4673 | <<<<<<< HEAD | |
| 4674 | "Per-account repo and app quotas (number or null; not enforced yet). With `key`, `value` (\"\" clears).", | |
| 4675 | ======= | |
| 4660 | 4676 | "Per-account repo and app quotas (number or null; not enforced yet). With `key`, `value` (\"\" clears), plans.", |
| 4677 | >>>>>>> origin/main | |
| 4661 | 4678 | inputSchema: { |
| 4662 | 4679 | type: "object", |
| 4663 | 4680 | properties: { |
| @@ -4725,6 +4742,16 @@ const TOOLS: readonly Tool[] = [ | ||
| 4725 | 4742 | }); |
| 4726 | 4743 | }, |
| 4727 | 4744 | }, |
| 4745 | { | |
| 4746 | name: "passkeys", | |
| 4747 | description: "Your passkeys: name, added, last used.", | |
| 4748 | inputSchema: { type: "object", properties: {} }, | |
| 4749 | writes: false, | |
| 4750 | async run(ctx, user) { | |
| 4751 | if (user.kind === "agent") return bad("forbidden", "an agent has no passkeys"); | |
| 4752 | return good({ items: listPasskeys(ctx.app.db, user.id) }); | |
| 4753 | }, | |
| 4754 | }, | |
| 4728 | 4755 | { |
| 4729 | 4756 | name: "email_verify", |
| 4730 | 4757 | description: "Send yourself a new verification link.", |
test/mcp-passkeys.test.ts added +86
| @@ -0,0 +1,86 @@ | ||
| 1 | /** The `passkeys` tool lists the caller's own passkeys, and nothing of the credential. */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { addPasskey } from "../src/core/passkeys.ts"; | |
| 8 | import { createToken } from "../src/core/tokens.ts"; | |
| 9 | import { createUser } from "../src/core/users.ts"; | |
| 10 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 11 | import { quietLogs } from "./helpers/globals.ts"; | |
| 12 | ||
| 13 | quietLogs(); | |
| 14 | ||
| 15 | let dir: string; | |
| 16 | let app: App; | |
| 17 | let servers: Servers; | |
| 18 | let ann = ""; | |
| 19 | let bob = ""; | |
| 20 | let bot = ""; | |
| 21 | let id = 1; | |
| 22 | ||
| 23 | const tool = async (token: string, name: string) => { | |
| 24 | const res = await fetch(`${servers.url}/mcp`, { | |
| 25 | method: "POST", | |
| 26 | headers: { | |
| 27 | "content-type": "application/json", | |
| 28 | accept: "application/json, text/event-stream", | |
| 29 | authorization: `Bearer ${token}`, | |
| 30 | }, | |
| 31 | body: JSON.stringify({ jsonrpc: "2.0", id: id++, method: "tools/call", params: { name, arguments: {} } }), | |
| 32 | }); | |
| 33 | const body = (await res.json()) as any; | |
| 34 | const text: string = body.result.content[0].text; | |
| 35 | return { text, error: body.result.isError === true, value: body.result.isError ? undefined : JSON.parse(text) }; | |
| 36 | }; | |
| 37 | ||
| 38 | const key = { kty: "EC", crv: "P-256", x: "xx", y: "yy" } as any; | |
| 39 | const cred = (n: string) => ({ id: `cred-secret-${n}`, alg: -7, key, signCount: 0 }) as any; | |
| 40 | ||
| 41 | beforeAll(async () => { | |
| 42 | dir = await mkdtemp(join(tmpdir(), "forge-mcp-passkeys-")); | |
| 43 | app = createApp({ dataDir: dir, port: 0 }); | |
| 44 | servers = await serve(app); | |
| 45 | const mk = async (username: string, agent = false) => { | |
| 46 | const u = await createUser(app.db, { | |
| 47 | origin: "seed", trusted: true, username, email: `${username}@f.dev`, password: "a-good-passphrase", | |
| 48 | }); | |
| 49 | if (!u.ok) throw new Error(u.error); | |
| 50 | if (agent) app.db.query("UPDATE user SET is_agent = 1 WHERE id = ?1").run(u.value.id); | |
| 51 | return u.value; | |
| 52 | }; | |
| 53 | const a = await mk("ann"); | |
| 54 | const b = await mk("bob"); | |
| 55 | const c = await mk("botty", true); | |
| 56 | addPasskey(app.db, a.id, "laptop", cred("1")); | |
| 57 | addPasskey(app.db, a.id, "phone", cred("2")); | |
| 58 | addPasskey(app.db, b.id, "bobs-key", cred("3")); | |
| 59 | ann = createToken(app.db, a.id, "t", "ro").token; | |
| 60 | bob = createToken(app.db, b.id, "t", "ro").token; | |
| 61 | bot = createToken(app.db, c.id, "t", "ro").token; | |
| 62 | }, 30_000); | |
| 63 | ||
| 64 | afterAll(async () => { | |
| 65 | servers.stop(); | |
| 66 | app.close(); | |
| 67 | await rm(dir, { recursive: true, force: true }); | |
| 68 | }); | |
| 69 | ||
| 70 | test("a person with two passkeys sees both, without the credential", async () => { | |
| 71 | const r = await tool(ann, "passkeys"); | |
| 72 | expect(r.value.items.map((p: any) => p.name)).toEqual(["laptop", "phone"]); | |
| 73 | expect(Object.keys(r.value.items[0]).sort()).toEqual(["createdAt", "id", "lastUsedAt", "name"]); | |
| 74 | expect(r.text).not.toContain("cred-secret"); | |
| 75 | expect(r.text).not.toContain("kty"); | |
| 76 | }); | |
| 77 | ||
| 78 | test("another person's passkeys are never listed", async () => { | |
| 79 | const r = await tool(bob, "passkeys"); | |
| 80 | expect(r.value.items.map((p: any) => p.name)).toEqual(["bobs-key"]); | |
| 81 | }); | |
| 82 | ||
| 83 | test("an agent token is refused", async () => { | |
| 84 | const r = await tool(bot, "passkeys"); | |
| 85 | expect(r.error).toBe(true); | |
| 86 | }); |
test/mcp.test.ts +1
| @@ -274,6 +274,7 @@ describe("the forge over MCP", () => { | ||
| 274 | 274 | "cloud_account", |
| 275 | 275 | "quotas", |
| 276 | 276 | "signup", |
| 277 | "passkeys", | |
| 277 | 278 | "email_verify", |
| 278 | 279 | "boards", |
| 279 | 280 | "board_write", |
new above
offline