Skip to content

Commit 0de20d8

Browse files
committed
Fix: Send folderKey on SignalR connect
1 parent 8cb3415 commit 0de20d8

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

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-mcp"
3-
version = "0.0.96"
3+
version = "0.0.97"
44
description = "UiPath MCP SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

src/uipath_mcp/_cli/_runtime/_context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class UiPathMcpRuntimeContext(UiPathRuntimeContext):
1010
"""Context information passed throughout the runtime execution."""
1111

1212
config: Optional[McpConfig] = None
13+
folder_key: str
1314

1415

1516
class UiPathServerType(Enum):

src/uipath_mcp/_cli/_runtime/_runtime.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from opentelemetry.sdk.trace import TracerProvider
1515
from opentelemetry.sdk.trace.export import BatchSpanProcessor
1616
from pysignalr.client import CompletionMessage, SignalRClient
17+
from uipath import UiPath
1718
from uipath._cli._runtime._contracts import (
1819
UiPathBaseRuntime,
1920
UiPathErrorCategory,
@@ -25,7 +26,6 @@
2526
from ._context import UiPathMcpRuntimeContext, UiPathServerType
2627
from ._exception import UiPathMcpRuntimeError
2728
from ._session import SessionServer
28-
from uipath import UiPath
2929

3030
logger = logging.getLogger(__name__)
3131
tracer = trace.get_tracer(__name__)
@@ -76,6 +76,26 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
7676
# Set up SignalR client
7777
signalr_url = f"{os.environ.get('UIPATH_URL')}/agenthub_/wsstunnel?slug={self._server.name}&runtimeId={self._runtime_id}"
7878

79+
if not self.context.folder_key:
80+
folder_path = os.environ.get("UIPATH_FOLDER_PATH")
81+
if not folder_path:
82+
raise UiPathMcpRuntimeError(
83+
"REGISTRATION_ERROR",
84+
"No UIPATH_FOLDER_PATH or UIPATH_FOLDER_KEY environment variable set.",
85+
"Please set the UIPATH_FOLDER_PATH or UIPATH_FOLDER_KEY environment variable.",
86+
UiPathErrorCategory.USER,
87+
)
88+
self.context.folder_key = self._uipath.folders.retrieve_key(folder_path=folder_path)
89+
if not self.context.folder_key:
90+
raise UiPathMcpRuntimeError(
91+
"REGISTRATION_ERROR",
92+
"Folder NOT FOUND. Invalid UIPATH_FOLDER_PATH environment variable.",
93+
"Please set the UIPATH_FOLDER_PATH or UIPATH_FOLDER_KEY environment variable.",
94+
UiPathErrorCategory.USER,
95+
)
96+
97+
logger.info(f"Folder key: {self.context.folder_key}")
98+
7999
with tracer.start_as_current_span(self._server.name) as root_span:
80100
root_span.set_attribute("runtime_id", self._runtime_id)
81101
root_span.set_attribute("command", self._server.command)
@@ -86,6 +106,7 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
86106
headers={
87107
"X-UiPath-Internal-TenantId": self.context.trace_context.tenant_id,
88108
"X-UiPath-Internal-AccountId": self.context.trace_context.org_id,
109+
"X-UIPATH-FolderKey": self.context.folder_key,
89110
},
90111
)
91112
self._signalr_client.on("MessageReceived", self._handle_signalr_message)
@@ -273,21 +294,6 @@ async def _handle_signalr_close(self) -> None:
273294
async def _register(self) -> None:
274295
"""Register the MCP server with UiPath."""
275296

276-
folder_key = os.environ.get("UIPATH_FOLDER_KEY")
277-
folder_path = os.environ.get("UIPATH_FOLDER_PATH")
278-
if not folder_key and not folder_path:
279-
raise UiPathMcpRuntimeError(
280-
"REGISTRATION_ERROR",
281-
"No UIPATH_FOLDER_PATH or UIPATH_FOLDER_KEY environment variable set.",
282-
"Please set the UIPATH_FOLDER_PATH or UIPATH_FOLDER_KEY environment variable.",
283-
UiPathErrorCategory.USER,
284-
)
285-
if not folder_key:
286-
uipath = UiPath()
287-
folder_key = uipath.folders.retrieve_key(folder_path=folder_path)
288-
289-
logger.info(f"Folder key: {folder_key}")
290-
291297
initialization_successful = False
292298
tools_result = None
293299
server_stderr_output = ""
@@ -386,7 +392,7 @@ async def _register(self) -> None:
386392
"POST",
387393
f"agenthub_/mcp/{self._server.name}/runtime/start?runtimeId={self._runtime_id}",
388394
json=client_info,
389-
headers={"X-UIPATH-FolderKey": folder_key},
395+
headers={"X-UIPATH-FolderKey": self.context.folder_key},
390396
)
391397
logger.info("Registered MCP Server type successfully")
392398
except Exception as e:

src/uipath_mcp/_cli/cli_run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ async def execute():
3939
context.resume = resume
4040
context.logs_min_level = env.get("LOG_LEVEL", "INFO")
4141
context.job_id = env.get("UIPATH_JOB_KEY")
42+
context.folder_key = env.get("UIPATH_FOLDER_KEY")
4243
context.trace_id = env.get("UIPATH_TRACE_ID")
4344
context.tracing_enabled = env.get("UIPATH_TRACING_ENABLED", True)
4445
context.trace_context = UiPathTraceContext(

0 commit comments

Comments
 (0)