{"record":{"id":"ef8e10a9c6466cf1","repo":"different-ai/openwork","slug":"mcp-initialize","errorCode":"MCP_INITIALIZE","errorMessage":"Initialize response JSON-RPC id did not match the request","messagePattern":"Initialize response JSON-RPC id did not match the request","errorType":"exception","errorClass":"ProbeFailure","httpStatus":null,"severity":"error","filePath":"packages/enterprise-mcp-mock-server/src/testing/probe.ts","lineNumber":755,"sourceCode":"    if (initializeRawResponse.status === 401 || initializeRawResponse.status === 403) {\n      throw new ProbeFailure(\n        \"AUTH_RESOURCE_VALIDATION\",\n        initializeRawResponse.status === 403 ? \"oauth_insufficient_scope\" : \"oauth_wrong_audience\",\n        `MCP resource rejected the synthetic access token with HTTP ${initializeRawResponse.status}`,\n      )\n    }\n    const initializeResponse = await expectOk(initializeRawResponse, \"MCP_INITIALIZE\")\n    sessionId = initializeResponse.headers.get(\"mcp-session-id\") ?? \"\"\n    negotiatedProtocolHeader = initializeResponse.headers.get(\"mcp-protocol-version\") ?? scenario.protocol.version\n    const initializeEnvelope = await parseRpc(initializeResponse, \"MCP_INITIALIZE\")\n    if (initializeEnvelope.error) {\n      const versionEvidence = z.object({ supportedVersions: z.array(z.string()).min(1) }).safeParse(initializeEnvelope.error.data)\n      throw versionEvidence.success || initializeEnvelope.error.message === \"Unsupported MCP protocol version\"\n        ? new ProbeFailure(\"MCP_VERSION\", \"mcp_version\", initializeEnvelope.error.message)\n        : new ProbeFailure(\"MCP_INITIALIZE\", \"mcp_initialize\", initializeEnvelope.error.message)\n    }\n    if (initializeEnvelope.id !== 1) {\n      throw new ProbeFailure(\"MCP_INITIALIZE\", \"mcp_initialize\", \"Initialize response JSON-RPC id did not match the request\")\n    }\n    const initialize = parseAt(\n      initializeResultSchema,\n      initializeEnvelope.result,\n      \"MCP_INITIALIZE\",\n      \"mcp_initialize\",\n      \"Initialize result did not match the required shape\",\n    )\n    if (initialize.protocolVersion !== scenario.protocol.version) {\n      throw new ProbeFailure(\"MCP_VERSION\", \"mcp_version\", \"Server selected an unexpected MCP protocol version\")\n    }\n    mutable.negotiatedProtocolVersion = initialize.protocolVersion\n    if (scenario.protocol.requireSession && !sessionId) {\n      throw new ProbeFailure(\"MCP_INITIALIZE\", \"mcp_initialize\", \"Initialize response omitted required MCP-Session-Id\")\n    }\n    recordPassed(phases, \"MCP_INITIALIZE\", startedAt, \"MCP version, capabilities, and session negotiated\")\n\n    const sessionHeaders = {","sourceCodeStart":737,"sourceCodeEnd":773,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/enterprise-mcp-mock-server/src/testing/probe.ts#L737-L773","documentation":"This ProbeFailure is thrown during the initialize handshake of the enterprise MCP mock-server probe when the JSON-RPC response envelope's id does not equal the request id (1). The probe requires strict request/response correlation; a mismatched id means the response came from a different (or fabricated) request, so the probe aborts the MCP_INITIALIZE phase rather than trusting the payload. It is distinct from MCP_VERSION failures, which handle legitimate initialize errors.","triggerScenarios":"An HTTP 200 initialize response whose JSON body has an id other than 1 — e.g. the server echoes id: null, omits id, or returns the id of an unrelated notification/request.","commonSituations":"Proxy or gateway that rewrites or strips JSON-RPC ids; a server that batches or multiplexes responses out of order and pairs them incorrectly; middleware returning a cached response for a different request; a hand-rolled MCP server that hardcodes the response id.","solutions":["Fix the MCP server/gateway to echo the request id verbatim in the initialize response","Remove any caching or response-rewriting middleware between the probe and the MCP endpoint","If the server batches responses, correlate responses by id before returning them to the client","Run the probe directly against the endpoint (bypass proxies) to isolate where the id is altered"],"exampleFix":"// before (server)\nres.json({ jsonrpc: \"2.0\", id: null, result: initializeResult })\n// after (server)\nres.json({ jsonrpc: \"2.0\", id: request.body.id, result: initializeResult })","handlingStrategy":"validation","validationCode":"const env = rpcEnvelopeSchema.safeParse(body)\nif (!env.success || env.data.id !== 1) throw new Error(\"initialize response id mismatch\")","typeGuard":"function isInitializeResponseForRequest1(e: { id?: unknown }): e is { id: number } {\n  return typeof e.id === \"number\" && e.id === 1\n}","tryCatchPattern":"try {\n  await probeEnterpriseMcpMockServer(scenario)\n} catch (e) {\n  if (e instanceof ProbeFailure && e.code === \"MCP_INITIALIZE\") {\n    console.error(\"Initialize handshake failed:\", e.message)\n  }\n}","preventionTips":["Echo the JSON-RPC request id verbatim in every server response","Avoid caching or rewriting JSON-RPC traffic in proxies","Unit-test the server's initialize response shape including id"],"tags":["json-rpc","mcp","initialize","id-mismatch"],"backgroundTag":"jsonrpc-id-mismatch","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}