@mcp-b/global 2.2.0 → 2.3.0
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/README.md +88 -72
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.iife.js +4 -4
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +54 -56
package/README.md
CHANGED
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
|
|
15
15
|
## Why Use @mcp-b/global?
|
|
16
16
|
|
|
17
|
-
| Feature
|
|
18
|
-
|
|
19
|
-
| **W3C Standard**
|
|
20
|
-
| **Drop-in IIFE**
|
|
21
|
-
| **Native Chromium Support**
|
|
22
|
-
| **Dual Transport**
|
|
23
|
-
| **Spec-Aware Compatibility** | `
|
|
24
|
-
| **Works with Any AI**
|
|
17
|
+
| Feature | Benefit |
|
|
18
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
19
|
+
| **W3C Standard** | Implements the emerging Web Model Context API specification |
|
|
20
|
+
| **Drop-in IIFE** | Add AI capabilities with a single `<script>` tag - no build step |
|
|
21
|
+
| **Native Chromium Support** | Auto-detects and uses native browser implementation when available |
|
|
22
|
+
| **Dual Transport** | Works with both same-window clients AND parent pages (iframe support) |
|
|
23
|
+
| **Spec-Aware Compatibility** | Tracks the April 23, 2026 WebMCP draft (`registerTool(tool, { signal })`). Deprecated APIs — `provideContext()`, `clearContext()`, `unregisterTool(name)`, and the `{ unregister }` return handle are still functional but emit one-time warnings and will be removed in the next major version. |
|
|
24
|
+
| **Works with Any AI** | Claude, ChatGPT, Gemini, Cursor, Copilot, and any MCP client |
|
|
25
25
|
|
|
26
26
|
## Package Selection
|
|
27
27
|
|
|
@@ -36,25 +36,25 @@
|
|
|
36
36
|
```html
|
|
37
37
|
<!DOCTYPE html>
|
|
38
38
|
<html>
|
|
39
|
-
<head>
|
|
40
|
-
|
|
41
|
-
</head>
|
|
42
|
-
<body>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
</body>
|
|
39
|
+
<head>
|
|
40
|
+
<script src="https://unpkg.com/@mcp-b/global@latest/dist/index.iife.js"></script>
|
|
41
|
+
</head>
|
|
42
|
+
<body>
|
|
43
|
+
<h1>My AI-Powered App</h1>
|
|
44
|
+
|
|
45
|
+
<script>
|
|
46
|
+
navigator.modelContext.registerTool({
|
|
47
|
+
name: 'get-page-title',
|
|
48
|
+
description: 'Get the current page title',
|
|
49
|
+
inputSchema: { type: 'object', properties: {} },
|
|
50
|
+
async execute() {
|
|
51
|
+
return {
|
|
52
|
+
content: [{ type: 'text', text: document.title }],
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
</script>
|
|
57
|
+
</body>
|
|
58
58
|
</html>
|
|
59
59
|
```
|
|
60
60
|
|
|
@@ -67,7 +67,9 @@
|
|
|
67
67
|
```html
|
|
68
68
|
<script type="module">
|
|
69
69
|
import '@mcp-b/global';
|
|
70
|
-
navigator.modelContext.registerTool({
|
|
70
|
+
navigator.modelContext.registerTool({
|
|
71
|
+
/* your tool */
|
|
72
|
+
});
|
|
71
73
|
</script>
|
|
72
74
|
```
|
|
73
75
|
|
|
@@ -82,7 +84,9 @@ npm install @mcp-b/global
|
|
|
82
84
|
```javascript
|
|
83
85
|
import '@mcp-b/global';
|
|
84
86
|
|
|
85
|
-
navigator.modelContext.registerTool({
|
|
87
|
+
navigator.modelContext.registerTool({
|
|
88
|
+
/* your tool */
|
|
89
|
+
});
|
|
86
90
|
```
|
|
87
91
|
|
|
88
92
|
## API Reference
|
|
@@ -105,6 +109,7 @@ initializeWebModelContext({
|
|
|
105
109
|
```
|
|
106
110
|
|
|
107
111
|
**Behavior:**
|
|
112
|
+
|
|
108
113
|
- Only operates in browser environments
|
|
109
114
|
- Idempotent - calling multiple times is a no-op after first initialization
|
|
110
115
|
- Preserves native `navigator.modelContext` by default (configurable)
|
|
@@ -170,36 +175,43 @@ navigator.modelContext.provideContext({
|
|
|
170
175
|
});
|
|
171
176
|
```
|
|
172
177
|
|
|
173
|
-
#### `registerTool(tool)`
|
|
178
|
+
#### `registerTool(tool, options?)`
|
|
174
179
|
|
|
175
|
-
Registers a single tool. The tool name must be unique
|
|
180
|
+
Registers a single tool. The tool name must be unique, otherwise throws if a tool with the same name already exists. The recommended unregistration path is `options.signal` (`AbortSignal`):
|
|
176
181
|
|
|
177
182
|
```typescript
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
const ac = new AbortController();
|
|
184
|
+
navigator.modelContext.registerTool(
|
|
185
|
+
{
|
|
186
|
+
name: 'add-to-cart',
|
|
187
|
+
description: 'Add a product to the shopping cart',
|
|
188
|
+
inputSchema: {
|
|
189
|
+
type: 'object',
|
|
190
|
+
properties: {
|
|
191
|
+
productId: { type: 'string' },
|
|
192
|
+
quantity: { type: 'integer' },
|
|
193
|
+
},
|
|
194
|
+
required: ['productId'],
|
|
195
|
+
},
|
|
196
|
+
async execute(args) {
|
|
197
|
+
const item = await addToCart(args.productId, args.quantity ?? 1);
|
|
198
|
+
return {
|
|
199
|
+
content: [{ type: 'text', text: `Added ${item.name} to cart` }],
|
|
200
|
+
};
|
|
186
201
|
},
|
|
187
|
-
required: ['productId'],
|
|
188
|
-
},
|
|
189
|
-
async execute(args) {
|
|
190
|
-
const item = await addToCart(args.productId, args.quantity ?? 1);
|
|
191
|
-
return {
|
|
192
|
-
content: [{ type: 'text', text: `Added ${item.name} to cart` }],
|
|
193
|
-
};
|
|
194
202
|
},
|
|
195
|
-
}
|
|
203
|
+
{ signal: ac.signal }
|
|
204
|
+
);
|
|
196
205
|
|
|
197
|
-
|
|
206
|
+
// Later — clean up:
|
|
207
|
+
ac.abort();
|
|
198
208
|
```
|
|
199
209
|
|
|
200
|
-
|
|
210
|
+
For backwards compatibility, `@mcp-b/global` also returns a deprecated `{ unregister }` handle so existing MCP-B integrations do not break, even though current Chromium and the WebMCP spec return `undefined`. The handle will be removed in the next major version.
|
|
201
211
|
|
|
202
|
-
|
|
212
|
+
#### `unregisterTool(nameOrTool)` (deprecated)
|
|
213
|
+
|
|
214
|
+
Removes a tool by name. The April 23, 2026 WebMCP draft removed `unregisterTool` from the spec in favor of `AbortSignal` on `registerTool`. `@mcp-b/global` keeps `unregisterTool` functional for compatibility with older native previews and existing MCP-B integrations, and emits a one-time deprecation warning when called. It will be removed in the next major version.
|
|
203
215
|
|
|
204
216
|
```typescript
|
|
205
217
|
navigator.modelContext.unregisterTool('add-to-cart');
|
|
@@ -238,14 +250,14 @@ const result = await navigator.modelContext.callTool({
|
|
|
238
250
|
|
|
239
251
|
### Tool Descriptor
|
|
240
252
|
|
|
241
|
-
| Property
|
|
242
|
-
|
|
243
|
-
| `name`
|
|
244
|
-
| `description`
|
|
245
|
-
| `inputSchema`
|
|
246
|
-
| `outputSchema` | `InputSchema`
|
|
247
|
-
| `annotations`
|
|
248
|
-
| `execute`
|
|
253
|
+
| Property | Type | Required | Description |
|
|
254
|
+
| -------------- | ----------------------------------------- | -------- | --------------------------------------------------------------------------------------- |
|
|
255
|
+
| `name` | `string` | Yes | Unique identifier for the tool |
|
|
256
|
+
| `description` | `string` | Yes | Natural language description of what the tool does |
|
|
257
|
+
| `inputSchema` | `InputSchema` | No | JSON Schema describing accepted input. Defaults to `{ type: 'object', properties: {} }` |
|
|
258
|
+
| `outputSchema` | `InputSchema` | No | JSON Schema describing the output payload shape |
|
|
259
|
+
| `annotations` | `ToolAnnotations` | No | Hints about tool behavior for LLM planners |
|
|
260
|
+
| `execute` | `(args, client) => Promise<ToolResponse>` | Yes | Async function implementing the tool logic |
|
|
249
261
|
|
|
250
262
|
### Tool Response Format
|
|
251
263
|
|
|
@@ -277,12 +289,12 @@ interface WebModelContextInitOptions {
|
|
|
277
289
|
}
|
|
278
290
|
```
|
|
279
291
|
|
|
280
|
-
| Option
|
|
281
|
-
|
|
282
|
-
| `transport`
|
|
283
|
-
| `autoInitialize`
|
|
284
|
-
| `nativeModelContextBehavior` | `'preserve'`
|
|
285
|
-
| `installTestingShim`
|
|
292
|
+
| Option | Default | Description |
|
|
293
|
+
| ---------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
294
|
+
| `transport` | Auto-detect | Transport layer configuration (tab server and/or iframe) |
|
|
295
|
+
| `autoInitialize` | `true` | Whether to auto-initialize on import |
|
|
296
|
+
| `nativeModelContextBehavior` | `'preserve'` | `'preserve'` keeps native implementation untouched. `'patch'` replaces it with a BrowserMcpServer that mirrors to the native object |
|
|
297
|
+
| `installTestingShim` | `'if-missing'` | Controls `navigator.modelContextTesting` installation. Only installs when not already present natively |
|
|
286
298
|
|
|
287
299
|
### Transport Configuration
|
|
288
300
|
|
|
@@ -364,7 +376,9 @@ const result = await navigator.modelContextTesting?.executeTool(
|
|
|
364
376
|
|
|
365
377
|
```javascript
|
|
366
378
|
if ('modelContext' in navigator) {
|
|
367
|
-
navigator.modelContext.registerTool({
|
|
379
|
+
navigator.modelContext.registerTool({
|
|
380
|
+
/* your tool */
|
|
381
|
+
});
|
|
368
382
|
}
|
|
369
383
|
```
|
|
370
384
|
|
|
@@ -388,7 +402,9 @@ navigator.modelContext.registerTool({
|
|
|
388
402
|
required: ['query'],
|
|
389
403
|
},
|
|
390
404
|
async execute(args) {
|
|
391
|
-
const results = await fetch(
|
|
405
|
+
const results = await fetch(
|
|
406
|
+
`/api/products?q=${args.query}&cat=${args.category ?? ''}&max=${args.maxPrice ?? ''}`
|
|
407
|
+
);
|
|
392
408
|
return { content: [{ type: 'text', text: await results.text() }] };
|
|
393
409
|
},
|
|
394
410
|
});
|
|
@@ -490,12 +506,12 @@ navigator.modelContext.registerTool({
|
|
|
490
506
|
|
|
491
507
|
## Browser Compatibility
|
|
492
508
|
|
|
493
|
-
| Browser
|
|
494
|
-
|
|
495
|
-
| Chrome/Edge (with flag) | Yes
|
|
496
|
-
| Chrome/Edge (default)
|
|
497
|
-
| Firefox
|
|
498
|
-
| Safari
|
|
509
|
+
| Browser | Native Support | Polyfill |
|
|
510
|
+
| ----------------------- | -------------- | -------- |
|
|
511
|
+
| Chrome/Edge (with flag) | Yes | N/A |
|
|
512
|
+
| Chrome/Edge (default) | No | Yes |
|
|
513
|
+
| Firefox | No | Yes |
|
|
514
|
+
| Safari | No | Yes |
|
|
499
515
|
|
|
500
516
|
## Zod Version Compatibility
|
|
501
517
|
|
package/dist/index.d.ts
CHANGED
|
@@ -29,8 +29,7 @@ declare global {
|
|
|
29
29
|
interface Window {
|
|
30
30
|
__webModelContextOptions?: WebModelContextInitOptions;
|
|
31
31
|
}
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=types.d.ts.map
|
|
32
|
+
} //# sourceMappingURL=types.d.ts.map
|
|
34
33
|
//#endregion
|
|
35
34
|
//#region src/global.d.ts
|
|
36
35
|
declare function initializeWebModelContext(options?: WebModelContextInitOptions): void;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/global.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/global.ts"],"mappings":";;;UAEiB,sBAAA;EACf,SAAA,GAAY,OAAA,CAAQ,yBAAA;EACpB,YAAA,GAAe,OAAA,CAAQ,2BAAA;AAAA;AAAA,KAGb,0BAAA;AAAA,UAEK,0BAAA;EACf,SAAA,GAAY,sBAAA;EACZ,cAAA;EAPe;;;;;;;EAef,0BAAA,GAA6B,0BAAA;EAfN;;;AAGzB;;;EAmBE,kBAAA;AAAA;AAAA,QAGM,MAAA;EAAA,UACI,MAAA;IACR,wBAAA,GAA2B,0BAAA;EAAA;AAAA;;;iBCgKf,yBAAA,CAA0B,OAAA,GAAU,0BAAA;AAAA,iBA+CpC,sBAAA,CAAA"}
|