Mcp protocol migration

From tinh2/skills-hub-registry · View interactive version

Mcp protocol migration is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. 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

How to use this skill

Skill file

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:

  1. 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.

  1. 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.

  1. 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.

  1. 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)

============================================================

  1. CHECK SDK VERSION
  1. VERIFY STDIO TRANSPORT

============================================================

PHASE 2: STATELESS CORE MIGRATION

============================================================

  1. FIND SESSION STATE USAGE

```typescript

// OLD — reads capabilities from cached session

const caps = server.session?.clientCapabilities;

```

```python

# OLD — reads capabilities from cached session

caps = server.session.client_capabilities

```

  1. REWRITE TO READ FROM REQUEST _META

```typescript

// NEW — read from request _meta

const caps = request.params._meta?.clientCapabilities ?? [];

const protocolVersion = request.params._meta?.protocolVersion ?? "2024-11-05";

```

```python

# NEW — read from request _meta

caps = (request.params._meta or {}).get("clientCapabilities", [])

protocol_version = (request.params._meta or {}).get("protocolVersion", "2024-11-05")

```

  1. REMOVE STICKY SESSION CONFIG
  1. WIRE W3C TRACE CONTEXT

```typescript

import { context, propagation } from "@opentelemetry/api";

const traceParent = request.params._meta?.traceContext?.traceparent;

if (traceParent) {

const carrier = { traceparent: traceParent };

propagation.extract(context.active(), carrier);

}

```

============================================================

PHASE 3: JSON SCHEMA 2020-12 UPGRADE

============================================================

  1. FIND ALL TOOL DEFINITIONS
  1. UPGRADE $schema DECLARATION

```json

"$schema": "https://json-schema.org/draft/2020-12/schema"

```

  1. REPLACE WORKAROUND PATTERNS

```json

// BEFORE (Draft 7 workaround)

"oneOf": [

{ "required": ["githubRepo"] },

{ "required": ["linearTeamId"] }

]

// AFTER (2020-12 conditional)

"if": { "properties": { "tracker": { "const": "linear" } } },

"then": { "required": ["linearTeamId"] },

"else": { "required": ["githubRepo"] }

```

  1. ADD outputSchema DECLARATIONS

```json

"outputSchema": {

"$schema": "https://json-schema.org/draft/2020-12/schema",

"type": "object",

"properties": {

"content": { "type": "array" }

}

}

```

  1. VALIDATE SCHEMAS

============================================================

PHASE 4: CLOUD-NATIVE ADDITIONS

============================================================

  1. ADD ROUTING HEADERS

add response headers on every MCP endpoint:

```typescript

// TypeScript / Express

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();

});

```

  1. ADD CACHE METADATA TO TOOL RESULTS

add _meta to the result:

```typescript

return {

content: [...],

_meta: {

ttlMs: 300_000, // 5 minutes

cacheScope: "session" // or "global" for user-agnostic results

}

};

```

============================================================

PHASE 5: OAUTH HARDENING

============================================================

  1. ISSUER VALIDATION

```typescript

const discovery = await fetch(${issuerUrl}/.well-known/openid-configuration);

const { issuer } = await discovery.json();

if (token.iss !== issuer) throw new Error("Token issuer mismatch");

```

  1. SCOPE DECLARATIONS IN MANIFESTS

```json

{

"name": "create_pr",

"requiredScopes": ["repo:write", "pull_request:write"]

}

```

  1. REFRESH TOKEN HANDLING

the refresh flow per spec section 4.3:

============================================================

PHASE 6: VALIDATE & COMMIT

============================================================

  1. RUN EXISTING TESTS
  1. SMOKE TEST STATELESS FORMAT
  1. 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

```

  1. UPDATE README

============================================================

SELF-HEALING VALIDATION (max 2 iterations)

============================================================

After applying changes, validate:

  1. All tool schemas parse without errors against JSON Schema 2020-12 validator
  2. Server handles both stateless (with _meta) and legacy requests correctly
  3. W3C Trace Context extraction does not throw on missing traceContext
  4. OAuth scope declarations are present on all tools that touch external APIs

IF VALIDATION FAILS:

============================================================

OUTPUT

============================================================

Report:

MCP 2026 Migration Complete

Security

Stateless Core

JSON Schema 2020-12

Cloud-Native

OAuth

Commits

Remaining manual steps

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.