@mcp-b/webmcp-ts-sdk 2.0.11 → 2.0.13

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/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.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
8
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@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.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
124
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@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.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/interfaces.js
1381
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@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.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js
1399
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@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.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js
1430
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@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.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/validation/ajv-provider.js
2314
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@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.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/client.js
2389
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@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.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/helpers.js
2557
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@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.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js
2609
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@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.26.0_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
3090
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@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,13 +3115,7 @@ function serializeMessage(message) {
3115
3115
  }
3116
3116
 
3117
3117
  //#endregion
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
- */
3118
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/server.js
3125
3119
  /**
3126
3120
  * Experimental task features for low-level MCP servers.
3127
3121
  *
@@ -3156,6 +3150,136 @@ var ExperimentalServerTasks = class {
3156
3150
  return this._server.requestStream(request, resultSchema, options);
3157
3151
  }
3158
3152
  /**
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
+ /**
3159
3283
  * Gets the current status of a task.
3160
3284
  *
3161
3285
  * @param taskId - The task identifier
@@ -3206,7 +3330,7 @@ var ExperimentalServerTasks = class {
3206
3330
  };
3207
3331
 
3208
3332
  //#endregion
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
3333
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js
3210
3334
  /**
3211
3335
  * An MCP server on top of a pluggable transport.
3212
3336
  *
@@ -3548,7 +3672,7 @@ var Server = class extends Protocol {
3548
3672
  };
3549
3673
 
3550
3674
  //#endregion
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
3675
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js
3552
3676
  const COMPLETABLE_SYMBOL = Symbol.for("mcp.completable");
3553
3677
  /**
3554
3678
  * Checks if a schema is completable (has completion metadata).
@@ -3568,7 +3692,7 @@ var McpZodTypeKind;
3568
3692
  })(McpZodTypeKind || (McpZodTypeKind = {}));
3569
3693
 
3570
3694
  //#endregion
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
3695
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/toolNameValidation.js
3572
3696
  /**
3573
3697
  * Tool name validation utilities according to SEP: Specify Format for Tool Names
3574
3698
  *
@@ -3640,7 +3764,7 @@ function validateAndWarnToolName(name) {
3640
3764
  }
3641
3765
 
3642
3766
  //#endregion
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
3767
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/mcp-server.js
3644
3768
  /**
3645
3769
  * Experimental McpServer task features for MCP SDK.
3646
3770
  * WARNING: These APIs are experimental and may change without notice.
@@ -3672,7 +3796,7 @@ var ExperimentalMcpServerTasks = class {
3672
3796
  };
3673
3797
 
3674
3798
  //#endregion
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
3799
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_@cfworker+json-schema@4.1.1_zod@4.3.5/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
3676
3800
  /**
3677
3801
  * High-level MCP server that provides a simpler API for working with resources, tools, and prompts.
3678
3802
  * For advanced usage (like sending notifications or setting custom request handlers), use the underlying