3636from google .adk .agents .remote_a2a_agent import RemoteA2aAgent
3737from google .adk .auth .auth_credential import AuthCredential
3838from google .adk .auth .auth_schemes import AuthScheme
39+ from google .adk .integrations .agent_identity .gcp_auth_provider_scheme import GcpAuthProviderScheme
3940from google .adk .telemetry .tracing import GCP_MCP_SERVER_DESTINATION_ID
4041from google .adk .tools .base_tool import BaseTool
4142from google .adk .tools .mcp_tool .mcp_session_manager import SseConnectionParams
@@ -292,8 +293,24 @@ def get_mcp_toolset(
292293 mcp_server_name : str ,
293294 auth_scheme : AuthScheme | None = None ,
294295 auth_credential : AuthCredential | None = None ,
296+ * ,
297+ continue_uri : str | None = None ,
295298 ) -> McpToolset :
296- """Constructs an McpToolset instance from a registered MCP Server."""
299+ """Constructs an McpToolset from a registered MCP Server.
300+
301+ If `auth_scheme` is omitted, it is automatically resolved from the server's
302+ IAM bindings via `GcpAuthProviderScheme`.
303+
304+ Args:
305+ mcp_server_name: Resource name of the MCP Server.
306+ auth_scheme: Optional auth scheme. Resolved via bindings if omitted.
307+ auth_credential: Optional auth credential.
308+ continue_uri: Optional continue URI to override what is in the auth
309+ provider.
310+
311+ Returns:
312+ An McpToolset for the MCP server.
313+ """
297314 server_details = self .get_mcp_server (mcp_server_name )
298315 name = self ._clean_name (server_details .get ("displayName" , mcp_server_name ))
299316 mcp_server_id = server_details .get ("mcpServerId" )
@@ -313,6 +330,23 @@ def get_mcp_toolset(
313330 )
314331
315332 headers = self ._get_auth_headers () if _is_google_api (endpoint_uri ) else None
333+ if mcp_server_id and not auth_scheme :
334+ try :
335+ bindings_data = self ._make_request ("bindings" )
336+ for b in bindings_data .get ("bindings" , []):
337+ target_id = b .get ("target" , {}).get ("identifier" , "" )
338+ if target_id .endswith (mcp_server_id ):
339+ auth_provider = b .get ("authProviderBinding" , {}).get ("authProvider" )
340+ if auth_provider :
341+ auth_scheme = GcpAuthProviderScheme (
342+ name = auth_provider , continue_uri = continue_uri
343+ )
344+ break
345+ except Exception as e :
346+ logger .warning (
347+ f"Failed to fetch bindings for MCP Server { mcp_server_name } : { e } "
348+ )
349+
316350 connection_params = StreamableHTTPConnectionParams (
317351 url = endpoint_uri ,
318352 headers = headers ,
0 commit comments