|
1 | 1 | import pytest
|
2 | 2 |
|
3 |
| -from agents import Agent |
4 |
| -from agents.mcp import MCPUtil |
5 |
| - |
6 | 3 | from .helpers import FakeMCPServer
|
7 | 4 |
|
8 | 5 |
|
@@ -82,142 +79,3 @@ async def test_server_both_filters():
|
82 | 79 | tools = await server.list_tools()
|
83 | 80 | assert len(tools) == 2
|
84 | 81 | assert {t.name for t in tools} == {"tool1", "tool2"}
|
85 |
| - |
86 |
| - |
87 |
| -@pytest.mark.asyncio |
88 |
| -async def test_agent_allowed_tools(): |
89 |
| - """Test that agent-level allowed_tools filters tools correctly""" |
90 |
| - server1 = FilterableFakeMCPServer(server_name="server1") |
91 |
| - server1.add_tool("tool1", {}) |
92 |
| - server1.add_tool("tool2", {}) |
93 |
| - |
94 |
| - server2 = FilterableFakeMCPServer(server_name="server2") |
95 |
| - server2.add_tool("tool3", {}) |
96 |
| - server2.add_tool("tool4", {}) |
97 |
| - |
98 |
| - # Create agent with allowed_tools in mcp_config |
99 |
| - agent = Agent( |
100 |
| - name="test_agent", |
101 |
| - mcp_servers=[server1, server2], |
102 |
| - mcp_config={ |
103 |
| - "allowed_tools": { |
104 |
| - "server1": ["tool1"], |
105 |
| - "server2": ["tool3"], |
106 |
| - } |
107 |
| - } |
108 |
| - ) |
109 |
| - |
110 |
| - # Get tools and verify filtering |
111 |
| - tools = await agent.get_mcp_tools() |
112 |
| - assert len(tools) == 2 |
113 |
| - assert {t.name for t in tools} == {"tool1", "tool3"} |
114 |
| - |
115 |
| - |
116 |
| -@pytest.mark.asyncio |
117 |
| -async def test_agent_excluded_tools(): |
118 |
| - """Test that agent-level excluded_tools filters tools correctly""" |
119 |
| - server1 = FilterableFakeMCPServer(server_name="server1") |
120 |
| - server1.add_tool("tool1", {}) |
121 |
| - server1.add_tool("tool2", {}) |
122 |
| - |
123 |
| - server2 = FilterableFakeMCPServer(server_name="server2") |
124 |
| - server2.add_tool("tool3", {}) |
125 |
| - server2.add_tool("tool4", {}) |
126 |
| - |
127 |
| - # Create agent with excluded_tools in mcp_config |
128 |
| - agent = Agent( |
129 |
| - name="test_agent", |
130 |
| - mcp_servers=[server1, server2], |
131 |
| - mcp_config={ |
132 |
| - "excluded_tools": { |
133 |
| - "server1": ["tool2"], |
134 |
| - "server2": ["tool4"], |
135 |
| - } |
136 |
| - } |
137 |
| - ) |
138 |
| - |
139 |
| - # Get tools and verify filtering |
140 |
| - tools = await agent.get_mcp_tools() |
141 |
| - assert len(tools) == 2 |
142 |
| - assert {t.name for t in tools} == {"tool1", "tool3"} |
143 |
| - |
144 |
| - |
145 |
| -@pytest.mark.asyncio |
146 |
| -async def test_combined_filtering(): |
147 |
| - """Test that server-level and agent-level filtering work together correctly""" |
148 |
| - # Server with its own filtering |
149 |
| - server = FilterableFakeMCPServer(server_name="test_server") |
150 |
| - server.add_tool("tool1", {}) |
151 |
| - server.add_tool("tool2", {}) |
152 |
| - server.add_tool("tool3", {}) |
153 |
| - server.add_tool("tool4", {}) |
154 |
| - server.allowed_tools = ["tool1", "tool2", "tool3"] # Server only exposes these |
155 |
| - |
156 |
| - # Agent with additional filtering |
157 |
| - agent = Agent( |
158 |
| - name="test_agent", |
159 |
| - mcp_servers=[server], |
160 |
| - mcp_config={ |
161 |
| - "excluded_tools": { |
162 |
| - "test_server": ["tool3"], # Agent excludes this one |
163 |
| - } |
164 |
| - } |
165 |
| - ) |
166 |
| - |
167 |
| - # Get tools and verify filtering |
168 |
| - tools = await agent.get_mcp_tools() |
169 |
| - assert len(tools) == 2 |
170 |
| - assert {t.name for t in tools} == {"tool1", "tool2"} |
171 |
| - |
172 |
| - |
173 |
| -@pytest.mark.asyncio |
174 |
| -async def test_util_direct_filtering(): |
175 |
| - """Test MCPUtil.get_all_function_tools with filtering parameters""" |
176 |
| - server1 = FilterableFakeMCPServer(server_name="server1") |
177 |
| - server1.add_tool("tool1", {}) |
178 |
| - server1.add_tool("tool2", {}) |
179 |
| - |
180 |
| - server2 = FilterableFakeMCPServer(server_name="server2") |
181 |
| - server2.add_tool("tool3", {}) |
182 |
| - server2.add_tool("tool4", {}) |
183 |
| - |
184 |
| - # Test direct filtering through MCPUtil |
185 |
| - allowed_tools_map = {"server1": ["tool1"]} |
186 |
| - excluded_tools_map = {"server2": ["tool4"]} |
187 |
| - |
188 |
| - tools = await MCPUtil.get_all_function_tools( |
189 |
| - [server1, server2], |
190 |
| - convert_schemas_to_strict=False, |
191 |
| - allowed_tools_map=allowed_tools_map, |
192 |
| - excluded_tools_map=excluded_tools_map |
193 |
| - ) |
194 |
| - |
195 |
| - assert len(tools) == 2 |
196 |
| - assert {t.name for t in tools} == {"tool1", "tool3"} |
197 |
| - |
198 |
| - |
199 |
| -@pytest.mark.asyncio |
200 |
| -async def test_filtering_priority(): |
201 |
| - """Test that server-level filtering takes priority over agent-level filtering""" |
202 |
| - # Server only exposes tool1 and tool2 |
203 |
| - server = FilterableFakeMCPServer(server_name="test_server") |
204 |
| - server.add_tool("tool1", {}) |
205 |
| - server.add_tool("tool2", {}) |
206 |
| - server.add_tool("tool3", {}) |
207 |
| - server.allowed_tools = ["tool1", "tool2"] |
208 |
| - |
209 |
| - # Agent tries to allow tool3 (which server doesn't expose) |
210 |
| - agent = Agent( |
211 |
| - name="test_agent", |
212 |
| - mcp_servers=[server], |
213 |
| - mcp_config={ |
214 |
| - "allowed_tools": { |
215 |
| - "test_server": ["tool2", "tool3"], # tool3 isn't available from server |
216 |
| - } |
217 |
| - } |
218 |
| - ) |
219 |
| - |
220 |
| - # Get tools and verify filtering |
221 |
| - tools = await agent.get_mcp_tools() |
222 |
| - assert len(tools) == 1 |
223 |
| - assert tools[0].name == "tool2" # Only tool2 passes both filters |
0 commit comments