@mastra/mcp 1.15.1 → 1.16.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -0
- package/dist/client/actions/elicitation.d.ts +1 -1
- package/dist/client/actions/elicitation.d.ts.map +1 -1
- package/dist/client/actions/progress.d.ts +1 -1
- package/dist/client/actions/progress.d.ts.map +1 -1
- package/dist/client/actions/prompt.d.ts +1 -1
- package/dist/client/actions/prompt.d.ts.map +1 -1
- package/dist/client/actions/resource.d.ts +38 -11
- package/dist/client/actions/resource.d.ts.map +1 -1
- package/dist/client/client.d.ts +3 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +50 -14
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/client/types.d.ts +65 -10
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/url-policy.d.ts +67 -0
- package/dist/client/url-policy.d.ts.map +1 -0
- package/dist/docs/SKILL.md +3 -3
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-connections-overview.md +94 -0
- package/dist/docs/references/docs-mcp-overview.md +229 -278
- package/dist/docs/references/reference-tools-mcp-client.md +54 -0
- package/dist/docs/references/reference-tools-mcp-server.md +1 -1
- package/dist/index.cjs +2435 -275
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2403 -243
- package/dist/index.js.map +1 -1
- package/dist/server/__tests__/mock-extra.d.ts +15 -0
- package/dist/server/__tests__/mock-extra.d.ts.map +1 -0
- package/dist/server/notificationBroadcast.d.ts +1 -1
- package/dist/server/notificationBroadcast.d.ts.map +1 -1
- package/dist/server/promptActions.d.ts +1 -1
- package/dist/server/promptActions.d.ts.map +1 -1
- package/dist/server/resourceActions.d.ts +1 -1
- package/dist/server/resourceActions.d.ts.map +1 -1
- package/dist/server/server.d.ts +10 -12
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/toolActions.d.ts +1 -1
- package/dist/server/toolActions.d.ts.map +1 -1
- package/dist/server/types.d.ts +7 -7
- package/dist/server/types.d.ts.map +1 -1
- package/dist/shared/oauth-types.d.ts +8 -6
- package/dist/shared/oauth-types.d.ts.map +1 -1
- package/package.json +18 -14
- package/dist/docs/references/docs-mcp-mcp-apps.md +0 -306
package/dist/index.cjs
CHANGED
|
@@ -35,14 +35,9 @@ let module$1 = require("module");
|
|
|
35
35
|
let _mastra_core_base = require("@mastra/core/base");
|
|
36
36
|
let _mastra_core_error = require("@mastra/core/error");
|
|
37
37
|
let _mastra_core_tools = require("@mastra/core/tools");
|
|
38
|
-
let
|
|
39
|
-
let
|
|
40
|
-
let _modelcontextprotocol_sdk_client_stdio_js = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
41
|
-
let _modelcontextprotocol_sdk_client_streamableHttp_js = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
42
|
-
let _modelcontextprotocol_sdk_shared_protocol_js = require("@modelcontextprotocol/sdk/shared/protocol.js");
|
|
43
|
-
let _modelcontextprotocol_sdk_types_js = require("@modelcontextprotocol/sdk/types.js");
|
|
38
|
+
let _modelcontextprotocol_client = require("@modelcontextprotocol/client");
|
|
39
|
+
let _modelcontextprotocol_client_stdio = require("@modelcontextprotocol/client/stdio");
|
|
44
40
|
let exit_hook = require("exit-hook");
|
|
45
|
-
let _modelcontextprotocol_sdk_client_auth_js = require("@modelcontextprotocol/sdk/client/auth.js");
|
|
46
41
|
let crypto$1 = require("crypto");
|
|
47
42
|
let fast_deep_equal = require("fast-deep-equal");
|
|
48
43
|
fast_deep_equal = __toESM$2(fast_deep_equal, 1);
|
|
@@ -52,11 +47,12 @@ let _mastra_core_schema = require("@mastra/core/schema");
|
|
|
52
47
|
let fs = require("fs");
|
|
53
48
|
let _mastra_core_request_context = require("@mastra/core/request-context");
|
|
54
49
|
let _mastra_core_utils = require("@mastra/core/utils");
|
|
50
|
+
let _modelcontextprotocol_core = require("@modelcontextprotocol/core");
|
|
55
51
|
let _modelcontextprotocol_ext_apps = require("@modelcontextprotocol/ext-apps");
|
|
56
|
-
let
|
|
57
|
-
let
|
|
58
|
-
let
|
|
59
|
-
let
|
|
52
|
+
let _modelcontextprotocol_node = require("@modelcontextprotocol/node");
|
|
53
|
+
let _modelcontextprotocol_server = require("@modelcontextprotocol/server");
|
|
54
|
+
let _modelcontextprotocol_server_stdio = require("@modelcontextprotocol/server/stdio");
|
|
55
|
+
let _modelcontextprotocol_server_legacy_sse = require("@modelcontextprotocol/server-legacy/sse");
|
|
60
56
|
//#region ../schema-compat/dist/json-schema-traverse-B35mHRM8.js
|
|
61
57
|
var __create$1 = Object.create;
|
|
62
58
|
var __defProp$2 = Object.defineProperty;
|
|
@@ -2011,6 +2007,62 @@ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
|
|
|
2011
2007
|
});
|
|
2012
2008
|
};
|
|
2013
2009
|
});
|
|
2010
|
+
const $ZodDiscriminatedUnion = /*@__PURE__*/ $constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
|
2011
|
+
def.inclusive = false;
|
|
2012
|
+
$ZodUnion.init(inst, def);
|
|
2013
|
+
const _super = inst._zod.parse;
|
|
2014
|
+
defineLazy(inst._zod, "propValues", () => {
|
|
2015
|
+
const propValues = {};
|
|
2016
|
+
for (const option of def.options) {
|
|
2017
|
+
const pv = option._zod.propValues;
|
|
2018
|
+
if (!pv || Object.keys(pv).length === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
2019
|
+
for (const [k, v] of Object.entries(pv)) {
|
|
2020
|
+
if (!propValues[k]) propValues[k] = /* @__PURE__ */ new Set();
|
|
2021
|
+
for (const val of v) propValues[k].add(val);
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
return propValues;
|
|
2025
|
+
});
|
|
2026
|
+
const disc = cached(() => {
|
|
2027
|
+
const opts = def.options;
|
|
2028
|
+
const map = /* @__PURE__ */ new Map();
|
|
2029
|
+
for (const o of opts) {
|
|
2030
|
+
const values = o._zod.propValues?.[def.discriminator];
|
|
2031
|
+
if (!values || values.size === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
|
|
2032
|
+
for (const v of values) {
|
|
2033
|
+
if (map.has(v)) throw new Error(`Duplicate discriminator value "${String(v)}"`);
|
|
2034
|
+
map.set(v, o);
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
return map;
|
|
2038
|
+
});
|
|
2039
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2040
|
+
const input = payload.value;
|
|
2041
|
+
if (!isObject(input)) {
|
|
2042
|
+
payload.issues.push({
|
|
2043
|
+
code: "invalid_type",
|
|
2044
|
+
expected: "object",
|
|
2045
|
+
input,
|
|
2046
|
+
inst
|
|
2047
|
+
});
|
|
2048
|
+
return payload;
|
|
2049
|
+
}
|
|
2050
|
+
const opt = disc.value.get(input?.[def.discriminator]);
|
|
2051
|
+
if (opt) return opt._zod.run(payload, ctx);
|
|
2052
|
+
if (def.unionFallback || ctx.direction === "backward") return _super(payload, ctx);
|
|
2053
|
+
payload.issues.push({
|
|
2054
|
+
code: "invalid_union",
|
|
2055
|
+
errors: [],
|
|
2056
|
+
note: "No matching discriminator",
|
|
2057
|
+
discriminator: def.discriminator,
|
|
2058
|
+
options: Array.from(disc.value.keys()),
|
|
2059
|
+
input,
|
|
2060
|
+
path: [def.discriminator],
|
|
2061
|
+
inst
|
|
2062
|
+
});
|
|
2063
|
+
return payload;
|
|
2064
|
+
};
|
|
2065
|
+
});
|
|
2014
2066
|
const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
|
|
2015
2067
|
$ZodType.init(inst, def);
|
|
2016
2068
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -2546,6 +2598,9 @@ function handlePipeResult(left, next, ctx) {
|
|
|
2546
2598
|
fallback: left.fallback
|
|
2547
2599
|
}, ctx);
|
|
2548
2600
|
}
|
|
2601
|
+
const $ZodPreprocess = /*@__PURE__*/ $constructor("$ZodPreprocess", (inst, def) => {
|
|
2602
|
+
$ZodPipe.init(inst, def);
|
|
2603
|
+
});
|
|
2549
2604
|
const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
|
|
2550
2605
|
$ZodType.init(inst, def);
|
|
2551
2606
|
defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
@@ -4565,6 +4620,14 @@ function object$1(shape, params) {
|
|
|
4565
4620
|
};
|
|
4566
4621
|
return new ZodObject$1(def);
|
|
4567
4622
|
}
|
|
4623
|
+
function looseObject(shape, params) {
|
|
4624
|
+
return new ZodObject$1({
|
|
4625
|
+
type: "object",
|
|
4626
|
+
shape,
|
|
4627
|
+
catchall: unknown(),
|
|
4628
|
+
...normalizeParams(params)
|
|
4629
|
+
});
|
|
4630
|
+
}
|
|
4568
4631
|
const ZodUnion$1 = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
|
|
4569
4632
|
$ZodUnion.init(inst, def);
|
|
4570
4633
|
ZodType$1.init(inst, def);
|
|
@@ -4578,6 +4641,18 @@ function union(options, params) {
|
|
|
4578
4641
|
...normalizeParams(params)
|
|
4579
4642
|
});
|
|
4580
4643
|
}
|
|
4644
|
+
const ZodDiscriminatedUnion$1 = /*@__PURE__*/ $constructor("ZodDiscriminatedUnion", (inst, def) => {
|
|
4645
|
+
ZodUnion$1.init(inst, def);
|
|
4646
|
+
$ZodDiscriminatedUnion.init(inst, def);
|
|
4647
|
+
});
|
|
4648
|
+
function discriminatedUnion(discriminator, options, params) {
|
|
4649
|
+
return new ZodDiscriminatedUnion$1({
|
|
4650
|
+
type: "union",
|
|
4651
|
+
options,
|
|
4652
|
+
discriminator,
|
|
4653
|
+
...normalizeParams(params)
|
|
4654
|
+
});
|
|
4655
|
+
}
|
|
4581
4656
|
const ZodIntersection$1 = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
|
|
4582
4657
|
$ZodIntersection.init(inst, def);
|
|
4583
4658
|
ZodType$1.init(inst, def);
|
|
@@ -4837,6 +4912,10 @@ function pipe(in_, out) {
|
|
|
4837
4912
|
out
|
|
4838
4913
|
});
|
|
4839
4914
|
}
|
|
4915
|
+
const ZodPreprocess = /*@__PURE__*/ $constructor("ZodPreprocess", (inst, def) => {
|
|
4916
|
+
ZodPipe.init(inst, def);
|
|
4917
|
+
$ZodPreprocess.init(inst, def);
|
|
4918
|
+
});
|
|
4840
4919
|
const ZodReadonly$1 = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
|
|
4841
4920
|
$ZodReadonly.init(inst, def);
|
|
4842
4921
|
ZodType$1.init(inst, def);
|
|
@@ -4895,6 +4974,13 @@ function _instanceof(cls, params = {}) {
|
|
|
4895
4974
|
};
|
|
4896
4975
|
return inst;
|
|
4897
4976
|
}
|
|
4977
|
+
function preprocess(fn, schema) {
|
|
4978
|
+
return new ZodPreprocess({
|
|
4979
|
+
type: "pipe",
|
|
4980
|
+
in: transform(fn),
|
|
4981
|
+
out: schema
|
|
4982
|
+
});
|
|
4983
|
+
}
|
|
4898
4984
|
//#endregion
|
|
4899
4985
|
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod-to-json-schema/3.25.2/e44095b6546ec71c6bc64e08880b3fed52703321484b7225302b788f83667662/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
4900
4986
|
const ignoreOverride$1 = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
@@ -20412,12 +20498,12 @@ var ClientOrServerImplementationSchema = object$1({
|
|
|
20412
20498
|
version: string()
|
|
20413
20499
|
}).passthrough();
|
|
20414
20500
|
var BaseParamsSchema = object$1({ _meta: optional(object$1({}).passthrough()) }).passthrough();
|
|
20415
|
-
var ResultSchema = BaseParamsSchema;
|
|
20416
|
-
var RequestSchema = object$1({
|
|
20501
|
+
var ResultSchema$1 = BaseParamsSchema;
|
|
20502
|
+
var RequestSchema$1 = object$1({
|
|
20417
20503
|
method: string(),
|
|
20418
20504
|
params: optional(BaseParamsSchema)
|
|
20419
20505
|
});
|
|
20420
|
-
var ServerCapabilitiesSchema = object$1({
|
|
20506
|
+
var ServerCapabilitiesSchema$1 = object$1({
|
|
20421
20507
|
experimental: optional(object$1({}).passthrough()),
|
|
20422
20508
|
logging: optional(object$1({}).passthrough()),
|
|
20423
20509
|
prompts: optional(object$1({ listChanged: optional(boolean()) }).passthrough()),
|
|
@@ -20427,14 +20513,14 @@ var ServerCapabilitiesSchema = object$1({
|
|
|
20427
20513
|
}).passthrough()),
|
|
20428
20514
|
tools: optional(object$1({ listChanged: optional(boolean()) }).passthrough())
|
|
20429
20515
|
}).passthrough();
|
|
20430
|
-
ResultSchema.extend({
|
|
20516
|
+
ResultSchema$1.extend({
|
|
20431
20517
|
protocolVersion: string(),
|
|
20432
|
-
capabilities: ServerCapabilitiesSchema,
|
|
20518
|
+
capabilities: ServerCapabilitiesSchema$1,
|
|
20433
20519
|
serverInfo: ClientOrServerImplementationSchema,
|
|
20434
20520
|
instructions: optional(string())
|
|
20435
20521
|
});
|
|
20436
|
-
var PaginatedResultSchema = ResultSchema.extend({ nextCursor: optional(string()) });
|
|
20437
|
-
var ToolSchema = object$1({
|
|
20522
|
+
var PaginatedResultSchema$1 = ResultSchema$1.extend({ nextCursor: optional(string()) });
|
|
20523
|
+
var ToolSchema$1 = object$1({
|
|
20438
20524
|
name: string(),
|
|
20439
20525
|
description: optional(string()),
|
|
20440
20526
|
inputSchema: object$1({
|
|
@@ -20442,17 +20528,17 @@ var ToolSchema = object$1({
|
|
|
20442
20528
|
properties: optional(object$1({}).passthrough())
|
|
20443
20529
|
}).passthrough()
|
|
20444
20530
|
}).passthrough();
|
|
20445
|
-
PaginatedResultSchema.extend({ tools: array(ToolSchema) });
|
|
20446
|
-
var TextContentSchema = object$1({
|
|
20531
|
+
PaginatedResultSchema$1.extend({ tools: array(ToolSchema$1) });
|
|
20532
|
+
var TextContentSchema$1 = object$1({
|
|
20447
20533
|
type: literal("text"),
|
|
20448
20534
|
text: string()
|
|
20449
20535
|
}).passthrough();
|
|
20450
|
-
var ImageContentSchema = object$1({
|
|
20536
|
+
var ImageContentSchema$1 = object$1({
|
|
20451
20537
|
type: literal("image"),
|
|
20452
20538
|
data: string().base64(),
|
|
20453
20539
|
mimeType: string()
|
|
20454
20540
|
}).passthrough();
|
|
20455
|
-
var ResourceContentsSchema = object$1({
|
|
20541
|
+
var ResourceContentsSchema$1 = object$1({
|
|
20456
20542
|
/**
|
|
20457
20543
|
* The URI of this resource.
|
|
20458
20544
|
*/
|
|
@@ -20462,32 +20548,32 @@ var ResourceContentsSchema = object$1({
|
|
|
20462
20548
|
*/
|
|
20463
20549
|
mimeType: optional(string())
|
|
20464
20550
|
}).passthrough();
|
|
20465
|
-
var TextResourceContentsSchema = ResourceContentsSchema.extend({ text: string() });
|
|
20466
|
-
var BlobResourceContentsSchema = ResourceContentsSchema.extend({ blob: string().base64() });
|
|
20467
|
-
var EmbeddedResourceSchema = object$1({
|
|
20551
|
+
var TextResourceContentsSchema$1 = ResourceContentsSchema$1.extend({ text: string() });
|
|
20552
|
+
var BlobResourceContentsSchema$1 = ResourceContentsSchema$1.extend({ blob: string().base64() });
|
|
20553
|
+
var EmbeddedResourceSchema$1 = object$1({
|
|
20468
20554
|
type: literal("resource"),
|
|
20469
|
-
resource: union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
|
20555
|
+
resource: union([TextResourceContentsSchema$1, BlobResourceContentsSchema$1])
|
|
20470
20556
|
}).passthrough();
|
|
20471
|
-
ResultSchema.extend({
|
|
20557
|
+
ResultSchema$1.extend({
|
|
20472
20558
|
content: array(union([
|
|
20473
|
-
TextContentSchema,
|
|
20474
|
-
ImageContentSchema,
|
|
20475
|
-
EmbeddedResourceSchema
|
|
20559
|
+
TextContentSchema$1,
|
|
20560
|
+
ImageContentSchema$1,
|
|
20561
|
+
EmbeddedResourceSchema$1
|
|
20476
20562
|
])),
|
|
20477
20563
|
isError: boolean().default(false).optional()
|
|
20478
|
-
}).or(ResultSchema.extend({ toolResult: unknown() }));
|
|
20479
|
-
var JSONRPC_VERSION = "2.0";
|
|
20480
|
-
var JSONRPCRequestSchema = object$1({
|
|
20481
|
-
jsonrpc: literal(JSONRPC_VERSION),
|
|
20564
|
+
}).or(ResultSchema$1.extend({ toolResult: unknown() }));
|
|
20565
|
+
var JSONRPC_VERSION$1 = "2.0";
|
|
20566
|
+
var JSONRPCRequestSchema$1 = object$1({
|
|
20567
|
+
jsonrpc: literal(JSONRPC_VERSION$1),
|
|
20482
20568
|
id: union([string(), number().int()])
|
|
20483
|
-
}).merge(RequestSchema).strict();
|
|
20484
|
-
var JSONRPCResponseSchema = object$1({
|
|
20485
|
-
jsonrpc: literal(JSONRPC_VERSION),
|
|
20569
|
+
}).merge(RequestSchema$1).strict();
|
|
20570
|
+
var JSONRPCResponseSchema$1 = object$1({
|
|
20571
|
+
jsonrpc: literal(JSONRPC_VERSION$1),
|
|
20486
20572
|
id: union([string(), number().int()]),
|
|
20487
|
-
result: ResultSchema
|
|
20573
|
+
result: ResultSchema$1
|
|
20488
20574
|
}).strict();
|
|
20489
20575
|
var JSONRPCErrorSchema = object$1({
|
|
20490
|
-
jsonrpc: literal(JSONRPC_VERSION),
|
|
20576
|
+
jsonrpc: literal(JSONRPC_VERSION$1),
|
|
20491
20577
|
id: union([string(), number().int()]),
|
|
20492
20578
|
error: object$1({
|
|
20493
20579
|
code: number().int(),
|
|
@@ -20496,12 +20582,12 @@ var JSONRPCErrorSchema = object$1({
|
|
|
20496
20582
|
})
|
|
20497
20583
|
}).strict();
|
|
20498
20584
|
union([
|
|
20499
|
-
JSONRPCRequestSchema,
|
|
20500
|
-
object$1({ jsonrpc: literal(JSONRPC_VERSION) }).merge(object$1({
|
|
20585
|
+
JSONRPCRequestSchema$1,
|
|
20586
|
+
object$1({ jsonrpc: literal(JSONRPC_VERSION$1) }).merge(object$1({
|
|
20501
20587
|
method: string(),
|
|
20502
20588
|
params: optional(BaseParamsSchema)
|
|
20503
20589
|
})).strict(),
|
|
20504
|
-
JSONRPCResponseSchema,
|
|
20590
|
+
JSONRPCResponseSchema$1,
|
|
20505
20591
|
JSONRPCErrorSchema
|
|
20506
20592
|
]);
|
|
20507
20593
|
__export({}, {
|
|
@@ -20824,7 +20910,7 @@ var PromptClientActions = class {
|
|
|
20824
20910
|
return [];
|
|
20825
20911
|
}
|
|
20826
20912
|
} catch (e) {
|
|
20827
|
-
if (e.code ===
|
|
20913
|
+
if (e.code === _modelcontextprotocol_client.ProtocolErrorCode.MethodNotFound) return [];
|
|
20828
20914
|
this.logger.error("Error getting prompts from server", {
|
|
20829
20915
|
server: this.client.name,
|
|
20830
20916
|
error: e instanceof Error ? e.message : String(e)
|
|
@@ -20931,7 +21017,7 @@ var ResourceClientActions = class {
|
|
|
20931
21017
|
return [];
|
|
20932
21018
|
}
|
|
20933
21019
|
} catch (e) {
|
|
20934
|
-
if (e.code ===
|
|
21020
|
+
if (e.code === _modelcontextprotocol_client.ProtocolErrorCode.MethodNotFound) return [];
|
|
20935
21021
|
this.logger.error("Error getting resources from server", {
|
|
20936
21022
|
server: this.client.name,
|
|
20937
21023
|
error: e instanceof Error ? e.message : String(e)
|
|
@@ -20968,7 +21054,7 @@ var ResourceClientActions = class {
|
|
|
20968
21054
|
return [];
|
|
20969
21055
|
}
|
|
20970
21056
|
} catch (e) {
|
|
20971
|
-
if (e.code ===
|
|
21057
|
+
if (e.code === _modelcontextprotocol_client.ProtocolErrorCode.MethodNotFound) return [];
|
|
20972
21058
|
this.logger.error("Error getting resource templates from server", {
|
|
20973
21059
|
server: this.client.name,
|
|
20974
21060
|
error: e instanceof Error ? e.message : String(e)
|
|
@@ -21076,6 +21162,202 @@ function isReconnectableMCPError(error) {
|
|
|
21076
21162
|
return errorMessage.includes("no valid session") || errorMessage.includes("session") || errorMessage.includes("server not initialized") || errorMessage.includes("not connected") || errorMessage.includes("http 400") || errorMessage.includes("http 401") || errorMessage.includes("http 403") || errorMessage.includes("http 404") || errorMessage.includes("econnrefused") || errorMessage.includes("fetch failed") || errorMessage.includes("connection refused") || errorMessage.includes("connection closed") || errorMessage.includes("sse stream disconnected") || errorMessage.includes("typeerror: terminated");
|
|
21077
21163
|
}
|
|
21078
21164
|
//#endregion
|
|
21165
|
+
//#region src/client/url-policy.ts
|
|
21166
|
+
/**
|
|
21167
|
+
* Redirect status codes the manual redirect loop follows. Other 3xx statuses
|
|
21168
|
+
* (e.g. 304) are not redirects and are returned to the caller as-is.
|
|
21169
|
+
*/
|
|
21170
|
+
const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
|
|
21171
|
+
301,
|
|
21172
|
+
302,
|
|
21173
|
+
303,
|
|
21174
|
+
307,
|
|
21175
|
+
308
|
|
21176
|
+
]);
|
|
21177
|
+
/** Maximum number of redirect hops followed before failing. */
|
|
21178
|
+
const MAX_REDIRECT_HOPS = 5;
|
|
21179
|
+
function normalizeHost(host) {
|
|
21180
|
+
return host.toLowerCase();
|
|
21181
|
+
}
|
|
21182
|
+
/** Best-effort release of a discarded response body so its socket is not left undrained. */
|
|
21183
|
+
function cancelResponseBody(response) {
|
|
21184
|
+
const body = response.body;
|
|
21185
|
+
if (typeof body?.cancel !== "function") return;
|
|
21186
|
+
try {
|
|
21187
|
+
Promise.resolve(body.cancel()).catch(() => {});
|
|
21188
|
+
} catch {}
|
|
21189
|
+
}
|
|
21190
|
+
function isHostAllowed(host, allowedHosts) {
|
|
21191
|
+
const normalized = normalizeHost(host);
|
|
21192
|
+
return allowedHosts.some((allowed) => normalizeHost(allowed) === normalized);
|
|
21193
|
+
}
|
|
21194
|
+
/**
|
|
21195
|
+
* Marker phrase embedded in every policy error's message. The `eventsource`
|
|
21196
|
+
* package flattens errors thrown from the SSE stream's fetch into a plain
|
|
21197
|
+
* message string (its internal `flattenError`), and the SDK re-wraps that
|
|
21198
|
+
* string as `SseError` — the `MastraError` identity does not survive that
|
|
21199
|
+
* boundary, but the message text does. {@link isUrlPolicyError} falls back to
|
|
21200
|
+
* matching this marker.
|
|
21201
|
+
*/
|
|
21202
|
+
const URL_POLICY_ERROR_MARKER = "allowedHosts policy";
|
|
21203
|
+
/**
|
|
21204
|
+
* Build the policy-violation error. The message deliberately avoids every
|
|
21205
|
+
* substring matched by `isReconnectableMCPError` (see ./error-utils.ts) so a
|
|
21206
|
+
* policy violation is never treated as a transient transport failure and fed
|
|
21207
|
+
* into the reconnect machinery — a blocked host must not be retried.
|
|
21208
|
+
*/
|
|
21209
|
+
function hostNotAllowedError(host, allowedHosts, detail) {
|
|
21210
|
+
const allowedList = allowedHosts.length > 0 ? allowedHosts.map((h) => `"${h}"`).join(", ") : "(empty list — all hosts are denied)";
|
|
21211
|
+
return new _mastra_core_error.MastraError({
|
|
21212
|
+
id: "MCP_CLIENT_HOST_NOT_ALLOWED",
|
|
21213
|
+
domain: _mastra_core_error.ErrorDomain.MCP,
|
|
21214
|
+
category: _mastra_core_error.ErrorCategory.USER,
|
|
21215
|
+
text: `Host "${host}" is blocked by the allowedHosts policy. Allowed hosts: ${allowedList}. ${detail}`,
|
|
21216
|
+
details: {
|
|
21217
|
+
host,
|
|
21218
|
+
allowedHosts: allowedHosts.join(",")
|
|
21219
|
+
}
|
|
21220
|
+
});
|
|
21221
|
+
}
|
|
21222
|
+
/**
|
|
21223
|
+
* Assert that the URL's host is in the allowlist.
|
|
21224
|
+
*
|
|
21225
|
+
* Matching is exact and case-insensitive against `URL.host` (hostname plus
|
|
21226
|
+
* port when the URL carries a non-default port — WHATWG URL elides default
|
|
21227
|
+
* ports, so `https://x.com:443` has host `x.com`). No wildcards. An empty
|
|
21228
|
+
* allowlist denies every host. The URL scheme is not checked.
|
|
21229
|
+
*
|
|
21230
|
+
* @returns the parsed URL, for callers that need it.
|
|
21231
|
+
* @throws {MastraError} `MCP_CLIENT_HOST_NOT_ALLOWED` when the host is not allowed.
|
|
21232
|
+
*/
|
|
21233
|
+
function assertHostAllowed(url, allowedHosts, detail = "The request was not sent.") {
|
|
21234
|
+
const parsed = typeof url === "string" ? new URL(url) : url;
|
|
21235
|
+
if (!isHostAllowed(parsed.host, allowedHosts)) throw hostNotAllowedError(parsed.host, allowedHosts, detail);
|
|
21236
|
+
return parsed;
|
|
21237
|
+
}
|
|
21238
|
+
/**
|
|
21239
|
+
* Post-hoc validation for responses produced by a caller-supplied fetch.
|
|
21240
|
+
*
|
|
21241
|
+
* A custom fetch may auto-follow redirects, so the final URL can differ from
|
|
21242
|
+
* the (already validated) request URL. When `response.url` lands on a
|
|
21243
|
+
* disallowed host the response is discarded by throwing — the outbound hop
|
|
21244
|
+
* already happened, but the data never reaches the caller or the model.
|
|
21245
|
+
*
|
|
21246
|
+
* Limitation (fail-open by design): a hand-built or proxied `Response` with an
|
|
21247
|
+
* empty `response.url` skips this check, because custom fetch implementations
|
|
21248
|
+
* legitimately construct such responses.
|
|
21249
|
+
*/
|
|
21250
|
+
function assertResponseHostAllowed(response, allowedHosts) {
|
|
21251
|
+
if (!response.url) return response;
|
|
21252
|
+
const parsed = new URL(response.url);
|
|
21253
|
+
if (!isHostAllowed(parsed.host, allowedHosts)) {
|
|
21254
|
+
cancelResponseBody(response);
|
|
21255
|
+
throw hostNotAllowedError(parsed.host, allowedHosts, "A custom fetch implementation followed a redirect to this host; the response was discarded.");
|
|
21256
|
+
}
|
|
21257
|
+
return response;
|
|
21258
|
+
}
|
|
21259
|
+
/**
|
|
21260
|
+
* True when the error is one of the allowedHosts policy errors. Policy
|
|
21261
|
+
* violations are final: they must never trigger the SSE fallback or the
|
|
21262
|
+
* reconnect machinery, because retrying a blocked host cannot succeed.
|
|
21263
|
+
*
|
|
21264
|
+
* Matches by `MastraError` id when the identity is intact, and by the
|
|
21265
|
+
* {@link URL_POLICY_ERROR_MARKER} message marker for errors that crossed the
|
|
21266
|
+
* eventsource boundary (which flattens thrown errors to message strings) or
|
|
21267
|
+
* were re-wrapped by another layer.
|
|
21268
|
+
*/
|
|
21269
|
+
const URL_POLICY_ERROR_IDS = /* @__PURE__ */ new Set([
|
|
21270
|
+
"MCP_CLIENT_HOST_NOT_ALLOWED",
|
|
21271
|
+
"MCP_CLIENT_TOO_MANY_REDIRECTS",
|
|
21272
|
+
"MCP_CLIENT_REDIRECT_MISSING_LOCATION",
|
|
21273
|
+
"MCP_CLIENT_REDIRECT_BODY_NOT_REPLAYABLE"
|
|
21274
|
+
]);
|
|
21275
|
+
function isUrlPolicyError(error) {
|
|
21276
|
+
if (!(error instanceof Error)) return false;
|
|
21277
|
+
if (error instanceof _mastra_core_error.MastraError && URL_POLICY_ERROR_IDS.has(error.id)) return true;
|
|
21278
|
+
return error.message.includes(URL_POLICY_ERROR_MARKER);
|
|
21279
|
+
}
|
|
21280
|
+
/**
|
|
21281
|
+
* Wrap a caller-supplied fetch with the allowedHosts policy: the request URL is
|
|
21282
|
+
* validated before the wrapped fetch runs, and the response is validated
|
|
21283
|
+
* post-hoc via {@link assertResponseHostAllowed}.
|
|
21284
|
+
*
|
|
21285
|
+
* Variadic over the trailing arguments deliberately: the same wrapper serves
|
|
21286
|
+
* the 3-arg `MastraFetchLike` (url, init, requestContext) and the 2-arg
|
|
21287
|
+
* eventsource stream fetch (url, init).
|
|
21288
|
+
*/
|
|
21289
|
+
function wrapFetchWithHostPolicy(fetchImpl, allowedHosts) {
|
|
21290
|
+
return async (...args) => {
|
|
21291
|
+
assertHostAllowed(args[0], allowedHosts);
|
|
21292
|
+
return assertResponseHostAllowed(await fetchImpl(...args), allowedHosts);
|
|
21293
|
+
};
|
|
21294
|
+
}
|
|
21295
|
+
/**
|
|
21296
|
+
* Fetch with manual redirect handling so every redirect hop is validated
|
|
21297
|
+
* against the allowlist BEFORE the hop request is sent. Platform fetch follows
|
|
21298
|
+
* redirects transparently, which would bypass a per-call host check.
|
|
21299
|
+
*
|
|
21300
|
+
* Semantics follow platform conventions:
|
|
21301
|
+
* - `Location` is resolved against the current hop's URL (relative Locations are legal).
|
|
21302
|
+
* - 303 switches the method to GET and drops the body; 301/302 on POST do the same.
|
|
21303
|
+
* - 307/308 preserve method and body; a non-replayable body (anything other
|
|
21304
|
+
* than a string) throws rather than silently re-sending an empty body.
|
|
21305
|
+
* - 301/302 on non-POST methods preserve the method and body, matching
|
|
21306
|
+
* platform behavior.
|
|
21307
|
+
* - The `Authorization` header is not carried across hops to a different
|
|
21308
|
+
* origin (scheme, host, or port change), matching the WHATWG Fetch
|
|
21309
|
+
* credential-stripping rule — same host over a downgraded scheme still
|
|
21310
|
+
* drops the header.
|
|
21311
|
+
* - A redirect status with no `Location` header throws.
|
|
21312
|
+
* - More than {@link MAX_REDIRECT_HOPS} hops throws.
|
|
21313
|
+
*/
|
|
21314
|
+
async function fetchFollowingAllowedRedirects(fetchImpl, url, init, allowedHosts) {
|
|
21315
|
+
let currentUrl = assertHostAllowed(url, allowedHosts);
|
|
21316
|
+
let method = init?.method ?? "GET";
|
|
21317
|
+
let body = init?.body;
|
|
21318
|
+
const headers = new Headers(init?.headers);
|
|
21319
|
+
for (let redirectsFollowed = 0;; redirectsFollowed++) {
|
|
21320
|
+
const response = await fetchImpl(currentUrl, {
|
|
21321
|
+
...init,
|
|
21322
|
+
method,
|
|
21323
|
+
body,
|
|
21324
|
+
headers,
|
|
21325
|
+
redirect: "manual"
|
|
21326
|
+
});
|
|
21327
|
+
if (!REDIRECT_STATUS_CODES.has(response.status)) return response;
|
|
21328
|
+
const location = response.headers.get("location");
|
|
21329
|
+
if (!location) throw new _mastra_core_error.MastraError({
|
|
21330
|
+
id: "MCP_CLIENT_REDIRECT_MISSING_LOCATION",
|
|
21331
|
+
domain: _mastra_core_error.ErrorDomain.MCP,
|
|
21332
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
21333
|
+
text: `Received a ${response.status} redirect with no Location header from "${currentUrl.host}" while following redirects under the allowedHosts policy.`
|
|
21334
|
+
});
|
|
21335
|
+
if (redirectsFollowed >= MAX_REDIRECT_HOPS) throw new _mastra_core_error.MastraError({
|
|
21336
|
+
id: "MCP_CLIENT_TOO_MANY_REDIRECTS",
|
|
21337
|
+
domain: _mastra_core_error.ErrorDomain.MCP,
|
|
21338
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
21339
|
+
text: `Exceeded the maximum of ${MAX_REDIRECT_HOPS} redirect hops while requesting host "${currentUrl.host}" under the allowedHosts policy.`
|
|
21340
|
+
});
|
|
21341
|
+
cancelResponseBody(response);
|
|
21342
|
+
const nextUrl = new URL(location, currentUrl);
|
|
21343
|
+
assertHostAllowed(nextUrl, allowedHosts, `A redirect from "${currentUrl.host}" pointed at it; the hop was not followed.`);
|
|
21344
|
+
const methodUpper = method.toUpperCase();
|
|
21345
|
+
if (response.status === 303 || (response.status === 301 || response.status === 302) && methodUpper === "POST") {
|
|
21346
|
+
method = "GET";
|
|
21347
|
+
body = void 0;
|
|
21348
|
+
headers.delete("content-type");
|
|
21349
|
+
headers.delete("content-length");
|
|
21350
|
+
} else if (body != null && typeof body !== "string") throw new _mastra_core_error.MastraError({
|
|
21351
|
+
id: "MCP_CLIENT_REDIRECT_BODY_NOT_REPLAYABLE",
|
|
21352
|
+
domain: _mastra_core_error.ErrorDomain.MCP,
|
|
21353
|
+
category: _mastra_core_error.ErrorCategory.USER,
|
|
21354
|
+
text: `Cannot follow a ${response.status} redirect under the allowedHosts policy: the request body is not replayable (only string bodies can be re-sent).`
|
|
21355
|
+
});
|
|
21356
|
+
if (nextUrl.origin !== currentUrl.origin) headers.delete("authorization");
|
|
21357
|
+
currentUrl = nextUrl;
|
|
21358
|
+
}
|
|
21359
|
+
}
|
|
21360
|
+
//#endregion
|
|
21079
21361
|
//#region src/client/client.ts
|
|
21080
21362
|
const DEFAULT_SERVER_CONNECT_TIMEOUT_MSEC = 3e3;
|
|
21081
21363
|
const DEFAULT_INSTRUCTIONS_MAX_LENGTH = 512;
|
|
@@ -21188,7 +21470,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21188
21470
|
/**
|
|
21189
21471
|
* @internal
|
|
21190
21472
|
*/
|
|
21191
|
-
constructor({ name, version = "1.0.0", server, capabilities = {}, timeout =
|
|
21473
|
+
constructor({ name, version = "1.0.0", server, capabilities = {}, timeout = _modelcontextprotocol_client.DEFAULT_REQUEST_TIMEOUT_MSEC }) {
|
|
21192
21474
|
super({ name: "MastraMCPClient" });
|
|
21193
21475
|
this.name = name;
|
|
21194
21476
|
this.timeout = timeout;
|
|
@@ -21213,7 +21495,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21213
21495
|
"io.modelcontextprotocol/ui": {}
|
|
21214
21496
|
}
|
|
21215
21497
|
};
|
|
21216
|
-
this.client = new
|
|
21498
|
+
this.client = new _modelcontextprotocol_client.Client({
|
|
21217
21499
|
name,
|
|
21218
21500
|
version
|
|
21219
21501
|
}, {
|
|
@@ -21259,7 +21541,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21259
21541
|
});
|
|
21260
21542
|
}
|
|
21261
21543
|
setupLogging() {
|
|
21262
|
-
if (this.enableServerLogs) this.client.setNotificationHandler(
|
|
21544
|
+
if (this.enableServerLogs) this.client.setNotificationHandler("notifications/message", (notification) => {
|
|
21263
21545
|
const { level, ...params } = notification.params;
|
|
21264
21546
|
this.log(level, "[MCP SERVER LOG]", params);
|
|
21265
21547
|
});
|
|
@@ -21272,7 +21554,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21272
21554
|
*/
|
|
21273
21555
|
setupRootsHandler() {
|
|
21274
21556
|
this.log("debug", "Setting up roots/list request handler");
|
|
21275
|
-
this.client.setRequestHandler(
|
|
21557
|
+
this.client.setRequestHandler("roots/list", async () => {
|
|
21276
21558
|
this.log("debug", `Responding to roots/list request with ${this._roots.length} roots`);
|
|
21277
21559
|
return { roots: this._roots };
|
|
21278
21560
|
});
|
|
@@ -21321,16 +21603,28 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21321
21603
|
this.log("debug", "Sending notifications/roots/list_changed");
|
|
21322
21604
|
await this.client.notification({ method: "notifications/roots/list_changed" });
|
|
21323
21605
|
}
|
|
21606
|
+
buildStdioEnv() {
|
|
21607
|
+
const configured = this.serverConfig.env || {};
|
|
21608
|
+
if (this.serverConfig.inheritDefaultEnv === false) {
|
|
21609
|
+
const suppressed = {};
|
|
21610
|
+
for (const key of Object.keys((0, _modelcontextprotocol_client_stdio.getDefaultEnvironment)())) suppressed[key] = void 0;
|
|
21611
|
+
return {
|
|
21612
|
+
...suppressed,
|
|
21613
|
+
...configured
|
|
21614
|
+
};
|
|
21615
|
+
}
|
|
21616
|
+
return {
|
|
21617
|
+
...(0, _modelcontextprotocol_client_stdio.getDefaultEnvironment)(),
|
|
21618
|
+
...configured
|
|
21619
|
+
};
|
|
21620
|
+
}
|
|
21324
21621
|
async connectStdio(command) {
|
|
21325
21622
|
this.log("debug", `Using Stdio transport for command: ${command}`);
|
|
21326
21623
|
try {
|
|
21327
|
-
this.transport = new
|
|
21624
|
+
this.transport = new _modelcontextprotocol_client_stdio.StdioClientTransport({
|
|
21328
21625
|
command,
|
|
21329
21626
|
args: this.serverConfig.args,
|
|
21330
|
-
env:
|
|
21331
|
-
...(0, _modelcontextprotocol_sdk_client_stdio_js.getDefaultEnvironment)(),
|
|
21332
|
-
...this.serverConfig.env || {}
|
|
21333
|
-
},
|
|
21627
|
+
env: this.buildStdioEnv(),
|
|
21334
21628
|
stderr: this.serverConfig.stderr,
|
|
21335
21629
|
cwd: this.serverConfig.cwd
|
|
21336
21630
|
});
|
|
@@ -21342,16 +21636,22 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21342
21636
|
}
|
|
21343
21637
|
}
|
|
21344
21638
|
async connectHttp(url) {
|
|
21345
|
-
const { requestInit, eventSourceInit, authProvider, connectTimeout, fetch: userFetch } = this.serverConfig;
|
|
21639
|
+
const { requestInit, eventSourceInit, authProvider, connectTimeout, fetch: userFetch, allowedHosts } = this.serverConfig;
|
|
21640
|
+
if (allowedHosts !== void 0) assertHostAllowed(url, allowedHosts);
|
|
21641
|
+
const policyUserFetch = userFetch && allowedHosts !== void 0 ? wrapFetchWithHostPolicy(userFetch, allowedHosts) : void 0;
|
|
21346
21642
|
const fetch = (requestUrl, init) => {
|
|
21347
21643
|
const requestContext = this.operationContextStore.getStore() ?? null;
|
|
21348
|
-
const executeFetch = () =>
|
|
21644
|
+
const executeFetch = () => {
|
|
21645
|
+
if (allowedHosts === void 0) return userFetch ? userFetch(requestUrl, init, requestContext) : globalThis.fetch(requestUrl, init);
|
|
21646
|
+
if (policyUserFetch) return policyUserFetch(requestUrl, init, requestContext);
|
|
21647
|
+
return fetchFollowingAllowedRedirects((u, i) => globalThis.fetch(u, i), requestUrl, init, allowedHosts);
|
|
21648
|
+
};
|
|
21349
21649
|
return shouldDetachPersistentTransportRequest(init) ? runOutsideDatadogTraceScope(executeFetch) : executeFetch();
|
|
21350
21650
|
};
|
|
21351
21651
|
this.log("debug", `Attempting to connect to URL: ${url}`);
|
|
21352
21652
|
let shouldTrySSE = url.pathname.endsWith(`/sse`);
|
|
21353
21653
|
if (!shouldTrySSE) {
|
|
21354
|
-
const streamableTransport = new
|
|
21654
|
+
const streamableTransport = new _modelcontextprotocol_client.StreamableHTTPClientTransport(url, {
|
|
21355
21655
|
requestInit,
|
|
21356
21656
|
reconnectionOptions: this.serverConfig.reconnectionOptions,
|
|
21357
21657
|
authProvider,
|
|
@@ -21364,11 +21664,12 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21364
21664
|
this.log("debug", "Successfully connected using Streamable HTTP transport.");
|
|
21365
21665
|
} catch (error) {
|
|
21366
21666
|
this.log("debug", `Streamable HTTP transport failed: ${error}`);
|
|
21367
|
-
if (authProvider && error instanceof
|
|
21667
|
+
if (authProvider && error instanceof _modelcontextprotocol_client.UnauthorizedError) {
|
|
21368
21668
|
this.markNeedsAuth(streamableTransport);
|
|
21369
21669
|
throw error;
|
|
21370
21670
|
}
|
|
21371
|
-
|
|
21671
|
+
if (isUrlPolicyError(error)) throw error;
|
|
21672
|
+
const status = error instanceof _modelcontextprotocol_client.SdkHttpError ? error.status : void 0;
|
|
21372
21673
|
if (status !== void 0 && !SSE_FALLBACK_STATUS_CODES.includes(status)) throw error;
|
|
21373
21674
|
shouldTrySSE = true;
|
|
21374
21675
|
}
|
|
@@ -21376,11 +21677,12 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21376
21677
|
if (shouldTrySSE) {
|
|
21377
21678
|
await this.detachStaleClientTransport();
|
|
21378
21679
|
this.log("debug", "Falling back to deprecated HTTP+SSE transport...");
|
|
21379
|
-
const
|
|
21680
|
+
const callerSseFetch = eventSourceInit?.fetch;
|
|
21681
|
+
const sseTransport = new _modelcontextprotocol_client.SSEClientTransport(url, {
|
|
21380
21682
|
requestInit,
|
|
21381
21683
|
eventSourceInit: {
|
|
21382
21684
|
...eventSourceInit,
|
|
21383
|
-
fetch:
|
|
21685
|
+
fetch: callerSseFetch && allowedHosts !== void 0 ? wrapFetchWithHostPolicy(callerSseFetch, allowedHosts) : callerSseFetch ?? fetch
|
|
21384
21686
|
},
|
|
21385
21687
|
authProvider,
|
|
21386
21688
|
fetch
|
|
@@ -21390,10 +21692,11 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21390
21692
|
this.transport = sseTransport;
|
|
21391
21693
|
this.log("debug", "Successfully connected using deprecated HTTP+SSE transport.");
|
|
21392
21694
|
} catch (sseError) {
|
|
21393
|
-
if (authProvider && sseError instanceof
|
|
21695
|
+
if (authProvider && sseError instanceof _modelcontextprotocol_client.UnauthorizedError) {
|
|
21394
21696
|
this.markNeedsAuth(sseTransport);
|
|
21395
21697
|
throw sseError;
|
|
21396
21698
|
}
|
|
21699
|
+
if (isUrlPolicyError(sseError)) throw sseError;
|
|
21397
21700
|
this.log("error", `Failed to connect with SSE transport after failing to connect to Streamable HTTP transport first. SSE error: ${sseError}`);
|
|
21398
21701
|
throw new Error("Could not connect to server with any available HTTP transport");
|
|
21399
21702
|
}
|
|
@@ -21563,7 +21866,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21563
21866
|
* @internal
|
|
21564
21867
|
*/
|
|
21565
21868
|
get sessionId() {
|
|
21566
|
-
if (this.transport instanceof
|
|
21869
|
+
if (this.transport instanceof _modelcontextprotocol_client.StreamableHTTPClientTransport) return this.transport.sessionId;
|
|
21567
21870
|
}
|
|
21568
21871
|
/**
|
|
21569
21872
|
* Gets the stderr stream of the child process, if using stdio transport with `stderr: 'pipe'`.
|
|
@@ -21573,7 +21876,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21573
21876
|
* @internal
|
|
21574
21877
|
*/
|
|
21575
21878
|
get stderr() {
|
|
21576
|
-
if (this.transport instanceof
|
|
21879
|
+
if (this.transport instanceof _modelcontextprotocol_client_stdio.StdioClientTransport) return this.transport.stderr;
|
|
21577
21880
|
return null;
|
|
21578
21881
|
}
|
|
21579
21882
|
get instructions() {
|
|
@@ -21686,39 +21989,39 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21686
21989
|
}
|
|
21687
21990
|
async listResources() {
|
|
21688
21991
|
this.log("debug", `Requesting resources from MCP server`);
|
|
21689
|
-
return await this.client.request({ method: "resources/list" },
|
|
21992
|
+
return await this.client.request({ method: "resources/list" }, { timeout: this.timeout });
|
|
21690
21993
|
}
|
|
21691
21994
|
async readResource(uri) {
|
|
21692
21995
|
this.log("debug", `Reading resource from MCP server: ${uri}`);
|
|
21693
21996
|
return await this.client.request({
|
|
21694
21997
|
method: "resources/read",
|
|
21695
21998
|
params: { uri }
|
|
21696
|
-
},
|
|
21999
|
+
}, { timeout: this.timeout });
|
|
21697
22000
|
}
|
|
21698
22001
|
async subscribeResource(uri) {
|
|
21699
22002
|
this.log("debug", `Subscribing to resource on MCP server: ${uri}`);
|
|
21700
22003
|
return await this.client.request({
|
|
21701
22004
|
method: "resources/subscribe",
|
|
21702
22005
|
params: { uri }
|
|
21703
|
-
},
|
|
22006
|
+
}, { timeout: this.timeout });
|
|
21704
22007
|
}
|
|
21705
22008
|
async unsubscribeResource(uri) {
|
|
21706
22009
|
this.log("debug", `Unsubscribing from resource on MCP server: ${uri}`);
|
|
21707
22010
|
return await this.client.request({
|
|
21708
22011
|
method: "resources/unsubscribe",
|
|
21709
22012
|
params: { uri }
|
|
21710
|
-
},
|
|
22013
|
+
}, { timeout: this.timeout });
|
|
21711
22014
|
}
|
|
21712
22015
|
async listResourceTemplates() {
|
|
21713
22016
|
this.log("debug", `Requesting resource templates from MCP server`);
|
|
21714
|
-
return await this.client.request({ method: "resources/templates/list" },
|
|
22017
|
+
return await this.client.request({ method: "resources/templates/list" }, { timeout: this.timeout });
|
|
21715
22018
|
}
|
|
21716
22019
|
/**
|
|
21717
22020
|
* Fetch the list of available prompts from the MCP server.
|
|
21718
22021
|
*/
|
|
21719
22022
|
async listPrompts() {
|
|
21720
22023
|
this.log("debug", `Requesting prompts from MCP server`);
|
|
21721
|
-
return await this.client.request({ method: "prompts/list" },
|
|
22024
|
+
return await this.client.request({ method: "prompts/list" }, { timeout: this.timeout });
|
|
21722
22025
|
}
|
|
21723
22026
|
/**
|
|
21724
22027
|
* Get a prompt and its dynamic messages from the server.
|
|
@@ -21733,7 +22036,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21733
22036
|
name,
|
|
21734
22037
|
arguments: args
|
|
21735
22038
|
}
|
|
21736
|
-
},
|
|
22039
|
+
}, { timeout: this.timeout });
|
|
21737
22040
|
}
|
|
21738
22041
|
/**
|
|
21739
22042
|
* Register a handler to be called when the prompt list changes on the server.
|
|
@@ -21741,7 +22044,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21741
22044
|
*/
|
|
21742
22045
|
setPromptListChangedNotificationHandler(handler) {
|
|
21743
22046
|
this.log("debug", "Setting prompt list changed notification handler");
|
|
21744
|
-
this.client.setNotificationHandler(
|
|
22047
|
+
this.client.setNotificationHandler("notifications/prompts/list_changed", () => {
|
|
21745
22048
|
handler();
|
|
21746
22049
|
});
|
|
21747
22050
|
}
|
|
@@ -21751,19 +22054,19 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21751
22054
|
*/
|
|
21752
22055
|
setToolListChangedNotificationHandler(handler) {
|
|
21753
22056
|
this.log("debug", "Setting tool list changed notification handler");
|
|
21754
|
-
this.client.setNotificationHandler(
|
|
22057
|
+
this.client.setNotificationHandler("notifications/tools/list_changed", () => {
|
|
21755
22058
|
handler();
|
|
21756
22059
|
});
|
|
21757
22060
|
}
|
|
21758
22061
|
setResourceUpdatedNotificationHandler(handler) {
|
|
21759
22062
|
this.log("debug", "Setting resource updated notification handler");
|
|
21760
|
-
this.client.setNotificationHandler(
|
|
22063
|
+
this.client.setNotificationHandler("notifications/resources/updated", (notification) => {
|
|
21761
22064
|
handler(notification.params);
|
|
21762
22065
|
});
|
|
21763
22066
|
}
|
|
21764
22067
|
setResourceListChangedNotificationHandler(handler) {
|
|
21765
22068
|
this.log("debug", "Setting resource list changed notification handler");
|
|
21766
|
-
this.client.setNotificationHandler(
|
|
22069
|
+
this.client.setNotificationHandler("notifications/resources/list_changed", () => {
|
|
21767
22070
|
handler();
|
|
21768
22071
|
});
|
|
21769
22072
|
}
|
|
@@ -21775,14 +22078,14 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21775
22078
|
} catch (error) {
|
|
21776
22079
|
throw new Error("Cannot register an elicitation handler after connecting unless elicitation capability was configured before initialization.", { cause: error });
|
|
21777
22080
|
}
|
|
21778
|
-
this.client.setRequestHandler(
|
|
22081
|
+
this.client.setRequestHandler("elicitation/create", async (request) => {
|
|
21779
22082
|
this.log("debug", `Received elicitation request: ${request.params.message}`);
|
|
21780
22083
|
return handler(request.params);
|
|
21781
22084
|
});
|
|
21782
22085
|
}
|
|
21783
22086
|
setProgressNotificationHandler(handler) {
|
|
21784
22087
|
this.log("debug", "Setting progress notification handler");
|
|
21785
|
-
this.client.setNotificationHandler(
|
|
22088
|
+
this.client.setNotificationHandler("notifications/progress", (notification) => {
|
|
21786
22089
|
handler(notification.params);
|
|
21787
22090
|
});
|
|
21788
22091
|
}
|
|
@@ -21790,7 +22093,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21790
22093
|
return "jsonSchema" in inputSchema ? inputSchema.jsonSchema : inputSchema;
|
|
21791
22094
|
}
|
|
21792
22095
|
/**
|
|
21793
|
-
* Wraps the output schema with a validator that always succeeds. The MCP
|
|
22096
|
+
* Wraps the output schema with a validator that always succeeds. The MCP client validates
|
|
21794
22097
|
* structuredContent via AJV; the JSON schema is surfaced here for documentation only.
|
|
21795
22098
|
*/
|
|
21796
22099
|
convertOutputSchema(outputSchema) {
|
|
@@ -21862,7 +22165,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21862
22165
|
name: tool.name,
|
|
21863
22166
|
arguments: input,
|
|
21864
22167
|
...combinedMeta ? { _meta: combinedMeta } : {}
|
|
21865
|
-
},
|
|
22168
|
+
}, {
|
|
21866
22169
|
timeout: this.timeout,
|
|
21867
22170
|
signal: context?.abortSignal
|
|
21868
22171
|
});
|
|
@@ -22643,7 +22946,7 @@ var MCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
22643
22946
|
*/
|
|
22644
22947
|
constructor(args) {
|
|
22645
22948
|
super({ name: "MCPClient" });
|
|
22646
|
-
this.defaultTimeout = args.timeout ??
|
|
22949
|
+
this.defaultTimeout = args.timeout ?? _modelcontextprotocol_client.DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
22647
22950
|
this.serverConfigs = args.servers;
|
|
22648
22951
|
this.id = args.id ?? this.makeId();
|
|
22649
22952
|
if (args.id) {
|
|
@@ -23285,14 +23588,14 @@ onListChanged: async (serverName, handler) => {
|
|
|
23285
23588
|
await client.connect();
|
|
23286
23589
|
return;
|
|
23287
23590
|
} catch (error) {
|
|
23288
|
-
if (!(error instanceof
|
|
23591
|
+
if (!(error instanceof _modelcontextprotocol_client.UnauthorizedError)) throw this.handleConnectError(serverName, error);
|
|
23289
23592
|
}
|
|
23290
23593
|
const { code } = await callbackServer.waitForCode(options);
|
|
23291
23594
|
await client.finishAuth(code);
|
|
23292
23595
|
try {
|
|
23293
23596
|
await client.connect();
|
|
23294
23597
|
} catch (error) {
|
|
23295
|
-
throw error instanceof
|
|
23598
|
+
throw error instanceof _modelcontextprotocol_client.UnauthorizedError ? error : this.handleConnectError(serverName, error);
|
|
23296
23599
|
}
|
|
23297
23600
|
} finally {
|
|
23298
23601
|
this.authCallbackServersByServer.delete(serverName);
|
|
@@ -23612,7 +23915,7 @@ onListChanged: async (serverName, handler) => {
|
|
|
23612
23915
|
}, error);
|
|
23613
23916
|
this.logger.trackException(mastraError);
|
|
23614
23917
|
this.logger.error("MCPClient errored connecting to MCP server:", { error: mastraError.toString() });
|
|
23615
|
-
if (!(error instanceof
|
|
23918
|
+
if (!(error instanceof _modelcontextprotocol_client.UnauthorizedError)) this.mcpClientsById.delete(name);
|
|
23616
23919
|
return mastraError;
|
|
23617
23920
|
}
|
|
23618
23921
|
async getConnectedClientForServer(serverName) {
|
|
@@ -23804,163 +24107,1994 @@ var streamSSE = (c, cb, onError) => {
|
|
|
23804
24107
|
return c.newResponse(stream.responseReadable);
|
|
23805
24108
|
};
|
|
23806
24109
|
//#endregion
|
|
23807
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links
|
|
23808
|
-
const
|
|
23809
|
-
var SSETransport = class {
|
|
23810
|
-
messageUrl;
|
|
23811
|
-
stream;
|
|
23812
|
-
_sessionId;
|
|
23813
|
-
onclose;
|
|
23814
|
-
onerror;
|
|
23815
|
-
onmessage;
|
|
23816
|
-
/**
|
|
23817
|
-
* Creates a new SSETransport, which will direct the MPC client to POST messages to messageUrl
|
|
23818
|
-
*/
|
|
23819
|
-
constructor(messageUrl, stream) {
|
|
23820
|
-
this.messageUrl = messageUrl;
|
|
23821
|
-
this.stream = stream;
|
|
23822
|
-
this._sessionId = crypto.randomUUID();
|
|
23823
|
-
this.stream.onAbort(() => {
|
|
23824
|
-
this.close();
|
|
23825
|
-
});
|
|
23826
|
-
}
|
|
23827
|
-
get sessionId() {
|
|
23828
|
-
return this._sessionId;
|
|
23829
|
-
}
|
|
23830
|
-
async start() {
|
|
23831
|
-
if (this.stream == null) throw new Error("Stream not initialized");
|
|
23832
|
-
if (this.stream.closed) throw new Error("SSE transport already closed!");
|
|
23833
|
-
await this.stream.writeSSE({
|
|
23834
|
-
event: "ping",
|
|
23835
|
-
data: ""
|
|
23836
|
-
});
|
|
23837
|
-
await this.stream.writeSSE({
|
|
23838
|
-
event: "endpoint",
|
|
23839
|
-
data: `${this.messageUrl}?sessionId=${this.sessionId}`
|
|
23840
|
-
});
|
|
23841
|
-
}
|
|
23842
|
-
async handlePostMessage(context) {
|
|
23843
|
-
if (this.stream?.closed == null) return context.text("SSE connection not established", 500);
|
|
23844
|
-
try {
|
|
23845
|
-
const contentType = context.req.header("content-type") || "";
|
|
23846
|
-
if (!contentType.includes("application/json")) throw new Error(`Unsupported content-type: ${contentType}`);
|
|
23847
|
-
const contentLength = Number.parseInt(context.req.header("content-length") || "0", 10);
|
|
23848
|
-
if (contentLength > MAXIMUM_MESSAGE_SIZE) throw new Error(`Request body too large: ${contentLength} bytes`);
|
|
23849
|
-
const body = await context.req.json();
|
|
23850
|
-
await this.handleMessage(body);
|
|
23851
|
-
return context.text("Accepted", 202);
|
|
23852
|
-
} catch (error) {
|
|
23853
|
-
this.onerror?.(error);
|
|
23854
|
-
return context.text("Error", 400);
|
|
23855
|
-
}
|
|
23856
|
-
}
|
|
23857
|
-
/**
|
|
23858
|
-
* Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.
|
|
23859
|
-
*/
|
|
23860
|
-
async handleMessage(message) {
|
|
23861
|
-
let parsedMessage;
|
|
23862
|
-
try {
|
|
23863
|
-
parsedMessage = _modelcontextprotocol_sdk_types_js.JSONRPCMessageSchema.parse(message);
|
|
23864
|
-
} catch (error) {
|
|
23865
|
-
this.onerror?.(error);
|
|
23866
|
-
throw error;
|
|
23867
|
-
}
|
|
23868
|
-
this.onmessage?.(parsedMessage);
|
|
23869
|
-
}
|
|
23870
|
-
async close() {
|
|
23871
|
-
if (this.stream?.closed) this.stream.abort();
|
|
23872
|
-
}
|
|
23873
|
-
async send(message) {
|
|
23874
|
-
if (this.stream?.closed) throw new Error("Not connected");
|
|
23875
|
-
await this.stream.writeSSE({
|
|
23876
|
-
event: "message",
|
|
23877
|
-
data: JSON.stringify(message)
|
|
23878
|
-
});
|
|
23879
|
-
}
|
|
23880
|
-
};
|
|
23881
|
-
//#endregion
|
|
23882
|
-
//#region src/server/notificationBroadcast.ts
|
|
24110
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@modelcontextprotocol/sdk/1.29.0/989ce0cb833930f9ef8da3e25bac11110cfeac46669bc69ae9534a6aa55b0aa7/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
24111
|
+
const RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
23883
24112
|
/**
|
|
23884
|
-
*
|
|
23885
|
-
* instance plus each streamable HTTP session instance).
|
|
23886
|
-
*
|
|
23887
|
-
* Failures are aggregated: if only some instances fail, the failure is logged
|
|
23888
|
-
* and the broadcast is considered best-effort. A `MastraError` is thrown only
|
|
23889
|
-
* when every send fails.
|
|
23890
|
-
*
|
|
23891
|
-
* Note: clients connected in stateless/serverless mode cannot receive
|
|
23892
|
-
* notifications because each request uses a transient server instance.
|
|
24113
|
+
* Assert 'object' type schema.
|
|
23893
24114
|
*
|
|
23894
24115
|
* @internal
|
|
23895
24116
|
*/
|
|
23896
|
-
|
|
23897
|
-
const errors = [];
|
|
23898
|
-
for (const server of servers) try {
|
|
23899
|
-
await send(server);
|
|
23900
|
-
} catch (error) {
|
|
23901
|
-
errors.push(error);
|
|
23902
|
-
}
|
|
23903
|
-
if (errors.length === 0) return;
|
|
23904
|
-
const mastraError = new _mastra_core_error.MastraError({
|
|
23905
|
-
id: errorId,
|
|
23906
|
-
domain: _mastra_core_error.ErrorDomain.MCP,
|
|
23907
|
-
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
23908
|
-
text: errorText,
|
|
23909
|
-
details: {
|
|
23910
|
-
...errorDetails,
|
|
23911
|
-
failedInstances: errors.length,
|
|
23912
|
-
totalInstances: servers.length
|
|
23913
|
-
}
|
|
23914
|
-
}, errors[0]);
|
|
23915
|
-
logger.error(`${errorText}:`, { error: mastraError.toString() });
|
|
23916
|
-
if (errors.length === servers.length) {
|
|
23917
|
-
logger.trackException(mastraError);
|
|
23918
|
-
throw mastraError;
|
|
23919
|
-
}
|
|
23920
|
-
}
|
|
23921
|
-
//#endregion
|
|
23922
|
-
//#region src/server/promptActions.ts
|
|
24117
|
+
const AssertObjectSchema = custom$1((v) => v !== null && (typeof v === "object" || typeof v === "function"));
|
|
23923
24118
|
/**
|
|
23924
|
-
*
|
|
23925
|
-
*
|
|
23926
|
-
* This class provides methods for MCP servers to notify connected clients when
|
|
23927
|
-
* the list of available prompts changes.
|
|
23928
|
-
*
|
|
23929
|
-
* Notifications are broadcast to every active server instance (the main
|
|
23930
|
-
* stdio/SSE instance plus each streamable HTTP session). Clients connected in
|
|
23931
|
-
* stateless/serverless mode cannot receive notifications because each request
|
|
23932
|
-
* uses a transient server instance.
|
|
24119
|
+
* A progress token, used to associate progress notifications with the original request.
|
|
23933
24120
|
*/
|
|
23934
|
-
|
|
23935
|
-
|
|
23936
|
-
|
|
23937
|
-
|
|
24121
|
+
const ProgressTokenSchema = union([string(), number().int()]);
|
|
24122
|
+
/**
|
|
24123
|
+
* An opaque token used to represent a cursor for pagination.
|
|
24124
|
+
*/
|
|
24125
|
+
const CursorSchema = string();
|
|
24126
|
+
looseObject({
|
|
23938
24127
|
/**
|
|
23939
|
-
*
|
|
24128
|
+
* Requested duration in milliseconds to retain task from creation.
|
|
23940
24129
|
*/
|
|
23941
|
-
|
|
23942
|
-
this.getLogger = dependencies.getLogger;
|
|
23943
|
-
this.getSdkServers = dependencies.getSdkServers;
|
|
23944
|
-
this.clearDefinedPrompts = dependencies.clearDefinedPrompts;
|
|
23945
|
-
}
|
|
24130
|
+
ttl: number().optional(),
|
|
23946
24131
|
/**
|
|
23947
|
-
*
|
|
23948
|
-
*
|
|
23949
|
-
* This clears the internal prompt cache and sends a `notifications/prompts/list_changed`
|
|
23950
|
-
* message to all clients, prompting them to re-fetch the prompt list.
|
|
23951
|
-
*
|
|
23952
|
-
* @throws {MastraError} If sending the notification fails on all server instances
|
|
23953
|
-
*
|
|
23954
|
-
* @example
|
|
23955
|
-
* ```typescript
|
|
23956
|
-
* // After adding or modifying prompts
|
|
23957
|
-
* await server.prompts.notifyListChanged();
|
|
23958
|
-
* ```
|
|
24132
|
+
* Time in milliseconds to wait between task status requests.
|
|
23959
24133
|
*/
|
|
23960
|
-
|
|
23961
|
-
|
|
23962
|
-
|
|
23963
|
-
|
|
24134
|
+
pollInterval: number().optional()
|
|
24135
|
+
});
|
|
24136
|
+
const TaskMetadataSchema = object$1({ ttl: number().optional() });
|
|
24137
|
+
/**
|
|
24138
|
+
* Metadata for associating messages with a task.
|
|
24139
|
+
* Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
|
|
24140
|
+
*/
|
|
24141
|
+
const RelatedTaskMetadataSchema = object$1({ taskId: string() });
|
|
24142
|
+
const RequestMetaSchema = looseObject({
|
|
24143
|
+
/**
|
|
24144
|
+
* 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.
|
|
24145
|
+
*/
|
|
24146
|
+
progressToken: ProgressTokenSchema.optional(),
|
|
24147
|
+
/**
|
|
24148
|
+
* If specified, this request is related to the provided task.
|
|
24149
|
+
*/
|
|
24150
|
+
[RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
|
|
24151
|
+
});
|
|
24152
|
+
/**
|
|
24153
|
+
* Common params for any request.
|
|
24154
|
+
*/
|
|
24155
|
+
const BaseRequestParamsSchema = object$1({
|
|
24156
|
+
/**
|
|
24157
|
+
* See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
|
|
24158
|
+
*/
|
|
24159
|
+
_meta: RequestMetaSchema.optional() });
|
|
24160
|
+
/**
|
|
24161
|
+
* Common params for any task-augmented request.
|
|
24162
|
+
*/
|
|
24163
|
+
const TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24164
|
+
/**
|
|
24165
|
+
* If specified, the caller is requesting task-augmented execution for this request.
|
|
24166
|
+
* The request will return a CreateTaskResult immediately, and the actual result can be
|
|
24167
|
+
* retrieved later via tasks/result.
|
|
24168
|
+
*
|
|
24169
|
+
* Task augmentation is subject to capability negotiation - receivers MUST declare support
|
|
24170
|
+
* for task augmentation of specific request types in their capabilities.
|
|
24171
|
+
*/
|
|
24172
|
+
task: TaskMetadataSchema.optional() });
|
|
24173
|
+
const RequestSchema = object$1({
|
|
24174
|
+
method: string(),
|
|
24175
|
+
params: BaseRequestParamsSchema.loose().optional()
|
|
24176
|
+
});
|
|
24177
|
+
const NotificationsParamsSchema = object$1({
|
|
24178
|
+
/**
|
|
24179
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24180
|
+
* for notes on _meta usage.
|
|
24181
|
+
*/
|
|
24182
|
+
_meta: RequestMetaSchema.optional() });
|
|
24183
|
+
const NotificationSchema = object$1({
|
|
24184
|
+
method: string(),
|
|
24185
|
+
params: NotificationsParamsSchema.loose().optional()
|
|
24186
|
+
});
|
|
24187
|
+
const ResultSchema = looseObject({
|
|
24188
|
+
/**
|
|
24189
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24190
|
+
* for notes on _meta usage.
|
|
24191
|
+
*/
|
|
24192
|
+
_meta: RequestMetaSchema.optional() });
|
|
24193
|
+
/**
|
|
24194
|
+
* A uniquely identifying ID for a request in JSON-RPC.
|
|
24195
|
+
*/
|
|
24196
|
+
const RequestIdSchema = union([string(), number().int()]);
|
|
24197
|
+
/**
|
|
24198
|
+
* A request that expects a response.
|
|
24199
|
+
*/
|
|
24200
|
+
const JSONRPCRequestSchema = object$1({
|
|
24201
|
+
jsonrpc: literal("2.0"),
|
|
24202
|
+
id: RequestIdSchema,
|
|
24203
|
+
...RequestSchema.shape
|
|
24204
|
+
}).strict();
|
|
24205
|
+
/**
|
|
24206
|
+
* A notification which does not expect a response.
|
|
24207
|
+
*/
|
|
24208
|
+
const JSONRPCNotificationSchema = object$1({
|
|
24209
|
+
jsonrpc: literal("2.0"),
|
|
24210
|
+
...NotificationSchema.shape
|
|
24211
|
+
}).strict();
|
|
24212
|
+
/**
|
|
24213
|
+
* A successful (non-error) response to a request.
|
|
24214
|
+
*/
|
|
24215
|
+
const JSONRPCResultResponseSchema = object$1({
|
|
24216
|
+
jsonrpc: literal("2.0"),
|
|
24217
|
+
id: RequestIdSchema,
|
|
24218
|
+
result: ResultSchema
|
|
24219
|
+
}).strict();
|
|
24220
|
+
/**
|
|
24221
|
+
* Error codes defined by the JSON-RPC specification.
|
|
24222
|
+
*/
|
|
24223
|
+
var ErrorCode;
|
|
24224
|
+
(function(ErrorCode) {
|
|
24225
|
+
ErrorCode[ErrorCode["ConnectionClosed"] = -32e3] = "ConnectionClosed";
|
|
24226
|
+
ErrorCode[ErrorCode["RequestTimeout"] = -32001] = "RequestTimeout";
|
|
24227
|
+
ErrorCode[ErrorCode["ParseError"] = -32700] = "ParseError";
|
|
24228
|
+
ErrorCode[ErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
24229
|
+
ErrorCode[ErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
24230
|
+
ErrorCode[ErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
24231
|
+
ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError";
|
|
24232
|
+
ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
|
|
24233
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
24234
|
+
/**
|
|
24235
|
+
* A response to a request that indicates an error occurred.
|
|
24236
|
+
*/
|
|
24237
|
+
const JSONRPCErrorResponseSchema = object$1({
|
|
24238
|
+
jsonrpc: literal("2.0"),
|
|
24239
|
+
id: RequestIdSchema.optional(),
|
|
24240
|
+
error: object$1({
|
|
24241
|
+
/**
|
|
24242
|
+
* The error type that occurred.
|
|
24243
|
+
*/
|
|
24244
|
+
code: number().int(),
|
|
24245
|
+
/**
|
|
24246
|
+
* A short description of the error. The message SHOULD be limited to a concise single sentence.
|
|
24247
|
+
*/
|
|
24248
|
+
message: string(),
|
|
24249
|
+
/**
|
|
24250
|
+
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
24251
|
+
*/
|
|
24252
|
+
data: unknown().optional()
|
|
24253
|
+
})
|
|
24254
|
+
}).strict();
|
|
24255
|
+
const JSONRPCMessageSchema = union([
|
|
24256
|
+
JSONRPCRequestSchema,
|
|
24257
|
+
JSONRPCNotificationSchema,
|
|
24258
|
+
JSONRPCResultResponseSchema,
|
|
24259
|
+
JSONRPCErrorResponseSchema
|
|
24260
|
+
]);
|
|
24261
|
+
union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
|
|
24262
|
+
/**
|
|
24263
|
+
* A response that indicates success but carries no data.
|
|
24264
|
+
*/
|
|
24265
|
+
const EmptyResultSchema = ResultSchema.strict();
|
|
24266
|
+
const CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
24267
|
+
/**
|
|
24268
|
+
* The ID of the request to cancel.
|
|
24269
|
+
*
|
|
24270
|
+
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
24271
|
+
*/
|
|
24272
|
+
requestId: RequestIdSchema.optional(),
|
|
24273
|
+
/**
|
|
24274
|
+
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
24275
|
+
*/
|
|
24276
|
+
reason: string().optional()
|
|
24277
|
+
});
|
|
24278
|
+
/**
|
|
24279
|
+
* This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
|
|
24280
|
+
*
|
|
24281
|
+
* The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished.
|
|
24282
|
+
*
|
|
24283
|
+
* This notification indicates that the result will be unused, so any associated processing SHOULD cease.
|
|
24284
|
+
*
|
|
24285
|
+
* A client MUST NOT attempt to cancel its `initialize` request.
|
|
24286
|
+
*/
|
|
24287
|
+
const CancelledNotificationSchema = NotificationSchema.extend({
|
|
24288
|
+
method: literal("notifications/cancelled"),
|
|
24289
|
+
params: CancelledNotificationParamsSchema
|
|
24290
|
+
});
|
|
24291
|
+
/**
|
|
24292
|
+
* Base schema to add `icons` property.
|
|
24293
|
+
*
|
|
24294
|
+
*/
|
|
24295
|
+
const IconsSchema = object$1({
|
|
24296
|
+
/**
|
|
24297
|
+
* Optional set of sized icons that the client can display in a user interface.
|
|
24298
|
+
*
|
|
24299
|
+
* Clients that support rendering icons MUST support at least the following MIME types:
|
|
24300
|
+
* - `image/png` - PNG images (safe, universal compatibility)
|
|
24301
|
+
* - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
|
|
24302
|
+
*
|
|
24303
|
+
* Clients that support rendering icons SHOULD also support:
|
|
24304
|
+
* - `image/svg+xml` - SVG images (scalable but requires security precautions)
|
|
24305
|
+
* - `image/webp` - WebP images (modern, efficient format)
|
|
24306
|
+
*/
|
|
24307
|
+
icons: array(object$1({
|
|
24308
|
+
/**
|
|
24309
|
+
* URL or data URI for the icon.
|
|
24310
|
+
*/
|
|
24311
|
+
src: string(),
|
|
24312
|
+
/**
|
|
24313
|
+
* Optional MIME type for the icon.
|
|
24314
|
+
*/
|
|
24315
|
+
mimeType: string().optional(),
|
|
24316
|
+
/**
|
|
24317
|
+
* Optional array of strings that specify sizes at which the icon can be used.
|
|
24318
|
+
* Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
|
|
24319
|
+
*
|
|
24320
|
+
* If not provided, the client should assume that the icon can be used at any size.
|
|
24321
|
+
*/
|
|
24322
|
+
sizes: array(string()).optional(),
|
|
24323
|
+
/**
|
|
24324
|
+
* Optional specifier for the theme this icon is designed for. `light` indicates
|
|
24325
|
+
* the icon is designed to be used with a light background, and `dark` indicates
|
|
24326
|
+
* the icon is designed to be used with a dark background.
|
|
24327
|
+
*
|
|
24328
|
+
* If not provided, the client should assume the icon can be used with any theme.
|
|
24329
|
+
*/
|
|
24330
|
+
theme: _enum(["light", "dark"]).optional()
|
|
24331
|
+
})).optional() });
|
|
24332
|
+
/**
|
|
24333
|
+
* Base metadata interface for common properties across resources, tools, prompts, and implementations.
|
|
24334
|
+
*/
|
|
24335
|
+
const BaseMetadataSchema = object$1({
|
|
24336
|
+
/** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
|
|
24337
|
+
name: string(),
|
|
24338
|
+
/**
|
|
24339
|
+
* Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
|
|
24340
|
+
* even by those unfamiliar with domain-specific terminology.
|
|
24341
|
+
*
|
|
24342
|
+
* If not provided, the name should be used for display (except for Tool,
|
|
24343
|
+
* where `annotations.title` should be given precedence over using `name`,
|
|
24344
|
+
* if present).
|
|
24345
|
+
*/
|
|
24346
|
+
title: string().optional()
|
|
24347
|
+
});
|
|
24348
|
+
/**
|
|
24349
|
+
* Describes the name and version of an MCP implementation.
|
|
24350
|
+
*/
|
|
24351
|
+
const ImplementationSchema = BaseMetadataSchema.extend({
|
|
24352
|
+
...BaseMetadataSchema.shape,
|
|
24353
|
+
...IconsSchema.shape,
|
|
24354
|
+
version: string(),
|
|
24355
|
+
/**
|
|
24356
|
+
* An optional URL of the website for this implementation.
|
|
24357
|
+
*/
|
|
24358
|
+
websiteUrl: string().optional(),
|
|
24359
|
+
/**
|
|
24360
|
+
* An optional human-readable description of what this implementation does.
|
|
24361
|
+
*
|
|
24362
|
+
* This can be used by clients or servers to provide context about their purpose
|
|
24363
|
+
* and capabilities. For example, a server might describe the types of resources
|
|
24364
|
+
* or tools it provides, while a client might describe its intended use case.
|
|
24365
|
+
*/
|
|
24366
|
+
description: string().optional()
|
|
24367
|
+
});
|
|
24368
|
+
const ElicitationCapabilitySchema = preprocess((value) => {
|
|
24369
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
24370
|
+
if (Object.keys(value).length === 0) return { form: {} };
|
|
24371
|
+
}
|
|
24372
|
+
return value;
|
|
24373
|
+
}, intersection(object$1({
|
|
24374
|
+
form: intersection(object$1({ applyDefaults: boolean().optional() }), record(string(), unknown())).optional(),
|
|
24375
|
+
url: AssertObjectSchema.optional()
|
|
24376
|
+
}), record(string(), unknown()).optional()));
|
|
24377
|
+
/**
|
|
24378
|
+
* Task capabilities for clients, indicating which request types support task creation.
|
|
24379
|
+
*/
|
|
24380
|
+
const ClientTasksCapabilitySchema = looseObject({
|
|
24381
|
+
/**
|
|
24382
|
+
* Present if the client supports listing tasks.
|
|
24383
|
+
*/
|
|
24384
|
+
list: AssertObjectSchema.optional(),
|
|
24385
|
+
/**
|
|
24386
|
+
* Present if the client supports cancelling tasks.
|
|
24387
|
+
*/
|
|
24388
|
+
cancel: AssertObjectSchema.optional(),
|
|
24389
|
+
/**
|
|
24390
|
+
* Capabilities for task creation on specific request types.
|
|
24391
|
+
*/
|
|
24392
|
+
requests: looseObject({
|
|
24393
|
+
/**
|
|
24394
|
+
* Task support for sampling requests.
|
|
24395
|
+
*/
|
|
24396
|
+
sampling: looseObject({ createMessage: AssertObjectSchema.optional() }).optional(),
|
|
24397
|
+
/**
|
|
24398
|
+
* Task support for elicitation requests.
|
|
24399
|
+
*/
|
|
24400
|
+
elicitation: looseObject({ create: AssertObjectSchema.optional() }).optional()
|
|
24401
|
+
}).optional()
|
|
24402
|
+
});
|
|
24403
|
+
/**
|
|
24404
|
+
* Task capabilities for servers, indicating which request types support task creation.
|
|
24405
|
+
*/
|
|
24406
|
+
const ServerTasksCapabilitySchema = looseObject({
|
|
24407
|
+
/**
|
|
24408
|
+
* Present if the server supports listing tasks.
|
|
24409
|
+
*/
|
|
24410
|
+
list: AssertObjectSchema.optional(),
|
|
24411
|
+
/**
|
|
24412
|
+
* Present if the server supports cancelling tasks.
|
|
24413
|
+
*/
|
|
24414
|
+
cancel: AssertObjectSchema.optional(),
|
|
24415
|
+
/**
|
|
24416
|
+
* Capabilities for task creation on specific request types.
|
|
24417
|
+
*/
|
|
24418
|
+
requests: looseObject({
|
|
24419
|
+
/**
|
|
24420
|
+
* Task support for tool requests.
|
|
24421
|
+
*/
|
|
24422
|
+
tools: looseObject({ call: AssertObjectSchema.optional() }).optional() }).optional()
|
|
24423
|
+
});
|
|
24424
|
+
/**
|
|
24425
|
+
* Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities.
|
|
24426
|
+
*/
|
|
24427
|
+
const ClientCapabilitiesSchema = object$1({
|
|
24428
|
+
/**
|
|
24429
|
+
* Experimental, non-standard capabilities that the client supports.
|
|
24430
|
+
*/
|
|
24431
|
+
experimental: record(string(), AssertObjectSchema).optional(),
|
|
24432
|
+
/**
|
|
24433
|
+
* Present if the client supports sampling from an LLM.
|
|
24434
|
+
*/
|
|
24435
|
+
sampling: object$1({
|
|
24436
|
+
/**
|
|
24437
|
+
* Present if the client supports context inclusion via includeContext parameter.
|
|
24438
|
+
* If not declared, servers SHOULD only use `includeContext: "none"` (or omit it).
|
|
24439
|
+
*/
|
|
24440
|
+
context: AssertObjectSchema.optional(),
|
|
24441
|
+
/**
|
|
24442
|
+
* Present if the client supports tool use via tools and toolChoice parameters.
|
|
24443
|
+
*/
|
|
24444
|
+
tools: AssertObjectSchema.optional()
|
|
24445
|
+
}).optional(),
|
|
24446
|
+
/**
|
|
24447
|
+
* Present if the client supports eliciting user input.
|
|
24448
|
+
*/
|
|
24449
|
+
elicitation: ElicitationCapabilitySchema.optional(),
|
|
24450
|
+
/**
|
|
24451
|
+
* Present if the client supports listing roots.
|
|
24452
|
+
*/
|
|
24453
|
+
roots: object$1({
|
|
24454
|
+
/**
|
|
24455
|
+
* Whether the client supports issuing notifications for changes to the roots list.
|
|
24456
|
+
*/
|
|
24457
|
+
listChanged: boolean().optional() }).optional(),
|
|
24458
|
+
/**
|
|
24459
|
+
* Present if the client supports task creation.
|
|
24460
|
+
*/
|
|
24461
|
+
tasks: ClientTasksCapabilitySchema.optional(),
|
|
24462
|
+
/**
|
|
24463
|
+
* Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
|
|
24464
|
+
*/
|
|
24465
|
+
extensions: record(string(), AssertObjectSchema).optional()
|
|
24466
|
+
});
|
|
24467
|
+
const InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24468
|
+
/**
|
|
24469
|
+
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
|
|
24470
|
+
*/
|
|
24471
|
+
protocolVersion: string(),
|
|
24472
|
+
capabilities: ClientCapabilitiesSchema,
|
|
24473
|
+
clientInfo: ImplementationSchema
|
|
24474
|
+
});
|
|
24475
|
+
/**
|
|
24476
|
+
* This request is sent from the client to the server when it first connects, asking it to begin initialization.
|
|
24477
|
+
*/
|
|
24478
|
+
const InitializeRequestSchema = RequestSchema.extend({
|
|
24479
|
+
method: literal("initialize"),
|
|
24480
|
+
params: InitializeRequestParamsSchema
|
|
24481
|
+
});
|
|
24482
|
+
/**
|
|
24483
|
+
* Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities.
|
|
24484
|
+
*/
|
|
24485
|
+
const ServerCapabilitiesSchema = object$1({
|
|
24486
|
+
/**
|
|
24487
|
+
* Experimental, non-standard capabilities that the server supports.
|
|
24488
|
+
*/
|
|
24489
|
+
experimental: record(string(), AssertObjectSchema).optional(),
|
|
24490
|
+
/**
|
|
24491
|
+
* Present if the server supports sending log messages to the client.
|
|
24492
|
+
*/
|
|
24493
|
+
logging: AssertObjectSchema.optional(),
|
|
24494
|
+
/**
|
|
24495
|
+
* Present if the server supports sending completions to the client.
|
|
24496
|
+
*/
|
|
24497
|
+
completions: AssertObjectSchema.optional(),
|
|
24498
|
+
/**
|
|
24499
|
+
* Present if the server offers any prompt templates.
|
|
24500
|
+
*/
|
|
24501
|
+
prompts: object$1({
|
|
24502
|
+
/**
|
|
24503
|
+
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
24504
|
+
*/
|
|
24505
|
+
listChanged: boolean().optional() }).optional(),
|
|
24506
|
+
/**
|
|
24507
|
+
* Present if the server offers any resources to read.
|
|
24508
|
+
*/
|
|
24509
|
+
resources: object$1({
|
|
24510
|
+
/**
|
|
24511
|
+
* Whether this server supports clients subscribing to resource updates.
|
|
24512
|
+
*/
|
|
24513
|
+
subscribe: boolean().optional(),
|
|
24514
|
+
/**
|
|
24515
|
+
* Whether this server supports issuing notifications for changes to the resource list.
|
|
24516
|
+
*/
|
|
24517
|
+
listChanged: boolean().optional()
|
|
24518
|
+
}).optional(),
|
|
24519
|
+
/**
|
|
24520
|
+
* Present if the server offers any tools to call.
|
|
24521
|
+
*/
|
|
24522
|
+
tools: object$1({
|
|
24523
|
+
/**
|
|
24524
|
+
* Whether this server supports issuing notifications for changes to the tool list.
|
|
24525
|
+
*/
|
|
24526
|
+
listChanged: boolean().optional() }).optional(),
|
|
24527
|
+
/**
|
|
24528
|
+
* Present if the server supports task creation.
|
|
24529
|
+
*/
|
|
24530
|
+
tasks: ServerTasksCapabilitySchema.optional(),
|
|
24531
|
+
/**
|
|
24532
|
+
* Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
|
|
24533
|
+
*/
|
|
24534
|
+
extensions: record(string(), AssertObjectSchema).optional()
|
|
24535
|
+
});
|
|
24536
|
+
/**
|
|
24537
|
+
* After receiving an initialize request from the client, the server sends this response.
|
|
24538
|
+
*/
|
|
24539
|
+
const InitializeResultSchema = ResultSchema.extend({
|
|
24540
|
+
/**
|
|
24541
|
+
* The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect.
|
|
24542
|
+
*/
|
|
24543
|
+
protocolVersion: string(),
|
|
24544
|
+
capabilities: ServerCapabilitiesSchema,
|
|
24545
|
+
serverInfo: ImplementationSchema,
|
|
24546
|
+
/**
|
|
24547
|
+
* Instructions describing how to use the server and its features.
|
|
24548
|
+
*
|
|
24549
|
+
* This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt.
|
|
24550
|
+
*/
|
|
24551
|
+
instructions: string().optional()
|
|
24552
|
+
});
|
|
24553
|
+
/**
|
|
24554
|
+
* This notification is sent from the client to the server after initialization has finished.
|
|
24555
|
+
*/
|
|
24556
|
+
const InitializedNotificationSchema = NotificationSchema.extend({
|
|
24557
|
+
method: literal("notifications/initialized"),
|
|
24558
|
+
params: NotificationsParamsSchema.optional()
|
|
24559
|
+
});
|
|
24560
|
+
/**
|
|
24561
|
+
* A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.
|
|
24562
|
+
*/
|
|
24563
|
+
const PingRequestSchema = RequestSchema.extend({
|
|
24564
|
+
method: literal("ping"),
|
|
24565
|
+
params: BaseRequestParamsSchema.optional()
|
|
24566
|
+
});
|
|
24567
|
+
const ProgressSchema = object$1({
|
|
24568
|
+
/**
|
|
24569
|
+
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
24570
|
+
*/
|
|
24571
|
+
progress: number(),
|
|
24572
|
+
/**
|
|
24573
|
+
* Total number of items to process (or total progress required), if known.
|
|
24574
|
+
*/
|
|
24575
|
+
total: optional(number()),
|
|
24576
|
+
/**
|
|
24577
|
+
* An optional message describing the current progress.
|
|
24578
|
+
*/
|
|
24579
|
+
message: optional(string())
|
|
24580
|
+
});
|
|
24581
|
+
const ProgressNotificationParamsSchema = object$1({
|
|
24582
|
+
...NotificationsParamsSchema.shape,
|
|
24583
|
+
...ProgressSchema.shape,
|
|
24584
|
+
/**
|
|
24585
|
+
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
|
|
24586
|
+
*/
|
|
24587
|
+
progressToken: ProgressTokenSchema
|
|
24588
|
+
});
|
|
24589
|
+
/**
|
|
24590
|
+
* An out-of-band notification used to inform the receiver of a progress update for a long-running request.
|
|
24591
|
+
*
|
|
24592
|
+
* @category notifications/progress
|
|
24593
|
+
*/
|
|
24594
|
+
const ProgressNotificationSchema = NotificationSchema.extend({
|
|
24595
|
+
method: literal("notifications/progress"),
|
|
24596
|
+
params: ProgressNotificationParamsSchema
|
|
24597
|
+
});
|
|
24598
|
+
const PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24599
|
+
/**
|
|
24600
|
+
* An opaque token representing the current pagination position.
|
|
24601
|
+
* If provided, the server should return results starting after this cursor.
|
|
24602
|
+
*/
|
|
24603
|
+
cursor: CursorSchema.optional() });
|
|
24604
|
+
const PaginatedRequestSchema = RequestSchema.extend({ params: PaginatedRequestParamsSchema.optional() });
|
|
24605
|
+
const PaginatedResultSchema = ResultSchema.extend({
|
|
24606
|
+
/**
|
|
24607
|
+
* An opaque token representing the pagination position after the last returned result.
|
|
24608
|
+
* If present, there may be more results available.
|
|
24609
|
+
*/
|
|
24610
|
+
nextCursor: CursorSchema.optional() });
|
|
24611
|
+
/**
|
|
24612
|
+
* The status of a task.
|
|
24613
|
+
* */
|
|
24614
|
+
const TaskStatusSchema = _enum([
|
|
24615
|
+
"working",
|
|
24616
|
+
"input_required",
|
|
24617
|
+
"completed",
|
|
24618
|
+
"failed",
|
|
24619
|
+
"cancelled"
|
|
24620
|
+
]);
|
|
24621
|
+
/**
|
|
24622
|
+
* A pollable state object associated with a request.
|
|
24623
|
+
*/
|
|
24624
|
+
const TaskSchema = object$1({
|
|
24625
|
+
taskId: string(),
|
|
24626
|
+
status: TaskStatusSchema,
|
|
24627
|
+
/**
|
|
24628
|
+
* Time in milliseconds to keep task results available after completion.
|
|
24629
|
+
* If null, the task has unlimited lifetime until manually cleaned up.
|
|
24630
|
+
*/
|
|
24631
|
+
ttl: union([number(), _null()]),
|
|
24632
|
+
/**
|
|
24633
|
+
* ISO 8601 timestamp when the task was created.
|
|
24634
|
+
*/
|
|
24635
|
+
createdAt: string(),
|
|
24636
|
+
/**
|
|
24637
|
+
* ISO 8601 timestamp when the task was last updated.
|
|
24638
|
+
*/
|
|
24639
|
+
lastUpdatedAt: string(),
|
|
24640
|
+
pollInterval: optional(number()),
|
|
24641
|
+
/**
|
|
24642
|
+
* Optional diagnostic message for failed tasks or other status information.
|
|
24643
|
+
*/
|
|
24644
|
+
statusMessage: optional(string())
|
|
24645
|
+
});
|
|
24646
|
+
/**
|
|
24647
|
+
* Result returned when a task is created, containing the task data wrapped in a task field.
|
|
24648
|
+
*/
|
|
24649
|
+
const CreateTaskResultSchema = ResultSchema.extend({ task: TaskSchema });
|
|
24650
|
+
/**
|
|
24651
|
+
* Parameters for task status notification.
|
|
24652
|
+
*/
|
|
24653
|
+
const TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
|
|
24654
|
+
/**
|
|
24655
|
+
* A notification sent when a task's status changes.
|
|
24656
|
+
*/
|
|
24657
|
+
const TaskStatusNotificationSchema = NotificationSchema.extend({
|
|
24658
|
+
method: literal("notifications/tasks/status"),
|
|
24659
|
+
params: TaskStatusNotificationParamsSchema
|
|
24660
|
+
});
|
|
24661
|
+
/**
|
|
24662
|
+
* A request to get the state of a specific task.
|
|
24663
|
+
*/
|
|
24664
|
+
const GetTaskRequestSchema = RequestSchema.extend({
|
|
24665
|
+
method: literal("tasks/get"),
|
|
24666
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
24667
|
+
});
|
|
24668
|
+
/**
|
|
24669
|
+
* The response to a tasks/get request.
|
|
24670
|
+
*/
|
|
24671
|
+
const GetTaskResultSchema = ResultSchema.merge(TaskSchema);
|
|
24672
|
+
/**
|
|
24673
|
+
* A request to get the result of a specific task.
|
|
24674
|
+
*/
|
|
24675
|
+
const GetTaskPayloadRequestSchema = RequestSchema.extend({
|
|
24676
|
+
method: literal("tasks/result"),
|
|
24677
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
24678
|
+
});
|
|
24679
|
+
ResultSchema.loose();
|
|
24680
|
+
/**
|
|
24681
|
+
* A request to list tasks.
|
|
24682
|
+
*/
|
|
24683
|
+
const ListTasksRequestSchema = PaginatedRequestSchema.extend({ method: literal("tasks/list") });
|
|
24684
|
+
/**
|
|
24685
|
+
* The response to a tasks/list request.
|
|
24686
|
+
*/
|
|
24687
|
+
const ListTasksResultSchema = PaginatedResultSchema.extend({ tasks: array(TaskSchema) });
|
|
24688
|
+
/**
|
|
24689
|
+
* A request to cancel a specific task.
|
|
24690
|
+
*/
|
|
24691
|
+
const CancelTaskRequestSchema = RequestSchema.extend({
|
|
24692
|
+
method: literal("tasks/cancel"),
|
|
24693
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
24694
|
+
});
|
|
24695
|
+
ResultSchema.merge(TaskSchema);
|
|
24696
|
+
/**
|
|
24697
|
+
* The contents of a specific resource or sub-resource.
|
|
24698
|
+
*/
|
|
24699
|
+
const ResourceContentsSchema = object$1({
|
|
24700
|
+
/**
|
|
24701
|
+
* The URI of this resource.
|
|
24702
|
+
*/
|
|
24703
|
+
uri: string(),
|
|
24704
|
+
/**
|
|
24705
|
+
* The MIME type of this resource, if known.
|
|
24706
|
+
*/
|
|
24707
|
+
mimeType: optional(string()),
|
|
24708
|
+
/**
|
|
24709
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24710
|
+
* for notes on _meta usage.
|
|
24711
|
+
*/
|
|
24712
|
+
_meta: record(string(), unknown()).optional()
|
|
24713
|
+
});
|
|
24714
|
+
const TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
24715
|
+
/**
|
|
24716
|
+
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
|
|
24717
|
+
*/
|
|
24718
|
+
text: string() });
|
|
24719
|
+
/**
|
|
24720
|
+
* A Zod schema for validating Base64 strings that is more performant and
|
|
24721
|
+
* robust for very large inputs than the default regex-based check. It avoids
|
|
24722
|
+
* stack overflows by using the native `atob` function for validation.
|
|
24723
|
+
*/
|
|
24724
|
+
const Base64Schema = string().refine((val) => {
|
|
24725
|
+
try {
|
|
24726
|
+
atob(val);
|
|
24727
|
+
return true;
|
|
24728
|
+
} catch {
|
|
24729
|
+
return false;
|
|
24730
|
+
}
|
|
24731
|
+
}, { message: "Invalid Base64 string" });
|
|
24732
|
+
const BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
24733
|
+
/**
|
|
24734
|
+
* A base64-encoded string representing the binary data of the item.
|
|
24735
|
+
*/
|
|
24736
|
+
blob: Base64Schema });
|
|
24737
|
+
/**
|
|
24738
|
+
* The sender or recipient of messages and data in a conversation.
|
|
24739
|
+
*/
|
|
24740
|
+
const RoleSchema = _enum(["user", "assistant"]);
|
|
24741
|
+
/**
|
|
24742
|
+
* Optional annotations providing clients additional context about a resource.
|
|
24743
|
+
*/
|
|
24744
|
+
const AnnotationsSchema = object$1({
|
|
24745
|
+
/**
|
|
24746
|
+
* Intended audience(s) for the resource.
|
|
24747
|
+
*/
|
|
24748
|
+
audience: array(RoleSchema).optional(),
|
|
24749
|
+
/**
|
|
24750
|
+
* Importance hint for the resource, from 0 (least) to 1 (most).
|
|
24751
|
+
*/
|
|
24752
|
+
priority: number().min(0).max(1).optional(),
|
|
24753
|
+
/**
|
|
24754
|
+
* ISO 8601 timestamp for the most recent modification.
|
|
24755
|
+
*/
|
|
24756
|
+
lastModified: datetime({ offset: true }).optional()
|
|
24757
|
+
});
|
|
24758
|
+
/**
|
|
24759
|
+
* A known resource that the server is capable of reading.
|
|
24760
|
+
*/
|
|
24761
|
+
const ResourceSchema = object$1({
|
|
24762
|
+
...BaseMetadataSchema.shape,
|
|
24763
|
+
...IconsSchema.shape,
|
|
24764
|
+
/**
|
|
24765
|
+
* The URI of this resource.
|
|
24766
|
+
*/
|
|
24767
|
+
uri: string(),
|
|
24768
|
+
/**
|
|
24769
|
+
* A description of what this resource represents.
|
|
24770
|
+
*
|
|
24771
|
+
* This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
|
|
24772
|
+
*/
|
|
24773
|
+
description: optional(string()),
|
|
24774
|
+
/**
|
|
24775
|
+
* The MIME type of this resource, if known.
|
|
24776
|
+
*/
|
|
24777
|
+
mimeType: optional(string()),
|
|
24778
|
+
/**
|
|
24779
|
+
* The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
|
|
24780
|
+
*
|
|
24781
|
+
* This can be used by Hosts to display file sizes and estimate context window usage.
|
|
24782
|
+
*/
|
|
24783
|
+
size: optional(number()),
|
|
24784
|
+
/**
|
|
24785
|
+
* Optional annotations for the client.
|
|
24786
|
+
*/
|
|
24787
|
+
annotations: AnnotationsSchema.optional(),
|
|
24788
|
+
/**
|
|
24789
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24790
|
+
* for notes on _meta usage.
|
|
24791
|
+
*/
|
|
24792
|
+
_meta: optional(looseObject({}))
|
|
24793
|
+
});
|
|
24794
|
+
/**
|
|
24795
|
+
* A template description for resources available on the server.
|
|
24796
|
+
*/
|
|
24797
|
+
const ResourceTemplateSchema = object$1({
|
|
24798
|
+
...BaseMetadataSchema.shape,
|
|
24799
|
+
...IconsSchema.shape,
|
|
24800
|
+
/**
|
|
24801
|
+
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
|
|
24802
|
+
*/
|
|
24803
|
+
uriTemplate: string(),
|
|
24804
|
+
/**
|
|
24805
|
+
* A description of what this template is for.
|
|
24806
|
+
*
|
|
24807
|
+
* This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
|
|
24808
|
+
*/
|
|
24809
|
+
description: optional(string()),
|
|
24810
|
+
/**
|
|
24811
|
+
* 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.
|
|
24812
|
+
*/
|
|
24813
|
+
mimeType: optional(string()),
|
|
24814
|
+
/**
|
|
24815
|
+
* Optional annotations for the client.
|
|
24816
|
+
*/
|
|
24817
|
+
annotations: AnnotationsSchema.optional(),
|
|
24818
|
+
/**
|
|
24819
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24820
|
+
* for notes on _meta usage.
|
|
24821
|
+
*/
|
|
24822
|
+
_meta: optional(looseObject({}))
|
|
24823
|
+
});
|
|
24824
|
+
/**
|
|
24825
|
+
* Sent from the client to request a list of resources the server has.
|
|
24826
|
+
*/
|
|
24827
|
+
const ListResourcesRequestSchema = PaginatedRequestSchema.extend({ method: literal("resources/list") });
|
|
24828
|
+
/**
|
|
24829
|
+
* The server's response to a resources/list request from the client.
|
|
24830
|
+
*/
|
|
24831
|
+
const ListResourcesResultSchema = PaginatedResultSchema.extend({ resources: array(ResourceSchema) });
|
|
24832
|
+
/**
|
|
24833
|
+
* Sent from the client to request a list of resource templates the server has.
|
|
24834
|
+
*/
|
|
24835
|
+
const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({ method: literal("resources/templates/list") });
|
|
24836
|
+
/**
|
|
24837
|
+
* The server's response to a resources/templates/list request from the client.
|
|
24838
|
+
*/
|
|
24839
|
+
const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({ resourceTemplates: array(ResourceTemplateSchema) });
|
|
24840
|
+
const ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24841
|
+
/**
|
|
24842
|
+
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
|
|
24843
|
+
*
|
|
24844
|
+
* @format uri
|
|
24845
|
+
*/
|
|
24846
|
+
uri: string() });
|
|
24847
|
+
/**
|
|
24848
|
+
* Parameters for a `resources/read` request.
|
|
24849
|
+
*/
|
|
24850
|
+
const ReadResourceRequestParamsSchema = ResourceRequestParamsSchema;
|
|
24851
|
+
/**
|
|
24852
|
+
* Sent from the client to the server, to read a specific resource URI.
|
|
24853
|
+
*/
|
|
24854
|
+
const ReadResourceRequestSchema = RequestSchema.extend({
|
|
24855
|
+
method: literal("resources/read"),
|
|
24856
|
+
params: ReadResourceRequestParamsSchema
|
|
24857
|
+
});
|
|
24858
|
+
/**
|
|
24859
|
+
* The server's response to a resources/read request from the client.
|
|
24860
|
+
*/
|
|
24861
|
+
const ReadResourceResultSchema = ResultSchema.extend({ contents: array(union([TextResourceContentsSchema, BlobResourceContentsSchema])) });
|
|
24862
|
+
/**
|
|
24863
|
+
* An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client.
|
|
24864
|
+
*/
|
|
24865
|
+
const ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
24866
|
+
method: literal("notifications/resources/list_changed"),
|
|
24867
|
+
params: NotificationsParamsSchema.optional()
|
|
24868
|
+
});
|
|
24869
|
+
const SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
24870
|
+
/**
|
|
24871
|
+
* Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
|
|
24872
|
+
*/
|
|
24873
|
+
const SubscribeRequestSchema = RequestSchema.extend({
|
|
24874
|
+
method: literal("resources/subscribe"),
|
|
24875
|
+
params: SubscribeRequestParamsSchema
|
|
24876
|
+
});
|
|
24877
|
+
const UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
24878
|
+
/**
|
|
24879
|
+
* Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
|
|
24880
|
+
*/
|
|
24881
|
+
const UnsubscribeRequestSchema = RequestSchema.extend({
|
|
24882
|
+
method: literal("resources/unsubscribe"),
|
|
24883
|
+
params: UnsubscribeRequestParamsSchema
|
|
24884
|
+
});
|
|
24885
|
+
/**
|
|
24886
|
+
* Parameters for a `notifications/resources/updated` notification.
|
|
24887
|
+
*/
|
|
24888
|
+
const ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
24889
|
+
/**
|
|
24890
|
+
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
|
|
24891
|
+
*/
|
|
24892
|
+
uri: string() });
|
|
24893
|
+
/**
|
|
24894
|
+
* A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request.
|
|
24895
|
+
*/
|
|
24896
|
+
const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
24897
|
+
method: literal("notifications/resources/updated"),
|
|
24898
|
+
params: ResourceUpdatedNotificationParamsSchema
|
|
24899
|
+
});
|
|
24900
|
+
/**
|
|
24901
|
+
* Describes an argument that a prompt can accept.
|
|
24902
|
+
*/
|
|
24903
|
+
const PromptArgumentSchema = object$1({
|
|
24904
|
+
/**
|
|
24905
|
+
* The name of the argument.
|
|
24906
|
+
*/
|
|
24907
|
+
name: string(),
|
|
24908
|
+
/**
|
|
24909
|
+
* A human-readable description of the argument.
|
|
24910
|
+
*/
|
|
24911
|
+
description: optional(string()),
|
|
24912
|
+
/**
|
|
24913
|
+
* Whether this argument must be provided.
|
|
24914
|
+
*/
|
|
24915
|
+
required: optional(boolean())
|
|
24916
|
+
});
|
|
24917
|
+
/**
|
|
24918
|
+
* A prompt or prompt template that the server offers.
|
|
24919
|
+
*/
|
|
24920
|
+
const PromptSchema$1 = object$1({
|
|
24921
|
+
...BaseMetadataSchema.shape,
|
|
24922
|
+
...IconsSchema.shape,
|
|
24923
|
+
/**
|
|
24924
|
+
* An optional description of what this prompt provides
|
|
24925
|
+
*/
|
|
24926
|
+
description: optional(string()),
|
|
24927
|
+
/**
|
|
24928
|
+
* A list of arguments to use for templating the prompt.
|
|
24929
|
+
*/
|
|
24930
|
+
arguments: optional(array(PromptArgumentSchema)),
|
|
24931
|
+
/**
|
|
24932
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24933
|
+
* for notes on _meta usage.
|
|
24934
|
+
*/
|
|
24935
|
+
_meta: optional(looseObject({}))
|
|
24936
|
+
});
|
|
24937
|
+
/**
|
|
24938
|
+
* Sent from the client to request a list of prompts and prompt templates the server has.
|
|
24939
|
+
*/
|
|
24940
|
+
const ListPromptsRequestSchema = PaginatedRequestSchema.extend({ method: literal("prompts/list") });
|
|
24941
|
+
/**
|
|
24942
|
+
* The server's response to a prompts/list request from the client.
|
|
24943
|
+
*/
|
|
24944
|
+
const ListPromptsResultSchema = PaginatedResultSchema.extend({ prompts: array(PromptSchema$1) });
|
|
24945
|
+
/**
|
|
24946
|
+
* Parameters for a `prompts/get` request.
|
|
24947
|
+
*/
|
|
24948
|
+
const GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24949
|
+
/**
|
|
24950
|
+
* The name of the prompt or prompt template.
|
|
24951
|
+
*/
|
|
24952
|
+
name: string(),
|
|
24953
|
+
/**
|
|
24954
|
+
* Arguments to use for templating the prompt.
|
|
24955
|
+
*/
|
|
24956
|
+
arguments: record(string(), string()).optional()
|
|
24957
|
+
});
|
|
24958
|
+
/**
|
|
24959
|
+
* Used by the client to get a prompt provided by the server.
|
|
24960
|
+
*/
|
|
24961
|
+
const GetPromptRequestSchema = RequestSchema.extend({
|
|
24962
|
+
method: literal("prompts/get"),
|
|
24963
|
+
params: GetPromptRequestParamsSchema
|
|
24964
|
+
});
|
|
24965
|
+
/**
|
|
24966
|
+
* Text provided to or from an LLM.
|
|
24967
|
+
*/
|
|
24968
|
+
const TextContentSchema = object$1({
|
|
24969
|
+
type: literal("text"),
|
|
24970
|
+
/**
|
|
24971
|
+
* The text content of the message.
|
|
24972
|
+
*/
|
|
24973
|
+
text: string(),
|
|
24974
|
+
/**
|
|
24975
|
+
* Optional annotations for the client.
|
|
24976
|
+
*/
|
|
24977
|
+
annotations: AnnotationsSchema.optional(),
|
|
24978
|
+
/**
|
|
24979
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24980
|
+
* for notes on _meta usage.
|
|
24981
|
+
*/
|
|
24982
|
+
_meta: record(string(), unknown()).optional()
|
|
24983
|
+
});
|
|
24984
|
+
/**
|
|
24985
|
+
* An image provided to or from an LLM.
|
|
24986
|
+
*/
|
|
24987
|
+
const ImageContentSchema = object$1({
|
|
24988
|
+
type: literal("image"),
|
|
24989
|
+
/**
|
|
24990
|
+
* The base64-encoded image data.
|
|
24991
|
+
*/
|
|
24992
|
+
data: Base64Schema,
|
|
24993
|
+
/**
|
|
24994
|
+
* The MIME type of the image. Different providers may support different image types.
|
|
24995
|
+
*/
|
|
24996
|
+
mimeType: string(),
|
|
24997
|
+
/**
|
|
24998
|
+
* Optional annotations for the client.
|
|
24999
|
+
*/
|
|
25000
|
+
annotations: AnnotationsSchema.optional(),
|
|
25001
|
+
/**
|
|
25002
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25003
|
+
* for notes on _meta usage.
|
|
25004
|
+
*/
|
|
25005
|
+
_meta: record(string(), unknown()).optional()
|
|
25006
|
+
});
|
|
25007
|
+
/**
|
|
25008
|
+
* An Audio provided to or from an LLM.
|
|
25009
|
+
*/
|
|
25010
|
+
const AudioContentSchema = object$1({
|
|
25011
|
+
type: literal("audio"),
|
|
25012
|
+
/**
|
|
25013
|
+
* The base64-encoded audio data.
|
|
25014
|
+
*/
|
|
25015
|
+
data: Base64Schema,
|
|
25016
|
+
/**
|
|
25017
|
+
* The MIME type of the audio. Different providers may support different audio types.
|
|
25018
|
+
*/
|
|
25019
|
+
mimeType: string(),
|
|
25020
|
+
/**
|
|
25021
|
+
* Optional annotations for the client.
|
|
25022
|
+
*/
|
|
25023
|
+
annotations: AnnotationsSchema.optional(),
|
|
25024
|
+
/**
|
|
25025
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25026
|
+
* for notes on _meta usage.
|
|
25027
|
+
*/
|
|
25028
|
+
_meta: record(string(), unknown()).optional()
|
|
25029
|
+
});
|
|
25030
|
+
/**
|
|
25031
|
+
* A tool call request from an assistant (LLM).
|
|
25032
|
+
* Represents the assistant's request to use a tool.
|
|
25033
|
+
*/
|
|
25034
|
+
const ToolUseContentSchema = object$1({
|
|
25035
|
+
type: literal("tool_use"),
|
|
25036
|
+
/**
|
|
25037
|
+
* The name of the tool to invoke.
|
|
25038
|
+
* Must match a tool name from the request's tools array.
|
|
25039
|
+
*/
|
|
25040
|
+
name: string(),
|
|
25041
|
+
/**
|
|
25042
|
+
* Unique identifier for this tool call.
|
|
25043
|
+
* Used to correlate with ToolResultContent in subsequent messages.
|
|
25044
|
+
*/
|
|
25045
|
+
id: string(),
|
|
25046
|
+
/**
|
|
25047
|
+
* Arguments to pass to the tool.
|
|
25048
|
+
* Must conform to the tool's inputSchema.
|
|
25049
|
+
*/
|
|
25050
|
+
input: record(string(), unknown()),
|
|
25051
|
+
/**
|
|
25052
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25053
|
+
* for notes on _meta usage.
|
|
25054
|
+
*/
|
|
25055
|
+
_meta: record(string(), unknown()).optional()
|
|
25056
|
+
});
|
|
25057
|
+
/**
|
|
25058
|
+
* The contents of a resource, embedded into a prompt or tool call result.
|
|
25059
|
+
*/
|
|
25060
|
+
const EmbeddedResourceSchema = object$1({
|
|
25061
|
+
type: literal("resource"),
|
|
25062
|
+
resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
|
|
25063
|
+
/**
|
|
25064
|
+
* Optional annotations for the client.
|
|
25065
|
+
*/
|
|
25066
|
+
annotations: AnnotationsSchema.optional(),
|
|
25067
|
+
/**
|
|
25068
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25069
|
+
* for notes on _meta usage.
|
|
25070
|
+
*/
|
|
25071
|
+
_meta: record(string(), unknown()).optional()
|
|
25072
|
+
});
|
|
25073
|
+
/**
|
|
25074
|
+
* A content block that can be used in prompts and tool results.
|
|
25075
|
+
*/
|
|
25076
|
+
const ContentBlockSchema = union([
|
|
25077
|
+
TextContentSchema,
|
|
25078
|
+
ImageContentSchema,
|
|
25079
|
+
AudioContentSchema,
|
|
25080
|
+
ResourceSchema.extend({ type: literal("resource_link") }),
|
|
25081
|
+
EmbeddedResourceSchema
|
|
25082
|
+
]);
|
|
25083
|
+
/**
|
|
25084
|
+
* Describes a message returned as part of a prompt.
|
|
25085
|
+
*/
|
|
25086
|
+
const PromptMessageSchema = object$1({
|
|
25087
|
+
role: RoleSchema,
|
|
25088
|
+
content: ContentBlockSchema
|
|
25089
|
+
});
|
|
25090
|
+
/**
|
|
25091
|
+
* The server's response to a prompts/get request from the client.
|
|
25092
|
+
*/
|
|
25093
|
+
const GetPromptResultSchema = ResultSchema.extend({
|
|
25094
|
+
/**
|
|
25095
|
+
* An optional description for the prompt.
|
|
25096
|
+
*/
|
|
25097
|
+
description: string().optional(),
|
|
25098
|
+
messages: array(PromptMessageSchema)
|
|
25099
|
+
});
|
|
25100
|
+
/**
|
|
25101
|
+
* An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client.
|
|
25102
|
+
*/
|
|
25103
|
+
const PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
25104
|
+
method: literal("notifications/prompts/list_changed"),
|
|
25105
|
+
params: NotificationsParamsSchema.optional()
|
|
25106
|
+
});
|
|
25107
|
+
/**
|
|
25108
|
+
* Additional properties describing a Tool to clients.
|
|
25109
|
+
*
|
|
25110
|
+
* NOTE: all properties in ToolAnnotations are **hints**.
|
|
25111
|
+
* They are not guaranteed to provide a faithful description of
|
|
25112
|
+
* tool behavior (including descriptive properties like `title`).
|
|
25113
|
+
*
|
|
25114
|
+
* Clients should never make tool use decisions based on ToolAnnotations
|
|
25115
|
+
* received from untrusted servers.
|
|
25116
|
+
*/
|
|
25117
|
+
const ToolAnnotationsSchema = object$1({
|
|
25118
|
+
/**
|
|
25119
|
+
* A human-readable title for the tool.
|
|
25120
|
+
*/
|
|
25121
|
+
title: string().optional(),
|
|
25122
|
+
/**
|
|
25123
|
+
* If true, the tool does not modify its environment.
|
|
25124
|
+
*
|
|
25125
|
+
* Default: false
|
|
25126
|
+
*/
|
|
25127
|
+
readOnlyHint: boolean().optional(),
|
|
25128
|
+
/**
|
|
25129
|
+
* If true, the tool may perform destructive updates to its environment.
|
|
25130
|
+
* If false, the tool performs only additive updates.
|
|
25131
|
+
*
|
|
25132
|
+
* (This property is meaningful only when `readOnlyHint == false`)
|
|
25133
|
+
*
|
|
25134
|
+
* Default: true
|
|
25135
|
+
*/
|
|
25136
|
+
destructiveHint: boolean().optional(),
|
|
25137
|
+
/**
|
|
25138
|
+
* If true, calling the tool repeatedly with the same arguments
|
|
25139
|
+
* will have no additional effect on the its environment.
|
|
25140
|
+
*
|
|
25141
|
+
* (This property is meaningful only when `readOnlyHint == false`)
|
|
25142
|
+
*
|
|
25143
|
+
* Default: false
|
|
25144
|
+
*/
|
|
25145
|
+
idempotentHint: boolean().optional(),
|
|
25146
|
+
/**
|
|
25147
|
+
* If true, this tool may interact with an "open world" of external
|
|
25148
|
+
* entities. If false, the tool's domain of interaction is closed.
|
|
25149
|
+
* For example, the world of a web search tool is open, whereas that
|
|
25150
|
+
* of a memory tool is not.
|
|
25151
|
+
*
|
|
25152
|
+
* Default: true
|
|
25153
|
+
*/
|
|
25154
|
+
openWorldHint: boolean().optional()
|
|
25155
|
+
});
|
|
25156
|
+
/**
|
|
25157
|
+
* Execution-related properties for a tool.
|
|
25158
|
+
*/
|
|
25159
|
+
const ToolExecutionSchema = object$1({
|
|
25160
|
+
/**
|
|
25161
|
+
* Indicates the tool's preference for task-augmented execution.
|
|
25162
|
+
* - "required": Clients MUST invoke the tool as a task
|
|
25163
|
+
* - "optional": Clients MAY invoke the tool as a task or normal request
|
|
25164
|
+
* - "forbidden": Clients MUST NOT attempt to invoke the tool as a task
|
|
25165
|
+
*
|
|
25166
|
+
* If not present, defaults to "forbidden".
|
|
25167
|
+
*/
|
|
25168
|
+
taskSupport: _enum([
|
|
25169
|
+
"required",
|
|
25170
|
+
"optional",
|
|
25171
|
+
"forbidden"
|
|
25172
|
+
]).optional() });
|
|
25173
|
+
/**
|
|
25174
|
+
* Definition for a tool the client can call.
|
|
25175
|
+
*/
|
|
25176
|
+
const ToolSchema = object$1({
|
|
25177
|
+
...BaseMetadataSchema.shape,
|
|
25178
|
+
...IconsSchema.shape,
|
|
25179
|
+
/**
|
|
25180
|
+
* A human-readable description of the tool.
|
|
25181
|
+
*/
|
|
25182
|
+
description: string().optional(),
|
|
25183
|
+
/**
|
|
25184
|
+
* A JSON Schema 2020-12 object defining the expected parameters for the tool.
|
|
25185
|
+
* Must have type: 'object' at the root level per MCP spec.
|
|
25186
|
+
*/
|
|
25187
|
+
inputSchema: object$1({
|
|
25188
|
+
type: literal("object"),
|
|
25189
|
+
properties: record(string(), AssertObjectSchema).optional(),
|
|
25190
|
+
required: array(string()).optional()
|
|
25191
|
+
}).catchall(unknown()),
|
|
25192
|
+
/**
|
|
25193
|
+
* An optional JSON Schema 2020-12 object defining the structure of the tool's output
|
|
25194
|
+
* returned in the structuredContent field of a CallToolResult.
|
|
25195
|
+
* Must have type: 'object' at the root level per MCP spec.
|
|
25196
|
+
*/
|
|
25197
|
+
outputSchema: object$1({
|
|
25198
|
+
type: literal("object"),
|
|
25199
|
+
properties: record(string(), AssertObjectSchema).optional(),
|
|
25200
|
+
required: array(string()).optional()
|
|
25201
|
+
}).catchall(unknown()).optional(),
|
|
25202
|
+
/**
|
|
25203
|
+
* Optional additional tool information.
|
|
25204
|
+
*/
|
|
25205
|
+
annotations: ToolAnnotationsSchema.optional(),
|
|
25206
|
+
/**
|
|
25207
|
+
* Execution-related properties for this tool.
|
|
25208
|
+
*/
|
|
25209
|
+
execution: ToolExecutionSchema.optional(),
|
|
25210
|
+
/**
|
|
25211
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25212
|
+
* for notes on _meta usage.
|
|
25213
|
+
*/
|
|
25214
|
+
_meta: record(string(), unknown()).optional()
|
|
25215
|
+
});
|
|
25216
|
+
/**
|
|
25217
|
+
* Sent from the client to request a list of tools the server has.
|
|
25218
|
+
*/
|
|
25219
|
+
const ListToolsRequestSchema = PaginatedRequestSchema.extend({ method: literal("tools/list") });
|
|
25220
|
+
/**
|
|
25221
|
+
* The server's response to a tools/list request from the client.
|
|
25222
|
+
*/
|
|
25223
|
+
const ListToolsResultSchema = PaginatedResultSchema.extend({ tools: array(ToolSchema) });
|
|
25224
|
+
/**
|
|
25225
|
+
* The server's response to a tool call.
|
|
25226
|
+
*/
|
|
25227
|
+
const CallToolResultSchema = ResultSchema.extend({
|
|
25228
|
+
/**
|
|
25229
|
+
* A list of content objects that represent the result of the tool call.
|
|
25230
|
+
*
|
|
25231
|
+
* If the Tool does not define an outputSchema, this field MUST be present in the result.
|
|
25232
|
+
* For backwards compatibility, this field is always present, but it may be empty.
|
|
25233
|
+
*/
|
|
25234
|
+
content: array(ContentBlockSchema).default([]),
|
|
25235
|
+
/**
|
|
25236
|
+
* An object containing structured tool output.
|
|
25237
|
+
*
|
|
25238
|
+
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
|
|
25239
|
+
*/
|
|
25240
|
+
structuredContent: record(string(), unknown()).optional(),
|
|
25241
|
+
/**
|
|
25242
|
+
* Whether the tool call ended in an error.
|
|
25243
|
+
*
|
|
25244
|
+
* If not set, this is assumed to be false (the call was successful).
|
|
25245
|
+
*
|
|
25246
|
+
* Any errors that originate from the tool SHOULD be reported inside the result
|
|
25247
|
+
* object, with `isError` set to true, _not_ as an MCP protocol-level error
|
|
25248
|
+
* response. Otherwise, the LLM would not be able to see that an error occurred
|
|
25249
|
+
* and self-correct.
|
|
25250
|
+
*
|
|
25251
|
+
* However, any errors in _finding_ the tool, an error indicating that the
|
|
25252
|
+
* server does not support tool calls, or any other exceptional conditions,
|
|
25253
|
+
* should be reported as an MCP error response.
|
|
25254
|
+
*/
|
|
25255
|
+
isError: boolean().optional()
|
|
25256
|
+
});
|
|
25257
|
+
CallToolResultSchema.or(ResultSchema.extend({ toolResult: unknown() }));
|
|
25258
|
+
/**
|
|
25259
|
+
* Parameters for a `tools/call` request.
|
|
25260
|
+
*/
|
|
25261
|
+
const CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
25262
|
+
/**
|
|
25263
|
+
* The name of the tool to call.
|
|
25264
|
+
*/
|
|
25265
|
+
name: string(),
|
|
25266
|
+
/**
|
|
25267
|
+
* Arguments to pass to the tool.
|
|
25268
|
+
*/
|
|
25269
|
+
arguments: record(string(), unknown()).optional()
|
|
25270
|
+
});
|
|
25271
|
+
/**
|
|
25272
|
+
* Used by the client to invoke a tool provided by the server.
|
|
25273
|
+
*/
|
|
25274
|
+
const CallToolRequestSchema = RequestSchema.extend({
|
|
25275
|
+
method: literal("tools/call"),
|
|
25276
|
+
params: CallToolRequestParamsSchema
|
|
25277
|
+
});
|
|
25278
|
+
/**
|
|
25279
|
+
* An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client.
|
|
25280
|
+
*/
|
|
25281
|
+
const ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
25282
|
+
method: literal("notifications/tools/list_changed"),
|
|
25283
|
+
params: NotificationsParamsSchema.optional()
|
|
25284
|
+
});
|
|
25285
|
+
object$1({
|
|
25286
|
+
/**
|
|
25287
|
+
* If true, the list will be refreshed automatically when a list changed notification is received.
|
|
25288
|
+
* The callback will be called with the updated list.
|
|
25289
|
+
*
|
|
25290
|
+
* If false, the callback will be called with null items, allowing manual refresh.
|
|
25291
|
+
*
|
|
25292
|
+
* @default true
|
|
25293
|
+
*/
|
|
25294
|
+
autoRefresh: boolean().default(true),
|
|
25295
|
+
/**
|
|
25296
|
+
* Debounce time in milliseconds for list changed notification processing.
|
|
25297
|
+
*
|
|
25298
|
+
* Multiple notifications received within this timeframe will only trigger one refresh.
|
|
25299
|
+
* Set to 0 to disable debouncing.
|
|
25300
|
+
*
|
|
25301
|
+
* @default 300
|
|
25302
|
+
*/
|
|
25303
|
+
debounceMs: number().int().nonnegative().default(300)
|
|
25304
|
+
});
|
|
25305
|
+
/**
|
|
25306
|
+
* The severity of a log message.
|
|
25307
|
+
*/
|
|
25308
|
+
const LoggingLevelSchema = _enum([
|
|
25309
|
+
"debug",
|
|
25310
|
+
"info",
|
|
25311
|
+
"notice",
|
|
25312
|
+
"warning",
|
|
25313
|
+
"error",
|
|
25314
|
+
"critical",
|
|
25315
|
+
"alert",
|
|
25316
|
+
"emergency"
|
|
25317
|
+
]);
|
|
25318
|
+
/**
|
|
25319
|
+
* Parameters for a `logging/setLevel` request.
|
|
25320
|
+
*/
|
|
25321
|
+
const SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
25322
|
+
/**
|
|
25323
|
+
* The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.
|
|
25324
|
+
*/
|
|
25325
|
+
level: LoggingLevelSchema });
|
|
25326
|
+
/**
|
|
25327
|
+
* A request from the client to the server, to enable or adjust logging.
|
|
25328
|
+
*/
|
|
25329
|
+
const SetLevelRequestSchema = RequestSchema.extend({
|
|
25330
|
+
method: literal("logging/setLevel"),
|
|
25331
|
+
params: SetLevelRequestParamsSchema
|
|
25332
|
+
});
|
|
25333
|
+
/**
|
|
25334
|
+
* Parameters for a `notifications/message` notification.
|
|
25335
|
+
*/
|
|
25336
|
+
const LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
25337
|
+
/**
|
|
25338
|
+
* The severity of this log message.
|
|
25339
|
+
*/
|
|
25340
|
+
level: LoggingLevelSchema,
|
|
25341
|
+
/**
|
|
25342
|
+
* An optional name of the logger issuing this message.
|
|
25343
|
+
*/
|
|
25344
|
+
logger: string().optional(),
|
|
25345
|
+
/**
|
|
25346
|
+
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
|
|
25347
|
+
*/
|
|
25348
|
+
data: unknown()
|
|
25349
|
+
});
|
|
25350
|
+
/**
|
|
25351
|
+
* Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically.
|
|
25352
|
+
*/
|
|
25353
|
+
const LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
25354
|
+
method: literal("notifications/message"),
|
|
25355
|
+
params: LoggingMessageNotificationParamsSchema
|
|
25356
|
+
});
|
|
25357
|
+
/**
|
|
25358
|
+
* The server's preferences for model selection, requested of the client during sampling.
|
|
25359
|
+
*/
|
|
25360
|
+
const ModelPreferencesSchema = object$1({
|
|
25361
|
+
/**
|
|
25362
|
+
* Optional hints to use for model selection.
|
|
25363
|
+
*/
|
|
25364
|
+
hints: array(object$1({
|
|
25365
|
+
/**
|
|
25366
|
+
* A hint for a model name.
|
|
25367
|
+
*/
|
|
25368
|
+
name: string().optional() })).optional(),
|
|
25369
|
+
/**
|
|
25370
|
+
* How much to prioritize cost when selecting a model.
|
|
25371
|
+
*/
|
|
25372
|
+
costPriority: number().min(0).max(1).optional(),
|
|
25373
|
+
/**
|
|
25374
|
+
* How much to prioritize sampling speed (latency) when selecting a model.
|
|
25375
|
+
*/
|
|
25376
|
+
speedPriority: number().min(0).max(1).optional(),
|
|
25377
|
+
/**
|
|
25378
|
+
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
25379
|
+
*/
|
|
25380
|
+
intelligencePriority: number().min(0).max(1).optional()
|
|
25381
|
+
});
|
|
25382
|
+
/**
|
|
25383
|
+
* Controls tool usage behavior in sampling requests.
|
|
25384
|
+
*/
|
|
25385
|
+
const ToolChoiceSchema = object$1({
|
|
25386
|
+
/**
|
|
25387
|
+
* Controls when tools are used:
|
|
25388
|
+
* - "auto": Model decides whether to use tools (default)
|
|
25389
|
+
* - "required": Model MUST use at least one tool before completing
|
|
25390
|
+
* - "none": Model MUST NOT use any tools
|
|
25391
|
+
*/
|
|
25392
|
+
mode: _enum([
|
|
25393
|
+
"auto",
|
|
25394
|
+
"required",
|
|
25395
|
+
"none"
|
|
25396
|
+
]).optional() });
|
|
25397
|
+
/**
|
|
25398
|
+
* The result of a tool execution, provided by the user (server).
|
|
25399
|
+
* Represents the outcome of invoking a tool requested via ToolUseContent.
|
|
25400
|
+
*/
|
|
25401
|
+
const ToolResultContentSchema = object$1({
|
|
25402
|
+
type: literal("tool_result"),
|
|
25403
|
+
toolUseId: string().describe("The unique identifier for the corresponding tool call."),
|
|
25404
|
+
content: array(ContentBlockSchema).default([]),
|
|
25405
|
+
structuredContent: object$1({}).loose().optional(),
|
|
25406
|
+
isError: boolean().optional(),
|
|
25407
|
+
/**
|
|
25408
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25409
|
+
* for notes on _meta usage.
|
|
25410
|
+
*/
|
|
25411
|
+
_meta: record(string(), unknown()).optional()
|
|
25412
|
+
});
|
|
25413
|
+
/**
|
|
25414
|
+
* Basic content types for sampling responses (without tool use).
|
|
25415
|
+
* Used for backwards-compatible CreateMessageResult when tools are not used.
|
|
25416
|
+
*/
|
|
25417
|
+
const SamplingContentSchema = discriminatedUnion("type", [
|
|
25418
|
+
TextContentSchema,
|
|
25419
|
+
ImageContentSchema,
|
|
25420
|
+
AudioContentSchema
|
|
25421
|
+
]);
|
|
25422
|
+
/**
|
|
25423
|
+
* Content block types allowed in sampling messages.
|
|
25424
|
+
* This includes text, image, audio, tool use requests, and tool results.
|
|
25425
|
+
*/
|
|
25426
|
+
const SamplingMessageContentBlockSchema = discriminatedUnion("type", [
|
|
25427
|
+
TextContentSchema,
|
|
25428
|
+
ImageContentSchema,
|
|
25429
|
+
AudioContentSchema,
|
|
25430
|
+
ToolUseContentSchema,
|
|
25431
|
+
ToolResultContentSchema
|
|
25432
|
+
]);
|
|
25433
|
+
/**
|
|
25434
|
+
* Describes a message issued to or received from an LLM API.
|
|
25435
|
+
*/
|
|
25436
|
+
const SamplingMessageSchema = object$1({
|
|
25437
|
+
role: RoleSchema,
|
|
25438
|
+
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)]),
|
|
25439
|
+
/**
|
|
25440
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25441
|
+
* for notes on _meta usage.
|
|
25442
|
+
*/
|
|
25443
|
+
_meta: record(string(), unknown()).optional()
|
|
25444
|
+
});
|
|
25445
|
+
/**
|
|
25446
|
+
* Parameters for a `sampling/createMessage` request.
|
|
25447
|
+
*/
|
|
25448
|
+
const CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
25449
|
+
messages: array(SamplingMessageSchema),
|
|
25450
|
+
/**
|
|
25451
|
+
* The server's preferences for which model to select. The client MAY modify or omit this request.
|
|
25452
|
+
*/
|
|
25453
|
+
modelPreferences: ModelPreferencesSchema.optional(),
|
|
25454
|
+
/**
|
|
25455
|
+
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
|
|
25456
|
+
*/
|
|
25457
|
+
systemPrompt: string().optional(),
|
|
25458
|
+
/**
|
|
25459
|
+
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt.
|
|
25460
|
+
* The client MAY ignore this request.
|
|
25461
|
+
*
|
|
25462
|
+
* Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client
|
|
25463
|
+
* declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
|
|
25464
|
+
*/
|
|
25465
|
+
includeContext: _enum([
|
|
25466
|
+
"none",
|
|
25467
|
+
"thisServer",
|
|
25468
|
+
"allServers"
|
|
25469
|
+
]).optional(),
|
|
25470
|
+
temperature: number().optional(),
|
|
25471
|
+
/**
|
|
25472
|
+
* The requested maximum number of tokens to sample (to prevent runaway completions).
|
|
25473
|
+
*
|
|
25474
|
+
* The client MAY choose to sample fewer tokens than the requested maximum.
|
|
25475
|
+
*/
|
|
25476
|
+
maxTokens: number().int(),
|
|
25477
|
+
stopSequences: array(string()).optional(),
|
|
25478
|
+
/**
|
|
25479
|
+
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
25480
|
+
*/
|
|
25481
|
+
metadata: AssertObjectSchema.optional(),
|
|
25482
|
+
/**
|
|
25483
|
+
* Tools that the model may use during generation.
|
|
25484
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
25485
|
+
*/
|
|
25486
|
+
tools: array(ToolSchema).optional(),
|
|
25487
|
+
/**
|
|
25488
|
+
* Controls how the model uses tools.
|
|
25489
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
25490
|
+
* Default is `{ mode: "auto" }`.
|
|
25491
|
+
*/
|
|
25492
|
+
toolChoice: ToolChoiceSchema.optional()
|
|
25493
|
+
});
|
|
25494
|
+
/**
|
|
25495
|
+
* A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it.
|
|
25496
|
+
*/
|
|
25497
|
+
const CreateMessageRequestSchema = RequestSchema.extend({
|
|
25498
|
+
method: literal("sampling/createMessage"),
|
|
25499
|
+
params: CreateMessageRequestParamsSchema
|
|
25500
|
+
});
|
|
25501
|
+
/**
|
|
25502
|
+
* The client's response to a sampling/create_message request from the server.
|
|
25503
|
+
* This is the backwards-compatible version that returns single content (no arrays).
|
|
25504
|
+
* Used when the request does not include tools.
|
|
25505
|
+
*/
|
|
25506
|
+
const CreateMessageResultSchema = ResultSchema.extend({
|
|
25507
|
+
/**
|
|
25508
|
+
* The name of the model that generated the message.
|
|
25509
|
+
*/
|
|
25510
|
+
model: string(),
|
|
25511
|
+
/**
|
|
25512
|
+
* The reason why sampling stopped, if known.
|
|
25513
|
+
*
|
|
25514
|
+
* Standard values:
|
|
25515
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
25516
|
+
* - "stopSequence": A stop sequence was encountered
|
|
25517
|
+
* - "maxTokens": Maximum token limit was reached
|
|
25518
|
+
*
|
|
25519
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
25520
|
+
*/
|
|
25521
|
+
stopReason: optional(_enum([
|
|
25522
|
+
"endTurn",
|
|
25523
|
+
"stopSequence",
|
|
25524
|
+
"maxTokens"
|
|
25525
|
+
]).or(string())),
|
|
25526
|
+
role: RoleSchema,
|
|
25527
|
+
/**
|
|
25528
|
+
* Response content. Single content block (text, image, or audio).
|
|
25529
|
+
*/
|
|
25530
|
+
content: SamplingContentSchema
|
|
25531
|
+
});
|
|
25532
|
+
/**
|
|
25533
|
+
* The client's response to a sampling/create_message request when tools were provided.
|
|
25534
|
+
* This version supports array content for tool use flows.
|
|
25535
|
+
*/
|
|
25536
|
+
const CreateMessageResultWithToolsSchema = ResultSchema.extend({
|
|
25537
|
+
/**
|
|
25538
|
+
* The name of the model that generated the message.
|
|
25539
|
+
*/
|
|
25540
|
+
model: string(),
|
|
25541
|
+
/**
|
|
25542
|
+
* The reason why sampling stopped, if known.
|
|
25543
|
+
*
|
|
25544
|
+
* Standard values:
|
|
25545
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
25546
|
+
* - "stopSequence": A stop sequence was encountered
|
|
25547
|
+
* - "maxTokens": Maximum token limit was reached
|
|
25548
|
+
* - "toolUse": The model wants to use one or more tools
|
|
25549
|
+
*
|
|
25550
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
25551
|
+
*/
|
|
25552
|
+
stopReason: optional(_enum([
|
|
25553
|
+
"endTurn",
|
|
25554
|
+
"stopSequence",
|
|
25555
|
+
"maxTokens",
|
|
25556
|
+
"toolUse"
|
|
25557
|
+
]).or(string())),
|
|
25558
|
+
role: RoleSchema,
|
|
25559
|
+
/**
|
|
25560
|
+
* Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
|
|
25561
|
+
*/
|
|
25562
|
+
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)])
|
|
25563
|
+
});
|
|
25564
|
+
/**
|
|
25565
|
+
* Primitive schema definition for boolean fields.
|
|
25566
|
+
*/
|
|
25567
|
+
const BooleanSchemaSchema = object$1({
|
|
25568
|
+
type: literal("boolean"),
|
|
25569
|
+
title: string().optional(),
|
|
25570
|
+
description: string().optional(),
|
|
25571
|
+
default: boolean().optional()
|
|
25572
|
+
});
|
|
25573
|
+
/**
|
|
25574
|
+
* Primitive schema definition for string fields.
|
|
25575
|
+
*/
|
|
25576
|
+
const StringSchemaSchema = object$1({
|
|
25577
|
+
type: literal("string"),
|
|
25578
|
+
title: string().optional(),
|
|
25579
|
+
description: string().optional(),
|
|
25580
|
+
minLength: number().optional(),
|
|
25581
|
+
maxLength: number().optional(),
|
|
25582
|
+
format: _enum([
|
|
25583
|
+
"email",
|
|
25584
|
+
"uri",
|
|
25585
|
+
"date",
|
|
25586
|
+
"date-time"
|
|
25587
|
+
]).optional(),
|
|
25588
|
+
default: string().optional()
|
|
25589
|
+
});
|
|
25590
|
+
/**
|
|
25591
|
+
* Primitive schema definition for number fields.
|
|
25592
|
+
*/
|
|
25593
|
+
const NumberSchemaSchema = object$1({
|
|
25594
|
+
type: _enum(["number", "integer"]),
|
|
25595
|
+
title: string().optional(),
|
|
25596
|
+
description: string().optional(),
|
|
25597
|
+
minimum: number().optional(),
|
|
25598
|
+
maximum: number().optional(),
|
|
25599
|
+
default: number().optional()
|
|
25600
|
+
});
|
|
25601
|
+
/**
|
|
25602
|
+
* Schema for single-selection enumeration without display titles for options.
|
|
25603
|
+
*/
|
|
25604
|
+
const UntitledSingleSelectEnumSchemaSchema = object$1({
|
|
25605
|
+
type: literal("string"),
|
|
25606
|
+
title: string().optional(),
|
|
25607
|
+
description: string().optional(),
|
|
25608
|
+
enum: array(string()),
|
|
25609
|
+
default: string().optional()
|
|
25610
|
+
});
|
|
25611
|
+
/**
|
|
25612
|
+
* Schema for single-selection enumeration with display titles for each option.
|
|
25613
|
+
*/
|
|
25614
|
+
const TitledSingleSelectEnumSchemaSchema = object$1({
|
|
25615
|
+
type: literal("string"),
|
|
25616
|
+
title: string().optional(),
|
|
25617
|
+
description: string().optional(),
|
|
25618
|
+
oneOf: array(object$1({
|
|
25619
|
+
const: string(),
|
|
25620
|
+
title: string()
|
|
25621
|
+
})),
|
|
25622
|
+
default: string().optional()
|
|
25623
|
+
});
|
|
25624
|
+
/**
|
|
25625
|
+
* Union of all primitive schema definitions.
|
|
25626
|
+
*/
|
|
25627
|
+
const PrimitiveSchemaDefinitionSchema = union([
|
|
25628
|
+
union([
|
|
25629
|
+
object$1({
|
|
25630
|
+
type: literal("string"),
|
|
25631
|
+
title: string().optional(),
|
|
25632
|
+
description: string().optional(),
|
|
25633
|
+
enum: array(string()),
|
|
25634
|
+
enumNames: array(string()).optional(),
|
|
25635
|
+
default: string().optional()
|
|
25636
|
+
}),
|
|
25637
|
+
union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]),
|
|
25638
|
+
union([object$1({
|
|
25639
|
+
type: literal("array"),
|
|
25640
|
+
title: string().optional(),
|
|
25641
|
+
description: string().optional(),
|
|
25642
|
+
minItems: number().optional(),
|
|
25643
|
+
maxItems: number().optional(),
|
|
25644
|
+
items: object$1({
|
|
25645
|
+
type: literal("string"),
|
|
25646
|
+
enum: array(string())
|
|
25647
|
+
}),
|
|
25648
|
+
default: array(string()).optional()
|
|
25649
|
+
}), object$1({
|
|
25650
|
+
type: literal("array"),
|
|
25651
|
+
title: string().optional(),
|
|
25652
|
+
description: string().optional(),
|
|
25653
|
+
minItems: number().optional(),
|
|
25654
|
+
maxItems: number().optional(),
|
|
25655
|
+
items: object$1({ anyOf: array(object$1({
|
|
25656
|
+
const: string(),
|
|
25657
|
+
title: string()
|
|
25658
|
+
})) }),
|
|
25659
|
+
default: array(string()).optional()
|
|
25660
|
+
})])
|
|
25661
|
+
]),
|
|
25662
|
+
BooleanSchemaSchema,
|
|
25663
|
+
StringSchemaSchema,
|
|
25664
|
+
NumberSchemaSchema
|
|
25665
|
+
]);
|
|
25666
|
+
/**
|
|
25667
|
+
* The parameters for a request to elicit additional information from the user via the client.
|
|
25668
|
+
*/
|
|
25669
|
+
const ElicitRequestParamsSchema = union([TaskAugmentedRequestParamsSchema.extend({
|
|
25670
|
+
/**
|
|
25671
|
+
* The elicitation mode.
|
|
25672
|
+
*
|
|
25673
|
+
* Optional for backward compatibility. Clients MUST treat missing mode as "form".
|
|
25674
|
+
*/
|
|
25675
|
+
mode: literal("form").optional(),
|
|
25676
|
+
/**
|
|
25677
|
+
* The message to present to the user describing what information is being requested.
|
|
25678
|
+
*/
|
|
25679
|
+
message: string(),
|
|
25680
|
+
/**
|
|
25681
|
+
* A restricted subset of JSON Schema.
|
|
25682
|
+
* Only top-level properties are allowed, without nesting.
|
|
25683
|
+
*/
|
|
25684
|
+
requestedSchema: object$1({
|
|
25685
|
+
type: literal("object"),
|
|
25686
|
+
properties: record(string(), PrimitiveSchemaDefinitionSchema),
|
|
25687
|
+
required: array(string()).optional()
|
|
25688
|
+
})
|
|
25689
|
+
}), TaskAugmentedRequestParamsSchema.extend({
|
|
25690
|
+
/**
|
|
25691
|
+
* The elicitation mode.
|
|
25692
|
+
*/
|
|
25693
|
+
mode: literal("url"),
|
|
25694
|
+
/**
|
|
25695
|
+
* The message to present to the user explaining why the interaction is needed.
|
|
25696
|
+
*/
|
|
25697
|
+
message: string(),
|
|
25698
|
+
/**
|
|
25699
|
+
* The ID of the elicitation, which must be unique within the context of the server.
|
|
25700
|
+
* The client MUST treat this ID as an opaque value.
|
|
25701
|
+
*/
|
|
25702
|
+
elicitationId: string(),
|
|
25703
|
+
/**
|
|
25704
|
+
* The URL that the user should navigate to.
|
|
25705
|
+
*/
|
|
25706
|
+
url: string().url()
|
|
25707
|
+
})]);
|
|
25708
|
+
/**
|
|
25709
|
+
* A request from the server to elicit user input via the client.
|
|
25710
|
+
* The client should present the message and form fields to the user (form mode)
|
|
25711
|
+
* or navigate to a URL (URL mode).
|
|
25712
|
+
*/
|
|
25713
|
+
const ElicitRequestSchema = RequestSchema.extend({
|
|
25714
|
+
method: literal("elicitation/create"),
|
|
25715
|
+
params: ElicitRequestParamsSchema
|
|
25716
|
+
});
|
|
25717
|
+
/**
|
|
25718
|
+
* Parameters for a `notifications/elicitation/complete` notification.
|
|
25719
|
+
*
|
|
25720
|
+
* @category notifications/elicitation/complete
|
|
25721
|
+
*/
|
|
25722
|
+
const ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
25723
|
+
/**
|
|
25724
|
+
* The ID of the elicitation that completed.
|
|
25725
|
+
*/
|
|
25726
|
+
elicitationId: string() });
|
|
25727
|
+
/**
|
|
25728
|
+
* A notification from the server to the client, informing it of a completion of an out-of-band elicitation request.
|
|
25729
|
+
*
|
|
25730
|
+
* @category notifications/elicitation/complete
|
|
25731
|
+
*/
|
|
25732
|
+
const ElicitationCompleteNotificationSchema = NotificationSchema.extend({
|
|
25733
|
+
method: literal("notifications/elicitation/complete"),
|
|
25734
|
+
params: ElicitationCompleteNotificationParamsSchema
|
|
25735
|
+
});
|
|
25736
|
+
/**
|
|
25737
|
+
* The client's response to an elicitation/create request from the server.
|
|
25738
|
+
*/
|
|
25739
|
+
const ElicitResultSchema = ResultSchema.extend({
|
|
25740
|
+
/**
|
|
25741
|
+
* The user action in response to the elicitation.
|
|
25742
|
+
* - "accept": User submitted the form/confirmed the action
|
|
25743
|
+
* - "decline": User explicitly decline the action
|
|
25744
|
+
* - "cancel": User dismissed without making an explicit choice
|
|
25745
|
+
*/
|
|
25746
|
+
action: _enum([
|
|
25747
|
+
"accept",
|
|
25748
|
+
"decline",
|
|
25749
|
+
"cancel"
|
|
25750
|
+
]),
|
|
25751
|
+
/**
|
|
25752
|
+
* The submitted form data, only present when action is "accept".
|
|
25753
|
+
* Contains values matching the requested schema.
|
|
25754
|
+
* Per MCP spec, content is "typically omitted" for decline/cancel actions.
|
|
25755
|
+
* We normalize null to undefined for leniency while maintaining type compatibility.
|
|
25756
|
+
*/
|
|
25757
|
+
content: preprocess((val) => val === null ? void 0 : val, record(string(), union([
|
|
25758
|
+
string(),
|
|
25759
|
+
number(),
|
|
25760
|
+
boolean(),
|
|
25761
|
+
array(string())
|
|
25762
|
+
])).optional())
|
|
25763
|
+
});
|
|
25764
|
+
/**
|
|
25765
|
+
* A reference to a resource or resource template definition.
|
|
25766
|
+
*/
|
|
25767
|
+
const ResourceTemplateReferenceSchema = object$1({
|
|
25768
|
+
type: literal("ref/resource"),
|
|
25769
|
+
/**
|
|
25770
|
+
* The URI or URI template of the resource.
|
|
25771
|
+
*/
|
|
25772
|
+
uri: string()
|
|
25773
|
+
});
|
|
25774
|
+
/**
|
|
25775
|
+
* Identifies a prompt.
|
|
25776
|
+
*/
|
|
25777
|
+
const PromptReferenceSchema = object$1({
|
|
25778
|
+
type: literal("ref/prompt"),
|
|
25779
|
+
/**
|
|
25780
|
+
* The name of the prompt or prompt template
|
|
25781
|
+
*/
|
|
25782
|
+
name: string()
|
|
25783
|
+
});
|
|
25784
|
+
/**
|
|
25785
|
+
* Parameters for a `completion/complete` request.
|
|
25786
|
+
*/
|
|
25787
|
+
const CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
25788
|
+
ref: union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
|
|
25789
|
+
/**
|
|
25790
|
+
* The argument's information
|
|
25791
|
+
*/
|
|
25792
|
+
argument: object$1({
|
|
25793
|
+
/**
|
|
25794
|
+
* The name of the argument
|
|
25795
|
+
*/
|
|
25796
|
+
name: string(),
|
|
25797
|
+
/**
|
|
25798
|
+
* The value of the argument to use for completion matching.
|
|
25799
|
+
*/
|
|
25800
|
+
value: string()
|
|
25801
|
+
}),
|
|
25802
|
+
context: object$1({
|
|
25803
|
+
/**
|
|
25804
|
+
* Previously-resolved variables in a URI template or prompt.
|
|
25805
|
+
*/
|
|
25806
|
+
arguments: record(string(), string()).optional() }).optional()
|
|
25807
|
+
});
|
|
25808
|
+
/**
|
|
25809
|
+
* A request from the client to the server, to ask for completion options.
|
|
25810
|
+
*/
|
|
25811
|
+
const CompleteRequestSchema = RequestSchema.extend({
|
|
25812
|
+
method: literal("completion/complete"),
|
|
25813
|
+
params: CompleteRequestParamsSchema
|
|
25814
|
+
});
|
|
25815
|
+
/**
|
|
25816
|
+
* The server's response to a completion/complete request
|
|
25817
|
+
*/
|
|
25818
|
+
const CompleteResultSchema = ResultSchema.extend({ completion: looseObject({
|
|
25819
|
+
/**
|
|
25820
|
+
* An array of completion values. Must not exceed 100 items.
|
|
25821
|
+
*/
|
|
25822
|
+
values: array(string()).max(100),
|
|
25823
|
+
/**
|
|
25824
|
+
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
25825
|
+
*/
|
|
25826
|
+
total: optional(number().int()),
|
|
25827
|
+
/**
|
|
25828
|
+
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
25829
|
+
*/
|
|
25830
|
+
hasMore: optional(boolean())
|
|
25831
|
+
}) });
|
|
25832
|
+
/**
|
|
25833
|
+
* Represents a root directory or file that the server can operate on.
|
|
25834
|
+
*/
|
|
25835
|
+
const RootSchema = object$1({
|
|
25836
|
+
/**
|
|
25837
|
+
* The URI identifying the root. This *must* start with file:// for now.
|
|
25838
|
+
*/
|
|
25839
|
+
uri: string().startsWith("file://"),
|
|
25840
|
+
/**
|
|
25841
|
+
* An optional name for the root.
|
|
25842
|
+
*/
|
|
25843
|
+
name: string().optional(),
|
|
25844
|
+
/**
|
|
25845
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25846
|
+
* for notes on _meta usage.
|
|
25847
|
+
*/
|
|
25848
|
+
_meta: record(string(), unknown()).optional()
|
|
25849
|
+
});
|
|
25850
|
+
/**
|
|
25851
|
+
* Sent from the server to request a list of root URIs from the client.
|
|
25852
|
+
*/
|
|
25853
|
+
const ListRootsRequestSchema = RequestSchema.extend({
|
|
25854
|
+
method: literal("roots/list"),
|
|
25855
|
+
params: BaseRequestParamsSchema.optional()
|
|
25856
|
+
});
|
|
25857
|
+
/**
|
|
25858
|
+
* The client's response to a roots/list request from the server.
|
|
25859
|
+
*/
|
|
25860
|
+
const ListRootsResultSchema = ResultSchema.extend({ roots: array(RootSchema) });
|
|
25861
|
+
/**
|
|
25862
|
+
* A notification from the client to the server, informing it that the list of roots has changed.
|
|
25863
|
+
*/
|
|
25864
|
+
const RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
25865
|
+
method: literal("notifications/roots/list_changed"),
|
|
25866
|
+
params: NotificationsParamsSchema.optional()
|
|
25867
|
+
});
|
|
25868
|
+
union([
|
|
25869
|
+
PingRequestSchema,
|
|
25870
|
+
InitializeRequestSchema,
|
|
25871
|
+
CompleteRequestSchema,
|
|
25872
|
+
SetLevelRequestSchema,
|
|
25873
|
+
GetPromptRequestSchema,
|
|
25874
|
+
ListPromptsRequestSchema,
|
|
25875
|
+
ListResourcesRequestSchema,
|
|
25876
|
+
ListResourceTemplatesRequestSchema,
|
|
25877
|
+
ReadResourceRequestSchema,
|
|
25878
|
+
SubscribeRequestSchema,
|
|
25879
|
+
UnsubscribeRequestSchema,
|
|
25880
|
+
CallToolRequestSchema,
|
|
25881
|
+
ListToolsRequestSchema,
|
|
25882
|
+
GetTaskRequestSchema,
|
|
25883
|
+
GetTaskPayloadRequestSchema,
|
|
25884
|
+
ListTasksRequestSchema,
|
|
25885
|
+
CancelTaskRequestSchema
|
|
25886
|
+
]);
|
|
25887
|
+
union([
|
|
25888
|
+
CancelledNotificationSchema,
|
|
25889
|
+
ProgressNotificationSchema,
|
|
25890
|
+
InitializedNotificationSchema,
|
|
25891
|
+
RootsListChangedNotificationSchema,
|
|
25892
|
+
TaskStatusNotificationSchema
|
|
25893
|
+
]);
|
|
25894
|
+
union([
|
|
25895
|
+
EmptyResultSchema,
|
|
25896
|
+
CreateMessageResultSchema,
|
|
25897
|
+
CreateMessageResultWithToolsSchema,
|
|
25898
|
+
ElicitResultSchema,
|
|
25899
|
+
ListRootsResultSchema,
|
|
25900
|
+
GetTaskResultSchema,
|
|
25901
|
+
ListTasksResultSchema,
|
|
25902
|
+
CreateTaskResultSchema
|
|
25903
|
+
]);
|
|
25904
|
+
union([
|
|
25905
|
+
PingRequestSchema,
|
|
25906
|
+
CreateMessageRequestSchema,
|
|
25907
|
+
ElicitRequestSchema,
|
|
25908
|
+
ListRootsRequestSchema,
|
|
25909
|
+
GetTaskRequestSchema,
|
|
25910
|
+
GetTaskPayloadRequestSchema,
|
|
25911
|
+
ListTasksRequestSchema,
|
|
25912
|
+
CancelTaskRequestSchema
|
|
25913
|
+
]);
|
|
25914
|
+
union([
|
|
25915
|
+
CancelledNotificationSchema,
|
|
25916
|
+
ProgressNotificationSchema,
|
|
25917
|
+
LoggingMessageNotificationSchema,
|
|
25918
|
+
ResourceUpdatedNotificationSchema,
|
|
25919
|
+
ResourceListChangedNotificationSchema,
|
|
25920
|
+
ToolListChangedNotificationSchema,
|
|
25921
|
+
PromptListChangedNotificationSchema,
|
|
25922
|
+
TaskStatusNotificationSchema,
|
|
25923
|
+
ElicitationCompleteNotificationSchema
|
|
25924
|
+
]);
|
|
25925
|
+
union([
|
|
25926
|
+
EmptyResultSchema,
|
|
25927
|
+
InitializeResultSchema,
|
|
25928
|
+
CompleteResultSchema,
|
|
25929
|
+
GetPromptResultSchema,
|
|
25930
|
+
ListPromptsResultSchema,
|
|
25931
|
+
ListResourcesResultSchema,
|
|
25932
|
+
ListResourceTemplatesResultSchema,
|
|
25933
|
+
ReadResourceResultSchema,
|
|
25934
|
+
CallToolResultSchema,
|
|
25935
|
+
ListToolsResultSchema,
|
|
25936
|
+
GetTaskResultSchema,
|
|
25937
|
+
ListTasksResultSchema,
|
|
25938
|
+
CreateTaskResultSchema
|
|
25939
|
+
]);
|
|
25940
|
+
//#endregion
|
|
25941
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono-mcp-server-sse-transport/0.0.7/518df2f53e0bbb46e48def5118fc7f6b5bba3a268854c8a5c7e83260299d376e/node_modules/hono-mcp-server-sse-transport/build/sse.js
|
|
25942
|
+
const MAXIMUM_MESSAGE_SIZE = 4 * 1024 * 1024;
|
|
25943
|
+
var SSETransport = class {
|
|
25944
|
+
messageUrl;
|
|
25945
|
+
stream;
|
|
25946
|
+
_sessionId;
|
|
25947
|
+
onclose;
|
|
25948
|
+
onerror;
|
|
25949
|
+
onmessage;
|
|
25950
|
+
/**
|
|
25951
|
+
* Creates a new SSETransport, which will direct the MPC client to POST messages to messageUrl
|
|
25952
|
+
*/
|
|
25953
|
+
constructor(messageUrl, stream) {
|
|
25954
|
+
this.messageUrl = messageUrl;
|
|
25955
|
+
this.stream = stream;
|
|
25956
|
+
this._sessionId = crypto.randomUUID();
|
|
25957
|
+
this.stream.onAbort(() => {
|
|
25958
|
+
this.close();
|
|
25959
|
+
});
|
|
25960
|
+
}
|
|
25961
|
+
get sessionId() {
|
|
25962
|
+
return this._sessionId;
|
|
25963
|
+
}
|
|
25964
|
+
async start() {
|
|
25965
|
+
if (this.stream == null) throw new Error("Stream not initialized");
|
|
25966
|
+
if (this.stream.closed) throw new Error("SSE transport already closed!");
|
|
25967
|
+
await this.stream.writeSSE({
|
|
25968
|
+
event: "ping",
|
|
25969
|
+
data: ""
|
|
25970
|
+
});
|
|
25971
|
+
await this.stream.writeSSE({
|
|
25972
|
+
event: "endpoint",
|
|
25973
|
+
data: `${this.messageUrl}?sessionId=${this.sessionId}`
|
|
25974
|
+
});
|
|
25975
|
+
}
|
|
25976
|
+
async handlePostMessage(context) {
|
|
25977
|
+
if (this.stream?.closed == null) return context.text("SSE connection not established", 500);
|
|
25978
|
+
try {
|
|
25979
|
+
const contentType = context.req.header("content-type") || "";
|
|
25980
|
+
if (!contentType.includes("application/json")) throw new Error(`Unsupported content-type: ${contentType}`);
|
|
25981
|
+
const contentLength = Number.parseInt(context.req.header("content-length") || "0", 10);
|
|
25982
|
+
if (contentLength > MAXIMUM_MESSAGE_SIZE) throw new Error(`Request body too large: ${contentLength} bytes`);
|
|
25983
|
+
const body = await context.req.json();
|
|
25984
|
+
await this.handleMessage(body);
|
|
25985
|
+
return context.text("Accepted", 202);
|
|
25986
|
+
} catch (error) {
|
|
25987
|
+
this.onerror?.(error);
|
|
25988
|
+
return context.text("Error", 400);
|
|
25989
|
+
}
|
|
25990
|
+
}
|
|
25991
|
+
/**
|
|
25992
|
+
* Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.
|
|
25993
|
+
*/
|
|
25994
|
+
async handleMessage(message) {
|
|
25995
|
+
let parsedMessage;
|
|
25996
|
+
try {
|
|
25997
|
+
parsedMessage = JSONRPCMessageSchema.parse(message);
|
|
25998
|
+
} catch (error) {
|
|
25999
|
+
this.onerror?.(error);
|
|
26000
|
+
throw error;
|
|
26001
|
+
}
|
|
26002
|
+
this.onmessage?.(parsedMessage);
|
|
26003
|
+
}
|
|
26004
|
+
async close() {
|
|
26005
|
+
if (this.stream?.closed) this.stream.abort();
|
|
26006
|
+
}
|
|
26007
|
+
async send(message) {
|
|
26008
|
+
if (this.stream?.closed) throw new Error("Not connected");
|
|
26009
|
+
await this.stream.writeSSE({
|
|
26010
|
+
event: "message",
|
|
26011
|
+
data: JSON.stringify(message)
|
|
26012
|
+
});
|
|
26013
|
+
}
|
|
26014
|
+
};
|
|
26015
|
+
//#endregion
|
|
26016
|
+
//#region src/server/notificationBroadcast.ts
|
|
26017
|
+
/**
|
|
26018
|
+
* Sends a notification to every active server instance (the main stdio/SSE
|
|
26019
|
+
* instance plus each streamable HTTP session instance).
|
|
26020
|
+
*
|
|
26021
|
+
* Failures are aggregated: if only some instances fail, the failure is logged
|
|
26022
|
+
* and the broadcast is considered best-effort. A `MastraError` is thrown only
|
|
26023
|
+
* when every send fails.
|
|
26024
|
+
*
|
|
26025
|
+
* Note: clients connected in stateless/serverless mode cannot receive
|
|
26026
|
+
* notifications because each request uses a transient server instance.
|
|
26027
|
+
*
|
|
26028
|
+
* @internal
|
|
26029
|
+
*/
|
|
26030
|
+
async function broadcastNotification({ servers, send, logger, errorId, errorText, errorDetails }) {
|
|
26031
|
+
const errors = [];
|
|
26032
|
+
for (const server of servers) try {
|
|
26033
|
+
await send(server);
|
|
26034
|
+
} catch (error) {
|
|
26035
|
+
errors.push(error);
|
|
26036
|
+
}
|
|
26037
|
+
if (errors.length === 0) return;
|
|
26038
|
+
const mastraError = new _mastra_core_error.MastraError({
|
|
26039
|
+
id: errorId,
|
|
26040
|
+
domain: _mastra_core_error.ErrorDomain.MCP,
|
|
26041
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
26042
|
+
text: errorText,
|
|
26043
|
+
details: {
|
|
26044
|
+
...errorDetails,
|
|
26045
|
+
failedInstances: errors.length,
|
|
26046
|
+
totalInstances: servers.length
|
|
26047
|
+
}
|
|
26048
|
+
}, errors[0]);
|
|
26049
|
+
logger.error(`${errorText}:`, { error: mastraError.toString() });
|
|
26050
|
+
if (errors.length === servers.length) {
|
|
26051
|
+
logger.trackException(mastraError);
|
|
26052
|
+
throw mastraError;
|
|
26053
|
+
}
|
|
26054
|
+
}
|
|
26055
|
+
//#endregion
|
|
26056
|
+
//#region src/server/promptActions.ts
|
|
26057
|
+
/**
|
|
26058
|
+
* Server-side prompt actions for notifying clients about prompt changes.
|
|
26059
|
+
*
|
|
26060
|
+
* This class provides methods for MCP servers to notify connected clients when
|
|
26061
|
+
* the list of available prompts changes.
|
|
26062
|
+
*
|
|
26063
|
+
* Notifications are broadcast to every active server instance (the main
|
|
26064
|
+
* stdio/SSE instance plus each streamable HTTP session). Clients connected in
|
|
26065
|
+
* stateless/serverless mode cannot receive notifications because each request
|
|
26066
|
+
* uses a transient server instance.
|
|
26067
|
+
*/
|
|
26068
|
+
var ServerPromptActions = class {
|
|
26069
|
+
getLogger;
|
|
26070
|
+
getSdkServers;
|
|
26071
|
+
clearDefinedPrompts;
|
|
26072
|
+
/**
|
|
26073
|
+
* @internal
|
|
26074
|
+
*/
|
|
26075
|
+
constructor(dependencies) {
|
|
26076
|
+
this.getLogger = dependencies.getLogger;
|
|
26077
|
+
this.getSdkServers = dependencies.getSdkServers;
|
|
26078
|
+
this.clearDefinedPrompts = dependencies.clearDefinedPrompts;
|
|
26079
|
+
}
|
|
26080
|
+
/**
|
|
26081
|
+
* Notifies clients that the overall list of available prompts has changed.
|
|
26082
|
+
*
|
|
26083
|
+
* This clears the internal prompt cache and sends a `notifications/prompts/list_changed`
|
|
26084
|
+
* message to all clients, prompting them to re-fetch the prompt list.
|
|
26085
|
+
*
|
|
26086
|
+
* @throws {MastraError} If sending the notification fails on all server instances
|
|
26087
|
+
*
|
|
26088
|
+
* @example
|
|
26089
|
+
* ```typescript
|
|
26090
|
+
* // After adding or modifying prompts
|
|
26091
|
+
* await server.prompts.notifyListChanged();
|
|
26092
|
+
* ```
|
|
26093
|
+
*/
|
|
26094
|
+
async notifyListChanged() {
|
|
26095
|
+
this.getLogger().info("Prompt list change externally notified. Clearing definedPrompts and sending notification.");
|
|
26096
|
+
this.clearDefinedPrompts();
|
|
26097
|
+
await broadcastNotification({
|
|
23964
26098
|
servers: this.getSdkServers(),
|
|
23965
26099
|
send: (server) => server.sendPromptListChanged(),
|
|
23966
26100
|
logger: this.getLogger(),
|
|
@@ -24146,6 +26280,25 @@ var ServerToolActions = class {
|
|
|
24146
26280
|
};
|
|
24147
26281
|
//#endregion
|
|
24148
26282
|
//#region src/server/server.ts
|
|
26283
|
+
/**
|
|
26284
|
+
* Flattens the MCP `ServerContext` into the shape Mastra tools receive as `extra`.
|
|
26285
|
+
*
|
|
26286
|
+
* MCP 2.0 nests per-request plumbing under `ctx.mcpReq` and transport details under
|
|
26287
|
+
* `ctx.http`, while Mastra tools have always read `signal`, `requestId`, `authInfo`,
|
|
26288
|
+
* `sendNotification`, `sendRequest`, and `_meta` off the top level. Both the nested and
|
|
26289
|
+
* flattened members are kept so tools written against either shape keep working.
|
|
26290
|
+
*/
|
|
26291
|
+
const toMCPRequestHandlerExtra = (ctx) => {
|
|
26292
|
+
return {
|
|
26293
|
+
...ctx,
|
|
26294
|
+
signal: ctx.mcpReq.signal,
|
|
26295
|
+
requestId: ctx.mcpReq.id,
|
|
26296
|
+
authInfo: ctx.http?.authInfo,
|
|
26297
|
+
sendNotification: ctx.mcpReq.notify,
|
|
26298
|
+
sendRequest: ctx.mcpReq.send,
|
|
26299
|
+
_meta: ctx.mcpReq._meta
|
|
26300
|
+
};
|
|
26301
|
+
};
|
|
24149
26302
|
const LOG_LEVEL_SEVERITY = {
|
|
24150
26303
|
debug: 0,
|
|
24151
26304
|
info: 1,
|
|
@@ -24292,11 +26445,11 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24292
26445
|
return this.sseHonoTransports.get(sessionId);
|
|
24293
26446
|
}
|
|
24294
26447
|
/**
|
|
24295
|
-
* Gets the underlying MCP
|
|
26448
|
+
* Gets the underlying MCP Server instance.
|
|
24296
26449
|
*
|
|
24297
26450
|
* This provides access to the low-level server instance for advanced use cases.
|
|
24298
26451
|
*
|
|
24299
|
-
* @returns The Server instance from @modelcontextprotocol/
|
|
26452
|
+
* @returns The Server instance from @modelcontextprotocol/server
|
|
24300
26453
|
*/
|
|
24301
26454
|
getServer() {
|
|
24302
26455
|
return this.server;
|
|
@@ -24370,7 +26523,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24370
26523
|
...capabilities.extensions,
|
|
24371
26524
|
"io.modelcontextprotocol/ui": {}
|
|
24372
26525
|
};
|
|
24373
|
-
this.server = new
|
|
26526
|
+
this.server = new _modelcontextprotocol_server.Server({
|
|
24374
26527
|
name: this.name,
|
|
24375
26528
|
version: this.version
|
|
24376
26529
|
}, {
|
|
@@ -24650,7 +26803,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24650
26803
|
...capabilities.extensions,
|
|
24651
26804
|
"io.modelcontextprotocol/ui": {}
|
|
24652
26805
|
};
|
|
24653
|
-
const serverInstance = new
|
|
26806
|
+
const serverInstance = new _modelcontextprotocol_server.Server({
|
|
24654
26807
|
name: this.name,
|
|
24655
26808
|
version: this.version
|
|
24656
26809
|
}, {
|
|
@@ -24666,8 +26819,8 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24666
26819
|
* This allows us to create multiple server instances with identical functionality.
|
|
24667
26820
|
*/
|
|
24668
26821
|
registerHandlersOnServer(serverInstance) {
|
|
24669
|
-
serverInstance.setRequestHandler(
|
|
24670
|
-
const proxiedContext = await this.createProxiedRequestContext(
|
|
26822
|
+
serverInstance.setRequestHandler("tools/list", async (_request, ctx) => {
|
|
26823
|
+
const proxiedContext = await this.createProxiedRequestContext(toMCPRequestHandlerExtra(ctx));
|
|
24671
26824
|
return { tools: (await this.getAuthorizedConvertedToolEntries(proxiedContext)).map(([, tool]) => {
|
|
24672
26825
|
const toolSpec = {
|
|
24673
26826
|
name: tool.id || "unknown",
|
|
@@ -24696,8 +26849,9 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24696
26849
|
return toolSpec;
|
|
24697
26850
|
}) };
|
|
24698
26851
|
});
|
|
24699
|
-
serverInstance.setRequestHandler(
|
|
26852
|
+
serverInstance.setRequestHandler("tools/call", async (request, ctx) => {
|
|
24700
26853
|
const startTime = Date.now();
|
|
26854
|
+
const extra = toMCPRequestHandlerExtra(ctx);
|
|
24701
26855
|
try {
|
|
24702
26856
|
const tool = this.convertedTools[request.params.name];
|
|
24703
26857
|
if (!tool) {
|
|
@@ -24865,7 +27019,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24865
27019
|
};
|
|
24866
27020
|
}
|
|
24867
27021
|
});
|
|
24868
|
-
serverInstance.setRequestHandler(
|
|
27022
|
+
serverInstance.setRequestHandler("logging/setLevel", async (request) => {
|
|
24869
27023
|
this.loggingLevels.set(serverInstance, request.params.level);
|
|
24870
27024
|
this.logger.debug("Logging level set", { level: request.params.level });
|
|
24871
27025
|
return {};
|
|
@@ -24879,9 +27033,9 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24879
27033
|
registerResourceHandlersOnServer(serverInstance) {
|
|
24880
27034
|
const capturedResourceOptions = this.resourceOptions;
|
|
24881
27035
|
if (!capturedResourceOptions) return;
|
|
24882
|
-
if (capturedResourceOptions.listResources) serverInstance.setRequestHandler(
|
|
27036
|
+
if (capturedResourceOptions.listResources) serverInstance.setRequestHandler("resources/list", async (_request, ctx) => {
|
|
24883
27037
|
try {
|
|
24884
|
-
const resources = await capturedResourceOptions.listResources({ extra });
|
|
27038
|
+
const resources = await capturedResourceOptions.listResources({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24885
27039
|
this.logger.debug("Fetched resources", { count: resources.length });
|
|
24886
27040
|
return { resources };
|
|
24887
27041
|
} catch (error) {
|
|
@@ -24889,21 +27043,21 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24889
27043
|
throw error;
|
|
24890
27044
|
}
|
|
24891
27045
|
});
|
|
24892
|
-
if (capturedResourceOptions.getResourceContent) serverInstance.setRequestHandler(
|
|
27046
|
+
if (capturedResourceOptions.getResourceContent) serverInstance.setRequestHandler("resources/read", async (request, ctx) => {
|
|
24893
27047
|
const startTime = Date.now();
|
|
24894
27048
|
const uri = request.params.uri;
|
|
24895
27049
|
this.logger.debug("Handling ReadResource request", { uri });
|
|
24896
|
-
const resources = await capturedResourceOptions.listResources?.({ extra });
|
|
27050
|
+
const resources = await capturedResourceOptions.listResources?.({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24897
27051
|
if (!resources) throw new Error("Failed to load resources");
|
|
24898
27052
|
const resource = resources.find((r) => r.uri === uri);
|
|
24899
27053
|
if (!resource) {
|
|
24900
27054
|
this.logger.warn("Unknown resource URI requested", { uri });
|
|
24901
|
-
throw new
|
|
27055
|
+
throw new _modelcontextprotocol_server.ProtocolError(_modelcontextprotocol_server.ProtocolErrorCode.InvalidParams, `Resource not found: ${uri}`);
|
|
24902
27056
|
}
|
|
24903
27057
|
try {
|
|
24904
27058
|
const resourcesOrResourceContent = await capturedResourceOptions.getResourceContent({
|
|
24905
27059
|
uri,
|
|
24906
|
-
extra
|
|
27060
|
+
extra: toMCPRequestHandlerExtra(ctx)
|
|
24907
27061
|
});
|
|
24908
27062
|
const resourcesContent = Array.isArray(resourcesOrResourceContent) ? resourcesOrResourceContent : [resourcesOrResourceContent];
|
|
24909
27063
|
const resourceMeta = resource._meta ? { _meta: resource._meta } : {};
|
|
@@ -24939,9 +27093,9 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24939
27093
|
throw error;
|
|
24940
27094
|
}
|
|
24941
27095
|
});
|
|
24942
|
-
if (capturedResourceOptions.resourceTemplates) serverInstance.setRequestHandler(
|
|
27096
|
+
if (capturedResourceOptions.resourceTemplates) serverInstance.setRequestHandler("resources/templates/list", async (_request, ctx) => {
|
|
24943
27097
|
try {
|
|
24944
|
-
const templates = await capturedResourceOptions.resourceTemplates({ extra });
|
|
27098
|
+
const templates = await capturedResourceOptions.resourceTemplates({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24945
27099
|
this.logger.debug("Fetched resource templates", { count: templates.length });
|
|
24946
27100
|
return { resourceTemplates: templates };
|
|
24947
27101
|
} catch (error) {
|
|
@@ -24949,7 +27103,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24949
27103
|
throw error;
|
|
24950
27104
|
}
|
|
24951
27105
|
});
|
|
24952
|
-
serverInstance.setRequestHandler(
|
|
27106
|
+
serverInstance.setRequestHandler("resources/subscribe", async (request) => {
|
|
24953
27107
|
const uri = request.params.uri;
|
|
24954
27108
|
this.logger.info("Received resources/subscribe request", { uri });
|
|
24955
27109
|
let subscriptions = this.subscriptionsByInstance.get(serverInstance);
|
|
@@ -24960,7 +27114,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24960
27114
|
subscriptions.add(uri);
|
|
24961
27115
|
return {};
|
|
24962
27116
|
});
|
|
24963
|
-
serverInstance.setRequestHandler(
|
|
27117
|
+
serverInstance.setRequestHandler("resources/unsubscribe", async (request) => {
|
|
24964
27118
|
const uri = request.params.uri;
|
|
24965
27119
|
this.logger.info("Received resources/unsubscribe request", { uri });
|
|
24966
27120
|
this.subscriptionsByInstance.get(serverInstance)?.delete(uri);
|
|
@@ -24973,12 +27127,12 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24973
27127
|
registerPromptHandlersOnServer(serverInstance) {
|
|
24974
27128
|
const capturedPromptOptions = this.promptOptions;
|
|
24975
27129
|
if (!capturedPromptOptions) return;
|
|
24976
|
-
if (capturedPromptOptions.listPrompts) serverInstance.setRequestHandler(
|
|
27130
|
+
if (capturedPromptOptions.listPrompts) serverInstance.setRequestHandler("prompts/list", async (_request, ctx) => {
|
|
24977
27131
|
this.logger.debug("Handling ListPrompts request");
|
|
24978
27132
|
if (this.definedPrompts) return { prompts: this.definedPrompts };
|
|
24979
27133
|
else try {
|
|
24980
|
-
const prompts = await capturedPromptOptions.listPrompts({ extra });
|
|
24981
|
-
for (const prompt of prompts)
|
|
27134
|
+
const prompts = await capturedPromptOptions.listPrompts({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
27135
|
+
for (const prompt of prompts) _modelcontextprotocol_core.PromptSchema.parse(prompt);
|
|
24982
27136
|
this.definedPrompts = prompts;
|
|
24983
27137
|
this.logger.debug("Fetched and cached prompts", { count: this.definedPrompts.length });
|
|
24984
27138
|
return { prompts: this.definedPrompts };
|
|
@@ -24987,18 +27141,18 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24987
27141
|
throw error;
|
|
24988
27142
|
}
|
|
24989
27143
|
});
|
|
24990
|
-
if (capturedPromptOptions.getPromptMessages) serverInstance.setRequestHandler(
|
|
27144
|
+
if (capturedPromptOptions.getPromptMessages) serverInstance.setRequestHandler("prompts/get", async (request, ctx) => {
|
|
24991
27145
|
const startTime = Date.now();
|
|
24992
27146
|
const { name, arguments: args } = request.params;
|
|
24993
27147
|
if (!this.definedPrompts) {
|
|
24994
|
-
const prompts = await this.promptOptions?.listPrompts?.({ extra });
|
|
27148
|
+
const prompts = await this.promptOptions?.listPrompts?.({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24995
27149
|
if (!prompts) throw new Error("Failed to load prompts");
|
|
24996
27150
|
this.definedPrompts = prompts;
|
|
24997
27151
|
}
|
|
24998
27152
|
const prompt = this.definedPrompts?.find((p) => p.name === name);
|
|
24999
27153
|
if (!prompt) throw new Error(`Prompt "${name}" not found`);
|
|
25000
27154
|
if (prompt.arguments) {
|
|
25001
|
-
for (const arg of prompt.arguments) if (arg.required && (args?.[arg.name] === void 0 || args?.[arg.name] === null)) throw new
|
|
27155
|
+
for (const arg of prompt.arguments) if (arg.required && (args?.[arg.name] === void 0 || args?.[arg.name] === null)) throw new _modelcontextprotocol_server.ProtocolError(_modelcontextprotocol_server.ProtocolErrorCode.InvalidParams, `Missing required argument: ${arg.name}`);
|
|
25002
27156
|
}
|
|
25003
27157
|
try {
|
|
25004
27158
|
let messages = [];
|
|
@@ -25006,7 +27160,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25006
27160
|
name,
|
|
25007
27161
|
version: prompt.version,
|
|
25008
27162
|
args,
|
|
25009
|
-
extra
|
|
27163
|
+
extra: toMCPRequestHandlerExtra(ctx)
|
|
25010
27164
|
});
|
|
25011
27165
|
const duration = Date.now() - startTime;
|
|
25012
27166
|
this.logger.info("Prompt retrieved successfully", {
|
|
@@ -25244,7 +27398,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25244
27398
|
* ```
|
|
25245
27399
|
*/
|
|
25246
27400
|
async startStdio() {
|
|
25247
|
-
this.stdioTransport = new
|
|
27401
|
+
this.stdioTransport = new _modelcontextprotocol_server_stdio.StdioServerTransport();
|
|
25248
27402
|
try {
|
|
25249
27403
|
await this.server.connect(this.stdioTransport);
|
|
25250
27404
|
} catch (error) {
|
|
@@ -25517,11 +27671,11 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25517
27671
|
this.logger.debug("No session ID provided", { method: req.method });
|
|
25518
27672
|
if (req.method === "POST") {
|
|
25519
27673
|
const body = await this.readJsonBody(req);
|
|
25520
|
-
const { isInitializeRequest } = await import("@modelcontextprotocol/
|
|
27674
|
+
const { isInitializeRequest } = await import("@modelcontextprotocol/server");
|
|
25521
27675
|
if (isInitializeRequest(body)) {
|
|
25522
27676
|
this.logger.debug("Received initialize request, creating new transport");
|
|
25523
27677
|
const sessionServerInstance = this.createServerInstance();
|
|
25524
|
-
transport = new
|
|
27678
|
+
transport = new _modelcontextprotocol_node.NodeStreamableHTTPServerTransport({
|
|
25525
27679
|
...mergedOptions,
|
|
25526
27680
|
sessionIdGenerator: mergedOptions.sessionIdGenerator,
|
|
25527
27681
|
onsessioninitialized: (id) => {
|
|
@@ -25618,7 +27772,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25618
27772
|
enableJsonResponse
|
|
25619
27773
|
});
|
|
25620
27774
|
const transientServer = this.createServerInstance();
|
|
25621
|
-
const tempTransport = new
|
|
27775
|
+
const tempTransport = new _modelcontextprotocol_node.NodeStreamableHTTPServerTransport({
|
|
25622
27776
|
sessionIdGenerator: void 0,
|
|
25623
27777
|
enableJsonResponse
|
|
25624
27778
|
});
|
|
@@ -25678,7 +27832,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25678
27832
|
await this.sseTransport.close?.();
|
|
25679
27833
|
this.sseTransport = void 0;
|
|
25680
27834
|
}
|
|
25681
|
-
this.sseTransport = new
|
|
27835
|
+
this.sseTransport = new _modelcontextprotocol_server_legacy_sse.SSEServerTransport(messagePath, res);
|
|
25682
27836
|
await this.server.connect(this.sseTransport);
|
|
25683
27837
|
this.server.onclose = async () => {
|
|
25684
27838
|
this.sseTransport = void 0;
|
|
@@ -25859,8 +28013,12 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25859
28013
|
};
|
|
25860
28014
|
}
|
|
25861
28015
|
convertSchema(schema) {
|
|
25862
|
-
|
|
25863
|
-
|
|
28016
|
+
const jsonSchema = (0, _mastra_core_schema.isStandardSchemaWithJSON)(schema) ? (0, _mastra_core_schema.standardSchemaToJSONSchema)(schema) : schema?.jsonSchema ?? schema;
|
|
28017
|
+
if (jsonSchema && typeof jsonSchema === "object" && "$schema" in jsonSchema) {
|
|
28018
|
+
const { $schema: _dialect, ...rest } = jsonSchema;
|
|
28019
|
+
return rest;
|
|
28020
|
+
}
|
|
28021
|
+
return jsonSchema;
|
|
25864
28022
|
}
|
|
25865
28023
|
/**
|
|
25866
28024
|
* Gets a list of all tools provided by this MCP server with their schemas.
|
|
@@ -25950,6 +28108,8 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25950
28108
|
Object.entries(extraRecord).forEach(([key, value]) => {
|
|
25951
28109
|
proxiedContext.set(key, value);
|
|
25952
28110
|
});
|
|
28111
|
+
const http = extraRecord.http;
|
|
28112
|
+
if (http && typeof http === "object" && "authInfo" in http) proxiedContext.set("authInfo", http.authInfo);
|
|
25953
28113
|
}
|
|
25954
28114
|
await this.resolveMappedFGAUser(proxiedContext, extraRecord);
|
|
25955
28115
|
return proxiedContext;
|
|
@@ -26425,19 +28585,19 @@ exports.MCPServer = MCPServer;
|
|
|
26425
28585
|
Object.defineProperty(exports, "UnauthorizedError", {
|
|
26426
28586
|
enumerable: true,
|
|
26427
28587
|
get: function() {
|
|
26428
|
-
return
|
|
28588
|
+
return _modelcontextprotocol_client.UnauthorizedError;
|
|
26429
28589
|
}
|
|
26430
28590
|
});
|
|
26431
28591
|
Object.defineProperty(exports, "auth", {
|
|
26432
28592
|
enumerable: true,
|
|
26433
28593
|
get: function() {
|
|
26434
|
-
return
|
|
28594
|
+
return _modelcontextprotocol_client.auth;
|
|
26435
28595
|
}
|
|
26436
28596
|
});
|
|
26437
28597
|
Object.defineProperty(exports, "buildDiscoveryUrls", {
|
|
26438
28598
|
enumerable: true,
|
|
26439
28599
|
get: function() {
|
|
26440
|
-
return
|
|
28600
|
+
return _modelcontextprotocol_client.buildDiscoveryUrls;
|
|
26441
28601
|
}
|
|
26442
28602
|
});
|
|
26443
28603
|
exports.createIntrospectionValidator = createIntrospectionValidator;
|
|
@@ -26448,32 +28608,32 @@ exports.createStaticTokenValidator = createStaticTokenValidator;
|
|
|
26448
28608
|
Object.defineProperty(exports, "discoverAuthorizationServerMetadata", {
|
|
26449
28609
|
enumerable: true,
|
|
26450
28610
|
get: function() {
|
|
26451
|
-
return
|
|
28611
|
+
return _modelcontextprotocol_client.discoverAuthorizationServerMetadata;
|
|
26452
28612
|
}
|
|
26453
28613
|
});
|
|
26454
28614
|
Object.defineProperty(exports, "discoverOAuthMetadata", {
|
|
26455
28615
|
enumerable: true,
|
|
26456
28616
|
get: function() {
|
|
26457
|
-
return
|
|
28617
|
+
return _modelcontextprotocol_client.discoverOAuthMetadata;
|
|
26458
28618
|
}
|
|
26459
28619
|
});
|
|
26460
28620
|
Object.defineProperty(exports, "discoverOAuthProtectedResourceMetadata", {
|
|
26461
28621
|
enumerable: true,
|
|
26462
28622
|
get: function() {
|
|
26463
|
-
return
|
|
28623
|
+
return _modelcontextprotocol_client.discoverOAuthProtectedResourceMetadata;
|
|
26464
28624
|
}
|
|
26465
28625
|
});
|
|
26466
28626
|
Object.defineProperty(exports, "exchangeAuthorization", {
|
|
26467
28627
|
enumerable: true,
|
|
26468
28628
|
get: function() {
|
|
26469
|
-
return
|
|
28629
|
+
return _modelcontextprotocol_client.exchangeAuthorization;
|
|
26470
28630
|
}
|
|
26471
28631
|
});
|
|
26472
28632
|
exports.extractBearerToken = extractBearerToken;
|
|
26473
28633
|
Object.defineProperty(exports, "extractResourceMetadataUrl", {
|
|
26474
28634
|
enumerable: true,
|
|
26475
28635
|
get: function() {
|
|
26476
|
-
return
|
|
28636
|
+
return _modelcontextprotocol_client.extractResourceMetadataUrl;
|
|
26477
28637
|
}
|
|
26478
28638
|
});
|
|
26479
28639
|
exports.generateProtectedResourceMetadata = generateProtectedResourceMetadata;
|
|
@@ -26482,31 +28642,31 @@ exports.getCallbackUrlCandidates = getCallbackUrlCandidates;
|
|
|
26482
28642
|
Object.defineProperty(exports, "parseErrorResponse", {
|
|
26483
28643
|
enumerable: true,
|
|
26484
28644
|
get: function() {
|
|
26485
|
-
return
|
|
28645
|
+
return _modelcontextprotocol_client.parseErrorResponse;
|
|
26486
28646
|
}
|
|
26487
28647
|
});
|
|
26488
28648
|
Object.defineProperty(exports, "refreshAuthorization", {
|
|
26489
28649
|
enumerable: true,
|
|
26490
28650
|
get: function() {
|
|
26491
|
-
return
|
|
28651
|
+
return _modelcontextprotocol_client.refreshAuthorization;
|
|
26492
28652
|
}
|
|
26493
28653
|
});
|
|
26494
28654
|
Object.defineProperty(exports, "registerClient", {
|
|
26495
28655
|
enumerable: true,
|
|
26496
28656
|
get: function() {
|
|
26497
|
-
return
|
|
28657
|
+
return _modelcontextprotocol_client.registerClient;
|
|
26498
28658
|
}
|
|
26499
28659
|
});
|
|
26500
28660
|
Object.defineProperty(exports, "selectResourceURL", {
|
|
26501
28661
|
enumerable: true,
|
|
26502
28662
|
get: function() {
|
|
26503
|
-
return
|
|
28663
|
+
return _modelcontextprotocol_client.selectResourceURL;
|
|
26504
28664
|
}
|
|
26505
28665
|
});
|
|
26506
28666
|
Object.defineProperty(exports, "startAuthorization", {
|
|
26507
28667
|
enumerable: true,
|
|
26508
28668
|
get: function() {
|
|
26509
|
-
return
|
|
28669
|
+
return _modelcontextprotocol_client.startAuthorization;
|
|
26510
28670
|
}
|
|
26511
28671
|
});
|
|
26512
28672
|
|