Skip to content

SDK v2 migration mechanics (behavior-neutral, versionNegotiation: 'legacy') #1624

Description

@cliffhall

Stack: SDK V2 + New Spec — 1 of 10 (foundation; do this first).

Migrate the codebase from @modelcontextprotocol/sdk@1.29 to SDK v2, keeping behavior identical against today's (legacy) servers. This is the behavior-neutral base that unblocks every other card in the stack: we're using SDK v2 underneath, with versionNegotiation: 'legacy' so nothing 2026-era goes on the wire yet.

Scope

  • Package split: @modelcontextprotocol/sdk@modelcontextprotocol/client (Client, transports, OAuth) + @modelcontextprotocol/core (public Zod schemas); stdio transport moves to @modelcontextprotocol/client/stdio (root barrel stays browser-safe). WebSocketClientTransport is removed.
  • Run the codemod (npx @modelcontextprotocol/codemod@beta v1-to-v2 .) per client, then hand-fix the rest.
  • Zod 3 → 4 (^4.2.0).
  • Handlers take method strings, not schemas: client.setRequestHandler('elicitation/create', …). Spec methods drop result schemas from request()/callTool(); the raw "send request" path must pass an explicit ResultSchema from core.
  • Error taxonomy rename: McpErrorProtocolError; new SdkError (string codes: RequestTimeout, ConnectionClosed, EraNegotiationFailed, …); StreamableHTTPErrorSdkHttpError (.status). Unknown-tool calls now reject with -32602 instead of resolving isError: true.
  • Elicitation mode discriminant: branch on params.mode === 'url' vs. form; ElicitResult.content values strictly string | number | boolean | string[].
  • Protocol base class no longer exported; use client.fallbackRequestHandler for arbitrary inbound requests.
  • Tasks note: requestor tasks currently ride client.experimental.tasks.* (inspectorClient.ts:listRequestorTasks). That surface changes under v2 — keep legacy tasks working here; the modern redesign is card 8.
  • Set versionNegotiation: { mode: 'legacy' } explicitly so this card changes no wire behavior.

Key files

core/mcp/inspectorClient.ts, core/mcp/remote/**, core/auth/**, clients/web|cli|tui/package.json, everywhere importing @modelcontextprotocol/sdk/*.

Acceptance

  • All three clients behave exactly as today against existing legacy servers.
  • npm run ci green (format, lint, build, per-file ≥90 coverage, smoke, storybook).

Ref: specification/v2_new_spec_impact.md §8.1, §9.5(1).

Metadata

Metadata

Assignees

Labels

v2Issues and PRs for v2

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions