Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions pydantic_ai_slim/pydantic_ai/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Copy link
Collaborator

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_partial method can now be deleted

async with streamable_http_client(self.url, http_client=self.http_client) as (
Copy link
Collaborator

Choose a reason for hiding this comment

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

This still need to use _transport_client

read_stream,
write_stream,
*_,
_,
Copy link
Collaborator

Choose a reason for hiding this comment

The 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:
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Expand Down
2 changes: 1 addition & 1 deletion pydantic_ai_slim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ cli = [
"pyperclip>=1.9.0",
]
# MCP
mcp = ["mcp>=1.18.0"]
mcp = ["mcp>=1.25.0"]
# FastMCP
fastmcp = ["fastmcp>=2.12.0"]
# Evals
Expand Down
29 changes: 25 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading