alita-sdk 0.3.446__py3-none-any.whl → 0.3.448__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.
Potentially problematic release.
This version of alita-sdk might be problematic. Click here for more details.
- alita_sdk/runtime/toolkits/mcp.py +12 -107
- alita_sdk/runtime/tools/mcp_remote_tool.py +5 -43
- {alita_sdk-0.3.446.dist-info → alita_sdk-0.3.448.dist-info}/METADATA +1 -1
- {alita_sdk-0.3.446.dist-info → alita_sdk-0.3.448.dist-info}/RECORD +7 -7
- {alita_sdk-0.3.446.dist-info → alita_sdk-0.3.448.dist-info}/WHEEL +0 -0
- {alita_sdk-0.3.446.dist-info → alita_sdk-0.3.448.dist-info}/licenses/LICENSE +0 -0
- {alita_sdk-0.3.446.dist-info → alita_sdk-0.3.448.dist-info}/top_level.txt +0 -0
|
@@ -402,7 +402,10 @@ class McpToolkit(BaseToolkit):
|
|
|
402
402
|
]
|
|
403
403
|
|
|
404
404
|
# Create BaseTool instances from discovered metadata
|
|
405
|
-
# Use session_id from
|
|
405
|
+
# Use session_id from frontend (passed via connection_config)
|
|
406
|
+
if session_id:
|
|
407
|
+
logger.info(f"[MCP Session] Using session_id from frontend: {session_id}")
|
|
408
|
+
|
|
406
409
|
for tool_metadata in tool_metadata_list:
|
|
407
410
|
server_tool = cls._create_tool_from_dict(
|
|
408
411
|
tool_dict=tool_metadata,
|
|
@@ -410,7 +413,7 @@ class McpToolkit(BaseToolkit):
|
|
|
410
413
|
connection_config=connection_config,
|
|
411
414
|
timeout=timeout,
|
|
412
415
|
client=client,
|
|
413
|
-
session_id=
|
|
416
|
+
session_id=session_id # Use session from discovery
|
|
414
417
|
)
|
|
415
418
|
|
|
416
419
|
if server_tool:
|
|
@@ -462,11 +465,13 @@ class McpToolkit(BaseToolkit):
|
|
|
462
465
|
"""
|
|
463
466
|
all_tools = []
|
|
464
467
|
|
|
465
|
-
#
|
|
466
|
-
#
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
468
|
+
# Use session_id from UI (passed via connection_config)
|
|
469
|
+
# For SSE-based MCP servers, frontend generates a UUID and sends it with the OAuth token
|
|
470
|
+
session_id = connection_config.session_id
|
|
471
|
+
|
|
472
|
+
if not session_id:
|
|
473
|
+
logger.warning(f"[MCP Session] No session_id provided for '{toolkit_name}' - server may require it")
|
|
474
|
+
logger.warning(f"[MCP Session] Frontend should generate a UUID and include it with mcp_tokens")
|
|
470
475
|
|
|
471
476
|
# Discover regular tools
|
|
472
477
|
tools_data = cls._discover_mcp_endpoint(
|
|
@@ -521,106 +526,6 @@ class McpToolkit(BaseToolkit):
|
|
|
521
526
|
logger.info(f"Total discovered {len(all_tools)} tools+prompts from MCP toolkit '{toolkit_name}'")
|
|
522
527
|
return all_tools, session_id
|
|
523
528
|
|
|
524
|
-
@classmethod
|
|
525
|
-
def _initialize_mcp_session(
|
|
526
|
-
cls,
|
|
527
|
-
toolkit_name: str,
|
|
528
|
-
connection_config: McpConnectionConfig,
|
|
529
|
-
timeout: int,
|
|
530
|
-
extra_headers: Optional[Dict[str, str]] = None
|
|
531
|
-
) -> Optional[str]:
|
|
532
|
-
"""
|
|
533
|
-
Initialize an MCP session for stateful SSE servers.
|
|
534
|
-
Returns sessionId if successful, None if server doesn't require sessions.
|
|
535
|
-
|
|
536
|
-
Note: This session should be stored by the caller (e.g., UI sessionStorage)
|
|
537
|
-
and passed back for subsequent requests. Sessions should NOT be cached
|
|
538
|
-
on the backend for security reasons (multi-tenant environment).
|
|
539
|
-
|
|
540
|
-
Args:
|
|
541
|
-
toolkit_name: Name of the toolkit
|
|
542
|
-
connection_config: MCP connection configuration
|
|
543
|
-
timeout: Request timeout in seconds
|
|
544
|
-
extra_headers: Additional headers (e.g., Authorization) to include
|
|
545
|
-
"""
|
|
546
|
-
import time
|
|
547
|
-
|
|
548
|
-
mcp_request = {
|
|
549
|
-
"jsonrpc": "2.0",
|
|
550
|
-
"id": f"initialize_{int(time.time())}",
|
|
551
|
-
"method": "initialize",
|
|
552
|
-
"params": {
|
|
553
|
-
"protocolVersion": "2024-11-05",
|
|
554
|
-
"capabilities": {
|
|
555
|
-
"roots": {"listChanged": True},
|
|
556
|
-
"sampling": {}
|
|
557
|
-
},
|
|
558
|
-
"clientInfo": {
|
|
559
|
-
"name": "Alita MCP Client",
|
|
560
|
-
"version": "1.0.0"
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
headers = {
|
|
566
|
-
"Content-Type": "application/json",
|
|
567
|
-
"Accept": "application/json, text/event-stream"
|
|
568
|
-
}
|
|
569
|
-
if connection_config.headers:
|
|
570
|
-
headers.update(connection_config.headers)
|
|
571
|
-
if extra_headers:
|
|
572
|
-
headers.update(extra_headers)
|
|
573
|
-
logger.debug(f"[MCP Session] Added extra headers: {list(extra_headers.keys())}")
|
|
574
|
-
|
|
575
|
-
try:
|
|
576
|
-
logger.info(f"[MCP Session] Attempting to initialize session for {connection_config.url}")
|
|
577
|
-
logger.debug(f"[MCP Session] Initialize request: {mcp_request}")
|
|
578
|
-
response = requests.post(
|
|
579
|
-
connection_config.url,
|
|
580
|
-
json=mcp_request,
|
|
581
|
-
headers=headers,
|
|
582
|
-
timeout=timeout
|
|
583
|
-
)
|
|
584
|
-
|
|
585
|
-
logger.info(f"[MCP Session] Initialize response status: {response.status_code}")
|
|
586
|
-
if response.status_code == 200:
|
|
587
|
-
# Parse the response to extract sessionId
|
|
588
|
-
content_type = response.headers.get('Content-Type', '')
|
|
589
|
-
logger.debug(f"[MCP Session] Response Content-Type: {content_type}")
|
|
590
|
-
|
|
591
|
-
if 'text/event-stream' in content_type:
|
|
592
|
-
data = cls._parse_sse_response(response.text)
|
|
593
|
-
elif 'application/json' in content_type:
|
|
594
|
-
data = response.json()
|
|
595
|
-
else:
|
|
596
|
-
logger.warning(f"[MCP Session] Unexpected Content-Type during initialize: {content_type}")
|
|
597
|
-
logger.debug(f"[MCP Session] Response text: {response.text[:500]}")
|
|
598
|
-
return None
|
|
599
|
-
|
|
600
|
-
logger.debug(f"[MCP Session] Parsed response: {data}")
|
|
601
|
-
|
|
602
|
-
# Extract sessionId from response
|
|
603
|
-
result = data.get("result", {})
|
|
604
|
-
session_id = result.get("sessionId")
|
|
605
|
-
if session_id:
|
|
606
|
-
logger.info(f"[MCP Session] ✓ Session initialized for '{toolkit_name}': {session_id}")
|
|
607
|
-
logger.info(f"[MCP Session] This sessionId should be stored by the caller and sent back for subsequent requests")
|
|
608
|
-
return session_id
|
|
609
|
-
else:
|
|
610
|
-
logger.info(f"[MCP Session] No sessionId in initialize response for '{toolkit_name}' - server may not require sessions")
|
|
611
|
-
logger.debug(f"[MCP Session] Full result: {result}")
|
|
612
|
-
return None
|
|
613
|
-
else:
|
|
614
|
-
logger.warning(f"[MCP Session] Initialize returned {response.status_code} for '{toolkit_name}' - server may not support sessions")
|
|
615
|
-
logger.debug(f"[MCP Session] Response: {response.text[:500]}")
|
|
616
|
-
return None
|
|
617
|
-
|
|
618
|
-
except Exception as e:
|
|
619
|
-
logger.warning(f"[MCP Session] Failed to initialize MCP session for '{toolkit_name}': {e} - proceeding without session")
|
|
620
|
-
import traceback
|
|
621
|
-
logger.debug(f"[MCP Session] Traceback: {traceback.format_exc()}")
|
|
622
|
-
return None
|
|
623
|
-
|
|
624
529
|
@classmethod
|
|
625
530
|
def _discover_mcp_endpoint(
|
|
626
531
|
cls,
|
|
@@ -188,49 +188,11 @@ class McpRemoteTool(McpServerTool):
|
|
|
188
188
|
error_text = await response.text()
|
|
189
189
|
|
|
190
190
|
# Check if this is a "Missing sessionId" error
|
|
191
|
-
if response.status == 404 and "sessionId" in error_text
|
|
192
|
-
logger.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
connection_config = McpConnectionConfig(
|
|
198
|
-
url=self.server_url,
|
|
199
|
-
headers=self.server_headers
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
# Initialize session with auth headers
|
|
203
|
-
session_id = McpToolkit._initialize_mcp_session(
|
|
204
|
-
toolkit_name=self.server,
|
|
205
|
-
connection_config=connection_config,
|
|
206
|
-
timeout=self.tool_timeout_sec,
|
|
207
|
-
extra_headers=headers # Include Authorization header
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
if session_id:
|
|
211
|
-
# Retry the request with session
|
|
212
|
-
self.session_id = session_id
|
|
213
|
-
# Update metadata so callbacks can access session info
|
|
214
|
-
self._update_metadata_with_session()
|
|
215
|
-
separator = '&' if '?' in self.server_url else '?'
|
|
216
|
-
retry_url = f"{self.server_url}{separator}sessionId={session_id}"
|
|
217
|
-
logger.info(f"[MCP Session] Retrying tool call with new session: {session_id}")
|
|
218
|
-
logger.info(f"[MCP Session] Created session - server: {canonical_resource(self.server_url)}, session_id: {session_id}")
|
|
219
|
-
|
|
220
|
-
async with session.post(retry_url, json=mcp_request, headers=headers) as retry_response:
|
|
221
|
-
if retry_response.status != 200:
|
|
222
|
-
retry_error = await retry_response.text()
|
|
223
|
-
raise Exception(f"HTTP {retry_response.status} (after session init): {retry_error}")
|
|
224
|
-
|
|
225
|
-
# Process successful retry response
|
|
226
|
-
content_type = retry_response.headers.get('Content-Type', '')
|
|
227
|
-
if 'text/event-stream' in content_type:
|
|
228
|
-
text = await retry_response.text()
|
|
229
|
-
data = self._parse_sse(text)
|
|
230
|
-
else:
|
|
231
|
-
data = await retry_response.json()
|
|
232
|
-
else:
|
|
233
|
-
raise Exception(f"HTTP {response.status}: {error_text} (session initialization failed)")
|
|
191
|
+
if response.status == 404 and "sessionId" in error_text:
|
|
192
|
+
logger.error(f"[MCP Session] Server requires session but none provided")
|
|
193
|
+
logger.error(f"[MCP Session] Frontend must generate a UUID and send it with mcp_tokens")
|
|
194
|
+
logger.error(f"[MCP Session] Example: mcp_tokens = {{'server_url': {{'access_token': '...', 'session_id': crypto.randomUUID()}}}}")
|
|
195
|
+
raise Exception(f"HTTP {response.status}: {error_text} - sessionId required but not provided by frontend")
|
|
234
196
|
else:
|
|
235
197
|
raise Exception(f"HTTP {response.status}: {error_text}")
|
|
236
198
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: alita_sdk
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.448
|
|
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=2RpT00q6qKkXHPMkFN6wnqUHYGjYpDAmZ5dWokEXA_s,42172
|
|
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
|
|
@@ -122,7 +122,7 @@ alita_sdk/runtime/tools/llm.py,sha256=iRG_wU4T01LRsjEMPZe5Uah7LiMqDc-vspwkMuQtlt
|
|
|
122
122
|
alita_sdk/runtime/tools/loop.py,sha256=uds0WhZvwMxDVFI6MZHrcmMle637cQfBNg682iLxoJA,8335
|
|
123
123
|
alita_sdk/runtime/tools/loop_output.py,sha256=U4hO9PCQgWlXwOq6jdmCGbegtAxGAPXObSxZQ3z38uk,8069
|
|
124
124
|
alita_sdk/runtime/tools/mcp_inspect_tool.py,sha256=38X8euaxDbEGjcfp6ElvExZalpZun6QEr6ZEW4nU5pQ,11496
|
|
125
|
-
alita_sdk/runtime/tools/mcp_remote_tool.py,sha256=
|
|
125
|
+
alita_sdk/runtime/tools/mcp_remote_tool.py,sha256=0-wqqq2ZY9cgGeTd6ao17e393YgD99n3X-k2pXlaR2g,13352
|
|
126
126
|
alita_sdk/runtime/tools/mcp_server_tool.py,sha256=-xO3H6BM63KaIV1CdcQKPVE0WPigiqOgFZDX7m2_yGs,4419
|
|
127
127
|
alita_sdk/runtime/tools/pgvector_search.py,sha256=NN2BGAnq4SsDHIhUcFZ8d_dbEOM8QwB0UwpsWCYruXU,11692
|
|
128
128
|
alita_sdk/runtime/tools/prompt.py,sha256=nJafb_e5aOM1Rr3qGFCR-SKziU9uCsiP2okIMs9PppM,741
|
|
@@ -360,8 +360,8 @@ alita_sdk/tools/zephyr_scale/api_wrapper.py,sha256=kT0TbmMvuKhDUZc0i7KO18O38JM9S
|
|
|
360
360
|
alita_sdk/tools/zephyr_squad/__init__.py,sha256=0ne8XLJEQSLOWfzd2HdnqOYmQlUliKHbBED5kW_Vias,2895
|
|
361
361
|
alita_sdk/tools/zephyr_squad/api_wrapper.py,sha256=kmw_xol8YIYFplBLWTqP_VKPRhL_1ItDD0_vXTe_UuI,14906
|
|
362
362
|
alita_sdk/tools/zephyr_squad/zephyr_squad_cloud_client.py,sha256=R371waHsms4sllHCbijKYs90C-9Yu0sSR3N4SUfQOgU,5066
|
|
363
|
-
alita_sdk-0.3.
|
|
364
|
-
alita_sdk-0.3.
|
|
365
|
-
alita_sdk-0.3.
|
|
366
|
-
alita_sdk-0.3.
|
|
367
|
-
alita_sdk-0.3.
|
|
363
|
+
alita_sdk-0.3.448.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
364
|
+
alita_sdk-0.3.448.dist-info/METADATA,sha256=FsoPHn8uhMeNXFvo4DkRBzyweY-GNMGH_-xJtnAVX2c,19071
|
|
365
|
+
alita_sdk-0.3.448.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
366
|
+
alita_sdk-0.3.448.dist-info/top_level.txt,sha256=0vJYy5p_jK6AwVb1aqXr7Kgqgk3WDtQ6t5C-XI9zkmg,10
|
|
367
|
+
alita_sdk-0.3.448.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|