{"record":{"id":"bda63f06c9d33bcc","repo":"different-ai/openwork","slug":"jsonrpc-error","errorCode":"jsonrpc_error","errorMessage":"jsonrpc_error","messagePattern":"jsonrpc_error","errorType":"error_code","errorClass":"SafeProbeFailure","httpStatus":null,"severity":"error","filePath":"apps/server/src/agent-context-cloud-probe.ts","lineNumber":531,"sourceCode":"    }\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\");\n  }\n  if (!Array.isArray(rpcResult.tools) || rpcResult.tools.length > MAX_TOOL_COUNT) {","sourceCodeStart":513,"sourceCodeEnd":549,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/server/src/agent-context-cloud-probe.ts#L513-L549","documentation":"parseJsonRpcResult throws SafeProbeFailure(\"jsonrpc_error\") when the response payload contains an 'error' member, meaning the remote MCP server rejected the request with a JSON-RPC error object instead of a result. The probe deliberately collapses the remote error's details into a safe fixed code so provider-controlled strings are never surfaced.","triggerScenarios":"Server responds with {\"jsonrpc\":\"2.0\",\"id\":...,\"error\":{\"code\":...,\"message\":...}} for the initialize or tools/list request.","commonSituations":"Invalid or expired bearer token rejected at protocol level; server does not support the requested MCP method; server-side rate limiting or policy denial; malformed request built by an outdated client.","solutions":["Check the bearer token/credentials the probe is sending are valid and authorized for this MCP server","Confirm the server supports the initialize and tools/list methods","Inspect server-side logs for the JSON-RPC error code it returned","Ensure the probe's JSON-RPC request bodies match the current MCP spec"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"// No reliable pre-call check: JSON-RPC errors depend on server state (auth, method support).\n// Pre-validate what you can: send valid credentials and only supported methods.","typeGuard":"function isJsonRpcError(v: unknown): boolean {\n  return typeof v === \"object\" && v !== null && Object.hasOwn(v as Record<string, unknown>, \"error\");\n}","tryCatchPattern":"try {\n  const result = parseJsonRpcResult(payload, requestId);\n} catch (e) {\n  if (e instanceof SafeProbeFailure && e.code === \"jsonrpc_error\") {\n    // rotate credentials / check method support; inspect server logs for the underlying error code\n  } else throw e;\n}","preventionTips":["Validate the bearer token's expiry and scopes before each probe run","Keep the client's JSON-RPC method payloads aligned with the MCP spec version in use","Monitor server-side JSON-RPC error logs to catch auth/policy failures early"],"tags":["json-rpc","mcp","server-error"],"backgroundTag":"json-rpc-error-response","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}