blaxel 0.2.0rc1__py3-none-any.whl → 0.2.0rc2__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.
- blaxel/core/mcp/server.py +1 -86
- {blaxel-0.2.0rc1.dist-info → blaxel-0.2.0rc2.dist-info}/METADATA +3 -3
- {blaxel-0.2.0rc1.dist-info → blaxel-0.2.0rc2.dist-info}/RECORD +5 -5
- {blaxel-0.2.0rc1.dist-info → blaxel-0.2.0rc2.dist-info}/WHEEL +0 -0
- {blaxel-0.2.0rc1.dist-info → blaxel-0.2.0rc2.dist-info}/licenses/LICENSE +0 -0
blaxel/core/mcp/server.py
CHANGED
@@ -2,7 +2,7 @@ import logging
|
|
2
2
|
import traceback
|
3
3
|
import uuid
|
4
4
|
from contextlib import asynccontextmanager
|
5
|
-
from typing import
|
5
|
+
from typing import Literal
|
6
6
|
|
7
7
|
import anyio
|
8
8
|
import mcp.types as types
|
@@ -10,63 +10,14 @@ from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStre
|
|
10
10
|
from mcp.server.fastmcp import FastMCP as FastMCPBase
|
11
11
|
from websockets.asyncio.server import ServerConnection, serve
|
12
12
|
|
13
|
-
try:
|
14
|
-
from opentelemetry.trace import Span, StatusCode
|
15
|
-
|
16
|
-
HAS_OPENTELEMETRY = True
|
17
|
-
except ImportError:
|
18
|
-
HAS_OPENTELEMETRY = False
|
19
|
-
|
20
|
-
# Create dummy classes for when opentelemetry is not available
|
21
|
-
class Span:
|
22
|
-
def set_attributes(self, *args, **kwargs):
|
23
|
-
pass
|
24
|
-
|
25
|
-
def set_status(self, *args, **kwargs):
|
26
|
-
pass
|
27
|
-
|
28
|
-
def record_exception(self, *args, **kwargs):
|
29
|
-
pass
|
30
|
-
|
31
|
-
def end(self, *args, **kwargs):
|
32
|
-
pass
|
33
|
-
|
34
|
-
def add_event(self, *args, **kwargs):
|
35
|
-
pass
|
36
|
-
|
37
|
-
def get_span_context(self, *args, **kwargs):
|
38
|
-
return None
|
39
|
-
|
40
|
-
def is_recording(self, *args, **kwargs):
|
41
|
-
return False
|
42
|
-
|
43
|
-
def set_attribute(self, *args, **kwargs):
|
44
|
-
pass
|
45
|
-
|
46
|
-
def update_name(self, *args, **kwargs):
|
47
|
-
pass
|
48
|
-
|
49
|
-
class StatusCode:
|
50
|
-
ERROR = "ERROR"
|
51
|
-
|
52
|
-
|
53
13
|
from ..common.env import env
|
54
14
|
|
55
15
|
logger = logging.getLogger(__name__)
|
56
16
|
|
57
17
|
|
58
|
-
class DummySpanManager:
|
59
|
-
"""Dummy span manager for when opentelemetry is not available."""
|
60
|
-
|
61
|
-
def create_span(self, name: str, attributes: dict = None):
|
62
|
-
return Span()
|
63
|
-
|
64
|
-
|
65
18
|
class BlaxelMcpServerTransport:
|
66
19
|
"""WebSocket server transport for MCP."""
|
67
20
|
|
68
|
-
spans: Dict[str, Span] = {}
|
69
|
-
|
70
21
|
def __init__(self, port: int = 8080):
|
71
22
|
"""Initialize the WebSocket server transport.
|
72
23
|
|
@@ -80,13 +31,6 @@ class BlaxelMcpServerTransport:
|
|
80
31
|
self.clients = {}
|
81
32
|
self.server = None
|
82
33
|
|
83
|
-
# Initialize span manager
|
84
|
-
if HAS_OPENTELEMETRY:
|
85
|
-
# TODO: Implement proper OpenTelemetry span manager when telemetry is available
|
86
|
-
self.span_manager = DummySpanManager()
|
87
|
-
else:
|
88
|
-
self.span_manager = DummySpanManager()
|
89
|
-
|
90
34
|
@asynccontextmanager
|
91
35
|
async def websocket_server(self):
|
92
36
|
"""Create and run a WebSocket server for MCP communication."""
|
@@ -106,30 +50,14 @@ class BlaxelMcpServerTransport:
|
|
106
50
|
|
107
51
|
try:
|
108
52
|
async for message in websocket:
|
109
|
-
span = self.span_manager.create_span("message", {"mcp.client.id": client_id})
|
110
53
|
try:
|
111
54
|
msg = types.JSONRPCMessage.model_validate_json(message)
|
112
55
|
# Modify message ID to include client ID
|
113
56
|
if hasattr(msg, "id") and msg.id is not None:
|
114
57
|
original_id = msg.id
|
115
58
|
msg.id = f"{client_id}:{original_id}"
|
116
|
-
span.set_attributes(
|
117
|
-
{
|
118
|
-
"mcp.message.parsed": True,
|
119
|
-
"mcp.method": getattr(msg, "method", None),
|
120
|
-
"mcp.messageId": getattr(msg, "id", None),
|
121
|
-
"mcp.toolName": getattr(
|
122
|
-
getattr(msg, "params", None), "name", None
|
123
|
-
),
|
124
|
-
"span.type": "mcp.message",
|
125
|
-
}
|
126
|
-
)
|
127
|
-
self.spans[client_id + ":" + msg.id] = span
|
128
59
|
await read_stream_writer.send(msg)
|
129
60
|
except Exception as exc:
|
130
|
-
span.set_status(StatusCode.ERROR)
|
131
|
-
span.record_exception(exc)
|
132
|
-
span.end()
|
133
61
|
logger.error(f"Failed to parse message: {exc}\n{traceback.format_exc()}")
|
134
62
|
await read_stream_writer.send(exc)
|
135
63
|
except Exception as e:
|
@@ -158,25 +86,12 @@ class BlaxelMcpServerTransport:
|
|
158
86
|
if client_id and client_id in self.clients:
|
159
87
|
# Send to specific client
|
160
88
|
websocket = self.clients[client_id]
|
161
|
-
span = self.spans.get(client_id + ":" + msg_id)
|
162
89
|
try:
|
163
90
|
await websocket.send(data)
|
164
|
-
if span:
|
165
|
-
span.set_attributes(
|
166
|
-
{
|
167
|
-
"mcp.message.response_sent": True,
|
168
|
-
}
|
169
|
-
)
|
170
91
|
except Exception as e:
|
171
|
-
if span:
|
172
|
-
span.set_status(StatusCode.ERROR)
|
173
|
-
span.record_exception(e)
|
174
92
|
logger.error(f"Failed to send message to client {client_id}: {e}")
|
175
93
|
if client_id in self.clients:
|
176
94
|
del self.clients[client_id]
|
177
|
-
finally:
|
178
|
-
if span:
|
179
|
-
span.end()
|
180
95
|
else:
|
181
96
|
# Broadcast to all clients
|
182
97
|
dead_clients = []
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: blaxel
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.0rc2
|
4
4
|
Summary: Blaxel - AI development platform SDK
|
5
5
|
Project-URL: Homepage, https://blaxel.ai
|
6
6
|
Project-URL: Documentation, https://docs.blaxel.ai
|
@@ -43,7 +43,7 @@ Requires-Dist: llama-index-llms-groq>=0.3.1; extra == 'all'
|
|
43
43
|
Requires-Dist: llama-index-llms-mistralai>=0.4.0; extra == 'all'
|
44
44
|
Requires-Dist: llama-index-llms-openai>=0.3.42; extra == 'all'
|
45
45
|
Requires-Dist: llama-index>=0.12.37; extra == 'all'
|
46
|
-
Requires-Dist: openai-agents>=0.0.
|
46
|
+
Requires-Dist: openai-agents>=0.0.14; extra == 'all'
|
47
47
|
Requires-Dist: opentelemetry-exporter-otlp>=1.28.0; extra == 'all'
|
48
48
|
Requires-Dist: opentelemetry-instrumentation-anthropic==0.40.6; extra == 'all'
|
49
49
|
Requires-Dist: opentelemetry-instrumentation-cohere==0.40.6; extra == 'all'
|
@@ -95,7 +95,7 @@ Requires-Dist: llama-index-llms-openai>=0.3.42; extra == 'llamaindex'
|
|
95
95
|
Requires-Dist: llama-index>=0.12.37; extra == 'llamaindex'
|
96
96
|
Requires-Dist: opentelemetry-instrumentation-llamaindex>=0.40.7; extra == 'llamaindex'
|
97
97
|
Provides-Extra: openai
|
98
|
-
Requires-Dist: openai-agents>=0.0.
|
98
|
+
Requires-Dist: openai-agents>=0.0.14; extra == 'openai'
|
99
99
|
Provides-Extra: pydantic
|
100
100
|
Requires-Dist: pydantic-ai>=0.0.48; extra == 'pydantic'
|
101
101
|
Provides-Extra: telemetry
|
@@ -302,7 +302,7 @@ blaxel/core/common/settings.py,sha256=7KTryuBdud0IfHqykX7xEEtpgq5M5h1Z8YEzYKsHB-
|
|
302
302
|
blaxel/core/jobs/__init__.py,sha256=tApZ6t6Savd5c9yH1RhuiPDGq19B464Fakd-YqCOEtI,5441
|
303
303
|
blaxel/core/mcp/__init__.py,sha256=5VjkiQFb1QWW5QKRgwPHARlxZJ9Xqaz0diJTpM8LLF0,142
|
304
304
|
blaxel/core/mcp/client.py,sha256=dFjPHirybqA3IMecSvdDss-iU5ferPUaunNrPyhFm8o,5195
|
305
|
-
blaxel/core/mcp/server.py,sha256=
|
305
|
+
blaxel/core/mcp/server.py,sha256=lx-4C71PdPxbG_tGuk81j44jrl7a1ztSixC-k4ObyBo,5812
|
306
306
|
blaxel/core/models/__init__.py,sha256=HbRDsMnUFHkPC-MMkzPXh4mUqkVjqO6p3j7m00N_XSo,1722
|
307
307
|
blaxel/core/sandbox/__init__.py,sha256=eWTH7PWNQZe9efqParwgXzltc7L4OyPtT_REqCdQybU,551
|
308
308
|
blaxel/core/sandbox/action.py,sha256=9Zjkco7YkLzBThD3N2Hr5SpeEiqU_-Ktk8HlKpkpiAg,2802
|
@@ -402,7 +402,7 @@ blaxel/telemetry/instrumentation/map.py,sha256=EVCw6ug1hemE-9kh77Vxs9cqr_p9TPzFw
|
|
402
402
|
blaxel/telemetry/instrumentation/utils.py,sha256=KInMYZH-mu9_wvetmf0EmgrfN3Sw8IWk2Y95v2u90_U,1901
|
403
403
|
blaxel/telemetry/log/log.py,sha256=RvQByRjZMoP_dRaAZu8oK6DTegsHs-xV4W-UIqis6CA,2461
|
404
404
|
blaxel/telemetry/log/logger.py,sha256=NPAS3g82ryROjvc_DEZaTIfrcehoLEZoP-JkLxADxc0,4113
|
405
|
-
blaxel-0.2.
|
406
|
-
blaxel-0.2.
|
407
|
-
blaxel-0.2.
|
408
|
-
blaxel-0.2.
|
405
|
+
blaxel-0.2.0rc2.dist-info/METADATA,sha256=g08ZNxaAovSAaeMwRLMFeoY5YJ2HWAOmTL1e-QqIHko,9878
|
406
|
+
blaxel-0.2.0rc2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
407
|
+
blaxel-0.2.0rc2.dist-info/licenses/LICENSE,sha256=p5PNQvpvyDT_0aYBDgmV1fFI_vAD2aSV0wWG7VTgRis,1069
|
408
|
+
blaxel-0.2.0rc2.dist-info/RECORD,,
|
File without changes
|
File without changes
|