alita-sdk 0.3.449__py3-none-any.whl → 0.3.450__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- alita_sdk/runtime/toolkits/mcp.py +5 -2
- alita_sdk/runtime/utils/mcp_sse_client.py +64 -6
- {alita_sdk-0.3.449.dist-info → alita_sdk-0.3.450.dist-info}/METADATA +1 -1
- {alita_sdk-0.3.449.dist-info → alita_sdk-0.3.450.dist-info}/RECORD +7 -7
- {alita_sdk-0.3.449.dist-info → alita_sdk-0.3.450.dist-info}/WHEEL +0 -0
- {alita_sdk-0.3.449.dist-info → alita_sdk-0.3.450.dist-info}/licenses/LICENSE +0 -0
- {alita_sdk-0.3.449.dist-info → alita_sdk-0.3.450.dist-info}/top_level.txt +0 -0
|
@@ -498,9 +498,12 @@ class McpToolkit(BaseToolkit):
|
|
|
498
498
|
all_tools = []
|
|
499
499
|
session_id = connection_config.session_id
|
|
500
500
|
|
|
501
|
+
# Generate temporary session_id if not provided (for OAuth flow)
|
|
502
|
+
# The real session_id should come from frontend after OAuth completes
|
|
501
503
|
if not session_id:
|
|
502
|
-
|
|
503
|
-
|
|
504
|
+
import uuid
|
|
505
|
+
session_id = str(uuid.uuid4())
|
|
506
|
+
logger.info(f"[MCP SSE] Generated temporary session_id for OAuth: {session_id}")
|
|
504
507
|
|
|
505
508
|
logger.info(f"[MCP SSE] Discovering from {connection_config.url} with session {session_id}")
|
|
506
509
|
|
|
@@ -65,6 +65,53 @@ class McpSseClient:
|
|
|
65
65
|
|
|
66
66
|
logger.info(f"[MCP SSE Client] Stream opened: status={self._stream_response.status}")
|
|
67
67
|
|
|
68
|
+
# Handle 401 Unauthorized - need OAuth
|
|
69
|
+
if self._stream_response.status == 401:
|
|
70
|
+
from ..utils.mcp_oauth import (
|
|
71
|
+
McpAuthorizationRequired,
|
|
72
|
+
canonical_resource,
|
|
73
|
+
extract_resource_metadata_url,
|
|
74
|
+
fetch_resource_metadata_async,
|
|
75
|
+
infer_authorization_servers_from_realm,
|
|
76
|
+
fetch_oauth_authorization_server_metadata
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
auth_header = self._stream_response.headers.get('WWW-Authenticate', '')
|
|
80
|
+
resource_metadata_url = extract_resource_metadata_url(auth_header, self.url)
|
|
81
|
+
|
|
82
|
+
metadata = None
|
|
83
|
+
if resource_metadata_url:
|
|
84
|
+
metadata = await fetch_resource_metadata_async(
|
|
85
|
+
resource_metadata_url,
|
|
86
|
+
session=self._stream_session,
|
|
87
|
+
timeout=30
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Infer authorization servers if not in metadata
|
|
91
|
+
if not metadata or not metadata.get('authorization_servers'):
|
|
92
|
+
inferred_servers = infer_authorization_servers_from_realm(auth_header, self.url)
|
|
93
|
+
if inferred_servers:
|
|
94
|
+
if not metadata:
|
|
95
|
+
metadata = {}
|
|
96
|
+
metadata['authorization_servers'] = inferred_servers
|
|
97
|
+
logger.info(f"[MCP SSE Client] Inferred authorization servers: {inferred_servers}")
|
|
98
|
+
|
|
99
|
+
# Fetch OAuth metadata
|
|
100
|
+
auth_server_metadata = fetch_oauth_authorization_server_metadata(inferred_servers[0], timeout=30)
|
|
101
|
+
if auth_server_metadata:
|
|
102
|
+
metadata['oauth_authorization_server'] = auth_server_metadata
|
|
103
|
+
logger.info(f"[MCP SSE Client] Fetched OAuth metadata")
|
|
104
|
+
|
|
105
|
+
raise McpAuthorizationRequired(
|
|
106
|
+
message=f"MCP server {self.url} requires OAuth authorization",
|
|
107
|
+
server_url=canonical_resource(self.url),
|
|
108
|
+
resource_metadata_url=resource_metadata_url,
|
|
109
|
+
www_authenticate=auth_header,
|
|
110
|
+
resource_metadata=metadata,
|
|
111
|
+
status=self._stream_response.status,
|
|
112
|
+
tool_name=self.url,
|
|
113
|
+
)
|
|
114
|
+
|
|
68
115
|
if self._stream_response.status != 200:
|
|
69
116
|
error_text = await self._stream_response.text()
|
|
70
117
|
raise Exception(f"Failed to open SSE stream: HTTP {self._stream_response.status}: {error_text}")
|
|
@@ -248,18 +295,29 @@ class McpSseClient:
|
|
|
248
295
|
"""Close the persistent SSE stream."""
|
|
249
296
|
logger.info(f"[MCP SSE Client] Closing connection...")
|
|
250
297
|
|
|
298
|
+
# Cancel background stream reader task
|
|
251
299
|
if self._stream_task and not self._stream_task.done():
|
|
252
300
|
self._stream_task.cancel()
|
|
253
301
|
try:
|
|
254
302
|
await self._stream_task
|
|
255
|
-
except asyncio.CancelledError:
|
|
256
|
-
|
|
303
|
+
except (asyncio.CancelledError, Exception) as e:
|
|
304
|
+
logger.debug(f"[MCP SSE Client] Stream task cleanup: {e}")
|
|
257
305
|
|
|
258
|
-
|
|
259
|
-
|
|
306
|
+
# Close response stream
|
|
307
|
+
if self._stream_response and not self._stream_response.closed:
|
|
308
|
+
try:
|
|
309
|
+
self._stream_response.close()
|
|
310
|
+
except Exception as e:
|
|
311
|
+
logger.debug(f"[MCP SSE Client] Response close error: {e}")
|
|
260
312
|
|
|
261
|
-
|
|
262
|
-
|
|
313
|
+
# Close session
|
|
314
|
+
if self._stream_session and not self._stream_session.closed:
|
|
315
|
+
try:
|
|
316
|
+
await self._stream_session.close()
|
|
317
|
+
# Give aiohttp time to cleanup
|
|
318
|
+
await asyncio.sleep(0.1)
|
|
319
|
+
except Exception as e:
|
|
320
|
+
logger.debug(f"[MCP SSE Client] Session close error: {e}")
|
|
263
321
|
|
|
264
322
|
logger.info(f"[MCP SSE Client] Connection closed")
|
|
265
323
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: alita_sdk
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.450
|
|
4
4
|
Summary: SDK for building langchain agents using resources from Alita
|
|
5
5
|
Author-email: Artem Rozumenko <artyom.rozumenko@gmail.com>, Mikalai Biazruchka <mikalai_biazruchka@epam.com>, Roman Mitusov <roman_mitusov@epam.com>, Ivan Krakhmaliuk <lifedj27@gmail.com>, Artem Dubrovskiy <ad13box@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -103,7 +103,7 @@ alita_sdk/runtime/toolkits/application.py,sha256=HHAKgwKOckxc7EQG-AV7rz4POOzQJKF
|
|
|
103
103
|
alita_sdk/runtime/toolkits/artifact.py,sha256=YChNCX4QhVpaQG7Jk4TS-Wl0Aruc4slQ2K21zh9nNO0,3176
|
|
104
104
|
alita_sdk/runtime/toolkits/configurations.py,sha256=kIDAlnryPQfbZyFxV-9SzN2-Vefzx06TX1BBdIIpN90,141
|
|
105
105
|
alita_sdk/runtime/toolkits/datasource.py,sha256=qk78OdPoReYPCWwahfkKLbKc4pfsu-061oXRryFLP6I,2498
|
|
106
|
-
alita_sdk/runtime/toolkits/mcp.py,sha256=
|
|
106
|
+
alita_sdk/runtime/toolkits/mcp.py,sha256=wa-47obeWm8WrIiaUw5BR40dsR5sLdQKZHzG7MCRnRM,37105
|
|
107
107
|
alita_sdk/runtime/toolkits/prompt.py,sha256=WIpTkkVYWqIqOWR_LlSWz3ug8uO9tm5jJ7aZYdiGRn0,1192
|
|
108
108
|
alita_sdk/runtime/toolkits/subgraph.py,sha256=wwUK8JjPXkGzyVZ3tAukmvST6eGbqx_U11rpnmbrvtg,2105
|
|
109
109
|
alita_sdk/runtime/toolkits/tools.py,sha256=74R0SadMiUJFUe3U5_PJcxzw5m1KMMBiVfVeiowZK6I,13434
|
|
@@ -137,7 +137,7 @@ alita_sdk/runtime/utils/constants.py,sha256=Xntx1b_uxUzT4clwqHA_U6K8y5bBqf_4lSQw
|
|
|
137
137
|
alita_sdk/runtime/utils/evaluate.py,sha256=iM1P8gzBLHTuSCe85_Ng_h30m52hFuGuhNXJ7kB1tgI,1872
|
|
138
138
|
alita_sdk/runtime/utils/logging.py,sha256=svPyiW8ztDfhqHFITv5FBCj8UhLxz6hWcqGIY6wpJJE,3331
|
|
139
139
|
alita_sdk/runtime/utils/mcp_oauth.py,sha256=Ynoa_C_G5WXL_tlcdol2wBLgQauyvIPX0isCJKsvWMs,6151
|
|
140
|
-
alita_sdk/runtime/utils/mcp_sse_client.py,sha256=
|
|
140
|
+
alita_sdk/runtime/utils/mcp_sse_client.py,sha256=cSOyfnOoxVorfIePQ4k-BmOutBOeL3YDhTNxWtFREA0,16251
|
|
141
141
|
alita_sdk/runtime/utils/save_dataframe.py,sha256=i-E1wp-t4wb17Zq3nA3xYwgSILjoXNizaQAA9opWvxY,1576
|
|
142
142
|
alita_sdk/runtime/utils/streamlit.py,sha256=yIb4YIGH8HRAXZtZlywjxI07Xdcb5eUt7rMA-elFTdc,107261
|
|
143
143
|
alita_sdk/runtime/utils/toolkit_runtime.py,sha256=MU63Fpxj0b5_r1IUUc0Q3-PN9VwL7rUxp2MRR4tmYR8,5136
|
|
@@ -361,8 +361,8 @@ alita_sdk/tools/zephyr_scale/api_wrapper.py,sha256=kT0TbmMvuKhDUZc0i7KO18O38JM9S
|
|
|
361
361
|
alita_sdk/tools/zephyr_squad/__init__.py,sha256=0ne8XLJEQSLOWfzd2HdnqOYmQlUliKHbBED5kW_Vias,2895
|
|
362
362
|
alita_sdk/tools/zephyr_squad/api_wrapper.py,sha256=kmw_xol8YIYFplBLWTqP_VKPRhL_1ItDD0_vXTe_UuI,14906
|
|
363
363
|
alita_sdk/tools/zephyr_squad/zephyr_squad_cloud_client.py,sha256=R371waHsms4sllHCbijKYs90C-9Yu0sSR3N4SUfQOgU,5066
|
|
364
|
-
alita_sdk-0.3.
|
|
365
|
-
alita_sdk-0.3.
|
|
366
|
-
alita_sdk-0.3.
|
|
367
|
-
alita_sdk-0.3.
|
|
368
|
-
alita_sdk-0.3.
|
|
364
|
+
alita_sdk-0.3.450.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
365
|
+
alita_sdk-0.3.450.dist-info/METADATA,sha256=ef9IMngx_rnicjlwr5pbK6rWNCbb8oGxTS4NbiAatuw,19101
|
|
366
|
+
alita_sdk-0.3.450.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
367
|
+
alita_sdk-0.3.450.dist-info/top_level.txt,sha256=0vJYy5p_jK6AwVb1aqXr7Kgqgk3WDtQ6t5C-XI9zkmg,10
|
|
368
|
+
alita_sdk-0.3.450.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|