alita-sdk 0.3.423__py3-none-any.whl → 0.3.449__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/clients/client.py +45 -9
- alita_sdk/runtime/clients/mcp_discovery.py +342 -0
- alita_sdk/runtime/clients/mcp_manager.py +262 -0
- alita_sdk/runtime/langchain/assistant.py +10 -2
- alita_sdk/runtime/langchain/constants.py +1 -1
- alita_sdk/runtime/langchain/langraph_agent.py +4 -1
- alita_sdk/runtime/models/mcp_models.py +61 -0
- alita_sdk/runtime/toolkits/__init__.py +24 -0
- alita_sdk/runtime/toolkits/mcp.py +892 -0
- alita_sdk/runtime/toolkits/tools.py +61 -3
- alita_sdk/runtime/tools/mcp_inspect_tool.py +284 -0
- alita_sdk/runtime/tools/mcp_remote_tool.py +166 -0
- alita_sdk/runtime/tools/mcp_server_tool.py +3 -1
- alita_sdk/runtime/utils/mcp_oauth.py +164 -0
- alita_sdk/runtime/utils/mcp_sse_client.py +347 -0
- alita_sdk/runtime/utils/streamlit.py +34 -3
- alita_sdk/runtime/utils/toolkit_utils.py +14 -4
- alita_sdk/tools/__init__.py +5 -0
- alita_sdk/tools/chunkers/sematic/proposal_chunker.py +1 -1
- alita_sdk/tools/gitlab/api_wrapper.py +5 -0
- alita_sdk/tools/qtest/api_wrapper.py +240 -39
- {alita_sdk-0.3.423.dist-info → alita_sdk-0.3.449.dist-info}/METADATA +2 -1
- {alita_sdk-0.3.423.dist-info → alita_sdk-0.3.449.dist-info}/RECORD +26 -18
- {alita_sdk-0.3.423.dist-info → alita_sdk-0.3.449.dist-info}/WHEEL +0 -0
- {alita_sdk-0.3.423.dist-info → alita_sdk-0.3.449.dist-info}/licenses/LICENSE +0 -0
- {alita_sdk-0.3.423.dist-info → alita_sdk-0.3.449.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MCP Manager - Unified interface for both static and dynamic MCP tool discovery.
|
|
3
|
+
Provides a single API that can work with both registry-based and live discovery.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import asyncio
|
|
7
|
+
import logging
|
|
8
|
+
from typing import Dict, List, Optional, Any, Union
|
|
9
|
+
from enum import Enum
|
|
10
|
+
|
|
11
|
+
from ..models.mcp_models import McpConnectionConfig, McpToolMetadata
|
|
12
|
+
from .mcp_discovery import McpDiscoveryService, get_discovery_service
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DiscoveryMode(Enum):
|
|
18
|
+
"""MCP discovery modes."""
|
|
19
|
+
STATIC = "static" # Use alita.get_mcp_toolkits() registry
|
|
20
|
+
DYNAMIC = "dynamic" # Live discovery from MCP servers
|
|
21
|
+
HYBRID = "hybrid" # Try dynamic first, fallback to static
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class McpManager:
|
|
25
|
+
"""
|
|
26
|
+
Unified manager for MCP tool discovery supporting multiple modes.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
default_mode: DiscoveryMode = DiscoveryMode.DYNAMIC,
|
|
32
|
+
discovery_service: Optional[McpDiscoveryService] = None
|
|
33
|
+
):
|
|
34
|
+
self.default_mode = default_mode
|
|
35
|
+
self.discovery_service = discovery_service or get_discovery_service()
|
|
36
|
+
self._static_fallback_enabled = True
|
|
37
|
+
|
|
38
|
+
async def discover_server_tools(
|
|
39
|
+
self,
|
|
40
|
+
server_name: str,
|
|
41
|
+
connection_config: Optional[McpConnectionConfig] = None,
|
|
42
|
+
alita_client=None,
|
|
43
|
+
mode: Optional[DiscoveryMode] = None,
|
|
44
|
+
**kwargs
|
|
45
|
+
) -> List[McpToolMetadata]:
|
|
46
|
+
"""
|
|
47
|
+
Discover tools from an MCP server using the specified mode.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
server_name: Name of the MCP server
|
|
51
|
+
connection_config: Connection configuration (required for dynamic mode)
|
|
52
|
+
alita_client: Alita client (required for static mode)
|
|
53
|
+
mode: Discovery mode to use (defaults to manager's default)
|
|
54
|
+
**kwargs: Additional options
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
List of discovered tool metadata
|
|
58
|
+
"""
|
|
59
|
+
discovery_mode = mode or self.default_mode
|
|
60
|
+
|
|
61
|
+
if discovery_mode == DiscoveryMode.DYNAMIC:
|
|
62
|
+
return await self._discover_dynamic(server_name, connection_config)
|
|
63
|
+
|
|
64
|
+
elif discovery_mode == DiscoveryMode.STATIC:
|
|
65
|
+
return await self._discover_static(server_name, alita_client)
|
|
66
|
+
|
|
67
|
+
elif discovery_mode == DiscoveryMode.HYBRID:
|
|
68
|
+
return await self._discover_hybrid(server_name, connection_config, alita_client)
|
|
69
|
+
|
|
70
|
+
else:
|
|
71
|
+
raise ValueError(f"Unknown discovery mode: {discovery_mode}")
|
|
72
|
+
|
|
73
|
+
async def _discover_dynamic(
|
|
74
|
+
self,
|
|
75
|
+
server_name: str,
|
|
76
|
+
connection_config: Optional[McpConnectionConfig]
|
|
77
|
+
) -> List[McpToolMetadata]:
|
|
78
|
+
"""Discover tools using dynamic MCP protocol."""
|
|
79
|
+
if not connection_config:
|
|
80
|
+
raise ValueError("Connection configuration required for dynamic discovery")
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
# Ensure discovery service is started
|
|
84
|
+
await self.discovery_service.start()
|
|
85
|
+
|
|
86
|
+
# Register and discover
|
|
87
|
+
await self.discovery_service.register_server(server_name, connection_config)
|
|
88
|
+
tools = await self.discovery_service.get_server_tools(server_name)
|
|
89
|
+
|
|
90
|
+
logger.info(f"Dynamic discovery found {len(tools)} tools from {server_name}")
|
|
91
|
+
return tools
|
|
92
|
+
|
|
93
|
+
except Exception as e:
|
|
94
|
+
logger.error(f"Dynamic discovery failed for {server_name}: {e}")
|
|
95
|
+
raise
|
|
96
|
+
|
|
97
|
+
async def _discover_static(
|
|
98
|
+
self,
|
|
99
|
+
server_name: str,
|
|
100
|
+
alita_client
|
|
101
|
+
) -> List[McpToolMetadata]:
|
|
102
|
+
"""Discover tools using static registry."""
|
|
103
|
+
if not alita_client or not hasattr(alita_client, 'get_mcp_toolkits'):
|
|
104
|
+
raise ValueError("Alita client with get_mcp_toolkits() required for static discovery")
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
# Use existing registry approach
|
|
108
|
+
all_toolkits = alita_client.get_mcp_toolkits()
|
|
109
|
+
server_toolkit = next((tk for tk in all_toolkits if tk.get('name') == server_name), None)
|
|
110
|
+
|
|
111
|
+
if not server_toolkit:
|
|
112
|
+
logger.warning(f"Static registry: Server {server_name} not found")
|
|
113
|
+
return []
|
|
114
|
+
|
|
115
|
+
# Convert to metadata format
|
|
116
|
+
tools = []
|
|
117
|
+
for tool_info in server_toolkit.get('tools', []):
|
|
118
|
+
metadata = McpToolMetadata(
|
|
119
|
+
name=tool_info.get('name', ''),
|
|
120
|
+
description=tool_info.get('description', ''),
|
|
121
|
+
server=server_name,
|
|
122
|
+
input_schema=tool_info.get('inputSchema', {}),
|
|
123
|
+
enabled=True
|
|
124
|
+
)
|
|
125
|
+
tools.append(metadata)
|
|
126
|
+
|
|
127
|
+
logger.info(f"Static discovery found {len(tools)} tools from {server_name}")
|
|
128
|
+
return tools
|
|
129
|
+
|
|
130
|
+
except Exception as e:
|
|
131
|
+
logger.error(f"Static discovery failed for {server_name}: {e}")
|
|
132
|
+
raise
|
|
133
|
+
|
|
134
|
+
async def _discover_hybrid(
|
|
135
|
+
self,
|
|
136
|
+
server_name: str,
|
|
137
|
+
connection_config: Optional[McpConnectionConfig],
|
|
138
|
+
alita_client
|
|
139
|
+
) -> List[McpToolMetadata]:
|
|
140
|
+
"""Discover tools using hybrid approach (dynamic first, static fallback)."""
|
|
141
|
+
|
|
142
|
+
# Try dynamic discovery first
|
|
143
|
+
if connection_config:
|
|
144
|
+
try:
|
|
145
|
+
return await self._discover_dynamic(server_name, connection_config)
|
|
146
|
+
except Exception as e:
|
|
147
|
+
logger.warning(f"Dynamic discovery failed for {server_name}, trying static: {e}")
|
|
148
|
+
|
|
149
|
+
# Fallback to static discovery
|
|
150
|
+
if self._static_fallback_enabled and alita_client:
|
|
151
|
+
try:
|
|
152
|
+
return await self._discover_static(server_name, alita_client)
|
|
153
|
+
except Exception as e:
|
|
154
|
+
logger.error(f"Static fallback also failed for {server_name}: {e}")
|
|
155
|
+
|
|
156
|
+
logger.error(f"All discovery methods failed for {server_name}")
|
|
157
|
+
return []
|
|
158
|
+
|
|
159
|
+
async def get_server_health(
|
|
160
|
+
self,
|
|
161
|
+
server_name: Optional[str] = None
|
|
162
|
+
) -> Dict[str, Any]:
|
|
163
|
+
"""Get health information for servers."""
|
|
164
|
+
try:
|
|
165
|
+
if server_name:
|
|
166
|
+
# Get specific server health from discovery service
|
|
167
|
+
all_health = self.discovery_service.get_server_health()
|
|
168
|
+
return all_health.get(server_name, {"status": "unknown"})
|
|
169
|
+
else:
|
|
170
|
+
# Get all server health
|
|
171
|
+
return self.discovery_service.get_server_health()
|
|
172
|
+
except Exception as e:
|
|
173
|
+
logger.error(f"Failed to get server health: {e}")
|
|
174
|
+
return {"status": "error", "error": str(e)}
|
|
175
|
+
|
|
176
|
+
async def refresh_server(self, server_name: str):
|
|
177
|
+
"""Force refresh a specific server's tools."""
|
|
178
|
+
try:
|
|
179
|
+
await self.discovery_service.refresh_server(server_name)
|
|
180
|
+
except Exception as e:
|
|
181
|
+
logger.error(f"Failed to refresh server {server_name}: {e}")
|
|
182
|
+
|
|
183
|
+
async def start(self):
|
|
184
|
+
"""Start the MCP manager."""
|
|
185
|
+
await self.discovery_service.start()
|
|
186
|
+
|
|
187
|
+
async def stop(self):
|
|
188
|
+
"""Stop the MCP manager."""
|
|
189
|
+
await self.discovery_service.stop()
|
|
190
|
+
|
|
191
|
+
def set_static_fallback(self, enabled: bool):
|
|
192
|
+
"""Enable or disable static fallback in hybrid mode."""
|
|
193
|
+
self._static_fallback_enabled = enabled
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
# Global manager instance
|
|
197
|
+
_mcp_manager: Optional[McpManager] = None
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def get_mcp_manager(mode: DiscoveryMode = DiscoveryMode.HYBRID) -> McpManager:
|
|
201
|
+
"""Get the global MCP manager instance."""
|
|
202
|
+
global _mcp_manager
|
|
203
|
+
if _mcp_manager is None:
|
|
204
|
+
_mcp_manager = McpManager(default_mode=mode)
|
|
205
|
+
return _mcp_manager
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
async def discover_mcp_tools(
|
|
209
|
+
server_name: str,
|
|
210
|
+
connection_config: Optional[McpConnectionConfig] = None,
|
|
211
|
+
alita_client=None,
|
|
212
|
+
mode: Optional[DiscoveryMode] = None
|
|
213
|
+
) -> List[McpToolMetadata]:
|
|
214
|
+
"""
|
|
215
|
+
Convenience function for discovering MCP tools.
|
|
216
|
+
|
|
217
|
+
Args:
|
|
218
|
+
server_name: Name of the MCP server
|
|
219
|
+
connection_config: Connection config (for dynamic discovery)
|
|
220
|
+
alita_client: Alita client (for static discovery)
|
|
221
|
+
mode: Discovery mode (defaults to HYBRID)
|
|
222
|
+
|
|
223
|
+
Returns:
|
|
224
|
+
List of discovered tool metadata
|
|
225
|
+
"""
|
|
226
|
+
manager = get_mcp_manager()
|
|
227
|
+
return await manager.discover_server_tools(
|
|
228
|
+
server_name=server_name,
|
|
229
|
+
connection_config=connection_config,
|
|
230
|
+
alita_client=alita_client,
|
|
231
|
+
mode=mode or DiscoveryMode.HYBRID
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
async def init_mcp_manager(mode: DiscoveryMode = DiscoveryMode.HYBRID):
|
|
236
|
+
"""Initialize the global MCP manager."""
|
|
237
|
+
manager = get_mcp_manager(mode)
|
|
238
|
+
await manager.start()
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
async def shutdown_mcp_manager():
|
|
242
|
+
"""Shutdown the global MCP manager."""
|
|
243
|
+
global _mcp_manager
|
|
244
|
+
if _mcp_manager:
|
|
245
|
+
await _mcp_manager.stop()
|
|
246
|
+
_mcp_manager = None
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
# Configuration helpers
|
|
250
|
+
def create_discovery_config(
|
|
251
|
+
mode: str = "hybrid",
|
|
252
|
+
discovery_interval: int = 300,
|
|
253
|
+
enable_static_fallback: bool = True,
|
|
254
|
+
**kwargs
|
|
255
|
+
) -> Dict[str, Any]:
|
|
256
|
+
"""Create a discovery configuration dictionary."""
|
|
257
|
+
return {
|
|
258
|
+
"discovery_mode": mode,
|
|
259
|
+
"discovery_interval": discovery_interval,
|
|
260
|
+
"enable_static_fallback": enable_static_fallback,
|
|
261
|
+
**kwargs
|
|
262
|
+
}
|
|
@@ -31,7 +31,8 @@ class Assistant:
|
|
|
31
31
|
tools: Optional[list] = [],
|
|
32
32
|
memory: Optional[Any] = None,
|
|
33
33
|
store: Optional[BaseStore] = None,
|
|
34
|
-
debug_mode: Optional[bool] = False
|
|
34
|
+
debug_mode: Optional[bool] = False,
|
|
35
|
+
mcp_tokens: Optional[dict] = None):
|
|
35
36
|
|
|
36
37
|
self.app_type = app_type
|
|
37
38
|
self.memory = memory
|
|
@@ -89,7 +90,14 @@ class Assistant:
|
|
|
89
90
|
for internal_tool_name in meta.get("internal_tools"):
|
|
90
91
|
version_tools.append({"type": "internal_tool", "name": internal_tool_name})
|
|
91
92
|
|
|
92
|
-
self.tools = get_tools(
|
|
93
|
+
self.tools = get_tools(
|
|
94
|
+
version_tools,
|
|
95
|
+
alita_client=alita,
|
|
96
|
+
llm=self.client,
|
|
97
|
+
memory_store=self.store,
|
|
98
|
+
debug_mode=debug_mode,
|
|
99
|
+
mcp_tokens=mcp_tokens
|
|
100
|
+
)
|
|
93
101
|
if tools:
|
|
94
102
|
self.tools += tools
|
|
95
103
|
# Handle prompt setup
|
|
@@ -27,7 +27,7 @@ Use this if you want to respond directly to the human. Markdown code snippet for
|
|
|
27
27
|
```json
|
|
28
28
|
{
|
|
29
29
|
"action": "Final Answer",
|
|
30
|
-
"action_input": string
|
|
30
|
+
"action_input": string // You should put what you want to return to use here
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
33
|
|
|
@@ -244,9 +244,12 @@ class PrinterNode(Runnable):
|
|
|
244
244
|
result = {}
|
|
245
245
|
logger.debug(f"Initial text pattern: {self.input_mapping}")
|
|
246
246
|
mapping = propagate_the_input_mapping(self.input_mapping, [], state)
|
|
247
|
-
if
|
|
247
|
+
if mapping.get(PRINTER) is None:
|
|
248
248
|
raise ToolException(f"PrinterNode requires '{PRINTER}' field in input mapping")
|
|
249
249
|
formatted_output = mapping[PRINTER]
|
|
250
|
+
# add info label to the printer's output
|
|
251
|
+
if formatted_output:
|
|
252
|
+
formatted_output += f"\n\n-----\n*How to proceed?*\n* *to resume the pipeline - type anything...*"
|
|
250
253
|
logger.debug(f"Formatted output: {formatted_output}")
|
|
251
254
|
result[PRINTER_NODE_RS] = formatted_output
|
|
252
255
|
return result
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Models for MCP (Model Context Protocol) configuration.
|
|
3
|
+
Following MCP specification for remote HTTP servers only.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Optional, List, Dict, Any
|
|
7
|
+
from pydantic import BaseModel, Field, validator
|
|
8
|
+
from urllib.parse import urlparse
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class McpConnectionConfig(BaseModel):
|
|
12
|
+
"""
|
|
13
|
+
MCP connection configuration for remote HTTP servers.
|
|
14
|
+
Based on https://modelcontextprotocol.io/specification/2025-06-18
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
url: str = Field(description="MCP server HTTP URL (http:// or https://)")
|
|
18
|
+
headers: Optional[Dict[str, str]] = Field(
|
|
19
|
+
default=None,
|
|
20
|
+
description="HTTP headers for the connection (JSON object)"
|
|
21
|
+
)
|
|
22
|
+
session_id: Optional[str] = Field(
|
|
23
|
+
default=None,
|
|
24
|
+
description="MCP session ID for stateful SSE servers (managed by client)"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
@validator('url')
|
|
28
|
+
def validate_url(cls, v):
|
|
29
|
+
"""Validate URL is HTTP/HTTPS."""
|
|
30
|
+
if not v:
|
|
31
|
+
raise ValueError("URL cannot be empty")
|
|
32
|
+
|
|
33
|
+
parsed = urlparse(v)
|
|
34
|
+
if parsed.scheme not in ['http', 'https']:
|
|
35
|
+
raise ValueError("URL must use http:// or https:// scheme for remote MCP servers")
|
|
36
|
+
|
|
37
|
+
if not parsed.netloc:
|
|
38
|
+
raise ValueError("URL must include host and port")
|
|
39
|
+
|
|
40
|
+
return v
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class McpToolkitConfig(BaseModel):
|
|
44
|
+
"""Configuration for a single remote MCP server toolkit."""
|
|
45
|
+
|
|
46
|
+
server_name: str = Field(description="MCP server name/identifier")
|
|
47
|
+
connection: McpConnectionConfig = Field(description="MCP connection configuration")
|
|
48
|
+
timeout: int = Field(default=60, description="Request timeout in seconds", ge=1, le=3600)
|
|
49
|
+
selected_tools: List[str] = Field(default_factory=list, description="Specific tools to enable (empty = all)")
|
|
50
|
+
enable_caching: bool = Field(default=True, description="Enable tool schema caching")
|
|
51
|
+
cache_ttl: int = Field(default=300, description="Cache TTL in seconds", ge=60, le=3600)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class McpToolMetadata(BaseModel):
|
|
55
|
+
"""Metadata about an MCP tool."""
|
|
56
|
+
|
|
57
|
+
name: str = Field(description="Tool name")
|
|
58
|
+
description: str = Field(description="Tool description")
|
|
59
|
+
server: str = Field(description="Source server name")
|
|
60
|
+
input_schema: Dict[str, Any] = Field(description="Tool input schema")
|
|
61
|
+
enabled: bool = Field(default=True, description="Whether tool is enabled")
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Runtime toolkits module for Alita SDK.
|
|
3
|
+
This module provides various toolkit implementations for LangGraph agents.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from .application import ApplicationToolkit
|
|
7
|
+
from .artifact import ArtifactToolkit
|
|
8
|
+
from .datasource import DatasourcesToolkit
|
|
9
|
+
from .prompt import PromptToolkit
|
|
10
|
+
from .subgraph import SubgraphToolkit
|
|
11
|
+
from .vectorstore import VectorStoreToolkit
|
|
12
|
+
from .mcp import McpToolkit
|
|
13
|
+
from ...tools.memory import MemoryToolkit
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"ApplicationToolkit",
|
|
17
|
+
"ArtifactToolkit",
|
|
18
|
+
"DatasourcesToolkit",
|
|
19
|
+
"PromptToolkit",
|
|
20
|
+
"SubgraphToolkit",
|
|
21
|
+
"VectorStoreToolkit",
|
|
22
|
+
"McpToolkit",
|
|
23
|
+
"MemoryToolkit"
|
|
24
|
+
]
|