modelcontextprotocol / modelcontextprotocol/java-sdk

Client request handlers that complete empty send no JSON-RPC response

未關閉 適合新手
#1,124 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

area/client bug P2
主要語言
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.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 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

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。