@mcp-b/global 5.1.0 → 6.0.0-beta.20261001010549
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 +69 -65
- package/dist/index.d.ts +2 -11
- package/dist/index.iife.js +11 -6
- package/dist/index.js +24 -73
- package/dist/index.js.map +1 -1
- package/package.json +5 -8
package/README.md
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/@mcp-b/global)
|
|
6
6
|
[](https://www.npmjs.com/package/@mcp-b/global)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
|
-
[](https://bundlephobia.com/package/@mcp-b/global)
|
|
9
8
|
[](https://webmachinelearning.github.io/webmcp/)
|
|
10
9
|
|
|
11
10
|
**[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)**
|
|
@@ -14,20 +13,40 @@
|
|
|
14
13
|
|
|
15
14
|
## Why Use @mcp-b/global?
|
|
16
15
|
|
|
17
|
-
| Feature | Benefit
|
|
18
|
-
| ---------------------------- |
|
|
19
|
-
| **W3C Standard** | Implements the emerging WebMCP 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 })`, and `getTools()`)
|
|
24
|
-
| **Works with Any AI** | Claude, ChatGPT, Gemini, Cursor, Copilot, and any MCP client
|
|
16
|
+
| Feature | Benefit |
|
|
17
|
+
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
18
|
+
| **W3C Standard** | Implements the emerging WebMCP API specification |
|
|
19
|
+
| **Drop-in IIFE** | Add AI capabilities with a single `<script>` tag - no build step |
|
|
20
|
+
| **Native Chromium Support** | Auto-detects and uses native browser implementation when available |
|
|
21
|
+
| **Dual Transport** | Works with both same-window clients AND parent pages (iframe support) |
|
|
22
|
+
| **Spec-Aware Compatibility** | Tracks the current WebMCP draft (`document.modelContext`, `registerTool(tool, { signal })`, and `getTools()`) and object-input `executeTool(...)`. |
|
|
23
|
+
| **Works with Any AI** | Claude, ChatGPT, Gemini, Cursor, Copilot, and any MCP client |
|
|
25
24
|
|
|
26
25
|
## Package Selection
|
|
27
26
|
|
|
28
|
-
- Use
|
|
27
|
+
- Use upstream `webmcp-types` for standard browser contracts and `@mcp-b/webmcp-ts-sdk` for MCP-B extensions.
|
|
29
28
|
- Use `@mcp-b/webmcp-polyfill` when you only need strict WebMCP runtime polyfill behavior.
|
|
30
|
-
- Use `@mcp-b/global` when you want MCPB integration features (bridge transport, prompts/resources,
|
|
29
|
+
- Use `@mcp-b/global` when you want MCPB integration features (bridge transport, prompts/resources, extension APIs).
|
|
30
|
+
|
|
31
|
+
## Upstream runtime
|
|
32
|
+
|
|
33
|
+
When no context is installed, `@mcp-b/global` calls `installWebMCP()` from
|
|
34
|
+
`@mcp-b/webmcp-polyfill`. That package bundles the upstream
|
|
35
|
+
[WebMCP polyfill](https://github.com/webmachinelearning/webmcp-polyfill) at
|
|
36
|
+
revision `439c6c341f1c632c63498ba206e2bd8471cb8efb`. It depends on the
|
|
37
|
+
upstream `webmcp-types` declarations. Consumers do not install or build a Git
|
|
38
|
+
dependency.
|
|
39
|
+
|
|
40
|
+
`@mcp-b/webmcp-polyfill` retains the declarative API and its `SubmitEvent` extensions
|
|
41
|
+
until upstream supports them. `@mcp-b/global` adds MCP-B transports, prompts,
|
|
42
|
+
resources, MCP `outputSchema` metadata, and structured MCP responses. Existing native
|
|
43
|
+
contexts take precedence and receive the MCP-B adapter when wrapped,
|
|
44
|
+
including when the upstream polyfill was installed before `@mcp-b/global`.
|
|
45
|
+
`cleanupWebModelContext()` removes the MCP-B adapter; the polyfill context and
|
|
46
|
+
declarative layer remain installed for the document lifetime. Existing native
|
|
47
|
+
`SubmitEvent` hooks are preserved.
|
|
48
|
+
|
|
49
|
+
`executeTool(tool, inputObject)` follows the current draft and returns JSON.
|
|
31
50
|
|
|
32
51
|
## Quick Start
|
|
33
52
|
|
|
@@ -37,7 +56,7 @@
|
|
|
37
56
|
<!DOCTYPE html>
|
|
38
57
|
<html>
|
|
39
58
|
<head>
|
|
40
|
-
<script src="https://unpkg.com/@mcp-b/global@
|
|
59
|
+
<script src="https://unpkg.com/@mcp-b/global@6/dist/index.iife.js"></script>
|
|
41
60
|
</head>
|
|
42
61
|
<body>
|
|
43
62
|
<h1>My AI-Powered App</h1>
|
|
@@ -60,7 +79,7 @@
|
|
|
60
79
|
</html>
|
|
61
80
|
```
|
|
62
81
|
|
|
63
|
-
- **Self-contained** - All dependencies bundled
|
|
82
|
+
- **Self-contained** - All dependencies bundled
|
|
64
83
|
- **Auto-initializes** - `document.modelContext` ready immediately
|
|
65
84
|
- **No build step** - Just drop it in your HTML
|
|
66
85
|
|
|
@@ -75,7 +94,8 @@
|
|
|
75
94
|
</script>
|
|
76
95
|
```
|
|
77
96
|
|
|
78
|
-
The ESM
|
|
97
|
+
The ESM entry keeps `@mcp-b/transports`, `@mcp-b/webmcp-polyfill`, and
|
|
98
|
+
`@mcp-b/webmcp-ts-sdk` external; only the IIFE bundles them.
|
|
79
99
|
|
|
80
100
|
### Via NPM
|
|
81
101
|
|
|
@@ -127,7 +147,9 @@ await document.modelContext.registerTool({
|
|
|
127
147
|
#### `cleanupWebModelContext()`
|
|
128
148
|
|
|
129
149
|
Tears down the adapter and restores `document.modelContext` to the captured native or polyfilled
|
|
130
|
-
context.
|
|
150
|
+
context. Closing the adapter aborts every registration made through `document.modelContext` while
|
|
151
|
+
it was installed; re-initializing does not restore them. Tools registered directly on the underlying
|
|
152
|
+
context, including declarative tools, survive.
|
|
131
153
|
|
|
132
154
|
```typescript
|
|
133
155
|
import { cleanupWebModelContext, initializeWebModelContext } from '@mcp-b/global';
|
|
@@ -186,43 +208,33 @@ Returns WebMCP tool descriptors for all registered tools.
|
|
|
186
208
|
|
|
187
209
|
```typescript
|
|
188
210
|
const tools = await document.modelContext.getTools();
|
|
189
|
-
// [{ name: 'search-products', inputSchema:
|
|
211
|
+
// [{ name: 'search-products', inputSchema: { type: 'object', ... }, ... }, ...]
|
|
190
212
|
```
|
|
191
213
|
|
|
192
|
-
#### `executeTool(tool,
|
|
214
|
+
#### `executeTool(tool, inputObject)`
|
|
193
215
|
|
|
194
|
-
|
|
195
|
-
on the canonical document surface.
|
|
196
|
-
|
|
197
|
-
```bash
|
|
198
|
-
npm install --save-dev @mcp-b/webmcp-types
|
|
199
|
-
```
|
|
216
|
+
Execute a discovered descriptor with an input object. The result is serialized JSON.
|
|
200
217
|
|
|
201
218
|
```typescript
|
|
202
219
|
import '@mcp-b/global';
|
|
203
|
-
import type { ChromeModelContext } from '@mcp-b/webmcp-types';
|
|
204
220
|
|
|
205
|
-
const modelContext = document.modelContext
|
|
206
|
-
if (
|
|
207
|
-
throw new Error('Tool execution is unavailable');
|
|
208
|
-
}
|
|
221
|
+
const modelContext = document.modelContext;
|
|
222
|
+
if (!modelContext) throw new Error('WebMCP is unavailable');
|
|
209
223
|
|
|
210
224
|
const tools = await modelContext.getTools();
|
|
211
225
|
const searchTool = tools.find((tool) => tool.name === 'search-products');
|
|
212
226
|
if (!searchTool) throw new Error('search-products is not available');
|
|
213
227
|
|
|
214
|
-
const
|
|
215
|
-
searchTool,
|
|
216
|
-
JSON.stringify({ query: 'laptop', limit: 5 })
|
|
228
|
+
const result = JSON.parse(
|
|
229
|
+
await modelContext.executeTool(searchTool, { query: 'laptop', limit: 5 })
|
|
217
230
|
);
|
|
218
|
-
const result = resultJson === null ? null : JSON.parse(resultJson);
|
|
219
231
|
// { content: [{ type: 'text', text: '...' }] }
|
|
220
232
|
```
|
|
221
233
|
|
|
222
234
|
#### `listTools()`
|
|
223
235
|
|
|
224
236
|
This MCP-B helper exposes MCP metadata. In-page WebMCP consumers should use
|
|
225
|
-
`getTools()` and
|
|
237
|
+
`getTools()` and `executeTool(tool, inputObject)`.
|
|
226
238
|
|
|
227
239
|
Prompt, resource, and lower-level MCP helpers are MCP-B extensions. Narrow
|
|
228
240
|
`document.modelContext` with `isBrowserMcpServer()` from
|
|
@@ -269,15 +281,13 @@ Tools may return an MCP `CallToolResult` object:
|
|
|
269
281
|
interface WebModelContextInitOptions {
|
|
270
282
|
transport?: TransportConfiguration;
|
|
271
283
|
autoInitialize?: boolean;
|
|
272
|
-
installTestingShim?: boolean;
|
|
273
284
|
}
|
|
274
285
|
```
|
|
275
286
|
|
|
276
|
-
| Option
|
|
277
|
-
|
|
|
278
|
-
| `transport`
|
|
279
|
-
| `autoInitialize`
|
|
280
|
-
| `installTestingShim` | `true` | Installs `navigator.modelContextTesting` only when no implementation is present |
|
|
287
|
+
| Option | Default | Description |
|
|
288
|
+
| ---------------- | ----------- | -------------------------------------------------------- |
|
|
289
|
+
| `transport` | Auto-detect | Transport layer configuration (tab server and/or iframe) |
|
|
290
|
+
| `autoInitialize` | `true` | Whether to auto-initialize on import |
|
|
281
291
|
|
|
282
292
|
### Transport Configuration
|
|
283
293
|
|
|
@@ -320,7 +330,7 @@ The package auto-initializes on import in browser environments. To customize bef
|
|
|
320
330
|
},
|
|
321
331
|
};
|
|
322
332
|
</script>
|
|
323
|
-
<script src="https://unpkg.com/@mcp-b/global@
|
|
333
|
+
<script src="https://unpkg.com/@mcp-b/global@6/dist/index.iife.js"></script>
|
|
324
334
|
```
|
|
325
335
|
|
|
326
336
|
To prevent auto-initialization:
|
|
@@ -329,29 +339,13 @@ To prevent auto-initialization:
|
|
|
329
339
|
<script>
|
|
330
340
|
window.__webModelContextOptions = { autoInitialize: false };
|
|
331
341
|
</script>
|
|
332
|
-
<script src="https://unpkg.com/@mcp-b/global@
|
|
342
|
+
<script src="https://unpkg.com/@mcp-b/global@6/dist/index.iife.js"></script>
|
|
333
343
|
<script>
|
|
334
344
|
// Initialize manually later
|
|
335
345
|
WebMCP.initializeWebModelContext();
|
|
336
346
|
</script>
|
|
337
347
|
```
|
|
338
348
|
|
|
339
|
-
## Testing
|
|
340
|
-
|
|
341
|
-
`navigator.modelContextTesting` provides a testing shim that stays in sync with registered tools:
|
|
342
|
-
|
|
343
|
-
```typescript
|
|
344
|
-
// List registered tools
|
|
345
|
-
const tools = navigator.modelContextTesting?.listTools();
|
|
346
|
-
// [{ name: 'search-products', description: '...', inputSchema: '...' }]
|
|
347
|
-
|
|
348
|
-
// Execute a tool (input args as JSON string)
|
|
349
|
-
const result = await navigator.modelContextTesting?.executeTool(
|
|
350
|
-
'search-products',
|
|
351
|
-
'{"query": "laptop"}'
|
|
352
|
-
);
|
|
353
|
-
```
|
|
354
|
-
|
|
355
349
|
## Feature Detection
|
|
356
350
|
|
|
357
351
|
```javascript
|
|
@@ -510,12 +504,21 @@ await document.modelContext.registerTool({
|
|
|
510
504
|
|
|
511
505
|
## Browser Compatibility
|
|
512
506
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
507
|
+
Native WebMCP needs Chrome 155 or newer with the WebMCP feature enabled; the
|
|
508
|
+
runtime wraps the native context when it exists. Everywhere else the bundled
|
|
509
|
+
polyfill runs. Its `installWebMCP()` installs only when the engine provides
|
|
510
|
+
every API the vendored core calls. Otherwise it returns without defining
|
|
511
|
+
`document.modelContext`, so `if (!document.modelContext)` remains a valid
|
|
512
|
+
feature check.
|
|
513
|
+
|
|
514
|
+
| API | Chrome | Firefox | Safari |
|
|
515
|
+
| ------------------------------- | ------ | ------- | ------ |
|
|
516
|
+
| `String.prototype.toWellFormed` | 111 | 119 | 16.4 |
|
|
517
|
+
| `AbortSignal.any()` | 116 | 124 | 17.4 |
|
|
518
|
+
| `Promise.withResolvers()` | 119 | 121 | 17.4 |
|
|
519
|
+
| `URL.parse()` | 126 | 126 | 18 |
|
|
520
|
+
|
|
521
|
+
The resulting floor is Chrome 126, Firefox 126, and Safari 18.
|
|
519
522
|
|
|
520
523
|
## Schema Compatibility
|
|
521
524
|
|
|
@@ -531,12 +534,13 @@ This package exports its initialization options:
|
|
|
531
534
|
import type { TransportConfiguration, WebModelContextInitOptions } from '@mcp-b/global';
|
|
532
535
|
```
|
|
533
536
|
|
|
534
|
-
Import browser
|
|
537
|
+
Import core browser contracts from upstream `webmcp-types`. Use
|
|
538
|
+
`@mcp-b/webmcp-ts-sdk` for MCP-B extensions.
|
|
535
539
|
|
|
536
540
|
## Tool Routing Contract
|
|
537
541
|
|
|
538
542
|
- MCP `tools/list`, `tools/call`, and tool list update notifications are sourced from the `BrowserMcpServer` registry.
|
|
539
|
-
- Native and polyfill tool backfill use `getTools()`
|
|
543
|
+
- Native and polyfill tool backfill use `getTools()` and object-input `executeTool()`.
|
|
540
544
|
|
|
541
545
|
## Related Packages
|
|
542
546
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="@mcp-b/webmcp-types" preserve="true" />
|
|
2
1
|
import { IframeChildTransportOptions, TabServerTransportOptions } from "@mcp-b/transports";
|
|
2
|
+
import { WebMCP } from "@mcp-b/webmcp-polyfill";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
5
|
interface TransportConfiguration {
|
|
@@ -13,15 +13,6 @@ interface TransportConfiguration {
|
|
|
13
13
|
interface WebModelContextInitOptions {
|
|
14
14
|
transport?: TransportConfiguration;
|
|
15
15
|
autoInitialize?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Forwarded to @mcp-b/webmcp-polyfill when polyfill installation is needed.
|
|
18
|
-
* Existing modelContextTesting implementations are never replaced.
|
|
19
|
-
*
|
|
20
|
-
* Deliberately inverts the polyfill's own default (false): this entry point is the
|
|
21
|
-
* batteries-included one, and the e2e suites rely on the shim being present.
|
|
22
|
-
* @default true
|
|
23
|
-
*/
|
|
24
|
-
installTestingShim?: boolean;
|
|
25
16
|
}
|
|
26
17
|
declare global {
|
|
27
18
|
interface Window {
|
|
@@ -34,5 +25,5 @@ declare global {
|
|
|
34
25
|
declare function initializeWebModelContext(options?: WebModelContextInitOptions): void;
|
|
35
26
|
declare function cleanupWebModelContext(): void;
|
|
36
27
|
//#endregion
|
|
37
|
-
export { type TransportConfiguration, type WebModelContextInitOptions, cleanupWebModelContext, initializeWebModelContext };
|
|
28
|
+
export { type TransportConfiguration, type WebMCP, type WebModelContextInitOptions, cleanupWebModelContext, initializeWebModelContext };
|
|
38
29
|
//# sourceMappingURL=index.d.ts.map
|