@blaxel/core 0.2.23-dev.169 → 0.2.23-dev.171
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.
- package/dist/mcp/client.d.ts +8 -1
- package/dist/mcp/client.js +35 -12
- package/dist/tools/mcpTool.js +19 -4
- package/package.json +1 -1
package/dist/mcp/client.d.ts
CHANGED
|
@@ -9,10 +9,17 @@ export declare class BlaxelMcpClientTransport implements Transport {
|
|
|
9
9
|
private _url;
|
|
10
10
|
private _headers;
|
|
11
11
|
private _isBrowser;
|
|
12
|
+
private _retry_max;
|
|
13
|
+
private _retry_delay;
|
|
12
14
|
onclose?: () => void;
|
|
13
15
|
onerror?: (error: Error) => void;
|
|
14
16
|
onmessage?: (message: JSONRPCMessage) => void;
|
|
15
|
-
constructor(url: string, headers?: Record<string, string
|
|
17
|
+
constructor(url: string, headers?: Record<string, string>, options?: {
|
|
18
|
+
retry: {
|
|
19
|
+
max?: number;
|
|
20
|
+
delay?: number;
|
|
21
|
+
};
|
|
22
|
+
});
|
|
16
23
|
start(): Promise<void>;
|
|
17
24
|
private _connect;
|
|
18
25
|
get isConnected(): boolean;
|
package/dist/mcp/client.js
CHANGED
|
@@ -21,8 +21,6 @@ if (!isBrowser) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
//const SUBPROTOCOL = "mcp";
|
|
24
|
-
const MAX_RETRIES = 3;
|
|
25
|
-
const RETRY_DELAY_MS = 1000;
|
|
26
24
|
// Helper function to wait
|
|
27
25
|
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
28
26
|
/**
|
|
@@ -34,11 +32,15 @@ class BlaxelMcpClientTransport {
|
|
|
34
32
|
_url;
|
|
35
33
|
_headers;
|
|
36
34
|
_isBrowser;
|
|
35
|
+
_retry_max;
|
|
36
|
+
_retry_delay;
|
|
37
37
|
onclose;
|
|
38
38
|
onerror;
|
|
39
39
|
onmessage;
|
|
40
|
-
constructor(url, headers) {
|
|
40
|
+
constructor(url, headers, options) {
|
|
41
41
|
this._url = new URL(url.replace("http", "ws"));
|
|
42
|
+
this._retry_max = options?.retry?.max ?? 3;
|
|
43
|
+
this._retry_delay = options?.retry?.delay ?? 1000;
|
|
42
44
|
this._headers = headers ?? {};
|
|
43
45
|
this._isBrowser = isBrowser;
|
|
44
46
|
}
|
|
@@ -47,7 +49,7 @@ class BlaxelMcpClientTransport {
|
|
|
47
49
|
throw new Error("Blaxel already started! If using Client class, note that connect() calls start() automatically.");
|
|
48
50
|
}
|
|
49
51
|
let attempts = 0;
|
|
50
|
-
while (attempts <
|
|
52
|
+
while (attempts < this._retry_max) {
|
|
51
53
|
try {
|
|
52
54
|
await this._connect();
|
|
53
55
|
return;
|
|
@@ -57,11 +59,14 @@ class BlaxelMcpClientTransport {
|
|
|
57
59
|
logger_js_1.logger.warn(error.stack ?? error.message);
|
|
58
60
|
}
|
|
59
61
|
attempts++;
|
|
60
|
-
if (attempts ===
|
|
62
|
+
if (attempts === this._retry_max) {
|
|
61
63
|
throw error;
|
|
62
64
|
}
|
|
63
|
-
logger_js_1.logger.debug(`WebSocket connection attempt ${attempts} failed, retrying in ${
|
|
64
|
-
await delay(
|
|
65
|
+
logger_js_1.logger.debug(`WebSocket connection attempt ${attempts} failed, retrying in ${this._retry_delay}ms...`);
|
|
66
|
+
await delay(this._retry_delay);
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
attempts++;
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
}
|
|
@@ -86,7 +91,25 @@ class BlaxelMcpClientTransport {
|
|
|
86
91
|
});
|
|
87
92
|
}
|
|
88
93
|
this._socket.onerror = (event) => {
|
|
89
|
-
|
|
94
|
+
// Log websocket error with meaningful information instead of raw event
|
|
95
|
+
const errorInfo = {
|
|
96
|
+
type: 'WebSocket Error',
|
|
97
|
+
url: this._url.toString(),
|
|
98
|
+
readyState: this._socket?.readyState,
|
|
99
|
+
browser: this._isBrowser,
|
|
100
|
+
// Extract any available error details from the event
|
|
101
|
+
eventType: event && typeof event === 'object' && 'type' in event
|
|
102
|
+
? String(event.type)
|
|
103
|
+
: 'unknown',
|
|
104
|
+
// Browser events might have different properties than Node.js
|
|
105
|
+
message: this._isBrowser && event && typeof event === 'object' && 'message' in event
|
|
106
|
+
? String(event.message)
|
|
107
|
+
: undefined,
|
|
108
|
+
error: !this._isBrowser && event && typeof event === 'object' && 'error' in event
|
|
109
|
+
? String(event.error)
|
|
110
|
+
: undefined
|
|
111
|
+
};
|
|
112
|
+
logger_js_1.logger.error('WebSocket connection error', errorInfo);
|
|
90
113
|
const error = this._isBrowser
|
|
91
114
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
92
115
|
? new Error(`WebSocket error: ${event.message}`)
|
|
@@ -174,7 +197,7 @@ class BlaxelMcpClientTransport {
|
|
|
174
197
|
}
|
|
175
198
|
async send(message) {
|
|
176
199
|
let attempts = 0;
|
|
177
|
-
while (attempts <
|
|
200
|
+
while (attempts < this._retry_max) {
|
|
178
201
|
try {
|
|
179
202
|
if (!this._socket || !this.isConnected) {
|
|
180
203
|
if (!this._socket) {
|
|
@@ -213,11 +236,11 @@ class BlaxelMcpClientTransport {
|
|
|
213
236
|
}
|
|
214
237
|
catch (error) {
|
|
215
238
|
attempts++;
|
|
216
|
-
if (attempts ===
|
|
239
|
+
if (attempts === this._retry_max) {
|
|
217
240
|
throw error;
|
|
218
241
|
}
|
|
219
|
-
logger_js_1.logger.warn(`WebSocket send attempt ${attempts} failed, retrying in ${
|
|
220
|
-
await delay(
|
|
242
|
+
logger_js_1.logger.warn(`WebSocket send attempt ${attempts} failed, retrying in ${this._retry_delay}ms...`);
|
|
243
|
+
await delay(this._retry_delay);
|
|
221
244
|
}
|
|
222
245
|
}
|
|
223
246
|
}
|
package/dist/tools/mcpTool.js
CHANGED
|
@@ -74,13 +74,18 @@ class McpTool {
|
|
|
74
74
|
await (0, index_js_2.authenticate)();
|
|
75
75
|
try {
|
|
76
76
|
logger_js_1.logger.debug(`MCP:${this.name}:Connecting::${this.url.toString()}`);
|
|
77
|
-
this.transport = new client_js_1.BlaxelMcpClientTransport(this.url.toString(), settings_js_1.settings.headers);
|
|
77
|
+
this.transport = new client_js_1.BlaxelMcpClientTransport(this.url.toString(), settings_js_1.settings.headers, { retry: { max: 0 } });
|
|
78
78
|
await this.client.connect(this.transport);
|
|
79
79
|
logger_js_1.logger.debug(`MCP:${this.name}:Connected`);
|
|
80
80
|
}
|
|
81
81
|
catch (err) {
|
|
82
82
|
if (err instanceof Error) {
|
|
83
|
-
logger_js_1.logger.error(err.
|
|
83
|
+
logger_js_1.logger.error(`MCP ${this.name} connection failed: ${err.message}`, {
|
|
84
|
+
error: err.message,
|
|
85
|
+
stack: err.stack,
|
|
86
|
+
mcpName: this.name,
|
|
87
|
+
url: this.url
|
|
88
|
+
});
|
|
84
89
|
}
|
|
85
90
|
if (!this.fallbackUrl) {
|
|
86
91
|
throw err;
|
|
@@ -107,7 +112,11 @@ class McpTool {
|
|
|
107
112
|
delete this.startPromise;
|
|
108
113
|
this.client.close().catch((err) => {
|
|
109
114
|
if (err instanceof Error) {
|
|
110
|
-
logger_js_1.logger.error(err.
|
|
115
|
+
logger_js_1.logger.error(`MCP ${this.name} close failed: ${err.message}`, {
|
|
116
|
+
error: err.message,
|
|
117
|
+
stack: err.stack,
|
|
118
|
+
mcpName: this.name
|
|
119
|
+
});
|
|
111
120
|
}
|
|
112
121
|
});
|
|
113
122
|
}, now ? 0 : this.ms);
|
|
@@ -178,7 +187,13 @@ class McpTool {
|
|
|
178
187
|
}
|
|
179
188
|
catch (err) {
|
|
180
189
|
if (err instanceof Error) {
|
|
181
|
-
logger_js_1.logger.error(err.
|
|
190
|
+
logger_js_1.logger.error(`MCP tool call failed: ${err.message}`, {
|
|
191
|
+
error: err.message,
|
|
192
|
+
stack: err.stack,
|
|
193
|
+
mcpName: this.name,
|
|
194
|
+
toolName,
|
|
195
|
+
args: JSON.stringify(args)
|
|
196
|
+
});
|
|
182
197
|
}
|
|
183
198
|
throw err;
|
|
184
199
|
}
|