Skip to content

Migrate MCP server to SDK v2 (@modelcontextprotocol/server) and serve protocol 2026-07-28 #262

Backlog

Description

@mobileskyfi

Summary

Move the MCP server from @modelcontextprotocol/sdk v1 (1.32.2 installed, the final v1 line, which only goes up to protocol 2025-11-25) to the v2 split packages (@modelcontextprotocol/server / client / core, currently 2.4.0). Then opt in to protocol revision 2026-07-28. v2 is required for the Skills extension (#261 layer 2, via @modelcontextprotocol/server/ext/skills) and for future protocol features such as server/discover, cache hints, and subscriptions/listen.

Client compatibility

Upgrading the SDK does not break existing clients.

  • Step A (package swap): v2 puts nothing from 2026-07-28 on the wire by default. A server built and connected the v1 way still speaks the 2025 protocol exactly as before.
  • Step B (opt in to 2026): the v2 entry points serve both eras on one endpoint by default.
    • serveStdio(() => buildServer()) (stdio): the opening exchange decides each connection's era.
    • createMcpHandler(factory) (HTTP, web-standard fetch): defaults to legacy: 'stateless'.
    • Only { legacy: 'reject' } would drop 2025 clients, and we won't use it.
  • Caveat: the 2026 era has no server→client request channel. Rosetta doesn't use sampling or elicitation, so this doesn't affect us.

Upstream guides: docs/migration/upgrade-to-v2.md, which is assembled from skills/mcp-typescript-sdk-upgrade-to-v2/, and docs/migration/support-2026-07-28.md.

Upstream gotcha (typescript-sdk #2977): the codemod's TL;DR ends at a server that only speaks the 2025 era. Step B is a separate, explicit change. Don't stop after the codemod.

Rosetta's current SDK surface

The surface is small, all in one file (src/mcp.ts, about 1.8k lines) plus two tests.

Use Location v2 change
McpServer src/mcp.ts:340 (dynamic import) @modelcontextprotocol/server
z from zod/v3 src/mcp.ts:341 Zod v3 is no longer supported. Switch to zod v4 (zod ^4.3.6 is already in package.json, so only the /v3 subpath import changes)
14 tools with raw-shape inputSchema: { … } registerTool calls Raw shapes are deprecated. Wrap them in z.object({…}), which the codemod does
about 20 registerTool / registerResource calls src/mcp.ts registerResource now needs a metadata argument (we already pass one). Check CallToolResult return annotations against the new outputSchema typing
WebStandardStreamableHTTPServerTransport + types.js src/mcp.ts:1685-1810 Sessionful (sessionIdGenerator: randomUUID, with a transports Map). Step B means moving to createMcpHandler, which is stateless per request. Our tools are read-only queries, so the per-session state isn't needed. That would delete the session map
StdioServerTransport src/mcp.ts:1815-1820 Step A: @modelcontextprotocol/server/stdio. Step B: serveStdio(() => buildServer())
Test clients src/mcp-stdio-client.test.ts, src/install.test.ts @modelcontextprotocol/client and client/stdio. Add tests that cover both eras (versionNegotiation: { mode: 'auto' } and the legacy default)

Structural change: v2's serveStdio and createMcpHandler take a factory that builds a fresh McpServer. Today rosetta builds one module-level server and registers everything at top level. That code needs to move into a buildServer() function. Registration is cheap, but the per-skill resource loop (listSkills()) and any other DB reads at registration time should be cached outside the factory.

Risks / checks

  • bun build --compile (scripts/build-release.ts:87): confirm the v2 packages (ESM .mjs / .cjs flat dist) bundle into the release binaries for every target. Do the same for the OCI image and the /app integration harness.
  • The v2 runtime floor is Node 20+. Bun is fine, but confirm the documented bunx / npx install paths still work.
  • Upstream v2 is still moving (skills-extension fixes are open: #3066, #3102, #3229, #3242). Pin exact versions and don't use ^, at least at first.
  • tui-mcp-parity: nothing should change for the TUI, since it uses the query core and not the SDK.
  • Release smoke (Release OCI smoke: real MCP session on both amd64 and arm64 images before tag promotion #246, full MCP session on amd64 and arm64) must pass for both a legacy and a modern client.

Suggested sequencing

  1. PR 1 (Step A): package swap, zod v4, z.object wrapping, import paths, test client. No wire change, so the risk is low.
  2. PR 2 (Step B): buildServer() factory, serveStdio, createMcpHandler (drops the session map), and dual-era tests.
  3. Then: Expose skills using the MCP Skills extension resource layout (skill://<name>/SKILL.md) #261 layer 2 (Skills extension) becomes ordinary wiring.

Status

Scoping only. Not agent-ready. Effort estimate: PR 1 is small, about half a day. PR 2 is medium, mostly the factory refactor and the HTTP path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions