Skip to content

Commit 84ed798

Browse files
FH-30francishodianto30
authored and
francishodianto30
committed
fix: propagate reactor context up till transport
1 parent f348a83 commit 84ed798

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,19 @@ private String generateRequestId() {
225225
public <T> Mono<T> sendRequest(String method, Object requestParams, TypeReference<T> typeRef) {
226226
String requestId = this.generateRequestId();
227227

228-
return Mono.<McpSchema.JSONRPCResponse>create(sink -> {
228+
return Mono.deferContextual(ctx -> Mono.<McpSchema.JSONRPCResponse>create(sink -> {
229229
this.pendingResponses.put(requestId, sink);
230230
McpSchema.JSONRPCRequest jsonrpcRequest = new McpSchema.JSONRPCRequest(McpSchema.JSONRPC_VERSION, method,
231231
requestId, requestParams);
232232
this.transport.sendMessage(jsonrpcRequest)
233+
.contextWrite(ctx)
233234
// TODO: It's most efficient to create a dedicated Subscriber here
234235
.subscribe(v -> {
235236
}, error -> {
236237
this.pendingResponses.remove(requestId);
237238
sink.error(error);
238239
});
239-
}).timeout(this.requestTimeout).handle((jsonRpcResponse, sink) -> {
240+
})).timeout(this.requestTimeout).handle((jsonRpcResponse, sink) -> {
240241
if (jsonRpcResponse.error() != null) {
241242
sink.error(new McpError(jsonRpcResponse.error()));
242243
}

0 commit comments

Comments
 (0)