feat(codemod): manifest handling overhaul and fixes from migrating sample dependents (#2393)

This commit is contained in:
Felix Weinberger 2026-06-30 15:01:07 +01:00 • committed by GitHub
commit e4e8b22dff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,9 @@ Codemods for migrating MCP TypeScript SDK code between major versions.
```bash
npx @modelcontextprotocol/codemod@alpha v1-to-v2 .
# or a single source file (manifest changes are reported, not applied)
npx @modelcontextprotocol/codemod@alpha v1-to-v2 src/server.ts
```
The codemod rewrites TypeScript and JavaScript source files
@ -33,8 +36,14 @@ raw shapes with `z.object()`), drop the result-schema argument from `client.requ
`@modelcontextprotocol/core`, rename
`StreamableHTTPError` → `SdkHttpError` / `IsomorphicHeaders` → `Headers`, rewrite
`SchemaInput<T>` → `StandardSchemaWithJSON.InferInput<T>`, route
`ErrorCode.{RequestTimeout,ConnectionClosed}` to `SdkErrorCode`, and rewrite `vi.mock`
/ `jest.mock` / dynamic `import()` paths.
`ErrorCode.{RequestTimeout,ConnectionClosed}` to `SdkErrorCode` (rewriting an
all-SDK condition's `instanceof ProtocolError` guard to `SdkError`, and marking
guards that mix the two enums), add `import { z } from 'zod'` when a wrap needs
it, rewrite `vi.mock`
/ `jest.mock` / dynamic `import()` paths, invert optional completable nesting
(`completable(schema.optional(), cb)` becomes `completable(schema, cb).optional()`),
and drop `Protocol` / `mergeCapabilities` (no v2 export) with an action-required
marker naming the replacement.
## `@mcp-codemod-error` markers
@ -54,7 +63,8 @@ grep -rn '@mcp-codemod-error' .
## What it does NOT cover
CJS→ESM / Node 20 pre-flight, `new Headers()` / `.get()` access rewrites, OAuth
CJS→ESM / Node 20 pre-flight, header **read** rewrites (`ctx.http?.req?.headers`
bracket access → `.get()`; sending plain-record headers keeps working), OAuth
error-class consolidation (`instanceof InvalidGrantError` → `OAuthError` +
`OAuthErrorCode`), per-scenario `SdkErrorCode` branch selection, `ctx.mcpReq.send()`
schema-arg drop, and behavioral adaptation are manual — see the