Public: anyone can read this; the crew can change it.

MCP tools to list, add, grant and remove crew SSH devices #16863

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I added one MCP tool, crewdevices, that does what the …/crew-devices API routes do. I ran tsc, bun scripts/gate.ts --explain and the tests that cover the change, and all passed. That included test/mcp-size.test.ts; the tool's description is one sentence, so I didn't touch the ceilings.

Notes

opened this

I added one MCP tool, crew_devices, that does what the …/crew-devices API routes do. I ran tsc, bun scripts/gate.ts --explain and the tests that cover the change, and all passed. That included test/mcp-size.test.ts; the tool's description is one sentence, so I didn't touch the ceilings. I did not run the full suite, so the forge's check will be the first to run it.

What it does

  • Call it as crew_devices with { repo, action: "list" | "add" | "grant" | "remove", device?, secret?, host_key? }. It needs an admin-scope token.
  • It calls the same actions as the API routes in src/actions/crew_devices.ts, so the permission checks are the same.
  • list answers { items, sessions, next_cursor }, as the GET route does. add lists a device with the repo secret that holds its key.
  • grant pins the host key, either the one you pass or the one the device shows right then. Only a site admin can grant, and an agent never can.
  • remove unlists a device and takes its grant with it.
  • Someone who isn't an admin of the repository gets not_found. A read-only token gets forbidden.
  • Any call that isn't list asks the person first when an agent holds the token. The confirmation wording is in src/crew/conversation_ask.ts and src/crew/conversation_confirm.ts.

What I chose not to do

  • No src/tty.ts command: that file doesn't exist. The terminal side is the Devices screen in src/tui/screens/crewdevices.ts, which #3470 already built on the same actions, so I added nothing there. The commit line says No door: … for that reason.
  • Own tool, not an action on an existing one: the only fit was repo_settings, whose description is already very long, so a new tool with a one-sentence description costs less.

Tests and docs

  • test/mcp-crew-devices.test.ts covers the owner's list, add and remove, the site-admin-only grant, and the refusals for other users and read-only tokens.
  • I added crew_devices to the lists in delete-tier, mixed-actions-held and mcp-forge-protocol.
  • docs/features/crew-devices.md and docs/MCP.md now mention the tool.

To try it: with an admin-scope token on a repository you administer, call crew_devices with { repo: "you/app", action: "list" }.

The first push was refused for lacking a Try: commit line, so I added an empty commit carrying it.

🤖 Generated with Claude Code

Closes #3685

4 earlier comments
commented

I added one MCP tool, crew_devices, that does what the …/crew-devices API routes do. I ran tsc, bun scripts/gate.ts --explain and the tests that cover the change, and all passed. That included test/mcp-size.test.ts; the tool's description is one sentence, so I didn't touch the ceilings. I did not run the full suite, so the forge's check will be the first to run it.

What it does

  • Call it as crew_devices with { repo, action: "list" | "add" | "grant" | "remove", device?, secret?, host_key? }. It needs an admin-scope token.
  • It calls the same actions as the API routes in src/actions/crew_devices.ts, so the permission checks are the same.
  • list answers { items, sessions, next_cursor }, as the GET route does. add lists a device with the repo secret that holds its key.
  • grant pins the host key, either the one you pass or the one the device shows right then. Only a site admin can grant, and an agent never can.
  • remove unlists a device and takes its grant with it.
  • Someone who isn't an admin of the repository gets not_found. A read-only token gets forbidden.
  • Any call that isn't list asks the person first when an agent holds the token. The confirmation wording is in src/crew/conversation_ask.ts and src/crew/conversation_confirm.ts.

What I chose not to do

  • No src/tty.ts command: that file doesn't exist. The terminal side is the Devices screen in src/tui/screens/crewdevices.ts, which #3470 already built on the same actions, so I added nothing there. The commit line says No door: … for that reason.
  • Own tool, not an action on an existing one: the only fit was repo_settings, whose description is already very long, so a new tool with a one-sentence description costs less.

Tests and docs

  • test/mcp-crew-devices.test.ts covers the owner's list, add and remove, the site-admin-only grant, and the refusals for other users and read-only tokens.
  • I added crew_devices to the lists in delete-tier, mixed-actions-held and mcp-forge-protocol.
  • docs/features/crew-devices.md and docs/MCP.md now mention the tool.

To try it: with an admin-scope token on a repository you administer, call crew_devices with { repo: "you/app", action: "list" }.

The first push was refused for lacking a Try: commit line, so I added an empty commit carrying it.

🤖 Generated with Claude Code

commented

This pull adds the crew_devices MCP tool. With {repo, action} it lists, adds, grants or removes a repository's crew SSH devices. It matches the REST …/crew-devices routes and is documented in docs/MCP.md. The check's red tests are now fixed, and I've pushed.

Three of the five failures came from this pull:

  • Held-form test: test/conversation-ask.test.ts had no entry for the new tool's held forms, so it failed. I added cases for add, grant and remove.
  • SSH switch: with the SSH switch off, the forge must not mention SSH on any page, and /agents and the agent card were showing this tool's doc. crew_devices now sets needsSwitch: "ssh" like ssh_keys, and src/core/mcp_card.ts hides it from the card while the switch is off. This fixed test/deadends.test.ts.
  • My own tests: test/mcp-crew-devices.test.ts now turns the switch on in its setup.

The NOT_YET_DESCRIBED and needsYouCard N+1 tests passed on my runs, so I changed nothing for them. I didn't run the first-page timing test.

Test runs: I ran the affected files and tsc --noEmit, and all passed.

Gate: scripts/gate.ts wanted a Replaces: line, which I put in the commit. It also flagged two likely-duplicate test helpers (call and make in test/mcp-crew-devices.test.ts). I left those as they are.

Try it: with the SSH switch on, call crew_devices with {repo, action: "list"} using an admin-scope token on a repository you administer.

🤖 Generated with Claude Code

commented

The four failing tests are fixed, and I've pushed. They are mcp-doc-matches-tools, mcp-args and mcp-door (two of its tests). I ran those three files and tsc --noEmit and they pass. I haven't run the full suite.

The cause was the same as last round. crew_devices now waits on the SSH switch, so it is absent from tools/list, the tool count and the well-known card while the switch is off. Those tests had ssh_keys hard-coded as the one tool that waits on the switch.

I added crew_devices alongside ssh_keys in:

  • the roster and count exclusions in test/mcp-doc-matches-tools.test.ts, via a shared SWITCHED list;
  • the HIDDEN list in test/mcp-args.test.ts;
  • the live-tool filter in test/mcp-door.test.ts.

The changes are in tests only. The rest of the pull is as in my last description: the crew_devices MCP tool that lists, adds, grants and removes a repository's crew SSH devices. To try it, switch SSH on and call crew_devices with {repo, action: "list"} using an admin-scope token on a repository you administer.

🤖 Generated with Claude Code

commented

crew_devices now uses needsAdminScope: true, and the cards filter on needsSwitch instead of tool names. I disagree with one part of the third point: the held asks is reachable, so I kept it and added a test. The change tests, tsc --noEmit and the gate pass; bun test was run only on the touched suites.

What changed

  • Scope check: the hand-rolled check in run is gone (src/http/mcp/tools/crew_devices.ts). A read-only token no longer sees the tool in tools/list, and a call by name answers "no tool named crew_devices".
  • Name lists: setCardTools and shownTools in src/core/mcp_card.ts take needsSwitch and filter on t.needsSwitch === undefined || ssh. The ssh_keys/crew_devices lists are gone from mcp_card.ts, mcp-door, mcp-args and mcp-doc-matches-tools. The two registry-wide tests now read needsSwitch off TOOLS, so the next switched tool needs no edit there.
  • New tests (test/mcp-crew-devices.test.ts, each fails without the change):
    • A read-only token does not see the tool in tools/list; an admin-scope token does.
    • With the SSH switch off the tool is unlisted and a call is refused. Switching it back on, the call answers.
    • The forge's agent calling add with a site admin's token is held with needs_confirm, and nothing is listed afterwards.
  • The existing read-only test now expects "no tool named crew_devices" instead of forbidden.

Where I disagree kind === "agent" in addCrewDevice, removeCrewDevice and grantCrewDevice is an agent account, which is refused every change. The forge's conversation agent is different: it speaks with a person's token, which ctx.auth.through marks. It is held for a yes, so the ASKING and ASKED_AS entries are reachable and I kept them. The held path only applies when the person is a site admin, which is how needsAdminScope already works for every tool. docs/features/crew-devices.md and the tool doc now spell out the two cases.

Not done The gate noted three similarity hints about test helpers (listedTools, call, make) that look like helpers in other test files. I left them rather than widen this pull.

I pushed once with tsc red, in the first commit (2d62b16fd). The second commit (9ae9eba93) fixes the types.

Try it Call crew_devices with {repo, action: "list"} using an admin-scope token on a repository you administer, with the SSH switch on. A read-only token or the switch off shows no tool.

commented

The crew_devices MCP tool lists, adds, grants and removes the devices a repository's crew may SSH to. The tool code is unchanged in this push. I fixed three tests that didn't account for it, and the forge's check will run again on the push.

  • test/mcp-write-scope.test.ts: crew_devices is an admin-scope tool, so it now has valid arguments in ADMIN_ARGS.
  • test/mcp-forge-protocol.test.ts: I removed crew_devices from the expected tool list. It is absent while the SSH switch is off, the same as ssh_keys.
  • test/talk-reads-not-held.test.ts: I added crew_devices to ON_PURPOSE. The forge's agent holds its read form (list) for an admin's yes, because the agent's rw token can't reach an admin-scope tool. hooks, prompts and sessions are treated the same way.

The two web-import-cost failures from the check did not reproduce here. That file passes locally, so I treated them as a timing flake and changed nothing for them.

I ran test/mcp*.test.ts (1311 pass), test/talk-reads-not-held.test.ts and test/web-import-cost.test.ts, and bun x tsc --noEmit was clean. I did not run the full suite.

gate.ts --fix changed no files. It still prints "one implementation?" similarity notes about helpers in test/mcp-crew-devices.test.ts, which this push doesn't touch. I did not merge those helpers with the similar ones in other test files.

To try it, call the MCP tool crew_devices with {repo, action: "list"} on a repository you administer, using an admin-scope token. The SSH switch must be on.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs