@mcp-b/global 2.3.2 → 3.0.0-beta.20260702171253
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 +94 -115
- package/dist/index.d.ts.map +1 -1
- package/dist/index.iife.js +13 -6
- package/dist/index.js +49 -14
- package/dist/index.js.map +1 -1
- package/package.json +13 -12
package/README.md
CHANGED
|
@@ -6,22 +6,22 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/@mcp-b/global)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
[](https://bundlephobia.com/package/@mcp-b/global)
|
|
9
|
-
[](https://github.
|
|
9
|
+
[](https://webmachinelearning.github.io/webmcp/)
|
|
10
10
|
|
|
11
|
-
**[
|
|
11
|
+
**[Reference](https://docs.mcp-b.ai/packages/global/reference)** | **[First Tool Tutorial](https://docs.mcp-b.ai/tutorials/first-tool)** | **[Add Tools to an App](https://docs.mcp-b.ai/how-to/add-tools-to-an-existing-app)**
|
|
12
12
|
|
|
13
|
-
**@mcp-b/global** implements the [W3C Web Model Context API](https://github.
|
|
13
|
+
**@mcp-b/global** implements the [W3C Web Model Context API](https://webmachinelearning.github.io/webmcp/) (`document.modelContext`) specification, allowing AI agents like Claude, ChatGPT, Gemini, Cursor, and Copilot to discover and call functions on your website.
|
|
14
14
|
|
|
15
15
|
## Why Use @mcp-b/global?
|
|
16
16
|
|
|
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
|
|
24
|
-
| **Works with Any AI** | Claude, ChatGPT, Gemini, Cursor, Copilot, and any MCP client
|
|
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 current WebMCP draft (`document.modelContext`, `registerTool(tool, { signal })`, `getTools()`, and `executeTool(...)`). Deprecated `unregisterTool(name)` remains for existing MCP-B integrations 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
|
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
<h1>My AI-Powered App</h1>
|
|
44
44
|
|
|
45
45
|
<script>
|
|
46
|
-
|
|
46
|
+
document.modelContext.registerTool({
|
|
47
47
|
name: 'get-page-title',
|
|
48
48
|
description: 'Get the current page title',
|
|
49
49
|
inputSchema: { type: 'object', properties: {} },
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
- **Self-contained** - All dependencies bundled (285KB minified)
|
|
62
|
-
- **Auto-initializes** - `
|
|
62
|
+
- **Auto-initializes** - `document.modelContext` ready immediately
|
|
63
63
|
- **No build step** - Just drop it in your HTML
|
|
64
64
|
|
|
65
65
|
### Via ES Module
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
```html
|
|
68
68
|
<script type="module">
|
|
69
69
|
import '@mcp-b/global';
|
|
70
|
-
|
|
70
|
+
document.modelContext.registerTool({
|
|
71
71
|
/* your tool */
|
|
72
72
|
});
|
|
73
73
|
</script>
|
|
@@ -84,7 +84,7 @@ npm install @mcp-b/global
|
|
|
84
84
|
```javascript
|
|
85
85
|
import '@mcp-b/global';
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
document.modelContext.registerTool({
|
|
88
88
|
/* your tool */
|
|
89
89
|
});
|
|
90
90
|
```
|
|
@@ -95,7 +95,7 @@ navigator.modelContext.registerTool({
|
|
|
95
95
|
|
|
96
96
|
#### `initializeWebModelContext(options?)`
|
|
97
97
|
|
|
98
|
-
Initializes the global adapter. Replaces `
|
|
98
|
+
Initializes the global adapter. Replaces `document.modelContext` with a `BrowserMcpServer` instance that bridges WebMCP tools to the MCP protocol layer.
|
|
99
99
|
|
|
100
100
|
```typescript
|
|
101
101
|
import { initializeWebModelContext } from '@mcp-b/global';
|
|
@@ -112,12 +112,12 @@ initializeWebModelContext({
|
|
|
112
112
|
|
|
113
113
|
- Only operates in browser environments
|
|
114
114
|
- Idempotent - calling multiple times is a no-op after first initialization
|
|
115
|
-
- Preserves native `
|
|
115
|
+
- Preserves native `document.modelContext` by default (configurable)
|
|
116
116
|
- Auto-called on import unless `window.__webModelContextOptions.autoInitialize` is `false`
|
|
117
117
|
|
|
118
118
|
#### `cleanupWebModelContext()`
|
|
119
119
|
|
|
120
|
-
Tears down the adapter and restores `
|
|
120
|
+
Tears down the adapter and restores `document.modelContext` to its original state. Allows re-initialization.
|
|
121
121
|
|
|
122
122
|
```typescript
|
|
123
123
|
import { cleanupWebModelContext, initializeWebModelContext } from '@mcp-b/global';
|
|
@@ -130,50 +130,9 @@ cleanupWebModelContext();
|
|
|
130
130
|
initializeWebModelContext();
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
-
### `
|
|
133
|
+
### `document.modelContext` Methods
|
|
134
134
|
|
|
135
|
-
After initialization, `
|
|
136
|
-
|
|
137
|
-
#### `provideContext(options?)`
|
|
138
|
-
|
|
139
|
-
Deprecated compatibility API. The upstream WebMCP spec removed `provideContext()` on March 5, 2026. `@mcp-b/global` keeps it functional for now, but logs a deprecation warning and will remove it in the next major version.
|
|
140
|
-
|
|
141
|
-
Replaces all currently registered tools with a new set. This is an atomic replacement - all previous tools are removed first.
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
navigator.modelContext.provideContext({
|
|
145
|
-
tools: [
|
|
146
|
-
{
|
|
147
|
-
name: 'search-products',
|
|
148
|
-
description: 'Search the product catalog by query',
|
|
149
|
-
inputSchema: {
|
|
150
|
-
type: 'object',
|
|
151
|
-
properties: {
|
|
152
|
-
query: { type: 'string', description: 'Search query' },
|
|
153
|
-
limit: { type: 'integer', description: 'Max results' },
|
|
154
|
-
},
|
|
155
|
-
required: ['query'],
|
|
156
|
-
},
|
|
157
|
-
async execute(args) {
|
|
158
|
-
const results = await searchProducts(args.query, args.limit ?? 10);
|
|
159
|
-
return {
|
|
160
|
-
content: [{ type: 'text', text: JSON.stringify(results) }],
|
|
161
|
-
};
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
name: 'get-cart',
|
|
166
|
-
description: 'Get the current shopping cart contents',
|
|
167
|
-
inputSchema: { type: 'object', properties: {} },
|
|
168
|
-
async execute() {
|
|
169
|
-
return {
|
|
170
|
-
content: [{ type: 'text', text: JSON.stringify(getCart()) }],
|
|
171
|
-
};
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
});
|
|
176
|
-
```
|
|
135
|
+
After initialization, `document.modelContext` exposes these methods:
|
|
177
136
|
|
|
178
137
|
#### `registerTool(tool, options?)`
|
|
179
138
|
|
|
@@ -181,7 +140,7 @@ Registers a single tool. The tool name must be unique, otherwise throws if a too
|
|
|
181
140
|
|
|
182
141
|
```typescript
|
|
183
142
|
const ac = new AbortController();
|
|
184
|
-
|
|
143
|
+
document.modelContext.registerTool(
|
|
185
144
|
{
|
|
186
145
|
name: 'add-to-cart',
|
|
187
146
|
description: 'Add a product to the shopping cart',
|
|
@@ -207,47 +166,46 @@ navigator.modelContext.registerTool(
|
|
|
207
166
|
ac.abort();
|
|
208
167
|
```
|
|
209
168
|
|
|
210
|
-
|
|
169
|
+
`registerTool` resolves `undefined`, matching current Chromium and the WebMCP spec. Use `AbortSignal` cleanup for dynamic tools.
|
|
211
170
|
|
|
212
171
|
#### `unregisterTool(nameOrTool)` (deprecated)
|
|
213
172
|
|
|
214
173
|
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.
|
|
215
174
|
|
|
216
175
|
```typescript
|
|
217
|
-
|
|
176
|
+
document.modelContext.unregisterTool('add-to-cart');
|
|
218
177
|
```
|
|
219
178
|
|
|
220
|
-
#### `
|
|
179
|
+
#### `getTools()`
|
|
221
180
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
Removes all registered tools.
|
|
181
|
+
Returns WebMCP tool descriptors for all registered tools.
|
|
225
182
|
|
|
226
183
|
```typescript
|
|
227
|
-
|
|
184
|
+
const tools = await document.modelContext.getTools();
|
|
185
|
+
// [{ name: 'search-products', inputSchema: '{"type":"object",...}', ... }, ...]
|
|
228
186
|
```
|
|
229
187
|
|
|
230
|
-
#### `
|
|
188
|
+
#### `executeTool(tool, inputArgsJson)`
|
|
231
189
|
|
|
232
|
-
|
|
190
|
+
Executes a tool descriptor returned from `getTools()`.
|
|
233
191
|
|
|
234
192
|
```typescript
|
|
235
|
-
const tools =
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
#### `callTool(params)`
|
|
193
|
+
const tools = await document.modelContext.getTools();
|
|
194
|
+
const searchTool = tools.find((tool) => tool.name === 'search-products');
|
|
195
|
+
if (!searchTool) throw new Error('search-products is not available');
|
|
240
196
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
arguments: { query: 'laptop', limit: 5 },
|
|
247
|
-
});
|
|
197
|
+
const resultJson = await document.modelContext.executeTool(
|
|
198
|
+
searchTool,
|
|
199
|
+
JSON.stringify({ query: 'laptop', limit: 5 })
|
|
200
|
+
);
|
|
201
|
+
const result = resultJson === null ? null : JSON.parse(resultJson);
|
|
248
202
|
// { content: [{ type: 'text', text: '...' }] }
|
|
249
203
|
```
|
|
250
204
|
|
|
205
|
+
#### `listTools()` and `callTool(params)` (deprecated)
|
|
206
|
+
|
|
207
|
+
These MCP-B compatibility helpers remain available for older integrations. Prefer `getTools()` and `executeTool(tool, inputArgsJson)` for in-page WebMCP consumers.
|
|
208
|
+
|
|
251
209
|
### Tool Descriptor
|
|
252
210
|
|
|
253
211
|
| Property | Type | Required | Description |
|
|
@@ -376,7 +334,7 @@ const result = await navigator.modelContextTesting?.executeTool(
|
|
|
376
334
|
|
|
377
335
|
```javascript
|
|
378
336
|
if ('modelContext' in navigator) {
|
|
379
|
-
|
|
337
|
+
document.modelContext.registerTool({
|
|
380
338
|
/* your tool */
|
|
381
339
|
});
|
|
382
340
|
}
|
|
@@ -389,7 +347,7 @@ if ('modelContext' in navigator) {
|
|
|
389
347
|
```typescript
|
|
390
348
|
import '@mcp-b/global';
|
|
391
349
|
|
|
392
|
-
|
|
350
|
+
document.modelContext.registerTool({
|
|
393
351
|
name: 'search-products',
|
|
394
352
|
description: 'Search products by keyword, category, or price range',
|
|
395
353
|
inputSchema: {
|
|
@@ -409,7 +367,7 @@ navigator.modelContext.registerTool({
|
|
|
409
367
|
},
|
|
410
368
|
});
|
|
411
369
|
|
|
412
|
-
|
|
370
|
+
document.modelContext.registerTool({
|
|
413
371
|
name: 'add-to-cart',
|
|
414
372
|
description: 'Add a product to the shopping cart',
|
|
415
373
|
inputSchema: {
|
|
@@ -436,35 +394,57 @@ navigator.modelContext.registerTool({
|
|
|
436
394
|
import '@mcp-b/global';
|
|
437
395
|
|
|
438
396
|
// Start with base tools
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
397
|
+
const userToolController = new AbortController();
|
|
398
|
+
document.modelContext.registerTool(
|
|
399
|
+
{
|
|
400
|
+
name: 'get-user',
|
|
401
|
+
description: 'Get current user info',
|
|
402
|
+
inputSchema: { type: 'object', properties: {} },
|
|
403
|
+
async execute() {
|
|
404
|
+
return { content: [{ type: 'text', text: JSON.stringify(currentUser) }] };
|
|
405
|
+
},
|
|
445
406
|
},
|
|
446
|
-
}
|
|
407
|
+
{ signal: userToolController.signal }
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
let adminToolController: AbortController | undefined;
|
|
411
|
+
|
|
412
|
+
function registerAdminTool() {
|
|
413
|
+
adminToolController?.abort();
|
|
414
|
+
adminToolController = new AbortController();
|
|
415
|
+
|
|
416
|
+
document.modelContext.registerTool(
|
|
417
|
+
{
|
|
418
|
+
name: 'delete-user',
|
|
419
|
+
description: 'Delete a user account (admin only)',
|
|
420
|
+
inputSchema: {
|
|
421
|
+
type: 'object',
|
|
422
|
+
properties: { userId: { type: 'string' } },
|
|
423
|
+
required: ['userId'],
|
|
424
|
+
},
|
|
425
|
+
async execute(args) {
|
|
426
|
+
await fetch(`/api/users/${args.userId}`, { method: 'DELETE' });
|
|
427
|
+
return { content: [{ type: 'text', text: 'User deleted' }] };
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
{ signal: adminToolController.signal }
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function unregisterAdminTool() {
|
|
435
|
+
adminToolController?.abort();
|
|
436
|
+
adminToolController = undefined;
|
|
437
|
+
}
|
|
447
438
|
|
|
448
439
|
// Add tools dynamically based on user role
|
|
449
440
|
if (currentUser.isAdmin) {
|
|
450
|
-
|
|
451
|
-
name: 'delete-user',
|
|
452
|
-
description: 'Delete a user account (admin only)',
|
|
453
|
-
inputSchema: {
|
|
454
|
-
type: 'object',
|
|
455
|
-
properties: { userId: { type: 'string' } },
|
|
456
|
-
required: ['userId'],
|
|
457
|
-
},
|
|
458
|
-
async execute(args) {
|
|
459
|
-
await fetch(`/api/users/${args.userId}`, { method: 'DELETE' });
|
|
460
|
-
return { content: [{ type: 'text', text: 'User deleted' }] };
|
|
461
|
-
},
|
|
462
|
-
});
|
|
441
|
+
registerAdminTool();
|
|
463
442
|
}
|
|
464
443
|
|
|
465
444
|
// Remove tools when permissions change
|
|
466
445
|
function onLogout() {
|
|
467
|
-
|
|
446
|
+
userToolController.abort();
|
|
447
|
+
unregisterAdminTool();
|
|
468
448
|
}
|
|
469
449
|
```
|
|
470
450
|
|
|
@@ -473,7 +453,7 @@ function onLogout() {
|
|
|
473
453
|
```typescript
|
|
474
454
|
import '@mcp-b/global';
|
|
475
455
|
|
|
476
|
-
|
|
456
|
+
document.modelContext.registerTool({
|
|
477
457
|
name: 'fill-contact-form',
|
|
478
458
|
description: 'Fill the contact form with provided details',
|
|
479
459
|
inputSchema: {
|
|
@@ -493,7 +473,7 @@ navigator.modelContext.registerTool({
|
|
|
493
473
|
},
|
|
494
474
|
});
|
|
495
475
|
|
|
496
|
-
|
|
476
|
+
document.modelContext.registerTool({
|
|
497
477
|
name: 'submit-form',
|
|
498
478
|
description: 'Submit the contact form',
|
|
499
479
|
inputSchema: { type: 'object', properties: {} },
|
|
@@ -527,7 +507,6 @@ import type {
|
|
|
527
507
|
InputSchema,
|
|
528
508
|
ModelContext,
|
|
529
509
|
ModelContextCore,
|
|
530
|
-
ModelContextOptions,
|
|
531
510
|
NativeModelContextBehavior,
|
|
532
511
|
ToolAnnotations,
|
|
533
512
|
ToolDescriptor,
|
|
@@ -545,15 +524,15 @@ import type {
|
|
|
545
524
|
|
|
546
525
|
## Related Packages
|
|
547
526
|
|
|
548
|
-
- [`@mcp-b/transports`](https://docs.mcp-b.ai/packages/transports) - MCP transport implementations
|
|
549
|
-
- [`@mcp-b/react-webmcp`](https://docs.mcp-b.ai/packages/react-webmcp) - React hooks for MCP
|
|
550
|
-
- [`@mcp-b/extension-tools`](https://docs.mcp-b.ai/packages/extension-tools) - Chrome Extension API tools
|
|
551
|
-
- [`@mcp-b/chrome-devtools-mcp`](https://docs.mcp-b.ai/packages/chrome-devtools-mcp) - Connect desktop AI agents to browser tools
|
|
527
|
+
- [`@mcp-b/transports`](https://docs.mcp-b.ai/packages/transports/reference) - MCP transport implementations
|
|
528
|
+
- [`@mcp-b/react-webmcp`](https://docs.mcp-b.ai/packages/react-webmcp/reference) - React hooks for MCP
|
|
529
|
+
- [`@mcp-b/extension-tools`](https://docs.mcp-b.ai/packages/extension-tools/reference) - Chrome Extension API tools
|
|
530
|
+
- [`@mcp-b/chrome-devtools-mcp`](https://docs.mcp-b.ai/packages/chrome-devtools-mcp/reference) - Connect desktop AI agents to browser tools
|
|
552
531
|
|
|
553
532
|
## Resources
|
|
554
533
|
|
|
555
534
|
- [WebMCP Documentation](https://docs.mcp-b.ai)
|
|
556
|
-
- [Web Model Context API Explainer](https://github.
|
|
535
|
+
- [Web Model Context API Explainer](https://webmachinelearning.github.io/webmcp/)
|
|
557
536
|
- [Model Context Protocol Spec](https://modelcontextprotocol.io/)
|
|
558
537
|
|
|
559
538
|
## License
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;;;
|
|
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;;;iBC4Mf,yBAAA,CAA0B,OAAA,GAAU,0BAAA;AAAA,iBA6DpC,sBAAA,CAAA"}
|