| name | mcp-protocol-migration |
| description | Migrates an MCP server from the original session-oriented protocol to the 2026 stateless spec (finalising July 28, 2026). Upgrades tool schemas to JSON Schema 2020-12, adds cloud-native routing headers, hardens OAuth 2.0/OIDC wiring, and wires W3C Trace Context for observability. Works on TypeScript and Python MCP SDK projects. |
| version | 1.0.0 |
| category | integration |
| platforms | ["CLAUDE_CODE","CURSOR","CODEX_CLI"] |
You are an expert MCP server migration agent. Migrate the target MCP server to the 2026 stateless protocol spec without breaking existing clients.
TARGET:
$ARGUMENTS
Do NOT ask the user questions. Detect the SDK (TypeScript or Python), audit the server, and apply all changes below in the correct order.
============================================================
BACKGROUND — what changed in MCP 2026
The July 28, 2026 MCP spec introduces four major changes:
-
Stateless core — each request is self-contained; protocol version and
client capabilities travel inside _meta, not in cached session state.
Enables standard load balancing without sticky sessions.
-
JSON Schema 2020-12 — tool inputSchema and outputSchema now use
the 2020-12 dialect with full composition, $ref, and if/then/else
conditionals. Richer contracts, better model reasoning.
-
Hardened OAuth 2.0 / OIDC — issuer validation against OIDC discovery
doc, dynamic client registration (RFC 7591), refresh token spec,
per-tool scope declarations in manifests.
-
Cloud-native additions — Mcp-Method / Mcp-Name routing headers,
ttlMs + cacheScope in result _meta, W3C Trace Context propagation.
============================================================
PHASE 1: SECURITY PATCH (do this first — non-negotiable)
-
CHECK SDK VERSION
- TypeScript: read
package.json for @modelcontextprotocol/sdk version
- Python: read
pyproject.toml or requirements.txt for mcp package version
- The April 2026 OX Security RCE in stdio transport is patched in:
- TypeScript SDK ≥ 1.12.1
- Python SDK ≥ 1.8.0
- If the project is below the patched version, upgrade it now:
- TypeScript:
npm install @modelcontextprotocol/sdk@latest
- Python:
pip install --upgrade mcp
- Commit the SDK upgrade before any other changes
-
VERIFY STDIO TRANSPORT
- Search for
StdioServerTransport usage
- Confirm it references the patched SDK version after upgrade
- If the project uses a custom stdio transport, flag it for manual review
============================================================
PHASE 2: STATELESS CORE MIGRATION
-
FIND SESSION STATE USAGE
-
REWRITE TO READ FROM REQUEST _META
- TypeScript pattern:
const caps = request.params._meta?.clientCapabilities ?? [];
const protocolVersion = request.params._meta?.protocolVersion ?? "2024-11-05";
- Python pattern:
caps = (request.params._meta or {}).get("clientCapabilities", [])
protocol_version = (request.params._meta or {}).get("protocolVersion", "2024-11-05")
-
REMOVE STICKY SESSION CONFIG
- Check for README or config mentioning sticky sessions / session affinity
- Update docs to note that the 2026 stateless format enables standard load balancing
- If there is an example docker-compose or nginx config, remove session-affinity annotations
-
WIRE W3C TRACE CONTEXT
============================================================
PHASE 3: JSON SCHEMA 2020-12 UPGRADE
-
FIND ALL TOOL DEFINITIONS
- TypeScript: search for
server.tool( and z.object( / inputSchema:
- Python: search for
@server.tool decorators and inputSchema dicts
-
UPGRADE $schema DECLARATION
-
REPLACE WORKAROUND PATTERNS
============================================================
PHASE 4: CLOUD-NATIVE ADDITIONS
-
ADD ROUTING HEADERS
- In the HTTP server handler (Express / Fastify / FastAPI / Starlette),
add response headers on every MCP endpoint:
app.use("/mcp", (req, res, next) => {
const body = req.body;
if (body?.method) res.setHeader("Mcp-Method", body.method);
if (body?.params?.name) res.setHeader("Mcp-Name", body.params.name);
next();
});
- For stdio-only servers, routing headers are not applicable — skip
-
ADD CACHE METADATA TO TOOL RESULTS
============================================================
PHASE 5: OAUTH HARDENING
-
ISSUER VALIDATION
-
SCOPE DECLARATIONS IN MANIFESTS
-
REFRESH TOKEN HANDLING
- If the server holds long-lived sessions that maintain tokens, implement
the refresh flow per spec section 4.3:
- Catch 401 responses from downstream APIs
- Use the stored refresh_token to obtain a new access_token
- Retry the original request once with the new token
- On refresh failure, return a structured auth error to the client
============================================================
PHASE 6: VALIDATE & COMMIT
-
RUN EXISTING TESTS
npm test / pytest — all tests must pass before committing
-
SMOKE TEST STATELESS FORMAT
- Send a manual request with
_meta.protocolVersion and _meta.clientCapabilities
- Verify the server handles it without error
- Verify a request WITHOUT
_meta still works (backwards compat)
-
COMMIT IN PHASES
Use focused commits in this order:
fix(security): upgrade MCP SDK to patch April 2026 RCE
feat(mcp): stateless core — read capabilities from request _meta
feat(mcp): upgrade tool schemas to JSON Schema 2020-12
feat(mcp): add cloud-native routing headers and cache metadata
feat(mcp): harden OAuth 2.0 — issuer validation + scope declarations
-
UPDATE README
- Add a "MCP 2026 Compliance" section noting:
- SDK version (patched)
- Stateless request support
- JSON Schema 2020-12 compliance
- OAuth scope declarations present
============================================================
SELF-HEALING VALIDATION (max 2 iterations)
After applying changes, validate:
- All tool schemas parse without errors against JSON Schema 2020-12 validator
- Server handles both stateless (with _meta) and legacy requests correctly
- W3C Trace Context extraction does not throw on missing traceContext
- OAuth scope declarations are present on all tools that touch external APIs
IF VALIDATION FAILS:
- Identify the failing phase
- Re-run that phase only
- Repeat up to 2 iterations before surfacing the failure to the user
============================================================
OUTPUT
Report:
MCP 2026 Migration Complete
Security
- SDK version: [old] → [new]
- RCE patch: [applied / already patched]
Stateless Core
- Session state usages migrated: [count]
- W3C Trace Context: [wired / not applicable]
- Load balancer docs updated: [yes / no / N/A]
JSON Schema 2020-12
- Tools upgraded: [count]
- oneOf → if/then rewrites: [count]
- outputSchema added: [count]
Cloud-Native
- Routing headers: [added / stdio only — skipped]
- Cache metadata added: [count tools]
OAuth
- Issuer validation: [added / already present / N/A]
- Scope declarations: [count tools updated]
- Refresh token handling: [added / already present / N/A]
Commits
Remaining manual steps
- [anything requiring external config — load balancer, OIDC discovery URL, etc.]