Skip to content

Commit 4341839

Browse files
wukathcopybara-github
authored andcommitted
chore: Convert MCPToolset to McpToolset in unittests
MCPToolset has been deprecated, use McpToolset instead. Co-authored-by: Kathy Wu <wukathy@google.com> PiperOrigin-RevId: 862457868
1 parent 32f9f92 commit 4341839

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

tests/unittests/tools/mcp_tool/test_mcp_toolset.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
3131
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
3232
from google.adk.tools.mcp_tool.mcp_tool import MCPTool
33-
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
3433
from google.adk.tools.mcp_tool.mcp_toolset import McpToolset
3534
from mcp import StdioServerParameters
3635
from mcp.types import ListResourcesResult
@@ -57,8 +56,8 @@ def __init__(self, tools):
5756
self.tools = tools
5857

5958

60-
class TestMCPToolset:
61-
"""Test suite for MCPToolset class."""
59+
class TestMcpToolset:
60+
"""Test suite for McpToolset class."""
6261

6362
def setup_method(self):
6463
"""Set up test fixtures."""
@@ -73,7 +72,7 @@ def setup_method(self):
7372

7473
def test_init_basic(self):
7574
"""Test basic initialization with StdioServerParameters."""
76-
toolset = MCPToolset(connection_params=self.mock_stdio_params)
75+
toolset = McpToolset(connection_params=self.mock_stdio_params)
7776

7877
# Note: StdioServerParameters gets converted to StdioConnectionParams internally
7978
assert toolset._errlog == sys.stderr
@@ -85,7 +84,7 @@ def test_init_with_stdio_connection_params(self):
8584
stdio_params = StdioConnectionParams(
8685
server_params=self.mock_stdio_params, timeout=10.0
8786
)
88-
toolset = MCPToolset(connection_params=stdio_params)
87+
toolset = McpToolset(connection_params=stdio_params)
8988

9089
assert toolset._connection_params == stdio_params
9190

@@ -94,7 +93,7 @@ def test_init_with_sse_connection_params(self):
9493
sse_params = SseConnectionParams(
9594
url="https://example.com/mcp", headers={"Authorization": "Bearer token"}
9695
)
97-
toolset = MCPToolset(connection_params=sse_params)
96+
toolset = McpToolset(connection_params=sse_params)
9897

9998
assert toolset._connection_params == sse_params
10099

@@ -104,14 +103,14 @@ def test_init_with_streamable_http_params(self):
104103
url="https://example.com/mcp",
105104
headers={"Content-Type": "application/json"},
106105
)
107-
toolset = MCPToolset(connection_params=http_params)
106+
toolset = McpToolset(connection_params=http_params)
108107

109108
assert toolset._connection_params == http_params
110109

111110
def test_init_with_tool_filter_list(self):
112111
"""Test initialization with tool filter as list."""
113112
tool_filter = ["tool1", "tool2"]
114-
toolset = MCPToolset(
113+
toolset = McpToolset(
115114
connection_params=self.mock_stdio_params, tool_filter=tool_filter
116115
)
117116

@@ -132,7 +131,7 @@ def test_init_with_auth(self):
132131
oauth2=OAuth2Auth(client_id="test_id", client_secret="test_secret"),
133132
)
134133

135-
toolset = MCPToolset(
134+
toolset = McpToolset(
136135
connection_params=self.mock_stdio_params,
137136
auth_scheme=auth_scheme,
138137
auth_credential=auth_credential,
@@ -144,7 +143,7 @@ def test_init_with_auth(self):
144143
def test_init_missing_connection_params(self):
145144
"""Test initialization with missing connection params raises error."""
146145
with pytest.raises(ValueError, match="Missing connection params"):
147-
MCPToolset(connection_params=None)
146+
McpToolset(connection_params=None)
148147

149148
@pytest.mark.asyncio
150149
async def test_get_tools_basic(self):
@@ -159,7 +158,7 @@ async def test_get_tools_basic(self):
159158
return_value=MockListToolsResult(mock_tools)
160159
)
161160

162-
toolset = MCPToolset(connection_params=self.mock_stdio_params)
161+
toolset = McpToolset(connection_params=self.mock_stdio_params)
163162
toolset._mcp_session_manager = self.mock_session_manager
164163

165164
tools = await toolset.get_tools()
@@ -185,7 +184,7 @@ async def test_get_tools_with_list_filter(self):
185184
)
186185

187186
tool_filter = ["tool1", "tool3"]
188-
toolset = MCPToolset(
187+
toolset = McpToolset(
189188
connection_params=self.mock_stdio_params, tool_filter=tool_filter
190189
)
191190
toolset._mcp_session_manager = self.mock_session_manager
@@ -213,7 +212,7 @@ def file_tools_filter(tool, context):
213212
"""Filter for file-related tools only."""
214213
return "file" in tool.name
215214

216-
toolset = MCPToolset(
215+
toolset = McpToolset(
217216
connection_params=self.mock_stdio_params, tool_filter=file_tools_filter
218217
)
219218
toolset._mcp_session_manager = self.mock_session_manager
@@ -235,7 +234,7 @@ async def test_get_tools_with_header_provider(self):
235234
expected_headers = {"X-Tenant-ID": "test-tenant"}
236235
header_provider = Mock(return_value=expected_headers)
237236

238-
toolset = MCPToolset(
237+
toolset = McpToolset(
239238
connection_params=self.mock_stdio_params,
240239
header_provider=header_provider,
241240
)
@@ -252,7 +251,7 @@ async def test_get_tools_with_header_provider(self):
252251
@pytest.mark.asyncio
253252
async def test_close_success(self):
254253
"""Test successful cleanup."""
255-
toolset = MCPToolset(connection_params=self.mock_stdio_params)
254+
toolset = McpToolset(connection_params=self.mock_stdio_params)
256255
toolset._mcp_session_manager = self.mock_session_manager
257256

258257
await toolset.close()
@@ -262,7 +261,7 @@ async def test_close_success(self):
262261
@pytest.mark.asyncio
263262
async def test_close_with_exception(self):
264263
"""Test cleanup when session manager raises exception."""
265-
toolset = MCPToolset(connection_params=self.mock_stdio_params)
264+
toolset = McpToolset(connection_params=self.mock_stdio_params)
266265
toolset._mcp_session_manager = self.mock_session_manager
267266

268267
# Mock close to raise an exception
@@ -287,7 +286,7 @@ async def test_get_tools_with_timeout(self):
287286
stdio_params = StdioConnectionParams(
288287
server_params=self.mock_stdio_params, timeout=0.01
289288
)
290-
toolset = MCPToolset(connection_params=stdio_params)
289+
toolset = McpToolset(connection_params=stdio_params)
291290
toolset._mcp_session_manager = self.mock_session_manager
292291

293292
async def long_running_list_tools():
@@ -304,7 +303,7 @@ async def long_running_list_tools():
304303
@pytest.mark.asyncio
305304
async def test_get_tools_retry_decorator(self):
306305
"""Test that get_tools has retry decorator applied."""
307-
toolset = MCPToolset(connection_params=self.mock_stdio_params)
306+
toolset = McpToolset(connection_params=self.mock_stdio_params)
308307

309308
# Check that the method has the retry decorator
310309
assert hasattr(toolset.get_tools, "__wrapped__")
@@ -376,7 +375,7 @@ async def test_list_resources(self):
376375
return_value=list_resources_result
377376
)
378377

379-
toolset = MCPToolset(connection_params=self.mock_stdio_params)
378+
toolset = McpToolset(connection_params=self.mock_stdio_params)
380379
toolset._mcp_session_manager = self.mock_session_manager
381380

382381
result = await toolset.list_resources()
@@ -402,7 +401,7 @@ async def test_get_resource_info_success(self):
402401
return_value=list_resources_result
403402
)
404403

405-
toolset = MCPToolset(connection_params=self.mock_stdio_params)
404+
toolset = McpToolset(connection_params=self.mock_stdio_params)
406405
toolset._mcp_session_manager = self.mock_session_manager
407406

408407
result = await toolset.get_resource_info("data.json")
@@ -427,7 +426,7 @@ async def test_get_resource_info_not_found(self):
427426
return_value=list_resources_result
428427
)
429428

430-
toolset = MCPToolset(connection_params=self.mock_stdio_params)
429+
toolset = McpToolset(connection_params=self.mock_stdio_params)
431430
toolset._mcp_session_manager = self.mock_session_manager
432431

433432
with pytest.raises(
@@ -482,7 +481,7 @@ async def test_read_resource(
482481
get_resource_result.encoding = encoding
483482
self.mock_session.get_resource = AsyncMock(return_value=get_resource_result)
484483

485-
toolset = MCPToolset(connection_params=self.mock_stdio_params)
484+
toolset = McpToolset(connection_params=self.mock_stdio_params)
486485
toolset._mcp_session_manager = self.mock_session_manager
487486

488487
result = await toolset.read_resource(name)

0 commit comments

Comments
 (0)