feat: add support for reactive hook in MCP client initialization#866
Open
noxymon wants to merge 1 commit into
Open
feat: add support for reactive hook in MCP client initialization#866noxymon wants to merge 1 commit into
noxymon wants to merge 1 commit into
Summary
This PR introduces a connectHook to the McpClient builders and improves connection error propagation in McpClientSession. It ensures that failures during the transport connection phase (e.g., process startup failures in Stdio) are correctly reported
to callers instead of being dropped by Project Reactor.
Motivation and Context
This change addresses Closes #712 (#712). Previously, errors occurring during the asynchronous connection phase were often "dropped" by Reactor because the internal subscription lacked an error
handler. This led to onErrorDropped logs and caused client.initialize() to hang until a timeout occurred, rather than failing immediately with a descriptive error. The new connectHook also provides the requested extensibility for users to intercept
and transform the connection lifecycle.
How Has This Been Tested?
Tested via a new functional test suite McpClientInitializationTests.java:
Breaking Changes
No breaking changes. The connectHook is optional, and the updated internal constructors maintain backward compatibility via @deprecated overloads.
Types of changes
Checklist
Additional context
The fix in McpClientSession works by iterating over all pendingResponses when a connection error is detected and failing them immediately. This is a more robust approach than relying on timeouts, as it provides the actual cause of the connection
failure (e.g., IOException) to the user.