Description
Is your feature request related to a problem? Please describe.
I have multiple MCP servers hosted behind the same authorization server, and my client environment provides a get_oauth_token()
API to get a short-lived access token. When writing custom agents or programs that connect to the MCP servers, I can use the APIs currently in main
and manually specify headers to connect to each MCP server:
token = get_oauth_token()
# Repeat this for each server URL
async with streamablehttp_client(url=f"{basic_server_url}/mcp/", headers={'Authorization': f'Bearer {token}'}) as (
read_stream,
write_stream,
_,
):
async with ClientSession(
read_stream,
write_stream,
) as session:
await session.initialize()
yield session
However, this of course isn't stable over time when I'm trying to authenticate using short-lived oauth access tokens (I'll get token expiry errors after 30 min etc).
Describe the solution you'd like
It seems we have a nice solution to implementing custom authentication behavior in MCP clients in the TypeScript SDK, where I can pass a custom OauthClientProvider when instantiating my client (e.g. here). Would it make sense to consider the same for the Python SDK? Happy to help with a contribution here :)
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.