modelcontextprotocol / modelcontextprotocol/java-sdk
Servlet transports serialize McpError exceptions instead of JSON-RPC error envelopes
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 3.7k
- 派生
- 1.1k
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 9
描述
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"
}
}
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从复现步骤中描述的 servlet 服务器传输错误路径开始,跟踪验证失败是如何序列化的。将当前响应与预期的 JSON-RPC 信封进行比较,然后执行所述的 Accept 标头验证请求,以确认正文仅包含 JSON-RPC 错误结构。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- api, backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 68/100