Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions deep_agent/aegra/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ async def _connect_single_server(
tool_interceptors=[
_TokenInjectorInterceptor(name, server_cfg),
],
tool_name_prefix=bool(server_cfg.get("tool_prefix", name)),
)
tools: list[Any] = await client.get_tools()
logger.info(f"[{name}] loaded {len(tools)} tool(s)")
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/infrastructure/test_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,44 @@ async def test_successful_connection(self):
assert len(tools) == 1
assert tools[0].name == "test_tool"

@pytest.mark.asyncio
async def test_tool_prefix_enables_name_prefix(self):
"""Test that tool_prefix in server_cfg sets tool_name_prefix=True."""
mock_client = MagicMock()
mock_client.get_tools = AsyncMock(return_value=[])

config = {"url": "http://localhost:8000/mcp/", "transport": "http"}
server_cfg = {"tool_prefix": "myprefix"}

with patch(
"deep_agent.aegra.mcp.MultiServerMCPClient",
return_value=mock_client,
) as mock_cls:
await _connect_single_server("myprefix", config, server_cfg, timeout=5)

mock_cls.assert_called_once()
call_kwargs = mock_cls.call_args[1]
assert call_kwargs["tool_name_prefix"] is True

@pytest.mark.asyncio
async def test_no_tool_prefix_falls_back_to_name(self):
"""Test that without tool_prefix, name is used as fallback and prefixing is enabled."""
mock_client = MagicMock()
mock_client.get_tools = AsyncMock(return_value=[])

config = {"url": "http://localhost:8000/mcp/", "transport": "streamable_http"}
server_cfg = {} # no tool_prefix

with patch(
"deep_agent.aegra.mcp.MultiServerMCPClient",
return_value=mock_client,
) as mock_cls:
await _connect_single_server("server-key", config, server_cfg, timeout=5)

mock_cls.assert_called_once()
call_kwargs = mock_cls.call_args[1]
assert call_kwargs["tool_name_prefix"] is True

@pytest.mark.asyncio
async def test_connection_timeout_returns_empty_list(self):
"""Test that connection timeout returns empty list."""
Expand Down
Loading