|
5 | 5 | import tempfile |
6 | 6 | from typing import Any, Dict, Optional |
7 | 7 |
|
| 8 | +import mcp.types as types |
8 | 9 | from mcp import ClientSession, StdioServerParameters |
9 | 10 | from mcp.client.stdio import stdio_client |
10 | 11 | from opentelemetry import trace |
@@ -272,7 +273,6 @@ async def _register(self) -> None: |
272 | 273 | except BaseException as e: |
273 | 274 | logger.error(f"Error during server initialization: {e}") |
274 | 275 |
|
275 | | - |
276 | 276 | # Now that we're outside the context managers, check if initialization succeeded |
277 | 277 | if not initialization_successful: |
278 | 278 | await self.dispose_session() |
@@ -329,7 +329,25 @@ async def dispose_session(self) -> None: |
329 | 329 | try: |
330 | 330 | response = self._uipath.api_client.request( |
331 | 331 | "POST", |
332 | | - f"mcp_/mcp/{self.server.name}/dispose?sessionId={self.server.session_id}" |
| 332 | + f"mcp_/mcp/{self.server.name}/out/message?sessionId={self.server.session_id}", |
| 333 | + json=types.JSONRPCNotification( |
| 334 | + jsonrpc="2.0", |
| 335 | + method="notifications/cancelled", |
| 336 | + params={"requestId": "*"}, |
| 337 | + ).model_dump(), |
| 338 | + ) |
| 339 | + if response.status_code == 202: |
| 340 | + logger.info( |
| 341 | + f"Sent outgoing cancelled message to UiPath MCP Server: {self.server.session_id}" |
| 342 | + ) |
| 343 | + else: |
| 344 | + logger.error( |
| 345 | + f"Error sending outgoing cancelled message to to UiPath MCP Server: {response.status_code} - {response.text}" |
| 346 | + ) |
| 347 | + |
| 348 | + response = self._uipath.api_client.request( |
| 349 | + "POST", |
| 350 | + f"mcp_/mcp/{self.server.name}/dispose?sessionId={self.server.session_id}", |
333 | 351 | ) |
334 | 352 | if response.status_code == 202: |
335 | 353 | logger.info( |
|
0 commit comments