fix: propagate reactor context up till transport #154
Merged
+3
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
When implementing my own custom transport class which has the requirement of passing in a unique JWT Token per incoming request to call tool, I came to realize that context propagation up till the transport's sendMessage function is not working for regular requests but only working for notifications.
Upon further inspection this is because of how sendRequest and sendNotification are implemented in the McpClientSession class.
The sendRequest method creates a response mono and the transport's sendMessage creates a separate mono, the context from the client is only propagated into the response mono but isn't passed into the mono returned by sendMessage. This differs from sendNotification that returns the mono created by the transport's sendMessage back to the client so the context attached by the client gets propagated into the mono in the transport's sendMessage for notifications.

This MR modifies the McpClientSession's sendRequest to explicitly propagate the context into the mono created by transport's sendMessage allowing the transport's sendMessage to access the JWT Token from this context and perform the required logic.
How Has This Been Tested?
yes, ran the existing tests.
Breaking Changes
None
Types of changes
Checklist
Additional context