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

Parked opened this
Closed without merging

scout/forge:scout/5479-mcp-passkeys-list-the-caller-s-own-passk → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +125 −10
docs/MCP.md +1
@@ -109,6 +109,7 @@ for a tunnel and a forge that sleeps.
109109 | `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 |
110110 | `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 |
111111 | `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 | |
112113 | `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 |
113114 | `plan` | `{ app, issues }`: open up to 12 linked issues, all or none (see below) | yes |
114115 | `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 {
191191 import { plannerDeclines } from "../crew/autonomy.ts";
192192 import { checkStale } from "../checks/stale.ts";
193193 import { checkSummary, listActiveRuns } from "../core/runs.ts";
194 import { listPasskeys } from "../core/passkeys.ts";
194195 import { scopeAllows } from "../core/tokens.ts";
195196 import { lastOwnerSays } from "../core/orgs.ts";
196197 import { getUserByName, getUsersByIds, type User } from "../core/users.ts";
@@ -718,7 +719,7 @@ const TOOLS: readonly Tool[] = [
718719 {
719720 name: "tell",
720721 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.",
722723 inputSchema: {
723724 type: "object",
724725 properties: {
@@ -856,7 +857,7 @@ const TOOLS: readonly Tool[] = [
856857 {
857858 name: "issue",
858859 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.",
860861 inputSchema: {
861862 type: "object",
862863 properties: {
@@ -925,7 +926,7 @@ const TOOLS: readonly Tool[] = [
925926 {
926927 name: "pull",
927928 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`.",
929930 inputSchema: {
930931 type: "object",
931932 properties: {
@@ -1026,7 +1027,7 @@ const TOOLS: readonly Tool[] = [
10261027 {
10271028 name: "variant",
10281029 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`).",
10301031 inputSchema: {
10311032 type: "object",
10321033 properties: {
@@ -1527,7 +1528,7 @@ const TOOLS: readonly Tool[] = [
15271528 {
15281529 name: "now",
15291530 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.",
15311532 inputSchema: { type: "object", properties: {} },
15321533 writes: false,
15331534 run(ctx, user) {
@@ -1650,7 +1651,7 @@ const TOOLS: readonly Tool[] = [
16501651 {
16511652 name: "audit",
16521653 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.",
16541655 inputSchema: {
16551656 type: "object",
16561657 properties: {
@@ -2013,7 +2014,7 @@ const TOOLS: readonly Tool[] = [
20132014 {
20142015 name: "decisions_by",
20152016 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.",
20172018 inputSchema: {
20182019 type: "object",
20192020 properties: {
@@ -2805,7 +2806,11 @@ const TOOLS: readonly Tool[] = [
28052806 {
28062807 name: "propose_to_parent_forge",
28072808 description:
2809 <<<<<<< HEAD
2810 "Offer this forge's landed change to its parent as a pull on `child/<name>/…`.",
2811 =======
28082812 "Offer this forge's landed change to its parent as a pull on `child/<name>/…`; the same tip answers it.",
2813 >>>>>>> origin/main
28092814 inputSchema: {
28102815 type: "object",
28112816 properties: { repo: REPO_ARG },
@@ -3633,7 +3638,7 @@ const TOOLS: readonly Tool[] = [
36333638 {
36343639 name: "returns",
36353640 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.",
36373642 inputSchema: {
36383643 type: "object",
36393644 properties: {
@@ -4313,7 +4318,11 @@ const TOOLS: readonly Tool[] = [
43134318 {
43144319 name: "access",
43154320 description:
4321 <<<<<<< HEAD
4322 "Redacted log of non-browser requests to public paths, newest first, max 500. Forge admin.",
4323 =======
43164324 "Outside agents' non-browser requests to public paths: redacted, newest first, max 500. Forge admin.",
4325 >>>>>>> origin/main
43174326 inputSchema: {
43184327 type: "object",
43194328 properties: {
@@ -4392,7 +4401,11 @@ const TOOLS: readonly Tool[] = [
43924401 {
43934402 name: "flow",
43944403 description:
4404 <<<<<<< HEAD
4405 "Pipeline (forge admin): stage counts, `oldestWaiting`, `capacity`, bottleneck, `queue`, `reviewing`.",
4406 =======
43954407 "The pipeline (forge admin): stage counts, `oldestWaiting`, `capacity`, bottleneck, `queue`, `reviewing`.",
4408 >>>>>>> origin/main
43964409 inputSchema: { type: "object", properties: {} },
43974410 writes: false,
43984411 run(ctx, user) {
@@ -4586,7 +4599,7 @@ const TOOLS: readonly Tool[] = [
45864599 {
45874600 name: "cloud_accounts",
45884601 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.",
45904603 inputSchema: { type: "object", properties: {} },
45914604 // A read, but marked a write so a `ro` token never lists the accounts; it
45924605 // is a forge admin's and the audit rows name every vendor call.
@@ -4602,7 +4615,7 @@ const TOOLS: readonly Tool[] = [
46024615 {
46034616 name: "cloud_account",
46044617 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.",
46064619 inputSchema: {
46074620 type: "object",
46084621 properties: {
@@ -4657,7 +4670,11 @@ const TOOLS: readonly Tool[] = [
46574670 {
46584671 name: "quotas",
46594672 description:
4673 <<<<<<< HEAD
4674 "Per-account repo and app quotas (number or null; not enforced yet). With `key`, `value` (\"\" clears).",
4675 =======
46604676 "Per-account repo and app quotas (number or null; not enforced yet). With `key`, `value` (\"\" clears), plans.",
4677 >>>>>>> origin/main
46614678 inputSchema: {
46624679 type: "object",
46634680 properties: {
@@ -4725,6 +4742,16 @@ const TOOLS: readonly Tool[] = [
47254742 });
47264743 },
47274744 },
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 },
47284755 {
47294756 name: "email_verify",
47304757 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", () => {
274274 "cloud_account",
275275 "quotas",
276276 "signup",
277 "passkeys",
277278 "email_verify",
278279 "boards",
279280 "board_write",

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs