{"record":{"id":"9feab5f293ab2e3f","repo":"different-ai/openwork","slug":"invalid-jsonrpc-envelope","errorCode":"invalid_jsonrpc_envelope","errorMessage":"invalid_jsonrpc_envelope","messagePattern":"invalid_jsonrpc_envelope","errorType":"error_code","errorClass":"SafeProbeFailure","httpStatus":null,"severity":"error","filePath":"apps/server/src/agent-context-cloud-probe.ts","lineNumber":529,"sourceCode":"      dispatch();\n      continue;\n    }\n    if (line.startsWith(\":\")) continue;\n    const colon = line.indexOf(\":\");\n    const field = colon < 0 ? line : line.slice(0, colon);\n    const rawValue = colon < 0 ? \"\" : line.slice(colon + 1);\n    const value = rawValue.startsWith(\" \") ? rawValue.slice(1) : rawValue;\n    if (field === \"event\") event = value;\n    if (field === \"data\") data.push(value);\n  }\n  dispatch();\n  if (messages.length !== 1) throw new SafeProbeFailure(\"invalid_json\");\n  return messages[0];\n}\n\nfunction parseJsonRpcResult(payload: unknown, requestId: string): Record<string, unknown> {\n  if (!isRecord(payload) || payload.jsonrpc !== \"2.0\") {\n    throw new SafeProbeFailure(\"invalid_jsonrpc_envelope\");\n  }\n  if (Object.hasOwn(payload, \"error\")) throw new SafeProbeFailure(\"jsonrpc_error\");\n  if (payload.id !== requestId) throw new SafeProbeFailure(\"request_id_mismatch\");\n  if (!isRecord(payload.result)) throw new SafeProbeFailure(\"invalid_jsonrpc_envelope\");\n  return payload.result;\n}\n\nfunction requireSupportedProtocolVersion(initializeResult: Record<string, unknown>): void {\n  const version = initializeResult.protocolVersion;\n  if (typeof version !== \"string\" || version.length === 0 || version.length > MAX_PROTOCOL_HEADER_LENGTH) {\n    throw new SafeProbeFailure(\"invalid_jsonrpc_envelope\");\n  }\n  if (version !== MCP_PROTOCOL_VERSION) throw new SafeProbeFailure(\"unsupported_protocol_version\");\n}\n\nfunction validateCatalog(rpcResult: Record<string, unknown>): { toolIds: string[]; totalToolCount: number } {\n  if (rpcResult.nextCursor !== undefined && rpcResult.nextCursor !== null) {\n    throw new SafeProbeFailure(\"pagination_unsupported\");","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/server/src/agent-context-cloud-probe.ts#L511-L547","documentation":"parseJsonRpcResult validates the decoded JSON-RPC payload envelope and throws SafeProbeFailure(\"invalid_jsonrpc_envelope\") at line 529 when the payload is not an object or its 'jsonrpc' field is not exactly \"2.0\". The probe only accepts well-formed JSON-RPC 2.0 responses. A second throw of the same code (line 533) fires when 'result' is missing or not an object.","triggerScenarios":"Endpoint returns a JSON body that is not an object (array/string/number/null), or an object whose jsonrpc field is absent or not \"2.0\".","commonSituations":"Hitting a non-MCP REST endpoint at the probe URL; server implements an older/different JSON-RPC dialect (e.g. jsonrpc \"1.0\" or omitted field); a gateway error page returning JSON but not JSON-RPC.","solutions":["Confirm the probe URL points at the MCP endpoint that speaks JSON-RPC 2.0","Make the server include \"jsonrpc\":\"2.0\" in every response","Inspect the raw response body to see what the server actually returned","Check for a reverse proxy serving an error/config page at that path"],"exampleFix":"// before\n{\"id\":1,\"result\":{...}}\n// after\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{...}}","handlingStrategy":"type-guard","validationCode":"const body = JSON.parse(raw);\nif (typeof body !== \"object\" || body === null || (body as Record<string, unknown>).jsonrpc !== \"2.0\") {\n  throw new Error(\"endpoint response is not JSON-RPC 2.0\");\n}","typeGuard":"function isJsonRpc2Envelope(v: unknown): v is { jsonrpc: \"2.0\"; id: unknown } & Record<string, unknown> {\n  return typeof v === \"object\" && v !== null && (v as Record<string, unknown>).jsonrpc === \"2.0\";\n}","tryCatchPattern":"try {\n  const result = parseJsonRpcResult(payload, requestId);\n} catch (e) {\n  if (e instanceof SafeProbeFailure && e.code === \"invalid_jsonrpc_envelope\") {\n    console.error(\"endpoint did not return a JSON-RPC 2.0 envelope\", rawBody);\n  } else throw e;\n}","preventionTips":["Pin probe URLs to verified MCP endpoints and version them in config","Smoke-test the endpoint with a raw JSON-RPC 2.0 initialize call before wiring it in","Add a contract test asserting the jsonrpc:\"2.0\" field on all server responses"],"tags":["json-rpc","protocol","mcp"],"backgroundTag":"invalid-json-rpc-envelope","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}