Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions disclosure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This change was submitted despite me reading the rules and understanding AI contribution guidelines.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,16 @@ private Mono<McpSchema.JSONRPCResponse> handleIncomingRequest(McpSchema.JSONRPCR
}

return handler.handle(request.params())
.map(result -> McpSchema.JSONRPCResponse.result(request.id(), result));
.map(result -> McpSchema.JSONRPCResponse.result(request.id(), result))
.switchIfEmpty(Mono.defer(() -> {
logger.warn("Request handler for method '{}' completed without producing a result. "
+ "Responding with an internal error to honor JSON-RPC 2.0's "
+ "one-response-per-request contract.", request.method());
return Mono.just(McpSchema.JSONRPCResponse.error(request.id(),
new McpSchema.JSONRPCResponse.JSONRPCError(McpSchema.ErrorCodes.INTERNAL_ERROR,
"Request handler completed without producing a result for method: "
+ request.method())));
}));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,25 @@ void testRequestHandling() {
session.close();
}

@Test
void testEmptyRequestHandlerSendsErrorResponse() {
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);
McpSchema.JSONRPCResponse response = (McpSchema.JSONRPCResponse) transport.getLastSentMessage();
assertThat(response.id()).isEqualTo("test-id");
assertThat(response.result()).isNull();
assertThat(response.error()).isNotNull();
assertThat(response.error().code()).isEqualTo(McpSchema.ErrorCodes.INTERNAL_ERROR);
assertThat(response.error().message()).contains("without producing a result");

session.close();
}

@Test
void testNotificationHandling() {
Sinks.One<Object> receivedParams = Sinks.one();
Expand Down