examples/mcp/streamablehttp_custom_client_example/README.md
This example demonstrates how to use the new httpx_client_factory parameter in MCPServerStreamableHttp to configure custom HTTP client behavior for MCP StreamableHTTP connections.
Make sure you have uv installed: https://docs.astral.sh/uv/getting-started/installation/
Run the example:
cd examples/mcp/streamablehttp_custom_client_example
uv run main.py
import httpx
from agents.mcp import MCPServerStreamableHttp
def create_custom_http_client() -> httpx.AsyncClient:
return httpx.AsyncClient(
verify=False, # Disable SSL verification for testing
timeout=httpx.Timeout(60.0, read=120.0),
headers={"X-Custom-Client": "my-app"},
)
async with MCPServerStreamableHttp(
name="Custom Client Server",
params={
"url": "http://localhost:<port>/mcp",
"httpx_client_factory": create_custom_http_client,
},
) as server:
# Use the server...
This example will auto-pick a free localhost port unless you set STREAMABLE_HTTP_PORT; use STREAMABLE_HTTP_HOST to change the bind address.