Replies: 3 comments 4 replies
-
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: The recommended approach is to use ADK's built-in authentication mechanisms by passing Hello! I'm an AI assistant, and I'm here to help with your questions about passing user-specific tokens. Here's a breakdown of best practices based on the information I found in the ADK documentation: 1. Token InjectionThe ADK provides a robust, built-in system for handling authentication, so you don't need to manually inject tokens at the request layer or create custom middleware. The recommended approach is to define your authentication requirements when you initialize the For example, to use a header-based API key, you could configure your toolset like this: from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
from google.adk.auth.auth_schemes import APIKey
from google.adk.auth.auth_schemes import APIKeyIn
from google.adk.auth.auth_credential import AuthCredential
# Define the authentication scheme for a header-based API key
auth_scheme = APIKey(type='apiKey', name='X-My-Custom-Header', in_val=APIKeyIn.header)
# Provide the user-specific token as a credential
auth_credential = AuthCredential(auth_type='API_KEY', api_key='user-specific-token-value')
# Initialize the MCPToolset with the auth configuration
mcp_toolset = MCPToolset(
connection_params=...,
auth_scheme=auth_scheme,
auth_credential=auth_credential
) The ADK will then manage the process of attaching the token to the request headers. [7] For more complex scenarios like OAuth2, the ADK can even handle the token exchange flow. [1] 2. Token StorageStoring tokens directly in the session state can be a security risk, especially in a production environment. [1] Here's the recommended approach:
3. Preventing Token ExposureTo prevent tokens from being logged, you should:
4. Conventions for Header-Based AuthenticationThe ADK codebase has several conventions and examples for header-based authentication that you can follow:
By following these guidelines, you can build a secure and robust integration with your MCP tool. I hope this information is helpful! This response was generated by an AI assistant. Please verify any critical information. |
Beta Was this translation helpful? Give feedback.
-
Some of my views are here: Should the token be stored per user session in memory, or retrieved fresh from a secure store (e.g., Vault) each time? Are there any existing conventions in our codebase for header-based auth that I should follow? |
Beta Was this translation helpful? Give feedback.
-
copying on above @haribabu-kasturi , extending his question. So I have protected my MCP with Oauth2.0, so whenever i call my MCP /mcp endpoint i need to authenticate with oauth token as header. So currently from my ADK i need to generate a token with client_id and client secret . And store that token somewhere in a place within the ADK state . And reuse it across the multiple MCPToolset which uses from
This is how i have used but i want to pass from root_agent , so i want to generate token. So for token generation do i need to write a separate function or is there a way or any kind of wrapper which can generate the token for me ? Would this be ideal way ?
i feel like paasing token directly not safe. i want a wrapper from root_agent, like before even agent starts when we hit agent the first callback has to be made in generating tokens and passing it safely. Can someone please give me a good end-to-end example ? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I’m working on integrating our MCP tool and need to send different authentication tokens for each user request.
The goal is:
Authorization: Bearer <token>
).Questions for discussion:
Example idea:
Looking forward to your input on security best practices and architecture for this.
Beta Was this translation helpful? Give feedback.
All reactions