@@ -143,6 +143,87 @@ def test_agent_tools(self, mock_tools, client):
143143 assert result == [mock_func1 , mock_func2 ]
144144 assert mock_create .call_count == 2
145145
146+ @patch .object (McpdClient , "tools" )
147+ def test_agent_tools_filter_by_single_server (self , mock_tools , client ):
148+ """Test filtering tools by a single server name."""
149+ mock_tools .return_value = {
150+ "server1" : [{"name" : "tool1" , "description" : "Test tool" }],
151+ "server2" : [{"name" : "tool2" , "description" : "Another tool" }],
152+ }
153+
154+ with patch .object (client ._function_builder , "create_function_from_schema" ) as mock_create :
155+ mock_func1 = Mock ()
156+ mock_create .return_value = mock_func1
157+
158+ result = client .agent_tools (servers = ["server1" ])
159+
160+ assert result == [mock_func1 ]
161+ assert mock_create .call_count == 1
162+ mock_create .assert_called_once_with ({"name" : "tool1" , "description" : "Test tool" }, "server1" )
163+
164+ @patch .object (McpdClient , "tools" )
165+ def test_agent_tools_filter_by_multiple_servers (self , mock_tools , client ):
166+ """Test filtering tools by multiple server names."""
167+ mock_tools .return_value = {
168+ "server1" : [{"name" : "tool1" , "description" : "Test tool" }],
169+ "server2" : [{"name" : "tool2" , "description" : "Another tool" }],
170+ "server3" : [{"name" : "tool3" , "description" : "Third tool" }],
171+ }
172+
173+ with patch .object (client ._function_builder , "create_function_from_schema" ) as mock_create :
174+ mock_func1 = Mock ()
175+ mock_func2 = Mock ()
176+ mock_create .side_effect = [mock_func1 , mock_func2 ]
177+
178+ result = client .agent_tools (servers = ["server1" , "server2" ])
179+
180+ assert result == [mock_func1 , mock_func2 ]
181+ assert mock_create .call_count == 2
182+
183+ @patch .object (McpdClient , "tools" )
184+ def test_agent_tools_with_nonexistent_server (self , mock_tools , client ):
185+ """Test filtering with server that doesn't exist."""
186+ mock_tools .return_value = {
187+ "server1" : [{"name" : "tool1" , "description" : "Test tool" }],
188+ }
189+
190+ with patch .object (client ._function_builder , "create_function_from_schema" ) as mock_create :
191+ result = client .agent_tools (servers = ["nonexistent" ])
192+
193+ assert result == []
194+ assert mock_create .call_count == 0
195+
196+ @patch .object (McpdClient , "tools" )
197+ def test_agent_tools_with_empty_servers_list (self , mock_tools , client ):
198+ """Test filtering with empty server list."""
199+ mock_tools .return_value = {
200+ "server1" : [{"name" : "tool1" , "description" : "Test tool" }],
201+ }
202+
203+ with patch .object (client ._function_builder , "create_function_from_schema" ) as mock_create :
204+ result = client .agent_tools (servers = [])
205+
206+ assert result == []
207+ assert mock_create .call_count == 0
208+
209+ @patch .object (McpdClient , "tools" )
210+ def test_agent_tools_without_servers_parameter (self , mock_tools , client ):
211+ """Test existing behavior - returns all tools when servers parameter not provided."""
212+ mock_tools .return_value = {
213+ "server1" : [{"name" : "tool1" , "description" : "Test tool" }],
214+ "server2" : [{"name" : "tool2" , "description" : "Another tool" }],
215+ }
216+
217+ with patch .object (client ._function_builder , "create_function_from_schema" ) as mock_create :
218+ mock_func1 = Mock ()
219+ mock_func2 = Mock ()
220+ mock_create .side_effect = [mock_func1 , mock_func2 ]
221+
222+ result = client .agent_tools ()
223+
224+ assert result == [mock_func1 , mock_func2 ]
225+ assert mock_create .call_count == 2
226+
146227 @patch .object (McpdClient , "tools" )
147228 def test_has_tool_exists (self , mock_tools , client ):
148229 mock_tools .return_value = [{"name" : "existing_tool" }, {"name" : "another_tool" }]
0 commit comments