Skip to content

fix: HTTP timeout correctly passed to httpx #956

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

akharlamov
Copy link

It may take some time for a starting MCP server to response to GET request. Hence, users of MCP Python SDK must have ability to configure HTTP read timeout.

Motivation and Context

HTTP timeout passed to MCP client does not apply properly.

How Has This Been Tested?

Our MCP server may respond very slowly during initial warm up and cache filling.
Hence, if client successfully connects to it, it may timeout and leave the client in a inconsistent state leading to overall application failing to progress.

Breaking Changes

No

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
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@@ -61,6 +61,7 @@ async def sse_client(
client,
"GET",
url,
timeout=httpx.Timeout(timeout, read=sse_read_timeout),
Copy link
Member

@Kludex Kludex Jun 13, 2025

Choose a reason for hiding this comment

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

That is being passed on line 57... 👀

@@ -106,7 +107,7 @@ async def sse_reader(
case _:
logger.warning(f"Unknown SSE event: {sse.event}")
except Exception as exc:
logger.error(f"Error in sse_reader: {exc}")
logger.error(f"Error in sse_reader: {exc.__class__.__name__}", exc_info=True)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logger.error(f"Error in sse_reader: {exc.__class__.__name__}", exc_info=True)
logger.exception("Error in sse_reader")

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.

2 participants