Skip to content

Servlet transports serialize McpError exceptions instead of JSON-RPC error envelopes #955

@ultramancode

Description

@ultramancode

Servlet transports serialize McpError exceptions instead of JSON-RPC error envelopes

Bug description

Some servlet transport error paths serialize McpError directly instead of returning a JSON-RPC error response envelope.

Because McpError extends RuntimeException, the response body can expose exception-shaped fields such as:

  • stackTrace
  • cause
  • localizedMessage
  • jsonRpcError

For example, on current main, a servlet transport validation error returns a body like this:

Image

This is not the JSON-RPC response shape clients expect.

Environment

  • MCP Java SDK version: current main
  • Java version: 21
  • Transport: servlet server transports

Steps to reproduce

  1. Run an MCP server with a servlet transport.
  2. Send a request that triggers a servlet transport error path.
  3. Inspect the response body.

Expected behavior

The response body should look like:

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32601,
    "message": "Both application/json and text/event-stream required in Accept header"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions