modelcontextprotocol / modelcontextprotocol/java-sdk
Client request handlers that complete empty send no JSON-RPC response
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 3.7k
- 派生
- 1.1k
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 9
描述
Bug description
When a server sends a request to a Java SDK client, an asynchronous sampling or elicitation handler can return Mono.empty(). McpClientSession then sends no JSON-RPC response, so the server waits until its request timeout.
JSON-RPC 2.0 requires a response for every request with an ID. An empty handler completion should produce an error response with the original request ID.
This is the client-side counterpart to https://github.com/modelcontextprotocol/java-sdk/issues/1081. The open fix at https://github.com/modelcontextprotocol/java-sdk/pull/1099 changes only server-side dispatch paths.
Environment
- Java SDK v2.0.1, commit
c7e1cfe90edcd9cbe030924310a194dc5492eab2 - Java SDK main, commit
39c225e46c51311eaf82192f15b950e421580fb5 - Temurin 25.0.3, compiling with the repository's Java 17 target
Steps to reproduce
Register a client request handler that returns Mono.empty(), then deliver a JSON-RPC request with an ID:
var transport = new MockMcpClientTransport();
var session = new McpClientSession(TIMEOUT, transport,
Map.of("test.method", params -> Mono.empty()), Map.of(), Function.identity());
transport.simulateIncomingMessage(new McpSchema.JSONRPCRequest("test.method", "test-id"));
assertThat(transport.getLastSentMessage()).isInstanceOf(McpSchema.JSONRPCResponse.class);
Both v2.0.1 and main fail because getLastSentMessage() is null:
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
Expecting actual not to be null
Expected behavior
The client sends one JSON-RPC error response with ID test-id and code -32603.
Minimal Complete Reproducible example
The regression test is in McpClientSessionTests.testEmptyRequestHandlerSendsErrorResponse.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 McpClientSession 和回归测试 McpClientSessionTests.testEmptyRequestHandlerSendsErrorResponse 开始,使用 MockMcpClientTransport 重现空处理程序的情况。跟踪传入 JSON-RPC 请求的分发,并验证 Mono.empty() 会生成一个请求 ID 为 test-id、代码为 -32603 的 JSON-RPC 错误响应。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- api
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 活跃
- 描述清晰度
- 描述清楚
- 新手友好度
- 84/100