@mcp-b/webmcp-local-relay 1.7.1 → 1.7.2
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/browser/embed.js +26 -42
- package/package.json +1 -1
package/dist/browser/embed.js
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* Usage:
|
|
5
5
|
* `<script src=".../embed.js" data-relay-host="127.0.0.1" data-relay-port="9333"></script>`
|
|
6
6
|
*
|
|
7
|
+
* Add `data-debug` to enable diagnostic logging:
|
|
8
|
+
* `<script src=".../embed.js" data-debug></script>`
|
|
9
|
+
*
|
|
7
10
|
* @typedef {{ [key: string]: unknown }} JsonObject
|
|
8
11
|
* @typedef {{ name: string; description?: string; inputSchema?: JsonObject }} ToolDescriptor
|
|
9
12
|
* @typedef {{ isError?: boolean; content?: Array<{ type: string; text: string }>; [key: string]: unknown }} ToolInvokeResult
|
|
@@ -25,6 +28,14 @@
|
|
|
25
28
|
return document.currentScript instanceof HTMLScriptElement ? document.currentScript : null;
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
const scriptEl = getCurrentScriptElement();
|
|
32
|
+
const DEBUG = scriptEl ? scriptEl.hasAttribute('data-debug') : false;
|
|
33
|
+
|
|
34
|
+
/** @param {unknown[]} args */
|
|
35
|
+
function debugWarn(...args) {
|
|
36
|
+
if (DEBUG) console.warn('[webmcp-relay-embed]', ...args);
|
|
37
|
+
}
|
|
38
|
+
|
|
28
39
|
/**
|
|
29
40
|
* @param {unknown} value
|
|
30
41
|
* @returns {value is JsonObject}
|
|
@@ -49,17 +60,14 @@
|
|
|
49
60
|
return storedTabId;
|
|
50
61
|
}
|
|
51
62
|
} catch (err) {
|
|
52
|
-
|
|
53
|
-
'[webmcp-relay-embed] sessionStorage read failed, tab ID will not persist:',
|
|
54
|
-
err
|
|
55
|
-
);
|
|
63
|
+
debugWarn('sessionStorage read failed, tab ID will not persist:', err);
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
const tabId = createTabId();
|
|
59
67
|
try {
|
|
60
68
|
sessionStorage.setItem(TAB_ID_STORAGE_KEY, tabId);
|
|
61
69
|
} catch (err) {
|
|
62
|
-
|
|
70
|
+
debugWarn('sessionStorage write failed:', err);
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
return tabId;
|
|
@@ -74,17 +82,10 @@
|
|
|
74
82
|
try {
|
|
75
83
|
return new URL('widget.html', script.src).href;
|
|
76
84
|
} catch (err) {
|
|
77
|
-
|
|
78
|
-
'[webmcp-relay-embed] Failed to resolve widget URL from script src, falling back to CDN.',
|
|
79
|
-
'This may cause version mismatches with your local relay server.',
|
|
80
|
-
err
|
|
81
|
-
);
|
|
85
|
+
debugWarn('Failed to resolve widget URL from script src, falling back to CDN:', err);
|
|
82
86
|
}
|
|
83
87
|
} else {
|
|
84
|
-
|
|
85
|
-
'[webmcp-relay-embed] Script element has no src attribute, falling back to CDN widget URL.',
|
|
86
|
-
'This may cause version mismatches with your local relay server.'
|
|
87
|
-
);
|
|
88
|
+
debugWarn('Script element has no src attribute, falling back to CDN widget URL.');
|
|
88
89
|
}
|
|
89
90
|
return FALLBACK_WIDGET_URL;
|
|
90
91
|
}
|
|
@@ -116,10 +117,8 @@
|
|
|
116
117
|
const parsed = JSON.parse(rawSchema);
|
|
117
118
|
return isJsonObject(parsed) ? parsed : { type: 'object', properties: {} };
|
|
118
119
|
} catch (err) {
|
|
119
|
-
|
|
120
|
-
'
|
|
121
|
-
'The tool will accept any arguments, which may cause invocation errors.',
|
|
122
|
-
'Raw schema:',
|
|
120
|
+
debugWarn(
|
|
121
|
+
'Tool inputSchema is not valid JSON:',
|
|
123
122
|
typeof rawSchema === 'string' ? rawSchema.slice(0, 200) : rawSchema,
|
|
124
123
|
err
|
|
125
124
|
);
|
|
@@ -134,11 +133,7 @@
|
|
|
134
133
|
function toInvokeArgs(value) {
|
|
135
134
|
if (isJsonObject(value)) return value;
|
|
136
135
|
if (value !== undefined && value !== null) {
|
|
137
|
-
|
|
138
|
-
'[webmcp-relay-embed] Tool invocation args must be an object, got',
|
|
139
|
-
typeof value,
|
|
140
|
-
'-- invocation will proceed with empty arguments'
|
|
141
|
-
);
|
|
136
|
+
debugWarn('Tool invocation args must be an object, got', typeof value);
|
|
142
137
|
}
|
|
143
138
|
return {};
|
|
144
139
|
}
|
|
@@ -205,10 +200,7 @@
|
|
|
205
200
|
};
|
|
206
201
|
}
|
|
207
202
|
|
|
208
|
-
|
|
209
|
-
'[webmcp-relay-embed] No WebMCP runtime found (navigator.modelContext or',
|
|
210
|
-
'navigator.modelContextTesting). Tools will not be relayed.'
|
|
211
|
-
);
|
|
203
|
+
debugWarn('No WebMCP runtime found (navigator.modelContext or navigator.modelContextTesting).');
|
|
212
204
|
return null;
|
|
213
205
|
}
|
|
214
206
|
|
|
@@ -238,7 +230,7 @@
|
|
|
238
230
|
);
|
|
239
231
|
})
|
|
240
232
|
.catch((err) => {
|
|
241
|
-
|
|
233
|
+
debugWarn('Failed to push tool changes:', err);
|
|
242
234
|
});
|
|
243
235
|
}, 0);
|
|
244
236
|
}
|
|
@@ -254,12 +246,7 @@
|
|
|
254
246
|
mc.addEventListener('toolschanged', onToolsChanged);
|
|
255
247
|
return true;
|
|
256
248
|
} catch (error) {
|
|
257
|
-
|
|
258
|
-
console.warn(
|
|
259
|
-
'[webmcp-relay-embed] Unexpected error subscribing via addEventListener:',
|
|
260
|
-
error
|
|
261
|
-
);
|
|
262
|
-
}
|
|
249
|
+
debugWarn('addEventListener threw:', error);
|
|
263
250
|
}
|
|
264
251
|
}
|
|
265
252
|
const testing = navigator.modelContextTesting;
|
|
@@ -268,10 +255,7 @@
|
|
|
268
255
|
testing.registerToolsChangedCallback(onToolsChanged);
|
|
269
256
|
return true;
|
|
270
257
|
} catch (error) {
|
|
271
|
-
|
|
272
|
-
'[webmcp-relay-embed] Failed to subscribe via registerToolsChangedCallback:',
|
|
273
|
-
error
|
|
274
|
-
);
|
|
258
|
+
debugWarn('Failed to subscribe via registerToolsChangedCallback:', error);
|
|
275
259
|
}
|
|
276
260
|
}
|
|
277
261
|
return false;
|
|
@@ -302,8 +286,8 @@
|
|
|
302
286
|
}
|
|
303
287
|
if (retries >= MAX_RETRIES) {
|
|
304
288
|
clearInterval(retryTimer);
|
|
305
|
-
|
|
306
|
-
'
|
|
289
|
+
debugWarn(
|
|
290
|
+
'Could not subscribe to tool changes after ' +
|
|
307
291
|
MAX_RETRIES +
|
|
308
292
|
' retries. Dynamic tool updates will not be relayed.'
|
|
309
293
|
);
|
|
@@ -367,7 +351,7 @@
|
|
|
367
351
|
});
|
|
368
352
|
})
|
|
369
353
|
.catch((error) => {
|
|
370
|
-
|
|
354
|
+
debugWarn('Failed to list tools:', error);
|
|
371
355
|
respondToSource(event.source, event.origin, {
|
|
372
356
|
type: 'webmcp.tools.list.response',
|
|
373
357
|
requestId: request.requestId,
|
|
@@ -451,7 +435,7 @@
|
|
|
451
435
|
|
|
452
436
|
let config;
|
|
453
437
|
try {
|
|
454
|
-
config = buildRelayConfig(
|
|
438
|
+
config = buildRelayConfig(scriptEl);
|
|
455
439
|
} catch (err) {
|
|
456
440
|
console.error('[webmcp-relay-embed] Failed to initialize relay configuration:', err);
|
|
457
441
|
return;
|