fix: propagate Reactor Context into client transport chain (#154)
This commit is contained in:
parent
9c92a2b8bf
commit
261554bb7f
1 changed files with 3 additions and 2 deletions
|
|
@ -230,18 +230,19 @@ public class McpClientSession implements McpSession {
|
||||||
public <T> Mono<T> sendRequest(String method, Object requestParams, TypeReference<T> typeRef) {
|
public <T> Mono<T> sendRequest(String method, Object requestParams, TypeReference<T> typeRef) {
|
||||||
String requestId = this.generateRequestId();
|
String requestId = this.generateRequestId();
|
||||||
|
|
||||||
return Mono.<McpSchema.JSONRPCResponse>create(sink -> {
|
return Mono.deferContextual(ctx -> Mono.<McpSchema.JSONRPCResponse>create(sink -> {
|
||||||
this.pendingResponses.put(requestId, sink);
|
this.pendingResponses.put(requestId, sink);
|
||||||
McpSchema.JSONRPCRequest jsonrpcRequest = new McpSchema.JSONRPCRequest(McpSchema.JSONRPC_VERSION, method,
|
McpSchema.JSONRPCRequest jsonrpcRequest = new McpSchema.JSONRPCRequest(McpSchema.JSONRPC_VERSION, method,
|
||||||
requestId, requestParams);
|
requestId, requestParams);
|
||||||
this.transport.sendMessage(jsonrpcRequest)
|
this.transport.sendMessage(jsonrpcRequest)
|
||||||
|
.contextWrite(ctx)
|
||||||
// TODO: It's most efficient to create a dedicated Subscriber here
|
// TODO: It's most efficient to create a dedicated Subscriber here
|
||||||
.subscribe(v -> {
|
.subscribe(v -> {
|
||||||
}, error -> {
|
}, error -> {
|
||||||
this.pendingResponses.remove(requestId);
|
this.pendingResponses.remove(requestId);
|
||||||
sink.error(error);
|
sink.error(error);
|
||||||
});
|
});
|
||||||
}).timeout(this.requestTimeout).handle((jsonRpcResponse, sink) -> {
|
})).timeout(this.requestTimeout).handle((jsonRpcResponse, sink) -> {
|
||||||
if (jsonRpcResponse.error() != null) {
|
if (jsonRpcResponse.error() != null) {
|
||||||
logger.error("Error handling request: {}", jsonRpcResponse.error());
|
logger.error("Error handling request: {}", jsonRpcResponse.error());
|
||||||
sink.error(new McpError(jsonRpcResponse.error()));
|
sink.error(new McpError(jsonRpcResponse.error()));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue