@opentiny/next-sdk 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WebMcpClient.ts +17 -19
- package/WebMcpServer.ts +11 -8
- package/agent/AgentModelProvider.ts +2 -0
- package/agent/type.ts +1 -1
- package/dist/WebMcpClient.d.ts +176 -35
- package/dist/WebMcpServer.d.ts +43 -154
- 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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
function getDefaultExportFromCjs(x) {
|
|
6
6
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
7
7
|
}
|
|
8
|
-
var ajv
|
|
8
|
+
var ajv = { exports: {} };
|
|
9
9
|
var core$1 = {};
|
|
10
10
|
var validate = {};
|
|
11
11
|
var boolSchema = {};
|
|
@@ -3921,7 +3921,7 @@
|
|
|
3921
3921
|
uriResolver
|
|
3922
3922
|
};
|
|
3923
3923
|
}
|
|
3924
|
-
class
|
|
3924
|
+
class Ajv2 {
|
|
3925
3925
|
constructor(opts = {}) {
|
|
3926
3926
|
this.schemas = {};
|
|
3927
3927
|
this.refs = {};
|
|
@@ -4291,9 +4291,9 @@
|
|
|
4291
4291
|
}
|
|
4292
4292
|
}
|
|
4293
4293
|
}
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
exports3.default =
|
|
4294
|
+
Ajv2.ValidationError = validation_error_1.default;
|
|
4295
|
+
Ajv2.MissingRefError = ref_error_1.default;
|
|
4296
|
+
exports3.default = Ajv2;
|
|
4297
4297
|
function checkOptions(checkOpts, options, msg, log = "error") {
|
|
4298
4298
|
for (const key in checkOpts) {
|
|
4299
4299
|
const opt = key;
|
|
@@ -6245,7 +6245,7 @@
|
|
|
6245
6245
|
};
|
|
6246
6246
|
var hasRequiredAjv;
|
|
6247
6247
|
function requireAjv() {
|
|
6248
|
-
if (hasRequiredAjv) return ajv
|
|
6248
|
+
if (hasRequiredAjv) return ajv.exports;
|
|
6249
6249
|
hasRequiredAjv = 1;
|
|
6250
6250
|
(function(module2, exports3) {
|
|
6251
6251
|
Object.defineProperty(exports3, "__esModule", { value: true });
|
|
@@ -6256,7 +6256,7 @@
|
|
|
6256
6256
|
const draft7MetaSchema = require$$3;
|
|
6257
6257
|
const META_SUPPORT_DATA = ["/properties"];
|
|
6258
6258
|
const META_SCHEMA_ID = "http://json-schema.org/draft-07/schema";
|
|
6259
|
-
class
|
|
6259
|
+
class Ajv2 extends core_1.default {
|
|
6260
6260
|
_addVocabularies() {
|
|
6261
6261
|
super._addVocabularies();
|
|
6262
6262
|
draft7_1.default.forEach((v) => this.addVocabulary(v));
|
|
@@ -6275,11 +6275,11 @@
|
|
|
6275
6275
|
return this.opts.defaultMeta = super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : void 0);
|
|
6276
6276
|
}
|
|
6277
6277
|
}
|
|
6278
|
-
exports3.Ajv =
|
|
6279
|
-
module2.exports = exports3 =
|
|
6280
|
-
module2.exports.Ajv =
|
|
6278
|
+
exports3.Ajv = Ajv2;
|
|
6279
|
+
module2.exports = exports3 = Ajv2;
|
|
6280
|
+
module2.exports.Ajv = Ajv2;
|
|
6281
6281
|
Object.defineProperty(exports3, "__esModule", { value: true });
|
|
6282
|
-
exports3.default =
|
|
6282
|
+
exports3.default = Ajv2;
|
|
6283
6283
|
var validate_1 = requireValidate();
|
|
6284
6284
|
Object.defineProperty(exports3, "KeywordCxt", { enumerable: true, get: function() {
|
|
6285
6285
|
return validate_1.KeywordCxt;
|
|
@@ -6311,11 +6311,11 @@
|
|
|
6311
6311
|
Object.defineProperty(exports3, "MissingRefError", { enumerable: true, get: function() {
|
|
6312
6312
|
return ref_error_1.default;
|
|
6313
6313
|
} });
|
|
6314
|
-
})(ajv
|
|
6315
|
-
return ajv
|
|
6314
|
+
})(ajv, ajv.exports);
|
|
6315
|
+
return ajv.exports;
|
|
6316
6316
|
}
|
|
6317
6317
|
var ajvExports = requireAjv();
|
|
6318
|
-
const
|
|
6318
|
+
const Ajv = /* @__PURE__ */ getDefaultExportFromCjs(ajvExports);
|
|
6319
6319
|
const NEVER = Object.freeze({
|
|
6320
6320
|
status: "aborted"
|
|
6321
6321
|
});
|
|
@@ -6851,8 +6851,9 @@
|
|
|
6851
6851
|
return new RegExp(`^${regex}$`);
|
|
6852
6852
|
};
|
|
6853
6853
|
const integer = /^\d+$/;
|
|
6854
|
-
const number$
|
|
6854
|
+
const number$2 = /^-?\d+(?:\.\d+)?/i;
|
|
6855
6855
|
const boolean$1 = /true|false/i;
|
|
6856
|
+
const _null$2 = /null/i;
|
|
6856
6857
|
const lowercase = /^[^A-Z]*$/;
|
|
6857
6858
|
const uppercase = /^[^a-z]*$/;
|
|
6858
6859
|
const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
|
|
@@ -7662,7 +7663,7 @@
|
|
|
7662
7663
|
});
|
|
7663
7664
|
const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
|
|
7664
7665
|
$ZodType.init(inst, def);
|
|
7665
|
-
inst._zod.pattern = inst._zod.bag.pattern ?? number$
|
|
7666
|
+
inst._zod.pattern = inst._zod.bag.pattern ?? number$2;
|
|
7666
7667
|
inst._zod.parse = (payload, _ctx) => {
|
|
7667
7668
|
if (def.coerce)
|
|
7668
7669
|
try {
|
|
@@ -7709,6 +7710,23 @@
|
|
|
7709
7710
|
return payload;
|
|
7710
7711
|
};
|
|
7711
7712
|
});
|
|
7713
|
+
const $ZodNull = /* @__PURE__ */ $constructor("$ZodNull", (inst, def) => {
|
|
7714
|
+
$ZodType.init(inst, def);
|
|
7715
|
+
inst._zod.pattern = _null$2;
|
|
7716
|
+
inst._zod.values = /* @__PURE__ */ new Set([null]);
|
|
7717
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
7718
|
+
const input = payload.value;
|
|
7719
|
+
if (input === null)
|
|
7720
|
+
return payload;
|
|
7721
|
+
payload.issues.push({
|
|
7722
|
+
expected: "null",
|
|
7723
|
+
code: "invalid_type",
|
|
7724
|
+
input,
|
|
7725
|
+
inst
|
|
7726
|
+
});
|
|
7727
|
+
return payload;
|
|
7728
|
+
};
|
|
7729
|
+
});
|
|
7712
7730
|
const $ZodAny = /* @__PURE__ */ $constructor("$ZodAny", (inst, def) => {
|
|
7713
7731
|
$ZodType.init(inst, def);
|
|
7714
7732
|
inst._zod.parse = (payload) => payload;
|
|
@@ -8796,6 +8814,14 @@
|
|
|
8796
8814
|
...normalizeParams(params)
|
|
8797
8815
|
});
|
|
8798
8816
|
}
|
|
8817
|
+
function _coercedNumber(Class, params) {
|
|
8818
|
+
return new Class({
|
|
8819
|
+
type: "number",
|
|
8820
|
+
coerce: true,
|
|
8821
|
+
checks: [],
|
|
8822
|
+
...normalizeParams(params)
|
|
8823
|
+
});
|
|
8824
|
+
}
|
|
8799
8825
|
function _int(Class, params) {
|
|
8800
8826
|
return new Class({
|
|
8801
8827
|
type: "number",
|
|
@@ -8811,6 +8837,12 @@
|
|
|
8811
8837
|
...normalizeParams(params)
|
|
8812
8838
|
});
|
|
8813
8839
|
}
|
|
8840
|
+
function _null$1(Class, params) {
|
|
8841
|
+
return new Class({
|
|
8842
|
+
type: "null",
|
|
8843
|
+
...normalizeParams(params)
|
|
8844
|
+
});
|
|
8845
|
+
}
|
|
8814
8846
|
function _any(Class) {
|
|
8815
8847
|
return new Class({
|
|
8816
8848
|
type: "any"
|
|
@@ -10034,7 +10066,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10034
10066
|
inst.isFinite = true;
|
|
10035
10067
|
inst.format = bag.format ?? null;
|
|
10036
10068
|
});
|
|
10037
|
-
function number(params) {
|
|
10069
|
+
function number$1(params) {
|
|
10038
10070
|
return _number(ZodNumber$1, params);
|
|
10039
10071
|
}
|
|
10040
10072
|
const ZodNumberFormat = /* @__PURE__ */ $constructor("ZodNumberFormat", (inst, def) => {
|
|
@@ -10051,6 +10083,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10051
10083
|
function boolean(params) {
|
|
10052
10084
|
return _boolean(ZodBoolean$1, params);
|
|
10053
10085
|
}
|
|
10086
|
+
const ZodNull$1 = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
|
|
10087
|
+
$ZodNull.init(inst, def);
|
|
10088
|
+
ZodType$1.init(inst, def);
|
|
10089
|
+
});
|
|
10090
|
+
function _null(params) {
|
|
10091
|
+
return _null$1(ZodNull$1, params);
|
|
10092
|
+
}
|
|
10054
10093
|
const ZodAny$1 = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
|
|
10055
10094
|
$ZodAny.init(inst, def);
|
|
10056
10095
|
ZodType$1.init(inst, def);
|
|
@@ -10419,48 +10458,85 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10419
10458
|
const ZodIssueCode$1 = {
|
|
10420
10459
|
custom: "custom"
|
|
10421
10460
|
};
|
|
10422
|
-
|
|
10461
|
+
function number(params) {
|
|
10462
|
+
return _coercedNumber(ZodNumber$1, params);
|
|
10463
|
+
}
|
|
10464
|
+
const LATEST_PROTOCOL_VERSION = "2025-11-25";
|
|
10423
10465
|
const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
|
|
10424
|
-
const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-03-26", "2024-11-05", "2024-10-07"];
|
|
10466
|
+
const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
|
|
10467
|
+
const RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
10425
10468
|
const JSONRPC_VERSION = "2.0";
|
|
10426
10469
|
const AssertObjectSchema = custom((v) => v !== null && (typeof v === "object" || typeof v === "function"));
|
|
10427
|
-
const ProgressTokenSchema = union([string(), number().int()]);
|
|
10470
|
+
const ProgressTokenSchema = union([string(), number$1().int()]);
|
|
10428
10471
|
const CursorSchema = string();
|
|
10472
|
+
const TaskCreationParamsSchema = looseObject({
|
|
10473
|
+
/**
|
|
10474
|
+
* Time in milliseconds to keep task results available after completion.
|
|
10475
|
+
* If null, the task has unlimited lifetime until manually cleaned up.
|
|
10476
|
+
*/
|
|
10477
|
+
ttl: union([number$1(), _null()]).optional(),
|
|
10478
|
+
/**
|
|
10479
|
+
* Time in milliseconds to wait between task status requests.
|
|
10480
|
+
*/
|
|
10481
|
+
pollInterval: number$1().optional()
|
|
10482
|
+
});
|
|
10483
|
+
const TaskMetadataSchema = object$1({
|
|
10484
|
+
ttl: number$1().optional()
|
|
10485
|
+
});
|
|
10486
|
+
const RelatedTaskMetadataSchema = object$1({
|
|
10487
|
+
taskId: string()
|
|
10488
|
+
});
|
|
10429
10489
|
const RequestMetaSchema = looseObject({
|
|
10430
10490
|
/**
|
|
10431
10491
|
* 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.
|
|
10432
10492
|
*/
|
|
10433
|
-
progressToken: ProgressTokenSchema.optional()
|
|
10493
|
+
progressToken: ProgressTokenSchema.optional(),
|
|
10494
|
+
/**
|
|
10495
|
+
* If specified, this request is related to the provided task.
|
|
10496
|
+
*/
|
|
10497
|
+
[RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
|
|
10434
10498
|
});
|
|
10435
|
-
const BaseRequestParamsSchema =
|
|
10499
|
+
const BaseRequestParamsSchema = object$1({
|
|
10436
10500
|
/**
|
|
10437
10501
|
* See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
|
|
10438
10502
|
*/
|
|
10439
10503
|
_meta: RequestMetaSchema.optional()
|
|
10440
10504
|
});
|
|
10505
|
+
const TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
10506
|
+
/**
|
|
10507
|
+
* If specified, the caller is requesting task-augmented execution for this request.
|
|
10508
|
+
* The request will return a CreateTaskResult immediately, and the actual result can be
|
|
10509
|
+
* retrieved later via tasks/result.
|
|
10510
|
+
*
|
|
10511
|
+
* Task augmentation is subject to capability negotiation - receivers MUST declare support
|
|
10512
|
+
* for task augmentation of specific request types in their capabilities.
|
|
10513
|
+
*/
|
|
10514
|
+
task: TaskMetadataSchema.optional()
|
|
10515
|
+
});
|
|
10516
|
+
const isTaskAugmentedRequestParams = (value) => TaskAugmentedRequestParamsSchema.safeParse(value).success;
|
|
10441
10517
|
const RequestSchema = object$1({
|
|
10442
10518
|
method: string(),
|
|
10443
|
-
params: BaseRequestParamsSchema.optional()
|
|
10519
|
+
params: BaseRequestParamsSchema.loose().optional()
|
|
10444
10520
|
});
|
|
10445
|
-
const NotificationsParamsSchema =
|
|
10521
|
+
const NotificationsParamsSchema = object$1({
|
|
10446
10522
|
/**
|
|
10447
10523
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10448
10524
|
* for notes on _meta usage.
|
|
10449
10525
|
*/
|
|
10450
|
-
_meta:
|
|
10526
|
+
_meta: RequestMetaSchema.optional()
|
|
10451
10527
|
});
|
|
10452
10528
|
const NotificationSchema = object$1({
|
|
10453
10529
|
method: string(),
|
|
10454
|
-
params: NotificationsParamsSchema.optional()
|
|
10530
|
+
params: NotificationsParamsSchema.loose().optional()
|
|
10455
10531
|
});
|
|
10456
10532
|
const ResultSchema = looseObject({
|
|
10457
10533
|
/**
|
|
10458
10534
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10459
10535
|
* for notes on _meta usage.
|
|
10460
10536
|
*/
|
|
10461
|
-
_meta:
|
|
10537
|
+
_meta: RequestMetaSchema.optional()
|
|
10462
10538
|
});
|
|
10463
|
-
const RequestIdSchema = union([string(), number().int()]);
|
|
10539
|
+
const RequestIdSchema = union([string(), number$1().int()]);
|
|
10464
10540
|
const JSONRPCRequestSchema = object$1({
|
|
10465
10541
|
jsonrpc: literal(JSONRPC_VERSION),
|
|
10466
10542
|
id: RequestIdSchema,
|
|
@@ -10472,12 +10548,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10472
10548
|
...NotificationSchema.shape
|
|
10473
10549
|
}).strict();
|
|
10474
10550
|
const isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safeParse(value).success;
|
|
10475
|
-
const
|
|
10551
|
+
const JSONRPCResultResponseSchema = object$1({
|
|
10476
10552
|
jsonrpc: literal(JSONRPC_VERSION),
|
|
10477
10553
|
id: RequestIdSchema,
|
|
10478
10554
|
result: ResultSchema
|
|
10479
10555
|
}).strict();
|
|
10480
|
-
const
|
|
10556
|
+
const isJSONRPCResultResponse = (value) => JSONRPCResultResponseSchema.safeParse(value).success;
|
|
10557
|
+
const isJSONRPCResponse = isJSONRPCResultResponse;
|
|
10481
10558
|
exports2.ErrorCode = void 0;
|
|
10482
10559
|
(function(ErrorCode) {
|
|
10483
10560
|
ErrorCode[ErrorCode["ConnectionClosed"] = -32e3] = "ConnectionClosed";
|
|
@@ -10489,14 +10566,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10489
10566
|
ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError";
|
|
10490
10567
|
ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
|
|
10491
10568
|
})(exports2.ErrorCode || (exports2.ErrorCode = {}));
|
|
10492
|
-
const
|
|
10569
|
+
const JSONRPCErrorResponseSchema = object$1({
|
|
10493
10570
|
jsonrpc: literal(JSONRPC_VERSION),
|
|
10494
|
-
id: RequestIdSchema,
|
|
10571
|
+
id: RequestIdSchema.optional(),
|
|
10495
10572
|
error: object$1({
|
|
10496
10573
|
/**
|
|
10497
10574
|
* The error type that occurred.
|
|
10498
10575
|
*/
|
|
10499
|
-
code: number().int(),
|
|
10576
|
+
code: number$1().int(),
|
|
10500
10577
|
/**
|
|
10501
10578
|
* A short description of the error. The message SHOULD be limited to a concise single sentence.
|
|
10502
10579
|
*/
|
|
@@ -10504,11 +10581,19 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10504
10581
|
/**
|
|
10505
10582
|
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
10506
10583
|
*/
|
|
10507
|
-
data:
|
|
10584
|
+
data: unknown().optional()
|
|
10508
10585
|
})
|
|
10509
10586
|
}).strict();
|
|
10510
|
-
const
|
|
10511
|
-
const
|
|
10587
|
+
const JSONRPCErrorSchema = JSONRPCErrorResponseSchema;
|
|
10588
|
+
const isJSONRPCErrorResponse = (value) => JSONRPCErrorResponseSchema.safeParse(value).success;
|
|
10589
|
+
const isJSONRPCError = isJSONRPCErrorResponse;
|
|
10590
|
+
const JSONRPCMessageSchema = union([
|
|
10591
|
+
JSONRPCRequestSchema,
|
|
10592
|
+
JSONRPCNotificationSchema,
|
|
10593
|
+
JSONRPCResultResponseSchema,
|
|
10594
|
+
JSONRPCErrorResponseSchema
|
|
10595
|
+
]);
|
|
10596
|
+
const JSONRPCResponseSchema = union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
|
|
10512
10597
|
const EmptyResultSchema = ResultSchema.strict();
|
|
10513
10598
|
const CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
10514
10599
|
/**
|
|
@@ -10516,7 +10601,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10516
10601
|
*
|
|
10517
10602
|
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
10518
10603
|
*/
|
|
10519
|
-
requestId: RequestIdSchema,
|
|
10604
|
+
requestId: RequestIdSchema.optional(),
|
|
10520
10605
|
/**
|
|
10521
10606
|
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
10522
10607
|
*/
|
|
@@ -10541,7 +10626,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10541
10626
|
*
|
|
10542
10627
|
* If not provided, the client should assume that the icon can be used at any size.
|
|
10543
10628
|
*/
|
|
10544
|
-
sizes: array(string()).optional()
|
|
10629
|
+
sizes: array(string()).optional(),
|
|
10630
|
+
/**
|
|
10631
|
+
* Optional specifier for the theme this icon is designed for. `light` indicates
|
|
10632
|
+
* the icon is designed to be used with a light background, and `dark` indicates
|
|
10633
|
+
* the icon is designed to be used with a dark background.
|
|
10634
|
+
*
|
|
10635
|
+
* If not provided, the client should assume the icon can be used with any theme.
|
|
10636
|
+
*/
|
|
10637
|
+
theme: _enum(["light", "dark"]).optional()
|
|
10545
10638
|
});
|
|
10546
10639
|
const IconsSchema = object$1({
|
|
10547
10640
|
/**
|
|
@@ -10577,7 +10670,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10577
10670
|
/**
|
|
10578
10671
|
* An optional URL of the website for this implementation.
|
|
10579
10672
|
*/
|
|
10580
|
-
websiteUrl: string().optional()
|
|
10673
|
+
websiteUrl: string().optional(),
|
|
10674
|
+
/**
|
|
10675
|
+
* An optional human-readable description of what this implementation does.
|
|
10676
|
+
*
|
|
10677
|
+
* This can be used by clients or servers to provide context about their purpose
|
|
10678
|
+
* and capabilities. For example, a server might describe the types of resources
|
|
10679
|
+
* or tools it provides, while a client might describe its intended use case.
|
|
10680
|
+
*/
|
|
10681
|
+
description: string().optional()
|
|
10581
10682
|
});
|
|
10582
10683
|
const FormElicitationCapabilitySchema = intersection(object$1({
|
|
10583
10684
|
applyDefaults: boolean().optional()
|
|
@@ -10593,6 +10694,54 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10593
10694
|
form: FormElicitationCapabilitySchema.optional(),
|
|
10594
10695
|
url: AssertObjectSchema.optional()
|
|
10595
10696
|
}), record(string(), unknown()).optional()));
|
|
10697
|
+
const ClientTasksCapabilitySchema = looseObject({
|
|
10698
|
+
/**
|
|
10699
|
+
* Present if the client supports listing tasks.
|
|
10700
|
+
*/
|
|
10701
|
+
list: AssertObjectSchema.optional(),
|
|
10702
|
+
/**
|
|
10703
|
+
* Present if the client supports cancelling tasks.
|
|
10704
|
+
*/
|
|
10705
|
+
cancel: AssertObjectSchema.optional(),
|
|
10706
|
+
/**
|
|
10707
|
+
* Capabilities for task creation on specific request types.
|
|
10708
|
+
*/
|
|
10709
|
+
requests: looseObject({
|
|
10710
|
+
/**
|
|
10711
|
+
* Task support for sampling requests.
|
|
10712
|
+
*/
|
|
10713
|
+
sampling: looseObject({
|
|
10714
|
+
createMessage: AssertObjectSchema.optional()
|
|
10715
|
+
}).optional(),
|
|
10716
|
+
/**
|
|
10717
|
+
* Task support for elicitation requests.
|
|
10718
|
+
*/
|
|
10719
|
+
elicitation: looseObject({
|
|
10720
|
+
create: AssertObjectSchema.optional()
|
|
10721
|
+
}).optional()
|
|
10722
|
+
}).optional()
|
|
10723
|
+
});
|
|
10724
|
+
const ServerTasksCapabilitySchema = looseObject({
|
|
10725
|
+
/**
|
|
10726
|
+
* Present if the server supports listing tasks.
|
|
10727
|
+
*/
|
|
10728
|
+
list: AssertObjectSchema.optional(),
|
|
10729
|
+
/**
|
|
10730
|
+
* Present if the server supports cancelling tasks.
|
|
10731
|
+
*/
|
|
10732
|
+
cancel: AssertObjectSchema.optional(),
|
|
10733
|
+
/**
|
|
10734
|
+
* Capabilities for task creation on specific request types.
|
|
10735
|
+
*/
|
|
10736
|
+
requests: looseObject({
|
|
10737
|
+
/**
|
|
10738
|
+
* Task support for tool requests.
|
|
10739
|
+
*/
|
|
10740
|
+
tools: looseObject({
|
|
10741
|
+
call: AssertObjectSchema.optional()
|
|
10742
|
+
}).optional()
|
|
10743
|
+
}).optional()
|
|
10744
|
+
});
|
|
10596
10745
|
const ClientCapabilitiesSchema = object$1({
|
|
10597
10746
|
/**
|
|
10598
10747
|
* Experimental, non-standard capabilities that the client supports.
|
|
@@ -10624,7 +10773,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10624
10773
|
* Whether the client supports issuing notifications for changes to the roots list.
|
|
10625
10774
|
*/
|
|
10626
10775
|
listChanged: boolean().optional()
|
|
10627
|
-
}).optional()
|
|
10776
|
+
}).optional(),
|
|
10777
|
+
/**
|
|
10778
|
+
* Present if the client supports task creation.
|
|
10779
|
+
*/
|
|
10780
|
+
tasks: ClientTasksCapabilitySchema.optional()
|
|
10628
10781
|
});
|
|
10629
10782
|
const InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
10630
10783
|
/**
|
|
@@ -10655,12 +10808,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10655
10808
|
/**
|
|
10656
10809
|
* Present if the server offers any prompt templates.
|
|
10657
10810
|
*/
|
|
10658
|
-
prompts:
|
|
10811
|
+
prompts: object$1({
|
|
10659
10812
|
/**
|
|
10660
10813
|
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
10661
10814
|
*/
|
|
10662
|
-
listChanged:
|
|
10663
|
-
})),
|
|
10815
|
+
listChanged: boolean().optional()
|
|
10816
|
+
}).optional(),
|
|
10664
10817
|
/**
|
|
10665
10818
|
* Present if the server offers any resources to read.
|
|
10666
10819
|
*/
|
|
@@ -10682,7 +10835,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10682
10835
|
* Whether this server supports issuing notifications for changes to the tool list.
|
|
10683
10836
|
*/
|
|
10684
10837
|
listChanged: boolean().optional()
|
|
10685
|
-
}).optional()
|
|
10838
|
+
}).optional(),
|
|
10839
|
+
/**
|
|
10840
|
+
* Present if the server supports task creation.
|
|
10841
|
+
*/
|
|
10842
|
+
tasks: ServerTasksCapabilitySchema.optional()
|
|
10686
10843
|
});
|
|
10687
10844
|
const InitializeResultSchema = ResultSchema.extend({
|
|
10688
10845
|
/**
|
|
@@ -10699,21 +10856,23 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10699
10856
|
instructions: string().optional()
|
|
10700
10857
|
});
|
|
10701
10858
|
const InitializedNotificationSchema = NotificationSchema.extend({
|
|
10702
|
-
method: literal("notifications/initialized")
|
|
10859
|
+
method: literal("notifications/initialized"),
|
|
10860
|
+
params: NotificationsParamsSchema.optional()
|
|
10703
10861
|
});
|
|
10704
10862
|
const isInitializedNotification = (value) => InitializedNotificationSchema.safeParse(value).success;
|
|
10705
10863
|
const PingRequestSchema = RequestSchema.extend({
|
|
10706
|
-
method: literal("ping")
|
|
10864
|
+
method: literal("ping"),
|
|
10865
|
+
params: BaseRequestParamsSchema.optional()
|
|
10707
10866
|
});
|
|
10708
10867
|
const ProgressSchema = object$1({
|
|
10709
10868
|
/**
|
|
10710
10869
|
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
10711
10870
|
*/
|
|
10712
|
-
progress: number(),
|
|
10871
|
+
progress: number$1(),
|
|
10713
10872
|
/**
|
|
10714
10873
|
* Total number of items to process (or total progress required), if known.
|
|
10715
10874
|
*/
|
|
10716
|
-
total: optional(number()),
|
|
10875
|
+
total: optional(number$1()),
|
|
10717
10876
|
/**
|
|
10718
10877
|
* An optional message describing the current progress.
|
|
10719
10878
|
*/
|
|
@@ -10746,8 +10905,66 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10746
10905
|
* An opaque token representing the pagination position after the last returned result.
|
|
10747
10906
|
* If present, there may be more results available.
|
|
10748
10907
|
*/
|
|
10749
|
-
nextCursor: optional(
|
|
10908
|
+
nextCursor: CursorSchema.optional()
|
|
10909
|
+
});
|
|
10910
|
+
const TaskStatusSchema = _enum(["working", "input_required", "completed", "failed", "cancelled"]);
|
|
10911
|
+
const TaskSchema = object$1({
|
|
10912
|
+
taskId: string(),
|
|
10913
|
+
status: TaskStatusSchema,
|
|
10914
|
+
/**
|
|
10915
|
+
* Time in milliseconds to keep task results available after completion.
|
|
10916
|
+
* If null, the task has unlimited lifetime until manually cleaned up.
|
|
10917
|
+
*/
|
|
10918
|
+
ttl: union([number$1(), _null()]),
|
|
10919
|
+
/**
|
|
10920
|
+
* ISO 8601 timestamp when the task was created.
|
|
10921
|
+
*/
|
|
10922
|
+
createdAt: string(),
|
|
10923
|
+
/**
|
|
10924
|
+
* ISO 8601 timestamp when the task was last updated.
|
|
10925
|
+
*/
|
|
10926
|
+
lastUpdatedAt: string(),
|
|
10927
|
+
pollInterval: optional(number$1()),
|
|
10928
|
+
/**
|
|
10929
|
+
* Optional diagnostic message for failed tasks or other status information.
|
|
10930
|
+
*/
|
|
10931
|
+
statusMessage: optional(string())
|
|
10932
|
+
});
|
|
10933
|
+
const CreateTaskResultSchema = ResultSchema.extend({
|
|
10934
|
+
task: TaskSchema
|
|
10935
|
+
});
|
|
10936
|
+
const TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
|
|
10937
|
+
const TaskStatusNotificationSchema = NotificationSchema.extend({
|
|
10938
|
+
method: literal("notifications/tasks/status"),
|
|
10939
|
+
params: TaskStatusNotificationParamsSchema
|
|
10940
|
+
});
|
|
10941
|
+
const GetTaskRequestSchema = RequestSchema.extend({
|
|
10942
|
+
method: literal("tasks/get"),
|
|
10943
|
+
params: BaseRequestParamsSchema.extend({
|
|
10944
|
+
taskId: string()
|
|
10945
|
+
})
|
|
10946
|
+
});
|
|
10947
|
+
const GetTaskResultSchema = ResultSchema.merge(TaskSchema);
|
|
10948
|
+
const GetTaskPayloadRequestSchema = RequestSchema.extend({
|
|
10949
|
+
method: literal("tasks/result"),
|
|
10950
|
+
params: BaseRequestParamsSchema.extend({
|
|
10951
|
+
taskId: string()
|
|
10952
|
+
})
|
|
10953
|
+
});
|
|
10954
|
+
const GetTaskPayloadResultSchema = ResultSchema.loose();
|
|
10955
|
+
const ListTasksRequestSchema = PaginatedRequestSchema.extend({
|
|
10956
|
+
method: literal("tasks/list")
|
|
10957
|
+
});
|
|
10958
|
+
const ListTasksResultSchema = PaginatedResultSchema.extend({
|
|
10959
|
+
tasks: array(TaskSchema)
|
|
10960
|
+
});
|
|
10961
|
+
const CancelTaskRequestSchema = RequestSchema.extend({
|
|
10962
|
+
method: literal("tasks/cancel"),
|
|
10963
|
+
params: BaseRequestParamsSchema.extend({
|
|
10964
|
+
taskId: string()
|
|
10965
|
+
})
|
|
10750
10966
|
});
|
|
10967
|
+
const CancelTaskResultSchema = ResultSchema.merge(TaskSchema);
|
|
10751
10968
|
const ResourceContentsSchema = object$1({
|
|
10752
10969
|
/**
|
|
10753
10970
|
* The URI of this resource.
|
|
@@ -10773,7 +10990,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10773
10990
|
try {
|
|
10774
10991
|
atob(val);
|
|
10775
10992
|
return true;
|
|
10776
|
-
} catch
|
|
10993
|
+
} catch {
|
|
10777
10994
|
return false;
|
|
10778
10995
|
}
|
|
10779
10996
|
}, { message: "Invalid Base64 string" });
|
|
@@ -10783,6 +11000,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10783
11000
|
*/
|
|
10784
11001
|
blob: Base64Schema
|
|
10785
11002
|
});
|
|
11003
|
+
const RoleSchema = _enum(["user", "assistant"]);
|
|
11004
|
+
const AnnotationsSchema = object$1({
|
|
11005
|
+
/**
|
|
11006
|
+
* Intended audience(s) for the resource.
|
|
11007
|
+
*/
|
|
11008
|
+
audience: array(RoleSchema).optional(),
|
|
11009
|
+
/**
|
|
11010
|
+
* Importance hint for the resource, from 0 (least) to 1 (most).
|
|
11011
|
+
*/
|
|
11012
|
+
priority: number$1().min(0).max(1).optional(),
|
|
11013
|
+
/**
|
|
11014
|
+
* ISO 8601 timestamp for the most recent modification.
|
|
11015
|
+
*/
|
|
11016
|
+
lastModified: datetime({ offset: true }).optional()
|
|
11017
|
+
});
|
|
10786
11018
|
const ResourceSchema = object$1({
|
|
10787
11019
|
...BaseMetadataSchema.shape,
|
|
10788
11020
|
...IconsSchema.shape,
|
|
@@ -10800,6 +11032,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10800
11032
|
* The MIME type of this resource, if known.
|
|
10801
11033
|
*/
|
|
10802
11034
|
mimeType: optional(string()),
|
|
11035
|
+
/**
|
|
11036
|
+
* Optional annotations for the client.
|
|
11037
|
+
*/
|
|
11038
|
+
annotations: AnnotationsSchema.optional(),
|
|
10803
11039
|
/**
|
|
10804
11040
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10805
11041
|
* for notes on _meta usage.
|
|
@@ -10823,6 +11059,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10823
11059
|
* 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.
|
|
10824
11060
|
*/
|
|
10825
11061
|
mimeType: optional(string()),
|
|
11062
|
+
/**
|
|
11063
|
+
* Optional annotations for the client.
|
|
11064
|
+
*/
|
|
11065
|
+
annotations: AnnotationsSchema.optional(),
|
|
10826
11066
|
/**
|
|
10827
11067
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10828
11068
|
* for notes on _meta usage.
|
|
@@ -10858,7 +11098,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10858
11098
|
contents: array(union([TextResourceContentsSchema, BlobResourceContentsSchema]))
|
|
10859
11099
|
});
|
|
10860
11100
|
const ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
10861
|
-
method: literal("notifications/resources/list_changed")
|
|
11101
|
+
method: literal("notifications/resources/list_changed"),
|
|
11102
|
+
params: NotificationsParamsSchema.optional()
|
|
10862
11103
|
});
|
|
10863
11104
|
const SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
10864
11105
|
const SubscribeRequestSchema = RequestSchema.extend({
|
|
@@ -10937,6 +11178,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10937
11178
|
* The text content of the message.
|
|
10938
11179
|
*/
|
|
10939
11180
|
text: string(),
|
|
11181
|
+
/**
|
|
11182
|
+
* Optional annotations for the client.
|
|
11183
|
+
*/
|
|
11184
|
+
annotations: AnnotationsSchema.optional(),
|
|
10940
11185
|
/**
|
|
10941
11186
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10942
11187
|
* for notes on _meta usage.
|
|
@@ -10953,6 +11198,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10953
11198
|
* The MIME type of the image. Different providers may support different image types.
|
|
10954
11199
|
*/
|
|
10955
11200
|
mimeType: string(),
|
|
11201
|
+
/**
|
|
11202
|
+
* Optional annotations for the client.
|
|
11203
|
+
*/
|
|
11204
|
+
annotations: AnnotationsSchema.optional(),
|
|
10956
11205
|
/**
|
|
10957
11206
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10958
11207
|
* for notes on _meta usage.
|
|
@@ -10969,6 +11218,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10969
11218
|
* The MIME type of the audio. Different providers may support different audio types.
|
|
10970
11219
|
*/
|
|
10971
11220
|
mimeType: string(),
|
|
11221
|
+
/**
|
|
11222
|
+
* Optional annotations for the client.
|
|
11223
|
+
*/
|
|
11224
|
+
annotations: AnnotationsSchema.optional(),
|
|
10972
11225
|
/**
|
|
10973
11226
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10974
11227
|
* for notes on _meta usage.
|
|
@@ -10991,16 +11244,20 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
10991
11244
|
* Arguments to pass to the tool.
|
|
10992
11245
|
* Must conform to the tool's inputSchema.
|
|
10993
11246
|
*/
|
|
10994
|
-
input:
|
|
11247
|
+
input: record(string(), unknown()),
|
|
10995
11248
|
/**
|
|
10996
11249
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
10997
11250
|
* for notes on _meta usage.
|
|
10998
11251
|
*/
|
|
10999
|
-
_meta:
|
|
11000
|
-
})
|
|
11252
|
+
_meta: record(string(), unknown()).optional()
|
|
11253
|
+
});
|
|
11001
11254
|
const EmbeddedResourceSchema = object$1({
|
|
11002
11255
|
type: literal("resource"),
|
|
11003
11256
|
resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
|
|
11257
|
+
/**
|
|
11258
|
+
* Optional annotations for the client.
|
|
11259
|
+
*/
|
|
11260
|
+
annotations: AnnotationsSchema.optional(),
|
|
11004
11261
|
/**
|
|
11005
11262
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
11006
11263
|
* for notes on _meta usage.
|
|
@@ -11018,18 +11275,19 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11018
11275
|
EmbeddedResourceSchema
|
|
11019
11276
|
]);
|
|
11020
11277
|
const PromptMessageSchema = object$1({
|
|
11021
|
-
role:
|
|
11278
|
+
role: RoleSchema,
|
|
11022
11279
|
content: ContentBlockSchema
|
|
11023
11280
|
});
|
|
11024
11281
|
const GetPromptResultSchema = ResultSchema.extend({
|
|
11025
11282
|
/**
|
|
11026
11283
|
* An optional description for the prompt.
|
|
11027
11284
|
*/
|
|
11028
|
-
description:
|
|
11285
|
+
description: string().optional(),
|
|
11029
11286
|
messages: array(PromptMessageSchema)
|
|
11030
11287
|
});
|
|
11031
11288
|
const PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
11032
|
-
method: literal("notifications/prompts/list_changed")
|
|
11289
|
+
method: literal("notifications/prompts/list_changed"),
|
|
11290
|
+
params: NotificationsParamsSchema.optional()
|
|
11033
11291
|
});
|
|
11034
11292
|
const ToolAnnotationsSchema = object$1({
|
|
11035
11293
|
/**
|
|
@@ -11070,6 +11328,17 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11070
11328
|
*/
|
|
11071
11329
|
openWorldHint: boolean().optional()
|
|
11072
11330
|
});
|
|
11331
|
+
const ToolExecutionSchema = object$1({
|
|
11332
|
+
/**
|
|
11333
|
+
* Indicates the tool's preference for task-augmented execution.
|
|
11334
|
+
* - "required": Clients MUST invoke the tool as a task
|
|
11335
|
+
* - "optional": Clients MAY invoke the tool as a task or normal request
|
|
11336
|
+
* - "forbidden": Clients MUST NOT attempt to invoke the tool as a task
|
|
11337
|
+
*
|
|
11338
|
+
* If not present, defaults to "forbidden".
|
|
11339
|
+
*/
|
|
11340
|
+
taskSupport: _enum(["required", "optional", "forbidden"]).optional()
|
|
11341
|
+
});
|
|
11073
11342
|
const ToolSchema = object$1({
|
|
11074
11343
|
...BaseMetadataSchema.shape,
|
|
11075
11344
|
...IconsSchema.shape,
|
|
@@ -11099,7 +11368,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11099
11368
|
/**
|
|
11100
11369
|
* Optional additional tool information.
|
|
11101
11370
|
*/
|
|
11102
|
-
annotations: optional(
|
|
11371
|
+
annotations: ToolAnnotationsSchema.optional(),
|
|
11372
|
+
/**
|
|
11373
|
+
* Execution-related properties for this tool.
|
|
11374
|
+
*/
|
|
11375
|
+
execution: ToolExecutionSchema.optional(),
|
|
11103
11376
|
/**
|
|
11104
11377
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
11105
11378
|
* for notes on _meta usage.
|
|
@@ -11140,12 +11413,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11140
11413
|
* server does not support tool calls, or any other exceptional conditions,
|
|
11141
11414
|
* should be reported as an MCP error response.
|
|
11142
11415
|
*/
|
|
11143
|
-
isError:
|
|
11416
|
+
isError: boolean().optional()
|
|
11144
11417
|
});
|
|
11145
11418
|
const CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
|
|
11146
11419
|
toolResult: unknown()
|
|
11147
11420
|
}));
|
|
11148
|
-
const CallToolRequestParamsSchema =
|
|
11421
|
+
const CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
11149
11422
|
/**
|
|
11150
11423
|
* The name of the tool to call.
|
|
11151
11424
|
*/
|
|
@@ -11153,14 +11426,35 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11153
11426
|
/**
|
|
11154
11427
|
* Arguments to pass to the tool.
|
|
11155
11428
|
*/
|
|
11156
|
-
arguments:
|
|
11429
|
+
arguments: record(string(), unknown()).optional()
|
|
11157
11430
|
});
|
|
11158
11431
|
const CallToolRequestSchema = RequestSchema.extend({
|
|
11159
11432
|
method: literal("tools/call"),
|
|
11160
11433
|
params: CallToolRequestParamsSchema
|
|
11161
11434
|
});
|
|
11162
11435
|
const ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
11163
|
-
method: literal("notifications/tools/list_changed")
|
|
11436
|
+
method: literal("notifications/tools/list_changed"),
|
|
11437
|
+
params: NotificationsParamsSchema.optional()
|
|
11438
|
+
});
|
|
11439
|
+
const ListChangedOptionsBaseSchema = object$1({
|
|
11440
|
+
/**
|
|
11441
|
+
* If true, the list will be refreshed automatically when a list changed notification is received.
|
|
11442
|
+
* The callback will be called with the updated list.
|
|
11443
|
+
*
|
|
11444
|
+
* If false, the callback will be called with null items, allowing manual refresh.
|
|
11445
|
+
*
|
|
11446
|
+
* @default true
|
|
11447
|
+
*/
|
|
11448
|
+
autoRefresh: boolean().default(true),
|
|
11449
|
+
/**
|
|
11450
|
+
* Debounce time in milliseconds for list changed notification processing.
|
|
11451
|
+
*
|
|
11452
|
+
* Multiple notifications received within this timeframe will only trigger one refresh.
|
|
11453
|
+
* Set to 0 to disable debouncing.
|
|
11454
|
+
*
|
|
11455
|
+
* @default 300
|
|
11456
|
+
*/
|
|
11457
|
+
debounceMs: number$1().int().nonnegative().default(300)
|
|
11164
11458
|
});
|
|
11165
11459
|
const LoggingLevelSchema = _enum(["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]);
|
|
11166
11460
|
const SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
@@ -11201,19 +11495,19 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11201
11495
|
/**
|
|
11202
11496
|
* Optional hints to use for model selection.
|
|
11203
11497
|
*/
|
|
11204
|
-
hints:
|
|
11498
|
+
hints: array(ModelHintSchema).optional(),
|
|
11205
11499
|
/**
|
|
11206
11500
|
* How much to prioritize cost when selecting a model.
|
|
11207
11501
|
*/
|
|
11208
|
-
costPriority:
|
|
11502
|
+
costPriority: number$1().min(0).max(1).optional(),
|
|
11209
11503
|
/**
|
|
11210
11504
|
* How much to prioritize sampling speed (latency) when selecting a model.
|
|
11211
11505
|
*/
|
|
11212
|
-
speedPriority:
|
|
11506
|
+
speedPriority: number$1().min(0).max(1).optional(),
|
|
11213
11507
|
/**
|
|
11214
11508
|
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
11215
11509
|
*/
|
|
11216
|
-
intelligencePriority:
|
|
11510
|
+
intelligencePriority: number$1().min(0).max(1).optional()
|
|
11217
11511
|
});
|
|
11218
11512
|
const ToolChoiceSchema = object$1({
|
|
11219
11513
|
/**
|
|
@@ -11222,20 +11516,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11222
11516
|
* - "required": Model MUST use at least one tool before completing
|
|
11223
11517
|
* - "none": Model MUST NOT use any tools
|
|
11224
11518
|
*/
|
|
11225
|
-
mode:
|
|
11519
|
+
mode: _enum(["auto", "required", "none"]).optional()
|
|
11226
11520
|
});
|
|
11227
11521
|
const ToolResultContentSchema = object$1({
|
|
11228
11522
|
type: literal("tool_result"),
|
|
11229
11523
|
toolUseId: string().describe("The unique identifier for the corresponding tool call."),
|
|
11230
11524
|
content: array(ContentBlockSchema).default([]),
|
|
11231
|
-
structuredContent: object$1({}).
|
|
11232
|
-
isError:
|
|
11525
|
+
structuredContent: object$1({}).loose().optional(),
|
|
11526
|
+
isError: boolean().optional(),
|
|
11233
11527
|
/**
|
|
11234
11528
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
11235
11529
|
* for notes on _meta usage.
|
|
11236
11530
|
*/
|
|
11237
|
-
_meta:
|
|
11238
|
-
})
|
|
11531
|
+
_meta: record(string(), unknown()).optional()
|
|
11532
|
+
});
|
|
11533
|
+
const SamplingContentSchema = discriminatedUnion("type", [TextContentSchema, ImageContentSchema, AudioContentSchema]);
|
|
11239
11534
|
const SamplingMessageContentBlockSchema = discriminatedUnion("type", [
|
|
11240
11535
|
TextContentSchema,
|
|
11241
11536
|
ImageContentSchema,
|
|
@@ -11244,15 +11539,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11244
11539
|
ToolResultContentSchema
|
|
11245
11540
|
]);
|
|
11246
11541
|
const SamplingMessageSchema = object$1({
|
|
11247
|
-
role:
|
|
11542
|
+
role: RoleSchema,
|
|
11248
11543
|
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)]),
|
|
11249
11544
|
/**
|
|
11250
11545
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
11251
11546
|
* for notes on _meta usage.
|
|
11252
11547
|
*/
|
|
11253
|
-
_meta:
|
|
11254
|
-
})
|
|
11255
|
-
const CreateMessageRequestParamsSchema =
|
|
11548
|
+
_meta: record(string(), unknown()).optional()
|
|
11549
|
+
});
|
|
11550
|
+
const CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
11256
11551
|
messages: array(SamplingMessageSchema),
|
|
11257
11552
|
/**
|
|
11258
11553
|
* The server's preferences for which model to select. The client MAY modify or omit this request.
|
|
@@ -11270,13 +11565,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11270
11565
|
* declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
|
|
11271
11566
|
*/
|
|
11272
11567
|
includeContext: _enum(["none", "thisServer", "allServers"]).optional(),
|
|
11273
|
-
temperature: number().optional(),
|
|
11568
|
+
temperature: number$1().optional(),
|
|
11274
11569
|
/**
|
|
11275
11570
|
* The requested maximum number of tokens to sample (to prevent runaway completions).
|
|
11276
11571
|
*
|
|
11277
11572
|
* The client MAY choose to sample fewer tokens than the requested maximum.
|
|
11278
11573
|
*/
|
|
11279
|
-
maxTokens: number().int(),
|
|
11574
|
+
maxTokens: number$1().int(),
|
|
11280
11575
|
stopSequences: array(string()).optional(),
|
|
11281
11576
|
/**
|
|
11282
11577
|
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
@@ -11286,19 +11581,41 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11286
11581
|
* Tools that the model may use during generation.
|
|
11287
11582
|
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
11288
11583
|
*/
|
|
11289
|
-
tools:
|
|
11584
|
+
tools: array(ToolSchema).optional(),
|
|
11290
11585
|
/**
|
|
11291
11586
|
* Controls how the model uses tools.
|
|
11292
11587
|
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
11293
11588
|
* Default is `{ mode: "auto" }`.
|
|
11294
11589
|
*/
|
|
11295
|
-
toolChoice: optional(
|
|
11590
|
+
toolChoice: ToolChoiceSchema.optional()
|
|
11296
11591
|
});
|
|
11297
11592
|
const CreateMessageRequestSchema = RequestSchema.extend({
|
|
11298
11593
|
method: literal("sampling/createMessage"),
|
|
11299
11594
|
params: CreateMessageRequestParamsSchema
|
|
11300
11595
|
});
|
|
11301
11596
|
const CreateMessageResultSchema = ResultSchema.extend({
|
|
11597
|
+
/**
|
|
11598
|
+
* The name of the model that generated the message.
|
|
11599
|
+
*/
|
|
11600
|
+
model: string(),
|
|
11601
|
+
/**
|
|
11602
|
+
* The reason why sampling stopped, if known.
|
|
11603
|
+
*
|
|
11604
|
+
* Standard values:
|
|
11605
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
11606
|
+
* - "stopSequence": A stop sequence was encountered
|
|
11607
|
+
* - "maxTokens": Maximum token limit was reached
|
|
11608
|
+
*
|
|
11609
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
11610
|
+
*/
|
|
11611
|
+
stopReason: optional(_enum(["endTurn", "stopSequence", "maxTokens"]).or(string())),
|
|
11612
|
+
role: RoleSchema,
|
|
11613
|
+
/**
|
|
11614
|
+
* Response content. Single content block (text, image, or audio).
|
|
11615
|
+
*/
|
|
11616
|
+
content: SamplingContentSchema
|
|
11617
|
+
});
|
|
11618
|
+
const CreateMessageResultWithToolsSchema = ResultSchema.extend({
|
|
11302
11619
|
/**
|
|
11303
11620
|
* The name of the model that generated the message.
|
|
11304
11621
|
*/
|
|
@@ -11315,9 +11632,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11315
11632
|
* This field is an open string to allow for provider-specific stop reasons.
|
|
11316
11633
|
*/
|
|
11317
11634
|
stopReason: optional(_enum(["endTurn", "stopSequence", "maxTokens", "toolUse"]).or(string())),
|
|
11318
|
-
role:
|
|
11635
|
+
role: RoleSchema,
|
|
11319
11636
|
/**
|
|
11320
|
-
* Response content. May be ToolUseContent if stopReason is "toolUse".
|
|
11637
|
+
* Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
|
|
11321
11638
|
*/
|
|
11322
11639
|
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)])
|
|
11323
11640
|
});
|
|
@@ -11331,8 +11648,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11331
11648
|
type: literal("string"),
|
|
11332
11649
|
title: string().optional(),
|
|
11333
11650
|
description: string().optional(),
|
|
11334
|
-
minLength: number().optional(),
|
|
11335
|
-
maxLength: number().optional(),
|
|
11651
|
+
minLength: number$1().optional(),
|
|
11652
|
+
maxLength: number$1().optional(),
|
|
11336
11653
|
format: _enum(["email", "uri", "date", "date-time"]).optional(),
|
|
11337
11654
|
default: string().optional()
|
|
11338
11655
|
});
|
|
@@ -11340,9 +11657,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11340
11657
|
type: _enum(["number", "integer"]),
|
|
11341
11658
|
title: string().optional(),
|
|
11342
11659
|
description: string().optional(),
|
|
11343
|
-
minimum: number().optional(),
|
|
11344
|
-
maximum: number().optional(),
|
|
11345
|
-
default: number().optional()
|
|
11660
|
+
minimum: number$1().optional(),
|
|
11661
|
+
maximum: number$1().optional(),
|
|
11662
|
+
default: number$1().optional()
|
|
11346
11663
|
});
|
|
11347
11664
|
const UntitledSingleSelectEnumSchemaSchema = object$1({
|
|
11348
11665
|
type: literal("string"),
|
|
@@ -11374,8 +11691,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11374
11691
|
type: literal("array"),
|
|
11375
11692
|
title: string().optional(),
|
|
11376
11693
|
description: string().optional(),
|
|
11377
|
-
minItems: number().optional(),
|
|
11378
|
-
maxItems: number().optional(),
|
|
11694
|
+
minItems: number$1().optional(),
|
|
11695
|
+
maxItems: number$1().optional(),
|
|
11379
11696
|
items: object$1({
|
|
11380
11697
|
type: literal("string"),
|
|
11381
11698
|
enum: array(string())
|
|
@@ -11386,8 +11703,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11386
11703
|
type: literal("array"),
|
|
11387
11704
|
title: string().optional(),
|
|
11388
11705
|
description: string().optional(),
|
|
11389
|
-
minItems: number().optional(),
|
|
11390
|
-
maxItems: number().optional(),
|
|
11706
|
+
minItems: number$1().optional(),
|
|
11707
|
+
maxItems: number$1().optional(),
|
|
11391
11708
|
items: object$1({
|
|
11392
11709
|
anyOf: array(object$1({
|
|
11393
11710
|
const: string(),
|
|
@@ -11399,7 +11716,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11399
11716
|
const MultiSelectEnumSchemaSchema = union([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema]);
|
|
11400
11717
|
const EnumSchemaSchema = union([LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema]);
|
|
11401
11718
|
const PrimitiveSchemaDefinitionSchema = union([EnumSchemaSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema]);
|
|
11402
|
-
const ElicitRequestFormParamsSchema =
|
|
11719
|
+
const ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
11403
11720
|
/**
|
|
11404
11721
|
* The elicitation mode.
|
|
11405
11722
|
*
|
|
@@ -11420,7 +11737,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11420
11737
|
required: array(string()).optional()
|
|
11421
11738
|
})
|
|
11422
11739
|
});
|
|
11423
|
-
const ElicitRequestURLParamsSchema =
|
|
11740
|
+
const ElicitRequestURLParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
11424
11741
|
/**
|
|
11425
11742
|
* The elicitation mode.
|
|
11426
11743
|
*/
|
|
@@ -11465,8 +11782,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11465
11782
|
/**
|
|
11466
11783
|
* The submitted form data, only present when action is "accept".
|
|
11467
11784
|
* Contains values matching the requested schema.
|
|
11785
|
+
* Per MCP spec, content is "typically omitted" for decline/cancel actions.
|
|
11786
|
+
* We normalize null to undefined for leniency while maintaining type compatibility.
|
|
11468
11787
|
*/
|
|
11469
|
-
content: record(string(), union([string(), number(), boolean(), array(string())])).optional()
|
|
11788
|
+
content: preprocess((val) => val === null ? void 0 : val, record(string(), union([string(), number$1(), boolean(), array(string())])).optional())
|
|
11470
11789
|
});
|
|
11471
11790
|
const ResourceTemplateReferenceSchema = object$1({
|
|
11472
11791
|
type: literal("ref/resource"),
|
|
@@ -11528,7 +11847,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11528
11847
|
/**
|
|
11529
11848
|
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
11530
11849
|
*/
|
|
11531
|
-
total: optional(number().int()),
|
|
11850
|
+
total: optional(number$1().int()),
|
|
11532
11851
|
/**
|
|
11533
11852
|
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
11534
11853
|
*/
|
|
@@ -11551,13 +11870,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11551
11870
|
_meta: record(string(), unknown()).optional()
|
|
11552
11871
|
});
|
|
11553
11872
|
const ListRootsRequestSchema = RequestSchema.extend({
|
|
11554
|
-
method: literal("roots/list")
|
|
11873
|
+
method: literal("roots/list"),
|
|
11874
|
+
params: BaseRequestParamsSchema.optional()
|
|
11555
11875
|
});
|
|
11556
11876
|
const ListRootsResultSchema = ResultSchema.extend({
|
|
11557
11877
|
roots: array(RootSchema)
|
|
11558
11878
|
});
|
|
11559
11879
|
const RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
11560
|
-
method: literal("notifications/roots/list_changed")
|
|
11880
|
+
method: literal("notifications/roots/list_changed"),
|
|
11881
|
+
params: NotificationsParamsSchema.optional()
|
|
11561
11882
|
});
|
|
11562
11883
|
const ClientRequestSchema = union([
|
|
11563
11884
|
PingRequestSchema,
|
|
@@ -11572,16 +11893,39 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11572
11893
|
SubscribeRequestSchema,
|
|
11573
11894
|
UnsubscribeRequestSchema,
|
|
11574
11895
|
CallToolRequestSchema,
|
|
11575
|
-
ListToolsRequestSchema
|
|
11896
|
+
ListToolsRequestSchema,
|
|
11897
|
+
GetTaskRequestSchema,
|
|
11898
|
+
GetTaskPayloadRequestSchema,
|
|
11899
|
+
ListTasksRequestSchema,
|
|
11900
|
+
CancelTaskRequestSchema
|
|
11576
11901
|
]);
|
|
11577
11902
|
const ClientNotificationSchema = union([
|
|
11578
11903
|
CancelledNotificationSchema,
|
|
11579
11904
|
ProgressNotificationSchema,
|
|
11580
11905
|
InitializedNotificationSchema,
|
|
11581
|
-
RootsListChangedNotificationSchema
|
|
11906
|
+
RootsListChangedNotificationSchema,
|
|
11907
|
+
TaskStatusNotificationSchema
|
|
11908
|
+
]);
|
|
11909
|
+
const ClientResultSchema = union([
|
|
11910
|
+
EmptyResultSchema,
|
|
11911
|
+
CreateMessageResultSchema,
|
|
11912
|
+
CreateMessageResultWithToolsSchema,
|
|
11913
|
+
ElicitResultSchema,
|
|
11914
|
+
ListRootsResultSchema,
|
|
11915
|
+
GetTaskResultSchema,
|
|
11916
|
+
ListTasksResultSchema,
|
|
11917
|
+
CreateTaskResultSchema
|
|
11918
|
+
]);
|
|
11919
|
+
const ServerRequestSchema = union([
|
|
11920
|
+
PingRequestSchema,
|
|
11921
|
+
CreateMessageRequestSchema,
|
|
11922
|
+
ElicitRequestSchema,
|
|
11923
|
+
ListRootsRequestSchema,
|
|
11924
|
+
GetTaskRequestSchema,
|
|
11925
|
+
GetTaskPayloadRequestSchema,
|
|
11926
|
+
ListTasksRequestSchema,
|
|
11927
|
+
CancelTaskRequestSchema
|
|
11582
11928
|
]);
|
|
11583
|
-
const ClientResultSchema = union([EmptyResultSchema, CreateMessageResultSchema, ElicitResultSchema, ListRootsResultSchema]);
|
|
11584
|
-
const ServerRequestSchema = union([PingRequestSchema, CreateMessageRequestSchema, ElicitRequestSchema, ListRootsRequestSchema]);
|
|
11585
11929
|
const ServerNotificationSchema = union([
|
|
11586
11930
|
CancelledNotificationSchema,
|
|
11587
11931
|
ProgressNotificationSchema,
|
|
@@ -11590,6 +11934,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11590
11934
|
ResourceListChangedNotificationSchema,
|
|
11591
11935
|
ToolListChangedNotificationSchema,
|
|
11592
11936
|
PromptListChangedNotificationSchema,
|
|
11937
|
+
TaskStatusNotificationSchema,
|
|
11593
11938
|
ElicitationCompleteNotificationSchema
|
|
11594
11939
|
]);
|
|
11595
11940
|
const ServerResultSchema = union([
|
|
@@ -11602,7 +11947,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11602
11947
|
ListResourceTemplatesResultSchema,
|
|
11603
11948
|
ReadResourceResultSchema,
|
|
11604
11949
|
CallToolResultSchema,
|
|
11605
|
-
ListToolsResultSchema
|
|
11950
|
+
ListToolsResultSchema,
|
|
11951
|
+
GetTaskResultSchema,
|
|
11952
|
+
ListTasksResultSchema,
|
|
11953
|
+
CreateTaskResultSchema
|
|
11606
11954
|
]);
|
|
11607
11955
|
class McpError extends Error {
|
|
11608
11956
|
constructor(code2, message, data) {
|
|
@@ -11631,8 +11979,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11631
11979
|
});
|
|
11632
11980
|
}
|
|
11633
11981
|
get elicitations() {
|
|
11634
|
-
|
|
11635
|
-
return (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.elicitations) !== null && _b !== void 0 ? _b : [];
|
|
11982
|
+
return this.data?.elicitations ?? [];
|
|
11636
11983
|
}
|
|
11637
11984
|
}
|
|
11638
11985
|
const MAX_TEMPLATE_LENGTH = 1e6;
|
|
@@ -11802,7 +12149,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11802
12149
|
const name = part.name;
|
|
11803
12150
|
switch (part.operator) {
|
|
11804
12151
|
case "":
|
|
11805
|
-
pattern2 = part.exploded ? "([
|
|
12152
|
+
pattern2 = part.exploded ? "([^/,]+(?:,[^/,]+)*)" : "([^/,]+)";
|
|
11806
12153
|
break;
|
|
11807
12154
|
case "+":
|
|
11808
12155
|
case "#":
|
|
@@ -11812,7 +12159,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11812
12159
|
pattern2 = "\\.([^/,]+)";
|
|
11813
12160
|
break;
|
|
11814
12161
|
case "/":
|
|
11815
|
-
pattern2 = "/" + (part.exploded ? "([
|
|
12162
|
+
pattern2 = "/" + (part.exploded ? "([^/,]+(?:,[^/,]+)*)" : "([^/,]+)");
|
|
11816
12163
|
break;
|
|
11817
12164
|
default:
|
|
11818
12165
|
pattern2 = "([^/]+)";
|
|
@@ -11870,7 +12217,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11870
12217
|
}
|
|
11871
12218
|
function getCompleter(schema) {
|
|
11872
12219
|
const meta = schema[COMPLETABLE_SYMBOL];
|
|
11873
|
-
return meta
|
|
12220
|
+
return meta?.complete;
|
|
11874
12221
|
}
|
|
11875
12222
|
function unwrapCompletable(schema) {
|
|
11876
12223
|
return schema;
|
|
@@ -11880,11 +12227,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
11880
12227
|
McpZodTypeKind["Completable"] = "McpCompletable";
|
|
11881
12228
|
})(exports2.McpZodTypeKind || (exports2.McpZodTypeKind = {}));
|
|
11882
12229
|
function getDisplayName(metadata2) {
|
|
11883
|
-
var _a;
|
|
11884
12230
|
if (metadata2.title !== void 0 && metadata2.title !== "") {
|
|
11885
12231
|
return metadata2.title;
|
|
11886
12232
|
}
|
|
11887
|
-
if (
|
|
12233
|
+
if ("annotations" in metadata2 && metadata2.annotations?.title) {
|
|
11888
12234
|
return metadata2.annotations.title;
|
|
11889
12235
|
}
|
|
11890
12236
|
return metadata2.name;
|
|
@@ -15537,13 +15883,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
15537
15883
|
return result;
|
|
15538
15884
|
}
|
|
15539
15885
|
function getObjectShape(schema) {
|
|
15540
|
-
var _a, _b;
|
|
15541
15886
|
if (!schema)
|
|
15542
15887
|
return void 0;
|
|
15543
15888
|
let rawShape;
|
|
15544
15889
|
if (isZ4Schema(schema)) {
|
|
15545
15890
|
const v4Schema = schema;
|
|
15546
|
-
rawShape =
|
|
15891
|
+
rawShape = v4Schema._zod?.def?.shape;
|
|
15547
15892
|
} else {
|
|
15548
15893
|
const v3Schema = schema;
|
|
15549
15894
|
rawShape = v3Schema.shape;
|
|
@@ -15553,14 +15898,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
15553
15898
|
if (typeof rawShape === "function") {
|
|
15554
15899
|
try {
|
|
15555
15900
|
return rawShape();
|
|
15556
|
-
} catch
|
|
15901
|
+
} catch {
|
|
15557
15902
|
return void 0;
|
|
15558
15903
|
}
|
|
15559
15904
|
}
|
|
15560
15905
|
return rawShape;
|
|
15561
15906
|
}
|
|
15562
15907
|
function normalizeObjectSchema(schema) {
|
|
15563
|
-
var _a;
|
|
15564
15908
|
if (!schema)
|
|
15565
15909
|
return void 0;
|
|
15566
15910
|
if (typeof schema === "object") {
|
|
@@ -15575,8 +15919,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
15575
15919
|
}
|
|
15576
15920
|
if (isZ4Schema(schema)) {
|
|
15577
15921
|
const v4Schema = schema;
|
|
15578
|
-
const def =
|
|
15579
|
-
if (def && (def.
|
|
15922
|
+
const def = v4Schema._zod?.def;
|
|
15923
|
+
if (def && (def.type === "object" || def.shape !== void 0)) {
|
|
15580
15924
|
return schema;
|
|
15581
15925
|
}
|
|
15582
15926
|
} else {
|
|
@@ -15600,38 +15944,30 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
15600
15944
|
}
|
|
15601
15945
|
try {
|
|
15602
15946
|
return JSON.stringify(error);
|
|
15603
|
-
} catch
|
|
15947
|
+
} catch {
|
|
15604
15948
|
return String(error);
|
|
15605
15949
|
}
|
|
15606
15950
|
}
|
|
15607
15951
|
return String(error);
|
|
15608
15952
|
}
|
|
15609
15953
|
function getSchemaDescription(schema) {
|
|
15610
|
-
|
|
15611
|
-
if (isZ4Schema(schema)) {
|
|
15612
|
-
const v4Schema = schema;
|
|
15613
|
-
return (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.description;
|
|
15614
|
-
}
|
|
15615
|
-
const v3Schema = schema;
|
|
15616
|
-
return (_c = schema.description) !== null && _c !== void 0 ? _c : (_d = v3Schema._def) === null || _d === void 0 ? void 0 : _d.description;
|
|
15954
|
+
return schema.description;
|
|
15617
15955
|
}
|
|
15618
15956
|
function isSchemaOptional(schema) {
|
|
15619
|
-
var _a, _b, _c;
|
|
15620
15957
|
if (isZ4Schema(schema)) {
|
|
15621
15958
|
const v4Schema = schema;
|
|
15622
|
-
return
|
|
15959
|
+
return v4Schema._zod?.def?.type === "optional";
|
|
15623
15960
|
}
|
|
15624
15961
|
const v3Schema = schema;
|
|
15625
15962
|
if (typeof schema.isOptional === "function") {
|
|
15626
15963
|
return schema.isOptional();
|
|
15627
15964
|
}
|
|
15628
|
-
return
|
|
15965
|
+
return v3Schema._def?.typeName === "ZodOptional";
|
|
15629
15966
|
}
|
|
15630
15967
|
function getLiteralValue(schema) {
|
|
15631
|
-
var _a;
|
|
15632
15968
|
if (isZ4Schema(schema)) {
|
|
15633
15969
|
const v4Schema = schema;
|
|
15634
|
-
const def2 =
|
|
15970
|
+
const def2 = v4Schema._zod?.def;
|
|
15635
15971
|
if (def2) {
|
|
15636
15972
|
if (def2.value !== void 0)
|
|
15637
15973
|
return def2.value;
|
|
@@ -15654,6 +15990,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
15654
15990
|
return directValue;
|
|
15655
15991
|
return void 0;
|
|
15656
15992
|
}
|
|
15993
|
+
function isTerminal(status) {
|
|
15994
|
+
return status === "completed" || status === "failed" || status === "cancelled";
|
|
15995
|
+
}
|
|
15657
15996
|
const ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
15658
15997
|
const defaultOptions = {
|
|
15659
15998
|
name: void 0,
|
|
@@ -16867,21 +17206,20 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
16867
17206
|
return "draft-7";
|
|
16868
17207
|
}
|
|
16869
17208
|
function toJsonSchemaCompat(schema, opts) {
|
|
16870
|
-
var _a, _b, _c;
|
|
16871
17209
|
if (isZ4Schema(schema)) {
|
|
16872
17210
|
return toJSONSchema(schema, {
|
|
16873
|
-
target: mapMiniTarget(opts
|
|
16874
|
-
io:
|
|
17211
|
+
target: mapMiniTarget(opts?.target),
|
|
17212
|
+
io: opts?.pipeStrategy ?? "input"
|
|
16875
17213
|
});
|
|
16876
17214
|
}
|
|
16877
17215
|
return zodToJsonSchema(schema, {
|
|
16878
|
-
strictUnions:
|
|
16879
|
-
pipeStrategy:
|
|
17216
|
+
strictUnions: opts?.strictUnions ?? true,
|
|
17217
|
+
pipeStrategy: opts?.pipeStrategy ?? "input"
|
|
16880
17218
|
});
|
|
16881
17219
|
}
|
|
16882
17220
|
function getMethodLiteral(schema) {
|
|
16883
17221
|
const shape = getObjectShape(schema);
|
|
16884
|
-
const methodSchema = shape
|
|
17222
|
+
const methodSchema = shape?.method;
|
|
16885
17223
|
if (!methodSchema) {
|
|
16886
17224
|
throw new Error("Schema is missing a method literal");
|
|
16887
17225
|
}
|
|
@@ -16910,9 +17248,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
16910
17248
|
this._progressHandlers = /* @__PURE__ */ new Map();
|
|
16911
17249
|
this._timeoutInfo = /* @__PURE__ */ new Map();
|
|
16912
17250
|
this._pendingDebouncedNotifications = /* @__PURE__ */ new Set();
|
|
17251
|
+
this._taskProgressTokens = /* @__PURE__ */ new Map();
|
|
17252
|
+
this._requestResolvers = /* @__PURE__ */ new Map();
|
|
16913
17253
|
this.setNotificationHandler(CancelledNotificationSchema, (notification) => {
|
|
16914
|
-
|
|
16915
|
-
controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason);
|
|
17254
|
+
this._oncancel(notification);
|
|
16916
17255
|
});
|
|
16917
17256
|
this.setNotificationHandler(ProgressNotificationSchema, (notification) => {
|
|
16918
17257
|
this._onprogress(notification);
|
|
@@ -16922,6 +17261,117 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
16922
17261
|
// Automatic pong by default.
|
|
16923
17262
|
(_request) => ({})
|
|
16924
17263
|
);
|
|
17264
|
+
this._taskStore = _options?.taskStore;
|
|
17265
|
+
this._taskMessageQueue = _options?.taskMessageQueue;
|
|
17266
|
+
if (this._taskStore) {
|
|
17267
|
+
this.setRequestHandler(GetTaskRequestSchema, async (request, extra) => {
|
|
17268
|
+
const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
17269
|
+
if (!task) {
|
|
17270
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, "Failed to retrieve task: Task not found");
|
|
17271
|
+
}
|
|
17272
|
+
return {
|
|
17273
|
+
...task
|
|
17274
|
+
};
|
|
17275
|
+
});
|
|
17276
|
+
this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
|
|
17277
|
+
const handleTaskResult = async () => {
|
|
17278
|
+
const taskId = request.params.taskId;
|
|
17279
|
+
if (this._taskMessageQueue) {
|
|
17280
|
+
let queuedMessage;
|
|
17281
|
+
while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
|
|
17282
|
+
if (queuedMessage.type === "response" || queuedMessage.type === "error") {
|
|
17283
|
+
const message = queuedMessage.message;
|
|
17284
|
+
const requestId = message.id;
|
|
17285
|
+
const resolver = this._requestResolvers.get(requestId);
|
|
17286
|
+
if (resolver) {
|
|
17287
|
+
this._requestResolvers.delete(requestId);
|
|
17288
|
+
if (queuedMessage.type === "response") {
|
|
17289
|
+
resolver(message);
|
|
17290
|
+
} else {
|
|
17291
|
+
const errorMessage = message;
|
|
17292
|
+
const error = new McpError(errorMessage.error.code, errorMessage.error.message, errorMessage.error.data);
|
|
17293
|
+
resolver(error);
|
|
17294
|
+
}
|
|
17295
|
+
} else {
|
|
17296
|
+
const messageType = queuedMessage.type === "response" ? "Response" : "Error";
|
|
17297
|
+
this._onerror(new Error(`${messageType} handler missing for request ${requestId}`));
|
|
17298
|
+
}
|
|
17299
|
+
continue;
|
|
17300
|
+
}
|
|
17301
|
+
await this._transport?.send(queuedMessage.message, { relatedRequestId: extra.requestId });
|
|
17302
|
+
}
|
|
17303
|
+
}
|
|
17304
|
+
const task = await this._taskStore.getTask(taskId, extra.sessionId);
|
|
17305
|
+
if (!task) {
|
|
17306
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Task not found: ${taskId}`);
|
|
17307
|
+
}
|
|
17308
|
+
if (!isTerminal(task.status)) {
|
|
17309
|
+
await this._waitForTaskUpdate(taskId, extra.signal);
|
|
17310
|
+
return await handleTaskResult();
|
|
17311
|
+
}
|
|
17312
|
+
if (isTerminal(task.status)) {
|
|
17313
|
+
const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
|
|
17314
|
+
this._clearTaskQueue(taskId);
|
|
17315
|
+
return {
|
|
17316
|
+
...result,
|
|
17317
|
+
_meta: {
|
|
17318
|
+
...result._meta,
|
|
17319
|
+
[RELATED_TASK_META_KEY]: {
|
|
17320
|
+
taskId
|
|
17321
|
+
}
|
|
17322
|
+
}
|
|
17323
|
+
};
|
|
17324
|
+
}
|
|
17325
|
+
return await handleTaskResult();
|
|
17326
|
+
};
|
|
17327
|
+
return await handleTaskResult();
|
|
17328
|
+
});
|
|
17329
|
+
this.setRequestHandler(ListTasksRequestSchema, async (request, extra) => {
|
|
17330
|
+
try {
|
|
17331
|
+
const { tasks, nextCursor } = await this._taskStore.listTasks(request.params?.cursor, extra.sessionId);
|
|
17332
|
+
return {
|
|
17333
|
+
tasks,
|
|
17334
|
+
nextCursor,
|
|
17335
|
+
_meta: {}
|
|
17336
|
+
};
|
|
17337
|
+
} catch (error) {
|
|
17338
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Failed to list tasks: ${error instanceof Error ? error.message : String(error)}`);
|
|
17339
|
+
}
|
|
17340
|
+
});
|
|
17341
|
+
this.setRequestHandler(CancelTaskRequestSchema, async (request, extra) => {
|
|
17342
|
+
try {
|
|
17343
|
+
const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
17344
|
+
if (!task) {
|
|
17345
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Task not found: ${request.params.taskId}`);
|
|
17346
|
+
}
|
|
17347
|
+
if (isTerminal(task.status)) {
|
|
17348
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
|
|
17349
|
+
}
|
|
17350
|
+
await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
|
|
17351
|
+
this._clearTaskQueue(request.params.taskId);
|
|
17352
|
+
const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
17353
|
+
if (!cancelledTask) {
|
|
17354
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
|
|
17355
|
+
}
|
|
17356
|
+
return {
|
|
17357
|
+
_meta: {},
|
|
17358
|
+
...cancelledTask
|
|
17359
|
+
};
|
|
17360
|
+
} catch (error) {
|
|
17361
|
+
if (error instanceof McpError) {
|
|
17362
|
+
throw error;
|
|
17363
|
+
}
|
|
17364
|
+
throw new McpError(exports2.ErrorCode.InvalidRequest, `Failed to cancel task: ${error instanceof Error ? error.message : String(error)}`);
|
|
17365
|
+
}
|
|
17366
|
+
});
|
|
17367
|
+
}
|
|
17368
|
+
}
|
|
17369
|
+
async _oncancel(notification) {
|
|
17370
|
+
if (!notification.params.requestId) {
|
|
17371
|
+
return;
|
|
17372
|
+
}
|
|
17373
|
+
const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
|
|
17374
|
+
controller?.abort(notification.params.reason);
|
|
16925
17375
|
}
|
|
16926
17376
|
_setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
16927
17377
|
this._timeoutInfo.set(messageId, {
|
|
@@ -16962,22 +17412,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
16962
17412
|
* 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.
|
|
16963
17413
|
*/
|
|
16964
17414
|
async connect(transport) {
|
|
16965
|
-
var _a, _b, _c;
|
|
16966
17415
|
this._transport = transport;
|
|
16967
|
-
const _onclose =
|
|
17416
|
+
const _onclose = this.transport?.onclose;
|
|
16968
17417
|
this._transport.onclose = () => {
|
|
16969
|
-
_onclose
|
|
17418
|
+
_onclose?.();
|
|
16970
17419
|
this._onclose();
|
|
16971
17420
|
};
|
|
16972
|
-
const _onerror =
|
|
17421
|
+
const _onerror = this.transport?.onerror;
|
|
16973
17422
|
this._transport.onerror = (error) => {
|
|
16974
|
-
_onerror
|
|
17423
|
+
_onerror?.(error);
|
|
16975
17424
|
this._onerror(error);
|
|
16976
17425
|
};
|
|
16977
|
-
const _onmessage =
|
|
17426
|
+
const _onmessage = this._transport?.onmessage;
|
|
16978
17427
|
this._transport.onmessage = (message, extra) => {
|
|
16979
|
-
_onmessage
|
|
16980
|
-
if (
|
|
17428
|
+
_onmessage?.(message, extra);
|
|
17429
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
16981
17430
|
this._onresponse(message);
|
|
16982
17431
|
} else if (isJSONRPCRequest(message)) {
|
|
16983
17432
|
this._onrequest(message, extra);
|
|
@@ -16990,80 +17439,131 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
16990
17439
|
await this._transport.start();
|
|
16991
17440
|
}
|
|
16992
17441
|
_onclose() {
|
|
16993
|
-
var _a;
|
|
16994
17442
|
const responseHandlers = this._responseHandlers;
|
|
16995
17443
|
this._responseHandlers = /* @__PURE__ */ new Map();
|
|
16996
17444
|
this._progressHandlers.clear();
|
|
17445
|
+
this._taskProgressTokens.clear();
|
|
16997
17446
|
this._pendingDebouncedNotifications.clear();
|
|
16998
|
-
this._transport = void 0;
|
|
16999
|
-
(_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
17000
17447
|
const error = McpError.fromError(exports2.ErrorCode.ConnectionClosed, "Connection closed");
|
|
17448
|
+
this._transport = void 0;
|
|
17449
|
+
this.onclose?.();
|
|
17001
17450
|
for (const handler of responseHandlers.values()) {
|
|
17002
17451
|
handler(error);
|
|
17003
17452
|
}
|
|
17004
17453
|
}
|
|
17005
17454
|
_onerror(error) {
|
|
17006
|
-
|
|
17007
|
-
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
17455
|
+
this.onerror?.(error);
|
|
17008
17456
|
}
|
|
17009
17457
|
_onnotification(notification) {
|
|
17010
|
-
|
|
17011
|
-
const handler = (_a = this._notificationHandlers.get(notification.method)) !== null && _a !== void 0 ? _a : this.fallbackNotificationHandler;
|
|
17458
|
+
const handler = this._notificationHandlers.get(notification.method) ?? this.fallbackNotificationHandler;
|
|
17012
17459
|
if (handler === void 0) {
|
|
17013
17460
|
return;
|
|
17014
17461
|
}
|
|
17015
17462
|
Promise.resolve().then(() => handler(notification)).catch((error) => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
|
|
17016
17463
|
}
|
|
17017
17464
|
_onrequest(request, extra) {
|
|
17018
|
-
|
|
17019
|
-
const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler;
|
|
17465
|
+
const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
|
|
17020
17466
|
const capturedTransport = this._transport;
|
|
17467
|
+
const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
|
|
17021
17468
|
if (handler === void 0) {
|
|
17022
|
-
|
|
17469
|
+
const errorResponse = {
|
|
17023
17470
|
jsonrpc: "2.0",
|
|
17024
17471
|
id: request.id,
|
|
17025
17472
|
error: {
|
|
17026
17473
|
code: exports2.ErrorCode.MethodNotFound,
|
|
17027
17474
|
message: "Method not found"
|
|
17028
17475
|
}
|
|
17029
|
-
}
|
|
17476
|
+
};
|
|
17477
|
+
if (relatedTaskId && this._taskMessageQueue) {
|
|
17478
|
+
this._enqueueTaskMessage(relatedTaskId, {
|
|
17479
|
+
type: "error",
|
|
17480
|
+
message: errorResponse,
|
|
17481
|
+
timestamp: Date.now()
|
|
17482
|
+
}, capturedTransport?.sessionId).catch((error) => this._onerror(new Error(`Failed to enqueue error response: ${error}`)));
|
|
17483
|
+
} else {
|
|
17484
|
+
capturedTransport?.send(errorResponse).catch((error) => this._onerror(new Error(`Failed to send an error response: ${error}`)));
|
|
17485
|
+
}
|
|
17030
17486
|
return;
|
|
17031
17487
|
}
|
|
17032
17488
|
const abortController = new AbortController();
|
|
17033
17489
|
this._requestHandlerAbortControllers.set(request.id, abortController);
|
|
17490
|
+
const taskCreationParams = isTaskAugmentedRequestParams(request.params) ? request.params.task : void 0;
|
|
17491
|
+
const taskStore = this._taskStore ? this.requestTaskStore(request, capturedTransport?.sessionId) : void 0;
|
|
17034
17492
|
const fullExtra = {
|
|
17035
17493
|
signal: abortController.signal,
|
|
17036
|
-
sessionId: capturedTransport
|
|
17037
|
-
_meta:
|
|
17038
|
-
sendNotification: (notification) =>
|
|
17039
|
-
|
|
17040
|
-
|
|
17494
|
+
sessionId: capturedTransport?.sessionId,
|
|
17495
|
+
_meta: request.params?._meta,
|
|
17496
|
+
sendNotification: async (notification) => {
|
|
17497
|
+
const notificationOptions = { relatedRequestId: request.id };
|
|
17498
|
+
if (relatedTaskId) {
|
|
17499
|
+
notificationOptions.relatedTask = { taskId: relatedTaskId };
|
|
17500
|
+
}
|
|
17501
|
+
await this.notification(notification, notificationOptions);
|
|
17502
|
+
},
|
|
17503
|
+
sendRequest: async (r, resultSchema, options) => {
|
|
17504
|
+
const requestOptions = { ...options, relatedRequestId: request.id };
|
|
17505
|
+
if (relatedTaskId && !requestOptions.relatedTask) {
|
|
17506
|
+
requestOptions.relatedTask = { taskId: relatedTaskId };
|
|
17507
|
+
}
|
|
17508
|
+
const effectiveTaskId = requestOptions.relatedTask?.taskId ?? relatedTaskId;
|
|
17509
|
+
if (effectiveTaskId && taskStore) {
|
|
17510
|
+
await taskStore.updateTaskStatus(effectiveTaskId, "input_required");
|
|
17511
|
+
}
|
|
17512
|
+
return await this.request(r, resultSchema, requestOptions);
|
|
17513
|
+
},
|
|
17514
|
+
authInfo: extra?.authInfo,
|
|
17041
17515
|
requestId: request.id,
|
|
17042
|
-
requestInfo: extra
|
|
17516
|
+
requestInfo: extra?.requestInfo,
|
|
17517
|
+
taskId: relatedTaskId,
|
|
17518
|
+
taskStore,
|
|
17519
|
+
taskRequestedTtl: taskCreationParams?.ttl,
|
|
17520
|
+
closeSSEStream: extra?.closeSSEStream,
|
|
17521
|
+
closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
|
|
17043
17522
|
};
|
|
17044
|
-
Promise.resolve().then(() =>
|
|
17523
|
+
Promise.resolve().then(() => {
|
|
17524
|
+
if (taskCreationParams) {
|
|
17525
|
+
this.assertTaskHandlerCapability(request.method);
|
|
17526
|
+
}
|
|
17527
|
+
}).then(() => handler(request, fullExtra)).then(async (result) => {
|
|
17045
17528
|
if (abortController.signal.aborted) {
|
|
17046
17529
|
return;
|
|
17047
17530
|
}
|
|
17048
|
-
|
|
17531
|
+
const response = {
|
|
17049
17532
|
result,
|
|
17050
17533
|
jsonrpc: "2.0",
|
|
17051
17534
|
id: request.id
|
|
17052
|
-
}
|
|
17053
|
-
|
|
17054
|
-
|
|
17535
|
+
};
|
|
17536
|
+
if (relatedTaskId && this._taskMessageQueue) {
|
|
17537
|
+
await this._enqueueTaskMessage(relatedTaskId, {
|
|
17538
|
+
type: "response",
|
|
17539
|
+
message: response,
|
|
17540
|
+
timestamp: Date.now()
|
|
17541
|
+
}, capturedTransport?.sessionId);
|
|
17542
|
+
} else {
|
|
17543
|
+
await capturedTransport?.send(response);
|
|
17544
|
+
}
|
|
17545
|
+
}, async (error) => {
|
|
17055
17546
|
if (abortController.signal.aborted) {
|
|
17056
17547
|
return;
|
|
17057
17548
|
}
|
|
17058
|
-
|
|
17549
|
+
const errorResponse = {
|
|
17059
17550
|
jsonrpc: "2.0",
|
|
17060
17551
|
id: request.id,
|
|
17061
17552
|
error: {
|
|
17062
17553
|
code: Number.isSafeInteger(error["code"]) ? error["code"] : exports2.ErrorCode.InternalError,
|
|
17063
|
-
message:
|
|
17554
|
+
message: error.message ?? "Internal error",
|
|
17064
17555
|
...error["data"] !== void 0 && { data: error["data"] }
|
|
17065
17556
|
}
|
|
17066
|
-
}
|
|
17557
|
+
};
|
|
17558
|
+
if (relatedTaskId && this._taskMessageQueue) {
|
|
17559
|
+
await this._enqueueTaskMessage(relatedTaskId, {
|
|
17560
|
+
type: "error",
|
|
17561
|
+
message: errorResponse,
|
|
17562
|
+
timestamp: Date.now()
|
|
17563
|
+
}, capturedTransport?.sessionId);
|
|
17564
|
+
} else {
|
|
17565
|
+
await capturedTransport?.send(errorResponse);
|
|
17566
|
+
}
|
|
17067
17567
|
}).catch((error) => this._onerror(new Error(`Failed to send response: ${error}`))).finally(() => {
|
|
17068
17568
|
this._requestHandlerAbortControllers.delete(request.id);
|
|
17069
17569
|
});
|
|
@@ -17082,6 +17582,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17082
17582
|
try {
|
|
17083
17583
|
this._resetTimeout(messageId);
|
|
17084
17584
|
} catch (error) {
|
|
17585
|
+
this._responseHandlers.delete(messageId);
|
|
17586
|
+
this._progressHandlers.delete(messageId);
|
|
17587
|
+
this._cleanupTimeout(messageId);
|
|
17085
17588
|
responseHandler(error);
|
|
17086
17589
|
return;
|
|
17087
17590
|
}
|
|
@@ -17090,15 +17593,39 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17090
17593
|
}
|
|
17091
17594
|
_onresponse(response) {
|
|
17092
17595
|
const messageId = Number(response.id);
|
|
17596
|
+
const resolver = this._requestResolvers.get(messageId);
|
|
17597
|
+
if (resolver) {
|
|
17598
|
+
this._requestResolvers.delete(messageId);
|
|
17599
|
+
if (isJSONRPCResultResponse(response)) {
|
|
17600
|
+
resolver(response);
|
|
17601
|
+
} else {
|
|
17602
|
+
const error = new McpError(response.error.code, response.error.message, response.error.data);
|
|
17603
|
+
resolver(error);
|
|
17604
|
+
}
|
|
17605
|
+
return;
|
|
17606
|
+
}
|
|
17093
17607
|
const handler = this._responseHandlers.get(messageId);
|
|
17094
17608
|
if (handler === void 0) {
|
|
17095
17609
|
this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`));
|
|
17096
17610
|
return;
|
|
17097
17611
|
}
|
|
17098
17612
|
this._responseHandlers.delete(messageId);
|
|
17099
|
-
this._progressHandlers.delete(messageId);
|
|
17100
17613
|
this._cleanupTimeout(messageId);
|
|
17101
|
-
|
|
17614
|
+
let isTaskResponse = false;
|
|
17615
|
+
if (isJSONRPCResultResponse(response) && response.result && typeof response.result === "object") {
|
|
17616
|
+
const result = response.result;
|
|
17617
|
+
if (result.task && typeof result.task === "object") {
|
|
17618
|
+
const task = result.task;
|
|
17619
|
+
if (typeof task.taskId === "string") {
|
|
17620
|
+
isTaskResponse = true;
|
|
17621
|
+
this._taskProgressTokens.set(task.taskId, messageId);
|
|
17622
|
+
}
|
|
17623
|
+
}
|
|
17624
|
+
}
|
|
17625
|
+
if (!isTaskResponse) {
|
|
17626
|
+
this._progressHandlers.delete(messageId);
|
|
17627
|
+
}
|
|
17628
|
+
if (isJSONRPCResultResponse(response)) {
|
|
17102
17629
|
handler(response);
|
|
17103
17630
|
} else {
|
|
17104
17631
|
const error = McpError.fromError(response.error.code, response.error.message, response.error.data);
|
|
@@ -17112,60 +17639,169 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17112
17639
|
* Closes the connection.
|
|
17113
17640
|
*/
|
|
17114
17641
|
async close() {
|
|
17115
|
-
|
|
17116
|
-
|
|
17642
|
+
await this._transport?.close();
|
|
17643
|
+
}
|
|
17644
|
+
/**
|
|
17645
|
+
* Sends a request and returns an AsyncGenerator that yields response messages.
|
|
17646
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
17647
|
+
*
|
|
17648
|
+
* @example
|
|
17649
|
+
* ```typescript
|
|
17650
|
+
* const stream = protocol.requestStream(request, resultSchema, options);
|
|
17651
|
+
* for await (const message of stream) {
|
|
17652
|
+
* switch (message.type) {
|
|
17653
|
+
* case 'taskCreated':
|
|
17654
|
+
* console.log('Task created:', message.task.taskId);
|
|
17655
|
+
* break;
|
|
17656
|
+
* case 'taskStatus':
|
|
17657
|
+
* console.log('Task status:', message.task.status);
|
|
17658
|
+
* break;
|
|
17659
|
+
* case 'result':
|
|
17660
|
+
* console.log('Final result:', message.result);
|
|
17661
|
+
* break;
|
|
17662
|
+
* case 'error':
|
|
17663
|
+
* console.error('Error:', message.error);
|
|
17664
|
+
* break;
|
|
17665
|
+
* }
|
|
17666
|
+
* }
|
|
17667
|
+
* ```
|
|
17668
|
+
*
|
|
17669
|
+
* @experimental Use `client.experimental.tasks.requestStream()` to access this method.
|
|
17670
|
+
*/
|
|
17671
|
+
async *requestStream(request, resultSchema, options) {
|
|
17672
|
+
const { task } = options ?? {};
|
|
17673
|
+
if (!task) {
|
|
17674
|
+
try {
|
|
17675
|
+
const result = await this.request(request, resultSchema, options);
|
|
17676
|
+
yield { type: "result", result };
|
|
17677
|
+
} catch (error) {
|
|
17678
|
+
yield {
|
|
17679
|
+
type: "error",
|
|
17680
|
+
error: error instanceof McpError ? error : new McpError(exports2.ErrorCode.InternalError, String(error))
|
|
17681
|
+
};
|
|
17682
|
+
}
|
|
17683
|
+
return;
|
|
17684
|
+
}
|
|
17685
|
+
let taskId;
|
|
17686
|
+
try {
|
|
17687
|
+
const createResult = await this.request(request, CreateTaskResultSchema, options);
|
|
17688
|
+
if (createResult.task) {
|
|
17689
|
+
taskId = createResult.task.taskId;
|
|
17690
|
+
yield { type: "taskCreated", task: createResult.task };
|
|
17691
|
+
} else {
|
|
17692
|
+
throw new McpError(exports2.ErrorCode.InternalError, "Task creation did not return a task");
|
|
17693
|
+
}
|
|
17694
|
+
while (true) {
|
|
17695
|
+
const task2 = await this.getTask({ taskId }, options);
|
|
17696
|
+
yield { type: "taskStatus", task: task2 };
|
|
17697
|
+
if (isTerminal(task2.status)) {
|
|
17698
|
+
if (task2.status === "completed") {
|
|
17699
|
+
const result = await this.getTaskResult({ taskId }, resultSchema, options);
|
|
17700
|
+
yield { type: "result", result };
|
|
17701
|
+
} else if (task2.status === "failed") {
|
|
17702
|
+
yield {
|
|
17703
|
+
type: "error",
|
|
17704
|
+
error: new McpError(exports2.ErrorCode.InternalError, `Task ${taskId} failed`)
|
|
17705
|
+
};
|
|
17706
|
+
} else if (task2.status === "cancelled") {
|
|
17707
|
+
yield {
|
|
17708
|
+
type: "error",
|
|
17709
|
+
error: new McpError(exports2.ErrorCode.InternalError, `Task ${taskId} was cancelled`)
|
|
17710
|
+
};
|
|
17711
|
+
}
|
|
17712
|
+
return;
|
|
17713
|
+
}
|
|
17714
|
+
if (task2.status === "input_required") {
|
|
17715
|
+
const result = await this.getTaskResult({ taskId }, resultSchema, options);
|
|
17716
|
+
yield { type: "result", result };
|
|
17717
|
+
return;
|
|
17718
|
+
}
|
|
17719
|
+
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
17720
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
17721
|
+
options?.signal?.throwIfAborted();
|
|
17722
|
+
}
|
|
17723
|
+
} catch (error) {
|
|
17724
|
+
yield {
|
|
17725
|
+
type: "error",
|
|
17726
|
+
error: error instanceof McpError ? error : new McpError(exports2.ErrorCode.InternalError, String(error))
|
|
17727
|
+
};
|
|
17728
|
+
}
|
|
17117
17729
|
}
|
|
17118
17730
|
/**
|
|
17119
|
-
* Sends a request and
|
|
17731
|
+
* Sends a request and waits for a response.
|
|
17120
17732
|
*
|
|
17121
17733
|
* Do not use this method to emit notifications! Use notification() instead.
|
|
17122
17734
|
*/
|
|
17123
17735
|
request(request, resultSchema, options) {
|
|
17124
|
-
const { relatedRequestId, resumptionToken, onresumptiontoken } = options
|
|
17736
|
+
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
17125
17737
|
return new Promise((resolve2, reject) => {
|
|
17126
|
-
|
|
17738
|
+
const earlyReject = (error) => {
|
|
17739
|
+
reject(error);
|
|
17740
|
+
};
|
|
17127
17741
|
if (!this._transport) {
|
|
17128
|
-
|
|
17742
|
+
earlyReject(new Error("Not connected"));
|
|
17129
17743
|
return;
|
|
17130
17744
|
}
|
|
17131
|
-
if (
|
|
17132
|
-
|
|
17745
|
+
if (this._options?.enforceStrictCapabilities === true) {
|
|
17746
|
+
try {
|
|
17747
|
+
this.assertCapabilityForMethod(request.method);
|
|
17748
|
+
if (task) {
|
|
17749
|
+
this.assertTaskCapability(request.method);
|
|
17750
|
+
}
|
|
17751
|
+
} catch (e) {
|
|
17752
|
+
earlyReject(e);
|
|
17753
|
+
return;
|
|
17754
|
+
}
|
|
17133
17755
|
}
|
|
17134
|
-
|
|
17756
|
+
options?.signal?.throwIfAborted();
|
|
17135
17757
|
const messageId = this._requestMessageId++;
|
|
17136
17758
|
const jsonrpcRequest = {
|
|
17137
17759
|
...request,
|
|
17138
17760
|
jsonrpc: "2.0",
|
|
17139
17761
|
id: messageId
|
|
17140
17762
|
};
|
|
17141
|
-
if (options
|
|
17763
|
+
if (options?.onprogress) {
|
|
17142
17764
|
this._progressHandlers.set(messageId, options.onprogress);
|
|
17143
17765
|
jsonrpcRequest.params = {
|
|
17144
17766
|
...request.params,
|
|
17145
17767
|
_meta: {
|
|
17146
|
-
...
|
|
17768
|
+
...request.params?._meta || {},
|
|
17147
17769
|
progressToken: messageId
|
|
17148
17770
|
}
|
|
17149
17771
|
};
|
|
17150
17772
|
}
|
|
17773
|
+
if (task) {
|
|
17774
|
+
jsonrpcRequest.params = {
|
|
17775
|
+
...jsonrpcRequest.params,
|
|
17776
|
+
task
|
|
17777
|
+
};
|
|
17778
|
+
}
|
|
17779
|
+
if (relatedTask) {
|
|
17780
|
+
jsonrpcRequest.params = {
|
|
17781
|
+
...jsonrpcRequest.params,
|
|
17782
|
+
_meta: {
|
|
17783
|
+
...jsonrpcRequest.params?._meta || {},
|
|
17784
|
+
[RELATED_TASK_META_KEY]: relatedTask
|
|
17785
|
+
}
|
|
17786
|
+
};
|
|
17787
|
+
}
|
|
17151
17788
|
const cancel = (reason) => {
|
|
17152
|
-
var _a2;
|
|
17153
17789
|
this._responseHandlers.delete(messageId);
|
|
17154
17790
|
this._progressHandlers.delete(messageId);
|
|
17155
17791
|
this._cleanupTimeout(messageId);
|
|
17156
|
-
|
|
17792
|
+
this._transport?.send({
|
|
17157
17793
|
jsonrpc: "2.0",
|
|
17158
17794
|
method: "notifications/cancelled",
|
|
17159
17795
|
params: {
|
|
17160
17796
|
requestId: messageId,
|
|
17161
17797
|
reason: String(reason)
|
|
17162
17798
|
}
|
|
17163
|
-
}, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((
|
|
17164
|
-
|
|
17799
|
+
}, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error2) => this._onerror(new Error(`Failed to send cancellation: ${error2}`)));
|
|
17800
|
+
const error = reason instanceof McpError ? reason : new McpError(exports2.ErrorCode.RequestTimeout, String(reason));
|
|
17801
|
+
reject(error);
|
|
17165
17802
|
};
|
|
17166
17803
|
this._responseHandlers.set(messageId, (response) => {
|
|
17167
|
-
|
|
17168
|
-
if ((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.aborted) {
|
|
17804
|
+
if (options?.signal?.aborted) {
|
|
17169
17805
|
return;
|
|
17170
17806
|
}
|
|
17171
17807
|
if (response instanceof Error) {
|
|
@@ -17182,53 +17818,147 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17182
17818
|
reject(error);
|
|
17183
17819
|
}
|
|
17184
17820
|
});
|
|
17185
|
-
|
|
17186
|
-
|
|
17187
|
-
cancel((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.reason);
|
|
17821
|
+
options?.signal?.addEventListener("abort", () => {
|
|
17822
|
+
cancel(options?.signal?.reason);
|
|
17188
17823
|
});
|
|
17189
|
-
const timeout =
|
|
17824
|
+
const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
17190
17825
|
const timeoutHandler = () => cancel(McpError.fromError(exports2.ErrorCode.RequestTimeout, "Request timed out", { timeout }));
|
|
17191
|
-
this._setupTimeout(messageId, timeout, options
|
|
17192
|
-
|
|
17193
|
-
|
|
17194
|
-
|
|
17195
|
-
|
|
17826
|
+
this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
|
|
17827
|
+
const relatedTaskId = relatedTask?.taskId;
|
|
17828
|
+
if (relatedTaskId) {
|
|
17829
|
+
const responseResolver = (response) => {
|
|
17830
|
+
const handler = this._responseHandlers.get(messageId);
|
|
17831
|
+
if (handler) {
|
|
17832
|
+
handler(response);
|
|
17833
|
+
} else {
|
|
17834
|
+
this._onerror(new Error(`Response handler missing for side-channeled request ${messageId}`));
|
|
17835
|
+
}
|
|
17836
|
+
};
|
|
17837
|
+
this._requestResolvers.set(messageId, responseResolver);
|
|
17838
|
+
this._enqueueTaskMessage(relatedTaskId, {
|
|
17839
|
+
type: "request",
|
|
17840
|
+
message: jsonrpcRequest,
|
|
17841
|
+
timestamp: Date.now()
|
|
17842
|
+
}).catch((error) => {
|
|
17843
|
+
this._cleanupTimeout(messageId);
|
|
17844
|
+
reject(error);
|
|
17845
|
+
});
|
|
17846
|
+
} else {
|
|
17847
|
+
this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error) => {
|
|
17848
|
+
this._cleanupTimeout(messageId);
|
|
17849
|
+
reject(error);
|
|
17850
|
+
});
|
|
17851
|
+
}
|
|
17196
17852
|
});
|
|
17197
17853
|
}
|
|
17854
|
+
/**
|
|
17855
|
+
* Gets the current status of a task.
|
|
17856
|
+
*
|
|
17857
|
+
* @experimental Use `client.experimental.tasks.getTask()` to access this method.
|
|
17858
|
+
*/
|
|
17859
|
+
async getTask(params, options) {
|
|
17860
|
+
return this.request({ method: "tasks/get", params }, GetTaskResultSchema, options);
|
|
17861
|
+
}
|
|
17862
|
+
/**
|
|
17863
|
+
* Retrieves the result of a completed task.
|
|
17864
|
+
*
|
|
17865
|
+
* @experimental Use `client.experimental.tasks.getTaskResult()` to access this method.
|
|
17866
|
+
*/
|
|
17867
|
+
async getTaskResult(params, resultSchema, options) {
|
|
17868
|
+
return this.request({ method: "tasks/result", params }, resultSchema, options);
|
|
17869
|
+
}
|
|
17870
|
+
/**
|
|
17871
|
+
* Lists tasks, optionally starting from a pagination cursor.
|
|
17872
|
+
*
|
|
17873
|
+
* @experimental Use `client.experimental.tasks.listTasks()` to access this method.
|
|
17874
|
+
*/
|
|
17875
|
+
async listTasks(params, options) {
|
|
17876
|
+
return this.request({ method: "tasks/list", params }, ListTasksResultSchema, options);
|
|
17877
|
+
}
|
|
17878
|
+
/**
|
|
17879
|
+
* Cancels a specific task.
|
|
17880
|
+
*
|
|
17881
|
+
* @experimental Use `client.experimental.tasks.cancelTask()` to access this method.
|
|
17882
|
+
*/
|
|
17883
|
+
async cancelTask(params, options) {
|
|
17884
|
+
return this.request({ method: "tasks/cancel", params }, CancelTaskResultSchema, options);
|
|
17885
|
+
}
|
|
17198
17886
|
/**
|
|
17199
17887
|
* Emits a notification, which is a one-way message that does not expect a response.
|
|
17200
17888
|
*/
|
|
17201
17889
|
async notification(notification, options) {
|
|
17202
|
-
var _a, _b;
|
|
17203
17890
|
if (!this._transport) {
|
|
17204
17891
|
throw new Error("Not connected");
|
|
17205
17892
|
}
|
|
17206
17893
|
this.assertNotificationCapability(notification.method);
|
|
17207
|
-
const
|
|
17208
|
-
|
|
17894
|
+
const relatedTaskId = options?.relatedTask?.taskId;
|
|
17895
|
+
if (relatedTaskId) {
|
|
17896
|
+
const jsonrpcNotification2 = {
|
|
17897
|
+
...notification,
|
|
17898
|
+
jsonrpc: "2.0",
|
|
17899
|
+
params: {
|
|
17900
|
+
...notification.params,
|
|
17901
|
+
_meta: {
|
|
17902
|
+
...notification.params?._meta || {},
|
|
17903
|
+
[RELATED_TASK_META_KEY]: options.relatedTask
|
|
17904
|
+
}
|
|
17905
|
+
}
|
|
17906
|
+
};
|
|
17907
|
+
await this._enqueueTaskMessage(relatedTaskId, {
|
|
17908
|
+
type: "notification",
|
|
17909
|
+
message: jsonrpcNotification2,
|
|
17910
|
+
timestamp: Date.now()
|
|
17911
|
+
});
|
|
17912
|
+
return;
|
|
17913
|
+
}
|
|
17914
|
+
const debouncedMethods = this._options?.debouncedNotificationMethods ?? [];
|
|
17915
|
+
const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !options?.relatedRequestId && !options?.relatedTask;
|
|
17209
17916
|
if (canDebounce) {
|
|
17210
17917
|
if (this._pendingDebouncedNotifications.has(notification.method)) {
|
|
17211
17918
|
return;
|
|
17212
17919
|
}
|
|
17213
17920
|
this._pendingDebouncedNotifications.add(notification.method);
|
|
17214
17921
|
Promise.resolve().then(() => {
|
|
17215
|
-
var _a2;
|
|
17216
17922
|
this._pendingDebouncedNotifications.delete(notification.method);
|
|
17217
17923
|
if (!this._transport) {
|
|
17218
17924
|
return;
|
|
17219
17925
|
}
|
|
17220
|
-
|
|
17926
|
+
let jsonrpcNotification2 = {
|
|
17221
17927
|
...notification,
|
|
17222
17928
|
jsonrpc: "2.0"
|
|
17223
17929
|
};
|
|
17224
|
-
|
|
17930
|
+
if (options?.relatedTask) {
|
|
17931
|
+
jsonrpcNotification2 = {
|
|
17932
|
+
...jsonrpcNotification2,
|
|
17933
|
+
params: {
|
|
17934
|
+
...jsonrpcNotification2.params,
|
|
17935
|
+
_meta: {
|
|
17936
|
+
...jsonrpcNotification2.params?._meta || {},
|
|
17937
|
+
[RELATED_TASK_META_KEY]: options.relatedTask
|
|
17938
|
+
}
|
|
17939
|
+
}
|
|
17940
|
+
};
|
|
17941
|
+
}
|
|
17942
|
+
this._transport?.send(jsonrpcNotification2, options).catch((error) => this._onerror(error));
|
|
17225
17943
|
});
|
|
17226
17944
|
return;
|
|
17227
17945
|
}
|
|
17228
|
-
|
|
17946
|
+
let jsonrpcNotification = {
|
|
17229
17947
|
...notification,
|
|
17230
17948
|
jsonrpc: "2.0"
|
|
17231
17949
|
};
|
|
17950
|
+
if (options?.relatedTask) {
|
|
17951
|
+
jsonrpcNotification = {
|
|
17952
|
+
...jsonrpcNotification,
|
|
17953
|
+
params: {
|
|
17954
|
+
...jsonrpcNotification.params,
|
|
17955
|
+
_meta: {
|
|
17956
|
+
...jsonrpcNotification.params?._meta || {},
|
|
17957
|
+
[RELATED_TASK_META_KEY]: options.relatedTask
|
|
17958
|
+
}
|
|
17959
|
+
}
|
|
17960
|
+
};
|
|
17961
|
+
}
|
|
17232
17962
|
await this._transport.send(jsonrpcNotification, options);
|
|
17233
17963
|
}
|
|
17234
17964
|
/**
|
|
@@ -17276,6 +18006,150 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17276
18006
|
removeNotificationHandler(method) {
|
|
17277
18007
|
this._notificationHandlers.delete(method);
|
|
17278
18008
|
}
|
|
18009
|
+
/**
|
|
18010
|
+
* Cleans up the progress handler associated with a task.
|
|
18011
|
+
* This should be called when a task reaches a terminal status.
|
|
18012
|
+
*/
|
|
18013
|
+
_cleanupTaskProgressHandler(taskId) {
|
|
18014
|
+
const progressToken = this._taskProgressTokens.get(taskId);
|
|
18015
|
+
if (progressToken !== void 0) {
|
|
18016
|
+
this._progressHandlers.delete(progressToken);
|
|
18017
|
+
this._taskProgressTokens.delete(taskId);
|
|
18018
|
+
}
|
|
18019
|
+
}
|
|
18020
|
+
/**
|
|
18021
|
+
* Enqueues a task-related message for side-channel delivery via tasks/result.
|
|
18022
|
+
* @param taskId The task ID to associate the message with
|
|
18023
|
+
* @param message The message to enqueue
|
|
18024
|
+
* @param sessionId Optional session ID for binding the operation to a specific session
|
|
18025
|
+
* @throws Error if taskStore is not configured or if enqueue fails (e.g., queue overflow)
|
|
18026
|
+
*
|
|
18027
|
+
* Note: If enqueue fails, it's the TaskMessageQueue implementation's responsibility to handle
|
|
18028
|
+
* the error appropriately (e.g., by failing the task, logging, etc.). The Protocol layer
|
|
18029
|
+
* simply propagates the error.
|
|
18030
|
+
*/
|
|
18031
|
+
async _enqueueTaskMessage(taskId, message, sessionId) {
|
|
18032
|
+
if (!this._taskStore || !this._taskMessageQueue) {
|
|
18033
|
+
throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
|
|
18034
|
+
}
|
|
18035
|
+
const maxQueueSize = this._options?.maxTaskQueueSize;
|
|
18036
|
+
await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
|
|
18037
|
+
}
|
|
18038
|
+
/**
|
|
18039
|
+
* Clears the message queue for a task and rejects any pending request resolvers.
|
|
18040
|
+
* @param taskId The task ID whose queue should be cleared
|
|
18041
|
+
* @param sessionId Optional session ID for binding the operation to a specific session
|
|
18042
|
+
*/
|
|
18043
|
+
async _clearTaskQueue(taskId, sessionId) {
|
|
18044
|
+
if (this._taskMessageQueue) {
|
|
18045
|
+
const messages = await this._taskMessageQueue.dequeueAll(taskId, sessionId);
|
|
18046
|
+
for (const message of messages) {
|
|
18047
|
+
if (message.type === "request" && isJSONRPCRequest(message.message)) {
|
|
18048
|
+
const requestId = message.message.id;
|
|
18049
|
+
const resolver = this._requestResolvers.get(requestId);
|
|
18050
|
+
if (resolver) {
|
|
18051
|
+
resolver(new McpError(exports2.ErrorCode.InternalError, "Task cancelled or completed"));
|
|
18052
|
+
this._requestResolvers.delete(requestId);
|
|
18053
|
+
} else {
|
|
18054
|
+
this._onerror(new Error(`Resolver missing for request ${requestId} during task ${taskId} cleanup`));
|
|
18055
|
+
}
|
|
18056
|
+
}
|
|
18057
|
+
}
|
|
18058
|
+
}
|
|
18059
|
+
}
|
|
18060
|
+
/**
|
|
18061
|
+
* Waits for a task update (new messages or status change) with abort signal support.
|
|
18062
|
+
* Uses polling to check for updates at the task's configured poll interval.
|
|
18063
|
+
* @param taskId The task ID to wait for
|
|
18064
|
+
* @param signal Abort signal to cancel the wait
|
|
18065
|
+
* @returns Promise that resolves when an update occurs or rejects if aborted
|
|
18066
|
+
*/
|
|
18067
|
+
async _waitForTaskUpdate(taskId, signal) {
|
|
18068
|
+
let interval = this._options?.defaultTaskPollInterval ?? 1e3;
|
|
18069
|
+
try {
|
|
18070
|
+
const task = await this._taskStore?.getTask(taskId);
|
|
18071
|
+
if (task?.pollInterval) {
|
|
18072
|
+
interval = task.pollInterval;
|
|
18073
|
+
}
|
|
18074
|
+
} catch {
|
|
18075
|
+
}
|
|
18076
|
+
return new Promise((resolve2, reject) => {
|
|
18077
|
+
if (signal.aborted) {
|
|
18078
|
+
reject(new McpError(exports2.ErrorCode.InvalidRequest, "Request cancelled"));
|
|
18079
|
+
return;
|
|
18080
|
+
}
|
|
18081
|
+
const timeoutId = setTimeout(resolve2, interval);
|
|
18082
|
+
signal.addEventListener("abort", () => {
|
|
18083
|
+
clearTimeout(timeoutId);
|
|
18084
|
+
reject(new McpError(exports2.ErrorCode.InvalidRequest, "Request cancelled"));
|
|
18085
|
+
}, { once: true });
|
|
18086
|
+
});
|
|
18087
|
+
}
|
|
18088
|
+
requestTaskStore(request, sessionId) {
|
|
18089
|
+
const taskStore = this._taskStore;
|
|
18090
|
+
if (!taskStore) {
|
|
18091
|
+
throw new Error("No task store configured");
|
|
18092
|
+
}
|
|
18093
|
+
return {
|
|
18094
|
+
createTask: async (taskParams) => {
|
|
18095
|
+
if (!request) {
|
|
18096
|
+
throw new Error("No request provided");
|
|
18097
|
+
}
|
|
18098
|
+
return await taskStore.createTask(taskParams, request.id, {
|
|
18099
|
+
method: request.method,
|
|
18100
|
+
params: request.params
|
|
18101
|
+
}, sessionId);
|
|
18102
|
+
},
|
|
18103
|
+
getTask: async (taskId) => {
|
|
18104
|
+
const task = await taskStore.getTask(taskId, sessionId);
|
|
18105
|
+
if (!task) {
|
|
18106
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, "Failed to retrieve task: Task not found");
|
|
18107
|
+
}
|
|
18108
|
+
return task;
|
|
18109
|
+
},
|
|
18110
|
+
storeTaskResult: async (taskId, status, result) => {
|
|
18111
|
+
await taskStore.storeTaskResult(taskId, status, result, sessionId);
|
|
18112
|
+
const task = await taskStore.getTask(taskId, sessionId);
|
|
18113
|
+
if (task) {
|
|
18114
|
+
const notification = TaskStatusNotificationSchema.parse({
|
|
18115
|
+
method: "notifications/tasks/status",
|
|
18116
|
+
params: task
|
|
18117
|
+
});
|
|
18118
|
+
await this.notification(notification);
|
|
18119
|
+
if (isTerminal(task.status)) {
|
|
18120
|
+
this._cleanupTaskProgressHandler(taskId);
|
|
18121
|
+
}
|
|
18122
|
+
}
|
|
18123
|
+
},
|
|
18124
|
+
getTaskResult: (taskId) => {
|
|
18125
|
+
return taskStore.getTaskResult(taskId, sessionId);
|
|
18126
|
+
},
|
|
18127
|
+
updateTaskStatus: async (taskId, status, statusMessage) => {
|
|
18128
|
+
const task = await taskStore.getTask(taskId, sessionId);
|
|
18129
|
+
if (!task) {
|
|
18130
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Task "${taskId}" not found - it may have been cleaned up`);
|
|
18131
|
+
}
|
|
18132
|
+
if (isTerminal(task.status)) {
|
|
18133
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Cannot update task "${taskId}" from terminal status "${task.status}" to "${status}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);
|
|
18134
|
+
}
|
|
18135
|
+
await taskStore.updateTaskStatus(taskId, status, statusMessage, sessionId);
|
|
18136
|
+
const updatedTask = await taskStore.getTask(taskId, sessionId);
|
|
18137
|
+
if (updatedTask) {
|
|
18138
|
+
const notification = TaskStatusNotificationSchema.parse({
|
|
18139
|
+
method: "notifications/tasks/status",
|
|
18140
|
+
params: updatedTask
|
|
18141
|
+
});
|
|
18142
|
+
await this.notification(notification);
|
|
18143
|
+
if (isTerminal(updatedTask.status)) {
|
|
18144
|
+
this._cleanupTaskProgressHandler(taskId);
|
|
18145
|
+
}
|
|
18146
|
+
}
|
|
18147
|
+
},
|
|
18148
|
+
listTasks: (cursor) => {
|
|
18149
|
+
return taskStore.listTasks(cursor, sessionId);
|
|
18150
|
+
}
|
|
18151
|
+
};
|
|
18152
|
+
}
|
|
17279
18153
|
}
|
|
17280
18154
|
function isPlainObject(value) {
|
|
17281
18155
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -17622,7 +18496,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17622
18496
|
var distExports = requireDist();
|
|
17623
18497
|
const _addFormats = /* @__PURE__ */ getDefaultExportFromCjs(distExports);
|
|
17624
18498
|
function createDefaultAjvInstance() {
|
|
17625
|
-
const ajv2 = new
|
|
18499
|
+
const ajv2 = new Ajv({
|
|
17626
18500
|
strict: false,
|
|
17627
18501
|
validateFormats: true,
|
|
17628
18502
|
validateSchema: false,
|
|
@@ -17654,7 +18528,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17654
18528
|
* ```
|
|
17655
18529
|
*/
|
|
17656
18530
|
constructor(ajv2) {
|
|
17657
|
-
this._ajv = ajv2
|
|
18531
|
+
this._ajv = ajv2 ?? createDefaultAjvInstance();
|
|
17658
18532
|
}
|
|
17659
18533
|
/**
|
|
17660
18534
|
* Create a validator for the given JSON Schema
|
|
@@ -17666,8 +18540,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17666
18540
|
* @returns A validator function that validates input data
|
|
17667
18541
|
*/
|
|
17668
18542
|
getValidator(schema) {
|
|
17669
|
-
|
|
17670
|
-
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);
|
|
18543
|
+
const ajvValidator = "$id" in schema && typeof schema.$id === "string" ? this._ajv.getSchema(schema.$id) ?? this._ajv.compile(schema) : this._ajv.compile(schema);
|
|
17671
18544
|
return (input) => {
|
|
17672
18545
|
const valid = ajvValidator(input);
|
|
17673
18546
|
if (valid) {
|
|
@@ -17686,6 +18559,187 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17686
18559
|
};
|
|
17687
18560
|
}
|
|
17688
18561
|
}
|
|
18562
|
+
class ExperimentalClientTasks {
|
|
18563
|
+
constructor(_client) {
|
|
18564
|
+
this._client = _client;
|
|
18565
|
+
}
|
|
18566
|
+
/**
|
|
18567
|
+
* Calls a tool and returns an AsyncGenerator that yields response messages.
|
|
18568
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
18569
|
+
*
|
|
18570
|
+
* This method provides streaming access to tool execution, allowing you to
|
|
18571
|
+
* observe intermediate task status updates for long-running tool calls.
|
|
18572
|
+
* Automatically validates structured output if the tool has an outputSchema.
|
|
18573
|
+
*
|
|
18574
|
+
* @example
|
|
18575
|
+
* ```typescript
|
|
18576
|
+
* const stream = client.experimental.tasks.callToolStream({ name: 'myTool', arguments: {} });
|
|
18577
|
+
* for await (const message of stream) {
|
|
18578
|
+
* switch (message.type) {
|
|
18579
|
+
* case 'taskCreated':
|
|
18580
|
+
* console.log('Tool execution started:', message.task.taskId);
|
|
18581
|
+
* break;
|
|
18582
|
+
* case 'taskStatus':
|
|
18583
|
+
* console.log('Tool status:', message.task.status);
|
|
18584
|
+
* break;
|
|
18585
|
+
* case 'result':
|
|
18586
|
+
* console.log('Tool result:', message.result);
|
|
18587
|
+
* break;
|
|
18588
|
+
* case 'error':
|
|
18589
|
+
* console.error('Tool error:', message.error);
|
|
18590
|
+
* break;
|
|
18591
|
+
* }
|
|
18592
|
+
* }
|
|
18593
|
+
* ```
|
|
18594
|
+
*
|
|
18595
|
+
* @param params - Tool call parameters (name and arguments)
|
|
18596
|
+
* @param resultSchema - Zod schema for validating the result (defaults to CallToolResultSchema)
|
|
18597
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
18598
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
18599
|
+
*
|
|
18600
|
+
* @experimental
|
|
18601
|
+
*/
|
|
18602
|
+
async *callToolStream(params, resultSchema = CallToolResultSchema, options) {
|
|
18603
|
+
const clientInternal = this._client;
|
|
18604
|
+
const optionsWithTask = {
|
|
18605
|
+
...options,
|
|
18606
|
+
// We check if the tool is known to be a task during auto-configuration, but assume
|
|
18607
|
+
// the caller knows what they're doing if they pass this explicitly
|
|
18608
|
+
task: options?.task ?? (clientInternal.isToolTask(params.name) ? {} : void 0)
|
|
18609
|
+
};
|
|
18610
|
+
const stream = clientInternal.requestStream({ method: "tools/call", params }, resultSchema, optionsWithTask);
|
|
18611
|
+
const validator = clientInternal.getToolOutputValidator(params.name);
|
|
18612
|
+
for await (const message of stream) {
|
|
18613
|
+
if (message.type === "result" && validator) {
|
|
18614
|
+
const result = message.result;
|
|
18615
|
+
if (!result.structuredContent && !result.isError) {
|
|
18616
|
+
yield {
|
|
18617
|
+
type: "error",
|
|
18618
|
+
error: new McpError(exports2.ErrorCode.InvalidRequest, `Tool ${params.name} has an output schema but did not return structured content`)
|
|
18619
|
+
};
|
|
18620
|
+
return;
|
|
18621
|
+
}
|
|
18622
|
+
if (result.structuredContent) {
|
|
18623
|
+
try {
|
|
18624
|
+
const validationResult = validator(result.structuredContent);
|
|
18625
|
+
if (!validationResult.valid) {
|
|
18626
|
+
yield {
|
|
18627
|
+
type: "error",
|
|
18628
|
+
error: new McpError(exports2.ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`)
|
|
18629
|
+
};
|
|
18630
|
+
return;
|
|
18631
|
+
}
|
|
18632
|
+
} catch (error) {
|
|
18633
|
+
if (error instanceof McpError) {
|
|
18634
|
+
yield { type: "error", error };
|
|
18635
|
+
return;
|
|
18636
|
+
}
|
|
18637
|
+
yield {
|
|
18638
|
+
type: "error",
|
|
18639
|
+
error: new McpError(exports2.ErrorCode.InvalidParams, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`)
|
|
18640
|
+
};
|
|
18641
|
+
return;
|
|
18642
|
+
}
|
|
18643
|
+
}
|
|
18644
|
+
}
|
|
18645
|
+
yield message;
|
|
18646
|
+
}
|
|
18647
|
+
}
|
|
18648
|
+
/**
|
|
18649
|
+
* Gets the current status of a task.
|
|
18650
|
+
*
|
|
18651
|
+
* @param taskId - The task identifier
|
|
18652
|
+
* @param options - Optional request options
|
|
18653
|
+
* @returns The task status
|
|
18654
|
+
*
|
|
18655
|
+
* @experimental
|
|
18656
|
+
*/
|
|
18657
|
+
async getTask(taskId, options) {
|
|
18658
|
+
return this._client.getTask({ taskId }, options);
|
|
18659
|
+
}
|
|
18660
|
+
/**
|
|
18661
|
+
* Retrieves the result of a completed task.
|
|
18662
|
+
*
|
|
18663
|
+
* @param taskId - The task identifier
|
|
18664
|
+
* @param resultSchema - Zod schema for validating the result
|
|
18665
|
+
* @param options - Optional request options
|
|
18666
|
+
* @returns The task result
|
|
18667
|
+
*
|
|
18668
|
+
* @experimental
|
|
18669
|
+
*/
|
|
18670
|
+
async getTaskResult(taskId, resultSchema, options) {
|
|
18671
|
+
return this._client.getTaskResult({ taskId }, resultSchema, options);
|
|
18672
|
+
}
|
|
18673
|
+
/**
|
|
18674
|
+
* Lists tasks with optional pagination.
|
|
18675
|
+
*
|
|
18676
|
+
* @param cursor - Optional pagination cursor
|
|
18677
|
+
* @param options - Optional request options
|
|
18678
|
+
* @returns List of tasks with optional next cursor
|
|
18679
|
+
*
|
|
18680
|
+
* @experimental
|
|
18681
|
+
*/
|
|
18682
|
+
async listTasks(cursor, options) {
|
|
18683
|
+
return this._client.listTasks(cursor ? { cursor } : void 0, options);
|
|
18684
|
+
}
|
|
18685
|
+
/**
|
|
18686
|
+
* Cancels a running task.
|
|
18687
|
+
*
|
|
18688
|
+
* @param taskId - The task identifier
|
|
18689
|
+
* @param options - Optional request options
|
|
18690
|
+
*
|
|
18691
|
+
* @experimental
|
|
18692
|
+
*/
|
|
18693
|
+
async cancelTask(taskId, options) {
|
|
18694
|
+
return this._client.cancelTask({ taskId }, options);
|
|
18695
|
+
}
|
|
18696
|
+
/**
|
|
18697
|
+
* Sends a request and returns an AsyncGenerator that yields response messages.
|
|
18698
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
18699
|
+
*
|
|
18700
|
+
* This method provides streaming access to request processing, allowing you to
|
|
18701
|
+
* observe intermediate task status updates for task-augmented requests.
|
|
18702
|
+
*
|
|
18703
|
+
* @param request - The request to send
|
|
18704
|
+
* @param resultSchema - Zod schema for validating the result
|
|
18705
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
18706
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
18707
|
+
*
|
|
18708
|
+
* @experimental
|
|
18709
|
+
*/
|
|
18710
|
+
requestStream(request, resultSchema, options) {
|
|
18711
|
+
return this._client.requestStream(request, resultSchema, options);
|
|
18712
|
+
}
|
|
18713
|
+
}
|
|
18714
|
+
function assertToolsCallTaskCapability(requests, method, entityName) {
|
|
18715
|
+
if (!requests) {
|
|
18716
|
+
throw new Error(`${entityName} does not support task creation (required for ${method})`);
|
|
18717
|
+
}
|
|
18718
|
+
switch (method) {
|
|
18719
|
+
case "tools/call":
|
|
18720
|
+
if (!requests.tools?.call) {
|
|
18721
|
+
throw new Error(`${entityName} does not support task creation for tools/call (required for ${method})`);
|
|
18722
|
+
}
|
|
18723
|
+
break;
|
|
18724
|
+
}
|
|
18725
|
+
}
|
|
18726
|
+
function assertClientRequestTaskCapability(requests, method, entityName) {
|
|
18727
|
+
if (!requests) {
|
|
18728
|
+
throw new Error(`${entityName} does not support task creation (required for ${method})`);
|
|
18729
|
+
}
|
|
18730
|
+
switch (method) {
|
|
18731
|
+
case "sampling/createMessage":
|
|
18732
|
+
if (!requests.sampling?.createMessage) {
|
|
18733
|
+
throw new Error(`${entityName} does not support task creation for sampling/createMessage (required for ${method})`);
|
|
18734
|
+
}
|
|
18735
|
+
break;
|
|
18736
|
+
case "elicitation/create":
|
|
18737
|
+
if (!requests.elicitation?.create) {
|
|
18738
|
+
throw new Error(`${entityName} does not support task creation for elicitation/create (required for ${method})`);
|
|
18739
|
+
}
|
|
18740
|
+
break;
|
|
18741
|
+
}
|
|
18742
|
+
}
|
|
17689
18743
|
function applyElicitationDefaults(schema, data) {
|
|
17690
18744
|
if (!schema || data === null || typeof data !== "object")
|
|
17691
18745
|
return;
|
|
@@ -17704,12 +18758,16 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17704
18758
|
}
|
|
17705
18759
|
if (Array.isArray(schema.anyOf)) {
|
|
17706
18760
|
for (const sub of schema.anyOf) {
|
|
17707
|
-
|
|
18761
|
+
if (typeof sub !== "boolean") {
|
|
18762
|
+
applyElicitationDefaults(sub, data);
|
|
18763
|
+
}
|
|
17708
18764
|
}
|
|
17709
18765
|
}
|
|
17710
18766
|
if (Array.isArray(schema.oneOf)) {
|
|
17711
18767
|
for (const sub of schema.oneOf) {
|
|
17712
|
-
|
|
18768
|
+
if (typeof sub !== "boolean") {
|
|
18769
|
+
applyElicitationDefaults(sub, data);
|
|
18770
|
+
}
|
|
17713
18771
|
}
|
|
17714
18772
|
}
|
|
17715
18773
|
}
|
|
@@ -17728,12 +18786,58 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17728
18786
|
* Initializes this client with the given name and version information.
|
|
17729
18787
|
*/
|
|
17730
18788
|
constructor(_clientInfo, options) {
|
|
17731
|
-
var _a, _b;
|
|
17732
18789
|
super(options);
|
|
17733
18790
|
this._clientInfo = _clientInfo;
|
|
17734
18791
|
this._cachedToolOutputValidators = /* @__PURE__ */ new Map();
|
|
17735
|
-
this.
|
|
17736
|
-
this.
|
|
18792
|
+
this._cachedKnownTaskTools = /* @__PURE__ */ new Set();
|
|
18793
|
+
this._cachedRequiredTaskTools = /* @__PURE__ */ new Set();
|
|
18794
|
+
this._listChangedDebounceTimers = /* @__PURE__ */ new Map();
|
|
18795
|
+
this._capabilities = options?.capabilities ?? {};
|
|
18796
|
+
this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new AjvJsonSchemaValidator();
|
|
18797
|
+
if (options?.listChanged) {
|
|
18798
|
+
this._pendingListChangedConfig = options.listChanged;
|
|
18799
|
+
}
|
|
18800
|
+
}
|
|
18801
|
+
/**
|
|
18802
|
+
* Set up handlers for list changed notifications based on config and server capabilities.
|
|
18803
|
+
* This should only be called after initialization when server capabilities are known.
|
|
18804
|
+
* Handlers are silently skipped if the server doesn't advertise the corresponding listChanged capability.
|
|
18805
|
+
* @internal
|
|
18806
|
+
*/
|
|
18807
|
+
_setupListChangedHandlers(config2) {
|
|
18808
|
+
if (config2.tools && this._serverCapabilities?.tools?.listChanged) {
|
|
18809
|
+
this._setupListChangedHandler("tools", ToolListChangedNotificationSchema, config2.tools, async () => {
|
|
18810
|
+
const result = await this.listTools();
|
|
18811
|
+
return result.tools;
|
|
18812
|
+
});
|
|
18813
|
+
}
|
|
18814
|
+
if (config2.prompts && this._serverCapabilities?.prompts?.listChanged) {
|
|
18815
|
+
this._setupListChangedHandler("prompts", PromptListChangedNotificationSchema, config2.prompts, async () => {
|
|
18816
|
+
const result = await this.listPrompts();
|
|
18817
|
+
return result.prompts;
|
|
18818
|
+
});
|
|
18819
|
+
}
|
|
18820
|
+
if (config2.resources && this._serverCapabilities?.resources?.listChanged) {
|
|
18821
|
+
this._setupListChangedHandler("resources", ResourceListChangedNotificationSchema, config2.resources, async () => {
|
|
18822
|
+
const result = await this.listResources();
|
|
18823
|
+
return result.resources;
|
|
18824
|
+
});
|
|
18825
|
+
}
|
|
18826
|
+
}
|
|
18827
|
+
/**
|
|
18828
|
+
* Access experimental features.
|
|
18829
|
+
*
|
|
18830
|
+
* WARNING: These APIs are experimental and may change without notice.
|
|
18831
|
+
*
|
|
18832
|
+
* @experimental
|
|
18833
|
+
*/
|
|
18834
|
+
get experimental() {
|
|
18835
|
+
if (!this._experimental) {
|
|
18836
|
+
this._experimental = {
|
|
18837
|
+
tasks: new ExperimentalClientTasks(this)
|
|
18838
|
+
};
|
|
18839
|
+
}
|
|
18840
|
+
return this._experimental;
|
|
17737
18841
|
}
|
|
17738
18842
|
/**
|
|
17739
18843
|
* Registers new capabilities. This can only be called before connecting to a transport.
|
|
@@ -17750,21 +18854,20 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17750
18854
|
* Override request handler registration to enforce client-side validation for elicitation.
|
|
17751
18855
|
*/
|
|
17752
18856
|
setRequestHandler(requestSchema, handler) {
|
|
17753
|
-
var _a, _b, _c;
|
|
17754
18857
|
const shape = getObjectShape(requestSchema);
|
|
17755
|
-
const methodSchema = shape
|
|
18858
|
+
const methodSchema = shape?.method;
|
|
17756
18859
|
if (!methodSchema) {
|
|
17757
18860
|
throw new Error("Schema is missing a method literal");
|
|
17758
18861
|
}
|
|
17759
18862
|
let methodValue;
|
|
17760
18863
|
if (isZ4Schema(methodSchema)) {
|
|
17761
18864
|
const v4Schema = methodSchema;
|
|
17762
|
-
const v4Def =
|
|
17763
|
-
methodValue =
|
|
18865
|
+
const v4Def = v4Schema._zod?.def;
|
|
18866
|
+
methodValue = v4Def?.value ?? v4Schema.value;
|
|
17764
18867
|
} else {
|
|
17765
18868
|
const v3Schema = methodSchema;
|
|
17766
18869
|
const legacyDef = v3Schema._def;
|
|
17767
|
-
methodValue =
|
|
18870
|
+
methodValue = legacyDef?.value ?? v3Schema.value;
|
|
17768
18871
|
}
|
|
17769
18872
|
if (typeof methodValue !== "string") {
|
|
17770
18873
|
throw new Error("Schema method literal must be a string");
|
|
@@ -17772,34 +18875,41 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17772
18875
|
const method = methodValue;
|
|
17773
18876
|
if (method === "elicitation/create") {
|
|
17774
18877
|
const wrappedHandler = async (request, extra) => {
|
|
17775
|
-
var _a2, _b2, _c2;
|
|
17776
18878
|
const validatedRequest = safeParse(ElicitRequestSchema, request);
|
|
17777
18879
|
if (!validatedRequest.success) {
|
|
17778
18880
|
const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
17779
18881
|
throw new McpError(exports2.ErrorCode.InvalidParams, `Invalid elicitation request: ${errorMessage}`);
|
|
17780
18882
|
}
|
|
17781
18883
|
const { params } = validatedRequest.data;
|
|
17782
|
-
|
|
18884
|
+
params.mode = params.mode ?? "form";
|
|
17783
18885
|
const { supportsFormMode, supportsUrlMode } = getSupportedElicitationModes(this._capabilities.elicitation);
|
|
17784
|
-
if (mode === "form" && !supportsFormMode) {
|
|
18886
|
+
if (params.mode === "form" && !supportsFormMode) {
|
|
17785
18887
|
throw new McpError(exports2.ErrorCode.InvalidParams, "Client does not support form-mode elicitation requests");
|
|
17786
18888
|
}
|
|
17787
|
-
if (mode === "url" && !supportsUrlMode) {
|
|
18889
|
+
if (params.mode === "url" && !supportsUrlMode) {
|
|
17788
18890
|
throw new McpError(exports2.ErrorCode.InvalidParams, "Client does not support URL-mode elicitation requests");
|
|
17789
18891
|
}
|
|
17790
18892
|
const result = await Promise.resolve(handler(request, extra));
|
|
18893
|
+
if (params.task) {
|
|
18894
|
+
const taskValidationResult = safeParse(CreateTaskResultSchema, result);
|
|
18895
|
+
if (!taskValidationResult.success) {
|
|
18896
|
+
const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
18897
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
|
|
18898
|
+
}
|
|
18899
|
+
return taskValidationResult.data;
|
|
18900
|
+
}
|
|
17791
18901
|
const validationResult = safeParse(ElicitResultSchema, result);
|
|
17792
18902
|
if (!validationResult.success) {
|
|
17793
18903
|
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
17794
18904
|
throw new McpError(exports2.ErrorCode.InvalidParams, `Invalid elicitation result: ${errorMessage}`);
|
|
17795
18905
|
}
|
|
17796
18906
|
const validatedResult = validationResult.data;
|
|
17797
|
-
const requestedSchema = mode === "form" ? params.requestedSchema : void 0;
|
|
17798
|
-
if (mode === "form" && validatedResult.action === "accept" && validatedResult.content && requestedSchema) {
|
|
17799
|
-
if (
|
|
18907
|
+
const requestedSchema = params.mode === "form" ? params.requestedSchema : void 0;
|
|
18908
|
+
if (params.mode === "form" && validatedResult.action === "accept" && validatedResult.content && requestedSchema) {
|
|
18909
|
+
if (this._capabilities.elicitation?.form?.applyDefaults) {
|
|
17800
18910
|
try {
|
|
17801
18911
|
applyElicitationDefaults(requestedSchema, validatedResult.content);
|
|
17802
|
-
} catch
|
|
18912
|
+
} catch {
|
|
17803
18913
|
}
|
|
17804
18914
|
}
|
|
17805
18915
|
}
|
|
@@ -17807,11 +18917,36 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17807
18917
|
};
|
|
17808
18918
|
return super.setRequestHandler(requestSchema, wrappedHandler);
|
|
17809
18919
|
}
|
|
18920
|
+
if (method === "sampling/createMessage") {
|
|
18921
|
+
const wrappedHandler = async (request, extra) => {
|
|
18922
|
+
const validatedRequest = safeParse(CreateMessageRequestSchema, request);
|
|
18923
|
+
if (!validatedRequest.success) {
|
|
18924
|
+
const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
18925
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Invalid sampling request: ${errorMessage}`);
|
|
18926
|
+
}
|
|
18927
|
+
const { params } = validatedRequest.data;
|
|
18928
|
+
const result = await Promise.resolve(handler(request, extra));
|
|
18929
|
+
if (params.task) {
|
|
18930
|
+
const taskValidationResult = safeParse(CreateTaskResultSchema, result);
|
|
18931
|
+
if (!taskValidationResult.success) {
|
|
18932
|
+
const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
18933
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
|
|
18934
|
+
}
|
|
18935
|
+
return taskValidationResult.data;
|
|
18936
|
+
}
|
|
18937
|
+
const validationResult = safeParse(CreateMessageResultSchema, result);
|
|
18938
|
+
if (!validationResult.success) {
|
|
18939
|
+
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
18940
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Invalid sampling result: ${errorMessage}`);
|
|
18941
|
+
}
|
|
18942
|
+
return validationResult.data;
|
|
18943
|
+
};
|
|
18944
|
+
return super.setRequestHandler(requestSchema, wrappedHandler);
|
|
18945
|
+
}
|
|
17810
18946
|
return super.setRequestHandler(requestSchema, handler);
|
|
17811
18947
|
}
|
|
17812
18948
|
assertCapability(capability, method) {
|
|
17813
|
-
|
|
17814
|
-
if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a[capability])) {
|
|
18949
|
+
if (!this._serverCapabilities?.[capability]) {
|
|
17815
18950
|
throw new Error(`Server does not support ${capability} (required for ${method})`);
|
|
17816
18951
|
}
|
|
17817
18952
|
}
|
|
@@ -17844,6 +18979,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17844
18979
|
await this.notification({
|
|
17845
18980
|
method: "notifications/initialized"
|
|
17846
18981
|
});
|
|
18982
|
+
if (this._pendingListChangedConfig) {
|
|
18983
|
+
this._setupListChangedHandlers(this._pendingListChangedConfig);
|
|
18984
|
+
this._pendingListChangedConfig = void 0;
|
|
18985
|
+
}
|
|
17847
18986
|
} catch (error) {
|
|
17848
18987
|
void this.close();
|
|
17849
18988
|
throw error;
|
|
@@ -17868,16 +19007,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17868
19007
|
return this._instructions;
|
|
17869
19008
|
}
|
|
17870
19009
|
assertCapabilityForMethod(method) {
|
|
17871
|
-
var _a, _b, _c, _d, _e;
|
|
17872
19010
|
switch (method) {
|
|
17873
19011
|
case "logging/setLevel":
|
|
17874
|
-
if (!
|
|
19012
|
+
if (!this._serverCapabilities?.logging) {
|
|
17875
19013
|
throw new Error(`Server does not support logging (required for ${method})`);
|
|
17876
19014
|
}
|
|
17877
19015
|
break;
|
|
17878
19016
|
case "prompts/get":
|
|
17879
19017
|
case "prompts/list":
|
|
17880
|
-
if (!
|
|
19018
|
+
if (!this._serverCapabilities?.prompts) {
|
|
17881
19019
|
throw new Error(`Server does not support prompts (required for ${method})`);
|
|
17882
19020
|
}
|
|
17883
19021
|
break;
|
|
@@ -17886,7 +19024,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17886
19024
|
case "resources/read":
|
|
17887
19025
|
case "resources/subscribe":
|
|
17888
19026
|
case "resources/unsubscribe":
|
|
17889
|
-
if (!
|
|
19027
|
+
if (!this._serverCapabilities?.resources) {
|
|
17890
19028
|
throw new Error(`Server does not support resources (required for ${method})`);
|
|
17891
19029
|
}
|
|
17892
19030
|
if (method === "resources/subscribe" && !this._serverCapabilities.resources.subscribe) {
|
|
@@ -17895,28 +19033,30 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17895
19033
|
break;
|
|
17896
19034
|
case "tools/call":
|
|
17897
19035
|
case "tools/list":
|
|
17898
|
-
if (!
|
|
19036
|
+
if (!this._serverCapabilities?.tools) {
|
|
17899
19037
|
throw new Error(`Server does not support tools (required for ${method})`);
|
|
17900
19038
|
}
|
|
17901
19039
|
break;
|
|
17902
19040
|
case "completion/complete":
|
|
17903
|
-
if (!
|
|
19041
|
+
if (!this._serverCapabilities?.completions) {
|
|
17904
19042
|
throw new Error(`Server does not support completions (required for ${method})`);
|
|
17905
19043
|
}
|
|
17906
19044
|
break;
|
|
17907
19045
|
}
|
|
17908
19046
|
}
|
|
17909
19047
|
assertNotificationCapability(method) {
|
|
17910
|
-
var _a;
|
|
17911
19048
|
switch (method) {
|
|
17912
19049
|
case "notifications/roots/list_changed":
|
|
17913
|
-
if (!
|
|
19050
|
+
if (!this._capabilities.roots?.listChanged) {
|
|
17914
19051
|
throw new Error(`Client does not support roots list changed notifications (required for ${method})`);
|
|
17915
19052
|
}
|
|
17916
19053
|
break;
|
|
17917
19054
|
}
|
|
17918
19055
|
}
|
|
17919
19056
|
assertRequestHandlerCapability(method) {
|
|
19057
|
+
if (!this._capabilities) {
|
|
19058
|
+
return;
|
|
19059
|
+
}
|
|
17920
19060
|
switch (method) {
|
|
17921
19061
|
case "sampling/createMessage":
|
|
17922
19062
|
if (!this._capabilities.sampling) {
|
|
@@ -17933,7 +19073,24 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17933
19073
|
throw new Error(`Client does not support roots capability (required for ${method})`);
|
|
17934
19074
|
}
|
|
17935
19075
|
break;
|
|
19076
|
+
case "tasks/get":
|
|
19077
|
+
case "tasks/list":
|
|
19078
|
+
case "tasks/result":
|
|
19079
|
+
case "tasks/cancel":
|
|
19080
|
+
if (!this._capabilities.tasks) {
|
|
19081
|
+
throw new Error(`Client does not support tasks capability (required for ${method})`);
|
|
19082
|
+
}
|
|
19083
|
+
break;
|
|
19084
|
+
}
|
|
19085
|
+
}
|
|
19086
|
+
assertTaskCapability(method) {
|
|
19087
|
+
assertToolsCallTaskCapability(this._serverCapabilities?.tasks?.requests, method, "Server");
|
|
19088
|
+
}
|
|
19089
|
+
assertTaskHandlerCapability(method) {
|
|
19090
|
+
if (!this._capabilities) {
|
|
19091
|
+
return;
|
|
17936
19092
|
}
|
|
19093
|
+
assertClientRequestTaskCapability(this._capabilities.tasks?.requests, method, "Client");
|
|
17937
19094
|
}
|
|
17938
19095
|
async ping(options) {
|
|
17939
19096
|
return this.request({ method: "ping" }, EmptyResultSchema, options);
|
|
@@ -17965,7 +19122,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17965
19122
|
async unsubscribeResource(params, options) {
|
|
17966
19123
|
return this.request({ method: "resources/unsubscribe", params }, EmptyResultSchema, options);
|
|
17967
19124
|
}
|
|
19125
|
+
/**
|
|
19126
|
+
* Calls a tool and waits for the result. Automatically validates structured output if the tool has an outputSchema.
|
|
19127
|
+
*
|
|
19128
|
+
* For task-based execution with streaming behavior, use client.experimental.tasks.callToolStream() instead.
|
|
19129
|
+
*/
|
|
17968
19130
|
async callTool(params, resultSchema = CallToolResultSchema, options) {
|
|
19131
|
+
if (this.isToolTaskRequired(params.name)) {
|
|
19132
|
+
throw new McpError(exports2.ErrorCode.InvalidRequest, `Tool "${params.name}" requires task-based execution. Use client.experimental.tasks.callToolStream() instead.`);
|
|
19133
|
+
}
|
|
17969
19134
|
const result = await this.request({ method: "tools/call", params }, resultSchema, options);
|
|
17970
19135
|
const validator = this.getToolOutputValidator(params.name);
|
|
17971
19136
|
if (validator) {
|
|
@@ -17988,17 +19153,39 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
17988
19153
|
}
|
|
17989
19154
|
return result;
|
|
17990
19155
|
}
|
|
19156
|
+
isToolTask(toolName) {
|
|
19157
|
+
if (!this._serverCapabilities?.tasks?.requests?.tools?.call) {
|
|
19158
|
+
return false;
|
|
19159
|
+
}
|
|
19160
|
+
return this._cachedKnownTaskTools.has(toolName);
|
|
19161
|
+
}
|
|
19162
|
+
/**
|
|
19163
|
+
* Check if a tool requires task-based execution.
|
|
19164
|
+
* Unlike isToolTask which includes 'optional' tools, this only checks for 'required'.
|
|
19165
|
+
*/
|
|
19166
|
+
isToolTaskRequired(toolName) {
|
|
19167
|
+
return this._cachedRequiredTaskTools.has(toolName);
|
|
19168
|
+
}
|
|
17991
19169
|
/**
|
|
17992
19170
|
* Cache validators for tool output schemas.
|
|
17993
19171
|
* Called after listTools() to pre-compile validators for better performance.
|
|
17994
19172
|
*/
|
|
17995
|
-
|
|
19173
|
+
cacheToolMetadata(tools) {
|
|
17996
19174
|
this._cachedToolOutputValidators.clear();
|
|
19175
|
+
this._cachedKnownTaskTools.clear();
|
|
19176
|
+
this._cachedRequiredTaskTools.clear();
|
|
17997
19177
|
for (const tool of tools) {
|
|
17998
19178
|
if (tool.outputSchema) {
|
|
17999
19179
|
const toolValidator = this._jsonSchemaValidator.getValidator(tool.outputSchema);
|
|
18000
19180
|
this._cachedToolOutputValidators.set(tool.name, toolValidator);
|
|
18001
19181
|
}
|
|
19182
|
+
const taskSupport = tool.execution?.taskSupport;
|
|
19183
|
+
if (taskSupport === "required" || taskSupport === "optional") {
|
|
19184
|
+
this._cachedKnownTaskTools.add(tool.name);
|
|
19185
|
+
}
|
|
19186
|
+
if (taskSupport === "required") {
|
|
19187
|
+
this._cachedRequiredTaskTools.add(tool.name);
|
|
19188
|
+
}
|
|
18002
19189
|
}
|
|
18003
19190
|
}
|
|
18004
19191
|
/**
|
|
@@ -18009,9 +19196,50 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18009
19196
|
}
|
|
18010
19197
|
async listTools(params, options) {
|
|
18011
19198
|
const result = await this.request({ method: "tools/list", params }, ListToolsResultSchema, options);
|
|
18012
|
-
this.
|
|
19199
|
+
this.cacheToolMetadata(result.tools);
|
|
18013
19200
|
return result;
|
|
18014
19201
|
}
|
|
19202
|
+
/**
|
|
19203
|
+
* Set up a single list changed handler.
|
|
19204
|
+
* @internal
|
|
19205
|
+
*/
|
|
19206
|
+
_setupListChangedHandler(listType, notificationSchema, options, fetcher) {
|
|
19207
|
+
const parseResult = ListChangedOptionsBaseSchema.safeParse(options);
|
|
19208
|
+
if (!parseResult.success) {
|
|
19209
|
+
throw new Error(`Invalid ${listType} listChanged options: ${parseResult.error.message}`);
|
|
19210
|
+
}
|
|
19211
|
+
if (typeof options.onChanged !== "function") {
|
|
19212
|
+
throw new Error(`Invalid ${listType} listChanged options: onChanged must be a function`);
|
|
19213
|
+
}
|
|
19214
|
+
const { autoRefresh, debounceMs } = parseResult.data;
|
|
19215
|
+
const { onChanged } = options;
|
|
19216
|
+
const refresh = async () => {
|
|
19217
|
+
if (!autoRefresh) {
|
|
19218
|
+
onChanged(null, null);
|
|
19219
|
+
return;
|
|
19220
|
+
}
|
|
19221
|
+
try {
|
|
19222
|
+
const items2 = await fetcher();
|
|
19223
|
+
onChanged(null, items2);
|
|
19224
|
+
} catch (e) {
|
|
19225
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
19226
|
+
onChanged(error, null);
|
|
19227
|
+
}
|
|
19228
|
+
};
|
|
19229
|
+
const handler = () => {
|
|
19230
|
+
if (debounceMs) {
|
|
19231
|
+
const existingTimer = this._listChangedDebounceTimers.get(listType);
|
|
19232
|
+
if (existingTimer) {
|
|
19233
|
+
clearTimeout(existingTimer);
|
|
19234
|
+
}
|
|
19235
|
+
const timer = setTimeout(refresh, debounceMs);
|
|
19236
|
+
this._listChangedDebounceTimers.set(listType, timer);
|
|
19237
|
+
} else {
|
|
19238
|
+
refresh();
|
|
19239
|
+
}
|
|
19240
|
+
};
|
|
19241
|
+
this.setNotificationHandler(notificationSchema, handler);
|
|
19242
|
+
}
|
|
18015
19243
|
async sendRootsListChanged() {
|
|
18016
19244
|
return this.notification({ method: "notifications/roots/list_changed" });
|
|
18017
19245
|
}
|
|
@@ -18185,8 +19413,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18185
19413
|
const OAuthClientInformationSchema = object$1({
|
|
18186
19414
|
client_id: string(),
|
|
18187
19415
|
client_secret: string().optional(),
|
|
18188
|
-
client_id_issued_at: number().optional(),
|
|
18189
|
-
client_secret_expires_at: number().optional()
|
|
19416
|
+
client_id_issued_at: number$1().optional(),
|
|
19417
|
+
client_secret_expires_at: number$1().optional()
|
|
18190
19418
|
}).strip();
|
|
18191
19419
|
const OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
|
|
18192
19420
|
object$1({
|
|
@@ -18286,6 +19514,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18286
19514
|
class InsufficientScopeError extends OAuthError {
|
|
18287
19515
|
}
|
|
18288
19516
|
InsufficientScopeError.errorCode = "insufficient_scope";
|
|
19517
|
+
class InvalidTargetError extends OAuthError {
|
|
19518
|
+
}
|
|
19519
|
+
InvalidTargetError.errorCode = "invalid_target";
|
|
18289
19520
|
const OAUTH_ERRORS = {
|
|
18290
19521
|
[InvalidRequestError.errorCode]: InvalidRequestError,
|
|
18291
19522
|
[InvalidClientError.errorCode]: InvalidClientError,
|
|
@@ -18302,11 +19533,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18302
19533
|
[MethodNotAllowedError.errorCode]: MethodNotAllowedError,
|
|
18303
19534
|
[TooManyRequestsError.errorCode]: TooManyRequestsError,
|
|
18304
19535
|
[InvalidClientMetadataError.errorCode]: InvalidClientMetadataError,
|
|
18305
|
-
[InsufficientScopeError.errorCode]: InsufficientScopeError
|
|
19536
|
+
[InsufficientScopeError.errorCode]: InsufficientScopeError,
|
|
19537
|
+
[InvalidTargetError.errorCode]: InvalidTargetError
|
|
18306
19538
|
};
|
|
18307
19539
|
class UnauthorizedError extends Error {
|
|
18308
19540
|
constructor(message) {
|
|
18309
|
-
super(message
|
|
19541
|
+
super(message ?? "Unauthorized");
|
|
18310
19542
|
}
|
|
18311
19543
|
}
|
|
18312
19544
|
function isClientAuthMethod(method) {
|
|
@@ -18379,22 +19611,20 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18379
19611
|
}
|
|
18380
19612
|
}
|
|
18381
19613
|
async function auth(provider, options) {
|
|
18382
|
-
var _a, _b;
|
|
18383
19614
|
try {
|
|
18384
19615
|
return await authInternal(provider, options);
|
|
18385
19616
|
} catch (error) {
|
|
18386
19617
|
if (error instanceof InvalidClientError || error instanceof UnauthorizedClientError) {
|
|
18387
|
-
await
|
|
19618
|
+
await provider.invalidateCredentials?.("all");
|
|
18388
19619
|
return await authInternal(provider, options);
|
|
18389
19620
|
} else if (error instanceof InvalidGrantError) {
|
|
18390
|
-
await
|
|
19621
|
+
await provider.invalidateCredentials?.("tokens");
|
|
18391
19622
|
return await authInternal(provider, options);
|
|
18392
19623
|
}
|
|
18393
19624
|
throw error;
|
|
18394
19625
|
}
|
|
18395
19626
|
}
|
|
18396
19627
|
async function authInternal(provider, { serverUrl, authorizationCode, scope: scope2, resourceMetadataUrl, fetchFn }) {
|
|
18397
|
-
var _a, _b;
|
|
18398
19628
|
let resourceMetadata;
|
|
18399
19629
|
let authorizationServerUrl;
|
|
18400
19630
|
try {
|
|
@@ -18402,7 +19632,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18402
19632
|
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
|
|
18403
19633
|
authorizationServerUrl = resourceMetadata.authorization_servers[0];
|
|
18404
19634
|
}
|
|
18405
|
-
} catch
|
|
19635
|
+
} catch {
|
|
18406
19636
|
}
|
|
18407
19637
|
if (!authorizationServerUrl) {
|
|
18408
19638
|
authorizationServerUrl = new URL("/", serverUrl);
|
|
@@ -18416,7 +19646,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18416
19646
|
if (authorizationCode !== void 0) {
|
|
18417
19647
|
throw new Error("Existing OAuth client information is required when exchanging an authorization code");
|
|
18418
19648
|
}
|
|
18419
|
-
const supportsUrlBasedClientId =
|
|
19649
|
+
const supportsUrlBasedClientId = metadata2?.client_id_metadata_document_supported === true;
|
|
18420
19650
|
const clientMetadataUrl = provider.clientMetadataUrl;
|
|
18421
19651
|
if (clientMetadataUrl && !isHttpsUrl(clientMetadataUrl)) {
|
|
18422
19652
|
throw new InvalidClientMetadataError(`clientMetadataUrl must be a valid HTTPS URL with a non-root pathname, got: ${clientMetadataUrl}`);
|
|
@@ -18426,7 +19656,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18426
19656
|
clientInformation = {
|
|
18427
19657
|
client_id: clientMetadataUrl
|
|
18428
19658
|
};
|
|
18429
|
-
await
|
|
19659
|
+
await provider.saveClientInformation?.(clientInformation);
|
|
18430
19660
|
} else {
|
|
18431
19661
|
if (!provider.saveClientInformation) {
|
|
18432
19662
|
throw new Error("OAuth client information must be saveable for dynamic registration");
|
|
@@ -18440,23 +19670,19 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18440
19670
|
clientInformation = fullInformation;
|
|
18441
19671
|
}
|
|
18442
19672
|
}
|
|
18443
|
-
|
|
18444
|
-
|
|
18445
|
-
const tokens2 = await
|
|
19673
|
+
const nonInteractiveFlow = !provider.redirectUrl;
|
|
19674
|
+
if (authorizationCode !== void 0 || nonInteractiveFlow) {
|
|
19675
|
+
const tokens2 = await fetchToken(provider, authorizationServerUrl, {
|
|
18446
19676
|
metadata: metadata2,
|
|
18447
|
-
clientInformation,
|
|
18448
|
-
authorizationCode,
|
|
18449
|
-
codeVerifier: codeVerifier2,
|
|
18450
|
-
redirectUri: provider.redirectUrl,
|
|
18451
19677
|
resource,
|
|
18452
|
-
|
|
19678
|
+
authorizationCode,
|
|
18453
19679
|
fetchFn
|
|
18454
19680
|
});
|
|
18455
19681
|
await provider.saveTokens(tokens2);
|
|
18456
19682
|
return "AUTHORIZED";
|
|
18457
19683
|
}
|
|
18458
19684
|
const tokens = await provider.tokens();
|
|
18459
|
-
if (tokens
|
|
19685
|
+
if (tokens?.refresh_token) {
|
|
18460
19686
|
try {
|
|
18461
19687
|
const newTokens = await refreshAuthorization(authorizationServerUrl, {
|
|
18462
19688
|
metadata: metadata2,
|
|
@@ -18481,7 +19707,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18481
19707
|
clientInformation,
|
|
18482
19708
|
state,
|
|
18483
19709
|
redirectUrl: provider.redirectUrl,
|
|
18484
|
-
scope: scope2 ||
|
|
19710
|
+
scope: scope2 || resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope,
|
|
18485
19711
|
resource
|
|
18486
19712
|
});
|
|
18487
19713
|
await provider.saveCodeVerifier(codeVerifier);
|
|
@@ -18494,14 +19720,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18494
19720
|
try {
|
|
18495
19721
|
const url2 = new URL(value);
|
|
18496
19722
|
return url2.protocol === "https:" && url2.pathname !== "/";
|
|
18497
|
-
} catch
|
|
19723
|
+
} catch {
|
|
18498
19724
|
return false;
|
|
18499
19725
|
}
|
|
18500
19726
|
}
|
|
18501
19727
|
async function selectResourceURL(serverUrl, provider, resourceMetadata) {
|
|
18502
19728
|
const defaultResource = resourceUrlFromServerUrl(serverUrl);
|
|
18503
19729
|
if (provider.validateResourceURL) {
|
|
18504
|
-
return await provider.validateResourceURL(defaultResource, resourceMetadata
|
|
19730
|
+
return await provider.validateResourceURL(defaultResource, resourceMetadata?.resource);
|
|
18505
19731
|
}
|
|
18506
19732
|
if (!resourceMetadata) {
|
|
18507
19733
|
return void 0;
|
|
@@ -18525,7 +19751,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18525
19751
|
if (resourceMetadataMatch) {
|
|
18526
19752
|
try {
|
|
18527
19753
|
resourceMetadataUrl = new URL(resourceMetadataMatch);
|
|
18528
|
-
} catch
|
|
19754
|
+
} catch {
|
|
18529
19755
|
}
|
|
18530
19756
|
}
|
|
18531
19757
|
const scope2 = extractFieldFromWwwAuth(res, "scope") || void 0;
|
|
@@ -18564,19 +19790,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18564
19790
|
}
|
|
18565
19791
|
try {
|
|
18566
19792
|
return new URL(match[1]);
|
|
18567
|
-
} catch
|
|
19793
|
+
} catch {
|
|
18568
19794
|
return void 0;
|
|
18569
19795
|
}
|
|
18570
19796
|
}
|
|
18571
19797
|
async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn = fetch) {
|
|
18572
19798
|
const response = await discoverMetadataWithFallback(serverUrl, "oauth-protected-resource", fetchFn, {
|
|
18573
|
-
protocolVersion: opts
|
|
18574
|
-
metadataUrl: opts
|
|
19799
|
+
protocolVersion: opts?.protocolVersion,
|
|
19800
|
+
metadataUrl: opts?.resourceMetadataUrl
|
|
18575
19801
|
});
|
|
18576
19802
|
if (!response || response.status === 404) {
|
|
19803
|
+
await response?.body?.cancel();
|
|
18577
19804
|
throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);
|
|
18578
19805
|
}
|
|
18579
19806
|
if (!response.ok) {
|
|
19807
|
+
await response.body?.cancel();
|
|
18580
19808
|
throw new Error(`HTTP ${response.status} trying to load well-known OAuth protected resource metadata.`);
|
|
18581
19809
|
}
|
|
18582
19810
|
return OAuthProtectedResourceMetadataSchema.parse(await response.json());
|
|
@@ -18611,19 +19839,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18611
19839
|
return !response || response.status >= 400 && response.status < 500 && pathname !== "/";
|
|
18612
19840
|
}
|
|
18613
19841
|
async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
|
|
18614
|
-
var _a, _b;
|
|
18615
19842
|
const issuer = new URL(serverUrl);
|
|
18616
|
-
const protocolVersion =
|
|
19843
|
+
const protocolVersion = opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION;
|
|
18617
19844
|
let url2;
|
|
18618
|
-
if (opts
|
|
19845
|
+
if (opts?.metadataUrl) {
|
|
18619
19846
|
url2 = new URL(opts.metadataUrl);
|
|
18620
19847
|
} else {
|
|
18621
19848
|
const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname);
|
|
18622
|
-
url2 = new URL(wellKnownPath,
|
|
19849
|
+
url2 = new URL(wellKnownPath, opts?.metadataServerUrl ?? issuer);
|
|
18623
19850
|
url2.search = issuer.search;
|
|
18624
19851
|
}
|
|
18625
19852
|
let response = await tryMetadataDiscovery(url2, protocolVersion, fetchFn);
|
|
18626
|
-
if (!
|
|
19853
|
+
if (!opts?.metadataUrl && shouldAttemptFallback(response, issuer.pathname)) {
|
|
18627
19854
|
const rootUrl = new URL(`/.well-known/${wellKnownType}`, issuer);
|
|
18628
19855
|
response = await tryMetadataDiscovery(rootUrl, protocolVersion, fetchFn);
|
|
18629
19856
|
}
|
|
@@ -18639,15 +19866,17 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18639
19866
|
if (typeof authorizationServerUrl === "string") {
|
|
18640
19867
|
authorizationServerUrl = new URL(authorizationServerUrl);
|
|
18641
19868
|
}
|
|
18642
|
-
protocolVersion
|
|
19869
|
+
protocolVersion ?? (protocolVersion = LATEST_PROTOCOL_VERSION);
|
|
18643
19870
|
const response = await discoverMetadataWithFallback(authorizationServerUrl, "oauth-authorization-server", fetchFn, {
|
|
18644
19871
|
protocolVersion,
|
|
18645
19872
|
metadataServerUrl: authorizationServerUrl
|
|
18646
19873
|
});
|
|
18647
19874
|
if (!response || response.status === 404) {
|
|
19875
|
+
await response?.body?.cancel();
|
|
18648
19876
|
return void 0;
|
|
18649
19877
|
}
|
|
18650
19878
|
if (!response.ok) {
|
|
19879
|
+
await response.body?.cancel();
|
|
18651
19880
|
throw new Error(`HTTP ${response.status} trying to load well-known OAuth metadata`);
|
|
18652
19881
|
}
|
|
18653
19882
|
return OAuthMetadataSchema.parse(await response.json());
|
|
@@ -18697,6 +19926,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18697
19926
|
continue;
|
|
18698
19927
|
}
|
|
18699
19928
|
if (!response.ok) {
|
|
19929
|
+
await response.body?.cancel();
|
|
18700
19930
|
if (response.status >= 400 && response.status < 500) {
|
|
18701
19931
|
continue;
|
|
18702
19932
|
}
|
|
@@ -18737,7 +19967,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18737
19967
|
if (scope2) {
|
|
18738
19968
|
authorizationUrl.searchParams.set("scope", scope2);
|
|
18739
19969
|
}
|
|
18740
|
-
if (scope2
|
|
19970
|
+
if (scope2?.includes("offline_access")) {
|
|
18741
19971
|
authorizationUrl.searchParams.append("prompt", "consent");
|
|
18742
19972
|
}
|
|
18743
19973
|
if (resource) {
|
|
@@ -18745,81 +19975,91 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18745
19975
|
}
|
|
18746
19976
|
return { authorizationUrl, codeVerifier };
|
|
18747
19977
|
}
|
|
18748
|
-
|
|
18749
|
-
|
|
18750
|
-
|
|
18751
|
-
const tokenUrl = (metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.token_endpoint) ? new URL(metadata2.token_endpoint) : new URL("/token", authorizationServerUrl);
|
|
18752
|
-
if ((metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.grant_types_supported) && !metadata2.grant_types_supported.includes(grantType)) {
|
|
18753
|
-
throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
|
|
18754
|
-
}
|
|
18755
|
-
const headers = new Headers({
|
|
18756
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
18757
|
-
Accept: "application/json"
|
|
18758
|
-
});
|
|
18759
|
-
const params = new URLSearchParams({
|
|
18760
|
-
grant_type: grantType,
|
|
19978
|
+
function prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, redirectUri) {
|
|
19979
|
+
return new URLSearchParams({
|
|
19980
|
+
grant_type: "authorization_code",
|
|
18761
19981
|
code: authorizationCode,
|
|
18762
19982
|
code_verifier: codeVerifier,
|
|
18763
19983
|
redirect_uri: String(redirectUri)
|
|
18764
19984
|
});
|
|
19985
|
+
}
|
|
19986
|
+
async function executeTokenRequest(authorizationServerUrl, { metadata: metadata2, tokenRequestParams, clientInformation, addClientAuthentication, resource, fetchFn }) {
|
|
19987
|
+
const tokenUrl = metadata2?.token_endpoint ? new URL(metadata2.token_endpoint) : new URL("/token", authorizationServerUrl);
|
|
19988
|
+
const headers = new Headers({
|
|
19989
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
19990
|
+
Accept: "application/json"
|
|
19991
|
+
});
|
|
19992
|
+
if (resource) {
|
|
19993
|
+
tokenRequestParams.set("resource", resource.href);
|
|
19994
|
+
}
|
|
18765
19995
|
if (addClientAuthentication) {
|
|
18766
|
-
addClientAuthentication(headers,
|
|
18767
|
-
} else {
|
|
18768
|
-
const supportedMethods =
|
|
19996
|
+
await addClientAuthentication(headers, tokenRequestParams, tokenUrl, metadata2);
|
|
19997
|
+
} else if (clientInformation) {
|
|
19998
|
+
const supportedMethods = metadata2?.token_endpoint_auth_methods_supported ?? [];
|
|
18769
19999
|
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
18770
|
-
applyClientAuthentication(authMethod, clientInformation, headers,
|
|
20000
|
+
applyClientAuthentication(authMethod, clientInformation, headers, tokenRequestParams);
|
|
18771
20001
|
}
|
|
18772
|
-
|
|
18773
|
-
params.set("resource", resource.href);
|
|
18774
|
-
}
|
|
18775
|
-
const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(tokenUrl, {
|
|
20002
|
+
const response = await (fetchFn ?? fetch)(tokenUrl, {
|
|
18776
20003
|
method: "POST",
|
|
18777
20004
|
headers,
|
|
18778
|
-
body:
|
|
20005
|
+
body: tokenRequestParams
|
|
18779
20006
|
});
|
|
18780
20007
|
if (!response.ok) {
|
|
18781
20008
|
throw await parseErrorResponse(response);
|
|
18782
20009
|
}
|
|
18783
20010
|
return OAuthTokensSchema.parse(await response.json());
|
|
18784
20011
|
}
|
|
18785
|
-
async function
|
|
18786
|
-
|
|
18787
|
-
|
|
18788
|
-
|
|
18789
|
-
|
|
18790
|
-
|
|
18791
|
-
|
|
18792
|
-
|
|
18793
|
-
|
|
18794
|
-
} else {
|
|
18795
|
-
tokenUrl = new URL("/token", authorizationServerUrl);
|
|
18796
|
-
}
|
|
18797
|
-
const headers = new Headers({
|
|
18798
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
20012
|
+
async function exchangeAuthorization(authorizationServerUrl, { metadata: metadata2, clientInformation, authorizationCode, codeVerifier, redirectUri, resource, addClientAuthentication, fetchFn }) {
|
|
20013
|
+
const tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, redirectUri);
|
|
20014
|
+
return executeTokenRequest(authorizationServerUrl, {
|
|
20015
|
+
metadata: metadata2,
|
|
20016
|
+
tokenRequestParams,
|
|
20017
|
+
clientInformation,
|
|
20018
|
+
addClientAuthentication,
|
|
20019
|
+
resource,
|
|
20020
|
+
fetchFn
|
|
18799
20021
|
});
|
|
18800
|
-
|
|
18801
|
-
|
|
20022
|
+
}
|
|
20023
|
+
async function refreshAuthorization(authorizationServerUrl, { metadata: metadata2, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) {
|
|
20024
|
+
const tokenRequestParams = new URLSearchParams({
|
|
20025
|
+
grant_type: "refresh_token",
|
|
18802
20026
|
refresh_token: refreshToken
|
|
18803
20027
|
});
|
|
18804
|
-
|
|
18805
|
-
|
|
18806
|
-
|
|
18807
|
-
|
|
18808
|
-
|
|
18809
|
-
|
|
20028
|
+
const tokens = await executeTokenRequest(authorizationServerUrl, {
|
|
20029
|
+
metadata: metadata2,
|
|
20030
|
+
tokenRequestParams,
|
|
20031
|
+
clientInformation,
|
|
20032
|
+
addClientAuthentication,
|
|
20033
|
+
resource,
|
|
20034
|
+
fetchFn
|
|
20035
|
+
});
|
|
20036
|
+
return { refresh_token: refreshToken, ...tokens };
|
|
20037
|
+
}
|
|
20038
|
+
async function fetchToken(provider, authorizationServerUrl, { metadata: metadata2, resource, authorizationCode, fetchFn } = {}) {
|
|
20039
|
+
const scope2 = provider.clientMetadata.scope;
|
|
20040
|
+
let tokenRequestParams;
|
|
20041
|
+
if (provider.prepareTokenRequest) {
|
|
20042
|
+
tokenRequestParams = await provider.prepareTokenRequest(scope2);
|
|
18810
20043
|
}
|
|
18811
|
-
if (
|
|
18812
|
-
|
|
20044
|
+
if (!tokenRequestParams) {
|
|
20045
|
+
if (!authorizationCode) {
|
|
20046
|
+
throw new Error("Either provider.prepareTokenRequest() or authorizationCode is required");
|
|
20047
|
+
}
|
|
20048
|
+
if (!provider.redirectUrl) {
|
|
20049
|
+
throw new Error("redirectUrl is required for authorization_code flow");
|
|
20050
|
+
}
|
|
20051
|
+
const codeVerifier = await provider.codeVerifier();
|
|
20052
|
+
tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, provider.redirectUrl);
|
|
18813
20053
|
}
|
|
18814
|
-
const
|
|
18815
|
-
|
|
18816
|
-
|
|
18817
|
-
|
|
20054
|
+
const clientInformation = await provider.clientInformation();
|
|
20055
|
+
return executeTokenRequest(authorizationServerUrl, {
|
|
20056
|
+
metadata: metadata2,
|
|
20057
|
+
tokenRequestParams,
|
|
20058
|
+
clientInformation: clientInformation ?? void 0,
|
|
20059
|
+
addClientAuthentication: provider.addClientAuthentication,
|
|
20060
|
+
resource,
|
|
20061
|
+
fetchFn
|
|
18818
20062
|
});
|
|
18819
|
-
if (!response.ok) {
|
|
18820
|
-
throw await parseErrorResponse(response);
|
|
18821
|
-
}
|
|
18822
|
-
return OAuthTokensSchema.parse({ refresh_token: refreshToken, ...await response.json() });
|
|
18823
20063
|
}
|
|
18824
20064
|
async function registerClient(authorizationServerUrl, { metadata: metadata2, clientMetadata, fetchFn }) {
|
|
18825
20065
|
let registrationUrl;
|
|
@@ -18831,7 +20071,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
18831
20071
|
} else {
|
|
18832
20072
|
registrationUrl = new URL("/register", authorizationServerUrl);
|
|
18833
20073
|
}
|
|
18834
|
-
const response = await (fetchFn
|
|
20074
|
+
const response = await (fetchFn ?? fetch)(registrationUrl, {
|
|
18835
20075
|
method: "POST",
|
|
18836
20076
|
headers: {
|
|
18837
20077
|
"Content-Type": "application/json"
|
|
@@ -19231,7 +20471,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19231
20471
|
...baseInit,
|
|
19232
20472
|
...init,
|
|
19233
20473
|
// Headers need special handling - merge instead of replace
|
|
19234
|
-
headers:
|
|
20474
|
+
headers: init?.headers ? { ...normalizeHeaders(baseInit.headers), ...normalizeHeaders(init.headers) } : baseInit.headers
|
|
19235
20475
|
};
|
|
19236
20476
|
return baseFetch(url2, mergedInit);
|
|
19237
20477
|
};
|
|
@@ -19248,14 +20488,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19248
20488
|
this._url = url2;
|
|
19249
20489
|
this._resourceMetadataUrl = void 0;
|
|
19250
20490
|
this._scope = void 0;
|
|
19251
|
-
this._eventSourceInit = opts
|
|
19252
|
-
this._requestInit = opts
|
|
19253
|
-
this._authProvider = opts
|
|
19254
|
-
this._fetch = opts
|
|
19255
|
-
this._fetchWithInit = createFetchWithInit(opts
|
|
20491
|
+
this._eventSourceInit = opts?.eventSourceInit;
|
|
20492
|
+
this._requestInit = opts?.requestInit;
|
|
20493
|
+
this._authProvider = opts?.authProvider;
|
|
20494
|
+
this._fetch = opts?.fetch;
|
|
20495
|
+
this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
|
|
19256
20496
|
}
|
|
19257
20497
|
async _authThenStart() {
|
|
19258
|
-
var _a;
|
|
19259
20498
|
if (!this._authProvider) {
|
|
19260
20499
|
throw new UnauthorizedError("No auth provider");
|
|
19261
20500
|
}
|
|
@@ -19268,7 +20507,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19268
20507
|
fetchFn: this._fetchWithInit
|
|
19269
20508
|
});
|
|
19270
20509
|
} catch (error) {
|
|
19271
|
-
|
|
20510
|
+
this.onerror?.(error);
|
|
19272
20511
|
throw error;
|
|
19273
20512
|
}
|
|
19274
20513
|
if (result !== "AUTHORIZED") {
|
|
@@ -19277,7 +20516,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19277
20516
|
return await this._startOrAuth();
|
|
19278
20517
|
}
|
|
19279
20518
|
async _commonHeaders() {
|
|
19280
|
-
var _a;
|
|
19281
20519
|
const headers = {};
|
|
19282
20520
|
if (this._authProvider) {
|
|
19283
20521
|
const tokens = await this._authProvider.tokens();
|
|
@@ -19288,11 +20526,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19288
20526
|
if (this._protocolVersion) {
|
|
19289
20527
|
headers["mcp-protocol-version"] = this._protocolVersion;
|
|
19290
20528
|
}
|
|
19291
|
-
|
|
20529
|
+
const extraHeaders = normalizeHeaders(this._requestInit?.headers);
|
|
20530
|
+
return new Headers({
|
|
20531
|
+
...headers,
|
|
20532
|
+
...extraHeaders
|
|
20533
|
+
});
|
|
19292
20534
|
}
|
|
19293
20535
|
_startOrAuth() {
|
|
19294
|
-
|
|
19295
|
-
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;
|
|
20536
|
+
const fetchImpl = this?._eventSourceInit?.fetch ?? this._fetch ?? fetch;
|
|
19296
20537
|
return new Promise((resolve2, reject) => {
|
|
19297
20538
|
this._eventSource = new EventSource(this._url.href, {
|
|
19298
20539
|
...this._eventSourceInit,
|
|
@@ -19313,19 +20554,17 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19313
20554
|
});
|
|
19314
20555
|
this._abortController = new AbortController();
|
|
19315
20556
|
this._eventSource.onerror = (event) => {
|
|
19316
|
-
var _a2;
|
|
19317
20557
|
if (event.code === 401 && this._authProvider) {
|
|
19318
20558
|
this._authThenStart().then(resolve2, reject);
|
|
19319
20559
|
return;
|
|
19320
20560
|
}
|
|
19321
20561
|
const error = new SseError(event.code, event.message, event);
|
|
19322
20562
|
reject(error);
|
|
19323
|
-
|
|
20563
|
+
this.onerror?.(error);
|
|
19324
20564
|
};
|
|
19325
20565
|
this._eventSource.onopen = () => {
|
|
19326
20566
|
};
|
|
19327
20567
|
this._eventSource.addEventListener("endpoint", (event) => {
|
|
19328
|
-
var _a2;
|
|
19329
20568
|
const messageEvent = event;
|
|
19330
20569
|
try {
|
|
19331
20570
|
this._endpoint = new URL(messageEvent.data, this._url);
|
|
@@ -19334,23 +20573,22 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19334
20573
|
}
|
|
19335
20574
|
} catch (error) {
|
|
19336
20575
|
reject(error);
|
|
19337
|
-
|
|
20576
|
+
this.onerror?.(error);
|
|
19338
20577
|
void this.close();
|
|
19339
20578
|
return;
|
|
19340
20579
|
}
|
|
19341
20580
|
resolve2();
|
|
19342
20581
|
});
|
|
19343
20582
|
this._eventSource.onmessage = (event) => {
|
|
19344
|
-
var _a2, _b2;
|
|
19345
20583
|
const messageEvent = event;
|
|
19346
20584
|
let message;
|
|
19347
20585
|
try {
|
|
19348
20586
|
message = JSONRPCMessageSchema.parse(JSON.parse(messageEvent.data));
|
|
19349
20587
|
} catch (error) {
|
|
19350
|
-
|
|
20588
|
+
this.onerror?.(error);
|
|
19351
20589
|
return;
|
|
19352
20590
|
}
|
|
19353
|
-
|
|
20591
|
+
this.onmessage?.(message);
|
|
19354
20592
|
};
|
|
19355
20593
|
});
|
|
19356
20594
|
}
|
|
@@ -19379,13 +20617,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19379
20617
|
}
|
|
19380
20618
|
}
|
|
19381
20619
|
async close() {
|
|
19382
|
-
|
|
19383
|
-
|
|
19384
|
-
|
|
19385
|
-
(_c = this.onclose) === null || _c === void 0 ? void 0 : _c.call(this);
|
|
20620
|
+
this._abortController?.abort();
|
|
20621
|
+
this._eventSource?.close();
|
|
20622
|
+
this.onclose?.();
|
|
19386
20623
|
}
|
|
19387
20624
|
async send(message) {
|
|
19388
|
-
var _a, _b, _c;
|
|
19389
20625
|
if (!this._endpoint) {
|
|
19390
20626
|
throw new Error("Not connected");
|
|
19391
20627
|
}
|
|
@@ -19397,10 +20633,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19397
20633
|
method: "POST",
|
|
19398
20634
|
headers,
|
|
19399
20635
|
body: JSON.stringify(message),
|
|
19400
|
-
signal:
|
|
20636
|
+
signal: this._abortController?.signal
|
|
19401
20637
|
};
|
|
19402
|
-
const response = await (
|
|
20638
|
+
const response = await (this._fetch ?? fetch)(this._endpoint, init);
|
|
19403
20639
|
if (!response.ok) {
|
|
20640
|
+
const text = await response.text().catch(() => null);
|
|
19404
20641
|
if (response.status === 401 && this._authProvider) {
|
|
19405
20642
|
const { resourceMetadataUrl, scope: scope2 } = extractWWWAuthenticateParams(response);
|
|
19406
20643
|
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
@@ -19416,11 +20653,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19416
20653
|
}
|
|
19417
20654
|
return this.send(message);
|
|
19418
20655
|
}
|
|
19419
|
-
const text = await response.text().catch(() => null);
|
|
19420
20656
|
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
|
|
19421
20657
|
}
|
|
20658
|
+
await response.body?.cancel();
|
|
19422
20659
|
} catch (error) {
|
|
19423
|
-
|
|
20660
|
+
this.onerror?.(error);
|
|
19424
20661
|
throw error;
|
|
19425
20662
|
}
|
|
19426
20663
|
}
|
|
@@ -19464,20 +20701,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19464
20701
|
}
|
|
19465
20702
|
class StreamableHTTPClientTransport {
|
|
19466
20703
|
constructor(url2, opts) {
|
|
19467
|
-
var _a;
|
|
19468
20704
|
this._hasCompletedAuthFlow = false;
|
|
19469
20705
|
this._url = url2;
|
|
19470
20706
|
this._resourceMetadataUrl = void 0;
|
|
19471
20707
|
this._scope = void 0;
|
|
19472
|
-
this._requestInit = opts
|
|
19473
|
-
this._authProvider = opts
|
|
19474
|
-
this._fetch = opts
|
|
19475
|
-
this._fetchWithInit = createFetchWithInit(opts
|
|
19476
|
-
this._sessionId = opts
|
|
19477
|
-
this._reconnectionOptions =
|
|
20708
|
+
this._requestInit = opts?.requestInit;
|
|
20709
|
+
this._authProvider = opts?.authProvider;
|
|
20710
|
+
this._fetch = opts?.fetch;
|
|
20711
|
+
this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
|
|
20712
|
+
this._sessionId = opts?.sessionId;
|
|
20713
|
+
this._reconnectionOptions = opts?.reconnectionOptions ?? DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS;
|
|
19478
20714
|
}
|
|
19479
20715
|
async _authThenStart() {
|
|
19480
|
-
var _a;
|
|
19481
20716
|
if (!this._authProvider) {
|
|
19482
20717
|
throw new UnauthorizedError("No auth provider");
|
|
19483
20718
|
}
|
|
@@ -19490,7 +20725,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19490
20725
|
fetchFn: this._fetchWithInit
|
|
19491
20726
|
});
|
|
19492
20727
|
} catch (error) {
|
|
19493
|
-
|
|
20728
|
+
this.onerror?.(error);
|
|
19494
20729
|
throw error;
|
|
19495
20730
|
}
|
|
19496
20731
|
if (result !== "AUTHORIZED") {
|
|
@@ -19499,7 +20734,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19499
20734
|
return await this._startOrAuthSse({ resumptionToken: void 0 });
|
|
19500
20735
|
}
|
|
19501
20736
|
async _commonHeaders() {
|
|
19502
|
-
var _a;
|
|
19503
20737
|
const headers = {};
|
|
19504
20738
|
if (this._authProvider) {
|
|
19505
20739
|
const tokens = await this._authProvider.tokens();
|
|
@@ -19513,14 +20747,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19513
20747
|
if (this._protocolVersion) {
|
|
19514
20748
|
headers["mcp-protocol-version"] = this._protocolVersion;
|
|
19515
20749
|
}
|
|
19516
|
-
const extraHeaders = normalizeHeaders(
|
|
20750
|
+
const extraHeaders = normalizeHeaders(this._requestInit?.headers);
|
|
19517
20751
|
return new Headers({
|
|
19518
20752
|
...headers,
|
|
19519
20753
|
...extraHeaders
|
|
19520
20754
|
});
|
|
19521
20755
|
}
|
|
19522
20756
|
async _startOrAuthSse(options) {
|
|
19523
|
-
var _a, _b, _c;
|
|
19524
20757
|
const { resumptionToken } = options;
|
|
19525
20758
|
try {
|
|
19526
20759
|
const headers = await this._commonHeaders();
|
|
@@ -19528,12 +20761,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19528
20761
|
if (resumptionToken) {
|
|
19529
20762
|
headers.set("last-event-id", resumptionToken);
|
|
19530
20763
|
}
|
|
19531
|
-
const response = await (
|
|
20764
|
+
const response = await (this._fetch ?? fetch)(this._url, {
|
|
19532
20765
|
method: "GET",
|
|
19533
20766
|
headers,
|
|
19534
|
-
signal:
|
|
20767
|
+
signal: this._abortController?.signal
|
|
19535
20768
|
});
|
|
19536
20769
|
if (!response.ok) {
|
|
20770
|
+
await response.body?.cancel();
|
|
19537
20771
|
if (response.status === 401 && this._authProvider) {
|
|
19538
20772
|
return await this._authThenStart();
|
|
19539
20773
|
}
|
|
@@ -19544,7 +20778,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19544
20778
|
}
|
|
19545
20779
|
this._handleSseStream(response.body, options, true);
|
|
19546
20780
|
} catch (error) {
|
|
19547
|
-
|
|
20781
|
+
this.onerror?.(error);
|
|
19548
20782
|
throw error;
|
|
19549
20783
|
}
|
|
19550
20784
|
}
|
|
@@ -19570,17 +20804,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19570
20804
|
* @param attemptCount Current reconnection attempt count for this specific stream
|
|
19571
20805
|
*/
|
|
19572
20806
|
_scheduleReconnection(options, attemptCount = 0) {
|
|
19573
|
-
var _a;
|
|
19574
20807
|
const maxRetries = this._reconnectionOptions.maxRetries;
|
|
19575
|
-
if (
|
|
19576
|
-
|
|
20808
|
+
if (attemptCount >= maxRetries) {
|
|
20809
|
+
this.onerror?.(new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`));
|
|
19577
20810
|
return;
|
|
19578
20811
|
}
|
|
19579
20812
|
const delay = this._getNextReconnectionDelay(attemptCount);
|
|
19580
|
-
setTimeout(() => {
|
|
20813
|
+
this._reconnectionTimeout = setTimeout(() => {
|
|
19581
20814
|
this._startOrAuthSse(options).catch((error) => {
|
|
19582
|
-
|
|
19583
|
-
(_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)}`));
|
|
20815
|
+
this.onerror?.(new Error(`Failed to reconnect SSE stream: ${error instanceof Error ? error.message : String(error)}`));
|
|
19584
20816
|
this._scheduleReconnection(options, attemptCount + 1);
|
|
19585
20817
|
});
|
|
19586
20818
|
}, delay);
|
|
@@ -19592,8 +20824,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19592
20824
|
const { onresumptiontoken, replayMessageId } = options;
|
|
19593
20825
|
let lastEventId;
|
|
19594
20826
|
let hasPrimingEvent = false;
|
|
20827
|
+
let receivedResponse = false;
|
|
19595
20828
|
const processStream = async () => {
|
|
19596
|
-
var _a, _b, _c, _d;
|
|
19597
20829
|
try {
|
|
19598
20830
|
const reader = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream({
|
|
19599
20831
|
onRetry: (retryMs) => {
|
|
@@ -19608,22 +20840,29 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19608
20840
|
if (event.id) {
|
|
19609
20841
|
lastEventId = event.id;
|
|
19610
20842
|
hasPrimingEvent = true;
|
|
19611
|
-
onresumptiontoken
|
|
20843
|
+
onresumptiontoken?.(event.id);
|
|
20844
|
+
}
|
|
20845
|
+
if (!event.data) {
|
|
20846
|
+
continue;
|
|
19612
20847
|
}
|
|
19613
20848
|
if (!event.event || event.event === "message") {
|
|
19614
20849
|
try {
|
|
19615
20850
|
const message = JSONRPCMessageSchema.parse(JSON.parse(event.data));
|
|
19616
|
-
if (
|
|
19617
|
-
|
|
20851
|
+
if (isJSONRPCResultResponse(message)) {
|
|
20852
|
+
receivedResponse = true;
|
|
20853
|
+
if (replayMessageId !== void 0) {
|
|
20854
|
+
message.id = replayMessageId;
|
|
20855
|
+
}
|
|
19618
20856
|
}
|
|
19619
|
-
|
|
20857
|
+
this.onmessage?.(message);
|
|
19620
20858
|
} catch (error) {
|
|
19621
|
-
|
|
20859
|
+
this.onerror?.(error);
|
|
19622
20860
|
}
|
|
19623
20861
|
}
|
|
19624
20862
|
}
|
|
19625
20863
|
const canResume = isReconnectable || hasPrimingEvent;
|
|
19626
|
-
|
|
20864
|
+
const needsReconnect = canResume && !receivedResponse;
|
|
20865
|
+
if (needsReconnect && this._abortController && !this._abortController.signal.aborted) {
|
|
19627
20866
|
this._scheduleReconnection({
|
|
19628
20867
|
resumptionToken: lastEventId,
|
|
19629
20868
|
onresumptiontoken,
|
|
@@ -19631,9 +20870,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19631
20870
|
}, 0);
|
|
19632
20871
|
}
|
|
19633
20872
|
} catch (error) {
|
|
19634
|
-
|
|
20873
|
+
this.onerror?.(new Error(`SSE stream disconnected: ${error}`));
|
|
19635
20874
|
const canResume = isReconnectable || hasPrimingEvent;
|
|
19636
|
-
|
|
20875
|
+
const needsReconnect = canResume && !receivedResponse;
|
|
20876
|
+
if (needsReconnect && this._abortController && !this._abortController.signal.aborted) {
|
|
19637
20877
|
try {
|
|
19638
20878
|
this._scheduleReconnection({
|
|
19639
20879
|
resumptionToken: lastEventId,
|
|
@@ -19641,7 +20881,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19641
20881
|
replayMessageId
|
|
19642
20882
|
}, 0);
|
|
19643
20883
|
} catch (error2) {
|
|
19644
|
-
|
|
20884
|
+
this.onerror?.(new Error(`Failed to reconnect: ${error2 instanceof Error ? error2.message : String(error2)}`));
|
|
19645
20885
|
}
|
|
19646
20886
|
}
|
|
19647
20887
|
}
|
|
@@ -19673,19 +20913,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19673
20913
|
}
|
|
19674
20914
|
}
|
|
19675
20915
|
async close() {
|
|
19676
|
-
|
|
19677
|
-
|
|
19678
|
-
|
|
20916
|
+
if (this._reconnectionTimeout) {
|
|
20917
|
+
clearTimeout(this._reconnectionTimeout);
|
|
20918
|
+
this._reconnectionTimeout = void 0;
|
|
20919
|
+
}
|
|
20920
|
+
this._abortController?.abort();
|
|
20921
|
+
this.onclose?.();
|
|
19679
20922
|
}
|
|
19680
20923
|
async send(message, options) {
|
|
19681
|
-
var _a, _b, _c, _d;
|
|
19682
20924
|
try {
|
|
19683
20925
|
const { resumptionToken, onresumptiontoken } = options || {};
|
|
19684
20926
|
if (resumptionToken) {
|
|
19685
|
-
this._startOrAuthSse({ resumptionToken, replayMessageId: isJSONRPCRequest(message) ? message.id : void 0 }).catch((err) =>
|
|
19686
|
-
var _a2;
|
|
19687
|
-
return (_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, err);
|
|
19688
|
-
});
|
|
20927
|
+
this._startOrAuthSse({ resumptionToken, replayMessageId: isJSONRPCRequest(message) ? message.id : void 0 }).catch((err) => this.onerror?.(err));
|
|
19689
20928
|
return;
|
|
19690
20929
|
}
|
|
19691
20930
|
const headers = await this._commonHeaders();
|
|
@@ -19696,14 +20935,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19696
20935
|
method: "POST",
|
|
19697
20936
|
headers,
|
|
19698
20937
|
body: JSON.stringify(message),
|
|
19699
|
-
signal:
|
|
20938
|
+
signal: this._abortController?.signal
|
|
19700
20939
|
};
|
|
19701
|
-
const response = await (
|
|
20940
|
+
const response = await (this._fetch ?? fetch)(this._url, init);
|
|
19702
20941
|
const sessionId = response.headers.get("mcp-session-id");
|
|
19703
20942
|
if (sessionId) {
|
|
19704
20943
|
this._sessionId = sessionId;
|
|
19705
20944
|
}
|
|
19706
20945
|
if (!response.ok) {
|
|
20946
|
+
const text = await response.text().catch(() => null);
|
|
19707
20947
|
if (response.status === 401 && this._authProvider) {
|
|
19708
20948
|
if (this._hasCompletedAuthFlow) {
|
|
19709
20949
|
throw new StreamableHTTPError(401, "Server returned 401 after successful authentication");
|
|
@@ -19736,7 +20976,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19736
20976
|
if (resourceMetadataUrl) {
|
|
19737
20977
|
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
19738
20978
|
}
|
|
19739
|
-
this._lastUpscopingHeader = wwwAuthHeader
|
|
20979
|
+
this._lastUpscopingHeader = wwwAuthHeader ?? void 0;
|
|
19740
20980
|
const result = await auth(this._authProvider, {
|
|
19741
20981
|
serverUrl: this._url,
|
|
19742
20982
|
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
@@ -19749,17 +20989,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19749
20989
|
return this.send(message);
|
|
19750
20990
|
}
|
|
19751
20991
|
}
|
|
19752
|
-
|
|
19753
|
-
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
|
|
20992
|
+
throw new StreamableHTTPError(response.status, `Error POSTing to endpoint: ${text}`);
|
|
19754
20993
|
}
|
|
19755
20994
|
this._hasCompletedAuthFlow = false;
|
|
19756
20995
|
this._lastUpscopingHeader = void 0;
|
|
19757
20996
|
if (response.status === 202) {
|
|
20997
|
+
await response.body?.cancel();
|
|
19758
20998
|
if (isInitializedNotification(message)) {
|
|
19759
|
-
this._startOrAuthSse({ resumptionToken: void 0 }).catch((err) =>
|
|
19760
|
-
var _a2;
|
|
19761
|
-
return (_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, err);
|
|
19762
|
-
});
|
|
20999
|
+
this._startOrAuthSse({ resumptionToken: void 0 }).catch((err) => this.onerror?.(err));
|
|
19763
21000
|
}
|
|
19764
21001
|
return;
|
|
19765
21002
|
}
|
|
@@ -19767,20 +21004,23 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19767
21004
|
const hasRequests = messages.filter((msg) => "method" in msg && "id" in msg && msg.id !== void 0).length > 0;
|
|
19768
21005
|
const contentType = response.headers.get("content-type");
|
|
19769
21006
|
if (hasRequests) {
|
|
19770
|
-
if (contentType
|
|
21007
|
+
if (contentType?.includes("text/event-stream")) {
|
|
19771
21008
|
this._handleSseStream(response.body, { onresumptiontoken }, false);
|
|
19772
|
-
} else if (contentType
|
|
21009
|
+
} else if (contentType?.includes("application/json")) {
|
|
19773
21010
|
const data = await response.json();
|
|
19774
21011
|
const responseMessages = Array.isArray(data) ? data.map((msg) => JSONRPCMessageSchema.parse(msg)) : [JSONRPCMessageSchema.parse(data)];
|
|
19775
21012
|
for (const msg of responseMessages) {
|
|
19776
|
-
|
|
21013
|
+
this.onmessage?.(msg);
|
|
19777
21014
|
}
|
|
19778
21015
|
} else {
|
|
21016
|
+
await response.body?.cancel();
|
|
19779
21017
|
throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`);
|
|
19780
21018
|
}
|
|
21019
|
+
} else {
|
|
21020
|
+
await response.body?.cancel();
|
|
19781
21021
|
}
|
|
19782
21022
|
} catch (error) {
|
|
19783
|
-
|
|
21023
|
+
this.onerror?.(error);
|
|
19784
21024
|
throw error;
|
|
19785
21025
|
}
|
|
19786
21026
|
}
|
|
@@ -19799,7 +21039,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19799
21039
|
* the server does not allow clients to terminate sessions.
|
|
19800
21040
|
*/
|
|
19801
21041
|
async terminateSession() {
|
|
19802
|
-
var _a, _b, _c;
|
|
19803
21042
|
if (!this._sessionId) {
|
|
19804
21043
|
return;
|
|
19805
21044
|
}
|
|
@@ -19809,15 +21048,16 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19809
21048
|
...this._requestInit,
|
|
19810
21049
|
method: "DELETE",
|
|
19811
21050
|
headers,
|
|
19812
|
-
signal:
|
|
21051
|
+
signal: this._abortController?.signal
|
|
19813
21052
|
};
|
|
19814
|
-
const response = await (
|
|
21053
|
+
const response = await (this._fetch ?? fetch)(this._url, init);
|
|
21054
|
+
await response.body?.cancel();
|
|
19815
21055
|
if (!response.ok && response.status !== 405) {
|
|
19816
21056
|
throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`);
|
|
19817
21057
|
}
|
|
19818
21058
|
this._sessionId = void 0;
|
|
19819
21059
|
} catch (error) {
|
|
19820
|
-
|
|
21060
|
+
this.onerror?.(error);
|
|
19821
21061
|
throw error;
|
|
19822
21062
|
}
|
|
19823
21063
|
}
|
|
@@ -19837,16 +21077,85 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19837
21077
|
async resumeStream(lastEventId, options) {
|
|
19838
21078
|
await this._startOrAuthSse({
|
|
19839
21079
|
resumptionToken: lastEventId,
|
|
19840
|
-
onresumptiontoken: options
|
|
21080
|
+
onresumptiontoken: options?.onresumptiontoken
|
|
19841
21081
|
});
|
|
19842
21082
|
}
|
|
19843
21083
|
}
|
|
21084
|
+
class ExperimentalServerTasks {
|
|
21085
|
+
constructor(_server) {
|
|
21086
|
+
this._server = _server;
|
|
21087
|
+
}
|
|
21088
|
+
/**
|
|
21089
|
+
* Sends a request and returns an AsyncGenerator that yields response messages.
|
|
21090
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
21091
|
+
*
|
|
21092
|
+
* This method provides streaming access to request processing, allowing you to
|
|
21093
|
+
* observe intermediate task status updates for task-augmented requests.
|
|
21094
|
+
*
|
|
21095
|
+
* @param request - The request to send
|
|
21096
|
+
* @param resultSchema - Zod schema for validating the result
|
|
21097
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
21098
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
21099
|
+
*
|
|
21100
|
+
* @experimental
|
|
21101
|
+
*/
|
|
21102
|
+
requestStream(request, resultSchema, options) {
|
|
21103
|
+
return this._server.requestStream(request, resultSchema, options);
|
|
21104
|
+
}
|
|
21105
|
+
/**
|
|
21106
|
+
* Gets the current status of a task.
|
|
21107
|
+
*
|
|
21108
|
+
* @param taskId - The task identifier
|
|
21109
|
+
* @param options - Optional request options
|
|
21110
|
+
* @returns The task status
|
|
21111
|
+
*
|
|
21112
|
+
* @experimental
|
|
21113
|
+
*/
|
|
21114
|
+
async getTask(taskId, options) {
|
|
21115
|
+
return this._server.getTask({ taskId }, options);
|
|
21116
|
+
}
|
|
21117
|
+
/**
|
|
21118
|
+
* Retrieves the result of a completed task.
|
|
21119
|
+
*
|
|
21120
|
+
* @param taskId - The task identifier
|
|
21121
|
+
* @param resultSchema - Zod schema for validating the result
|
|
21122
|
+
* @param options - Optional request options
|
|
21123
|
+
* @returns The task result
|
|
21124
|
+
*
|
|
21125
|
+
* @experimental
|
|
21126
|
+
*/
|
|
21127
|
+
async getTaskResult(taskId, resultSchema, options) {
|
|
21128
|
+
return this._server.getTaskResult({ taskId }, resultSchema, options);
|
|
21129
|
+
}
|
|
21130
|
+
/**
|
|
21131
|
+
* Lists tasks with optional pagination.
|
|
21132
|
+
*
|
|
21133
|
+
* @param cursor - Optional pagination cursor
|
|
21134
|
+
* @param options - Optional request options
|
|
21135
|
+
* @returns List of tasks with optional next cursor
|
|
21136
|
+
*
|
|
21137
|
+
* @experimental
|
|
21138
|
+
*/
|
|
21139
|
+
async listTasks(cursor, options) {
|
|
21140
|
+
return this._server.listTasks(cursor ? { cursor } : void 0, options);
|
|
21141
|
+
}
|
|
21142
|
+
/**
|
|
21143
|
+
* Cancels a running task.
|
|
21144
|
+
*
|
|
21145
|
+
* @param taskId - The task identifier
|
|
21146
|
+
* @param options - Optional request options
|
|
21147
|
+
*
|
|
21148
|
+
* @experimental
|
|
21149
|
+
*/
|
|
21150
|
+
async cancelTask(taskId, options) {
|
|
21151
|
+
return this._server.cancelTask({ taskId }, options);
|
|
21152
|
+
}
|
|
21153
|
+
}
|
|
19844
21154
|
class Server extends Protocol {
|
|
19845
21155
|
/**
|
|
19846
21156
|
* Initializes this server with the given name and version information.
|
|
19847
21157
|
*/
|
|
19848
21158
|
constructor(_serverInfo, options) {
|
|
19849
|
-
var _a, _b;
|
|
19850
21159
|
super(options);
|
|
19851
21160
|
this._serverInfo = _serverInfo;
|
|
19852
21161
|
this._loggingLevels = /* @__PURE__ */ new Map();
|
|
@@ -19855,18 +21164,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19855
21164
|
const currentLevel = this._loggingLevels.get(sessionId);
|
|
19856
21165
|
return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
|
|
19857
21166
|
};
|
|
19858
|
-
this._capabilities =
|
|
19859
|
-
this._instructions = options
|
|
19860
|
-
this._jsonSchemaValidator =
|
|
21167
|
+
this._capabilities = options?.capabilities ?? {};
|
|
21168
|
+
this._instructions = options?.instructions;
|
|
21169
|
+
this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new AjvJsonSchemaValidator();
|
|
19861
21170
|
this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request));
|
|
19862
|
-
this.setNotificationHandler(InitializedNotificationSchema, () =>
|
|
19863
|
-
var _a2;
|
|
19864
|
-
return (_a2 = this.oninitialized) === null || _a2 === void 0 ? void 0 : _a2.call(this);
|
|
19865
|
-
});
|
|
21171
|
+
this.setNotificationHandler(InitializedNotificationSchema, () => this.oninitialized?.());
|
|
19866
21172
|
if (this._capabilities.logging) {
|
|
19867
21173
|
this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
|
|
19868
|
-
|
|
19869
|
-
const transportSessionId = extra.sessionId || ((_a2 = extra.requestInfo) === null || _a2 === void 0 ? void 0 : _a2.headers["mcp-session-id"]) || void 0;
|
|
21174
|
+
const transportSessionId = extra.sessionId || extra.requestInfo?.headers["mcp-session-id"] || void 0;
|
|
19870
21175
|
const { level } = request.params;
|
|
19871
21176
|
const parseResult = LoggingLevelSchema.safeParse(level);
|
|
19872
21177
|
if (parseResult.success) {
|
|
@@ -19876,6 +21181,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19876
21181
|
});
|
|
19877
21182
|
}
|
|
19878
21183
|
}
|
|
21184
|
+
/**
|
|
21185
|
+
* Access experimental features.
|
|
21186
|
+
*
|
|
21187
|
+
* WARNING: These APIs are experimental and may change without notice.
|
|
21188
|
+
*
|
|
21189
|
+
* @experimental
|
|
21190
|
+
*/
|
|
21191
|
+
get experimental() {
|
|
21192
|
+
if (!this._experimental) {
|
|
21193
|
+
this._experimental = {
|
|
21194
|
+
tasks: new ExperimentalServerTasks(this)
|
|
21195
|
+
};
|
|
21196
|
+
}
|
|
21197
|
+
return this._experimental;
|
|
21198
|
+
}
|
|
19879
21199
|
/**
|
|
19880
21200
|
* Registers new capabilities. This can only be called before connecting to a transport.
|
|
19881
21201
|
*
|
|
@@ -19887,28 +21207,77 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19887
21207
|
}
|
|
19888
21208
|
this._capabilities = mergeCapabilities(this._capabilities, capabilities);
|
|
19889
21209
|
}
|
|
21210
|
+
/**
|
|
21211
|
+
* Override request handler registration to enforce server-side validation for tools/call.
|
|
21212
|
+
*/
|
|
21213
|
+
setRequestHandler(requestSchema, handler) {
|
|
21214
|
+
const shape = getObjectShape(requestSchema);
|
|
21215
|
+
const methodSchema = shape?.method;
|
|
21216
|
+
if (!methodSchema) {
|
|
21217
|
+
throw new Error("Schema is missing a method literal");
|
|
21218
|
+
}
|
|
21219
|
+
let methodValue;
|
|
21220
|
+
if (isZ4Schema(methodSchema)) {
|
|
21221
|
+
const v4Schema = methodSchema;
|
|
21222
|
+
const v4Def = v4Schema._zod?.def;
|
|
21223
|
+
methodValue = v4Def?.value ?? v4Schema.value;
|
|
21224
|
+
} else {
|
|
21225
|
+
const v3Schema = methodSchema;
|
|
21226
|
+
const legacyDef = v3Schema._def;
|
|
21227
|
+
methodValue = legacyDef?.value ?? v3Schema.value;
|
|
21228
|
+
}
|
|
21229
|
+
if (typeof methodValue !== "string") {
|
|
21230
|
+
throw new Error("Schema method literal must be a string");
|
|
21231
|
+
}
|
|
21232
|
+
const method = methodValue;
|
|
21233
|
+
if (method === "tools/call") {
|
|
21234
|
+
const wrappedHandler = async (request, extra) => {
|
|
21235
|
+
const validatedRequest = safeParse(CallToolRequestSchema, request);
|
|
21236
|
+
if (!validatedRequest.success) {
|
|
21237
|
+
const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
21238
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Invalid tools/call request: ${errorMessage}`);
|
|
21239
|
+
}
|
|
21240
|
+
const { params } = validatedRequest.data;
|
|
21241
|
+
const result = await Promise.resolve(handler(request, extra));
|
|
21242
|
+
if (params.task) {
|
|
21243
|
+
const taskValidationResult = safeParse(CreateTaskResultSchema, result);
|
|
21244
|
+
if (!taskValidationResult.success) {
|
|
21245
|
+
const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
21246
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
|
|
21247
|
+
}
|
|
21248
|
+
return taskValidationResult.data;
|
|
21249
|
+
}
|
|
21250
|
+
const validationResult = safeParse(CallToolResultSchema, result);
|
|
21251
|
+
if (!validationResult.success) {
|
|
21252
|
+
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
21253
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Invalid tools/call result: ${errorMessage}`);
|
|
21254
|
+
}
|
|
21255
|
+
return validationResult.data;
|
|
21256
|
+
};
|
|
21257
|
+
return super.setRequestHandler(requestSchema, wrappedHandler);
|
|
21258
|
+
}
|
|
21259
|
+
return super.setRequestHandler(requestSchema, handler);
|
|
21260
|
+
}
|
|
19890
21261
|
assertCapabilityForMethod(method) {
|
|
19891
|
-
var _a, _b, _c;
|
|
19892
21262
|
switch (method) {
|
|
19893
21263
|
case "sampling/createMessage":
|
|
19894
|
-
if (!
|
|
21264
|
+
if (!this._clientCapabilities?.sampling) {
|
|
19895
21265
|
throw new Error(`Client does not support sampling (required for ${method})`);
|
|
19896
21266
|
}
|
|
19897
21267
|
break;
|
|
19898
21268
|
case "elicitation/create":
|
|
19899
|
-
if (!
|
|
21269
|
+
if (!this._clientCapabilities?.elicitation) {
|
|
19900
21270
|
throw new Error(`Client does not support elicitation (required for ${method})`);
|
|
19901
21271
|
}
|
|
19902
21272
|
break;
|
|
19903
21273
|
case "roots/list":
|
|
19904
|
-
if (!
|
|
21274
|
+
if (!this._clientCapabilities?.roots) {
|
|
19905
21275
|
throw new Error(`Client does not support listing roots (required for ${method})`);
|
|
19906
21276
|
}
|
|
19907
21277
|
break;
|
|
19908
21278
|
}
|
|
19909
21279
|
}
|
|
19910
21280
|
assertNotificationCapability(method) {
|
|
19911
|
-
var _a, _b;
|
|
19912
21281
|
switch (method) {
|
|
19913
21282
|
case "notifications/message":
|
|
19914
21283
|
if (!this._capabilities.logging) {
|
|
@@ -19932,13 +21301,16 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19932
21301
|
}
|
|
19933
21302
|
break;
|
|
19934
21303
|
case "notifications/elicitation/complete":
|
|
19935
|
-
if (!
|
|
21304
|
+
if (!this._clientCapabilities?.elicitation?.url) {
|
|
19936
21305
|
throw new Error(`Client does not support URL elicitation (required for ${method})`);
|
|
19937
21306
|
}
|
|
19938
21307
|
break;
|
|
19939
21308
|
}
|
|
19940
21309
|
}
|
|
19941
21310
|
assertRequestHandlerCapability(method) {
|
|
21311
|
+
if (!this._capabilities) {
|
|
21312
|
+
return;
|
|
21313
|
+
}
|
|
19942
21314
|
switch (method) {
|
|
19943
21315
|
case "completion/complete":
|
|
19944
21316
|
if (!this._capabilities.completions) {
|
|
@@ -19969,7 +21341,24 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19969
21341
|
throw new Error(`Server does not support tools (required for ${method})`);
|
|
19970
21342
|
}
|
|
19971
21343
|
break;
|
|
21344
|
+
case "tasks/get":
|
|
21345
|
+
case "tasks/list":
|
|
21346
|
+
case "tasks/result":
|
|
21347
|
+
case "tasks/cancel":
|
|
21348
|
+
if (!this._capabilities.tasks) {
|
|
21349
|
+
throw new Error(`Server does not support tasks capability (required for ${method})`);
|
|
21350
|
+
}
|
|
21351
|
+
break;
|
|
21352
|
+
}
|
|
21353
|
+
}
|
|
21354
|
+
assertTaskCapability(method) {
|
|
21355
|
+
assertClientRequestTaskCapability(this._clientCapabilities?.tasks?.requests, method, "Client");
|
|
21356
|
+
}
|
|
21357
|
+
assertTaskHandlerCapability(method) {
|
|
21358
|
+
if (!this._capabilities) {
|
|
21359
|
+
return;
|
|
19972
21360
|
}
|
|
21361
|
+
assertToolsCallTaskCapability(this._capabilities.tasks?.requests, method, "Server");
|
|
19973
21362
|
}
|
|
19974
21363
|
async _oninitialize(request) {
|
|
19975
21364
|
const requestedVersion = request.params.protocolVersion;
|
|
@@ -20001,10 +21390,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20001
21390
|
async ping() {
|
|
20002
21391
|
return this.request({ method: "ping" }, EmptyResultSchema);
|
|
20003
21392
|
}
|
|
21393
|
+
// Implementation
|
|
20004
21394
|
async createMessage(params, options) {
|
|
20005
|
-
var _a, _b;
|
|
20006
21395
|
if (params.tools || params.toolChoice) {
|
|
20007
|
-
if (!
|
|
21396
|
+
if (!this._clientCapabilities?.sampling?.tools) {
|
|
20008
21397
|
throw new Error("Client does not support sampling tools capability.");
|
|
20009
21398
|
}
|
|
20010
21399
|
}
|
|
@@ -20031,6 +21420,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20031
21420
|
}
|
|
20032
21421
|
}
|
|
20033
21422
|
}
|
|
21423
|
+
if (params.tools) {
|
|
21424
|
+
return this.request({ method: "sampling/createMessage", params }, CreateMessageResultWithToolsSchema, options);
|
|
21425
|
+
}
|
|
20034
21426
|
return this.request({ method: "sampling/createMessage", params }, CreateMessageResultSchema, options);
|
|
20035
21427
|
}
|
|
20036
21428
|
/**
|
|
@@ -20041,18 +21433,17 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20041
21433
|
* @returns The result of the elicitation request.
|
|
20042
21434
|
*/
|
|
20043
21435
|
async elicitInput(params, options) {
|
|
20044
|
-
|
|
20045
|
-
const mode = (_a = params.mode) !== null && _a !== void 0 ? _a : "form";
|
|
21436
|
+
const mode = params.mode ?? "form";
|
|
20046
21437
|
switch (mode) {
|
|
20047
21438
|
case "url": {
|
|
20048
|
-
if (!
|
|
21439
|
+
if (!this._clientCapabilities?.elicitation?.url) {
|
|
20049
21440
|
throw new Error("Client does not support url elicitation.");
|
|
20050
21441
|
}
|
|
20051
21442
|
const urlParams = params;
|
|
20052
21443
|
return this.request({ method: "elicitation/create", params: urlParams }, ElicitResultSchema, options);
|
|
20053
21444
|
}
|
|
20054
21445
|
case "form": {
|
|
20055
|
-
if (!
|
|
21446
|
+
if (!this._clientCapabilities?.elicitation?.form) {
|
|
20056
21447
|
throw new Error("Client does not support form elicitation.");
|
|
20057
21448
|
}
|
|
20058
21449
|
const formParams = params.mode === "form" ? params : { ...params, mode: "form" };
|
|
@@ -20084,8 +21475,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20084
21475
|
* @returns A function that emits the completion notification when awaited.
|
|
20085
21476
|
*/
|
|
20086
21477
|
createElicitationCompletionNotifier(elicitationId, options) {
|
|
20087
|
-
|
|
20088
|
-
if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) {
|
|
21478
|
+
if (!this._clientCapabilities?.elicitation?.url) {
|
|
20089
21479
|
throw new Error("Client does not support URL elicitation (required for notifications/elicitation/complete)");
|
|
20090
21480
|
}
|
|
20091
21481
|
return () => this.notification({
|
|
@@ -20186,6 +21576,19 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20186
21576
|
issueToolNameWarning(name, result.warnings);
|
|
20187
21577
|
return result.isValid;
|
|
20188
21578
|
}
|
|
21579
|
+
class ExperimentalMcpServerTasks {
|
|
21580
|
+
constructor(_mcpServer) {
|
|
21581
|
+
this._mcpServer = _mcpServer;
|
|
21582
|
+
}
|
|
21583
|
+
registerToolTask(name, config2, handler) {
|
|
21584
|
+
const execution = { taskSupport: "required", ...config2.execution };
|
|
21585
|
+
if (execution.taskSupport === "forbidden") {
|
|
21586
|
+
throw new Error(`Cannot register task-based tool '${name}' with taskSupport 'forbidden'. Use registerTool() instead.`);
|
|
21587
|
+
}
|
|
21588
|
+
const mcpServerInternal = this._mcpServer;
|
|
21589
|
+
return mcpServerInternal._createRegisteredTool(name, config2.title, config2.description, config2.inputSchema, config2.outputSchema, config2.annotations, execution, config2._meta, handler);
|
|
21590
|
+
}
|
|
21591
|
+
}
|
|
20189
21592
|
class McpServer {
|
|
20190
21593
|
constructor(serverInfo, options) {
|
|
20191
21594
|
this._registeredResources = {};
|
|
@@ -20198,6 +21601,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20198
21601
|
this._promptHandlersInitialized = false;
|
|
20199
21602
|
this.server = new Server(serverInfo, options);
|
|
20200
21603
|
}
|
|
21604
|
+
/**
|
|
21605
|
+
* Access experimental features.
|
|
21606
|
+
*
|
|
21607
|
+
* WARNING: These APIs are experimental and may change without notice.
|
|
21608
|
+
*
|
|
21609
|
+
* @experimental
|
|
21610
|
+
*/
|
|
21611
|
+
get experimental() {
|
|
21612
|
+
if (!this._experimental) {
|
|
21613
|
+
this._experimental = {
|
|
21614
|
+
tasks: new ExperimentalMcpServerTasks(this)
|
|
21615
|
+
};
|
|
21616
|
+
}
|
|
21617
|
+
return this._experimental;
|
|
21618
|
+
}
|
|
20201
21619
|
/**
|
|
20202
21620
|
* Attaches to the given transport, starts it, and starts listening for messages.
|
|
20203
21621
|
*
|
|
@@ -20237,6 +21655,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20237
21655
|
}) : EMPTY_OBJECT_JSON_SCHEMA;
|
|
20238
21656
|
})(),
|
|
20239
21657
|
annotations: tool.annotations,
|
|
21658
|
+
execution: tool.execution,
|
|
20240
21659
|
_meta: tool._meta
|
|
20241
21660
|
};
|
|
20242
21661
|
if (tool.outputSchema) {
|
|
@@ -20252,39 +21671,33 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20252
21671
|
})
|
|
20253
21672
|
}));
|
|
20254
21673
|
this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
20255
|
-
const tool = this._registeredTools[request.params.name];
|
|
20256
|
-
let result;
|
|
20257
21674
|
try {
|
|
21675
|
+
const tool = this._registeredTools[request.params.name];
|
|
20258
21676
|
if (!tool) {
|
|
20259
21677
|
throw new McpError(exports2.ErrorCode.InvalidParams, `Tool ${request.params.name} not found`);
|
|
20260
21678
|
}
|
|
20261
21679
|
if (!tool.enabled) {
|
|
20262
21680
|
throw new McpError(exports2.ErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
|
|
20263
21681
|
}
|
|
20264
|
-
|
|
20265
|
-
|
|
20266
|
-
|
|
20267
|
-
|
|
20268
|
-
|
|
20269
|
-
if (!parseResult.success) {
|
|
20270
|
-
throw new McpError(exports2.ErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${request.params.name}: ${getParseErrorMessage(parseResult.error)}`);
|
|
20271
|
-
}
|
|
20272
|
-
const args = parseResult.data;
|
|
20273
|
-
result = await Promise.resolve(cb(args, extra));
|
|
20274
|
-
} else {
|
|
20275
|
-
const cb = tool.callback;
|
|
20276
|
-
result = await Promise.resolve(cb(extra));
|
|
21682
|
+
const isTaskRequest = !!request.params.task;
|
|
21683
|
+
const taskSupport = tool.execution?.taskSupport;
|
|
21684
|
+
const isTaskHandler = "createTask" in tool.handler;
|
|
21685
|
+
if ((taskSupport === "required" || taskSupport === "optional") && !isTaskHandler) {
|
|
21686
|
+
throw new McpError(exports2.ErrorCode.InternalError, `Tool ${request.params.name} has taskSupport '${taskSupport}' but was not registered with registerToolTask`);
|
|
20277
21687
|
}
|
|
20278
|
-
if (
|
|
20279
|
-
|
|
20280
|
-
|
|
20281
|
-
|
|
20282
|
-
|
|
20283
|
-
|
|
20284
|
-
|
|
20285
|
-
|
|
20286
|
-
|
|
21688
|
+
if (taskSupport === "required" && !isTaskRequest) {
|
|
21689
|
+
throw new McpError(exports2.ErrorCode.MethodNotFound, `Tool ${request.params.name} requires task augmentation (taskSupport: 'required')`);
|
|
21690
|
+
}
|
|
21691
|
+
if (taskSupport === "optional" && !isTaskRequest && isTaskHandler) {
|
|
21692
|
+
return await this.handleAutomaticTaskPolling(tool, request, extra);
|
|
21693
|
+
}
|
|
21694
|
+
const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);
|
|
21695
|
+
const result = await this.executeToolHandler(tool, args, extra);
|
|
21696
|
+
if (isTaskRequest) {
|
|
21697
|
+
return result;
|
|
20287
21698
|
}
|
|
21699
|
+
await this.validateToolOutput(tool, result, request.params.name);
|
|
21700
|
+
return result;
|
|
20288
21701
|
} catch (error) {
|
|
20289
21702
|
if (error instanceof McpError) {
|
|
20290
21703
|
if (error.code === exports2.ErrorCode.UrlElicitationRequired) {
|
|
@@ -20293,7 +21706,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20293
21706
|
}
|
|
20294
21707
|
return this.createToolError(error instanceof Error ? error.message : String(error));
|
|
20295
21708
|
}
|
|
20296
|
-
return result;
|
|
20297
21709
|
});
|
|
20298
21710
|
this._toolHandlersInitialized = true;
|
|
20299
21711
|
}
|
|
@@ -20314,6 +21726,101 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20314
21726
|
isError: true
|
|
20315
21727
|
};
|
|
20316
21728
|
}
|
|
21729
|
+
/**
|
|
21730
|
+
* Validates tool input arguments against the tool's input schema.
|
|
21731
|
+
*/
|
|
21732
|
+
async validateToolInput(tool, args, toolName) {
|
|
21733
|
+
if (!tool.inputSchema) {
|
|
21734
|
+
return void 0;
|
|
21735
|
+
}
|
|
21736
|
+
const inputObj = normalizeObjectSchema(tool.inputSchema);
|
|
21737
|
+
const schemaToParse = inputObj ?? tool.inputSchema;
|
|
21738
|
+
const parseResult = await safeParseAsync(schemaToParse, args);
|
|
21739
|
+
if (!parseResult.success) {
|
|
21740
|
+
const error = "error" in parseResult ? parseResult.error : "Unknown error";
|
|
21741
|
+
const errorMessage = getParseErrorMessage(error);
|
|
21742
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName}: ${errorMessage}`);
|
|
21743
|
+
}
|
|
21744
|
+
return parseResult.data;
|
|
21745
|
+
}
|
|
21746
|
+
/**
|
|
21747
|
+
* Validates tool output against the tool's output schema.
|
|
21748
|
+
*/
|
|
21749
|
+
async validateToolOutput(tool, result, toolName) {
|
|
21750
|
+
if (!tool.outputSchema) {
|
|
21751
|
+
return;
|
|
21752
|
+
}
|
|
21753
|
+
if (!("content" in result)) {
|
|
21754
|
+
return;
|
|
21755
|
+
}
|
|
21756
|
+
if (result.isError) {
|
|
21757
|
+
return;
|
|
21758
|
+
}
|
|
21759
|
+
if (!result.structuredContent) {
|
|
21760
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Output validation error: Tool ${toolName} has an output schema but no structured content was provided`);
|
|
21761
|
+
}
|
|
21762
|
+
const outputObj = normalizeObjectSchema(tool.outputSchema);
|
|
21763
|
+
const parseResult = await safeParseAsync(outputObj, result.structuredContent);
|
|
21764
|
+
if (!parseResult.success) {
|
|
21765
|
+
const error = "error" in parseResult ? parseResult.error : "Unknown error";
|
|
21766
|
+
const errorMessage = getParseErrorMessage(error);
|
|
21767
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName}: ${errorMessage}`);
|
|
21768
|
+
}
|
|
21769
|
+
}
|
|
21770
|
+
/**
|
|
21771
|
+
* Executes a tool handler (either regular or task-based).
|
|
21772
|
+
*/
|
|
21773
|
+
async executeToolHandler(tool, args, extra) {
|
|
21774
|
+
const handler = tool.handler;
|
|
21775
|
+
const isTaskHandler = "createTask" in handler;
|
|
21776
|
+
if (isTaskHandler) {
|
|
21777
|
+
if (!extra.taskStore) {
|
|
21778
|
+
throw new Error("No task store provided.");
|
|
21779
|
+
}
|
|
21780
|
+
const taskExtra = { ...extra, taskStore: extra.taskStore };
|
|
21781
|
+
if (tool.inputSchema) {
|
|
21782
|
+
const typedHandler = handler;
|
|
21783
|
+
return await Promise.resolve(typedHandler.createTask(args, taskExtra));
|
|
21784
|
+
} else {
|
|
21785
|
+
const typedHandler = handler;
|
|
21786
|
+
return await Promise.resolve(typedHandler.createTask(taskExtra));
|
|
21787
|
+
}
|
|
21788
|
+
}
|
|
21789
|
+
if (tool.inputSchema) {
|
|
21790
|
+
const typedHandler = handler;
|
|
21791
|
+
return await Promise.resolve(typedHandler(args, extra));
|
|
21792
|
+
} else {
|
|
21793
|
+
const typedHandler = handler;
|
|
21794
|
+
return await Promise.resolve(typedHandler(extra));
|
|
21795
|
+
}
|
|
21796
|
+
}
|
|
21797
|
+
/**
|
|
21798
|
+
* Handles automatic task polling for tools with taskSupport 'optional'.
|
|
21799
|
+
*/
|
|
21800
|
+
async handleAutomaticTaskPolling(tool, request, extra) {
|
|
21801
|
+
if (!extra.taskStore) {
|
|
21802
|
+
throw new Error("No task store provided for task-capable tool.");
|
|
21803
|
+
}
|
|
21804
|
+
const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);
|
|
21805
|
+
const handler = tool.handler;
|
|
21806
|
+
const taskExtra = { ...extra, taskStore: extra.taskStore };
|
|
21807
|
+
const createTaskResult = args ? await Promise.resolve(handler.createTask(args, taskExtra)) : (
|
|
21808
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21809
|
+
await Promise.resolve(handler.createTask(taskExtra))
|
|
21810
|
+
);
|
|
21811
|
+
const taskId = createTaskResult.task.taskId;
|
|
21812
|
+
let task = createTaskResult.task;
|
|
21813
|
+
const pollInterval = task.pollInterval ?? 5e3;
|
|
21814
|
+
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
21815
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
21816
|
+
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
21817
|
+
if (!updatedTask) {
|
|
21818
|
+
throw new McpError(exports2.ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
21819
|
+
}
|
|
21820
|
+
task = updatedTask;
|
|
21821
|
+
}
|
|
21822
|
+
return await extra.taskStore.getTaskResult(taskId);
|
|
21823
|
+
}
|
|
20317
21824
|
setCompletionRequestHandler() {
|
|
20318
21825
|
if (this._completionHandlerInitialized) {
|
|
20319
21826
|
return;
|
|
@@ -20348,7 +21855,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20348
21855
|
return EMPTY_COMPLETION_RESULT;
|
|
20349
21856
|
}
|
|
20350
21857
|
const promptShape = getObjectShape(prompt.argsSchema);
|
|
20351
|
-
const field = promptShape
|
|
21858
|
+
const field = promptShape?.[request.params.argument.name];
|
|
20352
21859
|
if (!isCompletable(field)) {
|
|
20353
21860
|
return EMPTY_COMPLETION_RESULT;
|
|
20354
21861
|
}
|
|
@@ -20433,7 +21940,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20433
21940
|
}
|
|
20434
21941
|
throw new McpError(exports2.ErrorCode.InvalidParams, `Resource ${uri2} not found`);
|
|
20435
21942
|
});
|
|
20436
|
-
this.setCompletionRequestHandler();
|
|
20437
21943
|
this._resourceHandlersInitialized = true;
|
|
20438
21944
|
}
|
|
20439
21945
|
setPromptRequestHandlers() {
|
|
@@ -20469,7 +21975,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20469
21975
|
const argsObj = normalizeObjectSchema(prompt.argsSchema);
|
|
20470
21976
|
const parseResult = await safeParseAsync(argsObj, request.params.arguments);
|
|
20471
21977
|
if (!parseResult.success) {
|
|
20472
|
-
|
|
21978
|
+
const error = "error" in parseResult ? parseResult.error : "Unknown error";
|
|
21979
|
+
const errorMessage = getParseErrorMessage(error);
|
|
21980
|
+
throw new McpError(exports2.ErrorCode.InvalidParams, `Invalid arguments for prompt ${request.params.name}: ${errorMessage}`);
|
|
20473
21981
|
}
|
|
20474
21982
|
const args = parseResult.data;
|
|
20475
21983
|
const cb = prompt.callback;
|
|
@@ -20479,7 +21987,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20479
21987
|
return await Promise.resolve(cb(extra));
|
|
20480
21988
|
}
|
|
20481
21989
|
});
|
|
20482
|
-
this.setCompletionRequestHandler();
|
|
20483
21990
|
this._promptHandlersInitialized = true;
|
|
20484
21991
|
}
|
|
20485
21992
|
resource(name, uriOrTemplate, ...rest) {
|
|
@@ -20587,6 +22094,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20587
22094
|
}
|
|
20588
22095
|
};
|
|
20589
22096
|
this._registeredResourceTemplates[name] = registeredResourceTemplate;
|
|
22097
|
+
const variableNames = template.uriTemplate.variableNames;
|
|
22098
|
+
const hasCompleter = Array.isArray(variableNames) && variableNames.some((v) => !!template.completeCallback(v));
|
|
22099
|
+
if (hasCompleter) {
|
|
22100
|
+
this.setCompletionRequestHandler();
|
|
22101
|
+
}
|
|
20590
22102
|
return registeredResourceTemplate;
|
|
20591
22103
|
}
|
|
20592
22104
|
_createRegisteredPrompt(name, title2, description2, argsSchema, callback) {
|
|
@@ -20619,9 +22131,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20619
22131
|
}
|
|
20620
22132
|
};
|
|
20621
22133
|
this._registeredPrompts[name] = registeredPrompt;
|
|
22134
|
+
if (argsSchema) {
|
|
22135
|
+
const hasCompletable = Object.values(argsSchema).some((field) => {
|
|
22136
|
+
const inner = field instanceof ZodOptional ? field._def?.innerType : field;
|
|
22137
|
+
return isCompletable(inner);
|
|
22138
|
+
});
|
|
22139
|
+
if (hasCompletable) {
|
|
22140
|
+
this.setCompletionRequestHandler();
|
|
22141
|
+
}
|
|
22142
|
+
}
|
|
20622
22143
|
return registeredPrompt;
|
|
20623
22144
|
}
|
|
20624
|
-
_createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, _meta,
|
|
22145
|
+
_createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, execution, _meta, handler) {
|
|
20625
22146
|
validateAndWarnToolName(name);
|
|
20626
22147
|
const registeredTool = {
|
|
20627
22148
|
title: title2,
|
|
@@ -20629,8 +22150,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20629
22150
|
inputSchema: getZodSchemaObject(inputSchema),
|
|
20630
22151
|
outputSchema: getZodSchemaObject(outputSchema),
|
|
20631
22152
|
annotations,
|
|
22153
|
+
execution,
|
|
20632
22154
|
_meta,
|
|
20633
|
-
|
|
22155
|
+
handler,
|
|
20634
22156
|
enabled: true,
|
|
20635
22157
|
disable: () => registeredTool.update({ enabled: false }),
|
|
20636
22158
|
enable: () => registeredTool.update({ enabled: true }),
|
|
@@ -20650,8 +22172,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20650
22172
|
registeredTool.description = updates.description;
|
|
20651
22173
|
if (typeof updates.paramsSchema !== "undefined")
|
|
20652
22174
|
registeredTool.inputSchema = objectFromShape(updates.paramsSchema);
|
|
22175
|
+
if (typeof updates.outputSchema !== "undefined")
|
|
22176
|
+
registeredTool.outputSchema = objectFromShape(updates.outputSchema);
|
|
20653
22177
|
if (typeof updates.callback !== "undefined")
|
|
20654
|
-
registeredTool.
|
|
22178
|
+
registeredTool.handler = updates.callback;
|
|
20655
22179
|
if (typeof updates.annotations !== "undefined")
|
|
20656
22180
|
registeredTool.annotations = updates.annotations;
|
|
20657
22181
|
if (typeof updates._meta !== "undefined")
|
|
@@ -20682,9 +22206,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20682
22206
|
}
|
|
20683
22207
|
if (rest.length > 1) {
|
|
20684
22208
|
const firstArg = rest[0];
|
|
20685
|
-
if (
|
|
22209
|
+
if (isZodRawShapeCompat(firstArg)) {
|
|
20686
22210
|
inputSchema = rest.shift();
|
|
20687
|
-
if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !
|
|
22211
|
+
if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !isZodRawShapeCompat(rest[0])) {
|
|
20688
22212
|
annotations = rest.shift();
|
|
20689
22213
|
}
|
|
20690
22214
|
} else if (typeof firstArg === "object" && firstArg !== null) {
|
|
@@ -20692,7 +22216,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20692
22216
|
}
|
|
20693
22217
|
}
|
|
20694
22218
|
const callback = rest[0];
|
|
20695
|
-
return this._createRegisteredTool(name, void 0, description2, inputSchema, outputSchema, annotations, void 0, callback);
|
|
22219
|
+
return this._createRegisteredTool(name, void 0, description2, inputSchema, outputSchema, annotations, { taskSupport: "forbidden" }, void 0, callback);
|
|
20696
22220
|
}
|
|
20697
22221
|
/**
|
|
20698
22222
|
* Registers a tool with a config object and callback.
|
|
@@ -20702,7 +22226,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20702
22226
|
throw new Error(`Tool ${name} is already registered`);
|
|
20703
22227
|
}
|
|
20704
22228
|
const { title: title2, description: description2, inputSchema, outputSchema, annotations, _meta } = config2;
|
|
20705
|
-
return this._createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, _meta, cb);
|
|
22229
|
+
return this._createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, { taskSupport: "forbidden" }, _meta, cb);
|
|
20706
22230
|
}
|
|
20707
22231
|
prompt(name, ...rest) {
|
|
20708
22232
|
if (this._registeredPrompts[name]) {
|
|
@@ -20798,28 +22322,36 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20798
22322
|
* Gets the callback for completing a specific URI template variable, if one was provided.
|
|
20799
22323
|
*/
|
|
20800
22324
|
completeCallback(variable) {
|
|
20801
|
-
|
|
20802
|
-
return (_a = this._callbacks.complete) === null || _a === void 0 ? void 0 : _a[variable];
|
|
22325
|
+
return this._callbacks.complete?.[variable];
|
|
20803
22326
|
}
|
|
20804
22327
|
}
|
|
20805
22328
|
const EMPTY_OBJECT_JSON_SCHEMA = {
|
|
20806
22329
|
type: "object",
|
|
20807
22330
|
properties: {}
|
|
20808
22331
|
};
|
|
20809
|
-
function isZodRawShape(obj) {
|
|
20810
|
-
if (typeof obj !== "object" || obj === null)
|
|
20811
|
-
return false;
|
|
20812
|
-
const isEmptyObject = Object.keys(obj).length === 0;
|
|
20813
|
-
return isEmptyObject || Object.values(obj).some(isZodTypeLike);
|
|
20814
|
-
}
|
|
20815
22332
|
function isZodTypeLike(value) {
|
|
20816
22333
|
return value !== null && typeof value === "object" && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
20817
22334
|
}
|
|
22335
|
+
function isZodSchemaInstance(obj) {
|
|
22336
|
+
return "_def" in obj || "_zod" in obj || isZodTypeLike(obj);
|
|
22337
|
+
}
|
|
22338
|
+
function isZodRawShapeCompat(obj) {
|
|
22339
|
+
if (typeof obj !== "object" || obj === null) {
|
|
22340
|
+
return false;
|
|
22341
|
+
}
|
|
22342
|
+
if (isZodSchemaInstance(obj)) {
|
|
22343
|
+
return false;
|
|
22344
|
+
}
|
|
22345
|
+
if (Object.keys(obj).length === 0) {
|
|
22346
|
+
return true;
|
|
22347
|
+
}
|
|
22348
|
+
return Object.values(obj).some(isZodTypeLike);
|
|
22349
|
+
}
|
|
20818
22350
|
function getZodSchemaObject(schema) {
|
|
20819
22351
|
if (!schema) {
|
|
20820
22352
|
return void 0;
|
|
20821
22353
|
}
|
|
20822
|
-
if (
|
|
22354
|
+
if (isZodRawShapeCompat(schema)) {
|
|
20823
22355
|
return objectFromShape(schema);
|
|
20824
22356
|
}
|
|
20825
22357
|
return schema;
|
|
@@ -20840,7 +22372,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20840
22372
|
}
|
|
20841
22373
|
function getMethodValue(schema) {
|
|
20842
22374
|
const shape = getObjectShape(schema);
|
|
20843
|
-
const methodSchema = shape
|
|
22375
|
+
const methodSchema = shape?.method;
|
|
20844
22376
|
if (!methodSchema) {
|
|
20845
22377
|
throw new Error("Schema is missing a method literal");
|
|
20846
22378
|
}
|
|
@@ -20865,7 +22397,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20865
22397
|
hasMore: false
|
|
20866
22398
|
}
|
|
20867
22399
|
};
|
|
20868
|
-
exports2.Ajv =
|
|
22400
|
+
exports2.Ajv = Ajv;
|
|
22401
|
+
exports2.AnnotationsSchema = AnnotationsSchema;
|
|
20869
22402
|
exports2.AudioContentSchema = AudioContentSchema;
|
|
20870
22403
|
exports2.BaseMetadataSchema = BaseMetadataSchema;
|
|
20871
22404
|
exports2.BlobResourceContentsSchema = BlobResourceContentsSchema;
|
|
@@ -20874,6 +22407,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20874
22407
|
exports2.CallToolRequestParamsSchema = CallToolRequestParamsSchema;
|
|
20875
22408
|
exports2.CallToolRequestSchema = CallToolRequestSchema;
|
|
20876
22409
|
exports2.CallToolResultSchema = CallToolResultSchema;
|
|
22410
|
+
exports2.CancelTaskRequestSchema = CancelTaskRequestSchema;
|
|
22411
|
+
exports2.CancelTaskResultSchema = CancelTaskResultSchema;
|
|
20877
22412
|
exports2.CancelledNotificationParamsSchema = CancelledNotificationParamsSchema;
|
|
20878
22413
|
exports2.CancelledNotificationSchema = CancelledNotificationSchema;
|
|
20879
22414
|
exports2.Client = Client;
|
|
@@ -20881,6 +22416,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20881
22416
|
exports2.ClientNotificationSchema = ClientNotificationSchema;
|
|
20882
22417
|
exports2.ClientRequestSchema = ClientRequestSchema;
|
|
20883
22418
|
exports2.ClientResultSchema = ClientResultSchema;
|
|
22419
|
+
exports2.ClientTasksCapabilitySchema = ClientTasksCapabilitySchema;
|
|
20884
22420
|
exports2.CompatibilityCallToolResultSchema = CompatibilityCallToolResultSchema;
|
|
20885
22421
|
exports2.CompleteRequestParamsSchema = CompleteRequestParamsSchema;
|
|
20886
22422
|
exports2.CompleteRequestSchema = CompleteRequestSchema;
|
|
@@ -20889,6 +22425,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20889
22425
|
exports2.CreateMessageRequestParamsSchema = CreateMessageRequestParamsSchema;
|
|
20890
22426
|
exports2.CreateMessageRequestSchema = CreateMessageRequestSchema;
|
|
20891
22427
|
exports2.CreateMessageResultSchema = CreateMessageResultSchema;
|
|
22428
|
+
exports2.CreateMessageResultWithToolsSchema = CreateMessageResultWithToolsSchema;
|
|
22429
|
+
exports2.CreateTaskResultSchema = CreateTaskResultSchema;
|
|
20892
22430
|
exports2.CursorSchema = CursorSchema;
|
|
20893
22431
|
exports2.DEFAULT_NEGOTIATED_PROTOCOL_VERSION = DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
|
|
20894
22432
|
exports2.DEFAULT_REQUEST_TIMEOUT_MSEC = DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
@@ -20905,6 +22443,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20905
22443
|
exports2.GetPromptRequestParamsSchema = GetPromptRequestParamsSchema;
|
|
20906
22444
|
exports2.GetPromptRequestSchema = GetPromptRequestSchema;
|
|
20907
22445
|
exports2.GetPromptResultSchema = GetPromptResultSchema;
|
|
22446
|
+
exports2.GetTaskPayloadRequestSchema = GetTaskPayloadRequestSchema;
|
|
22447
|
+
exports2.GetTaskPayloadResultSchema = GetTaskPayloadResultSchema;
|
|
22448
|
+
exports2.GetTaskRequestSchema = GetTaskRequestSchema;
|
|
22449
|
+
exports2.GetTaskResultSchema = GetTaskResultSchema;
|
|
20908
22450
|
exports2.IconSchema = IconSchema;
|
|
20909
22451
|
exports2.IconsSchema = IconsSchema;
|
|
20910
22452
|
exports2.ImageContentSchema = ImageContentSchema;
|
|
@@ -20913,14 +22455,17 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20913
22455
|
exports2.InitializeRequestSchema = InitializeRequestSchema;
|
|
20914
22456
|
exports2.InitializeResultSchema = InitializeResultSchema;
|
|
20915
22457
|
exports2.InitializedNotificationSchema = InitializedNotificationSchema;
|
|
22458
|
+
exports2.JSONRPCErrorResponseSchema = JSONRPCErrorResponseSchema;
|
|
20916
22459
|
exports2.JSONRPCErrorSchema = JSONRPCErrorSchema;
|
|
20917
22460
|
exports2.JSONRPCMessageSchema = JSONRPCMessageSchema;
|
|
20918
22461
|
exports2.JSONRPCNotificationSchema = JSONRPCNotificationSchema;
|
|
20919
22462
|
exports2.JSONRPCRequestSchema = JSONRPCRequestSchema;
|
|
20920
22463
|
exports2.JSONRPCResponseSchema = JSONRPCResponseSchema;
|
|
22464
|
+
exports2.JSONRPCResultResponseSchema = JSONRPCResultResponseSchema;
|
|
20921
22465
|
exports2.JSONRPC_VERSION = JSONRPC_VERSION;
|
|
20922
22466
|
exports2.LATEST_PROTOCOL_VERSION = LATEST_PROTOCOL_VERSION;
|
|
20923
22467
|
exports2.LegacyTitledEnumSchemaSchema = LegacyTitledEnumSchemaSchema;
|
|
22468
|
+
exports2.ListChangedOptionsBaseSchema = ListChangedOptionsBaseSchema;
|
|
20924
22469
|
exports2.ListPromptsRequestSchema = ListPromptsRequestSchema;
|
|
20925
22470
|
exports2.ListPromptsResultSchema = ListPromptsResultSchema;
|
|
20926
22471
|
exports2.ListResourceTemplatesRequestSchema = ListResourceTemplatesRequestSchema;
|
|
@@ -20929,6 +22474,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20929
22474
|
exports2.ListResourcesResultSchema = ListResourcesResultSchema;
|
|
20930
22475
|
exports2.ListRootsRequestSchema = ListRootsRequestSchema;
|
|
20931
22476
|
exports2.ListRootsResultSchema = ListRootsResultSchema;
|
|
22477
|
+
exports2.ListTasksRequestSchema = ListTasksRequestSchema;
|
|
22478
|
+
exports2.ListTasksResultSchema = ListTasksResultSchema;
|
|
20932
22479
|
exports2.ListToolsRequestSchema = ListToolsRequestSchema;
|
|
20933
22480
|
exports2.ListToolsResultSchema = ListToolsResultSchema;
|
|
20934
22481
|
exports2.LoggingLevelSchema = LoggingLevelSchema;
|
|
@@ -20956,9 +22503,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20956
22503
|
exports2.PromptReferenceSchema = PromptReferenceSchema;
|
|
20957
22504
|
exports2.PromptSchema = PromptSchema;
|
|
20958
22505
|
exports2.Protocol = Protocol;
|
|
22506
|
+
exports2.RELATED_TASK_META_KEY = RELATED_TASK_META_KEY;
|
|
20959
22507
|
exports2.ReadResourceRequestParamsSchema = ReadResourceRequestParamsSchema;
|
|
20960
22508
|
exports2.ReadResourceRequestSchema = ReadResourceRequestSchema;
|
|
20961
22509
|
exports2.ReadResourceResultSchema = ReadResourceResultSchema;
|
|
22510
|
+
exports2.RelatedTaskMetadataSchema = RelatedTaskMetadataSchema;
|
|
20962
22511
|
exports2.RequestIdSchema = RequestIdSchema;
|
|
20963
22512
|
exports2.RequestSchema = RequestSchema;
|
|
20964
22513
|
exports2.ResourceContentsSchema = ResourceContentsSchema;
|
|
@@ -20973,16 +22522,19 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20973
22522
|
exports2.ResourceUpdatedNotificationParamsSchema = ResourceUpdatedNotificationParamsSchema;
|
|
20974
22523
|
exports2.ResourceUpdatedNotificationSchema = ResourceUpdatedNotificationSchema;
|
|
20975
22524
|
exports2.ResultSchema = ResultSchema;
|
|
22525
|
+
exports2.RoleSchema = RoleSchema;
|
|
20976
22526
|
exports2.RootSchema = RootSchema;
|
|
20977
22527
|
exports2.RootsListChangedNotificationSchema = RootsListChangedNotificationSchema;
|
|
20978
22528
|
exports2.SSEClientTransport = SSEClientTransport;
|
|
20979
22529
|
exports2.SUPPORTED_PROTOCOL_VERSIONS = SUPPORTED_PROTOCOL_VERSIONS;
|
|
22530
|
+
exports2.SamplingContentSchema = SamplingContentSchema;
|
|
20980
22531
|
exports2.SamplingMessageContentBlockSchema = SamplingMessageContentBlockSchema;
|
|
20981
22532
|
exports2.SamplingMessageSchema = SamplingMessageSchema;
|
|
20982
22533
|
exports2.ServerCapabilitiesSchema = ServerCapabilitiesSchema;
|
|
20983
22534
|
exports2.ServerNotificationSchema = ServerNotificationSchema;
|
|
20984
22535
|
exports2.ServerRequestSchema = ServerRequestSchema;
|
|
20985
22536
|
exports2.ServerResultSchema = ServerResultSchema;
|
|
22537
|
+
exports2.ServerTasksCapabilitySchema = ServerTasksCapabilitySchema;
|
|
20986
22538
|
exports2.SetLevelRequestParamsSchema = SetLevelRequestParamsSchema;
|
|
20987
22539
|
exports2.SetLevelRequestSchema = SetLevelRequestSchema;
|
|
20988
22540
|
exports2.SingleSelectEnumSchemaSchema = SingleSelectEnumSchemaSchema;
|
|
@@ -20992,12 +22544,20 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
20992
22544
|
exports2.StringSchemaSchema = StringSchemaSchema;
|
|
20993
22545
|
exports2.SubscribeRequestParamsSchema = SubscribeRequestParamsSchema;
|
|
20994
22546
|
exports2.SubscribeRequestSchema = SubscribeRequestSchema;
|
|
22547
|
+
exports2.TaskAugmentedRequestParamsSchema = TaskAugmentedRequestParamsSchema;
|
|
22548
|
+
exports2.TaskCreationParamsSchema = TaskCreationParamsSchema;
|
|
22549
|
+
exports2.TaskMetadataSchema = TaskMetadataSchema;
|
|
22550
|
+
exports2.TaskSchema = TaskSchema;
|
|
22551
|
+
exports2.TaskStatusNotificationParamsSchema = TaskStatusNotificationParamsSchema;
|
|
22552
|
+
exports2.TaskStatusNotificationSchema = TaskStatusNotificationSchema;
|
|
22553
|
+
exports2.TaskStatusSchema = TaskStatusSchema;
|
|
20995
22554
|
exports2.TextContentSchema = TextContentSchema;
|
|
20996
22555
|
exports2.TextResourceContentsSchema = TextResourceContentsSchema;
|
|
20997
22556
|
exports2.TitledMultiSelectEnumSchemaSchema = TitledMultiSelectEnumSchemaSchema;
|
|
20998
22557
|
exports2.TitledSingleSelectEnumSchemaSchema = TitledSingleSelectEnumSchemaSchema;
|
|
20999
22558
|
exports2.ToolAnnotationsSchema = ToolAnnotationsSchema;
|
|
21000
22559
|
exports2.ToolChoiceSchema = ToolChoiceSchema;
|
|
22560
|
+
exports2.ToolExecutionSchema = ToolExecutionSchema;
|
|
21001
22561
|
exports2.ToolListChangedNotificationSchema = ToolListChangedNotificationSchema;
|
|
21002
22562
|
exports2.ToolResultContentSchema = ToolResultContentSchema;
|
|
21003
22563
|
exports2.ToolSchema = ToolSchema;
|
|
@@ -21021,6 +22581,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
21021
22581
|
exports2.exchangeAuthorization = exchangeAuthorization;
|
|
21022
22582
|
exports2.extractResourceMetadataUrl = extractResourceMetadataUrl;
|
|
21023
22583
|
exports2.extractWWWAuthenticateParams = extractWWWAuthenticateParams;
|
|
22584
|
+
exports2.fetchToken = fetchToken;
|
|
21024
22585
|
exports2.getCompleter = getCompleter;
|
|
21025
22586
|
exports2.getDisplayName = getDisplayName;
|
|
21026
22587
|
exports2.getSupportedElicitationModes = getSupportedElicitationModes;
|
|
@@ -21029,12 +22590,16 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
21029
22590
|
exports2.isInitializeRequest = isInitializeRequest;
|
|
21030
22591
|
exports2.isInitializedNotification = isInitializedNotification;
|
|
21031
22592
|
exports2.isJSONRPCError = isJSONRPCError;
|
|
22593
|
+
exports2.isJSONRPCErrorResponse = isJSONRPCErrorResponse;
|
|
21032
22594
|
exports2.isJSONRPCNotification = isJSONRPCNotification;
|
|
21033
22595
|
exports2.isJSONRPCRequest = isJSONRPCRequest;
|
|
21034
22596
|
exports2.isJSONRPCResponse = isJSONRPCResponse;
|
|
22597
|
+
exports2.isJSONRPCResultResponse = isJSONRPCResultResponse;
|
|
22598
|
+
exports2.isTaskAugmentedRequestParams = isTaskAugmentedRequestParams;
|
|
21035
22599
|
exports2.mergeCapabilities = mergeCapabilities;
|
|
21036
22600
|
exports2.normalizeHeaders = normalizeHeaders;
|
|
21037
22601
|
exports2.parseErrorResponse = parseErrorResponse;
|
|
22602
|
+
exports2.prepareAuthorizationCodeRequest = prepareAuthorizationCodeRequest;
|
|
21038
22603
|
exports2.refreshAuthorization = refreshAuthorization;
|
|
21039
22604
|
exports2.registerClient = registerClient;
|
|
21040
22605
|
exports2.selectClientAuthMethod = selectClientAuthMethod;
|