Skip to content

fix: accept FastMCP HTTP factory kwargs#5694

Open
he-yufeng wants to merge 1 commit into
pydantic:mainfrom
he-yufeng:fix/mcp-toolset-http-client-factory-kwargs
Open

fix: accept FastMCP HTTP factory kwargs#5694
he-yufeng wants to merge 1 commit into
pydantic:mainfrom
he-yufeng:fix/mcp-toolset-http-client-factory-kwargs

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Summary

MCPToolset(url, http_client=...) adapts the supplied httpx.AsyncClient into FastMCP's httpx_client_factory hook. FastMCP's HTTP transports can call that factory with extra runtime kwargs such as follow_redirects, so the adapter needs to accept and ignore them while still returning the caller-owned client.

This keeps the existing URL/SSE behavior and only makes the factory tolerant of the extra transport kwargs.

Fixes #5688.

To verify

  • python -m pytest tests/test_mcp_toolset.py::TestMCPToolsetConstruction -q -p no:cacheprovider --basetemp .tmp/pytest-5688-construction2
  • ruff format --check pydantic_ai_slim/pydantic_ai/mcp.py tests/test_mcp_toolset.py
  • ruff check pydantic_ai_slim/pydantic_ai/mcp.py tests/test_mcp_toolset.py
  • pyright pydantic_ai_slim/pydantic_ai/mcp.py
  • python -m py_compile pydantic_ai_slim/pydantic_ai/mcp.py tests/test_mcp_toolset.py
  • git diff --check

@github-actions github-actions Bot added size: S Small PR (≤100 weighted lines) bug Report that something isn't working, or PR implementing a fix labels May 27, 2026
@CostcoFanboy
Copy link
Copy Markdown

@DouweM deepest apologies for the tag I'm aware of how incredibly busy you are.
Do you think we could merge this in?

This small bug that unlocks quite a lot of features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Report that something isn't working, or PR implementing a fix size: S Small PR (≤100 weighted lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCPToolset(url, http_client=...) crashes: factory missing follow_redirects kwarg passed by FastMCP

2 participants