Skip to content

Pass Httpx Auth with token provider to MCPSessionManager #2759

Closed

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.

Activity

  1. added
    mcp
    on Aug 28, 2025
  2. added theissue type on Aug 28, 2025
  3. rei-arifi commented on Sep 22, 2025

    @rei-arifi
    Contributor

    Hello,

    We are also running on the same issue when using Agent Engine.
    Since the MCPToolset object is instantiated when the agent gets pickled, we end up shipping the access token of the CI system to Agent Engine. We have tried to pass a function, but it yields the same result.

    Code snippet:

    my_mcp = MCPToolset(
        connection_params=StreamableHTTPConnectionParams(
            url="https://airflow-mcp-staging-gcp-external.naturalint.com/mcp",
            auth=get_sa_token()
        ),
        errlog=None
    )
    
    root_agent = Agent(
        name="test_agent",
        model="gemini-2.0-flash",
        description="test_agent",
        instruction="Make HTTP GET requests to specified URLs and provide agent introduction when requested",
        tools=[
          my_mcp
        ]
    )
  4. hangfei commented on Nov 8, 2025

    @hangfei
    Collaborator

    Please use the main issue to track, closing this for now.

  5. wukath commented on Jan 14, 2026

    @wukath
    Collaborator

    @dannovikov @rei-arifi We have added a custom httpx_client_factory param exposed when creating a McpSessionManager (see #2997) -- I think this should allow you to pass in a httpx auth object. Let me know if it works?

  6. dannovikov commented on Jan 14, 2026

    @dannovikov
    Author

    @wukath Ah, cool! Will check it out tomorrow and report back. Thanks for the update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

mcp

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions