Skip to content

Commit 0ef5fc8

Browse files
authored
feat: mcp tool late binding (#468)
1 parent 7df90a6 commit 0ef5fc8

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-langchain"
3-
version = "0.5.1"
3+
version = "0.5.2"
44
description = "Python SDK that enables developers to build and deploy LangGraph agents to the UiPath Cloud Platform"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

src/uipath_langchain/agent/tools/mcp_tool.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,6 @@ async def create_mcp_tools_from_metadata(
110110
if config.is_enabled is False:
111111
return []
112112

113-
sdk = UiPath()
114-
mcpServer: McpServer = await sdk.mcp.retrieve_async(
115-
slug=config.slug, folder_path=config.folder_path
116-
)
117-
118-
default_client_kwargs = get_httpx_client_kwargs()
119-
client_kwargs = {
120-
**default_client_kwargs,
121-
"headers": {"Authorization": f"Bearer {sdk._config.secret}"},
122-
"timeout": httpx.Timeout(600),
123-
}
124-
125113
# Lazy import to improve cold start time
126114
from mcp import ClientSession
127115
from mcp.client.streamable_http import streamable_http_client
@@ -132,7 +120,7 @@ async def create_mcp_tools_from_metadata(
132120
tool_name = sanitize_tool_name(mcp_tool.name)
133121
input_model: Any = create_model(mcp_tool.input_schema)
134122

135-
def get_tool_coroutine(mcp_tool: AgentMcpTool, input_model: Any) -> Any:
123+
def build_mcp_tool(mcp_tool: AgentMcpTool, input_model: Any) -> Any:
136124
output_schema: Any
137125
if mcp_tool.output_schema:
138126
output_schema = create_model(mcp_tool.output_schema)
@@ -148,6 +136,18 @@ def get_tool_coroutine(mcp_tool: AgentMcpTool, input_model: Any) -> Any:
148136
async def tool_fn(**kwargs: Any) -> Any:
149137
"""Execute MCP tool call with ephemeral session."""
150138
async with AsyncExitStack() as stack:
139+
sdk = UiPath()
140+
mcpServer: McpServer = await sdk.mcp.retrieve_async(
141+
slug=config.slug, folder_path=config.folder_path
142+
)
143+
144+
default_client_kwargs = get_httpx_client_kwargs()
145+
client_kwargs = {
146+
**default_client_kwargs,
147+
"headers": {"Authorization": f"Bearer {sdk._config.secret}"},
148+
"timeout": httpx.Timeout(600),
149+
}
150+
151151
# Create HTTP client
152152
http_client = await stack.enter_async_context(
153153
httpx.AsyncClient(**client_kwargs)
@@ -176,7 +176,7 @@ async def tool_fn(**kwargs: Any) -> Any:
176176
name=tool_name,
177177
description=mcp_tool.description,
178178
args_schema=input_model,
179-
coroutine=get_tool_coroutine(mcp_tool, input_model),
179+
coroutine=build_mcp_tool(mcp_tool, input_model),
180180
metadata={
181181
"tool_type": "mcp",
182182
"display_name": mcp_tool.name,

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)