2727from google .adk .auth .auth_credential import AuthCredentialTypes
2828from google .adk .auth .auth_credential import HttpAuth
2929from google .adk .auth .auth_credential import HttpCredentials
30+ from google .adk .auth .auth_credential import OAuth2Auth
3031from google .adk .auth .auth_tool import AuthConfig
3132from google .adk .tools .load_mcp_resource_tool import LoadMcpResourceTool
3233from google .adk .tools .mcp_tool .mcp_session_manager import MCPSessionManager
3536from google .adk .tools .mcp_tool .mcp_session_manager import StreamableHTTPConnectionParams
3637from google .adk .tools .mcp_tool .mcp_tool import MCPTool
3738from google .adk .tools .mcp_tool .mcp_toolset import McpToolset
39+ from google .adk .tools .tool_configs import ToolArgsConfig
3840from mcp import StdioServerParameters
3941from mcp .types import BlobResourceContents
4042from mcp .types import ListResourcesResult
@@ -136,10 +138,8 @@ def test_init_with_tool_filter_list(self):
136138 def test_init_with_auth (self ):
137139 """Test initialization with authentication."""
138140 # Create real auth scheme instances
139- from fastapi .openapi .models import OAuth2
140141
141142 auth_scheme = OAuth2 (flows = {})
142- from google .adk .auth .auth_credential import OAuth2Auth
143143
144144 auth_credential = AuthCredential (
145145 auth_type = "oauth2" ,
@@ -155,6 +155,42 @@ def test_init_with_auth(self):
155155 assert toolset ._auth_scheme == auth_scheme
156156 assert toolset ._auth_credential == auth_credential
157157
158+ def test_init_with_auth_and_credential_key (self ):
159+ """Test initialization with authentication and a custom credential_key."""
160+
161+ auth_scheme = OAuth2 (flows = {})
162+
163+ auth_credential = AuthCredential (
164+ auth_type = "oauth2" ,
165+ oauth2 = OAuth2Auth (client_id = "test_id" , client_secret = "test_secret" ),
166+ )
167+
168+ toolset = McpToolset (
169+ connection_params = self .mock_stdio_params ,
170+ auth_scheme = auth_scheme ,
171+ auth_credential = auth_credential ,
172+ credential_key = "my_custom_key" ,
173+ )
174+
175+ assert toolset ._auth_scheme == auth_scheme
176+ assert toolset ._auth_credential == auth_credential
177+ assert toolset ._auth_config .credential_key == "my_custom_key"
178+
179+ def test_from_config_with_credential_key (self ):
180+ """Test that from_config correctly parses credential_key."""
181+
182+ auth_scheme = OAuth2 (flows = {})
183+
184+ config = ToolArgsConfig (
185+ stdio_server_params = self .mock_stdio_params ,
186+ auth_scheme = auth_scheme ,
187+ credential_key = "my_custom_key" ,
188+ )
189+ toolset = McpToolset .from_config (config , "" )
190+
191+ assert isinstance (toolset ._auth_scheme , OAuth2 )
192+ assert toolset ._auth_config .credential_key == "my_custom_key"
193+
158194 def test_init_missing_connection_params (self ):
159195 """Test initialization with missing connection params raises error."""
160196 with pytest .raises (ValueError , match = "Missing connection params" ):
0 commit comments