modelcontextprotocol / modelcontextprotocol/java-sdk

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

未关闭
#955 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P2 ready for work
主要语言
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:

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从复现步骤中描述的 servlet 服务器传输错误路径开始,跟踪验证失败是如何序列化的。将当前响应与预期的 JSON-RPC 信封进行比较,然后执行所述的 Accept 标头验证请求,以确认正文仅包含 JSON-RPC 错误结构。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
api, backend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
68/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。