{"record":{"id":"9d62102bc8cac97d","repo":"nikivdev/code","slug":"maple-mcp-error-code-message","errorCode":null,"errorMessage":"Maple MCP error {code}: {message}","messagePattern":"Maple MCP error (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/codex_telemetry.rs","lineNumber":427,"sourceCode":"            serde_json::to_string(&payload)\n                .unwrap_or_else(|_| \"unparseable error body\".to_string())\n        );\n    }\n    let envelope = if let Some(items) = payload.as_array() {\n        items.first().cloned().unwrap_or(serde_json::Value::Null)\n    } else {\n        payload\n    };\n    if let Some(error) = envelope.get(\"error\") {\n        let code = error\n            .get(\"code\")\n            .and_then(serde_json::Value::as_i64)\n            .unwrap_or(-1);\n        let message = error\n            .get(\"message\")\n            .and_then(serde_json::Value::as_str)\n            .unwrap_or(\"unknown Maple MCP error\");\n        anyhow::bail!(\"Maple MCP error {code}: {message}\");\n    }\n    envelope\n        .get(\"result\")\n        .cloned()\n        .ok_or_else(|| anyhow::anyhow!(\"Maple MCP response did not include a result payload\"))\n}\n\nfn maple_tool_result_error(result: &serde_json::Value) -> Option<String> {\n    if result.get(\"isError\").and_then(|value| value.as_bool()) != Some(true) {\n        return None;\n    }\n    result\n        .get(\"content\")\n        .and_then(|value| value.as_array())\n        .and_then(|items| items.first())\n        .and_then(|item| item.get(\"text\"))\n        .and_then(|value| value.as_str())\n        .map(|value| value.trim().to_string())","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/codex_telemetry.rs#L409-L445","documentation":"This error is raised by `maple_json_rpc_request` when the parsed JSON-RPC envelope contains an `error` object. The library extracts the `code` (defaulting to -1) and `message` (defaulting to 'unknown Maple MCP error') from the error payload and surfaces them. Unlike error 250, the HTTP transport succeeded but the JSON-RPC layer itself reported a failure (e.g. unknown method, invalid params).","triggerScenarios":"`maple_json_rpc_request` (called by `maple_call_tool` and `trace_status`) receives a 2xx response whose JSON body contains an `error` field, e.g. code -32601 (method not found) or -32602 (invalid params), and bails with `Maple MCP error {code}: {message}`.","commonSituations":"Calling a Maple tool name that does not exist on the server, passing arguments that fail server-side schema validation, using an MCP client protocol version the server rejects, or a server bug that returns a JSON-RPC error with no message (surfaced as 'unknown Maple MCP error').","solutions":["Read the code/message in the error: fix the tool name or arguments for -32601/-32602.","Dump the exact request arguments passed to `maple_call_tool` and validate them against the tool's input schema.","Confirm the Maple MCP server exposes the requested tool (list tools via the MCP protocol or server docs).","If code is -1 with 'unknown Maple MCP error', capture the raw response body to debug the server-side failure."],"exampleFix":"// before: nonexistent tool name\nmaple_call_tool(\"trace.inspect.v2\", args)?;\n// after: use the tool name the server actually exposes\nmaple_call_tool(\"inspect_trace\", args)?;","handlingStrategy":"try-catch","validationCode":"// validate tool name and arguments against the server's tool list first\nlet tools = list_maple_tools()?; // JSON-RPC tools/list\nif !tools.iter().any(|t| t[\"name\"] == tool_name) {\n    return Err(format!(\"tool {tool_name} not exposed by Maple MCP server\"));\n}","typeGuard":"fn json_rpc_error_code(envelope: &serde_json::Value) -> Option<i64> {\n    envelope.get(\"error\")?.get(\"code\")?.as_i64()\n}","tryCatchPattern":"match maple_json_rpc_request(&payload) {\n    Err(e) if e.to_string().starts_with(\"Maple MCP error \") => {\n        let code = extract_code(&e); // e.g. -32601 method not found\n        eprintln!(\"JSON-RPC error {code}: adjust method/args: {e}\");\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["List available tools from the server before calling them by name","Validate tool arguments against the published input schema","Keep MCP client/server protocol versions aligned","Treat code -1 / 'unknown' messages as a signal to capture the raw body for debugging"],"tags":["mcp","json-rpc","api","protocol"],"backgroundTag":"json-rpc-server-error","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}