Skip to content

Pass Httpx Auth with token provider to MCPSessionManager #2759

@dannovikov

Description

@dannovikov

Is your feature request related to a problem? Please describe.

MCPToolset parameter auth_credential takes an access token for the authenticated tool flow. However, our access tokens expire, and I don't see a way to pass a token provider to fetch refreshed tokens automatically.

I did see that the MCPSessionManager has a function _create_client which creates streamablehttp_client and sse_client, depending on the transport mode. These functions accept an auth parameter which is passed internally to the underlying httpx client. But this auth parameter isn't being exposed in the MCPSessionManager nor is it exposed in the top level user interface.

The approach we took was to subclass MCPSessionManager to add a token_provider property on init, and override _create_client, to create our Httpx auth and pass it to the client creation functions. This approach led us to bypass the auth_scheme and auth_credentials mechanisms because, in our estimation, they don't support token refresh mechanisms that the httpx client natively does.

Describe the solution you'd like
I think a preferable solution would be to expose the httpx auth property in the top-level user interface, like MCPToolset, or lower down in MCPTool or MCPSessionManager, so that I can pass an httpx auth object that goes into underlying the httpx MCP client.

Describe alternatives you've considered
An alternative I've considered is to allow us to pass a callable as the auth credential, rather than the token itself, which internally would be called to fetch an updated access token.

Additional context
I'm open to the possibilities that either:

  1. there may already be a token refresh mechanism in ADK for authenticated tools which I just don't know about, or
  2. there is a reason you haven't exposed such a mechanism. Would appreciate your thoughts on the situation.

Metadata

Metadata

Assignees

Labels

mcp[Component] Issues about MCP support

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions