Skip to content

Fix timeout parameter not being passed in HTTP posts #666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

CaelumF
Copy link

@CaelumF CaelumF commented May 8, 2025

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

Error in post writer:

(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

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • N/A I have added appropriate error handling
  • N/A I have added or updated documentation as needed

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's sse_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.

@CaelumF CaelumF changed the title Pass timeout parameter in HTTP posts Fix timeout parameter not being passed in HTTP posts May 8, 2025
Copy link

@mcp-shadow mcp-shadow bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mcp-shadow mcp-shadow bot closed this May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant