Skip to content

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

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"
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Moderate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingready for workThe goal is clear and work towards it can be commenced

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions