modelcontextprotocol / modelcontextprotocol/java-sdk

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

Open Beginner friendly
#1,124 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/client bug P2
Dominant language
Java
Stars
3.7k
Forks
1.1k
Avg merge
1d 15h
Merged PRs (30d)
9

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with McpClientSession and the regression test McpClientSessionTests.testEmptyRequestHandlerSendsErrorResponse, using MockMcpClientTransport to reproduce the empty-handler case. Trace incoming JSON-RPC request dispatch and verify that Mono.empty() produces one JSON-RPC error response with request ID test-id and code -32603.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.