Page
MCP connectors — the Python client example.
Problem
The documented Python example connects with streamable_http_client(url, headers=...). On mcp 2.0.0 (the version resolved in the Apify Python Actor base image) that call raises:
TypeError: streamable_http_client() got an unexpected keyword argument 'headers'
streamable_http_client on that version does not accept a headers keyword. It expects an httpx.AsyncClient passed as http_client, with the Authorization header set on that client. So the example as written does not run on a freshly built Actor.
Working form
import os
import httpx
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client
url = f"{os.environ['APIFY_MCP_PROXY_URL']}/{connector_id}"
headers = {"Authorization": f"Bearer {os.environ['APIFY_TOKEN']}"}
async with httpx.AsyncClient(headers=headers, timeout=60) as http_client:
async with streamable_http_client(url, http_client=http_client) as streams:
async with ClientSession(streams[0], streams[1]) as session:
await session.initialize()
# session.list_tools(), session.call_tool(...), etc.
Suggested fix
Update the Python example to the http_client= form and pin/note the mcp version it targets, since the headers= vs http_client= signature differs across mcp releases. Happy to open a PR if useful.
Page
MCP connectors — the Python client example.
Problem
The documented Python example connects with
streamable_http_client(url, headers=...). Onmcp2.0.0 (the version resolved in the Apify Python Actor base image) that call raises:streamable_http_clienton that version does not accept aheaderskeyword. It expects anhttpx.AsyncClientpassed ashttp_client, with theAuthorizationheader set on that client. So the example as written does not run on a freshly built Actor.Working form
Suggested fix
Update the Python example to the
http_client=form and pin/note themcpversion it targets, since theheaders=vshttp_client=signature differs acrossmcpreleases. Happy to open a PR if useful.