1010 AgentResourceType ,
1111)
1212
13- from uipath_langchain .agent .tools .mcp_tool import (
13+ from uipath_langchain .agent .tools .mcp . mcp_tool import (
1414 _deduplicate_tools ,
1515 _filter_tools ,
1616 create_mcp_tools ,
17- create_mcp_tools_from_metadata ,
17+ create_mcp_tools_from_metadata_for_mcp_server ,
1818)
1919
2020
@@ -52,35 +52,19 @@ def _make_mcp_resource(
5252class TestDeduplicateTools :
5353 """Tests for _deduplicate_tools."""
5454
55- def test_no_duplicates_unchanged (self ) -> None :
55+ def test_unique_names_unchanged (self ) -> None :
5656 tools = [_make_tool ("alpha" ), _make_tool ("beta" ), _make_tool ("gamma" )]
5757 result = _deduplicate_tools (tools )
5858 assert [t .name for t in result ] == ["alpha" , "beta" , "gamma" ]
5959
60- def test_all_duplicates_get_suffix (self ) -> None :
61- tools = [_make_tool ("search" ), _make_tool ("search " ), _make_tool ("search" )]
60+ def test_duplicate_names_get_numeric_suffix (self ) -> None :
61+ tools = [_make_tool ("search" ), _make_tool ("calc " ), _make_tool ("search" )]
6262 result = _deduplicate_tools (tools )
63- assert [t .name for t in result ] == ["search_1" , "search_2" , "search_3" ]
64-
65- def test_partial_duplicates (self ) -> None :
66- tools = [
67- _make_tool ("search" ),
68- _make_tool ("calc" ),
69- _make_tool ("search" ),
70- ]
71- result = _deduplicate_tools (tools )
72- assert result [0 ].name == "search_1"
73- assert result [1 ].name == "calc"
74- assert result [2 ].name == "search_2"
63+ assert [t .name for t in result ] == ["search_1" , "calc" , "search_2" ]
7564
7665 def test_empty_list (self ) -> None :
7766 assert _deduplicate_tools ([]) == []
7867
79- def test_single_tool (self ) -> None :
80- tools = [_make_tool ("only" )]
81- result = _deduplicate_tools (tools )
82- assert result [0 ].name == "only"
83-
8468
8569class TestFilterTools :
8670 """Tests for _filter_tools."""
@@ -158,17 +142,11 @@ async def test_disabled_configs_yield_empty(
158142 monkeypatch .setenv ("UIPATH_URL" , "https://example.com" )
159143 monkeypatch .setenv ("UIPATH_ACCESS_TOKEN" , "test-token" )
160144
145+ # Both single config and list of configs should yield empty
161146 cfg = _make_mcp_resource (is_enabled = False )
162147 async with create_mcp_tools (cfg ) as tools :
163148 assert tools == []
164149
165- @pytest .mark .asyncio
166- async def test_all_disabled_in_list_yield_empty (
167- self , monkeypatch : pytest .MonkeyPatch
168- ) -> None :
169- monkeypatch .setenv ("UIPATH_URL" , "https://example.com" )
170- monkeypatch .setenv ("UIPATH_ACCESS_TOKEN" , "test-token" )
171-
172150 configs = [
173151 _make_mcp_resource (is_enabled = False ),
174152 _make_mcp_resource (is_enabled = False ),
@@ -178,10 +156,10 @@ async def test_all_disabled_in_list_yield_empty(
178156
179157
180158class TestCreateMcpToolsFromMetadata :
181- """Tests for create_mcp_tools_from_metadata ."""
159+ """Tests for create_mcp_tools_from_metadata_for_mcp_server ."""
182160
183161 @pytest .mark .asyncio
184- async def test_creates_tools_from_available_tools (self ) -> None :
162+ async def test_creates_tools_with_correct_metadata (self ) -> None :
185163 mcp_tools = [
186164 AgentMcpTool (
187165 name = "get_weather" ,
@@ -201,38 +179,27 @@ async def test_creates_tools_from_available_tools(self) -> None:
201179 ),
202180 ]
203181 cfg = _make_mcp_resource (available_tools = mcp_tools )
182+ mock_client = MagicMock ()
204183
205- tools = await create_mcp_tools_from_metadata (cfg )
184+ tools = await create_mcp_tools_from_metadata_for_mcp_server (cfg , mock_client )
206185
207186 assert len (tools ) == 2
208187 assert tools [0 ].name == "get_weather"
209- assert tools [1 ].name == "search_docs"
210188 assert tools [0 ].description == "Get weather data"
211-
212- @pytest .mark .asyncio
213- async def test_tool_metadata_contains_expected_fields (self ) -> None :
214- mcp_tools = [
215- AgentMcpTool (
216- name = "my_tool" ,
217- description = "A tool" ,
218- inputSchema = {"type" : "object" , "properties" : {}},
219- ),
220- ]
221- cfg = _make_mcp_resource (available_tools = mcp_tools )
222-
223- tools = await create_mcp_tools_from_metadata (cfg )
224-
189+ assert tools [1 ].name == "search_docs"
190+ # Validate metadata on first tool
225191 assert tools [0 ].metadata is not None
226192 assert tools [0 ].metadata ["tool_type" ] == "mcp"
227- assert tools [0 ].metadata ["display_name" ] == "my_tool "
193+ assert tools [0 ].metadata ["display_name" ] == "get_weather "
228194 assert tools [0 ].metadata ["folder_path" ] == "/Shared"
229195 assert tools [0 ].metadata ["slug" ] == "test-slug"
230196
231197 @pytest .mark .asyncio
232198 async def test_empty_available_tools_returns_empty (self ) -> None :
233199 cfg = _make_mcp_resource (available_tools = [])
200+ mock_client = MagicMock ()
234201
235- tools = await create_mcp_tools_from_metadata (cfg )
202+ tools = await create_mcp_tools_from_metadata_for_mcp_server (cfg , mock_client )
236203
237204 assert tools == []
238205
@@ -246,9 +213,9 @@ async def test_tool_name_sanitized(self) -> None:
246213 ),
247214 ]
248215 cfg = _make_mcp_resource (available_tools = mcp_tools )
216+ mock_client = MagicMock ()
249217
250- tools = await create_mcp_tools_from_metadata (cfg )
218+ tools = await create_mcp_tools_from_metadata_for_mcp_server (cfg , mock_client )
251219
252- # sanitize_tool_name replaces spaces with underscores and strips non-alphanum
253220 assert " " not in tools [0 ].name
254221 assert "!" not in tools [0 ].name
0 commit comments