{"record":{"id":"c93cad193b540f18","repo":"rohitg00/ai-engineering-from-scratch","slug":"32022","errorCode":"-32022","errorMessage":"Unsupported protocol version","messagePattern":"Unsupported protocol version","errorType":"error_code","errorClass":"RpcProblem","httpStatus":null,"severity":"error","filePath":"phases/13-tools-and-protocols/07-building-an-mcp-server/code/main.ts","lineNumber":179,"sourceCode":"  }\n  const requestId: unknown = message.id;\n  if (requestId !== undefined && !isValidRequestId(requestId)) {\n    throw new RpcProblem(-32600, \"id must be a string or integer\");\n  }\n  const params = message.params;\n  if (!params || typeof params !== \"object\" || Array.isArray(params)) {\n    throw new RpcProblem(-32602, \"params must be an object\");\n  }\n  const meta = params._meta;\n  if (!meta || typeof meta !== \"object\" || Array.isArray(meta)) {\n    throw new RpcProblem(-32602, \"params._meta is required\");\n  }\n  const requested = meta[VERSION_KEY];\n  if (typeof requested !== \"string\") {\n    throw new RpcProblem(-32602, `${VERSION_KEY} is required`);\n  }\n  if (!SUPPORTED_VERSIONS.includes(requested)) {\n    throw new RpcProblem(-32022, \"Unsupported protocol version\", {\n      requested,\n      supported: [...SUPPORTED_VERSIONS],\n    });\n  }\n  const capabilities = meta[CAPABILITIES_KEY];\n  if (!capabilities || typeof capabilities !== \"object\" || Array.isArray(capabilities)) {\n    throw new RpcProblem(-32602, `${CAPABILITIES_KEY} is required`);\n  }\n  const clientInfo = meta[CLIENT_INFO_KEY];\n  if (\n    clientInfo !== undefined &&\n    (!clientInfo ||\n      typeof clientInfo !== \"object\" ||\n      typeof clientInfo.name !== \"string\" ||\n      typeof clientInfo.version !== \"string\")\n  ) {\n    throw new RpcProblem(-32602, `${CLIENT_INFO_KEY} is malformed`);\n  }","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/13-tools-and-protocols/07-building-an-mcp-server/code/main.ts#L161-L197","documentation":"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.","triggerScenarios":"Passing e.g. '2024-11-05' when the server only supports newer dated version strings, or a malformed version string.","commonSituations":"Client SDK pinned to an older MCP draft version than the server, or a version string copied from outdated docs.","solutions":["Read error.data.supported and send one of those exact strings","Upgrade or downgrade the client SDK so both sides share a version","If you control the server, add the requested version to SUPPORTED_VERSIONS"],"exampleFix":"// before\n_meta: { 'io.modelcontextprotocol/protocolVersion': '2024-11-05' }\n// after (match error.data.supported)\n_meta: { 'io.modelcontextprotocol/protocolVersion': '2025-06-18' }","handlingStrategy":"fallback","validationCode":"const supported = err.data?.supported ?? []; \nif (supported.includes(preferred)) retry(supported[0]);","typeGuard":null,"tryCatchPattern":"catch (e) { if (e instanceof RpcProblem && e.code === -32022) { const s = e.data?.supported?.[0]; if (s) resendWithVersion(s); } }","preventionTips":["On -32022, adopt error.data.supported[0] and cache it for the session","Pin client and server SDK versions together in one lockfile"],"tags":["mcp","protocol-version","version-mismatch"],"backgroundTag":"protocol-version-negotiation-failed","analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}