Skip to content

MCP connectors: Python example fails on shipped mcp 2.0.0 (streamable_http_client has no headers kwarg) #2878

Description

@factden

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.

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation.t-docsIssues owned by technical writing team.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions