|
11 | 11 |
|
12 | 12 | import agents._debug as _debug |
13 | 13 | from agents import Agent, FunctionTool, RunContextWrapper, default_tool_error_function |
14 | | -from agents.exceptions import AgentsException, MCPToolCancellationError, ModelBehaviorError |
| 14 | +from agents.exceptions import ( |
| 15 | + AgentsException, |
| 16 | + MCPToolCancellationError, |
| 17 | + ModelBehaviorError, |
| 18 | + UserError, |
| 19 | +) |
15 | 20 | from agents.mcp import MCPServer, MCPUtil |
16 | 21 | from agents.tool_context import ToolContext |
17 | 22 |
|
@@ -83,6 +88,25 @@ async def test_get_all_function_tools(): |
83 | 88 | assert all(tool.name in names for tool in tools) |
84 | 89 |
|
85 | 90 |
|
| 91 | +@pytest.mark.asyncio |
| 92 | +async def test_get_all_function_tools_duplicate_error_is_deterministic(): |
| 93 | + server1 = FakeMCPServer(server_name="server_1") |
| 94 | + server1.add_tool("zeta", {}) |
| 95 | + server1.add_tool("alpha", {}) |
| 96 | + |
| 97 | + server2 = FakeMCPServer(server_name="server_2") |
| 98 | + server2.add_tool("alpha", {}) |
| 99 | + server2.add_tool("zeta", {}) |
| 100 | + |
| 101 | + run_context = RunContextWrapper(context=None) |
| 102 | + agent = Agent(name="test_agent", instructions="Test agent") |
| 103 | + |
| 104 | + with pytest.raises(UserError) as exc_info: |
| 105 | + await MCPUtil.get_all_function_tools([server1, server2], False, run_context, agent) |
| 106 | + |
| 107 | + assert str(exc_info.value) == "Duplicate tool names found across MCP servers: alpha, zeta" |
| 108 | + |
| 109 | + |
86 | 110 | @pytest.mark.asyncio |
87 | 111 | async def test_invoke_mcp_tool(): |
88 | 112 | """Test that the invoke_mcp_tool function invokes an MCP tool and returns the result.""" |
|
0 commit comments