Close response after sending error in McpStreamableServerSession#responseStream (#1041)

Closes #1040

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
This commit is contained in:
Daniel Garnier-Moiroux 2026-06-26 16:06:36 +02:00 • committed by GitHub
commit ff78191ebd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -214,9 +214,13 @@ public class McpStreamableServerSession implements McpLoggableSession {
// (sink)
if (requestHandler == null) {
MethodNotFoundError error = getMethodNotFoundError(jsonrpcRequest.method());
return transport.sendMessage(
McpSchema.JSONRPCResponse.error(jsonrpcRequest.id(), new McpSchema.JSONRPCResponse.JSONRPCError(
McpSchema.ErrorCodes.METHOD_NOT_FOUND, error.message(), error.data())));
return transport
.sendMessage(
McpSchema.JSONRPCResponse
.error(jsonrpcRequest.id(),
new McpSchema.JSONRPCResponse.JSONRPCError(
McpSchema.ErrorCodes.METHOD_NOT_FOUND, error.message(), error.data())))
.then(transport.closeGracefully());
}
return requestHandler
.handle(new McpAsyncServerExchange(this.id, stream, clientCapabilities.get(), clientInfo.get(),