rohitg00/ai-engineering-from-scratch · error · RpcProblem

-32022

-32022

Error message

Unsupported protocol version

What it means

The requested MCP protocol version string is not in SUPPORTED_VERSIONS, so the server refuses the request with the custom code -32022 and reports the requested and supported versions in the error data. Version negotiation failed before any handler ran.

Source

Thrown at phases/13-tools-and-protocols/07-building-an-mcp-server/code/main.ts:179

  }
  const requestId: unknown = message.id;
  if (requestId !== undefined && !isValidRequestId(requestId)) {
    throw new RpcProblem(-32600, "id must be a string or integer");
  }
  const params = message.params;
  if (!params || typeof params !== "object" || Array.isArray(params)) {
    throw new RpcProblem(-32602, "params must be an object");
  }
  const meta = params._meta;
  if (!meta || typeof meta !== "object" || Array.isArray(meta)) {
    throw new RpcProblem(-32602, "params._meta is required");
  }
  const requested = meta[VERSION_KEY];
  if (typeof requested !== "string") {
    throw new RpcProblem(-32602, `${VERSION_KEY} is required`);
  }
  if (!SUPPORTED_VERSIONS.includes(requested)) {
    throw new RpcProblem(-32022, "Unsupported protocol version", {
      requested,
      supported: [...SUPPORTED_VERSIONS],
    });
  }
  const capabilities = meta[CAPABILITIES_KEY];
  if (!capabilities || typeof capabilities !== "object" || Array.isArray(capabilities)) {
    throw new RpcProblem(-32602, `${CAPABILITIES_KEY} is required`);
  }
  const clientInfo = meta[CLIENT_INFO_KEY];
  if (
    clientInfo !== undefined &&
    (!clientInfo ||
      typeof clientInfo !== "object" ||
      typeof clientInfo.name !== "string" ||
      typeof clientInfo.version !== "string")
  ) {
    throw new RpcProblem(-32602, `${CLIENT_INFO_KEY} is malformed`);
  }

View on GitHub (pinned to 39ea8a1c6d)

Solutions

  1. Read error.data.supported and send one of those exact strings
  2. Upgrade or downgrade the client SDK so both sides share a version
  3. If you control the server, add the requested version to SUPPORTED_VERSIONS

Example fix

// before
_meta: { 'io.modelcontextprotocol/protocolVersion': '2024-11-05' }
// after (match error.data.supported)
_meta: { 'io.modelcontextprotocol/protocolVersion': '2025-06-18' }
Defensive patterns

Strategy: fallback

Validate before calling

const supported = err.data?.supported ?? []; 
if (supported.includes(preferred)) retry(supported[0]);

Try / catch

catch (e) { if (e instanceof RpcProblem && e.code === -32022) { const s = e.data?.supported?.[0]; if (s) resendWithVersion(s); } }

Prevention

When it happens

Trigger: Passing e.g. '2024-11-05' when the server only supports newer dated version strings, or a malformed version string.

Common situations: Client SDK pinned to an older MCP draft version than the server, or a version string copied from outdated docs.

Related errors


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/c93cad193b540f18. Report an issue: GitHub.