-
Notifications
You must be signed in to change notification settings - Fork 5
Update uipath 2.2 #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edis-uipath
wants to merge
1
commit into
main
Choose a base branch
from
feature/update_uipath_2.2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Update uipath 2.2 #159
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "window.title": "${rootName}${separator}${activeEditorMedium}", | ||
| "files.exclude": { | ||
| "**/*.pyc": true, | ||
| "**/__pycache__": true, | ||
| ".pytest_cache": true, | ||
| ".mypy_cache": true, | ||
| ".ruff_cache": true, | ||
| ".venv": true | ||
| }, | ||
| "search.exclude": { | ||
| "**/__pycache__": true, | ||
| "**/*.pyc": true, | ||
| ".venv": true, | ||
| ".pytest_cache": true, | ||
| ".mypy_cache": true, | ||
| ".ruff_cache": true | ||
| }, | ||
| // Formatting | ||
| "editor.formatOnSave": true, | ||
| "[python]": { | ||
| "editor.defaultFormatter": "charliermarsh.ruff", | ||
| "editor.codeActionsOnSave": { | ||
| "source.organizeImports": "explicit" | ||
| } | ||
| }, | ||
| "workbench.colorCustomizations": { | ||
| "titleBar.activeBackground": "#0099cc", | ||
| "titleBar.inactiveBackground": "#0099cc" | ||
| }, | ||
| "python.testing.pytestArgs": [ | ||
| "tests" | ||
| ], | ||
| "python.testing.unittestEnabled": false, | ||
| "python.testing.pytestEnabled": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """UiPath MCP Runtime package.""" | ||
|
|
||
| from uipath.runtime import ( | ||
| UiPathRuntimeContext, | ||
| UiPathRuntimeFactoryProtocol, | ||
| UiPathRuntimeFactoryRegistry, | ||
| ) | ||
|
|
||
| from uipath_mcp._cli._runtime._factory import UiPathMcpRuntimeFactory | ||
| from uipath_mcp._cli._runtime._runtime import UiPathMcpRuntime | ||
|
|
||
|
|
||
| def register_runtime_factory() -> None: | ||
| """Register the MCP factory. Called automatically via entry point.""" | ||
|
|
||
| def create_factory( | ||
| context: UiPathRuntimeContext | None = None, | ||
| ) -> UiPathRuntimeFactoryProtocol: | ||
| return UiPathMcpRuntimeFactory( | ||
| context=context if context else UiPathRuntimeContext(), | ||
| ) | ||
|
|
||
| UiPathRuntimeFactoryRegistry.register("mcp", create_factory, "mcp.json") | ||
|
|
||
|
|
||
| __all__ = [ | ||
| "register_runtime_factory", | ||
| "UiPathMcpRuntimeFactory", | ||
| "UiPathMcpRuntime", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| """Factory for creating MCP runtime instances.""" | ||
|
|
||
| import json | ||
| import logging | ||
| import os | ||
| import uuid | ||
| from typing import Any | ||
|
|
||
| from uipath.runtime import ( | ||
| UiPathRuntimeContext, | ||
| UiPathRuntimeProtocol, | ||
| ) | ||
| from uipath.runtime.errors import UiPathErrorCategory | ||
|
|
||
| from uipath_mcp._cli._runtime._exception import McpErrorCode, UiPathMcpRuntimeError | ||
| from uipath_mcp._cli._runtime._runtime import UiPathMcpRuntime | ||
| from uipath_mcp._cli._utils._config import McpConfig | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class UiPathMcpRuntimeFactory: | ||
| """Factory for creating MCP runtimes from mcp.json configuration.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| context: UiPathRuntimeContext, | ||
| ): | ||
| """Initialize the factory. | ||
|
|
||
| Args: | ||
| context: UiPathRuntimeContext to use for runtime creation. | ||
| """ | ||
| self.context = context | ||
| self._mcp_config: McpConfig | None = None | ||
| self._server_id: str | None = None | ||
| self._server_slug: str | None = None | ||
|
|
||
| # Load fps context from uipath.json if available | ||
| self._load_fps_context() | ||
|
|
||
| def _load_fps_context(self) -> None: | ||
| """ | ||
| Load fps context from uipath.json for server registration. | ||
| """ | ||
| config_path = self.context.config_path or "uipath.json" | ||
| if os.path.exists(config_path): | ||
| try: | ||
| with open(config_path, "r") as f: | ||
| config: dict[str, Any] = json.load(f) | ||
|
|
||
| config_runtime = config.get("runtime", {}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be a part of the UiPathRuntimeContext, let's do something similar to what we did for conversational agents: https://github.com/UiPath/uipath-runtime-python/blob/main/src/uipath/runtime/context.py#L319 |
||
| if "fpsContext" in config_runtime: | ||
| fps_context = config_runtime["fpsContext"] | ||
| self._server_id = fps_context.get("Id") | ||
| self._server_slug = fps_context.get("Slug") | ||
| except Exception as e: | ||
| logger.warning(f"Failed to load fps context: {e}") | ||
|
|
||
| def _load_mcp_config(self) -> McpConfig: | ||
| """Load mcp.json configuration.""" | ||
| if self._mcp_config is None: | ||
| self._mcp_config = McpConfig() | ||
| return self._mcp_config | ||
|
|
||
| def discover_entrypoints(self) -> list[str]: | ||
| """Discover all MCP server entrypoints. | ||
|
|
||
| Returns: | ||
| List of server names that can be used as entrypoints. | ||
| """ | ||
| mcp_config = self._load_mcp_config() | ||
| if not mcp_config.exists: | ||
| return [] | ||
| return mcp_config.get_server_names() | ||
|
|
||
| async def discover_runtimes(self) -> list[UiPathRuntimeProtocol]: | ||
| """Discover runtime instances for all entrypoints. | ||
| This is not running as part of a job, but is intended for the dev machine. | ||
|
|
||
| Returns: | ||
| List of UiPathMcpRuntime instances, one per entrypoint. | ||
| """ | ||
| entrypoints = self.discover_entrypoints() | ||
| runtimes: list[UiPathRuntimeProtocol] = [] | ||
|
|
||
| for entrypoint in entrypoints: | ||
| runtime = await self.new_runtime(entrypoint, entrypoint) | ||
| runtimes.append(runtime) | ||
|
|
||
| return runtimes | ||
|
|
||
| async def new_runtime( | ||
| self, entrypoint: str, runtime_id: str | ||
| ) -> UiPathRuntimeProtocol: | ||
| """Create a new MCP runtime instance. | ||
|
|
||
| Args: | ||
| entrypoint: Server name from mcp.json. | ||
| runtime_id: Unique identifier for the runtime instance. | ||
|
|
||
| Returns: | ||
| Configured UiPathMcpRuntime instance. | ||
|
|
||
| Raises: | ||
| UiPathMcpRuntimeError: If configuration is invalid or server not found. | ||
| """ | ||
| mcp_config = self._load_mcp_config() | ||
|
|
||
| if not mcp_config.exists: | ||
| raise UiPathMcpRuntimeError( | ||
| McpErrorCode.CONFIGURATION_ERROR, | ||
| "Invalid configuration", | ||
| "mcp.json not found", | ||
| UiPathErrorCategory.DEPLOYMENT, | ||
| ) | ||
|
|
||
| server = mcp_config.get_server(entrypoint) | ||
| if not server: | ||
| available = ", ".join(mcp_config.get_server_names()) | ||
| raise UiPathMcpRuntimeError( | ||
| McpErrorCode.SERVER_NOT_FOUND, | ||
| "MCP server not found", | ||
| f"Server '{entrypoint}' not found. Available: {available}", | ||
| UiPathErrorCategory.DEPLOYMENT, | ||
| ) | ||
|
|
||
| # Validate runtime_id is a valid UUID, generate new one if not | ||
| try: | ||
| uuid.UUID(runtime_id) | ||
| except ValueError: | ||
| runtime_id = str(uuid.uuid4()) | ||
|
|
||
| return UiPathMcpRuntime( | ||
| server=server, | ||
| runtime_id=runtime_id, | ||
| entrypoint=entrypoint, | ||
| folder_key=self.context.folder_key, | ||
| server_id=self._server_id, | ||
| server_slug=self._server_slug, | ||
| ) | ||
|
|
||
| async def dispose(self) -> None: | ||
| """Cleanup factory resources.""" | ||
| self._mcp_config = None | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref: https://github.com/UiPath/uipath-python/blob/b2eed6e5d8322855144db0d3b71d2c219d1bdb71/src/uipath/platform/common/_config.py#L27