adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

feat: Dynamic authentication handling in MCPToolset from ADK Readonly…

Open pandasanjay opened this issue 4 months ago • 1 comments

…Context.state

This PR implements dynamic authentication handling in MCPToolset by passing authentication information (such as user-specific tokens) directly from the ADK session.state. With this approach, user tokens can be injected and sent from the ADK Context state to MCP, supporting user-specific authentication flows.

Key Improvements:

  1. Dynamic Token Management:

    • MCPToolset now reads authentication information from the ADK ReadonlyContext.state at runtime, enabling dynamic, user-specific token management.
    • STDIO Transport: Authentication information is passed to MCP via environment variables. - #1402
    • Other Transports (SSE and HTTP Stream): MCPToolset now receives authentication details from the ADK ReadonlyContext.state, making them available for further transmission, enabling a unified authentication mechanism across all transports. - #805
  2. Improved Unit Tests: Enhancements for better readability and maintainability.

  3. New Sample: Demonstrates passing user tokens to MCP via environment variables, showcasing the dynamic flow from session.state.

  4. Flexible & Secure Integration: Allows for more flexible and secure integration scenarios, supporting distinct authentication credentials per session or user.

pandasanjay avatar Jul 28 '25 08:07 pandasanjay

Hi @hangfei,

I've made the requested changes. Apologies for creating a new branch and pull request—I ran into some issues with the commit history on the previous one.

This pull request contains the latest code along with all the fixes.

pandasanjay avatar Jul 28 '25 09:07 pandasanjay