-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix MCPServerStreamableHTTP closing user-provided HTTP clients with MCP SDK 1.25+
#3854
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
base: main
Are you sure you want to change the base?
Changes from all commits
0ac6fdd
07bf1ed
839f9d2
03cc23d
a8adf25
05e7d0a
0f0d34e
9268afd
65dc17f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ | |
| from mcp.client.session import ClientSession, ElicitationFnT, LoggingFnT | ||
| from mcp.client.sse import sse_client | ||
| from mcp.client.stdio import StdioServerParameters, stdio_client | ||
| from mcp.client.streamable_http import GetSessionIdCallback, streamablehttp_client | ||
| from mcp.client.streamable_http import GetSessionIdCallback, streamable_http_client | ||
| from mcp.shared import exceptions as mcp_exceptions | ||
| from mcp.shared.context import RequestContext | ||
| from mcp.shared.message import SessionMessage | ||
|
|
@@ -1153,20 +1153,10 @@ async def client_streams( | |
| ) | ||
|
|
||
| if self.http_client is not None: | ||
| # TODO: Clean up once https://github.com/modelcontextprotocol/python-sdk/pull/1177 lands. | ||
| @asynccontextmanager | ||
| async def httpx_client_factory( | ||
| headers: dict[str, str] | None = None, | ||
| timeout: httpx.Timeout | None = None, | ||
| auth: httpx.Auth | None = None, | ||
| ) -> AsyncIterator[httpx.AsyncClient]: | ||
| assert self.http_client is not None | ||
| yield self.http_client | ||
|
|
||
| async with transport_client_partial(httpx_client_factory=httpx_client_factory) as ( | ||
| async with streamable_http_client(self.url, http_client=self.http_client) as ( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still need to use |
||
| read_stream, | ||
| write_stream, | ||
| *_, | ||
| _, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unsure if this is right |
||
| ): | ||
| yield read_stream, write_stream | ||
| else: | ||
|
|
@@ -1282,7 +1272,7 @@ def __get_pydantic_core_schema__(cls, _: Any, __: Any) -> CoreSchema: | |
|
|
||
| @property | ||
| def _transport_client(self): | ||
| return streamablehttp_client | ||
| return self.http_client | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be reverted |
||
|
|
||
| def __eq__(self, value: object, /) -> bool: | ||
| return super().__eq__(value) and isinstance(value, MCPServerStreamableHTTP) and self.url == value.url | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
transport_client_partialmethod can now be deleted