Skip to content

Commit 261554b

Browse files
authored
fix: propagate Reactor Context into client transport chain (#154)
1 parent 9c92a2b commit 261554b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mcp/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,19 @@ private String generateRequestId() {
230230
public <T> Mono<T> sendRequest(String method, Object requestParams, TypeReference<T> typeRef) {
231231
String requestId = this.generateRequestId();
232232

233-
return Mono.<McpSchema.JSONRPCResponse>create(sink -> {
233+
return Mono.deferContextual(ctx -> Mono.<McpSchema.JSONRPCResponse>create(sink -> {
234234
this.pendingResponses.put(requestId, sink);
235235
McpSchema.JSONRPCRequest jsonrpcRequest = new McpSchema.JSONRPCRequest(McpSchema.JSONRPC_VERSION, method,
236236
requestId, requestParams);
237237
this.transport.sendMessage(jsonrpcRequest)
238+
.contextWrite(ctx)
238239
// TODO: It's most efficient to create a dedicated Subscriber here
239240
.subscribe(v -> {
240241
}, error -> {
241242
this.pendingResponses.remove(requestId);
242243
sink.error(error);
243244
});
244-
}).timeout(this.requestTimeout).handle((jsonRpcResponse, sink) -> {
245+
})).timeout(this.requestTimeout).handle((jsonRpcResponse, sink) -> {
245246
if (jsonRpcResponse.error() != null) {
246247
logger.error("Error handling request: {}", jsonRpcResponse.error());
247248
sink.error(new McpError(jsonRpcResponse.error()));

0 commit comments

Comments
 (0)