feat(mcp): add per-call response timeouts with protocol cancellation - #20
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Add
McpConnection::call_tool_with_timeout(name, arguments, Duration)using RMCP's request handle lifecycle. Expiry attempts request-scoped protocol cancellation and returns the existing typedMcpError::Timeout;call_toolremains unlimited.Motivation
Preparatory AgentKit support for Kit #17, whose outer timeout cannot invoke RMCP cancellation. This PR does not complete the hard-deadline fix.
Impact
The new API provides a fixed response-wait timeout, not a total wall-clock deadline. Cancellation is best effort: remote effects can still complete and are not rolled back. Callers must inspect remote state before retrying side effects.
Technical details
RMCP
PeerRequestOptionsandRequestHandle::await_responseretain request ownership through expiry, attemptnotifications/cancelled, and remove pending state when cancellation transport send completes, including on send error. Typed results, argument validation, tracing, and non-timeout auth/error handling share the existing call path.With RMCP 3.1.2, admission happens before the timer starts, and cancellation transport I/O can stall timeout return and local cleanup indefinitely. Dropping the future is not cancel-safe. Full Kit hard-deadline delegation remains blocked until RMCP separates local abandonment from transport completion and bounds admission, followed by compatible published releases.