@opentiny/next-sdk 0.2.0 → 0.2.2
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/WebMcpClient.ts +17 -19
- package/WebMcpServer.ts +11 -8
- package/agent/AgentModelProvider.ts +2 -2
- package/agent/type.ts +1 -1
- package/dist/WebMcpClient.d.ts +176 -35
- package/dist/WebMcpServer.d.ts +43 -154
- package/dist/agent/AgentModelProvider.d.ts +0 -2
- package/dist/agent/type.d.ts +1 -0
- package/dist/index.es.dev.js +2433 -5635
- package/dist/index.es.js +13476 -16094
- package/dist/index.js +1 -1
- package/dist/index.umd.dev.js +2395 -5597
- package/dist/index.umd.js +52 -52
- package/dist/{mcpsdk@1.23.1.dev.js → mcpsdk@1.25.2.dev.js} +2047 -482
- package/dist/{mcpsdk@1.23.1.es.dev.js → mcpsdk@1.25.2.es.dev.js} +2047 -482
- package/dist/mcpsdk@1.25.2.es.js +16796 -0
- package/dist/mcpsdk@1.25.2.js +43 -0
- package/dist/webagent.dev.js +10248 -13732
- package/dist/webagent.es.dev.js +10231 -13715
- package/dist/webagent.es.js +13559 -16396
- package/dist/webagent.js +45 -45
- package/dist/webmcp-full.dev.js +2443 -5645
- package/dist/webmcp-full.es.dev.js +2422 -5624
- package/dist/webmcp-full.es.js +8284 -10901
- package/dist/webmcp-full.js +28 -28
- package/package.json +3 -3
- package/dist/mcpsdk@1.23.1.es.js +0 -15530
- package/dist/mcpsdk@1.23.1.js +0 -43
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function getDefaultExportFromCjs(x) {
|
|
2
2
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
3
3
|
}
|
|
4
|
-
var ajv
|
|
4
|
+
var ajv = { exports: {} };
|
|
5
5
|
var core$1 = {};
|
|
6
6
|
var validate = {};
|
|
7
7
|
var boolSchema = {};
|
|
@@ -3917,7 +3917,7 @@ function requireCore$1() {
|
|
|
3917
3917
|
uriResolver
|
|
3918
3918
|
};
|
|
3919
3919
|
}
|
|
3920
|
-
class
|
|
3920
|
+
class Ajv2 {
|
|
3921
3921
|
constructor(opts = {}) {
|
|
3922
3922
|
this.schemas = {};
|
|
3923
3923
|
this.refs = {};
|
|
@@ -4287,9 +4287,9 @@ function requireCore$1() {
|
|
|
4287
4287
|
}
|
|
4288
4288
|
}
|
|
4289
4289
|
}
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
exports.default =
|
|
4290
|
+
Ajv2.ValidationError = validation_error_1.default;
|
|
4291
|
+
Ajv2.MissingRefError = ref_error_1.default;
|
|
4292
|
+
exports.default = Ajv2;
|
|
4293
4293
|
function checkOptions(checkOpts, options, msg, log = "error") {
|
|
4294
4294
|
for (const key in checkOpts) {
|
|
4295
4295
|
const opt = key;
|
|
@@ -6241,7 +6241,7 @@ const require$$3 = {
|
|
|
6241
6241
|
};
|
|
6242
6242
|
var hasRequiredAjv;
|
|
6243
6243
|
function requireAjv() {
|
|
6244
|
-
if (hasRequiredAjv) return ajv
|
|
6244
|
+
if (hasRequiredAjv) return ajv.exports;
|
|
6245
6245
|
hasRequiredAjv = 1;
|
|
6246
6246
|
(function(module, exports) {
|
|
6247
6247
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6252,7 +6252,7 @@ function requireAjv() {
|
|
|
6252
6252
|
const draft7MetaSchema = require$$3;
|
|
6253
6253
|
const META_SUPPORT_DATA = ["/properties"];
|
|
6254
6254
|
const META_SCHEMA_ID = "http://json-schema.org/draft-07/schema";
|
|
6255
|
-
class
|
|
6255
|
+
class Ajv2 extends core_1.default {
|
|
6256
6256
|
_addVocabularies() {
|
|
6257
6257
|
super._addVocabularies();
|
|
6258
6258
|
draft7_1.default.forEach((v) => this.addVocabulary(v));
|
|
@@ -6271,11 +6271,11 @@ function requireAjv() {
|
|
|
6271
6271
|
return this.opts.defaultMeta = super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : void 0);
|
|
6272
6272
|
}
|
|
6273
6273
|
}
|
|
6274
|
-
exports.Ajv =
|
|
6275
|
-
module.exports = exports =
|
|
6276
|
-
module.exports.Ajv =
|
|
6274
|
+
exports.Ajv = Ajv2;
|
|
6275
|
+
module.exports = exports = Ajv2;
|
|
6276
|
+
module.exports.Ajv = Ajv2;
|
|
6277
6277
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6278
|
-
exports.default =
|
|
6278
|
+
exports.default = Ajv2;
|
|
6279
6279
|
var validate_1 = requireValidate();
|
|
6280
6280
|
Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
|
|
6281
6281
|
return validate_1.KeywordCxt;
|
|
@@ -6307,11 +6307,11 @@ function requireAjv() {
|
|
|
6307
6307
|
Object.defineProperty(exports, "MissingRefError", { enumerable: true, get: function() {
|
|
6308
6308
|
return ref_error_1.default;
|
|
6309
6309
|
} });
|
|
6310
|
-
})(ajv
|
|
6311
|
-
return ajv
|
|
6310
|
+
})(ajv, ajv.exports);
|
|
6311
|
+
return ajv.exports;
|
|
6312
6312
|
}
|
|
6313
6313
|
var ajvExports = requireAjv();
|
|
6314
|
-
const
|
|
6314
|
+
const Ajv = /* @__PURE__ */ getDefaultExportFromCjs(ajvExports);
|
|
6315
6315
|
const NEVER = Object.freeze({
|
|
6316
6316
|
status: "aborted"
|
|
6317
6317
|
});
|
|
@@ -6847,8 +6847,9 @@ const string$1 = (params) => {
|
|
|
6847
6847
|
return new RegExp(`^${regex}$`);
|
|
6848
6848
|
};
|
|
6849
6849
|
const integer = /^\d+$/;
|
|
6850
|
-
const number$
|
|
6850
|
+
const number$2 = /^-?\d+(?:\.\d+)?/i;
|
|
6851
6851
|
const boolean$1 = /true|false/i;
|
|
6852
|
+
const _null$2 = /null/i;
|
|
6852
6853
|
const lowercase = /^[^A-Z]*$/;
|
|
6853
6854
|
const uppercase = /^[^a-z]*$/;
|
|
6854
6855
|
const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
|
|
@@ -7658,7 +7659,7 @@ const $ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
|
|
|
7658
7659
|
});
|
|
7659
7660
|
const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
|
|
7660
7661
|
$ZodType.init(inst, def);
|
|
7661
|
-
inst._zod.pattern = inst._zod.bag.pattern ?? number$
|
|
7662
|
+
inst._zod.pattern = inst._zod.bag.pattern ?? number$2;
|
|
7662
7663
|
inst._zod.parse = (payload, _ctx) => {
|
|
7663
7664
|
if (def.coerce)
|
|
7664
7665
|
try {
|
|
@@ -7705,6 +7706,23 @@ const $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
|
|
|
7705
7706
|
return payload;
|
|
7706
7707
|
};
|
|
7707
7708
|
});
|
|
7709
|
+
const $ZodNull = /* @__PURE__ */ $constructor("$ZodNull", (inst, def) => {
|
|
7710
|
+
$ZodType.init(inst, def);
|
|
7711
|
+
inst._zod.pattern = _null$2;
|
|
7712
|
+
inst._zod.values = /* @__PURE__ */ new Set([null]);
|
|
7713
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
7714
|
+
const input = payload.value;
|
|
7715
|
+
if (input === null)
|
|
7716
|
+
return payload;
|
|
7717
|
+
payload.issues.push({
|
|
7718
|
+
expected: "null",
|
|
7719
|
+
code: "invalid_type",
|
|
7720
|
+
input,
|
|
7721
|
+
inst
|
|
7722
|
+
});
|
|
7723
|
+
return payload;
|
|
7724
|
+
};
|
|
7725
|
+
});
|
|
7708
7726
|
const $ZodAny = /* @__PURE__ */ $constructor("$ZodAny", (inst, def) => {
|
|
7709
7727
|
$ZodType.init(inst, def);
|
|
7710
7728
|
inst._zod.parse = (payload) => payload;
|
|
@@ -8792,6 +8810,14 @@ function _number(Class, params) {
|
|
|
8792
8810
|
...normalizeParams(params)
|
|
8793
8811
|
});
|
|
8794
8812
|
}
|
|
8813
|
+
function _coercedNumber(Class, params) {
|
|
8814
|
+
return new Class({
|
|
8815
|
+
type: "number",
|
|
8816
|
+
coerce: true,
|
|
8817
|
+
checks: [],
|
|
8818
|
+
...normalizeParams(params)
|
|
8819
|
+
});
|
|
8820
|
+
}
|
|
8795
8821
|
function _int(Class, params) {
|
|
8796
8822
|
return new Class({
|
|
8797
8823
|
type: "number",
|
|
@@ -8807,6 +8833,12 @@ function _boolean(Class, params) {
|
|
|
8807
8833
|
...normalizeParams(params)
|
|
8808
8834
|
});
|
|
8809
8835
|
}
|
|
8836
|
+
function _null$1(Class, params) {
|
|
8837
|
+
return new Class({
|
|
8838
|
+
type: "null",
|
|
8839
|
+
...normalizeParams(params)
|
|
8840
|
+
});
|
|
8841
|
+
}
|
|
8810
8842
|
function _any(Class) {
|
|
8811
8843
|
return new Class({
|
|
8812
8844
|
type: "any"
|
|
@@ -10030,7 +10062,7 @@ const ZodNumber$1 = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
|
|
|
10030
10062
|
inst.isFinite = true;
|
|
10031
10063
|
inst.format = bag.format ?? null;
|
|
10032
10064
|
});
|
|
10033
|
-
function number(params) {
|
|
10065
|
+
function number$1(params) {
|
|
10034
10066
|
return _number(ZodNumber$1, params);
|
|
10035
10067
|
}
|
|
10036
10068
|
const ZodNumberFormat = /* @__PURE__ */ $constructor("ZodNumberFormat", (inst, def) => {
|
|
@@ -10047,6 +10079,13 @@ const ZodBoolean$1 = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
|
|
|
10047
10079
|
function boolean(params) {
|
|
10048
10080
|
return _boolean(ZodBoolean$1, params);
|
|
10049
10081
|
}
|
|
10082
|
+
const ZodNull$1 = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
|
|
10083
|
+
$ZodNull.init(inst, def);
|
|
10084
|
+
ZodType$1.init(inst, def);
|
|
10085
|
+
});
|
|
10086
|
+
function _null(params) {
|
|
10087
|
+
return _null$1(ZodNull$1, params);
|
|
10088
|
+
}
|
|
10050
10089
|
const ZodAny$1 = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
|
|
10051
10090
|
$ZodAny.init(inst, def);
|
|
10052
10091
|
ZodType$1.init(inst, def);
|
|
@@ -10415,48 +10454,85 @@ function preprocess(fn, schema) {
|
|
|
10415
10454
|
const ZodIssueCode$1 = {
|
|
10416
10455
|
custom: "custom"
|
|
10417
10456
|
};
|
|
10418
|
-
|
|
10457
|
+
function number(params) {
|
|
10458
|
+
return _coercedNumber(ZodNumber$1, params);
|
|
10459
|
+
}
|
|
10460
|
+
const LATEST_PROTOCOL_VERSION = "2025-11-25";
|
|
10419
10461
|
const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
|
|
10420
|
-
const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-03-26", "2024-11-05", "2024-10-07"];
|
|
10462
|
+
const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
|
|
10463
|
+
const RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
10421
10464
|
const JSONRPC_VERSION = "2.0";
|
|
10422
10465
|
const AssertObjectSchema = custom((v) => v !== null && (typeof v === "object" || typeof v === "function"));
|
|
10423
|
-
const ProgressTokenSchema = union([string(), number().int()]);
|
|
10466
|
+
const ProgressTokenSchema = union([string(), number$1().int()]);
|
|
10424
10467
|
const CursorSchema = string();
|
|
10468
|
+
const TaskCreationParamsSchema = looseObject({
|
|
10469
|
+
/**
|
|
10470
|
+
* Time in milliseconds to keep task results available after completion.
|
|
10471
|
+
* If null, the task has unlimited lifetime until manually cleaned up.
|
|
10472
|
+
*/
|
|
10473
|
+
ttl: union([number$1(), _null()]).optional(),
|
|
10474
|
+
/**
|
|
10475
|
+
* Time in milliseconds to wait between task status requests.
|
|
10476
|
+
*/
|
|
10477
|
+
pollInterval: number$1().optional()
|
|
10478
|
+
});
|
|
10479
|
+
const TaskMetadataSchema = object$1({
|
|
10480
|
+
ttl: number$1().optional()
|
|
10481
|
+
});
|
|
10482
|
+
const RelatedTaskMetadataSchema = object$1({
|
|
10483
|
+
taskId: string()
|
|
10484
|
+
});
|
|
10425
10485
|
const RequestMetaSchema = looseObject({
|
|
10426
10486
|
/**
|
|
10427
10487
|
* If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
|
|
10428
10488
|
*/
|
|
10429
|
-
progressToken: ProgressTokenSchema.optional()
|
|
10489
|
+
progressToken: ProgressTokenSchema.optional(),
|
|
10490
|
+
/**
|
|
10491
|
+
* If specified, this request is related to the provided task.
|
|
10492
|
+
*/
|
|
10493
|
+
[RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
|
|
10430
10494
|
});
|
|
10431
|
-
const BaseRequestParamsSchema =
|
|
10495
|
+
const BaseRequestParamsSchema = object$1({
|
|
10432
10496
|
/**
|
|
10433
10497
|
* See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
|
|
10434
10498
|
*/
|
|
10435
10499
|
_meta: RequestMetaSchema.optional()
|
|
10436
10500
|
});
|
|
10501
|
+
const TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
10502
|
+
/**
|
|
10503
|
+
* If specified, the caller is requesting task-augmented execution for this request.
|
|
10504
|
+
* The request will return a CreateTaskResult immediately, and the actual result can be
|
|
10505
|
+
* retrieved later via tasks/result.
|
|
10506
|
+
*
|
|
10507
|
+
* Task augmentation is subject to capability negotiation - receivers MUST declare support
|
|
10508
|
+
* for task augmentation of specific request types in their capabilities.
|
|
10509
|
+
*/
|
|
10510
|
+
task: TaskMetadataSchema.optional()
|
|
10511
|
+
});
|
|
10512
|
+
const isTaskAugmentedRequestParams = (value) => TaskAugmentedRequestParamsSchema.safeParse(value).success;
|
|
10437
10513
|
const RequestSchema = object$1({
|
|
10438
10514
|
method: string(),
|
|
10439
|
-
params: BaseRequestParamsSchema.optional()
|
|
10515
|
+
params: BaseRequestParamsSchema.loose().optional()
|
|
10440
10516
|
});
|
|
10441
|
-
const NotificationsParamsSchema =
|
|
10517
|
+
const NotificationsParamsSchema = object$1({
|
|
10442
10518
|
/**
|
|
10443
10519
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10444
10520
|
* for notes on _meta usage.
|
|
10445
10521
|
*/
|
|
10446
|
-
_meta:
|
|
10522
|
+
_meta: RequestMetaSchema.optional()
|
|
10447
10523
|
});
|
|
10448
10524
|
const NotificationSchema = object$1({
|
|
10449
10525
|
method: string(),
|
|
10450
|
-
params: NotificationsParamsSchema.optional()
|
|
10526
|
+
params: NotificationsParamsSchema.loose().optional()
|
|
10451
10527
|
});
|
|
10452
10528
|
const ResultSchema = looseObject({
|
|
10453
10529
|
/**
|
|
10454
10530
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10455
10531
|
* for notes on _meta usage.
|
|
10456
10532
|
*/
|
|
10457
|
-
_meta:
|
|
10533
|
+
_meta: RequestMetaSchema.optional()
|
|
10458
10534
|
});
|
|
10459
|
-
const RequestIdSchema = union([string(), number().int()]);
|
|
10535
|
+
const RequestIdSchema = union([string(), number$1().int()]);
|
|
10460
10536
|
const JSONRPCRequestSchema = object$1({
|
|
10461
10537
|
jsonrpc: literal(JSONRPC_VERSION),
|
|
10462
10538
|
id: RequestIdSchema,
|
|
@@ -10468,12 +10544,13 @@ const JSONRPCNotificationSchema = object$1({
|
|
|
10468
10544
|
...NotificationSchema.shape
|
|
10469
10545
|
}).strict();
|
|
10470
10546
|
const isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safeParse(value).success;
|
|
10471
|
-
const
|
|
10547
|
+
const JSONRPCResultResponseSchema = object$1({
|
|
10472
10548
|
jsonrpc: literal(JSONRPC_VERSION),
|
|
10473
10549
|
id: RequestIdSchema,
|
|
10474
10550
|
result: ResultSchema
|
|
10475
10551
|
}).strict();
|
|
10476
|
-
const
|
|
10552
|
+
const isJSONRPCResultResponse = (value) => JSONRPCResultResponseSchema.safeParse(value).success;
|
|
10553
|
+
const isJSONRPCResponse = isJSONRPCResultResponse;
|
|
10477
10554
|
var ErrorCode;
|
|
10478
10555
|
(function(ErrorCode2) {
|
|
10479
10556
|
ErrorCode2[ErrorCode2["ConnectionClosed"] = -32e3] = "ConnectionClosed";
|
|
@@ -10485,14 +10562,14 @@ var ErrorCode;
|
|
|
10485
10562
|
ErrorCode2[ErrorCode2["InternalError"] = -32603] = "InternalError";
|
|
10486
10563
|
ErrorCode2[ErrorCode2["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
|
|
10487
10564
|
})(ErrorCode || (ErrorCode = {}));
|
|
10488
|
-
const
|
|
10565
|
+
const JSONRPCErrorResponseSchema = object$1({
|
|
10489
10566
|
jsonrpc: literal(JSONRPC_VERSION),
|
|
10490
|
-
id: RequestIdSchema,
|
|
10567
|
+
id: RequestIdSchema.optional(),
|
|
10491
10568
|
error: object$1({
|
|
10492
10569
|
/**
|
|
10493
10570
|
* The error type that occurred.
|
|
10494
10571
|
*/
|
|
10495
|
-
code: number().int(),
|
|
10572
|
+
code: number$1().int(),
|
|
10496
10573
|
/**
|
|
10497
10574
|
* A short description of the error. The message SHOULD be limited to a concise single sentence.
|
|
10498
10575
|
*/
|
|
@@ -10500,11 +10577,19 @@ const JSONRPCErrorSchema = object$1({
|
|
|
10500
10577
|
/**
|
|
10501
10578
|
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
10502
10579
|
*/
|
|
10503
|
-
data:
|
|
10580
|
+
data: unknown().optional()
|
|
10504
10581
|
})
|
|
10505
10582
|
}).strict();
|
|
10506
|
-
const
|
|
10507
|
-
const
|
|
10583
|
+
const JSONRPCErrorSchema = JSONRPCErrorResponseSchema;
|
|
10584
|
+
const isJSONRPCErrorResponse = (value) => JSONRPCErrorResponseSchema.safeParse(value).success;
|
|
10585
|
+
const isJSONRPCError = isJSONRPCErrorResponse;
|
|
10586
|
+
const JSONRPCMessageSchema = union([
|
|
10587
|
+
JSONRPCRequestSchema,
|
|
10588
|
+
JSONRPCNotificationSchema,
|
|
10589
|
+
JSONRPCResultResponseSchema,
|
|
10590
|
+
JSONRPCErrorResponseSchema
|
|
10591
|
+
]);
|
|
10592
|
+
const JSONRPCResponseSchema = union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
|
|
10508
10593
|
const EmptyResultSchema = ResultSchema.strict();
|
|
10509
10594
|
const CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
10510
10595
|
/**
|
|
@@ -10512,7 +10597,7 @@ const CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
|
10512
10597
|
*
|
|
10513
10598
|
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
10514
10599
|
*/
|
|
10515
|
-
requestId: RequestIdSchema,
|
|
10600
|
+
requestId: RequestIdSchema.optional(),
|
|
10516
10601
|
/**
|
|
10517
10602
|
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
10518
10603
|
*/
|
|
@@ -10537,7 +10622,15 @@ const IconSchema = object$1({
|
|
|
10537
10622
|
*
|
|
10538
10623
|
* If not provided, the client should assume that the icon can be used at any size.
|
|
10539
10624
|
*/
|
|
10540
|
-
sizes: array(string()).optional()
|
|
10625
|
+
sizes: array(string()).optional(),
|
|
10626
|
+
/**
|
|
10627
|
+
* Optional specifier for the theme this icon is designed for. `light` indicates
|
|
10628
|
+
* the icon is designed to be used with a light background, and `dark` indicates
|
|
10629
|
+
* the icon is designed to be used with a dark background.
|
|
10630
|
+
*
|
|
10631
|
+
* If not provided, the client should assume the icon can be used with any theme.
|
|
10632
|
+
*/
|
|
10633
|
+
theme: _enum(["light", "dark"]).optional()
|
|
10541
10634
|
});
|
|
10542
10635
|
const IconsSchema = object$1({
|
|
10543
10636
|
/**
|
|
@@ -10573,7 +10666,15 @@ const ImplementationSchema = BaseMetadataSchema.extend({
|
|
|
10573
10666
|
/**
|
|
10574
10667
|
* An optional URL of the website for this implementation.
|
|
10575
10668
|
*/
|
|
10576
|
-
websiteUrl: string().optional()
|
|
10669
|
+
websiteUrl: string().optional(),
|
|
10670
|
+
/**
|
|
10671
|
+
* An optional human-readable description of what this implementation does.
|
|
10672
|
+
*
|
|
10673
|
+
* This can be used by clients or servers to provide context about their purpose
|
|
10674
|
+
* and capabilities. For example, a server might describe the types of resources
|
|
10675
|
+
* or tools it provides, while a client might describe its intended use case.
|
|
10676
|
+
*/
|
|
10677
|
+
description: string().optional()
|
|
10577
10678
|
});
|
|
10578
10679
|
const FormElicitationCapabilitySchema = intersection(object$1({
|
|
10579
10680
|
applyDefaults: boolean().optional()
|
|
@@ -10589,6 +10690,54 @@ const ElicitationCapabilitySchema = preprocess((value) => {
|
|
|
10589
10690
|
form: FormElicitationCapabilitySchema.optional(),
|
|
10590
10691
|
url: AssertObjectSchema.optional()
|
|
10591
10692
|
}), record(string(), unknown()).optional()));
|
|
10693
|
+
const ClientTasksCapabilitySchema = looseObject({
|
|
10694
|
+
/**
|
|
10695
|
+
* Present if the client supports listing tasks.
|
|
10696
|
+
*/
|
|
10697
|
+
list: AssertObjectSchema.optional(),
|
|
10698
|
+
/**
|
|
10699
|
+
* Present if the client supports cancelling tasks.
|
|
10700
|
+
*/
|
|
10701
|
+
cancel: AssertObjectSchema.optional(),
|
|
10702
|
+
/**
|
|
10703
|
+
* Capabilities for task creation on specific request types.
|
|
10704
|
+
*/
|
|
10705
|
+
requests: looseObject({
|
|
10706
|
+
/**
|
|
10707
|
+
* Task support for sampling requests.
|
|
10708
|
+
*/
|
|
10709
|
+
sampling: looseObject({
|
|
10710
|
+
createMessage: AssertObjectSchema.optional()
|
|
10711
|
+
}).optional(),
|
|
10712
|
+
/**
|
|
10713
|
+
* Task support for elicitation requests.
|
|
10714
|
+
*/
|
|
10715
|
+
elicitation: looseObject({
|
|
10716
|
+
create: AssertObjectSchema.optional()
|
|
10717
|
+
}).optional()
|
|
10718
|
+
}).optional()
|
|
10719
|
+
});
|
|
10720
|
+
const ServerTasksCapabilitySchema = looseObject({
|
|
10721
|
+
/**
|
|
10722
|
+
* Present if the server supports listing tasks.
|
|
10723
|
+
*/
|
|
10724
|
+
list: AssertObjectSchema.optional(),
|
|
10725
|
+
/**
|
|
10726
|
+
* Present if the server supports cancelling tasks.
|
|
10727
|
+
*/
|
|
10728
|
+
cancel: AssertObjectSchema.optional(),
|
|
10729
|
+
/**
|
|
10730
|
+
* Capabilities for task creation on specific request types.
|
|
10731
|
+
*/
|
|
10732
|
+
requests: looseObject({
|
|
10733
|
+
/**
|
|
10734
|
+
* Task support for tool requests.
|
|
10735
|
+
*/
|
|
10736
|
+
tools: looseObject({
|
|
10737
|
+
call: AssertObjectSchema.optional()
|
|
10738
|
+
}).optional()
|
|
10739
|
+
}).optional()
|
|
10740
|
+
});
|
|
10592
10741
|
const ClientCapabilitiesSchema = object$1({
|
|
10593
10742
|
/**
|
|
10594
10743
|
* Experimental, non-standard capabilities that the client supports.
|
|
@@ -10620,7 +10769,11 @@ const ClientCapabilitiesSchema = object$1({
|
|
|
10620
10769
|
* Whether the client supports issuing notifications for changes to the roots list.
|
|
10621
10770
|
*/
|
|
10622
10771
|
listChanged: boolean().optional()
|
|
10623
|
-
}).optional()
|
|
10772
|
+
}).optional(),
|
|
10773
|
+
/**
|
|
10774
|
+
* Present if the client supports task creation.
|
|
10775
|
+
*/
|
|
10776
|
+
tasks: ClientTasksCapabilitySchema.optional()
|
|
10624
10777
|
});
|
|
10625
10778
|
const InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
10626
10779
|
/**
|
|
@@ -10651,12 +10804,12 @@ const ServerCapabilitiesSchema = object$1({
|
|
|
10651
10804
|
/**
|
|
10652
10805
|
* Present if the server offers any prompt templates.
|
|
10653
10806
|
*/
|
|
10654
|
-
prompts:
|
|
10807
|
+
prompts: object$1({
|
|
10655
10808
|
/**
|
|
10656
10809
|
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
10657
10810
|
*/
|
|
10658
|
-
listChanged:
|
|
10659
|
-
})),
|
|
10811
|
+
listChanged: boolean().optional()
|
|
10812
|
+
}).optional(),
|
|
10660
10813
|
/**
|
|
10661
10814
|
* Present if the server offers any resources to read.
|
|
10662
10815
|
*/
|
|
@@ -10678,7 +10831,11 @@ const ServerCapabilitiesSchema = object$1({
|
|
|
10678
10831
|
* Whether this server supports issuing notifications for changes to the tool list.
|
|
10679
10832
|
*/
|
|
10680
10833
|
listChanged: boolean().optional()
|
|
10681
|
-
}).optional()
|
|
10834
|
+
}).optional(),
|
|
10835
|
+
/**
|
|
10836
|
+
* Present if the server supports task creation.
|
|
10837
|
+
*/
|
|
10838
|
+
tasks: ServerTasksCapabilitySchema.optional()
|
|
10682
10839
|
});
|
|
10683
10840
|
const InitializeResultSchema = ResultSchema.extend({
|
|
10684
10841
|
/**
|
|
@@ -10695,21 +10852,23 @@ const InitializeResultSchema = ResultSchema.extend({
|
|
|
10695
10852
|
instructions: string().optional()
|
|
10696
10853
|
});
|
|
10697
10854
|
const InitializedNotificationSchema = NotificationSchema.extend({
|
|
10698
|
-
method: literal("notifications/initialized")
|
|
10855
|
+
method: literal("notifications/initialized"),
|
|
10856
|
+
params: NotificationsParamsSchema.optional()
|
|
10699
10857
|
});
|
|
10700
10858
|
const isInitializedNotification = (value) => InitializedNotificationSchema.safeParse(value).success;
|
|
10701
10859
|
const PingRequestSchema = RequestSchema.extend({
|
|
10702
|
-
method: literal("ping")
|
|
10860
|
+
method: literal("ping"),
|
|
10861
|
+
params: BaseRequestParamsSchema.optional()
|
|
10703
10862
|
});
|
|
10704
10863
|
const ProgressSchema = object$1({
|
|
10705
10864
|
/**
|
|
10706
10865
|
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
10707
10866
|
*/
|
|
10708
|
-
progress: number(),
|
|
10867
|
+
progress: number$1(),
|
|
10709
10868
|
/**
|
|
10710
10869
|
* Total number of items to process (or total progress required), if known.
|
|
10711
10870
|
*/
|
|
10712
|
-
total: optional(number()),
|
|
10871
|
+
total: optional(number$1()),
|
|
10713
10872
|
/**
|
|
10714
10873
|
* An optional message describing the current progress.
|
|
10715
10874
|
*/
|
|
@@ -10742,8 +10901,66 @@ const PaginatedResultSchema = ResultSchema.extend({
|
|
|
10742
10901
|
* An opaque token representing the pagination position after the last returned result.
|
|
10743
10902
|
* If present, there may be more results available.
|
|
10744
10903
|
*/
|
|
10745
|
-
nextCursor: optional(
|
|
10904
|
+
nextCursor: CursorSchema.optional()
|
|
10905
|
+
});
|
|
10906
|
+
const TaskStatusSchema = _enum(["working", "input_required", "completed", "failed", "cancelled"]);
|
|
10907
|
+
const TaskSchema = object$1({
|
|
10908
|
+
taskId: string(),
|
|
10909
|
+
status: TaskStatusSchema,
|
|
10910
|
+
/**
|
|
10911
|
+
* Time in milliseconds to keep task results available after completion.
|
|
10912
|
+
* If null, the task has unlimited lifetime until manually cleaned up.
|
|
10913
|
+
*/
|
|
10914
|
+
ttl: union([number$1(), _null()]),
|
|
10915
|
+
/**
|
|
10916
|
+
* ISO 8601 timestamp when the task was created.
|
|
10917
|
+
*/
|
|
10918
|
+
createdAt: string(),
|
|
10919
|
+
/**
|
|
10920
|
+
* ISO 8601 timestamp when the task was last updated.
|
|
10921
|
+
*/
|
|
10922
|
+
lastUpdatedAt: string(),
|
|
10923
|
+
pollInterval: optional(number$1()),
|
|
10924
|
+
/**
|
|
10925
|
+
* Optional diagnostic message for failed tasks or other status information.
|
|
10926
|
+
*/
|
|
10927
|
+
statusMessage: optional(string())
|
|
10928
|
+
});
|
|
10929
|
+
const CreateTaskResultSchema = ResultSchema.extend({
|
|
10930
|
+
task: TaskSchema
|
|
10931
|
+
});
|
|
10932
|
+
const TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
|
|
10933
|
+
const TaskStatusNotificationSchema = NotificationSchema.extend({
|
|
10934
|
+
method: literal("notifications/tasks/status"),
|
|
10935
|
+
params: TaskStatusNotificationParamsSchema
|
|
10936
|
+
});
|
|
10937
|
+
const GetTaskRequestSchema = RequestSchema.extend({
|
|
10938
|
+
method: literal("tasks/get"),
|
|
10939
|
+
params: BaseRequestParamsSchema.extend({
|
|
10940
|
+
taskId: string()
|
|
10941
|
+
})
|
|
10942
|
+
});
|
|
10943
|
+
const GetTaskResultSchema = ResultSchema.merge(TaskSchema);
|
|
10944
|
+
const GetTaskPayloadRequestSchema = RequestSchema.extend({
|
|
10945
|
+
method: literal("tasks/result"),
|
|
10946
|
+
params: BaseRequestParamsSchema.extend({
|
|
10947
|
+
taskId: string()
|
|
10948
|
+
})
|
|
10949
|
+
});
|
|
10950
|
+
const GetTaskPayloadResultSchema = ResultSchema.loose();
|
|
10951
|
+
const ListTasksRequestSchema = PaginatedRequestSchema.extend({
|
|
10952
|
+
method: literal("tasks/list")
|
|
10746
10953
|
});
|
|
10954
|
+
const ListTasksResultSchema = PaginatedResultSchema.extend({
|
|
10955
|
+
tasks: array(TaskSchema)
|
|
10956
|
+
});
|
|
10957
|
+
const CancelTaskRequestSchema = RequestSchema.extend({
|
|
10958
|
+
method: literal("tasks/cancel"),
|
|
10959
|
+
params: BaseRequestParamsSchema.extend({
|
|
10960
|
+
taskId: string()
|
|
10961
|
+
})
|
|
10962
|
+
});
|
|
10963
|
+
const CancelTaskResultSchema = ResultSchema.merge(TaskSchema);
|
|
10747
10964
|
const ResourceContentsSchema = object$1({
|
|
10748
10965
|
/**
|
|
10749
10966
|
* The URI of this resource.
|
|
@@ -10769,7 +10986,7 @@ const Base64Schema = string().refine((val) => {
|
|
|
10769
10986
|
try {
|
|
10770
10987
|
atob(val);
|
|
10771
10988
|
return true;
|
|
10772
|
-
} catch
|
|
10989
|
+
} catch {
|
|
10773
10990
|
return false;
|
|
10774
10991
|
}
|
|
10775
10992
|
}, { message: "Invalid Base64 string" });
|
|
@@ -10779,6 +10996,21 @@ const BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
|
10779
10996
|
*/
|
|
10780
10997
|
blob: Base64Schema
|
|
10781
10998
|
});
|
|
10999
|
+
const RoleSchema = _enum(["user", "assistant"]);
|
|
11000
|
+
const AnnotationsSchema = object$1({
|
|
11001
|
+
/**
|
|
11002
|
+
* Intended audience(s) for the resource.
|
|
11003
|
+
*/
|
|
11004
|
+
audience: array(RoleSchema).optional(),
|
|
11005
|
+
/**
|
|
11006
|
+
* Importance hint for the resource, from 0 (least) to 1 (most).
|
|
11007
|
+
*/
|
|
11008
|
+
priority: number$1().min(0).max(1).optional(),
|
|
11009
|
+
/**
|
|
11010
|
+
* ISO 8601 timestamp for the most recent modification.
|
|
11011
|
+
*/
|
|
11012
|
+
lastModified: datetime({ offset: true }).optional()
|
|
11013
|
+
});
|
|
10782
11014
|
const ResourceSchema = object$1({
|
|
10783
11015
|
...BaseMetadataSchema.shape,
|
|
10784
11016
|
...IconsSchema.shape,
|
|
@@ -10796,6 +11028,10 @@ const ResourceSchema = object$1({
|
|
|
10796
11028
|
* The MIME type of this resource, if known.
|
|
10797
11029
|
*/
|
|
10798
11030
|
mimeType: optional(string()),
|
|
11031
|
+
/**
|
|
11032
|
+
* Optional annotations for the client.
|
|
11033
|
+
*/
|
|
11034
|
+
annotations: AnnotationsSchema.optional(),
|
|
10799
11035
|
/**
|
|
10800
11036
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10801
11037
|
* for notes on _meta usage.
|
|
@@ -10819,6 +11055,10 @@ const ResourceTemplateSchema = object$1({
|
|
|
10819
11055
|
* The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type.
|
|
10820
11056
|
*/
|
|
10821
11057
|
mimeType: optional(string()),
|
|
11058
|
+
/**
|
|
11059
|
+
* Optional annotations for the client.
|
|
11060
|
+
*/
|
|
11061
|
+
annotations: AnnotationsSchema.optional(),
|
|
10822
11062
|
/**
|
|
10823
11063
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10824
11064
|
* for notes on _meta usage.
|
|
@@ -10854,7 +11094,8 @@ const ReadResourceResultSchema = ResultSchema.extend({
|
|
|
10854
11094
|
contents: array(union([TextResourceContentsSchema, BlobResourceContentsSchema]))
|
|
10855
11095
|
});
|
|
10856
11096
|
const ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
10857
|
-
method: literal("notifications/resources/list_changed")
|
|
11097
|
+
method: literal("notifications/resources/list_changed"),
|
|
11098
|
+
params: NotificationsParamsSchema.optional()
|
|
10858
11099
|
});
|
|
10859
11100
|
const SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
10860
11101
|
const SubscribeRequestSchema = RequestSchema.extend({
|
|
@@ -10933,6 +11174,10 @@ const TextContentSchema = object$1({
|
|
|
10933
11174
|
* The text content of the message.
|
|
10934
11175
|
*/
|
|
10935
11176
|
text: string(),
|
|
11177
|
+
/**
|
|
11178
|
+
* Optional annotations for the client.
|
|
11179
|
+
*/
|
|
11180
|
+
annotations: AnnotationsSchema.optional(),
|
|
10936
11181
|
/**
|
|
10937
11182
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10938
11183
|
* for notes on _meta usage.
|
|
@@ -10949,6 +11194,10 @@ const ImageContentSchema = object$1({
|
|
|
10949
11194
|
* The MIME type of the image. Different providers may support different image types.
|
|
10950
11195
|
*/
|
|
10951
11196
|
mimeType: string(),
|
|
11197
|
+
/**
|
|
11198
|
+
* Optional annotations for the client.
|
|
11199
|
+
*/
|
|
11200
|
+
annotations: AnnotationsSchema.optional(),
|
|
10952
11201
|
/**
|
|
10953
11202
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10954
11203
|
* for notes on _meta usage.
|
|
@@ -10965,6 +11214,10 @@ const AudioContentSchema = object$1({
|
|
|
10965
11214
|
* The MIME type of the audio. Different providers may support different audio types.
|
|
10966
11215
|
*/
|
|
10967
11216
|
mimeType: string(),
|
|
11217
|
+
/**
|
|
11218
|
+
* Optional annotations for the client.
|
|
11219
|
+
*/
|
|
11220
|
+
annotations: AnnotationsSchema.optional(),
|
|
10968
11221
|
/**
|
|
10969
11222
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10970
11223
|
* for notes on _meta usage.
|
|
@@ -10987,16 +11240,20 @@ const ToolUseContentSchema = object$1({
|
|
|
10987
11240
|
* Arguments to pass to the tool.
|
|
10988
11241
|
* Must conform to the tool's inputSchema.
|
|
10989
11242
|
*/
|
|
10990
|
-
input:
|
|
11243
|
+
input: record(string(), unknown()),
|
|
10991
11244
|
/**
|
|
10992
11245
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10993
11246
|
* for notes on _meta usage.
|
|
10994
11247
|
*/
|
|
10995
|
-
_meta:
|
|
10996
|
-
})
|
|
11248
|
+
_meta: record(string(), unknown()).optional()
|
|
11249
|
+
});
|
|
10997
11250
|
const EmbeddedResourceSchema = object$1({
|
|
10998
11251
|
type: literal("resource"),
|
|
10999
11252
|
resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
|
|
11253
|
+
/**
|
|
11254
|
+
* Optional annotations for the client.
|
|
11255
|
+
*/
|
|
11256
|
+
annotations: AnnotationsSchema.optional(),
|
|
11000
11257
|
/**
|
|
11001
11258
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
11002
11259
|
* for notes on _meta usage.
|
|
@@ -11014,18 +11271,19 @@ const ContentBlockSchema = union([
|
|
|
11014
11271
|
EmbeddedResourceSchema
|
|
11015
11272
|
]);
|
|
11016
11273
|
const PromptMessageSchema = object$1({
|
|
11017
|
-
role:
|
|
11274
|
+
role: RoleSchema,
|
|
11018
11275
|
content: ContentBlockSchema
|
|
11019
11276
|
});
|
|
11020
11277
|
const GetPromptResultSchema = ResultSchema.extend({
|
|
11021
11278
|
/**
|
|
11022
11279
|
* An optional description for the prompt.
|
|
11023
11280
|
*/
|
|
11024
|
-
description:
|
|
11281
|
+
description: string().optional(),
|
|
11025
11282
|
messages: array(PromptMessageSchema)
|
|
11026
11283
|
});
|
|
11027
11284
|
const PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
11028
|
-
method: literal("notifications/prompts/list_changed")
|
|
11285
|
+
method: literal("notifications/prompts/list_changed"),
|
|
11286
|
+
params: NotificationsParamsSchema.optional()
|
|
11029
11287
|
});
|
|
11030
11288
|
const ToolAnnotationsSchema = object$1({
|
|
11031
11289
|
/**
|
|
@@ -11066,6 +11324,17 @@ const ToolAnnotationsSchema = object$1({
|
|
|
11066
11324
|
*/
|
|
11067
11325
|
openWorldHint: boolean().optional()
|
|
11068
11326
|
});
|
|
11327
|
+
const ToolExecutionSchema = object$1({
|
|
11328
|
+
/**
|
|
11329
|
+
* Indicates the tool's preference for task-augmented execution.
|
|
11330
|
+
* - "required": Clients MUST invoke the tool as a task
|
|
11331
|
+
* - "optional": Clients MAY invoke the tool as a task or normal request
|
|
11332
|
+
* - "forbidden": Clients MUST NOT attempt to invoke the tool as a task
|
|
11333
|
+
*
|
|
11334
|
+
* If not present, defaults to "forbidden".
|
|
11335
|
+
*/
|
|
11336
|
+
taskSupport: _enum(["required", "optional", "forbidden"]).optional()
|
|
11337
|
+
});
|
|
11069
11338
|
const ToolSchema = object$1({
|
|
11070
11339
|
...BaseMetadataSchema.shape,
|
|
11071
11340
|
...IconsSchema.shape,
|
|
@@ -11095,7 +11364,11 @@ const ToolSchema = object$1({
|
|
|
11095
11364
|
/**
|
|
11096
11365
|
* Optional additional tool information.
|
|
11097
11366
|
*/
|
|
11098
|
-
annotations: optional(
|
|
11367
|
+
annotations: ToolAnnotationsSchema.optional(),
|
|
11368
|
+
/**
|
|
11369
|
+
* Execution-related properties for this tool.
|
|
11370
|
+
*/
|
|
11371
|
+
execution: ToolExecutionSchema.optional(),
|
|
11099
11372
|
/**
|
|
11100
11373
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
11101
11374
|
* for notes on _meta usage.
|
|
@@ -11136,12 +11409,12 @@ const CallToolResultSchema = ResultSchema.extend({
|
|
|
11136
11409
|
* server does not support tool calls, or any other exceptional conditions,
|
|
11137
11410
|
* should be reported as an MCP error response.
|
|
11138
11411
|
*/
|
|
11139
|
-
isError:
|
|
11412
|
+
isError: boolean().optional()
|
|
11140
11413
|
});
|
|
11141
11414
|
const CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
|
|
11142
11415
|
toolResult: unknown()
|
|
11143
11416
|
}));
|
|
11144
|
-
const CallToolRequestParamsSchema =
|
|
11417
|
+
const CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
11145
11418
|
/**
|
|
11146
11419
|
* The name of the tool to call.
|
|
11147
11420
|
*/
|
|
@@ -11149,14 +11422,35 @@ const CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
11149
11422
|
/**
|
|
11150
11423
|
* Arguments to pass to the tool.
|
|
11151
11424
|
*/
|
|
11152
|
-
arguments:
|
|
11425
|
+
arguments: record(string(), unknown()).optional()
|
|
11153
11426
|
});
|
|
11154
11427
|
const CallToolRequestSchema = RequestSchema.extend({
|
|
11155
11428
|
method: literal("tools/call"),
|
|
11156
11429
|
params: CallToolRequestParamsSchema
|
|
11157
11430
|
});
|
|
11158
11431
|
const ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
11159
|
-
method: literal("notifications/tools/list_changed")
|
|
11432
|
+
method: literal("notifications/tools/list_changed"),
|
|
11433
|
+
params: NotificationsParamsSchema.optional()
|
|
11434
|
+
});
|
|
11435
|
+
const ListChangedOptionsBaseSchema = object$1({
|
|
11436
|
+
/**
|
|
11437
|
+
* If true, the list will be refreshed automatically when a list changed notification is received.
|
|
11438
|
+
* The callback will be called with the updated list.
|
|
11439
|
+
*
|
|
11440
|
+
* If false, the callback will be called with null items, allowing manual refresh.
|
|
11441
|
+
*
|
|
11442
|
+
* @default true
|
|
11443
|
+
*/
|
|
11444
|
+
autoRefresh: boolean().default(true),
|
|
11445
|
+
/**
|
|
11446
|
+
* Debounce time in milliseconds for list changed notification processing.
|
|
11447
|
+
*
|
|
11448
|
+
* Multiple notifications received within this timeframe will only trigger one refresh.
|
|
11449
|
+
* Set to 0 to disable debouncing.
|
|
11450
|
+
*
|
|
11451
|
+
* @default 300
|
|
11452
|
+
*/
|
|
11453
|
+
debounceMs: number$1().int().nonnegative().default(300)
|
|
11160
11454
|
});
|
|
11161
11455
|
const LoggingLevelSchema = _enum(["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]);
|
|
11162
11456
|
const SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
@@ -11197,19 +11491,19 @@ const ModelPreferencesSchema = object$1({
|
|
|
11197
11491
|
/**
|
|
11198
11492
|
* Optional hints to use for model selection.
|
|
11199
11493
|
*/
|
|
11200
|
-
hints:
|
|
11494
|
+
hints: array(ModelHintSchema).optional(),
|
|
11201
11495
|
/**
|
|
11202
11496
|
* How much to prioritize cost when selecting a model.
|
|
11203
11497
|
*/
|
|
11204
|
-
costPriority:
|
|
11498
|
+
costPriority: number$1().min(0).max(1).optional(),
|
|
11205
11499
|
/**
|
|
11206
11500
|
* How much to prioritize sampling speed (latency) when selecting a model.
|
|
11207
11501
|
*/
|
|
11208
|
-
speedPriority:
|
|
11502
|
+
speedPriority: number$1().min(0).max(1).optional(),
|
|
11209
11503
|
/**
|
|
11210
11504
|
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
11211
11505
|
*/
|
|
11212
|
-
intelligencePriority:
|
|
11506
|
+
intelligencePriority: number$1().min(0).max(1).optional()
|
|
11213
11507
|
});
|
|
11214
11508
|
const ToolChoiceSchema = object$1({
|
|
11215
11509
|
/**
|
|
@@ -11218,20 +11512,21 @@ const ToolChoiceSchema = object$1({
|
|
|
11218
11512
|
* - "required": Model MUST use at least one tool before completing
|
|
11219
11513
|
* - "none": Model MUST NOT use any tools
|
|
11220
11514
|
*/
|
|
11221
|
-
mode:
|
|
11515
|
+
mode: _enum(["auto", "required", "none"]).optional()
|
|
11222
11516
|
});
|
|
11223
11517
|
const ToolResultContentSchema = object$1({
|
|
11224
11518
|
type: literal("tool_result"),
|
|
11225
11519
|
toolUseId: string().describe("The unique identifier for the corresponding tool call."),
|
|
11226
11520
|
content: array(ContentBlockSchema).default([]),
|
|
11227
|
-
structuredContent: object$1({}).
|
|
11228
|
-
isError:
|
|
11521
|
+
structuredContent: object$1({}).loose().optional(),
|
|
11522
|
+
isError: boolean().optional(),
|
|
11229
11523
|
/**
|
|
11230
11524
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
11231
11525
|
* for notes on _meta usage.
|
|
11232
11526
|
*/
|
|
11233
|
-
_meta:
|
|
11234
|
-
})
|
|
11527
|
+
_meta: record(string(), unknown()).optional()
|
|
11528
|
+
});
|
|
11529
|
+
const SamplingContentSchema = discriminatedUnion("type", [TextContentSchema, ImageContentSchema, AudioContentSchema]);
|
|
11235
11530
|
const SamplingMessageContentBlockSchema = discriminatedUnion("type", [
|
|
11236
11531
|
TextContentSchema,
|
|
11237
11532
|
ImageContentSchema,
|
|
@@ -11240,15 +11535,15 @@ const SamplingMessageContentBlockSchema = discriminatedUnion("type", [
|
|
|
11240
11535
|
ToolResultContentSchema
|
|
11241
11536
|
]);
|
|
11242
11537
|
const SamplingMessageSchema = object$1({
|
|
11243
|
-
role:
|
|
11538
|
+
role: RoleSchema,
|
|
11244
11539
|
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)]),
|
|
11245
11540
|
/**
|
|
11246
11541
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
11247
11542
|
* for notes on _meta usage.
|
|
11248
11543
|
*/
|
|
11249
|
-
_meta:
|
|
11250
|
-
})
|
|
11251
|
-
const CreateMessageRequestParamsSchema =
|
|
11544
|
+
_meta: record(string(), unknown()).optional()
|
|
11545
|
+
});
|
|
11546
|
+
const CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
11252
11547
|
messages: array(SamplingMessageSchema),
|
|
11253
11548
|
/**
|
|
11254
11549
|
* The server's preferences for which model to select. The client MAY modify or omit this request.
|
|
@@ -11266,13 +11561,13 @@ const CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
11266
11561
|
* declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
|
|
11267
11562
|
*/
|
|
11268
11563
|
includeContext: _enum(["none", "thisServer", "allServers"]).optional(),
|
|
11269
|
-
temperature: number().optional(),
|
|
11564
|
+
temperature: number$1().optional(),
|
|
11270
11565
|
/**
|
|
11271
11566
|
* The requested maximum number of tokens to sample (to prevent runaway completions).
|
|
11272
11567
|
*
|
|
11273
11568
|
* The client MAY choose to sample fewer tokens than the requested maximum.
|
|
11274
11569
|
*/
|
|
11275
|
-
maxTokens: number().int(),
|
|
11570
|
+
maxTokens: number$1().int(),
|
|
11276
11571
|
stopSequences: array(string()).optional(),
|
|
11277
11572
|
/**
|
|
11278
11573
|
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
@@ -11282,19 +11577,41 @@ const CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
11282
11577
|
* Tools that the model may use during generation.
|
|
11283
11578
|
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
11284
11579
|
*/
|
|
11285
|
-
tools:
|
|
11580
|
+
tools: array(ToolSchema).optional(),
|
|
11286
11581
|
/**
|
|
11287
11582
|
* Controls how the model uses tools.
|
|
11288
11583
|
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
11289
11584
|
* Default is `{ mode: "auto" }`.
|
|
11290
11585
|
*/
|
|
11291
|
-
toolChoice: optional(
|
|
11586
|
+
toolChoice: ToolChoiceSchema.optional()
|
|
11292
11587
|
});
|
|
11293
11588
|
const CreateMessageRequestSchema = RequestSchema.extend({
|
|
11294
11589
|
method: literal("sampling/createMessage"),
|
|
11295
11590
|
params: CreateMessageRequestParamsSchema
|
|
11296
11591
|
});
|
|
11297
11592
|
const CreateMessageResultSchema = ResultSchema.extend({
|
|
11593
|
+
/**
|
|
11594
|
+
* The name of the model that generated the message.
|
|
11595
|
+
*/
|
|
11596
|
+
model: string(),
|
|
11597
|
+
/**
|
|
11598
|
+
* The reason why sampling stopped, if known.
|
|
11599
|
+
*
|
|
11600
|
+
* Standard values:
|
|
11601
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
11602
|
+
* - "stopSequence": A stop sequence was encountered
|
|
11603
|
+
* - "maxTokens": Maximum token limit was reached
|
|
11604
|
+
*
|
|
11605
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
11606
|
+
*/
|
|
11607
|
+
stopReason: optional(_enum(["endTurn", "stopSequence", "maxTokens"]).or(string())),
|
|
11608
|
+
role: RoleSchema,
|
|
11609
|
+
/**
|
|
11610
|
+
* Response content. Single content block (text, image, or audio).
|
|
11611
|
+
*/
|
|
11612
|
+
content: SamplingContentSchema
|
|
11613
|
+
});
|
|
11614
|
+
const CreateMessageResultWithToolsSchema = ResultSchema.extend({
|
|
11298
11615
|
/**
|
|
11299
11616
|
* The name of the model that generated the message.
|
|
11300
11617
|
*/
|
|
@@ -11311,9 +11628,9 @@ const CreateMessageResultSchema = ResultSchema.extend({
|
|
|
11311
11628
|
* This field is an open string to allow for provider-specific stop reasons.
|
|
11312
11629
|
*/
|
|
11313
11630
|
stopReason: optional(_enum(["endTurn", "stopSequence", "maxTokens", "toolUse"]).or(string())),
|
|
11314
|
-
role:
|
|
11631
|
+
role: RoleSchema,
|
|
11315
11632
|
/**
|
|
11316
|
-
* Response content. May be ToolUseContent if stopReason is "toolUse".
|
|
11633
|
+
* Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
|
|
11317
11634
|
*/
|
|
11318
11635
|
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)])
|
|
11319
11636
|
});
|
|
@@ -11327,8 +11644,8 @@ const StringSchemaSchema = object$1({
|
|
|
11327
11644
|
type: literal("string"),
|
|
11328
11645
|
title: string().optional(),
|
|
11329
11646
|
description: string().optional(),
|
|
11330
|
-
minLength: number().optional(),
|
|
11331
|
-
maxLength: number().optional(),
|
|
11647
|
+
minLength: number$1().optional(),
|
|
11648
|
+
maxLength: number$1().optional(),
|
|
11332
11649
|
format: _enum(["email", "uri", "date", "date-time"]).optional(),
|
|
11333
11650
|
default: string().optional()
|
|
11334
11651
|
});
|
|
@@ -11336,9 +11653,9 @@ const NumberSchemaSchema = object$1({
|
|
|
11336
11653
|
type: _enum(["number", "integer"]),
|
|
11337
11654
|
title: string().optional(),
|
|
11338
11655
|
description: string().optional(),
|
|
11339
|
-
minimum: number().optional(),
|
|
11340
|
-
maximum: number().optional(),
|
|
11341
|
-
default: number().optional()
|
|
11656
|
+
minimum: number$1().optional(),
|
|
11657
|
+
maximum: number$1().optional(),
|
|
11658
|
+
default: number$1().optional()
|
|
11342
11659
|
});
|
|
11343
11660
|
const UntitledSingleSelectEnumSchemaSchema = object$1({
|
|
11344
11661
|
type: literal("string"),
|
|
@@ -11370,8 +11687,8 @@ const UntitledMultiSelectEnumSchemaSchema = object$1({
|
|
|
11370
11687
|
type: literal("array"),
|
|
11371
11688
|
title: string().optional(),
|
|
11372
11689
|
description: string().optional(),
|
|
11373
|
-
minItems: number().optional(),
|
|
11374
|
-
maxItems: number().optional(),
|
|
11690
|
+
minItems: number$1().optional(),
|
|
11691
|
+
maxItems: number$1().optional(),
|
|
11375
11692
|
items: object$1({
|
|
11376
11693
|
type: literal("string"),
|
|
11377
11694
|
enum: array(string())
|
|
@@ -11382,8 +11699,8 @@ const TitledMultiSelectEnumSchemaSchema = object$1({
|
|
|
11382
11699
|
type: literal("array"),
|
|
11383
11700
|
title: string().optional(),
|
|
11384
11701
|
description: string().optional(),
|
|
11385
|
-
minItems: number().optional(),
|
|
11386
|
-
maxItems: number().optional(),
|
|
11702
|
+
minItems: number$1().optional(),
|
|
11703
|
+
maxItems: number$1().optional(),
|
|
11387
11704
|
items: object$1({
|
|
11388
11705
|
anyOf: array(object$1({
|
|
11389
11706
|
const: string(),
|
|
@@ -11395,7 +11712,7 @@ const TitledMultiSelectEnumSchemaSchema = object$1({
|
|
|
11395
11712
|
const MultiSelectEnumSchemaSchema = union([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema]);
|
|
11396
11713
|
const EnumSchemaSchema = union([LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema]);
|
|
11397
11714
|
const PrimitiveSchemaDefinitionSchema = union([EnumSchemaSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema]);
|
|
11398
|
-
const ElicitRequestFormParamsSchema =
|
|
11715
|
+
const ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
11399
11716
|
/**
|
|
11400
11717
|
* The elicitation mode.
|
|
11401
11718
|
*
|
|
@@ -11416,7 +11733,7 @@ const ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
11416
11733
|
required: array(string()).optional()
|
|
11417
11734
|
})
|
|
11418
11735
|
});
|
|
11419
|
-
const ElicitRequestURLParamsSchema =
|
|
11736
|
+
const ElicitRequestURLParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
11420
11737
|
/**
|
|
11421
11738
|
* The elicitation mode.
|
|
11422
11739
|
*/
|
|
@@ -11461,8 +11778,10 @@ const ElicitResultSchema = ResultSchema.extend({
|
|
|
11461
11778
|
/**
|
|
11462
11779
|
* The submitted form data, only present when action is "accept".
|
|
11463
11780
|
* Contains values matching the requested schema.
|
|
11781
|
+
* Per MCP spec, content is "typically omitted" for decline/cancel actions.
|
|
11782
|
+
* We normalize null to undefined for leniency while maintaining type compatibility.
|
|
11464
11783
|
*/
|
|
11465
|
-
content: record(string(), union([string(), number(), boolean(), array(string())])).optional()
|
|
11784
|
+
content: preprocess((val) => val === null ? void 0 : val, record(string(), union([string(), number$1(), boolean(), array(string())])).optional())
|
|
11466
11785
|
});
|
|
11467
11786
|
const ResourceTemplateReferenceSchema = object$1({
|
|
11468
11787
|
type: literal("ref/resource"),
|
|
@@ -11524,7 +11843,7 @@ const CompleteResultSchema = ResultSchema.extend({
|
|
|
11524
11843
|
/**
|
|
11525
11844
|
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
11526
11845
|
*/
|
|
11527
|
-
total: optional(number().int()),
|
|
11846
|
+
total: optional(number$1().int()),
|
|
11528
11847
|
/**
|
|
11529
11848
|
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
11530
11849
|
*/
|
|
@@ -11547,13 +11866,15 @@ const RootSchema = object$1({
|
|
|
11547
11866
|
_meta: record(string(), unknown()).optional()
|
|
11548
11867
|
});
|
|
11549
11868
|
const ListRootsRequestSchema = RequestSchema.extend({
|
|
11550
|
-
method: literal("roots/list")
|
|
11869
|
+
method: literal("roots/list"),
|
|
11870
|
+
params: BaseRequestParamsSchema.optional()
|
|
11551
11871
|
});
|
|
11552
11872
|
const ListRootsResultSchema = ResultSchema.extend({
|
|
11553
11873
|
roots: array(RootSchema)
|
|
11554
11874
|
});
|
|
11555
11875
|
const RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
11556
|
-
method: literal("notifications/roots/list_changed")
|
|
11876
|
+
method: literal("notifications/roots/list_changed"),
|
|
11877
|
+
params: NotificationsParamsSchema.optional()
|
|
11557
11878
|
});
|
|
11558
11879
|
const ClientRequestSchema = union([
|
|
11559
11880
|
PingRequestSchema,
|
|
@@ -11568,16 +11889,39 @@ const ClientRequestSchema = union([
|
|
|
11568
11889
|
SubscribeRequestSchema,
|
|
11569
11890
|
UnsubscribeRequestSchema,
|
|
11570
11891
|
CallToolRequestSchema,
|
|
11571
|
-
ListToolsRequestSchema
|
|
11892
|
+
ListToolsRequestSchema,
|
|
11893
|
+
GetTaskRequestSchema,
|
|
11894
|
+
GetTaskPayloadRequestSchema,
|
|
11895
|
+
ListTasksRequestSchema,
|
|
11896
|
+
CancelTaskRequestSchema
|
|
11572
11897
|
]);
|
|
11573
11898
|
const ClientNotificationSchema = union([
|
|
11574
11899
|
CancelledNotificationSchema,
|
|
11575
11900
|
ProgressNotificationSchema,
|
|
11576
11901
|
InitializedNotificationSchema,
|
|
11577
|
-
RootsListChangedNotificationSchema
|
|
11902
|
+
RootsListChangedNotificationSchema,
|
|
11903
|
+
TaskStatusNotificationSchema
|
|
11904
|
+
]);
|
|
11905
|
+
const ClientResultSchema = union([
|
|
11906
|
+
EmptyResultSchema,
|
|
11907
|
+
CreateMessageResultSchema,
|
|
11908
|
+
CreateMessageResultWithToolsSchema,
|
|
11909
|
+
ElicitResultSchema,
|
|
11910
|
+
ListRootsResultSchema,
|
|
11911
|
+
GetTaskResultSchema,
|
|
11912
|
+
ListTasksResultSchema,
|
|
11913
|
+
CreateTaskResultSchema
|
|
11914
|
+
]);
|
|
11915
|
+
const ServerRequestSchema = union([
|
|
11916
|
+
PingRequestSchema,
|
|
11917
|
+
CreateMessageRequestSchema,
|
|
11918
|
+
ElicitRequestSchema,
|
|
11919
|
+
ListRootsRequestSchema,
|
|
11920
|
+
GetTaskRequestSchema,
|
|
11921
|
+
GetTaskPayloadRequestSchema,
|
|
11922
|
+
ListTasksRequestSchema,
|
|
11923
|
+
CancelTaskRequestSchema
|
|
11578
11924
|
]);
|
|
11579
|
-
const ClientResultSchema = union([EmptyResultSchema, CreateMessageResultSchema, ElicitResultSchema, ListRootsResultSchema]);
|
|
11580
|
-
const ServerRequestSchema = union([PingRequestSchema, CreateMessageRequestSchema, ElicitRequestSchema, ListRootsRequestSchema]);
|
|
11581
11925
|
const ServerNotificationSchema = union([
|
|
11582
11926
|
CancelledNotificationSchema,
|
|
11583
11927
|
ProgressNotificationSchema,
|
|
@@ -11586,6 +11930,7 @@ const ServerNotificationSchema = union([
|
|
|
11586
11930
|
ResourceListChangedNotificationSchema,
|
|
11587
11931
|
ToolListChangedNotificationSchema,
|
|
11588
11932
|
PromptListChangedNotificationSchema,
|
|
11933
|
+
TaskStatusNotificationSchema,
|
|
11589
11934
|
ElicitationCompleteNotificationSchema
|
|
11590
11935
|
]);
|
|
11591
11936
|
const ServerResultSchema = union([
|
|
@@ -11598,7 +11943,10 @@ const ServerResultSchema = union([
|
|
|
11598
11943
|
ListResourceTemplatesResultSchema,
|
|
11599
11944
|
ReadResourceResultSchema,
|
|
11600
11945
|
CallToolResultSchema,
|
|
11601
|
-
ListToolsResultSchema
|
|
11946
|
+
ListToolsResultSchema,
|
|
11947
|
+
GetTaskResultSchema,
|
|
11948
|
+
ListTasksResultSchema,
|
|
11949
|
+
CreateTaskResultSchema
|
|
11602
11950
|
]);
|
|
11603
11951
|
class McpError extends Error {
|
|
11604
11952
|
constructor(code2, message, data) {
|
|
@@ -11627,8 +11975,7 @@ class UrlElicitationRequiredError extends McpError {
|
|
|
11627
11975
|
});
|
|
11628
11976
|
}
|
|
11629
11977
|
get elicitations() {
|
|
11630
|
-
|
|
11631
|
-
return (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.elicitations) !== null && _b !== void 0 ? _b : [];
|
|
11978
|
+
return this.data?.elicitations ?? [];
|
|
11632
11979
|
}
|
|
11633
11980
|
}
|
|
11634
11981
|
const MAX_TEMPLATE_LENGTH = 1e6;
|
|
@@ -11798,7 +12145,7 @@ class UriTemplate {
|
|
|
11798
12145
|
const name = part.name;
|
|
11799
12146
|
switch (part.operator) {
|
|
11800
12147
|
case "":
|
|
11801
|
-
pattern2 = part.exploded ? "([
|
|
12148
|
+
pattern2 = part.exploded ? "([^/,]+(?:,[^/,]+)*)" : "([^/,]+)";
|
|
11802
12149
|
break;
|
|
11803
12150
|
case "+":
|
|
11804
12151
|
case "#":
|
|
@@ -11808,7 +12155,7 @@ class UriTemplate {
|
|
|
11808
12155
|
pattern2 = "\\.([^/,]+)";
|
|
11809
12156
|
break;
|
|
11810
12157
|
case "/":
|
|
11811
|
-
pattern2 = "/" + (part.exploded ? "([
|
|
12158
|
+
pattern2 = "/" + (part.exploded ? "([^/,]+(?:,[^/,]+)*)" : "([^/,]+)");
|
|
11812
12159
|
break;
|
|
11813
12160
|
default:
|
|
11814
12161
|
pattern2 = "([^/]+)";
|
|
@@ -11866,7 +12213,7 @@ function isCompletable(schema) {
|
|
|
11866
12213
|
}
|
|
11867
12214
|
function getCompleter(schema) {
|
|
11868
12215
|
const meta = schema[COMPLETABLE_SYMBOL];
|
|
11869
|
-
return meta
|
|
12216
|
+
return meta?.complete;
|
|
11870
12217
|
}
|
|
11871
12218
|
function unwrapCompletable(schema) {
|
|
11872
12219
|
return schema;
|
|
@@ -11876,11 +12223,10 @@ var McpZodTypeKind;
|
|
|
11876
12223
|
McpZodTypeKind2["Completable"] = "McpCompletable";
|
|
11877
12224
|
})(McpZodTypeKind || (McpZodTypeKind = {}));
|
|
11878
12225
|
function getDisplayName(metadata2) {
|
|
11879
|
-
var _a;
|
|
11880
12226
|
if (metadata2.title !== void 0 && metadata2.title !== "") {
|
|
11881
12227
|
return metadata2.title;
|
|
11882
12228
|
}
|
|
11883
|
-
if (
|
|
12229
|
+
if ("annotations" in metadata2 && metadata2.annotations?.title) {
|
|
11884
12230
|
return metadata2.annotations.title;
|
|
11885
12231
|
}
|
|
11886
12232
|
return metadata2.name;
|
|
@@ -15533,13 +15879,12 @@ async function safeParseAsync(schema, data) {
|
|
|
15533
15879
|
return result;
|
|
15534
15880
|
}
|
|
15535
15881
|
function getObjectShape(schema) {
|
|
15536
|
-
var _a, _b;
|
|
15537
15882
|
if (!schema)
|
|
15538
15883
|
return void 0;
|
|
15539
15884
|
let rawShape;
|
|
15540
15885
|
if (isZ4Schema(schema)) {
|
|
15541
15886
|
const v4Schema = schema;
|
|
15542
|
-
rawShape =
|
|
15887
|
+
rawShape = v4Schema._zod?.def?.shape;
|
|
15543
15888
|
} else {
|
|
15544
15889
|
const v3Schema = schema;
|
|
15545
15890
|
rawShape = v3Schema.shape;
|
|
@@ -15549,14 +15894,13 @@ function getObjectShape(schema) {
|
|
|
15549
15894
|
if (typeof rawShape === "function") {
|
|
15550
15895
|
try {
|
|
15551
15896
|
return rawShape();
|
|
15552
|
-
} catch
|
|
15897
|
+
} catch {
|
|
15553
15898
|
return void 0;
|
|
15554
15899
|
}
|
|
15555
15900
|
}
|
|
15556
15901
|
return rawShape;
|
|
15557
15902
|
}
|
|
15558
15903
|
function normalizeObjectSchema(schema) {
|
|
15559
|
-
var _a;
|
|
15560
15904
|
if (!schema)
|
|
15561
15905
|
return void 0;
|
|
15562
15906
|
if (typeof schema === "object") {
|
|
@@ -15571,8 +15915,8 @@ function normalizeObjectSchema(schema) {
|
|
|
15571
15915
|
}
|
|
15572
15916
|
if (isZ4Schema(schema)) {
|
|
15573
15917
|
const v4Schema = schema;
|
|
15574
|
-
const def =
|
|
15575
|
-
if (def && (def.
|
|
15918
|
+
const def = v4Schema._zod?.def;
|
|
15919
|
+
if (def && (def.type === "object" || def.shape !== void 0)) {
|
|
15576
15920
|
return schema;
|
|
15577
15921
|
}
|
|
15578
15922
|
} else {
|
|
@@ -15596,38 +15940,30 @@ function getParseErrorMessage(error) {
|
|
|
15596
15940
|
}
|
|
15597
15941
|
try {
|
|
15598
15942
|
return JSON.stringify(error);
|
|
15599
|
-
} catch
|
|
15943
|
+
} catch {
|
|
15600
15944
|
return String(error);
|
|
15601
15945
|
}
|
|
15602
15946
|
}
|
|
15603
15947
|
return String(error);
|
|
15604
15948
|
}
|
|
15605
15949
|
function getSchemaDescription(schema) {
|
|
15606
|
-
|
|
15607
|
-
if (isZ4Schema(schema)) {
|
|
15608
|
-
const v4Schema = schema;
|
|
15609
|
-
return (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.description;
|
|
15610
|
-
}
|
|
15611
|
-
const v3Schema = schema;
|
|
15612
|
-
return (_c = schema.description) !== null && _c !== void 0 ? _c : (_d = v3Schema._def) === null || _d === void 0 ? void 0 : _d.description;
|
|
15950
|
+
return schema.description;
|
|
15613
15951
|
}
|
|
15614
15952
|
function isSchemaOptional(schema) {
|
|
15615
|
-
var _a, _b, _c;
|
|
15616
15953
|
if (isZ4Schema(schema)) {
|
|
15617
15954
|
const v4Schema = schema;
|
|
15618
|
-
return
|
|
15955
|
+
return v4Schema._zod?.def?.type === "optional";
|
|
15619
15956
|
}
|
|
15620
15957
|
const v3Schema = schema;
|
|
15621
15958
|
if (typeof schema.isOptional === "function") {
|
|
15622
15959
|
return schema.isOptional();
|
|
15623
15960
|
}
|
|
15624
|
-
return
|
|
15961
|
+
return v3Schema._def?.typeName === "ZodOptional";
|
|
15625
15962
|
}
|
|
15626
15963
|
function getLiteralValue(schema) {
|
|
15627
|
-
var _a;
|
|
15628
15964
|
if (isZ4Schema(schema)) {
|
|
15629
15965
|
const v4Schema = schema;
|
|
15630
|
-
const def2 =
|
|
15966
|
+
const def2 = v4Schema._zod?.def;
|
|
15631
15967
|
if (def2) {
|
|
15632
15968
|
if (def2.value !== void 0)
|
|
15633
15969
|
return def2.value;
|
|
@@ -15650,6 +15986,9 @@ function getLiteralValue(schema) {
|
|
|
15650
15986
|
return directValue;
|
|
15651
15987
|
return void 0;
|
|
15652
15988
|
}
|
|
15989
|
+
function isTerminal(status) {
|
|
15990
|
+
return status === "completed" || status === "failed" || status === "cancelled";
|
|
15991
|
+
}
|
|
15653
15992
|
const ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
15654
15993
|
const defaultOptions = {
|
|
15655
15994
|
name: void 0,
|
|
@@ -16863,21 +17202,20 @@ function mapMiniTarget(t) {
|
|
|
16863
17202
|
return "draft-7";
|
|
16864
17203
|
}
|
|
16865
17204
|
function toJsonSchemaCompat(schema, opts) {
|
|
16866
|
-
var _a, _b, _c;
|
|
16867
17205
|
if (isZ4Schema(schema)) {
|
|
16868
17206
|
return toJSONSchema(schema, {
|
|
16869
|
-
target: mapMiniTarget(opts
|
|
16870
|
-
io:
|
|
17207
|
+
target: mapMiniTarget(opts?.target),
|
|
17208
|
+
io: opts?.pipeStrategy ?? "input"
|
|
16871
17209
|
});
|
|
16872
17210
|
}
|
|
16873
17211
|
return zodToJsonSchema(schema, {
|
|
16874
|
-
strictUnions:
|
|
16875
|
-
pipeStrategy:
|
|
17212
|
+
strictUnions: opts?.strictUnions ?? true,
|
|
17213
|
+
pipeStrategy: opts?.pipeStrategy ?? "input"
|
|
16876
17214
|
});
|
|
16877
17215
|
}
|
|
16878
17216
|
function getMethodLiteral(schema) {
|
|
16879
17217
|
const shape = getObjectShape(schema);
|
|
16880
|
-
const methodSchema = shape
|
|
17218
|
+
const methodSchema = shape?.method;
|
|
16881
17219
|
if (!methodSchema) {
|
|
16882
17220
|
throw new Error("Schema is missing a method literal");
|
|
16883
17221
|
}
|
|
@@ -16906,9 +17244,10 @@ class Protocol {
|
|
|
16906
17244
|
this._progressHandlers = /* @__PURE__ */ new Map();
|
|
16907
17245
|
this._timeoutInfo = /* @__PURE__ */ new Map();
|
|
16908
17246
|
this._pendingDebouncedNotifications = /* @__PURE__ */ new Set();
|
|
17247
|
+
this._taskProgressTokens = /* @__PURE__ */ new Map();
|
|
17248
|
+
this._requestResolvers = /* @__PURE__ */ new Map();
|
|
16909
17249
|
this.setNotificationHandler(CancelledNotificationSchema, (notification) => {
|
|
16910
|
-
|
|
16911
|
-
controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason);
|
|
17250
|
+
this._oncancel(notification);
|
|
16912
17251
|
});
|
|
16913
17252
|
this.setNotificationHandler(ProgressNotificationSchema, (notification) => {
|
|
16914
17253
|
this._onprogress(notification);
|
|
@@ -16918,6 +17257,117 @@ class Protocol {
|
|
|
16918
17257
|
// Automatic pong by default.
|
|
16919
17258
|
(_request) => ({})
|
|
16920
17259
|
);
|
|
17260
|
+
this._taskStore = _options?.taskStore;
|
|
17261
|
+
this._taskMessageQueue = _options?.taskMessageQueue;
|
|
17262
|
+
if (this._taskStore) {
|
|
17263
|
+
this.setRequestHandler(GetTaskRequestSchema, async (request, extra) => {
|
|
17264
|
+
const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
17265
|
+
if (!task) {
|
|
17266
|
+
throw new McpError(ErrorCode.InvalidParams, "Failed to retrieve task: Task not found");
|
|
17267
|
+
}
|
|
17268
|
+
return {
|
|
17269
|
+
...task
|
|
17270
|
+
};
|
|
17271
|
+
});
|
|
17272
|
+
this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
|
|
17273
|
+
const handleTaskResult = async () => {
|
|
17274
|
+
const taskId = request.params.taskId;
|
|
17275
|
+
if (this._taskMessageQueue) {
|
|
17276
|
+
let queuedMessage;
|
|
17277
|
+
while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
|
|
17278
|
+
if (queuedMessage.type === "response" || queuedMessage.type === "error") {
|
|
17279
|
+
const message = queuedMessage.message;
|
|
17280
|
+
const requestId = message.id;
|
|
17281
|
+
const resolver = this._requestResolvers.get(requestId);
|
|
17282
|
+
if (resolver) {
|
|
17283
|
+
this._requestResolvers.delete(requestId);
|
|
17284
|
+
if (queuedMessage.type === "response") {
|
|
17285
|
+
resolver(message);
|
|
17286
|
+
} else {
|
|
17287
|
+
const errorMessage = message;
|
|
17288
|
+
const error = new McpError(errorMessage.error.code, errorMessage.error.message, errorMessage.error.data);
|
|
17289
|
+
resolver(error);
|
|
17290
|
+
}
|
|
17291
|
+
} else {
|
|
17292
|
+
const messageType = queuedMessage.type === "response" ? "Response" : "Error";
|
|
17293
|
+
this._onerror(new Error(`${messageType} handler missing for request ${requestId}`));
|
|
17294
|
+
}
|
|
17295
|
+
continue;
|
|
17296
|
+
}
|
|
17297
|
+
await this._transport?.send(queuedMessage.message, { relatedRequestId: extra.requestId });
|
|
17298
|
+
}
|
|
17299
|
+
}
|
|
17300
|
+
const task = await this._taskStore.getTask(taskId, extra.sessionId);
|
|
17301
|
+
if (!task) {
|
|
17302
|
+
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
|
|
17303
|
+
}
|
|
17304
|
+
if (!isTerminal(task.status)) {
|
|
17305
|
+
await this._waitForTaskUpdate(taskId, extra.signal);
|
|
17306
|
+
return await handleTaskResult();
|
|
17307
|
+
}
|
|
17308
|
+
if (isTerminal(task.status)) {
|
|
17309
|
+
const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
|
|
17310
|
+
this._clearTaskQueue(taskId);
|
|
17311
|
+
return {
|
|
17312
|
+
...result,
|
|
17313
|
+
_meta: {
|
|
17314
|
+
...result._meta,
|
|
17315
|
+
[RELATED_TASK_META_KEY]: {
|
|
17316
|
+
taskId
|
|
17317
|
+
}
|
|
17318
|
+
}
|
|
17319
|
+
};
|
|
17320
|
+
}
|
|
17321
|
+
return await handleTaskResult();
|
|
17322
|
+
};
|
|
17323
|
+
return await handleTaskResult();
|
|
17324
|
+
});
|
|
17325
|
+
this.setRequestHandler(ListTasksRequestSchema, async (request, extra) => {
|
|
17326
|
+
try {
|
|
17327
|
+
const { tasks, nextCursor } = await this._taskStore.listTasks(request.params?.cursor, extra.sessionId);
|
|
17328
|
+
return {
|
|
17329
|
+
tasks,
|
|
17330
|
+
nextCursor,
|
|
17331
|
+
_meta: {}
|
|
17332
|
+
};
|
|
17333
|
+
} catch (error) {
|
|
17334
|
+
throw new McpError(ErrorCode.InvalidParams, `Failed to list tasks: ${error instanceof Error ? error.message : String(error)}`);
|
|
17335
|
+
}
|
|
17336
|
+
});
|
|
17337
|
+
this.setRequestHandler(CancelTaskRequestSchema, async (request, extra) => {
|
|
17338
|
+
try {
|
|
17339
|
+
const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
17340
|
+
if (!task) {
|
|
17341
|
+
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${request.params.taskId}`);
|
|
17342
|
+
}
|
|
17343
|
+
if (isTerminal(task.status)) {
|
|
17344
|
+
throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
|
|
17345
|
+
}
|
|
17346
|
+
await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
|
|
17347
|
+
this._clearTaskQueue(request.params.taskId);
|
|
17348
|
+
const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
17349
|
+
if (!cancelledTask) {
|
|
17350
|
+
throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
|
|
17351
|
+
}
|
|
17352
|
+
return {
|
|
17353
|
+
_meta: {},
|
|
17354
|
+
...cancelledTask
|
|
17355
|
+
};
|
|
17356
|
+
} catch (error) {
|
|
17357
|
+
if (error instanceof McpError) {
|
|
17358
|
+
throw error;
|
|
17359
|
+
}
|
|
17360
|
+
throw new McpError(ErrorCode.InvalidRequest, `Failed to cancel task: ${error instanceof Error ? error.message : String(error)}`);
|
|
17361
|
+
}
|
|
17362
|
+
});
|
|
17363
|
+
}
|
|
17364
|
+
}
|
|
17365
|
+
async _oncancel(notification) {
|
|
17366
|
+
if (!notification.params.requestId) {
|
|
17367
|
+
return;
|
|
17368
|
+
}
|
|
17369
|
+
const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
|
|
17370
|
+
controller?.abort(notification.params.reason);
|
|
16921
17371
|
}
|
|
16922
17372
|
_setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
16923
17373
|
this._timeoutInfo.set(messageId, {
|
|
@@ -16958,22 +17408,21 @@ class Protocol {
|
|
|
16958
17408
|
* The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
|
|
16959
17409
|
*/
|
|
16960
17410
|
async connect(transport) {
|
|
16961
|
-
var _a, _b, _c;
|
|
16962
17411
|
this._transport = transport;
|
|
16963
|
-
const _onclose =
|
|
17412
|
+
const _onclose = this.transport?.onclose;
|
|
16964
17413
|
this._transport.onclose = () => {
|
|
16965
|
-
_onclose
|
|
17414
|
+
_onclose?.();
|
|
16966
17415
|
this._onclose();
|
|
16967
17416
|
};
|
|
16968
|
-
const _onerror =
|
|
17417
|
+
const _onerror = this.transport?.onerror;
|
|
16969
17418
|
this._transport.onerror = (error) => {
|
|
16970
|
-
_onerror
|
|
17419
|
+
_onerror?.(error);
|
|
16971
17420
|
this._onerror(error);
|
|
16972
17421
|
};
|
|
16973
|
-
const _onmessage =
|
|
17422
|
+
const _onmessage = this._transport?.onmessage;
|
|
16974
17423
|
this._transport.onmessage = (message, extra) => {
|
|
16975
|
-
_onmessage
|
|
16976
|
-
if (
|
|
17424
|
+
_onmessage?.(message, extra);
|
|
17425
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
16977
17426
|
this._onresponse(message);
|
|
16978
17427
|
} else if (isJSONRPCRequest(message)) {
|
|
16979
17428
|
this._onrequest(message, extra);
|
|
@@ -16986,80 +17435,131 @@ class Protocol {
|
|
|
16986
17435
|
await this._transport.start();
|
|
16987
17436
|
}
|
|
16988
17437
|
_onclose() {
|
|
16989
|
-
var _a;
|
|
16990
17438
|
const responseHandlers = this._responseHandlers;
|
|
16991
17439
|
this._responseHandlers = /* @__PURE__ */ new Map();
|
|
16992
17440
|
this._progressHandlers.clear();
|
|
17441
|
+
this._taskProgressTokens.clear();
|
|
16993
17442
|
this._pendingDebouncedNotifications.clear();
|
|
16994
|
-
this._transport = void 0;
|
|
16995
|
-
(_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
16996
17443
|
const error = McpError.fromError(ErrorCode.ConnectionClosed, "Connection closed");
|
|
17444
|
+
this._transport = void 0;
|
|
17445
|
+
this.onclose?.();
|
|
16997
17446
|
for (const handler of responseHandlers.values()) {
|
|
16998
17447
|
handler(error);
|
|
16999
17448
|
}
|
|
17000
17449
|
}
|
|
17001
17450
|
_onerror(error) {
|
|
17002
|
-
|
|
17003
|
-
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
17451
|
+
this.onerror?.(error);
|
|
17004
17452
|
}
|
|
17005
17453
|
_onnotification(notification) {
|
|
17006
|
-
|
|
17007
|
-
const handler = (_a = this._notificationHandlers.get(notification.method)) !== null && _a !== void 0 ? _a : this.fallbackNotificationHandler;
|
|
17454
|
+
const handler = this._notificationHandlers.get(notification.method) ?? this.fallbackNotificationHandler;
|
|
17008
17455
|
if (handler === void 0) {
|
|
17009
17456
|
return;
|
|
17010
17457
|
}
|
|
17011
17458
|
Promise.resolve().then(() => handler(notification)).catch((error) => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
|
|
17012
17459
|
}
|
|
17013
17460
|
_onrequest(request, extra) {
|
|
17014
|
-
|
|
17015
|
-
const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler;
|
|
17461
|
+
const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
|
|
17016
17462
|
const capturedTransport = this._transport;
|
|
17463
|
+
const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
|
|
17017
17464
|
if (handler === void 0) {
|
|
17018
|
-
|
|
17465
|
+
const errorResponse = {
|
|
17019
17466
|
jsonrpc: "2.0",
|
|
17020
17467
|
id: request.id,
|
|
17021
17468
|
error: {
|
|
17022
17469
|
code: ErrorCode.MethodNotFound,
|
|
17023
17470
|
message: "Method not found"
|
|
17024
17471
|
}
|
|
17025
|
-
}
|
|
17472
|
+
};
|
|
17473
|
+
if (relatedTaskId && this._taskMessageQueue) {
|
|
17474
|
+
this._enqueueTaskMessage(relatedTaskId, {
|
|
17475
|
+
type: "error",
|
|
17476
|
+
message: errorResponse,
|
|
17477
|
+
timestamp: Date.now()
|
|
17478
|
+
}, capturedTransport?.sessionId).catch((error) => this._onerror(new Error(`Failed to enqueue error response: ${error}`)));
|
|
17479
|
+
} else {
|
|
17480
|
+
capturedTransport?.send(errorResponse).catch((error) => this._onerror(new Error(`Failed to send an error response: ${error}`)));
|
|
17481
|
+
}
|
|
17026
17482
|
return;
|
|
17027
17483
|
}
|
|
17028
17484
|
const abortController = new AbortController();
|
|
17029
17485
|
this._requestHandlerAbortControllers.set(request.id, abortController);
|
|
17486
|
+
const taskCreationParams = isTaskAugmentedRequestParams(request.params) ? request.params.task : void 0;
|
|
17487
|
+
const taskStore = this._taskStore ? this.requestTaskStore(request, capturedTransport?.sessionId) : void 0;
|
|
17030
17488
|
const fullExtra = {
|
|
17031
17489
|
signal: abortController.signal,
|
|
17032
|
-
sessionId: capturedTransport
|
|
17033
|
-
_meta:
|
|
17034
|
-
sendNotification: (notification) =>
|
|
17035
|
-
|
|
17036
|
-
|
|
17490
|
+
sessionId: capturedTransport?.sessionId,
|
|
17491
|
+
_meta: request.params?._meta,
|
|
17492
|
+
sendNotification: async (notification) => {
|
|
17493
|
+
const notificationOptions = { relatedRequestId: request.id };
|
|
17494
|
+
if (relatedTaskId) {
|
|
17495
|
+
notificationOptions.relatedTask = { taskId: relatedTaskId };
|
|
17496
|
+
}
|
|
17497
|
+
await this.notification(notification, notificationOptions);
|
|
17498
|
+
},
|
|
17499
|
+
sendRequest: async (r, resultSchema, options) => {
|
|
17500
|
+
const requestOptions = { ...options, relatedRequestId: request.id };
|
|
17501
|
+
if (relatedTaskId && !requestOptions.relatedTask) {
|
|
17502
|
+
requestOptions.relatedTask = { taskId: relatedTaskId };
|
|
17503
|
+
}
|
|
17504
|
+
const effectiveTaskId = requestOptions.relatedTask?.taskId ?? relatedTaskId;
|
|
17505
|
+
if (effectiveTaskId && taskStore) {
|
|
17506
|
+
await taskStore.updateTaskStatus(effectiveTaskId, "input_required");
|
|
17507
|
+
}
|
|
17508
|
+
return await this.request(r, resultSchema, requestOptions);
|
|
17509
|
+
},
|
|
17510
|
+
authInfo: extra?.authInfo,
|
|
17037
17511
|
requestId: request.id,
|
|
17038
|
-
requestInfo: extra
|
|
17512
|
+
requestInfo: extra?.requestInfo,
|
|
17513
|
+
taskId: relatedTaskId,
|
|
17514
|
+
taskStore,
|
|
17515
|
+
taskRequestedTtl: taskCreationParams?.ttl,
|
|
17516
|
+
closeSSEStream: extra?.closeSSEStream,
|
|
17517
|
+
closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
|
|
17039
17518
|
};
|
|
17040
|
-
Promise.resolve().then(() =>
|
|
17519
|
+
Promise.resolve().then(() => {
|
|
17520
|
+
if (taskCreationParams) {
|
|
17521
|
+
this.assertTaskHandlerCapability(request.method);
|
|
17522
|
+
}
|
|
17523
|
+
}).then(() => handler(request, fullExtra)).then(async (result) => {
|
|
17041
17524
|
if (abortController.signal.aborted) {
|
|
17042
17525
|
return;
|
|
17043
17526
|
}
|
|
17044
|
-
|
|
17527
|
+
const response = {
|
|
17045
17528
|
result,
|
|
17046
17529
|
jsonrpc: "2.0",
|
|
17047
17530
|
id: request.id
|
|
17048
|
-
}
|
|
17049
|
-
|
|
17050
|
-
|
|
17531
|
+
};
|
|
17532
|
+
if (relatedTaskId && this._taskMessageQueue) {
|
|
17533
|
+
await this._enqueueTaskMessage(relatedTaskId, {
|
|
17534
|
+
type: "response",
|
|
17535
|
+
message: response,
|
|
17536
|
+
timestamp: Date.now()
|
|
17537
|
+
}, capturedTransport?.sessionId);
|
|
17538
|
+
} else {
|
|
17539
|
+
await capturedTransport?.send(response);
|
|
17540
|
+
}
|
|
17541
|
+
}, async (error) => {
|
|
17051
17542
|
if (abortController.signal.aborted) {
|
|
17052
17543
|
return;
|
|
17053
17544
|
}
|
|
17054
|
-
|
|
17545
|
+
const errorResponse = {
|
|
17055
17546
|
jsonrpc: "2.0",
|
|
17056
17547
|
id: request.id,
|
|
17057
17548
|
error: {
|
|
17058
17549
|
code: Number.isSafeInteger(error["code"]) ? error["code"] : ErrorCode.InternalError,
|
|
17059
|
-
message:
|
|
17550
|
+
message: error.message ?? "Internal error",
|
|
17060
17551
|
...error["data"] !== void 0 && { data: error["data"] }
|
|
17061
17552
|
}
|
|
17062
|
-
}
|
|
17553
|
+
};
|
|
17554
|
+
if (relatedTaskId && this._taskMessageQueue) {
|
|
17555
|
+
await this._enqueueTaskMessage(relatedTaskId, {
|
|
17556
|
+
type: "error",
|
|
17557
|
+
message: errorResponse,
|
|
17558
|
+
timestamp: Date.now()
|
|
17559
|
+
}, capturedTransport?.sessionId);
|
|
17560
|
+
} else {
|
|
17561
|
+
await capturedTransport?.send(errorResponse);
|
|
17562
|
+
}
|
|
17063
17563
|
}).catch((error) => this._onerror(new Error(`Failed to send response: ${error}`))).finally(() => {
|
|
17064
17564
|
this._requestHandlerAbortControllers.delete(request.id);
|
|
17065
17565
|
});
|
|
@@ -17078,6 +17578,9 @@ class Protocol {
|
|
|
17078
17578
|
try {
|
|
17079
17579
|
this._resetTimeout(messageId);
|
|
17080
17580
|
} catch (error) {
|
|
17581
|
+
this._responseHandlers.delete(messageId);
|
|
17582
|
+
this._progressHandlers.delete(messageId);
|
|
17583
|
+
this._cleanupTimeout(messageId);
|
|
17081
17584
|
responseHandler(error);
|
|
17082
17585
|
return;
|
|
17083
17586
|
}
|
|
@@ -17086,15 +17589,39 @@ class Protocol {
|
|
|
17086
17589
|
}
|
|
17087
17590
|
_onresponse(response) {
|
|
17088
17591
|
const messageId = Number(response.id);
|
|
17592
|
+
const resolver = this._requestResolvers.get(messageId);
|
|
17593
|
+
if (resolver) {
|
|
17594
|
+
this._requestResolvers.delete(messageId);
|
|
17595
|
+
if (isJSONRPCResultResponse(response)) {
|
|
17596
|
+
resolver(response);
|
|
17597
|
+
} else {
|
|
17598
|
+
const error = new McpError(response.error.code, response.error.message, response.error.data);
|
|
17599
|
+
resolver(error);
|
|
17600
|
+
}
|
|
17601
|
+
return;
|
|
17602
|
+
}
|
|
17089
17603
|
const handler = this._responseHandlers.get(messageId);
|
|
17090
17604
|
if (handler === void 0) {
|
|
17091
17605
|
this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`));
|
|
17092
17606
|
return;
|
|
17093
17607
|
}
|
|
17094
17608
|
this._responseHandlers.delete(messageId);
|
|
17095
|
-
this._progressHandlers.delete(messageId);
|
|
17096
17609
|
this._cleanupTimeout(messageId);
|
|
17097
|
-
|
|
17610
|
+
let isTaskResponse = false;
|
|
17611
|
+
if (isJSONRPCResultResponse(response) && response.result && typeof response.result === "object") {
|
|
17612
|
+
const result = response.result;
|
|
17613
|
+
if (result.task && typeof result.task === "object") {
|
|
17614
|
+
const task = result.task;
|
|
17615
|
+
if (typeof task.taskId === "string") {
|
|
17616
|
+
isTaskResponse = true;
|
|
17617
|
+
this._taskProgressTokens.set(task.taskId, messageId);
|
|
17618
|
+
}
|
|
17619
|
+
}
|
|
17620
|
+
}
|
|
17621
|
+
if (!isTaskResponse) {
|
|
17622
|
+
this._progressHandlers.delete(messageId);
|
|
17623
|
+
}
|
|
17624
|
+
if (isJSONRPCResultResponse(response)) {
|
|
17098
17625
|
handler(response);
|
|
17099
17626
|
} else {
|
|
17100
17627
|
const error = McpError.fromError(response.error.code, response.error.message, response.error.data);
|
|
@@ -17108,60 +17635,169 @@ class Protocol {
|
|
|
17108
17635
|
* Closes the connection.
|
|
17109
17636
|
*/
|
|
17110
17637
|
async close() {
|
|
17111
|
-
|
|
17112
|
-
await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.close());
|
|
17638
|
+
await this._transport?.close();
|
|
17113
17639
|
}
|
|
17114
17640
|
/**
|
|
17115
|
-
* Sends a request and
|
|
17641
|
+
* Sends a request and returns an AsyncGenerator that yields response messages.
|
|
17642
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
17643
|
+
*
|
|
17644
|
+
* @example
|
|
17645
|
+
* ```typescript
|
|
17646
|
+
* const stream = protocol.requestStream(request, resultSchema, options);
|
|
17647
|
+
* for await (const message of stream) {
|
|
17648
|
+
* switch (message.type) {
|
|
17649
|
+
* case 'taskCreated':
|
|
17650
|
+
* console.log('Task created:', message.task.taskId);
|
|
17651
|
+
* break;
|
|
17652
|
+
* case 'taskStatus':
|
|
17653
|
+
* console.log('Task status:', message.task.status);
|
|
17654
|
+
* break;
|
|
17655
|
+
* case 'result':
|
|
17656
|
+
* console.log('Final result:', message.result);
|
|
17657
|
+
* break;
|
|
17658
|
+
* case 'error':
|
|
17659
|
+
* console.error('Error:', message.error);
|
|
17660
|
+
* break;
|
|
17661
|
+
* }
|
|
17662
|
+
* }
|
|
17663
|
+
* ```
|
|
17664
|
+
*
|
|
17665
|
+
* @experimental Use `client.experimental.tasks.requestStream()` to access this method.
|
|
17666
|
+
*/
|
|
17667
|
+
async *requestStream(request, resultSchema, options) {
|
|
17668
|
+
const { task } = options ?? {};
|
|
17669
|
+
if (!task) {
|
|
17670
|
+
try {
|
|
17671
|
+
const result = await this.request(request, resultSchema, options);
|
|
17672
|
+
yield { type: "result", result };
|
|
17673
|
+
} catch (error) {
|
|
17674
|
+
yield {
|
|
17675
|
+
type: "error",
|
|
17676
|
+
error: error instanceof McpError ? error : new McpError(ErrorCode.InternalError, String(error))
|
|
17677
|
+
};
|
|
17678
|
+
}
|
|
17679
|
+
return;
|
|
17680
|
+
}
|
|
17681
|
+
let taskId;
|
|
17682
|
+
try {
|
|
17683
|
+
const createResult = await this.request(request, CreateTaskResultSchema, options);
|
|
17684
|
+
if (createResult.task) {
|
|
17685
|
+
taskId = createResult.task.taskId;
|
|
17686
|
+
yield { type: "taskCreated", task: createResult.task };
|
|
17687
|
+
} else {
|
|
17688
|
+
throw new McpError(ErrorCode.InternalError, "Task creation did not return a task");
|
|
17689
|
+
}
|
|
17690
|
+
while (true) {
|
|
17691
|
+
const task2 = await this.getTask({ taskId }, options);
|
|
17692
|
+
yield { type: "taskStatus", task: task2 };
|
|
17693
|
+
if (isTerminal(task2.status)) {
|
|
17694
|
+
if (task2.status === "completed") {
|
|
17695
|
+
const result = await this.getTaskResult({ taskId }, resultSchema, options);
|
|
17696
|
+
yield { type: "result", result };
|
|
17697
|
+
} else if (task2.status === "failed") {
|
|
17698
|
+
yield {
|
|
17699
|
+
type: "error",
|
|
17700
|
+
error: new McpError(ErrorCode.InternalError, `Task ${taskId} failed`)
|
|
17701
|
+
};
|
|
17702
|
+
} else if (task2.status === "cancelled") {
|
|
17703
|
+
yield {
|
|
17704
|
+
type: "error",
|
|
17705
|
+
error: new McpError(ErrorCode.InternalError, `Task ${taskId} was cancelled`)
|
|
17706
|
+
};
|
|
17707
|
+
}
|
|
17708
|
+
return;
|
|
17709
|
+
}
|
|
17710
|
+
if (task2.status === "input_required") {
|
|
17711
|
+
const result = await this.getTaskResult({ taskId }, resultSchema, options);
|
|
17712
|
+
yield { type: "result", result };
|
|
17713
|
+
return;
|
|
17714
|
+
}
|
|
17715
|
+
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
17716
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
17717
|
+
options?.signal?.throwIfAborted();
|
|
17718
|
+
}
|
|
17719
|
+
} catch (error) {
|
|
17720
|
+
yield {
|
|
17721
|
+
type: "error",
|
|
17722
|
+
error: error instanceof McpError ? error : new McpError(ErrorCode.InternalError, String(error))
|
|
17723
|
+
};
|
|
17724
|
+
}
|
|
17725
|
+
}
|
|
17726
|
+
/**
|
|
17727
|
+
* Sends a request and waits for a response.
|
|
17116
17728
|
*
|
|
17117
17729
|
* Do not use this method to emit notifications! Use notification() instead.
|
|
17118
17730
|
*/
|
|
17119
17731
|
request(request, resultSchema, options) {
|
|
17120
|
-
const { relatedRequestId, resumptionToken, onresumptiontoken } = options
|
|
17732
|
+
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
17121
17733
|
return new Promise((resolve2, reject) => {
|
|
17122
|
-
|
|
17734
|
+
const earlyReject = (error) => {
|
|
17735
|
+
reject(error);
|
|
17736
|
+
};
|
|
17123
17737
|
if (!this._transport) {
|
|
17124
|
-
|
|
17738
|
+
earlyReject(new Error("Not connected"));
|
|
17125
17739
|
return;
|
|
17126
17740
|
}
|
|
17127
|
-
if (
|
|
17128
|
-
|
|
17741
|
+
if (this._options?.enforceStrictCapabilities === true) {
|
|
17742
|
+
try {
|
|
17743
|
+
this.assertCapabilityForMethod(request.method);
|
|
17744
|
+
if (task) {
|
|
17745
|
+
this.assertTaskCapability(request.method);
|
|
17746
|
+
}
|
|
17747
|
+
} catch (e) {
|
|
17748
|
+
earlyReject(e);
|
|
17749
|
+
return;
|
|
17750
|
+
}
|
|
17129
17751
|
}
|
|
17130
|
-
|
|
17752
|
+
options?.signal?.throwIfAborted();
|
|
17131
17753
|
const messageId = this._requestMessageId++;
|
|
17132
17754
|
const jsonrpcRequest = {
|
|
17133
17755
|
...request,
|
|
17134
17756
|
jsonrpc: "2.0",
|
|
17135
17757
|
id: messageId
|
|
17136
17758
|
};
|
|
17137
|
-
if (options
|
|
17759
|
+
if (options?.onprogress) {
|
|
17138
17760
|
this._progressHandlers.set(messageId, options.onprogress);
|
|
17139
17761
|
jsonrpcRequest.params = {
|
|
17140
17762
|
...request.params,
|
|
17141
17763
|
_meta: {
|
|
17142
|
-
...
|
|
17764
|
+
...request.params?._meta || {},
|
|
17143
17765
|
progressToken: messageId
|
|
17144
17766
|
}
|
|
17145
17767
|
};
|
|
17146
17768
|
}
|
|
17769
|
+
if (task) {
|
|
17770
|
+
jsonrpcRequest.params = {
|
|
17771
|
+
...jsonrpcRequest.params,
|
|
17772
|
+
task
|
|
17773
|
+
};
|
|
17774
|
+
}
|
|
17775
|
+
if (relatedTask) {
|
|
17776
|
+
jsonrpcRequest.params = {
|
|
17777
|
+
...jsonrpcRequest.params,
|
|
17778
|
+
_meta: {
|
|
17779
|
+
...jsonrpcRequest.params?._meta || {},
|
|
17780
|
+
[RELATED_TASK_META_KEY]: relatedTask
|
|
17781
|
+
}
|
|
17782
|
+
};
|
|
17783
|
+
}
|
|
17147
17784
|
const cancel = (reason) => {
|
|
17148
|
-
var _a2;
|
|
17149
17785
|
this._responseHandlers.delete(messageId);
|
|
17150
17786
|
this._progressHandlers.delete(messageId);
|
|
17151
17787
|
this._cleanupTimeout(messageId);
|
|
17152
|
-
|
|
17788
|
+
this._transport?.send({
|
|
17153
17789
|
jsonrpc: "2.0",
|
|
17154
17790
|
method: "notifications/cancelled",
|
|
17155
17791
|
params: {
|
|
17156
17792
|
requestId: messageId,
|
|
17157
17793
|
reason: String(reason)
|
|
17158
17794
|
}
|
|
17159
|
-
}, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((
|
|
17160
|
-
|
|
17795
|
+
}, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error2) => this._onerror(new Error(`Failed to send cancellation: ${error2}`)));
|
|
17796
|
+
const error = reason instanceof McpError ? reason : new McpError(ErrorCode.RequestTimeout, String(reason));
|
|
17797
|
+
reject(error);
|
|
17161
17798
|
};
|
|
17162
17799
|
this._responseHandlers.set(messageId, (response) => {
|
|
17163
|
-
|
|
17164
|
-
if ((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.aborted) {
|
|
17800
|
+
if (options?.signal?.aborted) {
|
|
17165
17801
|
return;
|
|
17166
17802
|
}
|
|
17167
17803
|
if (response instanceof Error) {
|
|
@@ -17178,53 +17814,147 @@ class Protocol {
|
|
|
17178
17814
|
reject(error);
|
|
17179
17815
|
}
|
|
17180
17816
|
});
|
|
17181
|
-
|
|
17182
|
-
|
|
17183
|
-
cancel((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.reason);
|
|
17817
|
+
options?.signal?.addEventListener("abort", () => {
|
|
17818
|
+
cancel(options?.signal?.reason);
|
|
17184
17819
|
});
|
|
17185
|
-
const timeout =
|
|
17820
|
+
const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
17186
17821
|
const timeoutHandler = () => cancel(McpError.fromError(ErrorCode.RequestTimeout, "Request timed out", { timeout }));
|
|
17187
|
-
this._setupTimeout(messageId, timeout, options
|
|
17188
|
-
|
|
17189
|
-
|
|
17190
|
-
|
|
17191
|
-
|
|
17822
|
+
this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
|
|
17823
|
+
const relatedTaskId = relatedTask?.taskId;
|
|
17824
|
+
if (relatedTaskId) {
|
|
17825
|
+
const responseResolver = (response) => {
|
|
17826
|
+
const handler = this._responseHandlers.get(messageId);
|
|
17827
|
+
if (handler) {
|
|
17828
|
+
handler(response);
|
|
17829
|
+
} else {
|
|
17830
|
+
this._onerror(new Error(`Response handler missing for side-channeled request ${messageId}`));
|
|
17831
|
+
}
|
|
17832
|
+
};
|
|
17833
|
+
this._requestResolvers.set(messageId, responseResolver);
|
|
17834
|
+
this._enqueueTaskMessage(relatedTaskId, {
|
|
17835
|
+
type: "request",
|
|
17836
|
+
message: jsonrpcRequest,
|
|
17837
|
+
timestamp: Date.now()
|
|
17838
|
+
}).catch((error) => {
|
|
17839
|
+
this._cleanupTimeout(messageId);
|
|
17840
|
+
reject(error);
|
|
17841
|
+
});
|
|
17842
|
+
} else {
|
|
17843
|
+
this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error) => {
|
|
17844
|
+
this._cleanupTimeout(messageId);
|
|
17845
|
+
reject(error);
|
|
17846
|
+
});
|
|
17847
|
+
}
|
|
17192
17848
|
});
|
|
17193
17849
|
}
|
|
17850
|
+
/**
|
|
17851
|
+
* Gets the current status of a task.
|
|
17852
|
+
*
|
|
17853
|
+
* @experimental Use `client.experimental.tasks.getTask()` to access this method.
|
|
17854
|
+
*/
|
|
17855
|
+
async getTask(params, options) {
|
|
17856
|
+
return this.request({ method: "tasks/get", params }, GetTaskResultSchema, options);
|
|
17857
|
+
}
|
|
17858
|
+
/**
|
|
17859
|
+
* Retrieves the result of a completed task.
|
|
17860
|
+
*
|
|
17861
|
+
* @experimental Use `client.experimental.tasks.getTaskResult()` to access this method.
|
|
17862
|
+
*/
|
|
17863
|
+
async getTaskResult(params, resultSchema, options) {
|
|
17864
|
+
return this.request({ method: "tasks/result", params }, resultSchema, options);
|
|
17865
|
+
}
|
|
17866
|
+
/**
|
|
17867
|
+
* Lists tasks, optionally starting from a pagination cursor.
|
|
17868
|
+
*
|
|
17869
|
+
* @experimental Use `client.experimental.tasks.listTasks()` to access this method.
|
|
17870
|
+
*/
|
|
17871
|
+
async listTasks(params, options) {
|
|
17872
|
+
return this.request({ method: "tasks/list", params }, ListTasksResultSchema, options);
|
|
17873
|
+
}
|
|
17874
|
+
/**
|
|
17875
|
+
* Cancels a specific task.
|
|
17876
|
+
*
|
|
17877
|
+
* @experimental Use `client.experimental.tasks.cancelTask()` to access this method.
|
|
17878
|
+
*/
|
|
17879
|
+
async cancelTask(params, options) {
|
|
17880
|
+
return this.request({ method: "tasks/cancel", params }, CancelTaskResultSchema, options);
|
|
17881
|
+
}
|
|
17194
17882
|
/**
|
|
17195
17883
|
* Emits a notification, which is a one-way message that does not expect a response.
|
|
17196
17884
|
*/
|
|
17197
17885
|
async notification(notification, options) {
|
|
17198
|
-
var _a, _b;
|
|
17199
17886
|
if (!this._transport) {
|
|
17200
17887
|
throw new Error("Not connected");
|
|
17201
17888
|
}
|
|
17202
17889
|
this.assertNotificationCapability(notification.method);
|
|
17203
|
-
const
|
|
17204
|
-
|
|
17890
|
+
const relatedTaskId = options?.relatedTask?.taskId;
|
|
17891
|
+
if (relatedTaskId) {
|
|
17892
|
+
const jsonrpcNotification2 = {
|
|
17893
|
+
...notification,
|
|
17894
|
+
jsonrpc: "2.0",
|
|
17895
|
+
params: {
|
|
17896
|
+
...notification.params,
|
|
17897
|
+
_meta: {
|
|
17898
|
+
...notification.params?._meta || {},
|
|
17899
|
+
[RELATED_TASK_META_KEY]: options.relatedTask
|
|
17900
|
+
}
|
|
17901
|
+
}
|
|
17902
|
+
};
|
|
17903
|
+
await this._enqueueTaskMessage(relatedTaskId, {
|
|
17904
|
+
type: "notification",
|
|
17905
|
+
message: jsonrpcNotification2,
|
|
17906
|
+
timestamp: Date.now()
|
|
17907
|
+
});
|
|
17908
|
+
return;
|
|
17909
|
+
}
|
|
17910
|
+
const debouncedMethods = this._options?.debouncedNotificationMethods ?? [];
|
|
17911
|
+
const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !options?.relatedRequestId && !options?.relatedTask;
|
|
17205
17912
|
if (canDebounce) {
|
|
17206
17913
|
if (this._pendingDebouncedNotifications.has(notification.method)) {
|
|
17207
17914
|
return;
|
|
17208
17915
|
}
|
|
17209
17916
|
this._pendingDebouncedNotifications.add(notification.method);
|
|
17210
17917
|
Promise.resolve().then(() => {
|
|
17211
|
-
var _a2;
|
|
17212
17918
|
this._pendingDebouncedNotifications.delete(notification.method);
|
|
17213
17919
|
if (!this._transport) {
|
|
17214
17920
|
return;
|
|
17215
17921
|
}
|
|
17216
|
-
|
|
17922
|
+
let jsonrpcNotification2 = {
|
|
17217
17923
|
...notification,
|
|
17218
17924
|
jsonrpc: "2.0"
|
|
17219
17925
|
};
|
|
17220
|
-
|
|
17926
|
+
if (options?.relatedTask) {
|
|
17927
|
+
jsonrpcNotification2 = {
|
|
17928
|
+
...jsonrpcNotification2,
|
|
17929
|
+
params: {
|
|
17930
|
+
...jsonrpcNotification2.params,
|
|
17931
|
+
_meta: {
|
|
17932
|
+
...jsonrpcNotification2.params?._meta || {},
|
|
17933
|
+
[RELATED_TASK_META_KEY]: options.relatedTask
|
|
17934
|
+
}
|
|
17935
|
+
}
|
|
17936
|
+
};
|
|
17937
|
+
}
|
|
17938
|
+
this._transport?.send(jsonrpcNotification2, options).catch((error) => this._onerror(error));
|
|
17221
17939
|
});
|
|
17222
17940
|
return;
|
|
17223
17941
|
}
|
|
17224
|
-
|
|
17942
|
+
let jsonrpcNotification = {
|
|
17225
17943
|
...notification,
|
|
17226
17944
|
jsonrpc: "2.0"
|
|
17227
17945
|
};
|
|
17946
|
+
if (options?.relatedTask) {
|
|
17947
|
+
jsonrpcNotification = {
|
|
17948
|
+
...jsonrpcNotification,
|
|
17949
|
+
params: {
|
|
17950
|
+
...jsonrpcNotification.params,
|
|
17951
|
+
_meta: {
|
|
17952
|
+
...jsonrpcNotification.params?._meta || {},
|
|
17953
|
+
[RELATED_TASK_META_KEY]: options.relatedTask
|
|
17954
|
+
}
|
|
17955
|
+
}
|
|
17956
|
+
};
|
|
17957
|
+
}
|
|
17228
17958
|
await this._transport.send(jsonrpcNotification, options);
|
|
17229
17959
|
}
|
|
17230
17960
|
/**
|
|
@@ -17272,6 +18002,150 @@ class Protocol {
|
|
|
17272
18002
|
removeNotificationHandler(method) {
|
|
17273
18003
|
this._notificationHandlers.delete(method);
|
|
17274
18004
|
}
|
|
18005
|
+
/**
|
|
18006
|
+
* Cleans up the progress handler associated with a task.
|
|
18007
|
+
* This should be called when a task reaches a terminal status.
|
|
18008
|
+
*/
|
|
18009
|
+
_cleanupTaskProgressHandler(taskId) {
|
|
18010
|
+
const progressToken = this._taskProgressTokens.get(taskId);
|
|
18011
|
+
if (progressToken !== void 0) {
|
|
18012
|
+
this._progressHandlers.delete(progressToken);
|
|
18013
|
+
this._taskProgressTokens.delete(taskId);
|
|
18014
|
+
}
|
|
18015
|
+
}
|
|
18016
|
+
/**
|
|
18017
|
+
* Enqueues a task-related message for side-channel delivery via tasks/result.
|
|
18018
|
+
* @param taskId The task ID to associate the message with
|
|
18019
|
+
* @param message The message to enqueue
|
|
18020
|
+
* @param sessionId Optional session ID for binding the operation to a specific session
|
|
18021
|
+
* @throws Error if taskStore is not configured or if enqueue fails (e.g., queue overflow)
|
|
18022
|
+
*
|
|
18023
|
+
* Note: If enqueue fails, it's the TaskMessageQueue implementation's responsibility to handle
|
|
18024
|
+
* the error appropriately (e.g., by failing the task, logging, etc.). The Protocol layer
|
|
18025
|
+
* simply propagates the error.
|
|
18026
|
+
*/
|
|
18027
|
+
async _enqueueTaskMessage(taskId, message, sessionId) {
|
|
18028
|
+
if (!this._taskStore || !this._taskMessageQueue) {
|
|
18029
|
+
throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
|
|
18030
|
+
}
|
|
18031
|
+
const maxQueueSize = this._options?.maxTaskQueueSize;
|
|
18032
|
+
await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
|
|
18033
|
+
}
|
|
18034
|
+
/**
|
|
18035
|
+
* Clears the message queue for a task and rejects any pending request resolvers.
|
|
18036
|
+
* @param taskId The task ID whose queue should be cleared
|
|
18037
|
+
* @param sessionId Optional session ID for binding the operation to a specific session
|
|
18038
|
+
*/
|
|
18039
|
+
async _clearTaskQueue(taskId, sessionId) {
|
|
18040
|
+
if (this._taskMessageQueue) {
|
|
18041
|
+
const messages = await this._taskMessageQueue.dequeueAll(taskId, sessionId);
|
|
18042
|
+
for (const message of messages) {
|
|
18043
|
+
if (message.type === "request" && isJSONRPCRequest(message.message)) {
|
|
18044
|
+
const requestId = message.message.id;
|
|
18045
|
+
const resolver = this._requestResolvers.get(requestId);
|
|
18046
|
+
if (resolver) {
|
|
18047
|
+
resolver(new McpError(ErrorCode.InternalError, "Task cancelled or completed"));
|
|
18048
|
+
this._requestResolvers.delete(requestId);
|
|
18049
|
+
} else {
|
|
18050
|
+
this._onerror(new Error(`Resolver missing for request ${requestId} during task ${taskId} cleanup`));
|
|
18051
|
+
}
|
|
18052
|
+
}
|
|
18053
|
+
}
|
|
18054
|
+
}
|
|
18055
|
+
}
|
|
18056
|
+
/**
|
|
18057
|
+
* Waits for a task update (new messages or status change) with abort signal support.
|
|
18058
|
+
* Uses polling to check for updates at the task's configured poll interval.
|
|
18059
|
+
* @param taskId The task ID to wait for
|
|
18060
|
+
* @param signal Abort signal to cancel the wait
|
|
18061
|
+
* @returns Promise that resolves when an update occurs or rejects if aborted
|
|
18062
|
+
*/
|
|
18063
|
+
async _waitForTaskUpdate(taskId, signal) {
|
|
18064
|
+
let interval = this._options?.defaultTaskPollInterval ?? 1e3;
|
|
18065
|
+
try {
|
|
18066
|
+
const task = await this._taskStore?.getTask(taskId);
|
|
18067
|
+
if (task?.pollInterval) {
|
|
18068
|
+
interval = task.pollInterval;
|
|
18069
|
+
}
|
|
18070
|
+
} catch {
|
|
18071
|
+
}
|
|
18072
|
+
return new Promise((resolve2, reject) => {
|
|
18073
|
+
if (signal.aborted) {
|
|
18074
|
+
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
18075
|
+
return;
|
|
18076
|
+
}
|
|
18077
|
+
const timeoutId = setTimeout(resolve2, interval);
|
|
18078
|
+
signal.addEventListener("abort", () => {
|
|
18079
|
+
clearTimeout(timeoutId);
|
|
18080
|
+
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
18081
|
+
}, { once: true });
|
|
18082
|
+
});
|
|
18083
|
+
}
|
|
18084
|
+
requestTaskStore(request, sessionId) {
|
|
18085
|
+
const taskStore = this._taskStore;
|
|
18086
|
+
if (!taskStore) {
|
|
18087
|
+
throw new Error("No task store configured");
|
|
18088
|
+
}
|
|
18089
|
+
return {
|
|
18090
|
+
createTask: async (taskParams) => {
|
|
18091
|
+
if (!request) {
|
|
18092
|
+
throw new Error("No request provided");
|
|
18093
|
+
}
|
|
18094
|
+
return await taskStore.createTask(taskParams, request.id, {
|
|
18095
|
+
method: request.method,
|
|
18096
|
+
params: request.params
|
|
18097
|
+
}, sessionId);
|
|
18098
|
+
},
|
|
18099
|
+
getTask: async (taskId) => {
|
|
18100
|
+
const task = await taskStore.getTask(taskId, sessionId);
|
|
18101
|
+
if (!task) {
|
|
18102
|
+
throw new McpError(ErrorCode.InvalidParams, "Failed to retrieve task: Task not found");
|
|
18103
|
+
}
|
|
18104
|
+
return task;
|
|
18105
|
+
},
|
|
18106
|
+
storeTaskResult: async (taskId, status, result) => {
|
|
18107
|
+
await taskStore.storeTaskResult(taskId, status, result, sessionId);
|
|
18108
|
+
const task = await taskStore.getTask(taskId, sessionId);
|
|
18109
|
+
if (task) {
|
|
18110
|
+
const notification = TaskStatusNotificationSchema.parse({
|
|
18111
|
+
method: "notifications/tasks/status",
|
|
18112
|
+
params: task
|
|
18113
|
+
});
|
|
18114
|
+
await this.notification(notification);
|
|
18115
|
+
if (isTerminal(task.status)) {
|
|
18116
|
+
this._cleanupTaskProgressHandler(taskId);
|
|
18117
|
+
}
|
|
18118
|
+
}
|
|
18119
|
+
},
|
|
18120
|
+
getTaskResult: (taskId) => {
|
|
18121
|
+
return taskStore.getTaskResult(taskId, sessionId);
|
|
18122
|
+
},
|
|
18123
|
+
updateTaskStatus: async (taskId, status, statusMessage) => {
|
|
18124
|
+
const task = await taskStore.getTask(taskId, sessionId);
|
|
18125
|
+
if (!task) {
|
|
18126
|
+
throw new McpError(ErrorCode.InvalidParams, `Task "${taskId}" not found - it may have been cleaned up`);
|
|
18127
|
+
}
|
|
18128
|
+
if (isTerminal(task.status)) {
|
|
18129
|
+
throw new McpError(ErrorCode.InvalidParams, `Cannot update task "${taskId}" from terminal status "${task.status}" to "${status}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);
|
|
18130
|
+
}
|
|
18131
|
+
await taskStore.updateTaskStatus(taskId, status, statusMessage, sessionId);
|
|
18132
|
+
const updatedTask = await taskStore.getTask(taskId, sessionId);
|
|
18133
|
+
if (updatedTask) {
|
|
18134
|
+
const notification = TaskStatusNotificationSchema.parse({
|
|
18135
|
+
method: "notifications/tasks/status",
|
|
18136
|
+
params: updatedTask
|
|
18137
|
+
});
|
|
18138
|
+
await this.notification(notification);
|
|
18139
|
+
if (isTerminal(updatedTask.status)) {
|
|
18140
|
+
this._cleanupTaskProgressHandler(taskId);
|
|
18141
|
+
}
|
|
18142
|
+
}
|
|
18143
|
+
},
|
|
18144
|
+
listTasks: (cursor) => {
|
|
18145
|
+
return taskStore.listTasks(cursor, sessionId);
|
|
18146
|
+
}
|
|
18147
|
+
};
|
|
18148
|
+
}
|
|
17275
18149
|
}
|
|
17276
18150
|
function isPlainObject(value) {
|
|
17277
18151
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -17618,7 +18492,7 @@ function requireDist() {
|
|
|
17618
18492
|
var distExports = requireDist();
|
|
17619
18493
|
const _addFormats = /* @__PURE__ */ getDefaultExportFromCjs(distExports);
|
|
17620
18494
|
function createDefaultAjvInstance() {
|
|
17621
|
-
const ajv2 = new
|
|
18495
|
+
const ajv2 = new Ajv({
|
|
17622
18496
|
strict: false,
|
|
17623
18497
|
validateFormats: true,
|
|
17624
18498
|
validateSchema: false,
|
|
@@ -17650,7 +18524,7 @@ class AjvJsonSchemaValidator {
|
|
|
17650
18524
|
* ```
|
|
17651
18525
|
*/
|
|
17652
18526
|
constructor(ajv2) {
|
|
17653
|
-
this._ajv = ajv2
|
|
18527
|
+
this._ajv = ajv2 ?? createDefaultAjvInstance();
|
|
17654
18528
|
}
|
|
17655
18529
|
/**
|
|
17656
18530
|
* Create a validator for the given JSON Schema
|
|
@@ -17662,8 +18536,7 @@ class AjvJsonSchemaValidator {
|
|
|
17662
18536
|
* @returns A validator function that validates input data
|
|
17663
18537
|
*/
|
|
17664
18538
|
getValidator(schema) {
|
|
17665
|
-
|
|
17666
|
-
const ajvValidator = "$id" in schema && typeof schema.$id === "string" ? (_a = this._ajv.getSchema(schema.$id)) !== null && _a !== void 0 ? _a : this._ajv.compile(schema) : this._ajv.compile(schema);
|
|
18539
|
+
const ajvValidator = "$id" in schema && typeof schema.$id === "string" ? this._ajv.getSchema(schema.$id) ?? this._ajv.compile(schema) : this._ajv.compile(schema);
|
|
17667
18540
|
return (input) => {
|
|
17668
18541
|
const valid = ajvValidator(input);
|
|
17669
18542
|
if (valid) {
|
|
@@ -17682,6 +18555,187 @@ class AjvJsonSchemaValidator {
|
|
|
17682
18555
|
};
|
|
17683
18556
|
}
|
|
17684
18557
|
}
|
|
18558
|
+
class ExperimentalClientTasks {
|
|
18559
|
+
constructor(_client) {
|
|
18560
|
+
this._client = _client;
|
|
18561
|
+
}
|
|
18562
|
+
/**
|
|
18563
|
+
* Calls a tool and returns an AsyncGenerator that yields response messages.
|
|
18564
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
18565
|
+
*
|
|
18566
|
+
* This method provides streaming access to tool execution, allowing you to
|
|
18567
|
+
* observe intermediate task status updates for long-running tool calls.
|
|
18568
|
+
* Automatically validates structured output if the tool has an outputSchema.
|
|
18569
|
+
*
|
|
18570
|
+
* @example
|
|
18571
|
+
* ```typescript
|
|
18572
|
+
* const stream = client.experimental.tasks.callToolStream({ name: 'myTool', arguments: {} });
|
|
18573
|
+
* for await (const message of stream) {
|
|
18574
|
+
* switch (message.type) {
|
|
18575
|
+
* case 'taskCreated':
|
|
18576
|
+
* console.log('Tool execution started:', message.task.taskId);
|
|
18577
|
+
* break;
|
|
18578
|
+
* case 'taskStatus':
|
|
18579
|
+
* console.log('Tool status:', message.task.status);
|
|
18580
|
+
* break;
|
|
18581
|
+
* case 'result':
|
|
18582
|
+
* console.log('Tool result:', message.result);
|
|
18583
|
+
* break;
|
|
18584
|
+
* case 'error':
|
|
18585
|
+
* console.error('Tool error:', message.error);
|
|
18586
|
+
* break;
|
|
18587
|
+
* }
|
|
18588
|
+
* }
|
|
18589
|
+
* ```
|
|
18590
|
+
*
|
|
18591
|
+
* @param params - Tool call parameters (name and arguments)
|
|
18592
|
+
* @param resultSchema - Zod schema for validating the result (defaults to CallToolResultSchema)
|
|
18593
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
18594
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
18595
|
+
*
|
|
18596
|
+
* @experimental
|
|
18597
|
+
*/
|
|
18598
|
+
async *callToolStream(params, resultSchema = CallToolResultSchema, options) {
|
|
18599
|
+
const clientInternal = this._client;
|
|
18600
|
+
const optionsWithTask = {
|
|
18601
|
+
...options,
|
|
18602
|
+
// We check if the tool is known to be a task during auto-configuration, but assume
|
|
18603
|
+
// the caller knows what they're doing if they pass this explicitly
|
|
18604
|
+
task: options?.task ?? (clientInternal.isToolTask(params.name) ? {} : void 0)
|
|
18605
|
+
};
|
|
18606
|
+
const stream = clientInternal.requestStream({ method: "tools/call", params }, resultSchema, optionsWithTask);
|
|
18607
|
+
const validator = clientInternal.getToolOutputValidator(params.name);
|
|
18608
|
+
for await (const message of stream) {
|
|
18609
|
+
if (message.type === "result" && validator) {
|
|
18610
|
+
const result = message.result;
|
|
18611
|
+
if (!result.structuredContent && !result.isError) {
|
|
18612
|
+
yield {
|
|
18613
|
+
type: "error",
|
|
18614
|
+
error: new McpError(ErrorCode.InvalidRequest, `Tool ${params.name} has an output schema but did not return structured content`)
|
|
18615
|
+
};
|
|
18616
|
+
return;
|
|
18617
|
+
}
|
|
18618
|
+
if (result.structuredContent) {
|
|
18619
|
+
try {
|
|
18620
|
+
const validationResult = validator(result.structuredContent);
|
|
18621
|
+
if (!validationResult.valid) {
|
|
18622
|
+
yield {
|
|
18623
|
+
type: "error",
|
|
18624
|
+
error: new McpError(ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`)
|
|
18625
|
+
};
|
|
18626
|
+
return;
|
|
18627
|
+
}
|
|
18628
|
+
} catch (error) {
|
|
18629
|
+
if (error instanceof McpError) {
|
|
18630
|
+
yield { type: "error", error };
|
|
18631
|
+
return;
|
|
18632
|
+
}
|
|
18633
|
+
yield {
|
|
18634
|
+
type: "error",
|
|
18635
|
+
error: new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`)
|
|
18636
|
+
};
|
|
18637
|
+
return;
|
|
18638
|
+
}
|
|
18639
|
+
}
|
|
18640
|
+
}
|
|
18641
|
+
yield message;
|
|
18642
|
+
}
|
|
18643
|
+
}
|
|
18644
|
+
/**
|
|
18645
|
+
* Gets the current status of a task.
|
|
18646
|
+
*
|
|
18647
|
+
* @param taskId - The task identifier
|
|
18648
|
+
* @param options - Optional request options
|
|
18649
|
+
* @returns The task status
|
|
18650
|
+
*
|
|
18651
|
+
* @experimental
|
|
18652
|
+
*/
|
|
18653
|
+
async getTask(taskId, options) {
|
|
18654
|
+
return this._client.getTask({ taskId }, options);
|
|
18655
|
+
}
|
|
18656
|
+
/**
|
|
18657
|
+
* Retrieves the result of a completed task.
|
|
18658
|
+
*
|
|
18659
|
+
* @param taskId - The task identifier
|
|
18660
|
+
* @param resultSchema - Zod schema for validating the result
|
|
18661
|
+
* @param options - Optional request options
|
|
18662
|
+
* @returns The task result
|
|
18663
|
+
*
|
|
18664
|
+
* @experimental
|
|
18665
|
+
*/
|
|
18666
|
+
async getTaskResult(taskId, resultSchema, options) {
|
|
18667
|
+
return this._client.getTaskResult({ taskId }, resultSchema, options);
|
|
18668
|
+
}
|
|
18669
|
+
/**
|
|
18670
|
+
* Lists tasks with optional pagination.
|
|
18671
|
+
*
|
|
18672
|
+
* @param cursor - Optional pagination cursor
|
|
18673
|
+
* @param options - Optional request options
|
|
18674
|
+
* @returns List of tasks with optional next cursor
|
|
18675
|
+
*
|
|
18676
|
+
* @experimental
|
|
18677
|
+
*/
|
|
18678
|
+
async listTasks(cursor, options) {
|
|
18679
|
+
return this._client.listTasks(cursor ? { cursor } : void 0, options);
|
|
18680
|
+
}
|
|
18681
|
+
/**
|
|
18682
|
+
* Cancels a running task.
|
|
18683
|
+
*
|
|
18684
|
+
* @param taskId - The task identifier
|
|
18685
|
+
* @param options - Optional request options
|
|
18686
|
+
*
|
|
18687
|
+
* @experimental
|
|
18688
|
+
*/
|
|
18689
|
+
async cancelTask(taskId, options) {
|
|
18690
|
+
return this._client.cancelTask({ taskId }, options);
|
|
18691
|
+
}
|
|
18692
|
+
/**
|
|
18693
|
+
* Sends a request and returns an AsyncGenerator that yields response messages.
|
|
18694
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
18695
|
+
*
|
|
18696
|
+
* This method provides streaming access to request processing, allowing you to
|
|
18697
|
+
* observe intermediate task status updates for task-augmented requests.
|
|
18698
|
+
*
|
|
18699
|
+
* @param request - The request to send
|
|
18700
|
+
* @param resultSchema - Zod schema for validating the result
|
|
18701
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
18702
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
18703
|
+
*
|
|
18704
|
+
* @experimental
|
|
18705
|
+
*/
|
|
18706
|
+
requestStream(request, resultSchema, options) {
|
|
18707
|
+
return this._client.requestStream(request, resultSchema, options);
|
|
18708
|
+
}
|
|
18709
|
+
}
|
|
18710
|
+
function assertToolsCallTaskCapability(requests, method, entityName) {
|
|
18711
|
+
if (!requests) {
|
|
18712
|
+
throw new Error(`${entityName} does not support task creation (required for ${method})`);
|
|
18713
|
+
}
|
|
18714
|
+
switch (method) {
|
|
18715
|
+
case "tools/call":
|
|
18716
|
+
if (!requests.tools?.call) {
|
|
18717
|
+
throw new Error(`${entityName} does not support task creation for tools/call (required for ${method})`);
|
|
18718
|
+
}
|
|
18719
|
+
break;
|
|
18720
|
+
}
|
|
18721
|
+
}
|
|
18722
|
+
function assertClientRequestTaskCapability(requests, method, entityName) {
|
|
18723
|
+
if (!requests) {
|
|
18724
|
+
throw new Error(`${entityName} does not support task creation (required for ${method})`);
|
|
18725
|
+
}
|
|
18726
|
+
switch (method) {
|
|
18727
|
+
case "sampling/createMessage":
|
|
18728
|
+
if (!requests.sampling?.createMessage) {
|
|
18729
|
+
throw new Error(`${entityName} does not support task creation for sampling/createMessage (required for ${method})`);
|
|
18730
|
+
}
|
|
18731
|
+
break;
|
|
18732
|
+
case "elicitation/create":
|
|
18733
|
+
if (!requests.elicitation?.create) {
|
|
18734
|
+
throw new Error(`${entityName} does not support task creation for elicitation/create (required for ${method})`);
|
|
18735
|
+
}
|
|
18736
|
+
break;
|
|
18737
|
+
}
|
|
18738
|
+
}
|
|
17685
18739
|
function applyElicitationDefaults(schema, data) {
|
|
17686
18740
|
if (!schema || data === null || typeof data !== "object")
|
|
17687
18741
|
return;
|
|
@@ -17700,12 +18754,16 @@ function applyElicitationDefaults(schema, data) {
|
|
|
17700
18754
|
}
|
|
17701
18755
|
if (Array.isArray(schema.anyOf)) {
|
|
17702
18756
|
for (const sub of schema.anyOf) {
|
|
17703
|
-
|
|
18757
|
+
if (typeof sub !== "boolean") {
|
|
18758
|
+
applyElicitationDefaults(sub, data);
|
|
18759
|
+
}
|
|
17704
18760
|
}
|
|
17705
18761
|
}
|
|
17706
18762
|
if (Array.isArray(schema.oneOf)) {
|
|
17707
18763
|
for (const sub of schema.oneOf) {
|
|
17708
|
-
|
|
18764
|
+
if (typeof sub !== "boolean") {
|
|
18765
|
+
applyElicitationDefaults(sub, data);
|
|
18766
|
+
}
|
|
17709
18767
|
}
|
|
17710
18768
|
}
|
|
17711
18769
|
}
|
|
@@ -17724,12 +18782,58 @@ class Client extends Protocol {
|
|
|
17724
18782
|
* Initializes this client with the given name and version information.
|
|
17725
18783
|
*/
|
|
17726
18784
|
constructor(_clientInfo, options) {
|
|
17727
|
-
var _a, _b;
|
|
17728
18785
|
super(options);
|
|
17729
18786
|
this._clientInfo = _clientInfo;
|
|
17730
18787
|
this._cachedToolOutputValidators = /* @__PURE__ */ new Map();
|
|
17731
|
-
this.
|
|
17732
|
-
this.
|
|
18788
|
+
this._cachedKnownTaskTools = /* @__PURE__ */ new Set();
|
|
18789
|
+
this._cachedRequiredTaskTools = /* @__PURE__ */ new Set();
|
|
18790
|
+
this._listChangedDebounceTimers = /* @__PURE__ */ new Map();
|
|
18791
|
+
this._capabilities = options?.capabilities ?? {};
|
|
18792
|
+
this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new AjvJsonSchemaValidator();
|
|
18793
|
+
if (options?.listChanged) {
|
|
18794
|
+
this._pendingListChangedConfig = options.listChanged;
|
|
18795
|
+
}
|
|
18796
|
+
}
|
|
18797
|
+
/**
|
|
18798
|
+
* Set up handlers for list changed notifications based on config and server capabilities.
|
|
18799
|
+
* This should only be called after initialization when server capabilities are known.
|
|
18800
|
+
* Handlers are silently skipped if the server doesn't advertise the corresponding listChanged capability.
|
|
18801
|
+
* @internal
|
|
18802
|
+
*/
|
|
18803
|
+
_setupListChangedHandlers(config2) {
|
|
18804
|
+
if (config2.tools && this._serverCapabilities?.tools?.listChanged) {
|
|
18805
|
+
this._setupListChangedHandler("tools", ToolListChangedNotificationSchema, config2.tools, async () => {
|
|
18806
|
+
const result = await this.listTools();
|
|
18807
|
+
return result.tools;
|
|
18808
|
+
});
|
|
18809
|
+
}
|
|
18810
|
+
if (config2.prompts && this._serverCapabilities?.prompts?.listChanged) {
|
|
18811
|
+
this._setupListChangedHandler("prompts", PromptListChangedNotificationSchema, config2.prompts, async () => {
|
|
18812
|
+
const result = await this.listPrompts();
|
|
18813
|
+
return result.prompts;
|
|
18814
|
+
});
|
|
18815
|
+
}
|
|
18816
|
+
if (config2.resources && this._serverCapabilities?.resources?.listChanged) {
|
|
18817
|
+
this._setupListChangedHandler("resources", ResourceListChangedNotificationSchema, config2.resources, async () => {
|
|
18818
|
+
const result = await this.listResources();
|
|
18819
|
+
return result.resources;
|
|
18820
|
+
});
|
|
18821
|
+
}
|
|
18822
|
+
}
|
|
18823
|
+
/**
|
|
18824
|
+
* Access experimental features.
|
|
18825
|
+
*
|
|
18826
|
+
* WARNING: These APIs are experimental and may change without notice.
|
|
18827
|
+
*
|
|
18828
|
+
* @experimental
|
|
18829
|
+
*/
|
|
18830
|
+
get experimental() {
|
|
18831
|
+
if (!this._experimental) {
|
|
18832
|
+
this._experimental = {
|
|
18833
|
+
tasks: new ExperimentalClientTasks(this)
|
|
18834
|
+
};
|
|
18835
|
+
}
|
|
18836
|
+
return this._experimental;
|
|
17733
18837
|
}
|
|
17734
18838
|
/**
|
|
17735
18839
|
* Registers new capabilities. This can only be called before connecting to a transport.
|
|
@@ -17746,21 +18850,20 @@ class Client extends Protocol {
|
|
|
17746
18850
|
* Override request handler registration to enforce client-side validation for elicitation.
|
|
17747
18851
|
*/
|
|
17748
18852
|
setRequestHandler(requestSchema, handler) {
|
|
17749
|
-
var _a, _b, _c;
|
|
17750
18853
|
const shape = getObjectShape(requestSchema);
|
|
17751
|
-
const methodSchema = shape
|
|
18854
|
+
const methodSchema = shape?.method;
|
|
17752
18855
|
if (!methodSchema) {
|
|
17753
18856
|
throw new Error("Schema is missing a method literal");
|
|
17754
18857
|
}
|
|
17755
18858
|
let methodValue;
|
|
17756
18859
|
if (isZ4Schema(methodSchema)) {
|
|
17757
18860
|
const v4Schema = methodSchema;
|
|
17758
|
-
const v4Def =
|
|
17759
|
-
methodValue =
|
|
18861
|
+
const v4Def = v4Schema._zod?.def;
|
|
18862
|
+
methodValue = v4Def?.value ?? v4Schema.value;
|
|
17760
18863
|
} else {
|
|
17761
18864
|
const v3Schema = methodSchema;
|
|
17762
18865
|
const legacyDef = v3Schema._def;
|
|
17763
|
-
methodValue =
|
|
18866
|
+
methodValue = legacyDef?.value ?? v3Schema.value;
|
|
17764
18867
|
}
|
|
17765
18868
|
if (typeof methodValue !== "string") {
|
|
17766
18869
|
throw new Error("Schema method literal must be a string");
|
|
@@ -17768,34 +18871,41 @@ class Client extends Protocol {
|
|
|
17768
18871
|
const method = methodValue;
|
|
17769
18872
|
if (method === "elicitation/create") {
|
|
17770
18873
|
const wrappedHandler = async (request, extra) => {
|
|
17771
|
-
var _a2, _b2, _c2;
|
|
17772
18874
|
const validatedRequest = safeParse(ElicitRequestSchema, request);
|
|
17773
18875
|
if (!validatedRequest.success) {
|
|
17774
18876
|
const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
17775
18877
|
throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation request: ${errorMessage}`);
|
|
17776
18878
|
}
|
|
17777
18879
|
const { params } = validatedRequest.data;
|
|
17778
|
-
|
|
18880
|
+
params.mode = params.mode ?? "form";
|
|
17779
18881
|
const { supportsFormMode, supportsUrlMode } = getSupportedElicitationModes(this._capabilities.elicitation);
|
|
17780
|
-
if (mode === "form" && !supportsFormMode) {
|
|
18882
|
+
if (params.mode === "form" && !supportsFormMode) {
|
|
17781
18883
|
throw new McpError(ErrorCode.InvalidParams, "Client does not support form-mode elicitation requests");
|
|
17782
18884
|
}
|
|
17783
|
-
if (mode === "url" && !supportsUrlMode) {
|
|
18885
|
+
if (params.mode === "url" && !supportsUrlMode) {
|
|
17784
18886
|
throw new McpError(ErrorCode.InvalidParams, "Client does not support URL-mode elicitation requests");
|
|
17785
18887
|
}
|
|
17786
18888
|
const result = await Promise.resolve(handler(request, extra));
|
|
18889
|
+
if (params.task) {
|
|
18890
|
+
const taskValidationResult = safeParse(CreateTaskResultSchema, result);
|
|
18891
|
+
if (!taskValidationResult.success) {
|
|
18892
|
+
const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
18893
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
|
|
18894
|
+
}
|
|
18895
|
+
return taskValidationResult.data;
|
|
18896
|
+
}
|
|
17787
18897
|
const validationResult = safeParse(ElicitResultSchema, result);
|
|
17788
18898
|
if (!validationResult.success) {
|
|
17789
18899
|
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
17790
18900
|
throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation result: ${errorMessage}`);
|
|
17791
18901
|
}
|
|
17792
18902
|
const validatedResult = validationResult.data;
|
|
17793
|
-
const requestedSchema = mode === "form" ? params.requestedSchema : void 0;
|
|
17794
|
-
if (mode === "form" && validatedResult.action === "accept" && validatedResult.content && requestedSchema) {
|
|
17795
|
-
if (
|
|
18903
|
+
const requestedSchema = params.mode === "form" ? params.requestedSchema : void 0;
|
|
18904
|
+
if (params.mode === "form" && validatedResult.action === "accept" && validatedResult.content && requestedSchema) {
|
|
18905
|
+
if (this._capabilities.elicitation?.form?.applyDefaults) {
|
|
17796
18906
|
try {
|
|
17797
18907
|
applyElicitationDefaults(requestedSchema, validatedResult.content);
|
|
17798
|
-
} catch
|
|
18908
|
+
} catch {
|
|
17799
18909
|
}
|
|
17800
18910
|
}
|
|
17801
18911
|
}
|
|
@@ -17803,11 +18913,36 @@ class Client extends Protocol {
|
|
|
17803
18913
|
};
|
|
17804
18914
|
return super.setRequestHandler(requestSchema, wrappedHandler);
|
|
17805
18915
|
}
|
|
18916
|
+
if (method === "sampling/createMessage") {
|
|
18917
|
+
const wrappedHandler = async (request, extra) => {
|
|
18918
|
+
const validatedRequest = safeParse(CreateMessageRequestSchema, request);
|
|
18919
|
+
if (!validatedRequest.success) {
|
|
18920
|
+
const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
18921
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling request: ${errorMessage}`);
|
|
18922
|
+
}
|
|
18923
|
+
const { params } = validatedRequest.data;
|
|
18924
|
+
const result = await Promise.resolve(handler(request, extra));
|
|
18925
|
+
if (params.task) {
|
|
18926
|
+
const taskValidationResult = safeParse(CreateTaskResultSchema, result);
|
|
18927
|
+
if (!taskValidationResult.success) {
|
|
18928
|
+
const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
18929
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
|
|
18930
|
+
}
|
|
18931
|
+
return taskValidationResult.data;
|
|
18932
|
+
}
|
|
18933
|
+
const validationResult = safeParse(CreateMessageResultSchema, result);
|
|
18934
|
+
if (!validationResult.success) {
|
|
18935
|
+
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
18936
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling result: ${errorMessage}`);
|
|
18937
|
+
}
|
|
18938
|
+
return validationResult.data;
|
|
18939
|
+
};
|
|
18940
|
+
return super.setRequestHandler(requestSchema, wrappedHandler);
|
|
18941
|
+
}
|
|
17806
18942
|
return super.setRequestHandler(requestSchema, handler);
|
|
17807
18943
|
}
|
|
17808
18944
|
assertCapability(capability, method) {
|
|
17809
|
-
|
|
17810
|
-
if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a[capability])) {
|
|
18945
|
+
if (!this._serverCapabilities?.[capability]) {
|
|
17811
18946
|
throw new Error(`Server does not support ${capability} (required for ${method})`);
|
|
17812
18947
|
}
|
|
17813
18948
|
}
|
|
@@ -17840,6 +18975,10 @@ class Client extends Protocol {
|
|
|
17840
18975
|
await this.notification({
|
|
17841
18976
|
method: "notifications/initialized"
|
|
17842
18977
|
});
|
|
18978
|
+
if (this._pendingListChangedConfig) {
|
|
18979
|
+
this._setupListChangedHandlers(this._pendingListChangedConfig);
|
|
18980
|
+
this._pendingListChangedConfig = void 0;
|
|
18981
|
+
}
|
|
17843
18982
|
} catch (error) {
|
|
17844
18983
|
void this.close();
|
|
17845
18984
|
throw error;
|
|
@@ -17864,16 +19003,15 @@ class Client extends Protocol {
|
|
|
17864
19003
|
return this._instructions;
|
|
17865
19004
|
}
|
|
17866
19005
|
assertCapabilityForMethod(method) {
|
|
17867
|
-
var _a, _b, _c, _d, _e;
|
|
17868
19006
|
switch (method) {
|
|
17869
19007
|
case "logging/setLevel":
|
|
17870
|
-
if (!
|
|
19008
|
+
if (!this._serverCapabilities?.logging) {
|
|
17871
19009
|
throw new Error(`Server does not support logging (required for ${method})`);
|
|
17872
19010
|
}
|
|
17873
19011
|
break;
|
|
17874
19012
|
case "prompts/get":
|
|
17875
19013
|
case "prompts/list":
|
|
17876
|
-
if (!
|
|
19014
|
+
if (!this._serverCapabilities?.prompts) {
|
|
17877
19015
|
throw new Error(`Server does not support prompts (required for ${method})`);
|
|
17878
19016
|
}
|
|
17879
19017
|
break;
|
|
@@ -17882,7 +19020,7 @@ class Client extends Protocol {
|
|
|
17882
19020
|
case "resources/read":
|
|
17883
19021
|
case "resources/subscribe":
|
|
17884
19022
|
case "resources/unsubscribe":
|
|
17885
|
-
if (!
|
|
19023
|
+
if (!this._serverCapabilities?.resources) {
|
|
17886
19024
|
throw new Error(`Server does not support resources (required for ${method})`);
|
|
17887
19025
|
}
|
|
17888
19026
|
if (method === "resources/subscribe" && !this._serverCapabilities.resources.subscribe) {
|
|
@@ -17891,28 +19029,30 @@ class Client extends Protocol {
|
|
|
17891
19029
|
break;
|
|
17892
19030
|
case "tools/call":
|
|
17893
19031
|
case "tools/list":
|
|
17894
|
-
if (!
|
|
19032
|
+
if (!this._serverCapabilities?.tools) {
|
|
17895
19033
|
throw new Error(`Server does not support tools (required for ${method})`);
|
|
17896
19034
|
}
|
|
17897
19035
|
break;
|
|
17898
19036
|
case "completion/complete":
|
|
17899
|
-
if (!
|
|
19037
|
+
if (!this._serverCapabilities?.completions) {
|
|
17900
19038
|
throw new Error(`Server does not support completions (required for ${method})`);
|
|
17901
19039
|
}
|
|
17902
19040
|
break;
|
|
17903
19041
|
}
|
|
17904
19042
|
}
|
|
17905
19043
|
assertNotificationCapability(method) {
|
|
17906
|
-
var _a;
|
|
17907
19044
|
switch (method) {
|
|
17908
19045
|
case "notifications/roots/list_changed":
|
|
17909
|
-
if (!
|
|
19046
|
+
if (!this._capabilities.roots?.listChanged) {
|
|
17910
19047
|
throw new Error(`Client does not support roots list changed notifications (required for ${method})`);
|
|
17911
19048
|
}
|
|
17912
19049
|
break;
|
|
17913
19050
|
}
|
|
17914
19051
|
}
|
|
17915
19052
|
assertRequestHandlerCapability(method) {
|
|
19053
|
+
if (!this._capabilities) {
|
|
19054
|
+
return;
|
|
19055
|
+
}
|
|
17916
19056
|
switch (method) {
|
|
17917
19057
|
case "sampling/createMessage":
|
|
17918
19058
|
if (!this._capabilities.sampling) {
|
|
@@ -17929,7 +19069,24 @@ class Client extends Protocol {
|
|
|
17929
19069
|
throw new Error(`Client does not support roots capability (required for ${method})`);
|
|
17930
19070
|
}
|
|
17931
19071
|
break;
|
|
19072
|
+
case "tasks/get":
|
|
19073
|
+
case "tasks/list":
|
|
19074
|
+
case "tasks/result":
|
|
19075
|
+
case "tasks/cancel":
|
|
19076
|
+
if (!this._capabilities.tasks) {
|
|
19077
|
+
throw new Error(`Client does not support tasks capability (required for ${method})`);
|
|
19078
|
+
}
|
|
19079
|
+
break;
|
|
19080
|
+
}
|
|
19081
|
+
}
|
|
19082
|
+
assertTaskCapability(method) {
|
|
19083
|
+
assertToolsCallTaskCapability(this._serverCapabilities?.tasks?.requests, method, "Server");
|
|
19084
|
+
}
|
|
19085
|
+
assertTaskHandlerCapability(method) {
|
|
19086
|
+
if (!this._capabilities) {
|
|
19087
|
+
return;
|
|
17932
19088
|
}
|
|
19089
|
+
assertClientRequestTaskCapability(this._capabilities.tasks?.requests, method, "Client");
|
|
17933
19090
|
}
|
|
17934
19091
|
async ping(options) {
|
|
17935
19092
|
return this.request({ method: "ping" }, EmptyResultSchema, options);
|
|
@@ -17961,7 +19118,15 @@ class Client extends Protocol {
|
|
|
17961
19118
|
async unsubscribeResource(params, options) {
|
|
17962
19119
|
return this.request({ method: "resources/unsubscribe", params }, EmptyResultSchema, options);
|
|
17963
19120
|
}
|
|
19121
|
+
/**
|
|
19122
|
+
* Calls a tool and waits for the result. Automatically validates structured output if the tool has an outputSchema.
|
|
19123
|
+
*
|
|
19124
|
+
* For task-based execution with streaming behavior, use client.experimental.tasks.callToolStream() instead.
|
|
19125
|
+
*/
|
|
17964
19126
|
async callTool(params, resultSchema = CallToolResultSchema, options) {
|
|
19127
|
+
if (this.isToolTaskRequired(params.name)) {
|
|
19128
|
+
throw new McpError(ErrorCode.InvalidRequest, `Tool "${params.name}" requires task-based execution. Use client.experimental.tasks.callToolStream() instead.`);
|
|
19129
|
+
}
|
|
17965
19130
|
const result = await this.request({ method: "tools/call", params }, resultSchema, options);
|
|
17966
19131
|
const validator = this.getToolOutputValidator(params.name);
|
|
17967
19132
|
if (validator) {
|
|
@@ -17984,17 +19149,39 @@ class Client extends Protocol {
|
|
|
17984
19149
|
}
|
|
17985
19150
|
return result;
|
|
17986
19151
|
}
|
|
19152
|
+
isToolTask(toolName) {
|
|
19153
|
+
if (!this._serverCapabilities?.tasks?.requests?.tools?.call) {
|
|
19154
|
+
return false;
|
|
19155
|
+
}
|
|
19156
|
+
return this._cachedKnownTaskTools.has(toolName);
|
|
19157
|
+
}
|
|
19158
|
+
/**
|
|
19159
|
+
* Check if a tool requires task-based execution.
|
|
19160
|
+
* Unlike isToolTask which includes 'optional' tools, this only checks for 'required'.
|
|
19161
|
+
*/
|
|
19162
|
+
isToolTaskRequired(toolName) {
|
|
19163
|
+
return this._cachedRequiredTaskTools.has(toolName);
|
|
19164
|
+
}
|
|
17987
19165
|
/**
|
|
17988
19166
|
* Cache validators for tool output schemas.
|
|
17989
19167
|
* Called after listTools() to pre-compile validators for better performance.
|
|
17990
19168
|
*/
|
|
17991
|
-
|
|
19169
|
+
cacheToolMetadata(tools) {
|
|
17992
19170
|
this._cachedToolOutputValidators.clear();
|
|
19171
|
+
this._cachedKnownTaskTools.clear();
|
|
19172
|
+
this._cachedRequiredTaskTools.clear();
|
|
17993
19173
|
for (const tool of tools) {
|
|
17994
19174
|
if (tool.outputSchema) {
|
|
17995
19175
|
const toolValidator = this._jsonSchemaValidator.getValidator(tool.outputSchema);
|
|
17996
19176
|
this._cachedToolOutputValidators.set(tool.name, toolValidator);
|
|
17997
19177
|
}
|
|
19178
|
+
const taskSupport = tool.execution?.taskSupport;
|
|
19179
|
+
if (taskSupport === "required" || taskSupport === "optional") {
|
|
19180
|
+
this._cachedKnownTaskTools.add(tool.name);
|
|
19181
|
+
}
|
|
19182
|
+
if (taskSupport === "required") {
|
|
19183
|
+
this._cachedRequiredTaskTools.add(tool.name);
|
|
19184
|
+
}
|
|
17998
19185
|
}
|
|
17999
19186
|
}
|
|
18000
19187
|
/**
|
|
@@ -18005,9 +19192,50 @@ class Client extends Protocol {
|
|
|
18005
19192
|
}
|
|
18006
19193
|
async listTools(params, options) {
|
|
18007
19194
|
const result = await this.request({ method: "tools/list", params }, ListToolsResultSchema, options);
|
|
18008
|
-
this.
|
|
19195
|
+
this.cacheToolMetadata(result.tools);
|
|
18009
19196
|
return result;
|
|
18010
19197
|
}
|
|
19198
|
+
/**
|
|
19199
|
+
* Set up a single list changed handler.
|
|
19200
|
+
* @internal
|
|
19201
|
+
*/
|
|
19202
|
+
_setupListChangedHandler(listType, notificationSchema, options, fetcher) {
|
|
19203
|
+
const parseResult = ListChangedOptionsBaseSchema.safeParse(options);
|
|
19204
|
+
if (!parseResult.success) {
|
|
19205
|
+
throw new Error(`Invalid ${listType} listChanged options: ${parseResult.error.message}`);
|
|
19206
|
+
}
|
|
19207
|
+
if (typeof options.onChanged !== "function") {
|
|
19208
|
+
throw new Error(`Invalid ${listType} listChanged options: onChanged must be a function`);
|
|
19209
|
+
}
|
|
19210
|
+
const { autoRefresh, debounceMs } = parseResult.data;
|
|
19211
|
+
const { onChanged } = options;
|
|
19212
|
+
const refresh = async () => {
|
|
19213
|
+
if (!autoRefresh) {
|
|
19214
|
+
onChanged(null, null);
|
|
19215
|
+
return;
|
|
19216
|
+
}
|
|
19217
|
+
try {
|
|
19218
|
+
const items2 = await fetcher();
|
|
19219
|
+
onChanged(null, items2);
|
|
19220
|
+
} catch (e) {
|
|
19221
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
19222
|
+
onChanged(error, null);
|
|
19223
|
+
}
|
|
19224
|
+
};
|
|
19225
|
+
const handler = () => {
|
|
19226
|
+
if (debounceMs) {
|
|
19227
|
+
const existingTimer = this._listChangedDebounceTimers.get(listType);
|
|
19228
|
+
if (existingTimer) {
|
|
19229
|
+
clearTimeout(existingTimer);
|
|
19230
|
+
}
|
|
19231
|
+
const timer = setTimeout(refresh, debounceMs);
|
|
19232
|
+
this._listChangedDebounceTimers.set(listType, timer);
|
|
19233
|
+
} else {
|
|
19234
|
+
refresh();
|
|
19235
|
+
}
|
|
19236
|
+
};
|
|
19237
|
+
this.setNotificationHandler(notificationSchema, handler);
|
|
19238
|
+
}
|
|
18011
19239
|
async sendRootsListChanged() {
|
|
18012
19240
|
return this.notification({ method: "notifications/roots/list_changed" });
|
|
18013
19241
|
}
|
|
@@ -18181,8 +19409,8 @@ const OAuthClientMetadataSchema = object$1({
|
|
|
18181
19409
|
const OAuthClientInformationSchema = object$1({
|
|
18182
19410
|
client_id: string(),
|
|
18183
19411
|
client_secret: string().optional(),
|
|
18184
|
-
client_id_issued_at: number().optional(),
|
|
18185
|
-
client_secret_expires_at: number().optional()
|
|
19412
|
+
client_id_issued_at: number$1().optional(),
|
|
19413
|
+
client_secret_expires_at: number$1().optional()
|
|
18186
19414
|
}).strip();
|
|
18187
19415
|
const OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
|
|
18188
19416
|
object$1({
|
|
@@ -18282,6 +19510,9 @@ InvalidClientMetadataError.errorCode = "invalid_client_metadata";
|
|
|
18282
19510
|
class InsufficientScopeError extends OAuthError {
|
|
18283
19511
|
}
|
|
18284
19512
|
InsufficientScopeError.errorCode = "insufficient_scope";
|
|
19513
|
+
class InvalidTargetError extends OAuthError {
|
|
19514
|
+
}
|
|
19515
|
+
InvalidTargetError.errorCode = "invalid_target";
|
|
18285
19516
|
const OAUTH_ERRORS = {
|
|
18286
19517
|
[InvalidRequestError.errorCode]: InvalidRequestError,
|
|
18287
19518
|
[InvalidClientError.errorCode]: InvalidClientError,
|
|
@@ -18298,11 +19529,12 @@ const OAUTH_ERRORS = {
|
|
|
18298
19529
|
[MethodNotAllowedError.errorCode]: MethodNotAllowedError,
|
|
18299
19530
|
[TooManyRequestsError.errorCode]: TooManyRequestsError,
|
|
18300
19531
|
[InvalidClientMetadataError.errorCode]: InvalidClientMetadataError,
|
|
18301
|
-
[InsufficientScopeError.errorCode]: InsufficientScopeError
|
|
19532
|
+
[InsufficientScopeError.errorCode]: InsufficientScopeError,
|
|
19533
|
+
[InvalidTargetError.errorCode]: InvalidTargetError
|
|
18302
19534
|
};
|
|
18303
19535
|
class UnauthorizedError extends Error {
|
|
18304
19536
|
constructor(message) {
|
|
18305
|
-
super(message
|
|
19537
|
+
super(message ?? "Unauthorized");
|
|
18306
19538
|
}
|
|
18307
19539
|
}
|
|
18308
19540
|
function isClientAuthMethod(method) {
|
|
@@ -18375,22 +19607,20 @@ async function parseErrorResponse(input) {
|
|
|
18375
19607
|
}
|
|
18376
19608
|
}
|
|
18377
19609
|
async function auth(provider, options) {
|
|
18378
|
-
var _a, _b;
|
|
18379
19610
|
try {
|
|
18380
19611
|
return await authInternal(provider, options);
|
|
18381
19612
|
} catch (error) {
|
|
18382
19613
|
if (error instanceof InvalidClientError || error instanceof UnauthorizedClientError) {
|
|
18383
|
-
await
|
|
19614
|
+
await provider.invalidateCredentials?.("all");
|
|
18384
19615
|
return await authInternal(provider, options);
|
|
18385
19616
|
} else if (error instanceof InvalidGrantError) {
|
|
18386
|
-
await
|
|
19617
|
+
await provider.invalidateCredentials?.("tokens");
|
|
18387
19618
|
return await authInternal(provider, options);
|
|
18388
19619
|
}
|
|
18389
19620
|
throw error;
|
|
18390
19621
|
}
|
|
18391
19622
|
}
|
|
18392
19623
|
async function authInternal(provider, { serverUrl, authorizationCode, scope: scope2, resourceMetadataUrl, fetchFn }) {
|
|
18393
|
-
var _a, _b;
|
|
18394
19624
|
let resourceMetadata;
|
|
18395
19625
|
let authorizationServerUrl;
|
|
18396
19626
|
try {
|
|
@@ -18398,7 +19628,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope: sco
|
|
|
18398
19628
|
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
|
|
18399
19629
|
authorizationServerUrl = resourceMetadata.authorization_servers[0];
|
|
18400
19630
|
}
|
|
18401
|
-
} catch
|
|
19631
|
+
} catch {
|
|
18402
19632
|
}
|
|
18403
19633
|
if (!authorizationServerUrl) {
|
|
18404
19634
|
authorizationServerUrl = new URL("/", serverUrl);
|
|
@@ -18412,7 +19642,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope: sco
|
|
|
18412
19642
|
if (authorizationCode !== void 0) {
|
|
18413
19643
|
throw new Error("Existing OAuth client information is required when exchanging an authorization code");
|
|
18414
19644
|
}
|
|
18415
|
-
const supportsUrlBasedClientId =
|
|
19645
|
+
const supportsUrlBasedClientId = metadata2?.client_id_metadata_document_supported === true;
|
|
18416
19646
|
const clientMetadataUrl = provider.clientMetadataUrl;
|
|
18417
19647
|
if (clientMetadataUrl && !isHttpsUrl(clientMetadataUrl)) {
|
|
18418
19648
|
throw new InvalidClientMetadataError(`clientMetadataUrl must be a valid HTTPS URL with a non-root pathname, got: ${clientMetadataUrl}`);
|
|
@@ -18422,7 +19652,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope: sco
|
|
|
18422
19652
|
clientInformation = {
|
|
18423
19653
|
client_id: clientMetadataUrl
|
|
18424
19654
|
};
|
|
18425
|
-
await
|
|
19655
|
+
await provider.saveClientInformation?.(clientInformation);
|
|
18426
19656
|
} else {
|
|
18427
19657
|
if (!provider.saveClientInformation) {
|
|
18428
19658
|
throw new Error("OAuth client information must be saveable for dynamic registration");
|
|
@@ -18436,23 +19666,19 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope: sco
|
|
|
18436
19666
|
clientInformation = fullInformation;
|
|
18437
19667
|
}
|
|
18438
19668
|
}
|
|
18439
|
-
|
|
18440
|
-
|
|
18441
|
-
const tokens2 = await
|
|
19669
|
+
const nonInteractiveFlow = !provider.redirectUrl;
|
|
19670
|
+
if (authorizationCode !== void 0 || nonInteractiveFlow) {
|
|
19671
|
+
const tokens2 = await fetchToken(provider, authorizationServerUrl, {
|
|
18442
19672
|
metadata: metadata2,
|
|
18443
|
-
clientInformation,
|
|
18444
|
-
authorizationCode,
|
|
18445
|
-
codeVerifier: codeVerifier2,
|
|
18446
|
-
redirectUri: provider.redirectUrl,
|
|
18447
19673
|
resource,
|
|
18448
|
-
|
|
19674
|
+
authorizationCode,
|
|
18449
19675
|
fetchFn
|
|
18450
19676
|
});
|
|
18451
19677
|
await provider.saveTokens(tokens2);
|
|
18452
19678
|
return "AUTHORIZED";
|
|
18453
19679
|
}
|
|
18454
19680
|
const tokens = await provider.tokens();
|
|
18455
|
-
if (tokens
|
|
19681
|
+
if (tokens?.refresh_token) {
|
|
18456
19682
|
try {
|
|
18457
19683
|
const newTokens = await refreshAuthorization(authorizationServerUrl, {
|
|
18458
19684
|
metadata: metadata2,
|
|
@@ -18477,7 +19703,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope: sco
|
|
|
18477
19703
|
clientInformation,
|
|
18478
19704
|
state,
|
|
18479
19705
|
redirectUrl: provider.redirectUrl,
|
|
18480
|
-
scope: scope2 ||
|
|
19706
|
+
scope: scope2 || resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope,
|
|
18481
19707
|
resource
|
|
18482
19708
|
});
|
|
18483
19709
|
await provider.saveCodeVerifier(codeVerifier);
|
|
@@ -18490,14 +19716,14 @@ function isHttpsUrl(value) {
|
|
|
18490
19716
|
try {
|
|
18491
19717
|
const url2 = new URL(value);
|
|
18492
19718
|
return url2.protocol === "https:" && url2.pathname !== "/";
|
|
18493
|
-
} catch
|
|
19719
|
+
} catch {
|
|
18494
19720
|
return false;
|
|
18495
19721
|
}
|
|
18496
19722
|
}
|
|
18497
19723
|
async function selectResourceURL(serverUrl, provider, resourceMetadata) {
|
|
18498
19724
|
const defaultResource = resourceUrlFromServerUrl(serverUrl);
|
|
18499
19725
|
if (provider.validateResourceURL) {
|
|
18500
|
-
return await provider.validateResourceURL(defaultResource, resourceMetadata
|
|
19726
|
+
return await provider.validateResourceURL(defaultResource, resourceMetadata?.resource);
|
|
18501
19727
|
}
|
|
18502
19728
|
if (!resourceMetadata) {
|
|
18503
19729
|
return void 0;
|
|
@@ -18521,7 +19747,7 @@ function extractWWWAuthenticateParams(res) {
|
|
|
18521
19747
|
if (resourceMetadataMatch) {
|
|
18522
19748
|
try {
|
|
18523
19749
|
resourceMetadataUrl = new URL(resourceMetadataMatch);
|
|
18524
|
-
} catch
|
|
19750
|
+
} catch {
|
|
18525
19751
|
}
|
|
18526
19752
|
}
|
|
18527
19753
|
const scope2 = extractFieldFromWwwAuth(res, "scope") || void 0;
|
|
@@ -18560,19 +19786,21 @@ function extractResourceMetadataUrl(res) {
|
|
|
18560
19786
|
}
|
|
18561
19787
|
try {
|
|
18562
19788
|
return new URL(match[1]);
|
|
18563
|
-
} catch
|
|
19789
|
+
} catch {
|
|
18564
19790
|
return void 0;
|
|
18565
19791
|
}
|
|
18566
19792
|
}
|
|
18567
19793
|
async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn = fetch) {
|
|
18568
19794
|
const response = await discoverMetadataWithFallback(serverUrl, "oauth-protected-resource", fetchFn, {
|
|
18569
|
-
protocolVersion: opts
|
|
18570
|
-
metadataUrl: opts
|
|
19795
|
+
protocolVersion: opts?.protocolVersion,
|
|
19796
|
+
metadataUrl: opts?.resourceMetadataUrl
|
|
18571
19797
|
});
|
|
18572
19798
|
if (!response || response.status === 404) {
|
|
19799
|
+
await response?.body?.cancel();
|
|
18573
19800
|
throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);
|
|
18574
19801
|
}
|
|
18575
19802
|
if (!response.ok) {
|
|
19803
|
+
await response.body?.cancel();
|
|
18576
19804
|
throw new Error(`HTTP ${response.status} trying to load well-known OAuth protected resource metadata.`);
|
|
18577
19805
|
}
|
|
18578
19806
|
return OAuthProtectedResourceMetadataSchema.parse(await response.json());
|
|
@@ -18607,19 +19835,18 @@ function shouldAttemptFallback(response, pathname) {
|
|
|
18607
19835
|
return !response || response.status >= 400 && response.status < 500 && pathname !== "/";
|
|
18608
19836
|
}
|
|
18609
19837
|
async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
|
|
18610
|
-
var _a, _b;
|
|
18611
19838
|
const issuer = new URL(serverUrl);
|
|
18612
|
-
const protocolVersion =
|
|
19839
|
+
const protocolVersion = opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION;
|
|
18613
19840
|
let url2;
|
|
18614
|
-
if (opts
|
|
19841
|
+
if (opts?.metadataUrl) {
|
|
18615
19842
|
url2 = new URL(opts.metadataUrl);
|
|
18616
19843
|
} else {
|
|
18617
19844
|
const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname);
|
|
18618
|
-
url2 = new URL(wellKnownPath,
|
|
19845
|
+
url2 = new URL(wellKnownPath, opts?.metadataServerUrl ?? issuer);
|
|
18619
19846
|
url2.search = issuer.search;
|
|
18620
19847
|
}
|
|
18621
19848
|
let response = await tryMetadataDiscovery(url2, protocolVersion, fetchFn);
|
|
18622
|
-
if (!
|
|
19849
|
+
if (!opts?.metadataUrl && shouldAttemptFallback(response, issuer.pathname)) {
|
|
18623
19850
|
const rootUrl = new URL(`/.well-known/${wellKnownType}`, issuer);
|
|
18624
19851
|
response = await tryMetadataDiscovery(rootUrl, protocolVersion, fetchFn);
|
|
18625
19852
|
}
|
|
@@ -18635,15 +19862,17 @@ async function discoverOAuthMetadata(issuer, { authorizationServerUrl, protocolV
|
|
|
18635
19862
|
if (typeof authorizationServerUrl === "string") {
|
|
18636
19863
|
authorizationServerUrl = new URL(authorizationServerUrl);
|
|
18637
19864
|
}
|
|
18638
|
-
protocolVersion
|
|
19865
|
+
protocolVersion ?? (protocolVersion = LATEST_PROTOCOL_VERSION);
|
|
18639
19866
|
const response = await discoverMetadataWithFallback(authorizationServerUrl, "oauth-authorization-server", fetchFn, {
|
|
18640
19867
|
protocolVersion,
|
|
18641
19868
|
metadataServerUrl: authorizationServerUrl
|
|
18642
19869
|
});
|
|
18643
19870
|
if (!response || response.status === 404) {
|
|
19871
|
+
await response?.body?.cancel();
|
|
18644
19872
|
return void 0;
|
|
18645
19873
|
}
|
|
18646
19874
|
if (!response.ok) {
|
|
19875
|
+
await response.body?.cancel();
|
|
18647
19876
|
throw new Error(`HTTP ${response.status} trying to load well-known OAuth metadata`);
|
|
18648
19877
|
}
|
|
18649
19878
|
return OAuthMetadataSchema.parse(await response.json());
|
|
@@ -18693,6 +19922,7 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
|
|
|
18693
19922
|
continue;
|
|
18694
19923
|
}
|
|
18695
19924
|
if (!response.ok) {
|
|
19925
|
+
await response.body?.cancel();
|
|
18696
19926
|
if (response.status >= 400 && response.status < 500) {
|
|
18697
19927
|
continue;
|
|
18698
19928
|
}
|
|
@@ -18733,7 +19963,7 @@ async function startAuthorization(authorizationServerUrl, { metadata: metadata2,
|
|
|
18733
19963
|
if (scope2) {
|
|
18734
19964
|
authorizationUrl.searchParams.set("scope", scope2);
|
|
18735
19965
|
}
|
|
18736
|
-
if (scope2
|
|
19966
|
+
if (scope2?.includes("offline_access")) {
|
|
18737
19967
|
authorizationUrl.searchParams.append("prompt", "consent");
|
|
18738
19968
|
}
|
|
18739
19969
|
if (resource) {
|
|
@@ -18741,81 +19971,91 @@ async function startAuthorization(authorizationServerUrl, { metadata: metadata2,
|
|
|
18741
19971
|
}
|
|
18742
19972
|
return { authorizationUrl, codeVerifier };
|
|
18743
19973
|
}
|
|
18744
|
-
|
|
18745
|
-
|
|
18746
|
-
|
|
18747
|
-
const tokenUrl = (metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.token_endpoint) ? new URL(metadata2.token_endpoint) : new URL("/token", authorizationServerUrl);
|
|
18748
|
-
if ((metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.grant_types_supported) && !metadata2.grant_types_supported.includes(grantType)) {
|
|
18749
|
-
throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
|
|
18750
|
-
}
|
|
18751
|
-
const headers = new Headers({
|
|
18752
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
18753
|
-
Accept: "application/json"
|
|
18754
|
-
});
|
|
18755
|
-
const params = new URLSearchParams({
|
|
18756
|
-
grant_type: grantType,
|
|
19974
|
+
function prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, redirectUri) {
|
|
19975
|
+
return new URLSearchParams({
|
|
19976
|
+
grant_type: "authorization_code",
|
|
18757
19977
|
code: authorizationCode,
|
|
18758
19978
|
code_verifier: codeVerifier,
|
|
18759
19979
|
redirect_uri: String(redirectUri)
|
|
18760
19980
|
});
|
|
19981
|
+
}
|
|
19982
|
+
async function executeTokenRequest(authorizationServerUrl, { metadata: metadata2, tokenRequestParams, clientInformation, addClientAuthentication, resource, fetchFn }) {
|
|
19983
|
+
const tokenUrl = metadata2?.token_endpoint ? new URL(metadata2.token_endpoint) : new URL("/token", authorizationServerUrl);
|
|
19984
|
+
const headers = new Headers({
|
|
19985
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
19986
|
+
Accept: "application/json"
|
|
19987
|
+
});
|
|
19988
|
+
if (resource) {
|
|
19989
|
+
tokenRequestParams.set("resource", resource.href);
|
|
19990
|
+
}
|
|
18761
19991
|
if (addClientAuthentication) {
|
|
18762
|
-
addClientAuthentication(headers,
|
|
18763
|
-
} else {
|
|
18764
|
-
const supportedMethods =
|
|
19992
|
+
await addClientAuthentication(headers, tokenRequestParams, tokenUrl, metadata2);
|
|
19993
|
+
} else if (clientInformation) {
|
|
19994
|
+
const supportedMethods = metadata2?.token_endpoint_auth_methods_supported ?? [];
|
|
18765
19995
|
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
18766
|
-
applyClientAuthentication(authMethod, clientInformation, headers,
|
|
19996
|
+
applyClientAuthentication(authMethod, clientInformation, headers, tokenRequestParams);
|
|
18767
19997
|
}
|
|
18768
|
-
|
|
18769
|
-
params.set("resource", resource.href);
|
|
18770
|
-
}
|
|
18771
|
-
const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(tokenUrl, {
|
|
19998
|
+
const response = await (fetchFn ?? fetch)(tokenUrl, {
|
|
18772
19999
|
method: "POST",
|
|
18773
20000
|
headers,
|
|
18774
|
-
body:
|
|
20001
|
+
body: tokenRequestParams
|
|
18775
20002
|
});
|
|
18776
20003
|
if (!response.ok) {
|
|
18777
20004
|
throw await parseErrorResponse(response);
|
|
18778
20005
|
}
|
|
18779
20006
|
return OAuthTokensSchema.parse(await response.json());
|
|
18780
20007
|
}
|
|
18781
|
-
async function
|
|
18782
|
-
|
|
18783
|
-
|
|
18784
|
-
|
|
18785
|
-
|
|
18786
|
-
|
|
18787
|
-
|
|
18788
|
-
|
|
18789
|
-
|
|
18790
|
-
} else {
|
|
18791
|
-
tokenUrl = new URL("/token", authorizationServerUrl);
|
|
18792
|
-
}
|
|
18793
|
-
const headers = new Headers({
|
|
18794
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
20008
|
+
async function exchangeAuthorization(authorizationServerUrl, { metadata: metadata2, clientInformation, authorizationCode, codeVerifier, redirectUri, resource, addClientAuthentication, fetchFn }) {
|
|
20009
|
+
const tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, redirectUri);
|
|
20010
|
+
return executeTokenRequest(authorizationServerUrl, {
|
|
20011
|
+
metadata: metadata2,
|
|
20012
|
+
tokenRequestParams,
|
|
20013
|
+
clientInformation,
|
|
20014
|
+
addClientAuthentication,
|
|
20015
|
+
resource,
|
|
20016
|
+
fetchFn
|
|
18795
20017
|
});
|
|
18796
|
-
|
|
18797
|
-
|
|
20018
|
+
}
|
|
20019
|
+
async function refreshAuthorization(authorizationServerUrl, { metadata: metadata2, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) {
|
|
20020
|
+
const tokenRequestParams = new URLSearchParams({
|
|
20021
|
+
grant_type: "refresh_token",
|
|
18798
20022
|
refresh_token: refreshToken
|
|
18799
20023
|
});
|
|
18800
|
-
|
|
18801
|
-
|
|
18802
|
-
|
|
18803
|
-
|
|
18804
|
-
|
|
18805
|
-
|
|
20024
|
+
const tokens = await executeTokenRequest(authorizationServerUrl, {
|
|
20025
|
+
metadata: metadata2,
|
|
20026
|
+
tokenRequestParams,
|
|
20027
|
+
clientInformation,
|
|
20028
|
+
addClientAuthentication,
|
|
20029
|
+
resource,
|
|
20030
|
+
fetchFn
|
|
20031
|
+
});
|
|
20032
|
+
return { refresh_token: refreshToken, ...tokens };
|
|
20033
|
+
}
|
|
20034
|
+
async function fetchToken(provider, authorizationServerUrl, { metadata: metadata2, resource, authorizationCode, fetchFn } = {}) {
|
|
20035
|
+
const scope2 = provider.clientMetadata.scope;
|
|
20036
|
+
let tokenRequestParams;
|
|
20037
|
+
if (provider.prepareTokenRequest) {
|
|
20038
|
+
tokenRequestParams = await provider.prepareTokenRequest(scope2);
|
|
18806
20039
|
}
|
|
18807
|
-
if (
|
|
18808
|
-
|
|
20040
|
+
if (!tokenRequestParams) {
|
|
20041
|
+
if (!authorizationCode) {
|
|
20042
|
+
throw new Error("Either provider.prepareTokenRequest() or authorizationCode is required");
|
|
20043
|
+
}
|
|
20044
|
+
if (!provider.redirectUrl) {
|
|
20045
|
+
throw new Error("redirectUrl is required for authorization_code flow");
|
|
20046
|
+
}
|
|
20047
|
+
const codeVerifier = await provider.codeVerifier();
|
|
20048
|
+
tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, provider.redirectUrl);
|
|
18809
20049
|
}
|
|
18810
|
-
const
|
|
18811
|
-
|
|
18812
|
-
|
|
18813
|
-
|
|
20050
|
+
const clientInformation = await provider.clientInformation();
|
|
20051
|
+
return executeTokenRequest(authorizationServerUrl, {
|
|
20052
|
+
metadata: metadata2,
|
|
20053
|
+
tokenRequestParams,
|
|
20054
|
+
clientInformation: clientInformation ?? void 0,
|
|
20055
|
+
addClientAuthentication: provider.addClientAuthentication,
|
|
20056
|
+
resource,
|
|
20057
|
+
fetchFn
|
|
18814
20058
|
});
|
|
18815
|
-
if (!response.ok) {
|
|
18816
|
-
throw await parseErrorResponse(response);
|
|
18817
|
-
}
|
|
18818
|
-
return OAuthTokensSchema.parse({ refresh_token: refreshToken, ...await response.json() });
|
|
18819
20059
|
}
|
|
18820
20060
|
async function registerClient(authorizationServerUrl, { metadata: metadata2, clientMetadata, fetchFn }) {
|
|
18821
20061
|
let registrationUrl;
|
|
@@ -18827,7 +20067,7 @@ async function registerClient(authorizationServerUrl, { metadata: metadata2, cli
|
|
|
18827
20067
|
} else {
|
|
18828
20068
|
registrationUrl = new URL("/register", authorizationServerUrl);
|
|
18829
20069
|
}
|
|
18830
|
-
const response = await (fetchFn
|
|
20070
|
+
const response = await (fetchFn ?? fetch)(registrationUrl, {
|
|
18831
20071
|
method: "POST",
|
|
18832
20072
|
headers: {
|
|
18833
20073
|
"Content-Type": "application/json"
|
|
@@ -19227,7 +20467,7 @@ function createFetchWithInit(baseFetch = fetch, baseInit) {
|
|
|
19227
20467
|
...baseInit,
|
|
19228
20468
|
...init,
|
|
19229
20469
|
// Headers need special handling - merge instead of replace
|
|
19230
|
-
headers:
|
|
20470
|
+
headers: init?.headers ? { ...normalizeHeaders(baseInit.headers), ...normalizeHeaders(init.headers) } : baseInit.headers
|
|
19231
20471
|
};
|
|
19232
20472
|
return baseFetch(url2, mergedInit);
|
|
19233
20473
|
};
|
|
@@ -19244,14 +20484,13 @@ class SSEClientTransport {
|
|
|
19244
20484
|
this._url = url2;
|
|
19245
20485
|
this._resourceMetadataUrl = void 0;
|
|
19246
20486
|
this._scope = void 0;
|
|
19247
|
-
this._eventSourceInit = opts
|
|
19248
|
-
this._requestInit = opts
|
|
19249
|
-
this._authProvider = opts
|
|
19250
|
-
this._fetch = opts
|
|
19251
|
-
this._fetchWithInit = createFetchWithInit(opts
|
|
20487
|
+
this._eventSourceInit = opts?.eventSourceInit;
|
|
20488
|
+
this._requestInit = opts?.requestInit;
|
|
20489
|
+
this._authProvider = opts?.authProvider;
|
|
20490
|
+
this._fetch = opts?.fetch;
|
|
20491
|
+
this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
|
|
19252
20492
|
}
|
|
19253
20493
|
async _authThenStart() {
|
|
19254
|
-
var _a;
|
|
19255
20494
|
if (!this._authProvider) {
|
|
19256
20495
|
throw new UnauthorizedError("No auth provider");
|
|
19257
20496
|
}
|
|
@@ -19264,7 +20503,7 @@ class SSEClientTransport {
|
|
|
19264
20503
|
fetchFn: this._fetchWithInit
|
|
19265
20504
|
});
|
|
19266
20505
|
} catch (error) {
|
|
19267
|
-
|
|
20506
|
+
this.onerror?.(error);
|
|
19268
20507
|
throw error;
|
|
19269
20508
|
}
|
|
19270
20509
|
if (result !== "AUTHORIZED") {
|
|
@@ -19273,7 +20512,6 @@ class SSEClientTransport {
|
|
|
19273
20512
|
return await this._startOrAuth();
|
|
19274
20513
|
}
|
|
19275
20514
|
async _commonHeaders() {
|
|
19276
|
-
var _a;
|
|
19277
20515
|
const headers = {};
|
|
19278
20516
|
if (this._authProvider) {
|
|
19279
20517
|
const tokens = await this._authProvider.tokens();
|
|
@@ -19284,11 +20522,14 @@ class SSEClientTransport {
|
|
|
19284
20522
|
if (this._protocolVersion) {
|
|
19285
20523
|
headers["mcp-protocol-version"] = this._protocolVersion;
|
|
19286
20524
|
}
|
|
19287
|
-
|
|
20525
|
+
const extraHeaders = normalizeHeaders(this._requestInit?.headers);
|
|
20526
|
+
return new Headers({
|
|
20527
|
+
...headers,
|
|
20528
|
+
...extraHeaders
|
|
20529
|
+
});
|
|
19288
20530
|
}
|
|
19289
20531
|
_startOrAuth() {
|
|
19290
|
-
|
|
19291
|
-
const fetchImpl = (_c = (_b = (_a = this === null || this === void 0 ? void 0 : this._eventSourceInit) === null || _a === void 0 ? void 0 : _a.fetch) !== null && _b !== void 0 ? _b : this._fetch) !== null && _c !== void 0 ? _c : fetch;
|
|
20532
|
+
const fetchImpl = this?._eventSourceInit?.fetch ?? this._fetch ?? fetch;
|
|
19292
20533
|
return new Promise((resolve2, reject) => {
|
|
19293
20534
|
this._eventSource = new EventSource(this._url.href, {
|
|
19294
20535
|
...this._eventSourceInit,
|
|
@@ -19309,19 +20550,17 @@ class SSEClientTransport {
|
|
|
19309
20550
|
});
|
|
19310
20551
|
this._abortController = new AbortController();
|
|
19311
20552
|
this._eventSource.onerror = (event) => {
|
|
19312
|
-
var _a2;
|
|
19313
20553
|
if (event.code === 401 && this._authProvider) {
|
|
19314
20554
|
this._authThenStart().then(resolve2, reject);
|
|
19315
20555
|
return;
|
|
19316
20556
|
}
|
|
19317
20557
|
const error = new SseError(event.code, event.message, event);
|
|
19318
20558
|
reject(error);
|
|
19319
|
-
|
|
20559
|
+
this.onerror?.(error);
|
|
19320
20560
|
};
|
|
19321
20561
|
this._eventSource.onopen = () => {
|
|
19322
20562
|
};
|
|
19323
20563
|
this._eventSource.addEventListener("endpoint", (event) => {
|
|
19324
|
-
var _a2;
|
|
19325
20564
|
const messageEvent = event;
|
|
19326
20565
|
try {
|
|
19327
20566
|
this._endpoint = new URL(messageEvent.data, this._url);
|
|
@@ -19330,23 +20569,22 @@ class SSEClientTransport {
|
|
|
19330
20569
|
}
|
|
19331
20570
|
} catch (error) {
|
|
19332
20571
|
reject(error);
|
|
19333
|
-
|
|
20572
|
+
this.onerror?.(error);
|
|
19334
20573
|
void this.close();
|
|
19335
20574
|
return;
|
|
19336
20575
|
}
|
|
19337
20576
|
resolve2();
|
|
19338
20577
|
});
|
|
19339
20578
|
this._eventSource.onmessage = (event) => {
|
|
19340
|
-
var _a2, _b2;
|
|
19341
20579
|
const messageEvent = event;
|
|
19342
20580
|
let message;
|
|
19343
20581
|
try {
|
|
19344
20582
|
message = JSONRPCMessageSchema.parse(JSON.parse(messageEvent.data));
|
|
19345
20583
|
} catch (error) {
|
|
19346
|
-
|
|
20584
|
+
this.onerror?.(error);
|
|
19347
20585
|
return;
|
|
19348
20586
|
}
|
|
19349
|
-
|
|
20587
|
+
this.onmessage?.(message);
|
|
19350
20588
|
};
|
|
19351
20589
|
});
|
|
19352
20590
|
}
|
|
@@ -19375,13 +20613,11 @@ class SSEClientTransport {
|
|
|
19375
20613
|
}
|
|
19376
20614
|
}
|
|
19377
20615
|
async close() {
|
|
19378
|
-
|
|
19379
|
-
|
|
19380
|
-
|
|
19381
|
-
(_c = this.onclose) === null || _c === void 0 ? void 0 : _c.call(this);
|
|
20616
|
+
this._abortController?.abort();
|
|
20617
|
+
this._eventSource?.close();
|
|
20618
|
+
this.onclose?.();
|
|
19382
20619
|
}
|
|
19383
20620
|
async send(message) {
|
|
19384
|
-
var _a, _b, _c;
|
|
19385
20621
|
if (!this._endpoint) {
|
|
19386
20622
|
throw new Error("Not connected");
|
|
19387
20623
|
}
|
|
@@ -19393,10 +20629,11 @@ class SSEClientTransport {
|
|
|
19393
20629
|
method: "POST",
|
|
19394
20630
|
headers,
|
|
19395
20631
|
body: JSON.stringify(message),
|
|
19396
|
-
signal:
|
|
20632
|
+
signal: this._abortController?.signal
|
|
19397
20633
|
};
|
|
19398
|
-
const response = await (
|
|
20634
|
+
const response = await (this._fetch ?? fetch)(this._endpoint, init);
|
|
19399
20635
|
if (!response.ok) {
|
|
20636
|
+
const text = await response.text().catch(() => null);
|
|
19400
20637
|
if (response.status === 401 && this._authProvider) {
|
|
19401
20638
|
const { resourceMetadataUrl, scope: scope2 } = extractWWWAuthenticateParams(response);
|
|
19402
20639
|
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
@@ -19412,11 +20649,11 @@ class SSEClientTransport {
|
|
|
19412
20649
|
}
|
|
19413
20650
|
return this.send(message);
|
|
19414
20651
|
}
|
|
19415
|
-
const text = await response.text().catch(() => null);
|
|
19416
20652
|
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
|
|
19417
20653
|
}
|
|
20654
|
+
await response.body?.cancel();
|
|
19418
20655
|
} catch (error) {
|
|
19419
|
-
|
|
20656
|
+
this.onerror?.(error);
|
|
19420
20657
|
throw error;
|
|
19421
20658
|
}
|
|
19422
20659
|
}
|
|
@@ -19460,20 +20697,18 @@ class StreamableHTTPError extends Error {
|
|
|
19460
20697
|
}
|
|
19461
20698
|
class StreamableHTTPClientTransport {
|
|
19462
20699
|
constructor(url2, opts) {
|
|
19463
|
-
var _a;
|
|
19464
20700
|
this._hasCompletedAuthFlow = false;
|
|
19465
20701
|
this._url = url2;
|
|
19466
20702
|
this._resourceMetadataUrl = void 0;
|
|
19467
20703
|
this._scope = void 0;
|
|
19468
|
-
this._requestInit = opts
|
|
19469
|
-
this._authProvider = opts
|
|
19470
|
-
this._fetch = opts
|
|
19471
|
-
this._fetchWithInit = createFetchWithInit(opts
|
|
19472
|
-
this._sessionId = opts
|
|
19473
|
-
this._reconnectionOptions =
|
|
20704
|
+
this._requestInit = opts?.requestInit;
|
|
20705
|
+
this._authProvider = opts?.authProvider;
|
|
20706
|
+
this._fetch = opts?.fetch;
|
|
20707
|
+
this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
|
|
20708
|
+
this._sessionId = opts?.sessionId;
|
|
20709
|
+
this._reconnectionOptions = opts?.reconnectionOptions ?? DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS;
|
|
19474
20710
|
}
|
|
19475
20711
|
async _authThenStart() {
|
|
19476
|
-
var _a;
|
|
19477
20712
|
if (!this._authProvider) {
|
|
19478
20713
|
throw new UnauthorizedError("No auth provider");
|
|
19479
20714
|
}
|
|
@@ -19486,7 +20721,7 @@ class StreamableHTTPClientTransport {
|
|
|
19486
20721
|
fetchFn: this._fetchWithInit
|
|
19487
20722
|
});
|
|
19488
20723
|
} catch (error) {
|
|
19489
|
-
|
|
20724
|
+
this.onerror?.(error);
|
|
19490
20725
|
throw error;
|
|
19491
20726
|
}
|
|
19492
20727
|
if (result !== "AUTHORIZED") {
|
|
@@ -19495,7 +20730,6 @@ class StreamableHTTPClientTransport {
|
|
|
19495
20730
|
return await this._startOrAuthSse({ resumptionToken: void 0 });
|
|
19496
20731
|
}
|
|
19497
20732
|
async _commonHeaders() {
|
|
19498
|
-
var _a;
|
|
19499
20733
|
const headers = {};
|
|
19500
20734
|
if (this._authProvider) {
|
|
19501
20735
|
const tokens = await this._authProvider.tokens();
|
|
@@ -19509,14 +20743,13 @@ class StreamableHTTPClientTransport {
|
|
|
19509
20743
|
if (this._protocolVersion) {
|
|
19510
20744
|
headers["mcp-protocol-version"] = this._protocolVersion;
|
|
19511
20745
|
}
|
|
19512
|
-
const extraHeaders = normalizeHeaders(
|
|
20746
|
+
const extraHeaders = normalizeHeaders(this._requestInit?.headers);
|
|
19513
20747
|
return new Headers({
|
|
19514
20748
|
...headers,
|
|
19515
20749
|
...extraHeaders
|
|
19516
20750
|
});
|
|
19517
20751
|
}
|
|
19518
20752
|
async _startOrAuthSse(options) {
|
|
19519
|
-
var _a, _b, _c;
|
|
19520
20753
|
const { resumptionToken } = options;
|
|
19521
20754
|
try {
|
|
19522
20755
|
const headers = await this._commonHeaders();
|
|
@@ -19524,12 +20757,13 @@ class StreamableHTTPClientTransport {
|
|
|
19524
20757
|
if (resumptionToken) {
|
|
19525
20758
|
headers.set("last-event-id", resumptionToken);
|
|
19526
20759
|
}
|
|
19527
|
-
const response = await (
|
|
20760
|
+
const response = await (this._fetch ?? fetch)(this._url, {
|
|
19528
20761
|
method: "GET",
|
|
19529
20762
|
headers,
|
|
19530
|
-
signal:
|
|
20763
|
+
signal: this._abortController?.signal
|
|
19531
20764
|
});
|
|
19532
20765
|
if (!response.ok) {
|
|
20766
|
+
await response.body?.cancel();
|
|
19533
20767
|
if (response.status === 401 && this._authProvider) {
|
|
19534
20768
|
return await this._authThenStart();
|
|
19535
20769
|
}
|
|
@@ -19540,7 +20774,7 @@ class StreamableHTTPClientTransport {
|
|
|
19540
20774
|
}
|
|
19541
20775
|
this._handleSseStream(response.body, options, true);
|
|
19542
20776
|
} catch (error) {
|
|
19543
|
-
|
|
20777
|
+
this.onerror?.(error);
|
|
19544
20778
|
throw error;
|
|
19545
20779
|
}
|
|
19546
20780
|
}
|
|
@@ -19566,17 +20800,15 @@ class StreamableHTTPClientTransport {
|
|
|
19566
20800
|
* @param attemptCount Current reconnection attempt count for this specific stream
|
|
19567
20801
|
*/
|
|
19568
20802
|
_scheduleReconnection(options, attemptCount = 0) {
|
|
19569
|
-
var _a;
|
|
19570
20803
|
const maxRetries = this._reconnectionOptions.maxRetries;
|
|
19571
|
-
if (
|
|
19572
|
-
|
|
20804
|
+
if (attemptCount >= maxRetries) {
|
|
20805
|
+
this.onerror?.(new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`));
|
|
19573
20806
|
return;
|
|
19574
20807
|
}
|
|
19575
20808
|
const delay = this._getNextReconnectionDelay(attemptCount);
|
|
19576
|
-
setTimeout(() => {
|
|
20809
|
+
this._reconnectionTimeout = setTimeout(() => {
|
|
19577
20810
|
this._startOrAuthSse(options).catch((error) => {
|
|
19578
|
-
|
|
19579
|
-
(_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, new Error(`Failed to reconnect SSE stream: ${error instanceof Error ? error.message : String(error)}`));
|
|
20811
|
+
this.onerror?.(new Error(`Failed to reconnect SSE stream: ${error instanceof Error ? error.message : String(error)}`));
|
|
19580
20812
|
this._scheduleReconnection(options, attemptCount + 1);
|
|
19581
20813
|
});
|
|
19582
20814
|
}, delay);
|
|
@@ -19588,8 +20820,8 @@ class StreamableHTTPClientTransport {
|
|
|
19588
20820
|
const { onresumptiontoken, replayMessageId } = options;
|
|
19589
20821
|
let lastEventId;
|
|
19590
20822
|
let hasPrimingEvent = false;
|
|
20823
|
+
let receivedResponse = false;
|
|
19591
20824
|
const processStream = async () => {
|
|
19592
|
-
var _a, _b, _c, _d;
|
|
19593
20825
|
try {
|
|
19594
20826
|
const reader = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream({
|
|
19595
20827
|
onRetry: (retryMs) => {
|
|
@@ -19604,22 +20836,29 @@ class StreamableHTTPClientTransport {
|
|
|
19604
20836
|
if (event.id) {
|
|
19605
20837
|
lastEventId = event.id;
|
|
19606
20838
|
hasPrimingEvent = true;
|
|
19607
|
-
onresumptiontoken
|
|
20839
|
+
onresumptiontoken?.(event.id);
|
|
20840
|
+
}
|
|
20841
|
+
if (!event.data) {
|
|
20842
|
+
continue;
|
|
19608
20843
|
}
|
|
19609
20844
|
if (!event.event || event.event === "message") {
|
|
19610
20845
|
try {
|
|
19611
20846
|
const message = JSONRPCMessageSchema.parse(JSON.parse(event.data));
|
|
19612
|
-
if (
|
|
19613
|
-
|
|
20847
|
+
if (isJSONRPCResultResponse(message)) {
|
|
20848
|
+
receivedResponse = true;
|
|
20849
|
+
if (replayMessageId !== void 0) {
|
|
20850
|
+
message.id = replayMessageId;
|
|
20851
|
+
}
|
|
19614
20852
|
}
|
|
19615
|
-
|
|
20853
|
+
this.onmessage?.(message);
|
|
19616
20854
|
} catch (error) {
|
|
19617
|
-
|
|
20855
|
+
this.onerror?.(error);
|
|
19618
20856
|
}
|
|
19619
20857
|
}
|
|
19620
20858
|
}
|
|
19621
20859
|
const canResume = isReconnectable || hasPrimingEvent;
|
|
19622
|
-
|
|
20860
|
+
const needsReconnect = canResume && !receivedResponse;
|
|
20861
|
+
if (needsReconnect && this._abortController && !this._abortController.signal.aborted) {
|
|
19623
20862
|
this._scheduleReconnection({
|
|
19624
20863
|
resumptionToken: lastEventId,
|
|
19625
20864
|
onresumptiontoken,
|
|
@@ -19627,9 +20866,10 @@ class StreamableHTTPClientTransport {
|
|
|
19627
20866
|
}, 0);
|
|
19628
20867
|
}
|
|
19629
20868
|
} catch (error) {
|
|
19630
|
-
|
|
20869
|
+
this.onerror?.(new Error(`SSE stream disconnected: ${error}`));
|
|
19631
20870
|
const canResume = isReconnectable || hasPrimingEvent;
|
|
19632
|
-
|
|
20871
|
+
const needsReconnect = canResume && !receivedResponse;
|
|
20872
|
+
if (needsReconnect && this._abortController && !this._abortController.signal.aborted) {
|
|
19633
20873
|
try {
|
|
19634
20874
|
this._scheduleReconnection({
|
|
19635
20875
|
resumptionToken: lastEventId,
|
|
@@ -19637,7 +20877,7 @@ class StreamableHTTPClientTransport {
|
|
|
19637
20877
|
replayMessageId
|
|
19638
20878
|
}, 0);
|
|
19639
20879
|
} catch (error2) {
|
|
19640
|
-
|
|
20880
|
+
this.onerror?.(new Error(`Failed to reconnect: ${error2 instanceof Error ? error2.message : String(error2)}`));
|
|
19641
20881
|
}
|
|
19642
20882
|
}
|
|
19643
20883
|
}
|
|
@@ -19669,19 +20909,18 @@ class StreamableHTTPClientTransport {
|
|
|
19669
20909
|
}
|
|
19670
20910
|
}
|
|
19671
20911
|
async close() {
|
|
19672
|
-
|
|
19673
|
-
|
|
19674
|
-
|
|
20912
|
+
if (this._reconnectionTimeout) {
|
|
20913
|
+
clearTimeout(this._reconnectionTimeout);
|
|
20914
|
+
this._reconnectionTimeout = void 0;
|
|
20915
|
+
}
|
|
20916
|
+
this._abortController?.abort();
|
|
20917
|
+
this.onclose?.();
|
|
19675
20918
|
}
|
|
19676
20919
|
async send(message, options) {
|
|
19677
|
-
var _a, _b, _c, _d;
|
|
19678
20920
|
try {
|
|
19679
20921
|
const { resumptionToken, onresumptiontoken } = options || {};
|
|
19680
20922
|
if (resumptionToken) {
|
|
19681
|
-
this._startOrAuthSse({ resumptionToken, replayMessageId: isJSONRPCRequest(message) ? message.id : void 0 }).catch((err) =>
|
|
19682
|
-
var _a2;
|
|
19683
|
-
return (_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, err);
|
|
19684
|
-
});
|
|
20923
|
+
this._startOrAuthSse({ resumptionToken, replayMessageId: isJSONRPCRequest(message) ? message.id : void 0 }).catch((err) => this.onerror?.(err));
|
|
19685
20924
|
return;
|
|
19686
20925
|
}
|
|
19687
20926
|
const headers = await this._commonHeaders();
|
|
@@ -19692,14 +20931,15 @@ class StreamableHTTPClientTransport {
|
|
|
19692
20931
|
method: "POST",
|
|
19693
20932
|
headers,
|
|
19694
20933
|
body: JSON.stringify(message),
|
|
19695
|
-
signal:
|
|
20934
|
+
signal: this._abortController?.signal
|
|
19696
20935
|
};
|
|
19697
|
-
const response = await (
|
|
20936
|
+
const response = await (this._fetch ?? fetch)(this._url, init);
|
|
19698
20937
|
const sessionId = response.headers.get("mcp-session-id");
|
|
19699
20938
|
if (sessionId) {
|
|
19700
20939
|
this._sessionId = sessionId;
|
|
19701
20940
|
}
|
|
19702
20941
|
if (!response.ok) {
|
|
20942
|
+
const text = await response.text().catch(() => null);
|
|
19703
20943
|
if (response.status === 401 && this._authProvider) {
|
|
19704
20944
|
if (this._hasCompletedAuthFlow) {
|
|
19705
20945
|
throw new StreamableHTTPError(401, "Server returned 401 after successful authentication");
|
|
@@ -19732,7 +20972,7 @@ class StreamableHTTPClientTransport {
|
|
|
19732
20972
|
if (resourceMetadataUrl) {
|
|
19733
20973
|
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
19734
20974
|
}
|
|
19735
|
-
this._lastUpscopingHeader = wwwAuthHeader
|
|
20975
|
+
this._lastUpscopingHeader = wwwAuthHeader ?? void 0;
|
|
19736
20976
|
const result = await auth(this._authProvider, {
|
|
19737
20977
|
serverUrl: this._url,
|
|
19738
20978
|
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
@@ -19745,17 +20985,14 @@ class StreamableHTTPClientTransport {
|
|
|
19745
20985
|
return this.send(message);
|
|
19746
20986
|
}
|
|
19747
20987
|
}
|
|
19748
|
-
|
|
19749
|
-
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
|
|
20988
|
+
throw new StreamableHTTPError(response.status, `Error POSTing to endpoint: ${text}`);
|
|
19750
20989
|
}
|
|
19751
20990
|
this._hasCompletedAuthFlow = false;
|
|
19752
20991
|
this._lastUpscopingHeader = void 0;
|
|
19753
20992
|
if (response.status === 202) {
|
|
20993
|
+
await response.body?.cancel();
|
|
19754
20994
|
if (isInitializedNotification(message)) {
|
|
19755
|
-
this._startOrAuthSse({ resumptionToken: void 0 }).catch((err) =>
|
|
19756
|
-
var _a2;
|
|
19757
|
-
return (_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, err);
|
|
19758
|
-
});
|
|
20995
|
+
this._startOrAuthSse({ resumptionToken: void 0 }).catch((err) => this.onerror?.(err));
|
|
19759
20996
|
}
|
|
19760
20997
|
return;
|
|
19761
20998
|
}
|
|
@@ -19763,20 +21000,23 @@ class StreamableHTTPClientTransport {
|
|
|
19763
21000
|
const hasRequests = messages.filter((msg) => "method" in msg && "id" in msg && msg.id !== void 0).length > 0;
|
|
19764
21001
|
const contentType = response.headers.get("content-type");
|
|
19765
21002
|
if (hasRequests) {
|
|
19766
|
-
if (contentType
|
|
21003
|
+
if (contentType?.includes("text/event-stream")) {
|
|
19767
21004
|
this._handleSseStream(response.body, { onresumptiontoken }, false);
|
|
19768
|
-
} else if (contentType
|
|
21005
|
+
} else if (contentType?.includes("application/json")) {
|
|
19769
21006
|
const data = await response.json();
|
|
19770
21007
|
const responseMessages = Array.isArray(data) ? data.map((msg) => JSONRPCMessageSchema.parse(msg)) : [JSONRPCMessageSchema.parse(data)];
|
|
19771
21008
|
for (const msg of responseMessages) {
|
|
19772
|
-
|
|
21009
|
+
this.onmessage?.(msg);
|
|
19773
21010
|
}
|
|
19774
21011
|
} else {
|
|
21012
|
+
await response.body?.cancel();
|
|
19775
21013
|
throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`);
|
|
19776
21014
|
}
|
|
21015
|
+
} else {
|
|
21016
|
+
await response.body?.cancel();
|
|
19777
21017
|
}
|
|
19778
21018
|
} catch (error) {
|
|
19779
|
-
|
|
21019
|
+
this.onerror?.(error);
|
|
19780
21020
|
throw error;
|
|
19781
21021
|
}
|
|
19782
21022
|
}
|
|
@@ -19795,7 +21035,6 @@ class StreamableHTTPClientTransport {
|
|
|
19795
21035
|
* the server does not allow clients to terminate sessions.
|
|
19796
21036
|
*/
|
|
19797
21037
|
async terminateSession() {
|
|
19798
|
-
var _a, _b, _c;
|
|
19799
21038
|
if (!this._sessionId) {
|
|
19800
21039
|
return;
|
|
19801
21040
|
}
|
|
@@ -19805,15 +21044,16 @@ class StreamableHTTPClientTransport {
|
|
|
19805
21044
|
...this._requestInit,
|
|
19806
21045
|
method: "DELETE",
|
|
19807
21046
|
headers,
|
|
19808
|
-
signal:
|
|
21047
|
+
signal: this._abortController?.signal
|
|
19809
21048
|
};
|
|
19810
|
-
const response = await (
|
|
21049
|
+
const response = await (this._fetch ?? fetch)(this._url, init);
|
|
21050
|
+
await response.body?.cancel();
|
|
19811
21051
|
if (!response.ok && response.status !== 405) {
|
|
19812
21052
|
throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`);
|
|
19813
21053
|
}
|
|
19814
21054
|
this._sessionId = void 0;
|
|
19815
21055
|
} catch (error) {
|
|
19816
|
-
|
|
21056
|
+
this.onerror?.(error);
|
|
19817
21057
|
throw error;
|
|
19818
21058
|
}
|
|
19819
21059
|
}
|
|
@@ -19833,16 +21073,85 @@ class StreamableHTTPClientTransport {
|
|
|
19833
21073
|
async resumeStream(lastEventId, options) {
|
|
19834
21074
|
await this._startOrAuthSse({
|
|
19835
21075
|
resumptionToken: lastEventId,
|
|
19836
|
-
onresumptiontoken: options
|
|
21076
|
+
onresumptiontoken: options?.onresumptiontoken
|
|
19837
21077
|
});
|
|
19838
21078
|
}
|
|
19839
21079
|
}
|
|
21080
|
+
class ExperimentalServerTasks {
|
|
21081
|
+
constructor(_server) {
|
|
21082
|
+
this._server = _server;
|
|
21083
|
+
}
|
|
21084
|
+
/**
|
|
21085
|
+
* Sends a request and returns an AsyncGenerator that yields response messages.
|
|
21086
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
21087
|
+
*
|
|
21088
|
+
* This method provides streaming access to request processing, allowing you to
|
|
21089
|
+
* observe intermediate task status updates for task-augmented requests.
|
|
21090
|
+
*
|
|
21091
|
+
* @param request - The request to send
|
|
21092
|
+
* @param resultSchema - Zod schema for validating the result
|
|
21093
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
21094
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
21095
|
+
*
|
|
21096
|
+
* @experimental
|
|
21097
|
+
*/
|
|
21098
|
+
requestStream(request, resultSchema, options) {
|
|
21099
|
+
return this._server.requestStream(request, resultSchema, options);
|
|
21100
|
+
}
|
|
21101
|
+
/**
|
|
21102
|
+
* Gets the current status of a task.
|
|
21103
|
+
*
|
|
21104
|
+
* @param taskId - The task identifier
|
|
21105
|
+
* @param options - Optional request options
|
|
21106
|
+
* @returns The task status
|
|
21107
|
+
*
|
|
21108
|
+
* @experimental
|
|
21109
|
+
*/
|
|
21110
|
+
async getTask(taskId, options) {
|
|
21111
|
+
return this._server.getTask({ taskId }, options);
|
|
21112
|
+
}
|
|
21113
|
+
/**
|
|
21114
|
+
* Retrieves the result of a completed task.
|
|
21115
|
+
*
|
|
21116
|
+
* @param taskId - The task identifier
|
|
21117
|
+
* @param resultSchema - Zod schema for validating the result
|
|
21118
|
+
* @param options - Optional request options
|
|
21119
|
+
* @returns The task result
|
|
21120
|
+
*
|
|
21121
|
+
* @experimental
|
|
21122
|
+
*/
|
|
21123
|
+
async getTaskResult(taskId, resultSchema, options) {
|
|
21124
|
+
return this._server.getTaskResult({ taskId }, resultSchema, options);
|
|
21125
|
+
}
|
|
21126
|
+
/**
|
|
21127
|
+
* Lists tasks with optional pagination.
|
|
21128
|
+
*
|
|
21129
|
+
* @param cursor - Optional pagination cursor
|
|
21130
|
+
* @param options - Optional request options
|
|
21131
|
+
* @returns List of tasks with optional next cursor
|
|
21132
|
+
*
|
|
21133
|
+
* @experimental
|
|
21134
|
+
*/
|
|
21135
|
+
async listTasks(cursor, options) {
|
|
21136
|
+
return this._server.listTasks(cursor ? { cursor } : void 0, options);
|
|
21137
|
+
}
|
|
21138
|
+
/**
|
|
21139
|
+
* Cancels a running task.
|
|
21140
|
+
*
|
|
21141
|
+
* @param taskId - The task identifier
|
|
21142
|
+
* @param options - Optional request options
|
|
21143
|
+
*
|
|
21144
|
+
* @experimental
|
|
21145
|
+
*/
|
|
21146
|
+
async cancelTask(taskId, options) {
|
|
21147
|
+
return this._server.cancelTask({ taskId }, options);
|
|
21148
|
+
}
|
|
21149
|
+
}
|
|
19840
21150
|
class Server extends Protocol {
|
|
19841
21151
|
/**
|
|
19842
21152
|
* Initializes this server with the given name and version information.
|
|
19843
21153
|
*/
|
|
19844
21154
|
constructor(_serverInfo, options) {
|
|
19845
|
-
var _a, _b;
|
|
19846
21155
|
super(options);
|
|
19847
21156
|
this._serverInfo = _serverInfo;
|
|
19848
21157
|
this._loggingLevels = /* @__PURE__ */ new Map();
|
|
@@ -19851,18 +21160,14 @@ class Server extends Protocol {
|
|
|
19851
21160
|
const currentLevel = this._loggingLevels.get(sessionId);
|
|
19852
21161
|
return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
|
|
19853
21162
|
};
|
|
19854
|
-
this._capabilities =
|
|
19855
|
-
this._instructions = options
|
|
19856
|
-
this._jsonSchemaValidator =
|
|
21163
|
+
this._capabilities = options?.capabilities ?? {};
|
|
21164
|
+
this._instructions = options?.instructions;
|
|
21165
|
+
this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new AjvJsonSchemaValidator();
|
|
19857
21166
|
this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request));
|
|
19858
|
-
this.setNotificationHandler(InitializedNotificationSchema, () =>
|
|
19859
|
-
var _a2;
|
|
19860
|
-
return (_a2 = this.oninitialized) === null || _a2 === void 0 ? void 0 : _a2.call(this);
|
|
19861
|
-
});
|
|
21167
|
+
this.setNotificationHandler(InitializedNotificationSchema, () => this.oninitialized?.());
|
|
19862
21168
|
if (this._capabilities.logging) {
|
|
19863
21169
|
this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
|
|
19864
|
-
|
|
19865
|
-
const transportSessionId = extra.sessionId || ((_a2 = extra.requestInfo) === null || _a2 === void 0 ? void 0 : _a2.headers["mcp-session-id"]) || void 0;
|
|
21170
|
+
const transportSessionId = extra.sessionId || extra.requestInfo?.headers["mcp-session-id"] || void 0;
|
|
19866
21171
|
const { level } = request.params;
|
|
19867
21172
|
const parseResult = LoggingLevelSchema.safeParse(level);
|
|
19868
21173
|
if (parseResult.success) {
|
|
@@ -19872,6 +21177,21 @@ class Server extends Protocol {
|
|
|
19872
21177
|
});
|
|
19873
21178
|
}
|
|
19874
21179
|
}
|
|
21180
|
+
/**
|
|
21181
|
+
* Access experimental features.
|
|
21182
|
+
*
|
|
21183
|
+
* WARNING: These APIs are experimental and may change without notice.
|
|
21184
|
+
*
|
|
21185
|
+
* @experimental
|
|
21186
|
+
*/
|
|
21187
|
+
get experimental() {
|
|
21188
|
+
if (!this._experimental) {
|
|
21189
|
+
this._experimental = {
|
|
21190
|
+
tasks: new ExperimentalServerTasks(this)
|
|
21191
|
+
};
|
|
21192
|
+
}
|
|
21193
|
+
return this._experimental;
|
|
21194
|
+
}
|
|
19875
21195
|
/**
|
|
19876
21196
|
* Registers new capabilities. This can only be called before connecting to a transport.
|
|
19877
21197
|
*
|
|
@@ -19883,28 +21203,77 @@ class Server extends Protocol {
|
|
|
19883
21203
|
}
|
|
19884
21204
|
this._capabilities = mergeCapabilities(this._capabilities, capabilities);
|
|
19885
21205
|
}
|
|
21206
|
+
/**
|
|
21207
|
+
* Override request handler registration to enforce server-side validation for tools/call.
|
|
21208
|
+
*/
|
|
21209
|
+
setRequestHandler(requestSchema, handler) {
|
|
21210
|
+
const shape = getObjectShape(requestSchema);
|
|
21211
|
+
const methodSchema = shape?.method;
|
|
21212
|
+
if (!methodSchema) {
|
|
21213
|
+
throw new Error("Schema is missing a method literal");
|
|
21214
|
+
}
|
|
21215
|
+
let methodValue;
|
|
21216
|
+
if (isZ4Schema(methodSchema)) {
|
|
21217
|
+
const v4Schema = methodSchema;
|
|
21218
|
+
const v4Def = v4Schema._zod?.def;
|
|
21219
|
+
methodValue = v4Def?.value ?? v4Schema.value;
|
|
21220
|
+
} else {
|
|
21221
|
+
const v3Schema = methodSchema;
|
|
21222
|
+
const legacyDef = v3Schema._def;
|
|
21223
|
+
methodValue = legacyDef?.value ?? v3Schema.value;
|
|
21224
|
+
}
|
|
21225
|
+
if (typeof methodValue !== "string") {
|
|
21226
|
+
throw new Error("Schema method literal must be a string");
|
|
21227
|
+
}
|
|
21228
|
+
const method = methodValue;
|
|
21229
|
+
if (method === "tools/call") {
|
|
21230
|
+
const wrappedHandler = async (request, extra) => {
|
|
21231
|
+
const validatedRequest = safeParse(CallToolRequestSchema, request);
|
|
21232
|
+
if (!validatedRequest.success) {
|
|
21233
|
+
const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
21234
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid tools/call request: ${errorMessage}`);
|
|
21235
|
+
}
|
|
21236
|
+
const { params } = validatedRequest.data;
|
|
21237
|
+
const result = await Promise.resolve(handler(request, extra));
|
|
21238
|
+
if (params.task) {
|
|
21239
|
+
const taskValidationResult = safeParse(CreateTaskResultSchema, result);
|
|
21240
|
+
if (!taskValidationResult.success) {
|
|
21241
|
+
const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
21242
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
|
|
21243
|
+
}
|
|
21244
|
+
return taskValidationResult.data;
|
|
21245
|
+
}
|
|
21246
|
+
const validationResult = safeParse(CallToolResultSchema, result);
|
|
21247
|
+
if (!validationResult.success) {
|
|
21248
|
+
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
21249
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid tools/call result: ${errorMessage}`);
|
|
21250
|
+
}
|
|
21251
|
+
return validationResult.data;
|
|
21252
|
+
};
|
|
21253
|
+
return super.setRequestHandler(requestSchema, wrappedHandler);
|
|
21254
|
+
}
|
|
21255
|
+
return super.setRequestHandler(requestSchema, handler);
|
|
21256
|
+
}
|
|
19886
21257
|
assertCapabilityForMethod(method) {
|
|
19887
|
-
var _a, _b, _c;
|
|
19888
21258
|
switch (method) {
|
|
19889
21259
|
case "sampling/createMessage":
|
|
19890
|
-
if (!
|
|
21260
|
+
if (!this._clientCapabilities?.sampling) {
|
|
19891
21261
|
throw new Error(`Client does not support sampling (required for ${method})`);
|
|
19892
21262
|
}
|
|
19893
21263
|
break;
|
|
19894
21264
|
case "elicitation/create":
|
|
19895
|
-
if (!
|
|
21265
|
+
if (!this._clientCapabilities?.elicitation) {
|
|
19896
21266
|
throw new Error(`Client does not support elicitation (required for ${method})`);
|
|
19897
21267
|
}
|
|
19898
21268
|
break;
|
|
19899
21269
|
case "roots/list":
|
|
19900
|
-
if (!
|
|
21270
|
+
if (!this._clientCapabilities?.roots) {
|
|
19901
21271
|
throw new Error(`Client does not support listing roots (required for ${method})`);
|
|
19902
21272
|
}
|
|
19903
21273
|
break;
|
|
19904
21274
|
}
|
|
19905
21275
|
}
|
|
19906
21276
|
assertNotificationCapability(method) {
|
|
19907
|
-
var _a, _b;
|
|
19908
21277
|
switch (method) {
|
|
19909
21278
|
case "notifications/message":
|
|
19910
21279
|
if (!this._capabilities.logging) {
|
|
@@ -19928,13 +21297,16 @@ class Server extends Protocol {
|
|
|
19928
21297
|
}
|
|
19929
21298
|
break;
|
|
19930
21299
|
case "notifications/elicitation/complete":
|
|
19931
|
-
if (!
|
|
21300
|
+
if (!this._clientCapabilities?.elicitation?.url) {
|
|
19932
21301
|
throw new Error(`Client does not support URL elicitation (required for ${method})`);
|
|
19933
21302
|
}
|
|
19934
21303
|
break;
|
|
19935
21304
|
}
|
|
19936
21305
|
}
|
|
19937
21306
|
assertRequestHandlerCapability(method) {
|
|
21307
|
+
if (!this._capabilities) {
|
|
21308
|
+
return;
|
|
21309
|
+
}
|
|
19938
21310
|
switch (method) {
|
|
19939
21311
|
case "completion/complete":
|
|
19940
21312
|
if (!this._capabilities.completions) {
|
|
@@ -19965,7 +21337,24 @@ class Server extends Protocol {
|
|
|
19965
21337
|
throw new Error(`Server does not support tools (required for ${method})`);
|
|
19966
21338
|
}
|
|
19967
21339
|
break;
|
|
21340
|
+
case "tasks/get":
|
|
21341
|
+
case "tasks/list":
|
|
21342
|
+
case "tasks/result":
|
|
21343
|
+
case "tasks/cancel":
|
|
21344
|
+
if (!this._capabilities.tasks) {
|
|
21345
|
+
throw new Error(`Server does not support tasks capability (required for ${method})`);
|
|
21346
|
+
}
|
|
21347
|
+
break;
|
|
21348
|
+
}
|
|
21349
|
+
}
|
|
21350
|
+
assertTaskCapability(method) {
|
|
21351
|
+
assertClientRequestTaskCapability(this._clientCapabilities?.tasks?.requests, method, "Client");
|
|
21352
|
+
}
|
|
21353
|
+
assertTaskHandlerCapability(method) {
|
|
21354
|
+
if (!this._capabilities) {
|
|
21355
|
+
return;
|
|
19968
21356
|
}
|
|
21357
|
+
assertToolsCallTaskCapability(this._capabilities.tasks?.requests, method, "Server");
|
|
19969
21358
|
}
|
|
19970
21359
|
async _oninitialize(request) {
|
|
19971
21360
|
const requestedVersion = request.params.protocolVersion;
|
|
@@ -19997,10 +21386,10 @@ class Server extends Protocol {
|
|
|
19997
21386
|
async ping() {
|
|
19998
21387
|
return this.request({ method: "ping" }, EmptyResultSchema);
|
|
19999
21388
|
}
|
|
21389
|
+
// Implementation
|
|
20000
21390
|
async createMessage(params, options) {
|
|
20001
|
-
var _a, _b;
|
|
20002
21391
|
if (params.tools || params.toolChoice) {
|
|
20003
|
-
if (!
|
|
21392
|
+
if (!this._clientCapabilities?.sampling?.tools) {
|
|
20004
21393
|
throw new Error("Client does not support sampling tools capability.");
|
|
20005
21394
|
}
|
|
20006
21395
|
}
|
|
@@ -20027,6 +21416,9 @@ class Server extends Protocol {
|
|
|
20027
21416
|
}
|
|
20028
21417
|
}
|
|
20029
21418
|
}
|
|
21419
|
+
if (params.tools) {
|
|
21420
|
+
return this.request({ method: "sampling/createMessage", params }, CreateMessageResultWithToolsSchema, options);
|
|
21421
|
+
}
|
|
20030
21422
|
return this.request({ method: "sampling/createMessage", params }, CreateMessageResultSchema, options);
|
|
20031
21423
|
}
|
|
20032
21424
|
/**
|
|
@@ -20037,18 +21429,17 @@ class Server extends Protocol {
|
|
|
20037
21429
|
* @returns The result of the elicitation request.
|
|
20038
21430
|
*/
|
|
20039
21431
|
async elicitInput(params, options) {
|
|
20040
|
-
|
|
20041
|
-
const mode = (_a = params.mode) !== null && _a !== void 0 ? _a : "form";
|
|
21432
|
+
const mode = params.mode ?? "form";
|
|
20042
21433
|
switch (mode) {
|
|
20043
21434
|
case "url": {
|
|
20044
|
-
if (!
|
|
21435
|
+
if (!this._clientCapabilities?.elicitation?.url) {
|
|
20045
21436
|
throw new Error("Client does not support url elicitation.");
|
|
20046
21437
|
}
|
|
20047
21438
|
const urlParams = params;
|
|
20048
21439
|
return this.request({ method: "elicitation/create", params: urlParams }, ElicitResultSchema, options);
|
|
20049
21440
|
}
|
|
20050
21441
|
case "form": {
|
|
20051
|
-
if (!
|
|
21442
|
+
if (!this._clientCapabilities?.elicitation?.form) {
|
|
20052
21443
|
throw new Error("Client does not support form elicitation.");
|
|
20053
21444
|
}
|
|
20054
21445
|
const formParams = params.mode === "form" ? params : { ...params, mode: "form" };
|
|
@@ -20080,8 +21471,7 @@ class Server extends Protocol {
|
|
|
20080
21471
|
* @returns A function that emits the completion notification when awaited.
|
|
20081
21472
|
*/
|
|
20082
21473
|
createElicitationCompletionNotifier(elicitationId, options) {
|
|
20083
|
-
|
|
20084
|
-
if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) {
|
|
21474
|
+
if (!this._clientCapabilities?.elicitation?.url) {
|
|
20085
21475
|
throw new Error("Client does not support URL elicitation (required for notifications/elicitation/complete)");
|
|
20086
21476
|
}
|
|
20087
21477
|
return () => this.notification({
|
|
@@ -20182,6 +21572,19 @@ function validateAndWarnToolName(name) {
|
|
|
20182
21572
|
issueToolNameWarning(name, result.warnings);
|
|
20183
21573
|
return result.isValid;
|
|
20184
21574
|
}
|
|
21575
|
+
class ExperimentalMcpServerTasks {
|
|
21576
|
+
constructor(_mcpServer) {
|
|
21577
|
+
this._mcpServer = _mcpServer;
|
|
21578
|
+
}
|
|
21579
|
+
registerToolTask(name, config2, handler) {
|
|
21580
|
+
const execution = { taskSupport: "required", ...config2.execution };
|
|
21581
|
+
if (execution.taskSupport === "forbidden") {
|
|
21582
|
+
throw new Error(`Cannot register task-based tool '${name}' with taskSupport 'forbidden'. Use registerTool() instead.`);
|
|
21583
|
+
}
|
|
21584
|
+
const mcpServerInternal = this._mcpServer;
|
|
21585
|
+
return mcpServerInternal._createRegisteredTool(name, config2.title, config2.description, config2.inputSchema, config2.outputSchema, config2.annotations, execution, config2._meta, handler);
|
|
21586
|
+
}
|
|
21587
|
+
}
|
|
20185
21588
|
class McpServer {
|
|
20186
21589
|
constructor(serverInfo, options) {
|
|
20187
21590
|
this._registeredResources = {};
|
|
@@ -20194,6 +21597,21 @@ class McpServer {
|
|
|
20194
21597
|
this._promptHandlersInitialized = false;
|
|
20195
21598
|
this.server = new Server(serverInfo, options);
|
|
20196
21599
|
}
|
|
21600
|
+
/**
|
|
21601
|
+
* Access experimental features.
|
|
21602
|
+
*
|
|
21603
|
+
* WARNING: These APIs are experimental and may change without notice.
|
|
21604
|
+
*
|
|
21605
|
+
* @experimental
|
|
21606
|
+
*/
|
|
21607
|
+
get experimental() {
|
|
21608
|
+
if (!this._experimental) {
|
|
21609
|
+
this._experimental = {
|
|
21610
|
+
tasks: new ExperimentalMcpServerTasks(this)
|
|
21611
|
+
};
|
|
21612
|
+
}
|
|
21613
|
+
return this._experimental;
|
|
21614
|
+
}
|
|
20197
21615
|
/**
|
|
20198
21616
|
* Attaches to the given transport, starts it, and starts listening for messages.
|
|
20199
21617
|
*
|
|
@@ -20233,6 +21651,7 @@ class McpServer {
|
|
|
20233
21651
|
}) : EMPTY_OBJECT_JSON_SCHEMA;
|
|
20234
21652
|
})(),
|
|
20235
21653
|
annotations: tool.annotations,
|
|
21654
|
+
execution: tool.execution,
|
|
20236
21655
|
_meta: tool._meta
|
|
20237
21656
|
};
|
|
20238
21657
|
if (tool.outputSchema) {
|
|
@@ -20248,39 +21667,33 @@ class McpServer {
|
|
|
20248
21667
|
})
|
|
20249
21668
|
}));
|
|
20250
21669
|
this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
20251
|
-
const tool = this._registeredTools[request.params.name];
|
|
20252
|
-
let result;
|
|
20253
21670
|
try {
|
|
21671
|
+
const tool = this._registeredTools[request.params.name];
|
|
20254
21672
|
if (!tool) {
|
|
20255
21673
|
throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} not found`);
|
|
20256
21674
|
}
|
|
20257
21675
|
if (!tool.enabled) {
|
|
20258
21676
|
throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
|
|
20259
21677
|
}
|
|
20260
|
-
|
|
20261
|
-
|
|
20262
|
-
|
|
20263
|
-
|
|
20264
|
-
|
|
20265
|
-
if (!parseResult.success) {
|
|
20266
|
-
throw new McpError(ErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${request.params.name}: ${getParseErrorMessage(parseResult.error)}`);
|
|
20267
|
-
}
|
|
20268
|
-
const args = parseResult.data;
|
|
20269
|
-
result = await Promise.resolve(cb(args, extra));
|
|
20270
|
-
} else {
|
|
20271
|
-
const cb = tool.callback;
|
|
20272
|
-
result = await Promise.resolve(cb(extra));
|
|
21678
|
+
const isTaskRequest = !!request.params.task;
|
|
21679
|
+
const taskSupport = tool.execution?.taskSupport;
|
|
21680
|
+
const isTaskHandler = "createTask" in tool.handler;
|
|
21681
|
+
if ((taskSupport === "required" || taskSupport === "optional") && !isTaskHandler) {
|
|
21682
|
+
throw new McpError(ErrorCode.InternalError, `Tool ${request.params.name} has taskSupport '${taskSupport}' but was not registered with registerToolTask`);
|
|
20273
21683
|
}
|
|
20274
|
-
if (
|
|
20275
|
-
|
|
20276
|
-
|
|
20277
|
-
|
|
20278
|
-
|
|
20279
|
-
|
|
20280
|
-
|
|
20281
|
-
|
|
20282
|
-
|
|
21684
|
+
if (taskSupport === "required" && !isTaskRequest) {
|
|
21685
|
+
throw new McpError(ErrorCode.MethodNotFound, `Tool ${request.params.name} requires task augmentation (taskSupport: 'required')`);
|
|
21686
|
+
}
|
|
21687
|
+
if (taskSupport === "optional" && !isTaskRequest && isTaskHandler) {
|
|
21688
|
+
return await this.handleAutomaticTaskPolling(tool, request, extra);
|
|
21689
|
+
}
|
|
21690
|
+
const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);
|
|
21691
|
+
const result = await this.executeToolHandler(tool, args, extra);
|
|
21692
|
+
if (isTaskRequest) {
|
|
21693
|
+
return result;
|
|
20283
21694
|
}
|
|
21695
|
+
await this.validateToolOutput(tool, result, request.params.name);
|
|
21696
|
+
return result;
|
|
20284
21697
|
} catch (error) {
|
|
20285
21698
|
if (error instanceof McpError) {
|
|
20286
21699
|
if (error.code === ErrorCode.UrlElicitationRequired) {
|
|
@@ -20289,7 +21702,6 @@ class McpServer {
|
|
|
20289
21702
|
}
|
|
20290
21703
|
return this.createToolError(error instanceof Error ? error.message : String(error));
|
|
20291
21704
|
}
|
|
20292
|
-
return result;
|
|
20293
21705
|
});
|
|
20294
21706
|
this._toolHandlersInitialized = true;
|
|
20295
21707
|
}
|
|
@@ -20310,6 +21722,101 @@ class McpServer {
|
|
|
20310
21722
|
isError: true
|
|
20311
21723
|
};
|
|
20312
21724
|
}
|
|
21725
|
+
/**
|
|
21726
|
+
* Validates tool input arguments against the tool's input schema.
|
|
21727
|
+
*/
|
|
21728
|
+
async validateToolInput(tool, args, toolName) {
|
|
21729
|
+
if (!tool.inputSchema) {
|
|
21730
|
+
return void 0;
|
|
21731
|
+
}
|
|
21732
|
+
const inputObj = normalizeObjectSchema(tool.inputSchema);
|
|
21733
|
+
const schemaToParse = inputObj ?? tool.inputSchema;
|
|
21734
|
+
const parseResult = await safeParseAsync(schemaToParse, args);
|
|
21735
|
+
if (!parseResult.success) {
|
|
21736
|
+
const error = "error" in parseResult ? parseResult.error : "Unknown error";
|
|
21737
|
+
const errorMessage = getParseErrorMessage(error);
|
|
21738
|
+
throw new McpError(ErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName}: ${errorMessage}`);
|
|
21739
|
+
}
|
|
21740
|
+
return parseResult.data;
|
|
21741
|
+
}
|
|
21742
|
+
/**
|
|
21743
|
+
* Validates tool output against the tool's output schema.
|
|
21744
|
+
*/
|
|
21745
|
+
async validateToolOutput(tool, result, toolName) {
|
|
21746
|
+
if (!tool.outputSchema) {
|
|
21747
|
+
return;
|
|
21748
|
+
}
|
|
21749
|
+
if (!("content" in result)) {
|
|
21750
|
+
return;
|
|
21751
|
+
}
|
|
21752
|
+
if (result.isError) {
|
|
21753
|
+
return;
|
|
21754
|
+
}
|
|
21755
|
+
if (!result.structuredContent) {
|
|
21756
|
+
throw new McpError(ErrorCode.InvalidParams, `Output validation error: Tool ${toolName} has an output schema but no structured content was provided`);
|
|
21757
|
+
}
|
|
21758
|
+
const outputObj = normalizeObjectSchema(tool.outputSchema);
|
|
21759
|
+
const parseResult = await safeParseAsync(outputObj, result.structuredContent);
|
|
21760
|
+
if (!parseResult.success) {
|
|
21761
|
+
const error = "error" in parseResult ? parseResult.error : "Unknown error";
|
|
21762
|
+
const errorMessage = getParseErrorMessage(error);
|
|
21763
|
+
throw new McpError(ErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName}: ${errorMessage}`);
|
|
21764
|
+
}
|
|
21765
|
+
}
|
|
21766
|
+
/**
|
|
21767
|
+
* Executes a tool handler (either regular or task-based).
|
|
21768
|
+
*/
|
|
21769
|
+
async executeToolHandler(tool, args, extra) {
|
|
21770
|
+
const handler = tool.handler;
|
|
21771
|
+
const isTaskHandler = "createTask" in handler;
|
|
21772
|
+
if (isTaskHandler) {
|
|
21773
|
+
if (!extra.taskStore) {
|
|
21774
|
+
throw new Error("No task store provided.");
|
|
21775
|
+
}
|
|
21776
|
+
const taskExtra = { ...extra, taskStore: extra.taskStore };
|
|
21777
|
+
if (tool.inputSchema) {
|
|
21778
|
+
const typedHandler = handler;
|
|
21779
|
+
return await Promise.resolve(typedHandler.createTask(args, taskExtra));
|
|
21780
|
+
} else {
|
|
21781
|
+
const typedHandler = handler;
|
|
21782
|
+
return await Promise.resolve(typedHandler.createTask(taskExtra));
|
|
21783
|
+
}
|
|
21784
|
+
}
|
|
21785
|
+
if (tool.inputSchema) {
|
|
21786
|
+
const typedHandler = handler;
|
|
21787
|
+
return await Promise.resolve(typedHandler(args, extra));
|
|
21788
|
+
} else {
|
|
21789
|
+
const typedHandler = handler;
|
|
21790
|
+
return await Promise.resolve(typedHandler(extra));
|
|
21791
|
+
}
|
|
21792
|
+
}
|
|
21793
|
+
/**
|
|
21794
|
+
* Handles automatic task polling for tools with taskSupport 'optional'.
|
|
21795
|
+
*/
|
|
21796
|
+
async handleAutomaticTaskPolling(tool, request, extra) {
|
|
21797
|
+
if (!extra.taskStore) {
|
|
21798
|
+
throw new Error("No task store provided for task-capable tool.");
|
|
21799
|
+
}
|
|
21800
|
+
const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);
|
|
21801
|
+
const handler = tool.handler;
|
|
21802
|
+
const taskExtra = { ...extra, taskStore: extra.taskStore };
|
|
21803
|
+
const createTaskResult = args ? await Promise.resolve(handler.createTask(args, taskExtra)) : (
|
|
21804
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21805
|
+
await Promise.resolve(handler.createTask(taskExtra))
|
|
21806
|
+
);
|
|
21807
|
+
const taskId = createTaskResult.task.taskId;
|
|
21808
|
+
let task = createTaskResult.task;
|
|
21809
|
+
const pollInterval = task.pollInterval ?? 5e3;
|
|
21810
|
+
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
21811
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
21812
|
+
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
21813
|
+
if (!updatedTask) {
|
|
21814
|
+
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
21815
|
+
}
|
|
21816
|
+
task = updatedTask;
|
|
21817
|
+
}
|
|
21818
|
+
return await extra.taskStore.getTaskResult(taskId);
|
|
21819
|
+
}
|
|
20313
21820
|
setCompletionRequestHandler() {
|
|
20314
21821
|
if (this._completionHandlerInitialized) {
|
|
20315
21822
|
return;
|
|
@@ -20344,7 +21851,7 @@ class McpServer {
|
|
|
20344
21851
|
return EMPTY_COMPLETION_RESULT;
|
|
20345
21852
|
}
|
|
20346
21853
|
const promptShape = getObjectShape(prompt.argsSchema);
|
|
20347
|
-
const field = promptShape
|
|
21854
|
+
const field = promptShape?.[request.params.argument.name];
|
|
20348
21855
|
if (!isCompletable(field)) {
|
|
20349
21856
|
return EMPTY_COMPLETION_RESULT;
|
|
20350
21857
|
}
|
|
@@ -20429,7 +21936,6 @@ class McpServer {
|
|
|
20429
21936
|
}
|
|
20430
21937
|
throw new McpError(ErrorCode.InvalidParams, `Resource ${uri2} not found`);
|
|
20431
21938
|
});
|
|
20432
|
-
this.setCompletionRequestHandler();
|
|
20433
21939
|
this._resourceHandlersInitialized = true;
|
|
20434
21940
|
}
|
|
20435
21941
|
setPromptRequestHandlers() {
|
|
@@ -20465,7 +21971,9 @@ class McpServer {
|
|
|
20465
21971
|
const argsObj = normalizeObjectSchema(prompt.argsSchema);
|
|
20466
21972
|
const parseResult = await safeParseAsync(argsObj, request.params.arguments);
|
|
20467
21973
|
if (!parseResult.success) {
|
|
20468
|
-
|
|
21974
|
+
const error = "error" in parseResult ? parseResult.error : "Unknown error";
|
|
21975
|
+
const errorMessage = getParseErrorMessage(error);
|
|
21976
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for prompt ${request.params.name}: ${errorMessage}`);
|
|
20469
21977
|
}
|
|
20470
21978
|
const args = parseResult.data;
|
|
20471
21979
|
const cb = prompt.callback;
|
|
@@ -20475,7 +21983,6 @@ class McpServer {
|
|
|
20475
21983
|
return await Promise.resolve(cb(extra));
|
|
20476
21984
|
}
|
|
20477
21985
|
});
|
|
20478
|
-
this.setCompletionRequestHandler();
|
|
20479
21986
|
this._promptHandlersInitialized = true;
|
|
20480
21987
|
}
|
|
20481
21988
|
resource(name, uriOrTemplate, ...rest) {
|
|
@@ -20583,6 +22090,11 @@ class McpServer {
|
|
|
20583
22090
|
}
|
|
20584
22091
|
};
|
|
20585
22092
|
this._registeredResourceTemplates[name] = registeredResourceTemplate;
|
|
22093
|
+
const variableNames = template.uriTemplate.variableNames;
|
|
22094
|
+
const hasCompleter = Array.isArray(variableNames) && variableNames.some((v) => !!template.completeCallback(v));
|
|
22095
|
+
if (hasCompleter) {
|
|
22096
|
+
this.setCompletionRequestHandler();
|
|
22097
|
+
}
|
|
20586
22098
|
return registeredResourceTemplate;
|
|
20587
22099
|
}
|
|
20588
22100
|
_createRegisteredPrompt(name, title2, description2, argsSchema, callback) {
|
|
@@ -20615,9 +22127,18 @@ class McpServer {
|
|
|
20615
22127
|
}
|
|
20616
22128
|
};
|
|
20617
22129
|
this._registeredPrompts[name] = registeredPrompt;
|
|
22130
|
+
if (argsSchema) {
|
|
22131
|
+
const hasCompletable = Object.values(argsSchema).some((field) => {
|
|
22132
|
+
const inner = field instanceof ZodOptional ? field._def?.innerType : field;
|
|
22133
|
+
return isCompletable(inner);
|
|
22134
|
+
});
|
|
22135
|
+
if (hasCompletable) {
|
|
22136
|
+
this.setCompletionRequestHandler();
|
|
22137
|
+
}
|
|
22138
|
+
}
|
|
20618
22139
|
return registeredPrompt;
|
|
20619
22140
|
}
|
|
20620
|
-
_createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, _meta,
|
|
22141
|
+
_createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, execution, _meta, handler) {
|
|
20621
22142
|
validateAndWarnToolName(name);
|
|
20622
22143
|
const registeredTool = {
|
|
20623
22144
|
title: title2,
|
|
@@ -20625,8 +22146,9 @@ class McpServer {
|
|
|
20625
22146
|
inputSchema: getZodSchemaObject(inputSchema),
|
|
20626
22147
|
outputSchema: getZodSchemaObject(outputSchema),
|
|
20627
22148
|
annotations,
|
|
22149
|
+
execution,
|
|
20628
22150
|
_meta,
|
|
20629
|
-
|
|
22151
|
+
handler,
|
|
20630
22152
|
enabled: true,
|
|
20631
22153
|
disable: () => registeredTool.update({ enabled: false }),
|
|
20632
22154
|
enable: () => registeredTool.update({ enabled: true }),
|
|
@@ -20646,8 +22168,10 @@ class McpServer {
|
|
|
20646
22168
|
registeredTool.description = updates.description;
|
|
20647
22169
|
if (typeof updates.paramsSchema !== "undefined")
|
|
20648
22170
|
registeredTool.inputSchema = objectFromShape(updates.paramsSchema);
|
|
22171
|
+
if (typeof updates.outputSchema !== "undefined")
|
|
22172
|
+
registeredTool.outputSchema = objectFromShape(updates.outputSchema);
|
|
20649
22173
|
if (typeof updates.callback !== "undefined")
|
|
20650
|
-
registeredTool.
|
|
22174
|
+
registeredTool.handler = updates.callback;
|
|
20651
22175
|
if (typeof updates.annotations !== "undefined")
|
|
20652
22176
|
registeredTool.annotations = updates.annotations;
|
|
20653
22177
|
if (typeof updates._meta !== "undefined")
|
|
@@ -20678,9 +22202,9 @@ class McpServer {
|
|
|
20678
22202
|
}
|
|
20679
22203
|
if (rest.length > 1) {
|
|
20680
22204
|
const firstArg = rest[0];
|
|
20681
|
-
if (
|
|
22205
|
+
if (isZodRawShapeCompat(firstArg)) {
|
|
20682
22206
|
inputSchema = rest.shift();
|
|
20683
|
-
if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !
|
|
22207
|
+
if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !isZodRawShapeCompat(rest[0])) {
|
|
20684
22208
|
annotations = rest.shift();
|
|
20685
22209
|
}
|
|
20686
22210
|
} else if (typeof firstArg === "object" && firstArg !== null) {
|
|
@@ -20688,7 +22212,7 @@ class McpServer {
|
|
|
20688
22212
|
}
|
|
20689
22213
|
}
|
|
20690
22214
|
const callback = rest[0];
|
|
20691
|
-
return this._createRegisteredTool(name, void 0, description2, inputSchema, outputSchema, annotations, void 0, callback);
|
|
22215
|
+
return this._createRegisteredTool(name, void 0, description2, inputSchema, outputSchema, annotations, { taskSupport: "forbidden" }, void 0, callback);
|
|
20692
22216
|
}
|
|
20693
22217
|
/**
|
|
20694
22218
|
* Registers a tool with a config object and callback.
|
|
@@ -20698,7 +22222,7 @@ class McpServer {
|
|
|
20698
22222
|
throw new Error(`Tool ${name} is already registered`);
|
|
20699
22223
|
}
|
|
20700
22224
|
const { title: title2, description: description2, inputSchema, outputSchema, annotations, _meta } = config2;
|
|
20701
|
-
return this._createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, _meta, cb);
|
|
22225
|
+
return this._createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, { taskSupport: "forbidden" }, _meta, cb);
|
|
20702
22226
|
}
|
|
20703
22227
|
prompt(name, ...rest) {
|
|
20704
22228
|
if (this._registeredPrompts[name]) {
|
|
@@ -20794,28 +22318,36 @@ class ResourceTemplate {
|
|
|
20794
22318
|
* Gets the callback for completing a specific URI template variable, if one was provided.
|
|
20795
22319
|
*/
|
|
20796
22320
|
completeCallback(variable) {
|
|
20797
|
-
|
|
20798
|
-
return (_a = this._callbacks.complete) === null || _a === void 0 ? void 0 : _a[variable];
|
|
22321
|
+
return this._callbacks.complete?.[variable];
|
|
20799
22322
|
}
|
|
20800
22323
|
}
|
|
20801
22324
|
const EMPTY_OBJECT_JSON_SCHEMA = {
|
|
20802
22325
|
type: "object",
|
|
20803
22326
|
properties: {}
|
|
20804
22327
|
};
|
|
20805
|
-
function isZodRawShape(obj) {
|
|
20806
|
-
if (typeof obj !== "object" || obj === null)
|
|
20807
|
-
return false;
|
|
20808
|
-
const isEmptyObject = Object.keys(obj).length === 0;
|
|
20809
|
-
return isEmptyObject || Object.values(obj).some(isZodTypeLike);
|
|
20810
|
-
}
|
|
20811
22328
|
function isZodTypeLike(value) {
|
|
20812
22329
|
return value !== null && typeof value === "object" && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
20813
22330
|
}
|
|
22331
|
+
function isZodSchemaInstance(obj) {
|
|
22332
|
+
return "_def" in obj || "_zod" in obj || isZodTypeLike(obj);
|
|
22333
|
+
}
|
|
22334
|
+
function isZodRawShapeCompat(obj) {
|
|
22335
|
+
if (typeof obj !== "object" || obj === null) {
|
|
22336
|
+
return false;
|
|
22337
|
+
}
|
|
22338
|
+
if (isZodSchemaInstance(obj)) {
|
|
22339
|
+
return false;
|
|
22340
|
+
}
|
|
22341
|
+
if (Object.keys(obj).length === 0) {
|
|
22342
|
+
return true;
|
|
22343
|
+
}
|
|
22344
|
+
return Object.values(obj).some(isZodTypeLike);
|
|
22345
|
+
}
|
|
20814
22346
|
function getZodSchemaObject(schema) {
|
|
20815
22347
|
if (!schema) {
|
|
20816
22348
|
return void 0;
|
|
20817
22349
|
}
|
|
20818
|
-
if (
|
|
22350
|
+
if (isZodRawShapeCompat(schema)) {
|
|
20819
22351
|
return objectFromShape(schema);
|
|
20820
22352
|
}
|
|
20821
22353
|
return schema;
|
|
@@ -20836,7 +22368,7 @@ function promptArgumentsFromSchema(schema) {
|
|
|
20836
22368
|
}
|
|
20837
22369
|
function getMethodValue(schema) {
|
|
20838
22370
|
const shape = getObjectShape(schema);
|
|
20839
|
-
const methodSchema = shape
|
|
22371
|
+
const methodSchema = shape?.method;
|
|
20840
22372
|
if (!methodSchema) {
|
|
20841
22373
|
throw new Error("Schema is missing a method literal");
|
|
20842
22374
|
}
|
|
@@ -20862,7 +22394,8 @@ const EMPTY_COMPLETION_RESULT = {
|
|
|
20862
22394
|
}
|
|
20863
22395
|
};
|
|
20864
22396
|
export {
|
|
20865
|
-
|
|
22397
|
+
Ajv,
|
|
22398
|
+
AnnotationsSchema,
|
|
20866
22399
|
AudioContentSchema,
|
|
20867
22400
|
BaseMetadataSchema,
|
|
20868
22401
|
BlobResourceContentsSchema,
|
|
@@ -20871,6 +22404,8 @@ export {
|
|
|
20871
22404
|
CallToolRequestParamsSchema,
|
|
20872
22405
|
CallToolRequestSchema,
|
|
20873
22406
|
CallToolResultSchema,
|
|
22407
|
+
CancelTaskRequestSchema,
|
|
22408
|
+
CancelTaskResultSchema,
|
|
20874
22409
|
CancelledNotificationParamsSchema,
|
|
20875
22410
|
CancelledNotificationSchema,
|
|
20876
22411
|
Client,
|
|
@@ -20878,6 +22413,7 @@ export {
|
|
|
20878
22413
|
ClientNotificationSchema,
|
|
20879
22414
|
ClientRequestSchema,
|
|
20880
22415
|
ClientResultSchema,
|
|
22416
|
+
ClientTasksCapabilitySchema,
|
|
20881
22417
|
CompatibilityCallToolResultSchema,
|
|
20882
22418
|
CompleteRequestParamsSchema,
|
|
20883
22419
|
CompleteRequestSchema,
|
|
@@ -20886,6 +22422,8 @@ export {
|
|
|
20886
22422
|
CreateMessageRequestParamsSchema,
|
|
20887
22423
|
CreateMessageRequestSchema,
|
|
20888
22424
|
CreateMessageResultSchema,
|
|
22425
|
+
CreateMessageResultWithToolsSchema,
|
|
22426
|
+
CreateTaskResultSchema,
|
|
20889
22427
|
CursorSchema,
|
|
20890
22428
|
DEFAULT_NEGOTIATED_PROTOCOL_VERSION,
|
|
20891
22429
|
DEFAULT_REQUEST_TIMEOUT_MSEC,
|
|
@@ -20903,6 +22441,10 @@ export {
|
|
|
20903
22441
|
GetPromptRequestParamsSchema,
|
|
20904
22442
|
GetPromptRequestSchema,
|
|
20905
22443
|
GetPromptResultSchema,
|
|
22444
|
+
GetTaskPayloadRequestSchema,
|
|
22445
|
+
GetTaskPayloadResultSchema,
|
|
22446
|
+
GetTaskRequestSchema,
|
|
22447
|
+
GetTaskResultSchema,
|
|
20906
22448
|
IconSchema,
|
|
20907
22449
|
IconsSchema,
|
|
20908
22450
|
ImageContentSchema,
|
|
@@ -20911,14 +22453,17 @@ export {
|
|
|
20911
22453
|
InitializeRequestSchema,
|
|
20912
22454
|
InitializeResultSchema,
|
|
20913
22455
|
InitializedNotificationSchema,
|
|
22456
|
+
JSONRPCErrorResponseSchema,
|
|
20914
22457
|
JSONRPCErrorSchema,
|
|
20915
22458
|
JSONRPCMessageSchema,
|
|
20916
22459
|
JSONRPCNotificationSchema,
|
|
20917
22460
|
JSONRPCRequestSchema,
|
|
20918
22461
|
JSONRPCResponseSchema,
|
|
22462
|
+
JSONRPCResultResponseSchema,
|
|
20919
22463
|
JSONRPC_VERSION,
|
|
20920
22464
|
LATEST_PROTOCOL_VERSION,
|
|
20921
22465
|
LegacyTitledEnumSchemaSchema,
|
|
22466
|
+
ListChangedOptionsBaseSchema,
|
|
20922
22467
|
ListPromptsRequestSchema,
|
|
20923
22468
|
ListPromptsResultSchema,
|
|
20924
22469
|
ListResourceTemplatesRequestSchema,
|
|
@@ -20927,6 +22472,8 @@ export {
|
|
|
20927
22472
|
ListResourcesResultSchema,
|
|
20928
22473
|
ListRootsRequestSchema,
|
|
20929
22474
|
ListRootsResultSchema,
|
|
22475
|
+
ListTasksRequestSchema,
|
|
22476
|
+
ListTasksResultSchema,
|
|
20930
22477
|
ListToolsRequestSchema,
|
|
20931
22478
|
ListToolsResultSchema,
|
|
20932
22479
|
LoggingLevelSchema,
|
|
@@ -20955,9 +22502,11 @@ export {
|
|
|
20955
22502
|
PromptReferenceSchema,
|
|
20956
22503
|
PromptSchema,
|
|
20957
22504
|
Protocol,
|
|
22505
|
+
RELATED_TASK_META_KEY,
|
|
20958
22506
|
ReadResourceRequestParamsSchema,
|
|
20959
22507
|
ReadResourceRequestSchema,
|
|
20960
22508
|
ReadResourceResultSchema,
|
|
22509
|
+
RelatedTaskMetadataSchema,
|
|
20961
22510
|
RequestIdSchema,
|
|
20962
22511
|
RequestSchema,
|
|
20963
22512
|
ResourceContentsSchema,
|
|
@@ -20972,16 +22521,19 @@ export {
|
|
|
20972
22521
|
ResourceUpdatedNotificationParamsSchema,
|
|
20973
22522
|
ResourceUpdatedNotificationSchema,
|
|
20974
22523
|
ResultSchema,
|
|
22524
|
+
RoleSchema,
|
|
20975
22525
|
RootSchema,
|
|
20976
22526
|
RootsListChangedNotificationSchema,
|
|
20977
22527
|
SSEClientTransport,
|
|
20978
22528
|
SUPPORTED_PROTOCOL_VERSIONS,
|
|
22529
|
+
SamplingContentSchema,
|
|
20979
22530
|
SamplingMessageContentBlockSchema,
|
|
20980
22531
|
SamplingMessageSchema,
|
|
20981
22532
|
ServerCapabilitiesSchema,
|
|
20982
22533
|
ServerNotificationSchema,
|
|
20983
22534
|
ServerRequestSchema,
|
|
20984
22535
|
ServerResultSchema,
|
|
22536
|
+
ServerTasksCapabilitySchema,
|
|
20985
22537
|
SetLevelRequestParamsSchema,
|
|
20986
22538
|
SetLevelRequestSchema,
|
|
20987
22539
|
SingleSelectEnumSchemaSchema,
|
|
@@ -20991,12 +22543,20 @@ export {
|
|
|
20991
22543
|
StringSchemaSchema,
|
|
20992
22544
|
SubscribeRequestParamsSchema,
|
|
20993
22545
|
SubscribeRequestSchema,
|
|
22546
|
+
TaskAugmentedRequestParamsSchema,
|
|
22547
|
+
TaskCreationParamsSchema,
|
|
22548
|
+
TaskMetadataSchema,
|
|
22549
|
+
TaskSchema,
|
|
22550
|
+
TaskStatusNotificationParamsSchema,
|
|
22551
|
+
TaskStatusNotificationSchema,
|
|
22552
|
+
TaskStatusSchema,
|
|
20994
22553
|
TextContentSchema,
|
|
20995
22554
|
TextResourceContentsSchema,
|
|
20996
22555
|
TitledMultiSelectEnumSchemaSchema,
|
|
20997
22556
|
TitledSingleSelectEnumSchemaSchema,
|
|
20998
22557
|
ToolAnnotationsSchema,
|
|
20999
22558
|
ToolChoiceSchema,
|
|
22559
|
+
ToolExecutionSchema,
|
|
21000
22560
|
ToolListChangedNotificationSchema,
|
|
21001
22561
|
ToolResultContentSchema,
|
|
21002
22562
|
ToolSchema,
|
|
@@ -21020,6 +22580,7 @@ export {
|
|
|
21020
22580
|
exchangeAuthorization,
|
|
21021
22581
|
extractResourceMetadataUrl,
|
|
21022
22582
|
extractWWWAuthenticateParams,
|
|
22583
|
+
fetchToken,
|
|
21023
22584
|
getCompleter,
|
|
21024
22585
|
getDisplayName,
|
|
21025
22586
|
getSupportedElicitationModes,
|
|
@@ -21028,12 +22589,16 @@ export {
|
|
|
21028
22589
|
isInitializeRequest,
|
|
21029
22590
|
isInitializedNotification,
|
|
21030
22591
|
isJSONRPCError,
|
|
22592
|
+
isJSONRPCErrorResponse,
|
|
21031
22593
|
isJSONRPCNotification,
|
|
21032
22594
|
isJSONRPCRequest,
|
|
21033
22595
|
isJSONRPCResponse,
|
|
22596
|
+
isJSONRPCResultResponse,
|
|
22597
|
+
isTaskAugmentedRequestParams,
|
|
21034
22598
|
mergeCapabilities,
|
|
21035
22599
|
normalizeHeaders,
|
|
21036
22600
|
parseErrorResponse,
|
|
22601
|
+
prepareAuthorizationCodeRequest,
|
|
21037
22602
|
refreshAuthorization,
|
|
21038
22603
|
registerClient,
|
|
21039
22604
|
selectClientAuthMethod,
|