modelcontextprotocol / modelcontextprotocol/java-sdk

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

Open
#955 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2 ready for work
Dominant language
Java
Stars
3.7k
Forks
1.1k
Avg merge
1d 15h
Merged PRs (30d)
9

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the servlet server transport error paths described in the reproduction and trace how validation failures are serialized. Compare the current response with the expected JSON-RPC envelope, then exercise the stated Accept-header validation request to confirm the body contains only the JSON-RPC error shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.