Skip to content

feat(cli): move squirrel mcp to MCP SDK v2 for protocol 2026-07-28 - #572

Merged
nc9 merged 2 commits into
mainfrom
claude/pub-570-mcp-sdk-v2
Oct 8, 2026
Merged

nc9 merged 2 commits into
mainfrom
claude/pub-570-mcp-sdk-v2

Conversation

@nc9

@nc9 nc9 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What changed and why

squirrel mcp moves from @modelcontextprotocol/sdk v1 (1.32.1) to the v2 SDK (@modelcontextprotocol/server 2.3.1). v1 will not support MCP revision 2026-07-28 (no initialize, server/discover), and Claude Code's v2 runtime asks stdio servers for that revision by default.

  • runMcpServer now uses serveStdio(() => createMcpServer()), which picks the era from the client's first message and serves 2026-07-28 and 2025-era clients from one process.
  • Tool registrations wrap their input shapes in z.object(...) (v2 requires Standard Schema objects; inputSchema: {} no longer typechecks). Imports moved to @modelcontextprotocol/server. Nothing under src/mcp imports v1.
  • @modelcontextprotocol/client is a dev dependency, used by tests and scripts/mcp-smoke.ts only.
  • Tests that poked the server's private _requestHandlers / _registeredTools now drive it through a real Client over a linked in-memory transport.
  • Docs: new "Supported protocol versions" section in docs/cli/mcp.mdx.
  • THIRD_PARTY_NOTICES regenerated (v2 is Apache-2.0; the v1 transitive express/hono deps are gone).

The hosted server is migrating separately.

The channel question: path (a)

squirrel channel (#571) must stay on the legacy handshake, because Claude Code refuses to register a channel server that negotiates 2026-07-28. The v2 SDK can do this. A hand-wired Server + StdioServerTransport (no serveStdio) is 2025-era only. Checked against a real stdio child on v2.3.1 (tests/mcp/protocol.test.ts, fixture tests/mcp/fixtures/legacy-only-server.ts):

  • a client in auto negotiation mode lands on the legacy era (2025-11-25), oninitialized fires, the experimental["claude/channel"] capability is advertised;
  • a client pinned to 2026-07-28 is refused ("did not offer pinned protocol version").
  • Server.notification() and oninitialized exist in v2, which is what feat(cli): add squirrel channel to push cloud audit events into Claude Code #571's sendChannelEvent and poll-loop start use.

How #571 should switch after both merge:

  1. Change its imports to Server from @modelcontextprotocol/server and StdioServerTransport from @modelcontextprotocol/server/stdio.
  2. Keep server.connect(new StdioServerTransport()). Do not use serveStdio there: it would also serve 2026-07-28.
  3. Its package.json should depend on @modelcontextprotocol/server and not re-add @modelcontextprotocol/sdk. Its tests' Client/InMemoryTransport imports move to @modelcontextprotocol/client.

Until #571 switches it still imports v1, so whichever merges second needs a trivial rebase of apps/cli/package.json and bun.lock. I did not touch the channel module. The legacy-only test in this PR will fail if a future SDK changes that behavior.

Acceptance criteria

  • squirrel mcp serves a 2026-07-28 client (no initialize, server/discover) and a 2025-11-25 client from the same binary: tests/mcp/protocol.test.ts ("serves a 2025-era client...", "serves a 2026-07-28 client with no initialize", "an auto-negotiating client lands on 2026-07-28", "both eras list identical tools", plus an in-process 2026 tool call).
  • The CLI no longer depends on @modelcontextprotocol/sdk v1: removed from apps/cli/package.json and bun.lock; grep -rn modelcontextprotocol/sdk apps/cli/src apps/cli/tests apps/cli/scripts is empty. The channel can drop it too, see path (a) above.
  • squirrel channel still negotiates the legacy handshake: not verifiable here, the channel lives in feat(cli): add squirrel channel to push cloud audit events into Claude Code #571. This PR proves the v2 SDK supports it (legacy-only test) and leaves the module alone. To be ticked once feat(cli): add squirrel channel to push cloud audit events into Claude Code #571 switches.
  • scripts/mcp-smoke.ts and tests/mcp/* pass against both protocol versions. The smoke script takes --protocol legacy|2026-07-28; both runs list the same 15 tools and list_rules returns 297. The quick_check and audit_website calls return an error in the sandbox (no outbound network), identical in both eras.
  • Documented: docs/cli/mcp.mdx, "Supported protocol versions".

Tool surface unchanged

I dumped tools/list from main (v1) and from this branch (v2) over stdio. Names, titles, descriptions, input properties, required and annotations are identical. Two wire differences come from the SDK, not from this change: the schema dialect is now JSON Schema 2020-12 ($schema was draft-07, SEP-2106), and v1's execution.taskSupport: "forbidden" marker is no longer emitted.

Verification

In apps/cli unless noted:

  • bun run typecheck: clean
  • bun test tests/mcp/server.test.ts tests/mcp/entity-tools.test.ts tests/mcp/report-tools.test.ts tests/mcp/feedback-tools.test.ts tests/mcp/cloud.test.ts: 72 pass
  • bun test tests/mcp/scopes.test.ts tests/mcp/protocol.test.ts tests/cli: 158 pass
  • bun scripts/mcp-smoke.ts https://example.com --protocol legacy and --protocol 2026-07-28: as above
  • repo root: bun run lint, bun run format:check: clean; bun run notices:generate committed
  • cd docs && make validate: all checks passed

Shell completions: no CLI surface change, none needed.

Agent skill

Does the squirrelscan agent skill need a change? No. Tool names, descriptions and schemas are unchanged and no commands or flags changed; the skill only restates those.

Risk

Runtime dependency change (SDK major). Clients that only speak the 2025-era handshake are covered by the legacy tests; 2026-07-28 clients by the pinned-era tests.

Refs #570. Deliberately not Closes: the third criterion stays open until #571 switches to the v2 Server.


Generated by Claude Code

Serve over serveStdio so one process answers 2026-07-28 clients (no initialize, server/discover) and 2025-era clients. Drop @modelcontextprotocol/sdk v1. Tool names, descriptions and schemas are unchanged apart from the JSON Schema dialect. Document supported protocol versions.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 marked this pull request as ready for review October 8, 2026 09:54
@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewed the diff. CI is green, and protocol.test.ts drives both protocol eras over a real stdio child. I couldn't run the code locally, so the points below come from reading it.

  • (low) apps/cli/src/mcp/server.ts:62: serveStdio(...) is no longer awaited, so runMcpServer returns right away. The comment above it still says "block until the transport closes". The stdio tests pass, so stdin is presumably keeping the process alive. Still, await the returned handle if serveStdio exposes a closed promise. Otherwise correct the comment, so a later process.exit after run() in commands/mcp.ts doesn't cut the server off.
  • (low) apps/cli/src/mcp/server.ts: serveStdio(() => createMcpServer()) builds a fresh server, and re-runs every register* call, per session. That's fine for stdio, which has one session. Confirm the factory isn't called per request in the 2026-07-28 era. The tool registrations are cheap, but loadAllRules should stay cached.
  • (nit) apps/cli/src/mcp/tools/audit-tools.ts:3-4: two separate import type lines come from the same module, @modelcontextprotocol/server. Merge them.
  • (nit) apps/cli/src/mcp/tools/entity-tools.ts:10: the header comment still says "the SDK's inputSchema takes zod only". That's no longer accurate, since v2 takes Standard Schema.
  • (nit) @modelcontextprotocol/server and client are pinned to exact 2.3.1, while other deps use carets. Pinning is reasonable for a fresh major, but say so in the PR or a comment so the next dependency bump doesn't miss it.

The channel path (a) fixture and the pinned-version refusal test are good coverage for #571. No security concerns: the dependency set shrinks, with express and hono removed.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Pushed d2a119d for the points below.

  • serveStdio not awaited (low): it only returns a close() handle, with no closed promise to await. v1's connect() also resolved immediately and commands/mcp.ts does nothing after runMcpServer(), so the open stdin keeps the process alive exactly as before. I corrected the misleading comment, and the stdio tests in protocol.test.ts cover the lifetime.
  • Factory per request (low): no. The SDK calls the factory once per connection, when the era is pinned (serveStdio in the SDK's stdio.mjs, the single await factory({ era })), so register* runs once per process. Noted in the code comment.
  • Duplicate imports in audit-tools.ts (nit): merged.
  • Stale comment in entity-tools.ts (nit): reworded.
  • Exact 2.3.1 pins (nit): deliberate for a fresh major, so an unreviewed minor can't change the wire behavior the legacy-only test pins. Bump them on purpose and re-run tests/mcp/protocol.test.ts.

Re-ran bun run typecheck, bun run lint, oxfmt --check and bun test tests/mcp (84 pass).

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewed the diff. The migration is mechanical and consistent: imports moved to @modelcontextprotocol/server, and every tool's inputSchema is now wrapped in z.object(...). I found no remaining v1 imports in the repo. I did not run the tests or the smoke script.

  • (low) apps/cli/src/mcp/server.ts: serveStdio(...) is neither awaited nor returned. The comment says the open stdin keeps the process alive. If serveStdio returns a promise, a startup failure becomes an unhandled rejection instead of a clean exit. Consider awaiting it, or confirm that it is synchronous.
  • (low) apps/cli/package.json: the SDK is pinned to the exact version 2.3.1, and @modelcontextprotocol/client is pinned to match. That is reasonable for a young major version. Make sure someone owns bumping both together.
  • (nit) server.ts: the new comment lines are very long. Wrap them to match the surrounding style.
  • (nit) scripts/mcp-smoke.ts: args.splice(protocolFlag, 2)[1] is terse, and a trailing --protocol with no value reports undefined as an unknown protocol. This is only a smoke script, so it's minor.

Tests: moving from private _requestHandlers access to a real Client over a linked transport is a clear improvement. Adding a legacy-only fixture and protocol.test.ts covers both protocol eras. No blocking issues found.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Both lows were already handled in d2a119d.

  • serveStdio not awaited: it is synchronous. Its declaration is serveStdio(factory, options?): StdioServerHandle, not a promise, so a startup failure can't become an unhandled rejection from this call. The comment in server.ts now says that runMcpServer returns once serving starts.
  • Exact pins: deliberate, with the rationale in my earlier comment. server and client are bumped together, and tests/mcp/protocol.test.ts is the check to re-run.

The two nits (long comment lines in server.ts, terse --protocol parsing in the smoke script) stay as they are. I'm not pushing again for them; the lead asked for a single push. They can ride along if another push is needed.

@nc9
nc9 merged commit 66f0d15 into main Oct 8, 2026
15 checks passed
@nc9
nc9 deleted the claude/pub-570-mcp-sdk-v2 branch October 8, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant