conductor-oss/conductor · error · RuntimeException

JSON-RPC error: {error}

Error message

JSON-RPC error: {error}

What it means

Thrown by listToolsDirectHttp when the parsed JSON-RPC response contains an `error` field. JSON-RPC 2.0 uses an error object {code, message, data} for protocol-level failures (e.g. -32601 Method not found, -32602 Invalid params, -32700 Parse error). The thrown message embeds the whole error object's toString().

Source

Thrown at ai/src/main/java/org/conductoross/conductor/ai/mcp/MCPService.java:149

                                response.statusCode, response.body));
            }

            // Get response body and content type
            String responseBody = response.body;
            String contentType = response.contentType;

            // Parse response based on content type
            JsonNode responseJson;
            if (contentType != null && contentType.contains("text/event-stream")) {
                // Parse SSE format
                responseJson = parseSseResponse(responseBody);
            } else {
                // Parse as JSON directly
                responseJson = objectMapper.readTree(responseBody);
            }

            if (responseJson.has("error")) {
                throw new RuntimeException(
                        "JSON-RPC error: " + responseJson.get("error").toString());
            }

            if (!responseJson.has("result")) {
                throw new RuntimeException("Invalid JSON-RPC response: missing 'result' field");
            }

            JsonNode result = responseJson.get("result");
            JsonNode toolsNode = result.get("tools");

            if (toolsNode == null || !toolsNode.isArray()) {
                throw new RuntimeException(
                        "Invalid response: 'tools' field is missing or not an array");
            }
            ExternalDataLimits.validateStructure(objectMapper.convertValue(result, Object.class));

            // Convert to McpSchema.Tool list
            // Use Jackson to deserialize tools directly (same pattern as stdio implementation)

View on GitHub (pinned to cf7c3e4a8a)

Solutions

  1. Read the embedded error.code in the message to classify (-32601 => server lacks tools/list; -32xxx => protocol/session problem).
  2. If the server needs initialization, switch to an MCP client transport that performs initialize/initialized first.
  3. Confirm the server actually advertises the tools capability in its initialize response.
  4. Check the server version supports tools/list with the exact param shape sent.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    List<McpSchema.Tool> tools = mcpService.listTools(serverUrl, headers);
} catch (RuntimeException e) {
    // e.getMessage() starts with 'JSON-RPC error: ' followed by the error object.
    // Parse code (-32601 method not found, -32602 invalid params) to decide handling.
    if (e.getMessage().contains("-32601")) { /* server lacks tools/list */ }
    throw e;
}

Prevention

When it happens

Trigger: Calling listTools against a server that does not implement tools/list (returns -32601 method not found); sending a malformed id or params that the server rejects as -32602; a server that requires an initialized session id and returns -32000 because initialize was never called.

Common situations: Server is an older/other protocol that ignores tools/list; session negotiation was skipped; server enforces a capability negotiation (initialize) that this client bypasses by using direct JSON-RPC.

Related errors


AI-assisted analysis of conductor-oss/conductor@cf7c3e4a8a (2026-08-14). Data as JSON: /api/errors/51da8b0982c6b70e. Report an issue: GitHub.