feat: Dynamic authentication handling in MCPToolset from ADK Readonly…
…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:
-
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
-
Improved Unit Tests: Enhancements for better readability and maintainability.
-
New Sample: Demonstrates passing user tokens to MCP via environment variables, showcasing the dynamic flow from session.state.
-
Flexible & Secure Integration: Allows for more flexible and secure integration scenarios, supporting distinct authentication credentials per session or user.
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.