Skip to content

Support custom OAuthClientProviders (similar to TypeScript SDK) to enable custom authentication logic in client code #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
smurching opened this issue May 7, 2025 · 2 comments
Assignees

Comments

@smurching
Copy link

smurching commented May 7, 2025

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.

@smurching smurching 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 May 7, 2025
@omarbenhamid
Copy link

Important feature, I hope it will be merged soon

@ihrpr
Copy link
Contributor

ihrpr commented May 13, 2025

linking PR: #308

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants