Skip to content

ADK agents to support changing identity tokens #2221

Closed

Description

@VeerMuchandi

** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.

Is your feature request related to a problem? Please describe.
When external tools (APIs, MCP tools) require auth tokens, we need the ability refresh those tokens every once in a while. We need ability for ADK agents to accept refreshed tokens.

Describe the solution you'd like
A clear and concise description of what you want to happen.
See this agent code as an example

from google.adk.tools.mcp_tool.mcp_session_manager import (
    SseConnectionParams,
)
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
from google.adk.agents import LlmAgent
from google.auth.transport.requests import Request as AuthRequest
from google.oauth2 import id_token
from urllib.parse import urlparse


def create_agent():
  """Gets tools from MCP Server."""
  url = "https://country-server-121968733869.us-central1.run.app/sse"

  # For invoking a Cloud Run service, we need an ID token.
  # The audience for the ID token is the root URL of the service.
  parsed_url = urlparse(url)
  audience = f"{parsed_url.scheme}://{parsed_url.netloc}"

  identity_token = id_token.fetch_id_token(AuthRequest(), audience)

  auth_header = {"Authorization": f"Bearer {identity_token}"}

  toolset = MCPToolset(
      connection_params=SseConnectionParams(url=url, headers=auth_header)
  )
  agent = LlmAgent(
      model="gemini-2.0-flash",
      name="country_agent",
      instruction=("Help get detailed information about a country"),
      tools=[toolset],
  )
  return agent


root_agent = create_agent()

In this case the tool running on Cloud Run requires identity_token passed as a Authorization param and this token expires every 60m. How do we refresh the agent with the changed identity_token after the agent creation?

If there is way to do it already, happy to use that approach.

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.

Activity

  1. added
    tools
    on Jul 28, 2025
  2. added theissue type on Jul 28, 2025
  3. Satheesh-Balachandran commented on Jul 29, 2025

    @Satheesh-Balachandran

    +1 - This is mandatory for connecting to an enterprise grade MCP server

  4. added
    mcp
    on Aug 21, 2025
  5. m-breitbach commented on Aug 28, 2025

    @m-breitbach

    I am in a similar situation, however, not with an MCP but with the agent itself. I have to use a custom LLM endpoint that works with expiring API keys.

  6. m-breitbach commented on Sep 17, 2025

    @m-breitbach

    The problem with the MCP could be resolved with #2966 together with adding event hooks to the client.

  7. mertbozkir commented on Oct 24, 2025

    @mertbozkir

    +1 - This is mandatory for connecting to an enterprise grade MCP server

    Agree!

  8. m-breitbach commented on Oct 29, 2025

    @m-breitbach

    For the MCP integration, the issue seems to be fixed:

    * Support dynamic per-request headers in MCPToolset ([6dcbb5a](https://github.com/google/adk-python/commit/6dcbb5aca642290112a7c81162b455526c15cd14))

  9. klateefa commented on Nov 25, 2025

    @klateefa

    @VeerMuchandi Thank you for reporting this. I understand the request is currently under review. Please keep me posted if anything else is needed. Thanks for your patience.

  10. added
    needs review
    on Nov 25, 2025
  11. m-breitbach commented on Mar 3, 2026

    @m-breitbach

    The issue is addressed by, if I am not mistaken: bfed19cd

    One can now pass a custom client with event hooks configured and thereby inject live tokens.

  12. DeanChensj commented on Jun 24, 2026

    @DeanChensj
    Collaborator

    Thanks @m-breitbach for the heads up, closing this one.

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

Metadata

Metadata

Assignees

Labels

mcpneeds reviewtools

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions