You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support custom OAuthClientProviders (similar to TypeScript SDK) to enable custom authentication logic in client code #652
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 URLasyncwithstreamablehttp_client(url=f"{basic_server_url}/mcp/", headers={'Authorization': f'Bearer {token}'}) as (
read_stream,
write_stream,
_,
):
asyncwithClientSession(
read_stream,
write_stream,
) assession:
awaitsession.initialize()
yieldsession
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.
changed the title [-]Support custom OauthProviders in the client (similar to TypeScript SDK)[/-][+]Support custom OAuthClientProviders (similar to TypeScript SDK) to enable custom authentication logic in client code[/+]on May 7, 2025
Activity
[-]Support custom OauthProviders in the client (similar to TypeScript SDK)[/-][+]Support custom OAuthClientProviders (similar to TypeScript SDK) to enable custom authentication logic in client code[/+]omarbenhamid commentedon May 11, 2025
Important feature, I hope it will be merged soon
ihrpr commentedon May 13, 2025
linking PR: #308
felixweinberger commentedon Oct 6, 2025
Closing as #308 has landed.