Fix timeout parameter not being passed in HTTP posts#666
Closed
CaelumF wants to merge 1 commit intomodelcontextprotocol:v1.7.xfrom
Closed
Fix timeout parameter not being passed in HTTP posts#666CaelumF wants to merge 1 commit intomodelcontextprotocol:v1.7.xfrom
CaelumF wants to merge 1 commit intomodelcontextprotocol:v1.7.xfrom
Conversation
There was a problem hiding this comment.
Thank you for your contribution to fix the timeout issue in the post_writer function. This is indeed a valid issue that needs addressing.
However, I'm closing this PR as a duplicate of PR #340, which addresses the same issue with a more complete solution by applying both the general timeout and read timeout parameters. PR #340 has already been assigned to the r-05-25 milestone and will be included in an upcoming release.
We appreciate your efforts to improve the MCP Python SDK.
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.
Use the sse_client timeout in POSTs it sends.
Motivation and Context
A server I am writing has need for timeouts longer than the httpx default for tool calls (they are about intentionally delaying an agent's execution loop until a condition is met in order to save cycles, so it wouldn't be appropriate to switch to a job pattern)
The timeout parameters are already passed into the event source that wraps the client via kwargs, but POSTs are made using the httpx client directly. Before this change when I pass long timeouts into the sse_client, it still timeouts when the MCP server takes longer than the httpx default to respond to POSTs.
How Has This Been Tested?
I tried using https://github.com/Coral-Protocol/coral-server 's
wait_for_mentionstool with a client powered by the MCP python sdk. When using with timeouts too close to exceeding the default httpx timeout, it fails with(Side note: the underlying exception has no description. I recommend we use
repr(e)to show the exception type)With this change made in site-packages, it works with timeouts greater than the httpx default.
Breaking Changes
Any users who are passing in longer timeouts than they desire, relying on the POST timeout to be ignored, will end up with undesired behaviour. I estimate this to be extremely rare.
Types of changes
Checklist
Additional context
Since this is a HTTP post via httpx, only the write timeout needs to be set. Though I am conscious of underlying implementations and/or future versions also being liable to
ReadTimeouts (e.g. developers wish for separate timeouts on preflight requests), I would have included a read timeout, though this function'ssse_read_timeoutis explicitly described about being time without new events, a new parameter for this feels excessive. It is probably premature to consider anyway.