Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0dce65c
fix(mcp): Initialize tool_name_prefix in MCPToolse
shsha4 Sep 2, 2025
5e21bc2
fix(mcp): Use original tool name when calling MCP server
shsha4 Sep 5, 2025
df0dfdd
fix(mcp): Initialize tool_name_prefix in MCPToolse
shsha4 Sep 2, 2025
1cd9ff4
fix(mcp): Use original tool name when calling MCP server
shsha4 Sep 5, 2025
6853afb
Merge branch 'fix/issue-2814' of https://github.com/shsha4/adk-python…
shsha4 Sep 6, 2025
a8eea55
fix(mcp): Make tool_name_prefix parameter optional in McpToolset
shsha4 Sep 6, 2025
56285aa
Merge branch 'main' into fix/issue-2814
seanzhou1023 Sep 8, 2025
fd396bf
test: Skip MCP tests when Python version is less than 3.10
shsha4 Sep 9, 2025
276f068
fix(mcp): Initialize tool_name_prefix in MCPToolse
shsha4 Sep 2, 2025
b23a49b
fix(mcp): Use original tool name when calling MCP server
shsha4 Sep 5, 2025
ec370b5
fix(mcp): Make tool_name_prefix parameter optional in McpToolset
shsha4 Sep 6, 2025
0705450
test: Skip MCP tests when Python version is less than 3.10
shsha4 Sep 9, 2025
6679309
Merge branch 'main' into fix/issue-2814
seanzhou1023 Sep 19, 2025
d40a846
Merge branch 'fix/issue-2814' of https://github.com/shsha4/adk-python…
shsha4 Sep 20, 2025
1778a2d
fix(mcp): Initialize tool_name_prefix in MCPToolse
shsha4 Sep 2, 2025
0a1676e
fix(mcp): Use original tool name when calling MCP server
shsha4 Sep 5, 2025
36c5433
fix(mcp): Make tool_name_prefix parameter optional in McpToolset
shsha4 Sep 6, 2025
2e384d4
test: Skip MCP tests when Python version is less than 3.10
shsha4 Sep 9, 2025
ef5159c
Merge branch 'fix/issue-2814' of https://github.com/shsha4/adk-python…
shsha4 Sep 20, 2025
e8e5b0d
style: Run autoformat.sh to resolve formatting issues
shsha4 Sep 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/google/adk/tools/mcp_tool/mcp_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def _run_async_impl(
# Get the session from the session manager
session = await self._mcp_session_manager.create_session(headers=headers)

response = await session.call_tool(self.name, arguments=args)
response = await session.call_tool(self._mcp_tool.name, arguments=args)
return response

async def _get_headers(
Expand Down
8 changes: 7 additions & 1 deletion src/google/adk/tools/mcp_tool/mcp_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(
StreamableHTTPConnectionParams,
],
tool_filter: Optional[Union[ToolPredicate, List[str]]] = None,
tool_name_prefix: Optional[str] = None,
errlog: TextIO = sys.stderr,
auth_scheme: Optional[AuthScheme] = None,
auth_credential: Optional[AuthCredential] = None,
Expand All @@ -118,11 +119,13 @@ def __init__(
tool_filter: Optional filter to select specific tools. Can be either: - A
list of tool names to include - A ToolPredicate function for custom
filtering logic
tool_name_prefix: A prefix to be added to the name of each tool in this
toolset.
errlog: TextIO stream for error logging.
auth_scheme: The auth scheme of the tool for tool calling
auth_credential: The auth credential of the tool for tool calling
"""
super().__init__(tool_filter=tool_filter)
super().__init__(tool_filter=tool_filter, tool_name_prefix=tool_name_prefix)

if not connection_params:
raise ValueError("Missing connection params in MCPToolset.")
Expand Down Expand Up @@ -207,6 +210,7 @@ def from_config(
return cls(
connection_params=connection_params,
tool_filter=mcp_toolset_config.tool_filter,
tool_name_prefix=mcp_toolset_config.tool_name_prefix,
auth_scheme=mcp_toolset_config.auth_scheme,
auth_credential=mcp_toolset_config.auth_credential,
)
Expand Down Expand Up @@ -239,6 +243,8 @@ class McpToolsetConfig(BaseToolConfig):

tool_filter: Optional[List[str]] = None

tool_name_prefix: Optional[str] = None

auth_scheme: Optional[AuthScheme] = None

auth_credential: Optional[AuthCredential] = None
Expand Down
89 changes: 89 additions & 0 deletions tests/unittests/tools/test_mcp_toolset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Unit tests for McpToolset."""

import sys
from unittest.mock import AsyncMock
from unittest.mock import MagicMock

import pytest

# Skip all tests in this module if Python version is less than 3.10
pytestmark = pytest.mark.skipif(
sys.version_info < (3, 10), reason="MCP tool requires Python 3.10+"
)

# Import dependencies with version checking
try:
from google.adk.tools.mcp_tool.mcp_toolset import McpToolset
except ImportError as e:
if sys.version_info < (3, 10):
# Create dummy classes to prevent NameError during test collection
# Tests will be skipped anyway due to pytestmark
class DummyClass:
pass

McpToolset = DummyClass
else:
raise e


@pytest.mark.asyncio
async def test_mcp_toolset_with_prefix():
"""Test that McpToolset correctly applies the tool_name_prefix."""
# Mock the connection parameters
mock_connection_params = MagicMock()

# Mock the MCPSessionManager and its create_session method
mock_session_manager = MagicMock()
mock_session = MagicMock()

# Mock the list_tools response from the MCP server
mock_tool1 = MagicMock()
mock_tool1.name = "tool1"
mock_tool1.description = "tool 1 desc"
mock_tool2 = MagicMock()
mock_tool2.name = "tool2"
mock_tool2.description = "tool 2 desc"
list_tools_result = MagicMock()
list_tools_result.tools = [mock_tool1, mock_tool2]
mock_session.list_tools = AsyncMock(return_value=list_tools_result)
mock_session_manager.create_session = AsyncMock(return_value=mock_session)

# Create an instance of McpToolset with a prefix
toolset = McpToolset(
connection_params=mock_connection_params,
tool_name_prefix="my_prefix",
)

# Replace the internal session manager with our mock
toolset._mcp_session_manager = mock_session_manager

# Get the tools from the toolset
tools = await toolset.get_tools()

# The get_tools method in McpToolset returns MCPTool objects, which are
# instances of BaseTool. The prefixing is handled by the BaseToolset,
# so we need to call get_tools_with_prefix to get the prefixed tools.
prefixed_tools = await toolset.get_tools_with_prefix()

# Assert that the tools are prefixed correctly
assert len(prefixed_tools) == 2
assert prefixed_tools[0].name == "my_prefix_tool1"
assert prefixed_tools[1].name == "my_prefix_tool2"

# Assert that the original tools are not modified
assert tools[0].name == "tool1"
assert tools[1].name == "tool2"