@mcp-b/webmcp-ts-sdk 2.2.0 → 2.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 CHANGED
@@ -14,13 +14,13 @@
14
14
 
15
15
  ## Why Use @mcp-b/webmcp-ts-sdk?
16
16
 
17
- | Feature | Benefit |
18
- |---------|---------|
17
+ | Feature | Benefit |
18
+ | ----------------------------- | --------------------------------------------------------------------- |
19
19
  | **Dynamic Tool Registration** | Register tools after transport connection - required for browser apps |
20
- | **Minimal Overhead** | Only ~50 lines of custom code on top of official SDK |
21
- | **Full SDK Compatibility** | Re-exports all types, classes, and utilities from official SDK |
22
- | **Type-Safe** | No prototype hacks - clean TypeScript extension |
23
- | **Auto-Updates** | Types and protocol follow official SDK automatically |
20
+ | **Minimal Overhead** | Only ~50 lines of custom code on top of official SDK |
21
+ | **Full SDK Compatibility** | Re-exports all types, classes, and utilities from official SDK |
22
+ | **Type-Safe** | No prototype hacks - clean TypeScript extension |
23
+ | **Auto-Updates** | Types and protocol follow official SDK automatically |
24
24
 
25
25
  ## Overview
26
26
 
@@ -49,9 +49,10 @@ This package solves the problem by **pre-registering tool capabilities** before
49
49
 
50
50
  Compatibility note:
51
51
 
52
- - `BrowserMcpServer.registerTool(...)` still returns a deprecated compatibility handle with `unregister()` so existing MCP-B integrations do not break, even though current Chrome Beta 147 and Chromium `main` return `undefined`.
53
- - Current Chromium exposes `unregisterTool(name)` as a string-name API.
54
- - The upstream WebMCP unregistration design is still under discussion, so avoid assuming the current Chromium shape is the final spec outcome.
52
+ - `BrowserMcpServer.registerTool(tool, options?)` accepts the WebMCP April 23, 2026 draft signature, including `options.signal` (`AbortSignal`) for unregistration. When the signal aborts, both the server-side registration and the mirrored native registration are removed.
53
+ - The same call still returns a deprecated `{ unregister }` compatibility handle so existing MCP-B integrations do not break, even though spec/native runtimes return `undefined`. The handle will be removed in the next major version — prefer `options.signal`.
54
+ - `unregisterTool(name)` was removed from the WebMCP draft on April 23, 2026 in favor of the `AbortSignal` flow. It is kept on `BrowserMcpServer` with a one-time deprecation warning to interoperate with current Chrome Beta 147 (which still ships the string-name API). It will be removed in the next major version.
55
+ - `provideContext()` and `clearContext()` were removed from the WebMCP draft on March 5, 2026. They are kept here as deprecated compatibility shims and emit a one-time deprecation warning when invoked.
55
56
 
56
57
  ## Modifications from Official SDK
57
58
 
@@ -66,8 +67,8 @@ export class BrowserMcpServer extends BaseMcpServer {
66
67
  const enhancedOptions = {
67
68
  ...options,
68
69
  capabilities: mergeCapabilities(options?.capabilities || {}, {
69
- tools: { listChanged: true }
70
- })
70
+ tools: { listChanged: true },
71
+ }),
71
72
  };
72
73
  super(serverInfo, enhancedOptions);
73
74
  }
@@ -87,16 +88,19 @@ export class BrowserMcpServer extends BaseMcpServer {
87
88
  This package re-exports almost everything from the official SDK:
88
89
 
89
90
  ### Types
91
+
90
92
  - All MCP protocol types (`Tool`, `Resource`, `Prompt`, etc.)
91
93
  - Request/response schemas
92
94
  - Client and server capabilities
93
95
  - Error codes and constants
94
96
 
95
97
  ### Classes
98
+
96
99
  - `Server` - Base server class (unchanged)
97
100
  - `McpServer` - Aliased to `BrowserMcpServer` with our modifications
98
101
 
99
102
  ### Utilities
103
+
100
104
  - `Transport` interface
101
105
  - `mergeCapabilities` helper
102
106
  - Protocol version constants
@@ -119,7 +123,7 @@ import { TabServerTransport } from '@mcp-b/transports';
119
123
 
120
124
  const server = new McpServer({
121
125
  name: 'my-web-app',
122
- version: '1.0.0'
126
+ version: '1.0.0',
123
127
  });
124
128
 
125
129
  // Connect transport first
@@ -127,42 +131,50 @@ const transport = new TabServerTransport({ allowedOrigins: ['*'] });
127
131
  await server.connect(transport);
128
132
 
129
133
  // Now you can register tools dynamically (this would fail with official SDK)
130
- server.registerTool('my-tool', {
131
- description: 'A dynamically registered tool',
132
- inputSchema: { message: z.string() },
133
- // Output schemas enable structured, type-safe AI responses
134
- outputSchema: { result: z.string() }
135
- }, async ({ message }) => {
136
- return {
137
- content: [{ type: 'text', text: `Echo: ${message}` }],
138
- // structuredContent must match the outputSchema
139
- structuredContent: { result: `Echo: ${message}` }
140
- };
141
- });
134
+ server.registerTool(
135
+ 'my-tool',
136
+ {
137
+ description: 'A dynamically registered tool',
138
+ inputSchema: { message: z.string() },
139
+ // Output schemas enable structured, type-safe AI responses
140
+ outputSchema: { result: z.string() },
141
+ },
142
+ async ({ message }) => {
143
+ return {
144
+ content: [{ type: 'text', text: `Echo: ${message}` }],
145
+ // structuredContent must match the outputSchema
146
+ structuredContent: { result: `Echo: ${message}` },
147
+ };
148
+ }
149
+ );
142
150
 
143
151
  // Example with complex output schema
144
- server.registerTool('analyze-data', {
145
- description: 'Analyze data and return structured results',
146
- inputSchema: {
147
- data: z.array(z.number()),
148
- operation: z.enum(['sum', 'average', 'stats'])
152
+ server.registerTool(
153
+ 'analyze-data',
154
+ {
155
+ description: 'Analyze data and return structured results',
156
+ inputSchema: {
157
+ data: z.array(z.number()),
158
+ operation: z.enum(['sum', 'average', 'stats']),
159
+ },
160
+ outputSchema: {
161
+ result: z.number(),
162
+ operation: z.string(),
163
+ metadata: z.object({
164
+ count: z.number(),
165
+ min: z.number().optional(),
166
+ max: z.number().optional(),
167
+ }),
168
+ },
149
169
  },
150
- outputSchema: {
151
- result: z.number(),
152
- operation: z.string(),
153
- metadata: z.object({
154
- count: z.number(),
155
- min: z.number().optional(),
156
- max: z.number().optional()
157
- })
170
+ async ({ data, operation }) => {
171
+ const stats = calculateStats(data, operation);
172
+ return {
173
+ content: [{ type: 'text', text: `Result: ${stats.result}` }],
174
+ structuredContent: stats,
175
+ };
158
176
  }
159
- }, async ({ data, operation }) => {
160
- const stats = calculateStats(data, operation);
161
- return {
162
- content: [{ type: 'text', text: `Result: ${stats.result}` }],
163
- structuredContent: stats
164
- };
165
- });
177
+ );
166
178
  ```
167
179
 
168
180
  ## Architecture