@mcp-b/webmcp-polyfill 0.2.0 → 0.2.1
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 +77 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,6 +11,21 @@ Strict WebMCP core runtime polyfill for `navigator.modelContext`.
|
|
|
11
11
|
|
|
12
12
|
It does not install MCP bridge extensions like `callTool`, resources, or prompts.
|
|
13
13
|
|
|
14
|
+
Important:
|
|
15
|
+
|
|
16
|
+
- `navigator.modelContext` in this package does not provide `listTools()` or `callTool(...)`.
|
|
17
|
+
- For list/execute test flows, use `navigator.modelContextTesting` (when `installTestingShim` is enabled).
|
|
18
|
+
|
|
19
|
+
## Type Safety First
|
|
20
|
+
|
|
21
|
+
`@mcp-b/webmcp-polyfill` is runtime-focused. For compile-time safety, pair it with
|
|
22
|
+
`@mcp-b/webmcp-types`.
|
|
23
|
+
|
|
24
|
+
Recommended setup:
|
|
25
|
+
|
|
26
|
+
- `@mcp-b/webmcp-polyfill` for strict runtime behavior
|
|
27
|
+
- `@mcp-b/webmcp-types` for schema-driven TypeScript inference
|
|
28
|
+
|
|
14
29
|
## Package Selection
|
|
15
30
|
|
|
16
31
|
| Package | Use When |
|
|
@@ -59,6 +74,45 @@ navigator.modelContext.registerTool({
|
|
|
59
74
|
|
|
60
75
|
The IIFE auto-initializes by default.
|
|
61
76
|
|
|
77
|
+
## Type Inference (with `@mcp-b/webmcp-types`)
|
|
78
|
+
|
|
79
|
+
The polyfill provides runtime behavior. For strict compile-time inference, pair it with `@mcp-b/webmcp-types`.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import type { JsonSchemaForInference } from '@mcp-b/webmcp-types';
|
|
83
|
+
import { initializeWebMCPPolyfill } from '@mcp-b/webmcp-polyfill';
|
|
84
|
+
|
|
85
|
+
initializeWebMCPPolyfill();
|
|
86
|
+
|
|
87
|
+
const inputSchema = {
|
|
88
|
+
type: 'object',
|
|
89
|
+
properties: {
|
|
90
|
+
query: { type: 'string' },
|
|
91
|
+
limit: { type: 'integer', minimum: 1, maximum: 50 },
|
|
92
|
+
},
|
|
93
|
+
required: ['query'],
|
|
94
|
+
additionalProperties: false,
|
|
95
|
+
} as const satisfies JsonSchemaForInference;
|
|
96
|
+
|
|
97
|
+
navigator.modelContext.registerTool({
|
|
98
|
+
name: 'search',
|
|
99
|
+
description: 'Search indexed docs',
|
|
100
|
+
inputSchema,
|
|
101
|
+
async execute(args) {
|
|
102
|
+
// Inferred type:
|
|
103
|
+
// { query: string; limit?: number }
|
|
104
|
+
return {
|
|
105
|
+
content: [{ type: 'text', text: `Searching for ${args.query} (${args.limit ?? 10})` }],
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Inference notes:
|
|
112
|
+
|
|
113
|
+
- Best results come from literal schemas (`as const satisfies JsonSchemaForInference`).
|
|
114
|
+
- Widened/runtime schemas fall back to `Record<string, unknown>` for safety.
|
|
115
|
+
|
|
62
116
|
## API
|
|
63
117
|
|
|
64
118
|
### `initializeWebMCPPolyfill(options?)`
|
|
@@ -107,6 +161,29 @@ Restores previous `navigator.modelContext` and `navigator.modelContextTesting` d
|
|
|
107
161
|
|
|
108
162
|
- Removes all registered tools.
|
|
109
163
|
|
|
164
|
+
## Listing and Executing Tools
|
|
165
|
+
|
|
166
|
+
In `@mcp-b/webmcp-polyfill`, listing and execution helpers are exposed on
|
|
167
|
+
`navigator.modelContextTesting` (not `navigator.modelContext`) when the testing shim is enabled.
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import { initializeWebMCPPolyfill } from '@mcp-b/webmcp-polyfill';
|
|
171
|
+
|
|
172
|
+
initializeWebMCPPolyfill({ installTestingShim: true });
|
|
173
|
+
|
|
174
|
+
const tools = navigator.modelContextTesting?.listTools();
|
|
175
|
+
const result = await navigator.modelContextTesting?.executeTool(
|
|
176
|
+
'search',
|
|
177
|
+
JSON.stringify({ query: 'webmcp' })
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
void tools;
|
|
181
|
+
void result;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
If you want `callTool(...)` / extension-style runtime methods on `navigator.modelContext`, use
|
|
185
|
+
`@mcp-b/global`.
|
|
186
|
+
|
|
110
187
|
## Input Schema Support
|
|
111
188
|
|
|
112
189
|
`inputSchema` accepts:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-b/webmcp-polyfill",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Strict WebMCP core runtime polyfill for navigator.modelContext",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webmcp",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@cfworker/json-schema": "^4.1.1",
|
|
45
45
|
"@standard-schema/spec": "^1.1.0",
|
|
46
|
-
"@mcp-b/webmcp-types": "0.2.
|
|
46
|
+
"@mcp-b/webmcp-types": "0.2.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@vitest/browser": "^4.0.18",
|