File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed
mcp/src/main/java/io/modelcontextprotocol/spec Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff 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 ()));
You can’t perform that action at this time.
0 commit comments