Class McpErrorBodies

java.lang.Object
com.mcpdbwizard.pub.McpErrorBodies

public final class McpErrorBodies extends Object
Turns the MCP Java SDK's transport-level error bodies into JSON-RPC errors.

Why this exists. SDK 2.0.0's Streamable HTTP transport answers its own errors -- no session, an unknown session, an unparseable message, and any method it rejects before initialize (such as the 2026-07-28 revision's server/discover) -- by serialising the whole McpError EXCEPTION OBJECT: its JSON-RPC code and message, and also its stackTrace, naming our classes, source files, line numbers and the Jetty and JDK versions. Measured 2026-10-02. That body is not a JSON-RPC error at all, and the web proxy carries it to whoever called.

The rewrite keeps exactly the code and the message and drops everything else, giving {"jsonrpc":"2.0","id":null,"error":{"code":..,"message":".."}} -- id null because the transport answered before reading one, as JSON-RPC prescribes for that case. The status code is not touched: a 2026-07-28 client deciding whether we are a legacy server reads the status and whether the body is one of ITS error types, and a plain JSON-RPC error is still not one, so the documented fallback to initialize behaves exactly as before. Copyright 2003-2026 ATB Consultancy Services Ltd (formerly Orinda Software Ltd, Dublin, Ireland)

  • Method Details

    • jsonRpcErrorFor

      public static String jsonRpcErrorFor(String theBody)
      The JSON-RPC error to send instead of an SDK transport error body, or null when the body is not one (it is then passed on unchanged -- this rewrites the one shape it knows, and nothing else).
      Parameters:
      theBody - the response body as written
      Returns:
      the replacement body, or null