modelcontextprotocol / modelcontextprotocol/java-sdk
Servlet transports serialize McpError exceptions instead of JSON-RPC error envelopes
Nobody has claimed this yet.
- 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:
stackTracecauselocalizedMessagejsonRpcError
For example, on current main, a servlet transport validation error returns a body like this:
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
- Run an MCP server with a servlet transport.
- Send a request that triggers a servlet transport error path.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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