Fix timeout parameter not being passed in HTTP posts #666
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_mentions
tool 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
ReadTimeout
s (e.g. developers wish for separate timeouts on preflight requests), I would have included a read timeout, though this function'ssse_read_timeout
is explicitly described about being time without new events, a new parameter for this feels excessive. It is probably premature to consider anyway.