fix: Fix mcp timeout issue#922
Merged
Unshure merged 1 commit intostrands-agents:mainfrom Sep 26, 2025
Merged
Conversation
cb1e39d to
805c4a5
Compare
mkmeral
approved these changes
Sep 25, 2025
zastrowm
approved these changes
Sep 26, 2025
3 tasks
dbschmigelski
pushed a commit
to dbschmigelski/sdk-python
that referenced
this pull request
Dec 9, 2025
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.
Description
Fixed the timeout issue with the mcp client when the http server times out before the tool finishes
I was able to replicate this bug by creating an mcp server with a tool that waits ~5 seconds, and then configuring the mcp client to time out before that:
MCP Server
Test code:
I ended up figuring out this is due to an odd behavior in the MCP client where it does not raise an exception automatically. The MCP Client we use, defined in mcp code here, takes in a parameter called
message_handlerwhich is meant to handle different kind of messages returned by the underlying server. One of those message types is an exception(ref), so if you dont raise that exception, it will be silently swallowed. This swallowed exception does not close the tool connection, and this causes the application to hang.Ive implemented a message handler that checks if the message is an exception, and if so raises it. This helps avoid the silent failure we have seen so far. As not raising an exception is a very odd behavior, I have reached out on the mcp repo to try and understand why this is the case: modelcontextprotocol/python-sdk#1401
Related Issues
Documentation PR
N/A
Type of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.