MCPToolset ignores auth_scheme/auth_credential during initialization and tool listing
Describe the bug
When passing auth_scheme and auth_credential to MCPToolset, the authentication is not performed during the MCP initialization and tool listing phases. This results in a failure when using authenticated MCP services.
To Reproduce
Steps to reproduce the behavior:
1.Install the MCP server:
pip install fastmcp
2.Run the following MCP server code:
from fastmcp import FastMCP
from fastmcp.server.auth import BearerAuthProvider
from fastmcp.server.auth.providers.bearer import RSAKeyPair
key_pair = RSAKeyPair.generate()
auth = BearerAuthProvider(
public_key=key_pair.public_key,
issuer="https://dev.example.com",
audience="my-dev-server"
)
token = key_pair.create_token(
subject="test_user",
issuer="https://dev.example.com"
)
print("token:", token) # paste the token to next
mcp = FastMCP(name="My MCP Server", auth=auth)
@mcp.tool
def real_time() -> str:
return "2025-07-24 12:30"
if __name__ == "__main__":
mcp.run(port=8080)
- Use the following ADK client code to access the server:
from google.adk.agents.llm_agent import LlmAgent
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPServerParams
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
from google.adk.tools.openapi_tool.auth.auth_helpers import token_to_scheme_credential
token = "your paste token"
auth_scheme, auth_credential = token_to_scheme_credential(
"oauth2Token", "header", "Authorization", token
)
root_agent = LlmAgent(
model="gemini-2.0-flash",
name='Assistant',
instruction="""You are a professional assistant with access to real-time tool.""",
tools=[
MCPToolset(
connection_params=StreamableHTTPServerParams(
url='https://127.0.0.1:8080/mcp/',
),
auth_scheme=auth_scheme,
auth_credential=auth_credential
)
],
)
-
Run agent and ask any question.
-
See the error due to missing authentication.
Expected behavior
The MCPToolset should correctly apply the auth_scheme and auth_credential during the initialization and tool listing phases, ensuring authentication occurs as expected and the tool can be invoked successfully.
Screenshots
Desktop:
- OS: Mac OS
- Python version: python 3.11.9
- ADK version: v1.8.0
Model Information:
Model: gemini-2.0-flash
Additional context
Trying to post the same issue as well. Thank you @chyok @seanzhou1023 @chyok @hangfei I have a following question. Are there any plans for the MCPToolset to comply with the MCP authorization spec [1]? Specifically, if the MCP server requires client authentication credentials, will the client first request authorization server information from an OAuth-protected resource, and then send a request to /oauth-authorization-server to obtain authorization information?
[1]https://modelcontextprotocol.io/specification/draft/basic/authorization#authorization-flow-steps
Bumping this - there seems to be auth support for MCPs in the Google ADK source code (auth_scheme, auth_credentials parameters) but it isn't well documented. Many modern MCPs require authentication so it would be great if this could be implemented down the line!
yes, the auth scheme and auth credentials here are for tool calling only. we cannot reuse same field for tool listing because tool listing could have different auth requirement as tool calling.
we will add new field to handle that.
Hi @seanzhou1023 I'm curious how the new field may looks like, Also if both MCP Server an the underlying tool calling are required "Authorization" header, how ADK may handle it?
E.g: MCP enable authorization and it is using Google OAuth as provider, and tool calling also need authorization from third party service (e.g: Azure AD)
User -(header "Authorization": "Bearer
yes, the auth scheme and auth credentials here are for tool calling only. we cannot reuse same field for tool listing because tool listing could have different auth requirement as tool calling.
we will add new field to handle that.
Why would tool listing have different auth requirement? Having different auths per resource will make it more complicated.
@seanzhou1023 the MCP specification says that all endpoints (including both LIST tools and CALL tools) should be authenticated with an access token obtained by an Oauth flow. It doesnt mention that there is a different auth requirement for LIST, nor does is say that LIST should not be authenticated.
The issue is that ADK calls the LIST tools endpoint when the agent is initialized rather than when a user session has started. I think this will have to be moved to when the user session is created so that the API call to LIST tools has access to a user access token.
I think this issue should be labeled as a bug rather than a feature because ADK does not handle MCP according to specification.
Regarding this statement:
yes, the auth scheme and auth credentials here are for tool calling only. we cannot reuse same field for tool listing because tool listing could have different auth requirement as tool calling.
I don't know of a single proper use-case where this is true. No one is asking for this. Beyond ADK, I don't know of any other client that accommodates different auth for tools/list and tools/call on the same MCP Server.
The real request here is to use the auth_scheme and auth_credential before making the tools/list call. It's that simple.
A couple other things:
-
while the spec includes a sequence diagram showing the client trying to invoke something, getting a 401, and only then using the auth discovery endpoints,.... if the client (built on ADK) already knows that the
tools/listcall requires auth, there's no requirement in the spec that the client MUST make an initial unauthenticated call. ADK can skip that and go right to discovery. -
the MCP specification requires that MCP clients use discovery: MCP clients MUST follow the OAuth 2.0 Authorization Server Metadata protocol defined in RFC8414. BUT, if the client-side configuration of an MCP server includes the tokenUrl and authorizationUrl, then discovery is unnecessary and the client can just build the /authorize URI and proceed.
Any official plans to progress on this? although we can workaround this just passing custom headers to the connection params, I think this should be fixed to work as the other tools. Additionally, the logs are noise also due to the missing auth_scheme.
Thank you!
Any official plans to progress on this? although we can workaround this just passing custom headers to the connection params, I think this should be fixed to work as the other tools. Additionally, the logs are noise also due to the missing
auth_scheme.Thank you!
the auth_schema issue is fixed now.
This issue is not fixed. The auth_scheme and auth_credential parameters in McpToolset are not used during the initial "List Tools" call. Instead, authentication for listing tools depends on the token provided in StreamableHTTPConnectionParams.headers. Therefore, I had to generate and inject the token directly into StreamableHTTPConnectionParams for the "List Tools" operation
I also don't see how this is fixed, I stil run into the same issues.
@hangfei Can you clarify, what specifically do you mean by "the auth_schema issue" in this comment?
the auth_schema issue is fixed now.
@darkmars27
I had to generate and inject the token directly into StreamableHTTPConnectionParams for the "List Tools" operation
Can you explain how? or share a gist?
Is there any update on this issue? Seems to be still a issue
I used the MCcpToolSet header_provider parameter as a work around
agent.py
from typing import Dict
from google.adk.agents.llm_agent import LlmAgent
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPServerParams
from google.adk.tools.mcp_tool.mcp_toolset import McpToolset
from google.adk.tools.openapi_tool.auth.auth_helpers import token_to_scheme_credential
from google.adk.agents.readonly_context import ReadonlyContext
token = "..."
auth_scheme, auth_credential = token_to_scheme_credential(
"oauth2Token", "header", "Authorization", token
)
def auth_header(context: ReadonlyContext) -> Dict[str, str]:
return {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
root_agent = LlmAgent(
model="gemini-2.5-flash",
name='Assistant',
instruction="""You are a professional assistant with access to real-time tool.""",
tools=[
McpToolset(
connection_params=StreamableHTTPServerParams(
url='http://127.0.0.1:8080/mcp',
),
auth_scheme=auth_scheme,
auth_credential=auth_credential,
header_provider=auth_header
)
],
)
mcp_server.py
from fastmcp import FastMCP
from fastmcp.server.auth import JWTVerifier
from fastmcp.server.auth.providers.jwt import RSAKeyPair
# Generate a key pair for testing
key_pair = RSAKeyPair.generate()
# Configure your server with the public key
verifier = JWTVerifier(
public_key=key_pair.public_key,
issuer="https://test.yourcompany.com",
audience="test-mcp-server"
)
# Generate a test token using the private key
test_token = key_pair.create_token(
subject="test-user-123",
issuer="https://test.yourcompany.com",
audience="test-mcp-server",
scopes=["read", "write", "admin"]
)
print(f"Test token: {test_token}")
mcp = FastMCP(name="My MCP Server", auth=verifier)
@mcp.tool
def real_time() -> str:
return "2025-07-24 12:30"
if __name__ == "__main__":
mcp.run(transport="streamable-http", port=8080)
That is a workaround but it does not integrate with the auth_scheme. In other words if auth_Scheme is oauth2 , this approach of using a header provider does not kick off the OAuth2 signin. right?
@wukath there is still a bug after your PR. ReadonlyContext object has no attribute ‘load_credential’ , your unittest pass is because yku mock get_auth_credential from Credential Manager…..
@seanzhou1023
I just pull the latest ADK code and try to test it. Unfortunately, it still not working, self._header_provider is None and also readonly_context doesn't have access_token within state as well, it cause headers is still None, so we can't list tool if MCP server is auth protected. Can we reopen this ticket....?
https://github.com/google/adk-python/blob/e3d542a5ba3d357407f8cd29cfdd722f583c8564/src/google/adk/tools/mcp_tool/mcp_toolset.py#L157-L161
sorry for the back and forth, we've rolled back the old change and are we're working on a different approach now
Thank you @wukath @seanzhou1023 . Very appreciate your hard work for this. If you need any end-to-end testing after next change. I am willing to do so