@mcp-b/webmcp-ts-sdk 2.0.13 → 2.2.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 +7 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -151
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -41,12 +41,18 @@ public registerCapabilities(capabilities: ServerCapabilities): void {
|
|
|
41
41
|
|
|
42
42
|
For the Web Model Context API, this restriction is incompatible because:
|
|
43
43
|
|
|
44
|
-
1. **Tools arrive dynamically** - Web pages call `window.navigator.modelContext.
|
|
44
|
+
1. **Tools arrive dynamically** - Web pages call `window.navigator.modelContext.registerTool(...)` at any time
|
|
45
45
|
2. **Transport must be ready immediately** - The MCP server/transport needs to be connected when the page loads
|
|
46
46
|
3. **Asynchronous registration** - Tools are registered as the page's JavaScript executes, potentially long after initialization
|
|
47
47
|
|
|
48
48
|
This package solves the problem by **pre-registering tool capabilities** before the transport connects, allowing dynamic tool registration to work seamlessly.
|
|
49
49
|
|
|
50
|
+
Compatibility note:
|
|
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.
|
|
55
|
+
|
|
50
56
|
## Modifications from Official SDK
|
|
51
57
|
|
|
52
58
|
### BrowserMcpServer Class
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { RequestOptions, RequestOptions as RequestOptions$1, mergeCapabilities }
|
|
|
3
3
|
import { ReadBuffer, serializeMessage } from "@modelcontextprotocol/sdk/shared/stdio.js";
|
|
4
4
|
import { Transport, Transport as Transport$1, TransportSendOptions } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
5
5
|
import { CallToolRequest, CallToolRequestSchema, CallToolResult, CallToolResultSchema, ClientCapabilities, ClientNotification, ClientRequest, ClientResult, CreateMessageRequest, CreateMessageRequest as CreateMessageRequest$1, CreateMessageRequestSchema, CreateMessageResult, CreateMessageResult as CreateMessageResult$1, CreateMessageResultSchema, ElicitRequest, ElicitRequest as ElicitRequest$1, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, ElicitResultSchema, ErrorCode, GetPromptRequest, GetPromptRequestSchema, GetPromptResult, GetPromptResultSchema, Implementation, Implementation as Implementation$1, InitializeRequest, InitializeRequestSchema, InitializeResult, InitializeResultSchema, JSONRPCMessage, JSONRPCMessageSchema, LATEST_PROTOCOL_VERSION, ListPromptsRequest, ListPromptsRequestSchema, ListPromptsResult, ListPromptsResultSchema, ListResourcesRequest, ListResourcesRequestSchema, ListResourcesResult, ListResourcesResultSchema, ListToolsRequest, ListToolsRequestSchema, ListToolsResult, ListToolsResultSchema, LoggingLevel, LoggingLevelSchema, LoggingMessageNotification, McpError, Notification, Prompt, PromptMessage, PromptMessage as PromptMessage$1, ReadResourceRequest, ReadResourceRequestSchema, ReadResourceResult, ReadResourceResultSchema, Request, Resource, ResourceContents, ResourceListChangedNotificationSchema, ResourceTemplate, Result, SUPPORTED_PROTOCOL_VERSIONS, ServerCapabilities, ServerNotification, ServerRequest, ServerResult, Tool, ToolAnnotations, ToolListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
-
import { InputSchema, ModelContextCore, ModelContextOptions, ResourceContents as ResourceContents$1, ToolDescriptor, ToolListItem, ToolResponse } from "@mcp-b/webmcp-types";
|
|
6
|
+
import { InputSchema, ModelContextCore, ModelContextOptions, ModelContextToolReference, ResourceContents as ResourceContents$1, ToolDescriptor, ToolListItem, ToolResponse } from "@mcp-b/webmcp-types";
|
|
7
7
|
import { ServerOptions } from "@modelcontextprotocol/sdk/server/index.js";
|
|
8
8
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
9
9
|
|
|
@@ -12,6 +12,9 @@ declare const SERVER_MARKER_PROPERTY: "__isBrowserMcpServer";
|
|
|
12
12
|
interface BrowserMcpServerOptions extends ServerOptions {
|
|
13
13
|
native?: ModelContextCore;
|
|
14
14
|
}
|
|
15
|
+
type RegisteredToolHandle = {
|
|
16
|
+
unregister: () => void;
|
|
17
|
+
};
|
|
15
18
|
/**
|
|
16
19
|
* Browser-optimized MCP Server that speaks WebMCP natively.
|
|
17
20
|
*
|
|
@@ -29,6 +32,8 @@ declare class BrowserMcpServer extends McpServer {
|
|
|
29
32
|
private _promptSchemas;
|
|
30
33
|
private _jsonValidator;
|
|
31
34
|
private _publicMethodsBound;
|
|
35
|
+
private _provideContextDeprecationWarned;
|
|
36
|
+
private _clearContextDeprecationWarned;
|
|
32
37
|
constructor(serverInfo: Implementation$1, options?: BrowserMcpServerOptions);
|
|
33
38
|
/**
|
|
34
39
|
* navigator.modelContext consumers may destructure methods (e.g. const { registerTool } = ...).
|
|
@@ -50,15 +55,14 @@ declare class BrowserMcpServer extends McpServer {
|
|
|
50
55
|
private getNativeToolsApi;
|
|
51
56
|
private registerToolInServer;
|
|
52
57
|
backfillTools(tools: readonly ToolListItem[], execute: (name: string, args: Record<string, unknown>) => Promise<ToolResponse>): number;
|
|
53
|
-
registerTool(tool: ToolDescriptor):
|
|
54
|
-
unregister: () => void;
|
|
55
|
-
};
|
|
58
|
+
registerTool(tool: ToolDescriptor): RegisteredToolHandle;
|
|
56
59
|
/**
|
|
57
60
|
* Backfill tools that were already registered on the native/polyfill context
|
|
58
61
|
* before this BrowserMcpServer wrapper was installed.
|
|
59
62
|
*/
|
|
60
63
|
syncNativeTools(): number;
|
|
61
|
-
unregisterTool(
|
|
64
|
+
unregisterTool(nameOrTool: string | ModelContextToolReference): void;
|
|
65
|
+
private clearRegisteredTools;
|
|
62
66
|
registerResource(descriptor: {
|
|
63
67
|
uri: string;
|
|
64
68
|
name: string;
|
|
@@ -82,6 +86,9 @@ declare class BrowserMcpServer extends McpServer {
|
|
|
82
86
|
};
|
|
83
87
|
provideContext(options?: ModelContextOptions): void;
|
|
84
88
|
clearContext(): void;
|
|
89
|
+
private resolveToolNameForUnregister;
|
|
90
|
+
private warnProvideContextDeprecationOnce;
|
|
91
|
+
private warnClearContextDeprecationOnce;
|
|
85
92
|
listResources(): Array<{
|
|
86
93
|
uri: string;
|
|
87
94
|
name: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/browser-server.ts","../src/no-op-validator.ts","../src/polyfill-validator.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/browser-server.ts","../src/no-op-validator.ts","../src/polyfill-validator.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cA0Ca;UAyGI,uBAAA,SAAgC;WACtC;;AA1GX,KAiIK,oBAAA,GAjIQ;EAyGI,UAAA,EAAA,GAAA,GAAA,IAAA;AAEhB,CAAA;AAmCD;;;;;;;;;;;AAkQgB,cAlQH,gBAAA,SAAyB,SAAA,CAkQtB;EAAc,UAjQlB,sBAAA,CAiQkB,EAAA,IAAA;EAA+C,QAAA,MAAA;EAApB,QAAA,cAAA;EAuBxC,QAAA,cAAA;EACD,QAAA,mBAAA;EAAgD,QAAA,gCAAA;EAApB,QAAA,8BAAA;EA2BjB,WAAA,CAAA,UAAA,EA3SD,gBA2SC,EAAA,OAAA,CAAA,EA3SyB,uBA2SzB;EAuDR;;;;EAwBF,QAAA,oBAAA;EA6BP,YAAA,YAAA,CAAA;EACe,YAAA,gBAAA,CAAA;EAApB,YAAA,cAAA,CAAA;EAkBU;;;;;;;EA0FT,QAAA,iBAAA;EASkC,QAAA,WAAA;EAAuC,QAAA,iBAAA;EAAR,QAAA,oBAAA;EAYnC,aAAA,CA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8C,0BAA0B;;KAG7E;;QACoB;;;;;EFkCZ,YAAA,EAAA,MAAA;AAyGb,CAAA;AAwBK,cEhKQ,2BAAA,YAAuC,mBFgK3B,CAAA;EAaZ,YAAA,CAAA,CAAA,CAAA,CAAA,MAAiB,EAAA,OAAA,CAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GE5K0B,yBF4K1B,CE5KoD,CF4KpD,CAAA;;;;AArCb,KG/CL,qBAAA,GAAwB,sBHgDzB,CAAA,QADsC,CAAA;AAwB5C,KGtEO,cAAA,GAAiB,qBHsEJ"}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { zodToJsonSchema } from "zod-to-json-schema";
|
|
|
5
5
|
import { ZodOptional } from "zod";
|
|
6
6
|
import { isPlainObject, validateArgsWithSchema } from "@mcp-b/webmcp-polyfill";
|
|
7
7
|
|
|
8
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
8
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
|
|
9
9
|
function isZ4Schema(s) {
|
|
10
10
|
return !!s._zod;
|
|
11
11
|
}
|
|
@@ -121,7 +121,7 @@ function getLiteralValue(schema) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
//#endregion
|
|
124
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
124
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
125
125
|
const LATEST_PROTOCOL_VERSION = "2025-11-25";
|
|
126
126
|
const SUPPORTED_PROTOCOL_VERSIONS = [
|
|
127
127
|
LATEST_PROTOCOL_VERSION,
|
|
@@ -1378,7 +1378,7 @@ var UrlElicitationRequiredError = class extends McpError {
|
|
|
1378
1378
|
};
|
|
1379
1379
|
|
|
1380
1380
|
//#endregion
|
|
1381
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
1381
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/interfaces.js
|
|
1382
1382
|
/**
|
|
1383
1383
|
* Experimental task interfaces for MCP SDK.
|
|
1384
1384
|
* WARNING: These APIs are experimental and may change without notice.
|
|
@@ -1396,7 +1396,7 @@ function isTerminal(status) {
|
|
|
1396
1396
|
}
|
|
1397
1397
|
|
|
1398
1398
|
//#endregion
|
|
1399
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
1399
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js
|
|
1400
1400
|
function mapMiniTarget(t) {
|
|
1401
1401
|
if (!t) return "draft-7";
|
|
1402
1402
|
if (t === "jsonSchema7" || t === "draft-7") return "draft-7";
|
|
@@ -1427,7 +1427,7 @@ function parseWithCompat(schema, data) {
|
|
|
1427
1427
|
}
|
|
1428
1428
|
|
|
1429
1429
|
//#endregion
|
|
1430
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
1430
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js
|
|
1431
1431
|
/**
|
|
1432
1432
|
* The default request timeout, in miliseconds.
|
|
1433
1433
|
*/
|
|
@@ -2311,7 +2311,7 @@ var ajv_default = Ajv;
|
|
|
2311
2311
|
function addFormats(_ajv) {}
|
|
2312
2312
|
|
|
2313
2313
|
//#endregion
|
|
2314
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
2314
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/validation/ajv-provider.js
|
|
2315
2315
|
function createDefaultAjvInstance() {
|
|
2316
2316
|
const ajv = new ajv_default({
|
|
2317
2317
|
strict: false,
|
|
@@ -2386,7 +2386,7 @@ var AjvJsonSchemaValidator = class {
|
|
|
2386
2386
|
};
|
|
2387
2387
|
|
|
2388
2388
|
//#endregion
|
|
2389
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
2389
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/client.js
|
|
2390
2390
|
/**
|
|
2391
2391
|
* Experimental task features for MCP clients.
|
|
2392
2392
|
*
|
|
@@ -2554,7 +2554,7 @@ var ExperimentalClientTasks = class {
|
|
|
2554
2554
|
};
|
|
2555
2555
|
|
|
2556
2556
|
//#endregion
|
|
2557
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
2557
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/helpers.js
|
|
2558
2558
|
/**
|
|
2559
2559
|
* Experimental task capability assertion helpers.
|
|
2560
2560
|
* WARNING: These APIs are experimental and may change without notice.
|
|
@@ -2606,7 +2606,7 @@ function assertClientRequestTaskCapability(requests, method, entityName) {
|
|
|
2606
2606
|
}
|
|
2607
2607
|
|
|
2608
2608
|
//#endregion
|
|
2609
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
2609
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js
|
|
2610
2610
|
/**
|
|
2611
2611
|
* Elicitation default application helper. Applies defaults to the data based on the schema.
|
|
2612
2612
|
*
|
|
@@ -3087,7 +3087,7 @@ var Client = class extends Protocol {
|
|
|
3087
3087
|
};
|
|
3088
3088
|
|
|
3089
3089
|
//#endregion
|
|
3090
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
3090
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
|
|
3091
3091
|
/**
|
|
3092
3092
|
* Buffers a continuous stdio stream into discrete JSON-RPC messages.
|
|
3093
3093
|
*/
|
|
@@ -3115,7 +3115,13 @@ function serializeMessage(message) {
|
|
|
3115
3115
|
}
|
|
3116
3116
|
|
|
3117
3117
|
//#endregion
|
|
3118
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
3118
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/server.js
|
|
3119
|
+
/**
|
|
3120
|
+
* Experimental server task features for MCP SDK.
|
|
3121
|
+
* WARNING: These APIs are experimental and may change without notice.
|
|
3122
|
+
*
|
|
3123
|
+
* @experimental
|
|
3124
|
+
*/
|
|
3119
3125
|
/**
|
|
3120
3126
|
* Experimental task features for low-level MCP servers.
|
|
3121
3127
|
*
|
|
@@ -3150,136 +3156,6 @@ var ExperimentalServerTasks = class {
|
|
|
3150
3156
|
return this._server.requestStream(request, resultSchema, options);
|
|
3151
3157
|
}
|
|
3152
3158
|
/**
|
|
3153
|
-
* Sends a sampling request and returns an AsyncGenerator that yields response messages.
|
|
3154
|
-
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
3155
|
-
*
|
|
3156
|
-
* For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
|
|
3157
|
-
* before the final result.
|
|
3158
|
-
*
|
|
3159
|
-
* @example
|
|
3160
|
-
* ```typescript
|
|
3161
|
-
* const stream = server.experimental.tasks.createMessageStream({
|
|
3162
|
-
* messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
|
|
3163
|
-
* maxTokens: 100
|
|
3164
|
-
* }, {
|
|
3165
|
-
* onprogress: (progress) => {
|
|
3166
|
-
* // Handle streaming tokens via progress notifications
|
|
3167
|
-
* console.log('Progress:', progress.message);
|
|
3168
|
-
* }
|
|
3169
|
-
* });
|
|
3170
|
-
*
|
|
3171
|
-
* for await (const message of stream) {
|
|
3172
|
-
* switch (message.type) {
|
|
3173
|
-
* case 'taskCreated':
|
|
3174
|
-
* console.log('Task created:', message.task.taskId);
|
|
3175
|
-
* break;
|
|
3176
|
-
* case 'taskStatus':
|
|
3177
|
-
* console.log('Task status:', message.task.status);
|
|
3178
|
-
* break;
|
|
3179
|
-
* case 'result':
|
|
3180
|
-
* console.log('Final result:', message.result);
|
|
3181
|
-
* break;
|
|
3182
|
-
* case 'error':
|
|
3183
|
-
* console.error('Error:', message.error);
|
|
3184
|
-
* break;
|
|
3185
|
-
* }
|
|
3186
|
-
* }
|
|
3187
|
-
* ```
|
|
3188
|
-
*
|
|
3189
|
-
* @param params - The sampling request parameters
|
|
3190
|
-
* @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
|
|
3191
|
-
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
3192
|
-
*
|
|
3193
|
-
* @experimental
|
|
3194
|
-
*/
|
|
3195
|
-
createMessageStream(params, options) {
|
|
3196
|
-
const clientCapabilities = this._server.getClientCapabilities();
|
|
3197
|
-
if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) throw new Error("Client does not support sampling tools capability.");
|
|
3198
|
-
if (params.messages.length > 0) {
|
|
3199
|
-
const lastMessage = params.messages[params.messages.length - 1];
|
|
3200
|
-
const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
|
|
3201
|
-
const hasToolResults = lastContent.some((c) => c.type === "tool_result");
|
|
3202
|
-
const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
|
|
3203
|
-
const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
|
|
3204
|
-
const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
|
|
3205
|
-
if (hasToolResults) {
|
|
3206
|
-
if (lastContent.some((c) => c.type !== "tool_result")) throw new Error("The last message must contain only tool_result content if any is present");
|
|
3207
|
-
if (!hasPreviousToolUse) throw new Error("tool_result blocks are not matching any tool_use from the previous message");
|
|
3208
|
-
}
|
|
3209
|
-
if (hasPreviousToolUse) {
|
|
3210
|
-
const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
|
|
3211
|
-
const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
|
|
3212
|
-
if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
return this.requestStream({
|
|
3216
|
-
method: "sampling/createMessage",
|
|
3217
|
-
params
|
|
3218
|
-
}, CreateMessageResultSchema, options);
|
|
3219
|
-
}
|
|
3220
|
-
/**
|
|
3221
|
-
* Sends an elicitation request and returns an AsyncGenerator that yields response messages.
|
|
3222
|
-
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
3223
|
-
*
|
|
3224
|
-
* For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
|
|
3225
|
-
* and 'taskStatus' messages before the final result.
|
|
3226
|
-
*
|
|
3227
|
-
* @example
|
|
3228
|
-
* ```typescript
|
|
3229
|
-
* const stream = server.experimental.tasks.elicitInputStream({
|
|
3230
|
-
* mode: 'url',
|
|
3231
|
-
* message: 'Please authenticate',
|
|
3232
|
-
* elicitationId: 'auth-123',
|
|
3233
|
-
* url: 'https://example.com/auth'
|
|
3234
|
-
* }, {
|
|
3235
|
-
* task: { ttl: 300000 } // Task-augmented for long-running auth flow
|
|
3236
|
-
* });
|
|
3237
|
-
*
|
|
3238
|
-
* for await (const message of stream) {
|
|
3239
|
-
* switch (message.type) {
|
|
3240
|
-
* case 'taskCreated':
|
|
3241
|
-
* console.log('Task created:', message.task.taskId);
|
|
3242
|
-
* break;
|
|
3243
|
-
* case 'taskStatus':
|
|
3244
|
-
* console.log('Task status:', message.task.status);
|
|
3245
|
-
* break;
|
|
3246
|
-
* case 'result':
|
|
3247
|
-
* console.log('User action:', message.result.action);
|
|
3248
|
-
* break;
|
|
3249
|
-
* case 'error':
|
|
3250
|
-
* console.error('Error:', message.error);
|
|
3251
|
-
* break;
|
|
3252
|
-
* }
|
|
3253
|
-
* }
|
|
3254
|
-
* ```
|
|
3255
|
-
*
|
|
3256
|
-
* @param params - The elicitation request parameters
|
|
3257
|
-
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
3258
|
-
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
3259
|
-
*
|
|
3260
|
-
* @experimental
|
|
3261
|
-
*/
|
|
3262
|
-
elicitInputStream(params, options) {
|
|
3263
|
-
const clientCapabilities = this._server.getClientCapabilities();
|
|
3264
|
-
const mode = params.mode ?? "form";
|
|
3265
|
-
switch (mode) {
|
|
3266
|
-
case "url":
|
|
3267
|
-
if (!clientCapabilities?.elicitation?.url) throw new Error("Client does not support url elicitation.");
|
|
3268
|
-
break;
|
|
3269
|
-
case "form":
|
|
3270
|
-
if (!clientCapabilities?.elicitation?.form) throw new Error("Client does not support form elicitation.");
|
|
3271
|
-
break;
|
|
3272
|
-
}
|
|
3273
|
-
const normalizedParams = mode === "form" && params.mode === void 0 ? {
|
|
3274
|
-
...params,
|
|
3275
|
-
mode: "form"
|
|
3276
|
-
} : params;
|
|
3277
|
-
return this.requestStream({
|
|
3278
|
-
method: "elicitation/create",
|
|
3279
|
-
params: normalizedParams
|
|
3280
|
-
}, ElicitResultSchema, options);
|
|
3281
|
-
}
|
|
3282
|
-
/**
|
|
3283
3159
|
* Gets the current status of a task.
|
|
3284
3160
|
*
|
|
3285
3161
|
* @param taskId - The task identifier
|
|
@@ -3330,7 +3206,7 @@ var ExperimentalServerTasks = class {
|
|
|
3330
3206
|
};
|
|
3331
3207
|
|
|
3332
3208
|
//#endregion
|
|
3333
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
3209
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js
|
|
3334
3210
|
/**
|
|
3335
3211
|
* An MCP server on top of a pluggable transport.
|
|
3336
3212
|
*
|
|
@@ -3672,7 +3548,7 @@ var Server = class extends Protocol {
|
|
|
3672
3548
|
};
|
|
3673
3549
|
|
|
3674
3550
|
//#endregion
|
|
3675
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
3551
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js
|
|
3676
3552
|
const COMPLETABLE_SYMBOL = Symbol.for("mcp.completable");
|
|
3677
3553
|
/**
|
|
3678
3554
|
* Checks if a schema is completable (has completion metadata).
|
|
@@ -3692,7 +3568,7 @@ var McpZodTypeKind;
|
|
|
3692
3568
|
})(McpZodTypeKind || (McpZodTypeKind = {}));
|
|
3693
3569
|
|
|
3694
3570
|
//#endregion
|
|
3695
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
3571
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/toolNameValidation.js
|
|
3696
3572
|
/**
|
|
3697
3573
|
* Tool name validation utilities according to SEP: Specify Format for Tool Names
|
|
3698
3574
|
*
|
|
@@ -3764,7 +3640,7 @@ function validateAndWarnToolName(name) {
|
|
|
3764
3640
|
}
|
|
3765
3641
|
|
|
3766
3642
|
//#endregion
|
|
3767
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
3643
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/mcp-server.js
|
|
3768
3644
|
/**
|
|
3769
3645
|
* Experimental McpServer task features for MCP SDK.
|
|
3770
3646
|
* WARNING: These APIs are experimental and may change without notice.
|
|
@@ -3796,7 +3672,7 @@ var ExperimentalMcpServerTasks = class {
|
|
|
3796
3672
|
};
|
|
3797
3673
|
|
|
3798
3674
|
//#endregion
|
|
3799
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
3675
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
|
|
3800
3676
|
/**
|
|
3801
3677
|
* High-level MCP server that provides a simpler API for working with resources, tools, and prompts.
|
|
3802
3678
|
* For advanced usage (like sending notifications or setting custom request handlers), use the underlying
|
|
@@ -4514,6 +4390,8 @@ var BrowserMcpServer = class extends McpServer {
|
|
|
4514
4390
|
_promptSchemas = /* @__PURE__ */ new Map();
|
|
4515
4391
|
_jsonValidator;
|
|
4516
4392
|
_publicMethodsBound = false;
|
|
4393
|
+
_provideContextDeprecationWarned = false;
|
|
4394
|
+
_clearContextDeprecationWarned = false;
|
|
4517
4395
|
constructor(serverInfo, options) {
|
|
4518
4396
|
const validator = new PolyfillJsonSchemaValidator();
|
|
4519
4397
|
const enhancedOptions = {
|
|
@@ -4657,10 +4535,14 @@ var BrowserMcpServer = class extends McpServer {
|
|
|
4657
4535
|
arguments: args
|
|
4658
4536
|
}));
|
|
4659
4537
|
}
|
|
4660
|
-
unregisterTool(
|
|
4538
|
+
unregisterTool(nameOrTool) {
|
|
4539
|
+
const name = this.resolveToolNameForUnregister(nameOrTool);
|
|
4661
4540
|
this._parentTools[name]?.remove();
|
|
4662
4541
|
if (this.native) this.native.unregisterTool(name);
|
|
4663
4542
|
}
|
|
4543
|
+
clearRegisteredTools() {
|
|
4544
|
+
for (const name of Object.keys(this._parentTools)) this.unregisterTool(name);
|
|
4545
|
+
}
|
|
4664
4546
|
registerResource(descriptor) {
|
|
4665
4547
|
const registered = super.registerResource(descriptor.name, descriptor.uri, {
|
|
4666
4548
|
...descriptor.description !== void 0 && { description: descriptor.description },
|
|
@@ -4677,13 +4559,28 @@ var BrowserMcpServer = class extends McpServer {
|
|
|
4677
4559
|
} };
|
|
4678
4560
|
}
|
|
4679
4561
|
provideContext(options) {
|
|
4680
|
-
|
|
4681
|
-
|
|
4562
|
+
this.warnProvideContextDeprecationOnce();
|
|
4563
|
+
this.clearRegisteredTools();
|
|
4682
4564
|
for (const tool of options?.tools ?? []) this.registerTool(tool);
|
|
4683
4565
|
}
|
|
4684
4566
|
clearContext() {
|
|
4685
|
-
|
|
4686
|
-
|
|
4567
|
+
this.warnClearContextDeprecationOnce();
|
|
4568
|
+
this.clearRegisteredTools();
|
|
4569
|
+
}
|
|
4570
|
+
resolveToolNameForUnregister(nameOrTool) {
|
|
4571
|
+
if (typeof nameOrTool === "string") return nameOrTool;
|
|
4572
|
+
if (isPlainObject$1(nameOrTool) && typeof nameOrTool.name === "string") return nameOrTool.name;
|
|
4573
|
+
throw new TypeError("Failed to execute 'unregisterTool' on 'ModelContext': parameter 1 must be a string or an object with a string name.");
|
|
4574
|
+
}
|
|
4575
|
+
warnProvideContextDeprecationOnce() {
|
|
4576
|
+
if (this._provideContextDeprecationWarned) return;
|
|
4577
|
+
this._provideContextDeprecationWarned = true;
|
|
4578
|
+
console.warn("[BrowserMcpServer] navigator.modelContext.provideContext() is deprecated and will be removed in the next major version. Register tools individually with registerTool() instead.");
|
|
4579
|
+
}
|
|
4580
|
+
warnClearContextDeprecationOnce() {
|
|
4581
|
+
if (this._clearContextDeprecationWarned) return;
|
|
4582
|
+
this._clearContextDeprecationWarned = true;
|
|
4583
|
+
console.warn("[BrowserMcpServer] navigator.modelContext.clearContext() is deprecated and will be removed in the next major version. Unregister individual tools instead.");
|
|
4687
4584
|
}
|
|
4688
4585
|
listResources() {
|
|
4689
4586
|
return Object.entries(this._parentResources).filter(([, resource]) => resource.enabled).map(([uri, resource]) => ({
|