Skip to content

Dynamic authentication handling in MCPToolset from Adk session.state #1198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

pandasanjay
Copy link

@pandasanjay pandasanjay commented Jun 5, 2025

Add authentication information to MCPToolset from Adk session.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 session state to MCP, supporting user-specific authentication flows.

Key Improvements:

  1. Dynamic Token Management:

    • MCPToolset now reads authentication information from the Adk session.state at runtime, enabling dynamic, user-specific token management.
    • STDIO Transport: Authentication information is passed to MCP via environment variables.
    • Other Transports (SSE and HTTP Stream): MCPToolset now receives authentication details from the Adk session.state, making them available for further transmission, enabling a unified authentication mechanism across all transports.
  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.

#805

Copy link

google-cla bot commented Jun 5, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@pandasanjay pandasanjay force-pushed the stdio_mcp_passing_env_from_adk_state branch 3 times, most recently from 6b9f641 to 673d387 Compare June 5, 2025 22:09
…riable functionality

- Updated test_mcp_toolset_auth.py to improve code readability and maintainability by restructuring imports and fixtures.
- Added new test cases to validate the behavior of MCPToolset with both authentication and environment callbacks.
- Enhanced mock setups to ensure proper isolation of tests and avoid dependency issues.
- Refactored test assertions for clarity and consistency.
- Updated test_mcp_toolset_env.py to rename environment transform callback for clarity and improved structure.
- Ensured that tests validate the integration of environment variable extraction and injection with the MCPToolset.
@pandasanjay pandasanjay force-pushed the stdio_mcp_passing_env_from_adk_state branch from afd46e2 to f257b9a Compare June 5, 2025 22:23
@pandasanjay pandasanjay changed the title Add authentication support and refactor tests for MCPToolset Add authentication information to MCPToolset from Adk session.state Jun 5, 2025
@pandasanjay pandasanjay changed the title Add authentication information to MCPToolset from Adk session.state dynamic authentication handling in MCPToolset from Adk session.state Jun 5, 2025
@pandasanjay pandasanjay changed the title dynamic authentication handling in MCPToolset from Adk session.state Dynamic authentication handling in MCPToolset from Adk session.state Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant