@mastra/mcp 1.15.1 → 1.16.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +76 -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 +8 -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 +2496 -265
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2464 -234
- 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;
|
|
@@ -21096,9 +21378,71 @@ function shouldDetachPersistentTransportRequest(init) {
|
|
|
21096
21378
|
function extractToolErrorText(content) {
|
|
21097
21379
|
const fallback = "MCP tool execution failed";
|
|
21098
21380
|
if (!Array.isArray(content)) return fallback;
|
|
21381
|
+
return extractModelTextFromToolContent(content) || fallback;
|
|
21382
|
+
}
|
|
21383
|
+
/**
|
|
21384
|
+
* Extract LLM-facing text from a successful CallToolResult's `content` blocks.
|
|
21385
|
+
* Per MCP spec, `content` is the human/model-readable channel; `structuredContent`
|
|
21386
|
+
* is for client/UI consumption.
|
|
21387
|
+
*/
|
|
21388
|
+
function extractModelTextFromToolContent(content) {
|
|
21389
|
+
if (!Array.isArray(content)) return void 0;
|
|
21099
21390
|
return content.filter((part) => {
|
|
21100
21391
|
return !!part && typeof part === "object" && part.type === "text";
|
|
21101
|
-
}).map((part) => part.text).join("\n").trim() ||
|
|
21392
|
+
}).map((part) => part.text).join("\n").trim() || void 0;
|
|
21393
|
+
}
|
|
21394
|
+
/**
|
|
21395
|
+
* Non-enumerable metadata attached to structured tool execute results so
|
|
21396
|
+
* `toModelOutput` can read MCP `content` without changing the execute return shape.
|
|
21397
|
+
*/
|
|
21398
|
+
const MCP_CALL_TOOL_CONTENT = Symbol.for("mastra.mcp.callToolContent");
|
|
21399
|
+
function reserveScalarMcpContent(queue) {
|
|
21400
|
+
const reservation = { ready: false };
|
|
21401
|
+
queue.push(reservation);
|
|
21402
|
+
return reservation;
|
|
21403
|
+
}
|
|
21404
|
+
function removeScalarMcpContentReservation(queue, reservation) {
|
|
21405
|
+
if (!reservation) return;
|
|
21406
|
+
const index = queue.indexOf(reservation);
|
|
21407
|
+
if (index !== -1) queue.splice(index, 1);
|
|
21408
|
+
}
|
|
21409
|
+
function attachMcpCallToolContent(structuredContent, content, scalarMcpContentQueue, reservation) {
|
|
21410
|
+
if (structuredContent !== null && typeof structuredContent === "object") {
|
|
21411
|
+
removeScalarMcpContentReservation(scalarMcpContentQueue, reservation);
|
|
21412
|
+
Object.defineProperty(structuredContent, MCP_CALL_TOOL_CONTENT, {
|
|
21413
|
+
value: content,
|
|
21414
|
+
enumerable: false,
|
|
21415
|
+
configurable: true
|
|
21416
|
+
});
|
|
21417
|
+
return structuredContent;
|
|
21418
|
+
}
|
|
21419
|
+
if (reservation) {
|
|
21420
|
+
reservation.output = structuredContent;
|
|
21421
|
+
reservation.content = content;
|
|
21422
|
+
reservation.ready = true;
|
|
21423
|
+
}
|
|
21424
|
+
return structuredContent;
|
|
21425
|
+
}
|
|
21426
|
+
function getMcpCallToolContent(output, scalarMcpContentQueue) {
|
|
21427
|
+
if (output !== null && typeof output === "object") {
|
|
21428
|
+
const attached = output[MCP_CALL_TOOL_CONTENT];
|
|
21429
|
+
if (attached !== void 0) return attached;
|
|
21430
|
+
}
|
|
21431
|
+
const index = scalarMcpContentQueue.findIndex((entry) => entry.ready && Object.is(entry.output, output));
|
|
21432
|
+
if (index !== -1) return scalarMcpContentQueue.splice(index, 1)[0]?.content;
|
|
21433
|
+
}
|
|
21434
|
+
function createStructuredToolToModelOutput(scalarMcpContentQueue) {
|
|
21435
|
+
return (output) => {
|
|
21436
|
+
const modelText = extractModelTextFromToolContent(getMcpCallToolContent(output, scalarMcpContentQueue));
|
|
21437
|
+
if (modelText !== void 0) return {
|
|
21438
|
+
type: "text",
|
|
21439
|
+
value: modelText
|
|
21440
|
+
};
|
|
21441
|
+
return {
|
|
21442
|
+
type: "json",
|
|
21443
|
+
value: output
|
|
21444
|
+
};
|
|
21445
|
+
};
|
|
21102
21446
|
}
|
|
21103
21447
|
function getDatadogScope() {
|
|
21104
21448
|
const tracer = globalThis[DATADOG_TRACER_TEST_SYMBOL] ?? loadDatadogTracer();
|
|
@@ -21188,7 +21532,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21188
21532
|
/**
|
|
21189
21533
|
* @internal
|
|
21190
21534
|
*/
|
|
21191
|
-
constructor({ name, version = "1.0.0", server, capabilities = {}, timeout =
|
|
21535
|
+
constructor({ name, version = "1.0.0", server, capabilities = {}, timeout = _modelcontextprotocol_client.DEFAULT_REQUEST_TIMEOUT_MSEC }) {
|
|
21192
21536
|
super({ name: "MastraMCPClient" });
|
|
21193
21537
|
this.name = name;
|
|
21194
21538
|
this.timeout = timeout;
|
|
@@ -21213,7 +21557,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21213
21557
|
"io.modelcontextprotocol/ui": {}
|
|
21214
21558
|
}
|
|
21215
21559
|
};
|
|
21216
|
-
this.client = new
|
|
21560
|
+
this.client = new _modelcontextprotocol_client.Client({
|
|
21217
21561
|
name,
|
|
21218
21562
|
version
|
|
21219
21563
|
}, {
|
|
@@ -21259,7 +21603,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21259
21603
|
});
|
|
21260
21604
|
}
|
|
21261
21605
|
setupLogging() {
|
|
21262
|
-
if (this.enableServerLogs) this.client.setNotificationHandler(
|
|
21606
|
+
if (this.enableServerLogs) this.client.setNotificationHandler("notifications/message", (notification) => {
|
|
21263
21607
|
const { level, ...params } = notification.params;
|
|
21264
21608
|
this.log(level, "[MCP SERVER LOG]", params);
|
|
21265
21609
|
});
|
|
@@ -21272,7 +21616,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21272
21616
|
*/
|
|
21273
21617
|
setupRootsHandler() {
|
|
21274
21618
|
this.log("debug", "Setting up roots/list request handler");
|
|
21275
|
-
this.client.setRequestHandler(
|
|
21619
|
+
this.client.setRequestHandler("roots/list", async () => {
|
|
21276
21620
|
this.log("debug", `Responding to roots/list request with ${this._roots.length} roots`);
|
|
21277
21621
|
return { roots: this._roots };
|
|
21278
21622
|
});
|
|
@@ -21321,16 +21665,28 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21321
21665
|
this.log("debug", "Sending notifications/roots/list_changed");
|
|
21322
21666
|
await this.client.notification({ method: "notifications/roots/list_changed" });
|
|
21323
21667
|
}
|
|
21668
|
+
buildStdioEnv() {
|
|
21669
|
+
const configured = this.serverConfig.env || {};
|
|
21670
|
+
if (this.serverConfig.inheritDefaultEnv === false) {
|
|
21671
|
+
const suppressed = {};
|
|
21672
|
+
for (const key of Object.keys((0, _modelcontextprotocol_client_stdio.getDefaultEnvironment)())) suppressed[key] = void 0;
|
|
21673
|
+
return {
|
|
21674
|
+
...suppressed,
|
|
21675
|
+
...configured
|
|
21676
|
+
};
|
|
21677
|
+
}
|
|
21678
|
+
return {
|
|
21679
|
+
...(0, _modelcontextprotocol_client_stdio.getDefaultEnvironment)(),
|
|
21680
|
+
...configured
|
|
21681
|
+
};
|
|
21682
|
+
}
|
|
21324
21683
|
async connectStdio(command) {
|
|
21325
21684
|
this.log("debug", `Using Stdio transport for command: ${command}`);
|
|
21326
21685
|
try {
|
|
21327
|
-
this.transport = new
|
|
21686
|
+
this.transport = new _modelcontextprotocol_client_stdio.StdioClientTransport({
|
|
21328
21687
|
command,
|
|
21329
21688
|
args: this.serverConfig.args,
|
|
21330
|
-
env:
|
|
21331
|
-
...(0, _modelcontextprotocol_sdk_client_stdio_js.getDefaultEnvironment)(),
|
|
21332
|
-
...this.serverConfig.env || {}
|
|
21333
|
-
},
|
|
21689
|
+
env: this.buildStdioEnv(),
|
|
21334
21690
|
stderr: this.serverConfig.stderr,
|
|
21335
21691
|
cwd: this.serverConfig.cwd
|
|
21336
21692
|
});
|
|
@@ -21342,16 +21698,22 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21342
21698
|
}
|
|
21343
21699
|
}
|
|
21344
21700
|
async connectHttp(url) {
|
|
21345
|
-
const { requestInit, eventSourceInit, authProvider, connectTimeout, fetch: userFetch } = this.serverConfig;
|
|
21701
|
+
const { requestInit, eventSourceInit, authProvider, connectTimeout, fetch: userFetch, allowedHosts } = this.serverConfig;
|
|
21702
|
+
if (allowedHosts !== void 0) assertHostAllowed(url, allowedHosts);
|
|
21703
|
+
const policyUserFetch = userFetch && allowedHosts !== void 0 ? wrapFetchWithHostPolicy(userFetch, allowedHosts) : void 0;
|
|
21346
21704
|
const fetch = (requestUrl, init) => {
|
|
21347
21705
|
const requestContext = this.operationContextStore.getStore() ?? null;
|
|
21348
|
-
const executeFetch = () =>
|
|
21706
|
+
const executeFetch = () => {
|
|
21707
|
+
if (allowedHosts === void 0) return userFetch ? userFetch(requestUrl, init, requestContext) : globalThis.fetch(requestUrl, init);
|
|
21708
|
+
if (policyUserFetch) return policyUserFetch(requestUrl, init, requestContext);
|
|
21709
|
+
return fetchFollowingAllowedRedirects((u, i) => globalThis.fetch(u, i), requestUrl, init, allowedHosts);
|
|
21710
|
+
};
|
|
21349
21711
|
return shouldDetachPersistentTransportRequest(init) ? runOutsideDatadogTraceScope(executeFetch) : executeFetch();
|
|
21350
21712
|
};
|
|
21351
21713
|
this.log("debug", `Attempting to connect to URL: ${url}`);
|
|
21352
21714
|
let shouldTrySSE = url.pathname.endsWith(`/sse`);
|
|
21353
21715
|
if (!shouldTrySSE) {
|
|
21354
|
-
const streamableTransport = new
|
|
21716
|
+
const streamableTransport = new _modelcontextprotocol_client.StreamableHTTPClientTransport(url, {
|
|
21355
21717
|
requestInit,
|
|
21356
21718
|
reconnectionOptions: this.serverConfig.reconnectionOptions,
|
|
21357
21719
|
authProvider,
|
|
@@ -21364,11 +21726,12 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21364
21726
|
this.log("debug", "Successfully connected using Streamable HTTP transport.");
|
|
21365
21727
|
} catch (error) {
|
|
21366
21728
|
this.log("debug", `Streamable HTTP transport failed: ${error}`);
|
|
21367
|
-
if (authProvider && error instanceof
|
|
21729
|
+
if (authProvider && error instanceof _modelcontextprotocol_client.UnauthorizedError) {
|
|
21368
21730
|
this.markNeedsAuth(streamableTransport);
|
|
21369
21731
|
throw error;
|
|
21370
21732
|
}
|
|
21371
|
-
|
|
21733
|
+
if (isUrlPolicyError(error)) throw error;
|
|
21734
|
+
const status = error instanceof _modelcontextprotocol_client.SdkHttpError ? error.status : void 0;
|
|
21372
21735
|
if (status !== void 0 && !SSE_FALLBACK_STATUS_CODES.includes(status)) throw error;
|
|
21373
21736
|
shouldTrySSE = true;
|
|
21374
21737
|
}
|
|
@@ -21376,11 +21739,12 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21376
21739
|
if (shouldTrySSE) {
|
|
21377
21740
|
await this.detachStaleClientTransport();
|
|
21378
21741
|
this.log("debug", "Falling back to deprecated HTTP+SSE transport...");
|
|
21379
|
-
const
|
|
21742
|
+
const callerSseFetch = eventSourceInit?.fetch;
|
|
21743
|
+
const sseTransport = new _modelcontextprotocol_client.SSEClientTransport(url, {
|
|
21380
21744
|
requestInit,
|
|
21381
21745
|
eventSourceInit: {
|
|
21382
21746
|
...eventSourceInit,
|
|
21383
|
-
fetch:
|
|
21747
|
+
fetch: callerSseFetch && allowedHosts !== void 0 ? wrapFetchWithHostPolicy(callerSseFetch, allowedHosts) : callerSseFetch ?? fetch
|
|
21384
21748
|
},
|
|
21385
21749
|
authProvider,
|
|
21386
21750
|
fetch
|
|
@@ -21390,10 +21754,11 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21390
21754
|
this.transport = sseTransport;
|
|
21391
21755
|
this.log("debug", "Successfully connected using deprecated HTTP+SSE transport.");
|
|
21392
21756
|
} catch (sseError) {
|
|
21393
|
-
if (authProvider && sseError instanceof
|
|
21757
|
+
if (authProvider && sseError instanceof _modelcontextprotocol_client.UnauthorizedError) {
|
|
21394
21758
|
this.markNeedsAuth(sseTransport);
|
|
21395
21759
|
throw sseError;
|
|
21396
21760
|
}
|
|
21761
|
+
if (isUrlPolicyError(sseError)) throw sseError;
|
|
21397
21762
|
this.log("error", `Failed to connect with SSE transport after failing to connect to Streamable HTTP transport first. SSE error: ${sseError}`);
|
|
21398
21763
|
throw new Error("Could not connect to server with any available HTTP transport");
|
|
21399
21764
|
}
|
|
@@ -21563,7 +21928,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21563
21928
|
* @internal
|
|
21564
21929
|
*/
|
|
21565
21930
|
get sessionId() {
|
|
21566
|
-
if (this.transport instanceof
|
|
21931
|
+
if (this.transport instanceof _modelcontextprotocol_client.StreamableHTTPClientTransport) return this.transport.sessionId;
|
|
21567
21932
|
}
|
|
21568
21933
|
/**
|
|
21569
21934
|
* Gets the stderr stream of the child process, if using stdio transport with `stderr: 'pipe'`.
|
|
@@ -21573,7 +21938,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21573
21938
|
* @internal
|
|
21574
21939
|
*/
|
|
21575
21940
|
get stderr() {
|
|
21576
|
-
if (this.transport instanceof
|
|
21941
|
+
if (this.transport instanceof _modelcontextprotocol_client_stdio.StdioClientTransport) return this.transport.stderr;
|
|
21577
21942
|
return null;
|
|
21578
21943
|
}
|
|
21579
21944
|
get instructions() {
|
|
@@ -21686,39 +22051,39 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21686
22051
|
}
|
|
21687
22052
|
async listResources() {
|
|
21688
22053
|
this.log("debug", `Requesting resources from MCP server`);
|
|
21689
|
-
return await this.client.request({ method: "resources/list" },
|
|
22054
|
+
return await this.client.request({ method: "resources/list" }, { timeout: this.timeout });
|
|
21690
22055
|
}
|
|
21691
22056
|
async readResource(uri) {
|
|
21692
22057
|
this.log("debug", `Reading resource from MCP server: ${uri}`);
|
|
21693
22058
|
return await this.client.request({
|
|
21694
22059
|
method: "resources/read",
|
|
21695
22060
|
params: { uri }
|
|
21696
|
-
},
|
|
22061
|
+
}, { timeout: this.timeout });
|
|
21697
22062
|
}
|
|
21698
22063
|
async subscribeResource(uri) {
|
|
21699
22064
|
this.log("debug", `Subscribing to resource on MCP server: ${uri}`);
|
|
21700
22065
|
return await this.client.request({
|
|
21701
22066
|
method: "resources/subscribe",
|
|
21702
22067
|
params: { uri }
|
|
21703
|
-
},
|
|
22068
|
+
}, { timeout: this.timeout });
|
|
21704
22069
|
}
|
|
21705
22070
|
async unsubscribeResource(uri) {
|
|
21706
22071
|
this.log("debug", `Unsubscribing from resource on MCP server: ${uri}`);
|
|
21707
22072
|
return await this.client.request({
|
|
21708
22073
|
method: "resources/unsubscribe",
|
|
21709
22074
|
params: { uri }
|
|
21710
|
-
},
|
|
22075
|
+
}, { timeout: this.timeout });
|
|
21711
22076
|
}
|
|
21712
22077
|
async listResourceTemplates() {
|
|
21713
22078
|
this.log("debug", `Requesting resource templates from MCP server`);
|
|
21714
|
-
return await this.client.request({ method: "resources/templates/list" },
|
|
22079
|
+
return await this.client.request({ method: "resources/templates/list" }, { timeout: this.timeout });
|
|
21715
22080
|
}
|
|
21716
22081
|
/**
|
|
21717
22082
|
* Fetch the list of available prompts from the MCP server.
|
|
21718
22083
|
*/
|
|
21719
22084
|
async listPrompts() {
|
|
21720
22085
|
this.log("debug", `Requesting prompts from MCP server`);
|
|
21721
|
-
return await this.client.request({ method: "prompts/list" },
|
|
22086
|
+
return await this.client.request({ method: "prompts/list" }, { timeout: this.timeout });
|
|
21722
22087
|
}
|
|
21723
22088
|
/**
|
|
21724
22089
|
* Get a prompt and its dynamic messages from the server.
|
|
@@ -21733,7 +22098,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21733
22098
|
name,
|
|
21734
22099
|
arguments: args
|
|
21735
22100
|
}
|
|
21736
|
-
},
|
|
22101
|
+
}, { timeout: this.timeout });
|
|
21737
22102
|
}
|
|
21738
22103
|
/**
|
|
21739
22104
|
* Register a handler to be called when the prompt list changes on the server.
|
|
@@ -21741,7 +22106,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21741
22106
|
*/
|
|
21742
22107
|
setPromptListChangedNotificationHandler(handler) {
|
|
21743
22108
|
this.log("debug", "Setting prompt list changed notification handler");
|
|
21744
|
-
this.client.setNotificationHandler(
|
|
22109
|
+
this.client.setNotificationHandler("notifications/prompts/list_changed", () => {
|
|
21745
22110
|
handler();
|
|
21746
22111
|
});
|
|
21747
22112
|
}
|
|
@@ -21751,19 +22116,19 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21751
22116
|
*/
|
|
21752
22117
|
setToolListChangedNotificationHandler(handler) {
|
|
21753
22118
|
this.log("debug", "Setting tool list changed notification handler");
|
|
21754
|
-
this.client.setNotificationHandler(
|
|
22119
|
+
this.client.setNotificationHandler("notifications/tools/list_changed", () => {
|
|
21755
22120
|
handler();
|
|
21756
22121
|
});
|
|
21757
22122
|
}
|
|
21758
22123
|
setResourceUpdatedNotificationHandler(handler) {
|
|
21759
22124
|
this.log("debug", "Setting resource updated notification handler");
|
|
21760
|
-
this.client.setNotificationHandler(
|
|
22125
|
+
this.client.setNotificationHandler("notifications/resources/updated", (notification) => {
|
|
21761
22126
|
handler(notification.params);
|
|
21762
22127
|
});
|
|
21763
22128
|
}
|
|
21764
22129
|
setResourceListChangedNotificationHandler(handler) {
|
|
21765
22130
|
this.log("debug", "Setting resource list changed notification handler");
|
|
21766
|
-
this.client.setNotificationHandler(
|
|
22131
|
+
this.client.setNotificationHandler("notifications/resources/list_changed", () => {
|
|
21767
22132
|
handler();
|
|
21768
22133
|
});
|
|
21769
22134
|
}
|
|
@@ -21775,14 +22140,14 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21775
22140
|
} catch (error) {
|
|
21776
22141
|
throw new Error("Cannot register an elicitation handler after connecting unless elicitation capability was configured before initialization.", { cause: error });
|
|
21777
22142
|
}
|
|
21778
|
-
this.client.setRequestHandler(
|
|
22143
|
+
this.client.setRequestHandler("elicitation/create", async (request) => {
|
|
21779
22144
|
this.log("debug", `Received elicitation request: ${request.params.message}`);
|
|
21780
22145
|
return handler(request.params);
|
|
21781
22146
|
});
|
|
21782
22147
|
}
|
|
21783
22148
|
setProgressNotificationHandler(handler) {
|
|
21784
22149
|
this.log("debug", "Setting progress notification handler");
|
|
21785
|
-
this.client.setNotificationHandler(
|
|
22150
|
+
this.client.setNotificationHandler("notifications/progress", (notification) => {
|
|
21786
22151
|
handler(notification.params);
|
|
21787
22152
|
});
|
|
21788
22153
|
}
|
|
@@ -21790,7 +22155,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21790
22155
|
return "jsonSchema" in inputSchema ? inputSchema.jsonSchema : inputSchema;
|
|
21791
22156
|
}
|
|
21792
22157
|
/**
|
|
21793
|
-
* Wraps the output schema with a validator that always succeeds. The MCP
|
|
22158
|
+
* Wraps the output schema with a validator that always succeeds. The MCP client validates
|
|
21794
22159
|
* structuredContent via AJV; the JSON schema is surfaced here for documentation only.
|
|
21795
22160
|
*/
|
|
21796
22161
|
convertOutputSchema(outputSchema) {
|
|
@@ -21829,6 +22194,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21829
22194
|
...toolMeta ? { _meta: toolMeta } : {},
|
|
21830
22195
|
...annotations ? { annotations } : {}
|
|
21831
22196
|
} } : {};
|
|
22197
|
+
const scalarMcpContentQueue = [];
|
|
21832
22198
|
const mastraTool = (0, _mastra_core_tools.createTool)({
|
|
21833
22199
|
id: `${this.name}_${tool.name}`,
|
|
21834
22200
|
description: tool.description || "",
|
|
@@ -21844,8 +22210,10 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21844
22210
|
forwardInstructions: this.forwardInstructions,
|
|
21845
22211
|
instructionsMaxLength: this.instructionsMaxLength
|
|
21846
22212
|
},
|
|
22213
|
+
...tool.outputSchema ? { toModelOutput: createStructuredToolToModelOutput(scalarMcpContentQueue) } : {},
|
|
21847
22214
|
execute: async (input, context) => {
|
|
21848
22215
|
const operationContext = context?.requestContext ?? null;
|
|
22216
|
+
const scalarMcpContentReservation = tool.outputSchema ? reserveScalarMcpContent(scalarMcpContentQueue) : void 0;
|
|
21849
22217
|
return this.operationContextStore.run(operationContext, async () => {
|
|
21850
22218
|
const executeToolCall = async () => {
|
|
21851
22219
|
this.log("debug", `Executing tool: ${tool.name}`, {
|
|
@@ -21862,7 +22230,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21862
22230
|
name: tool.name,
|
|
21863
22231
|
arguments: input,
|
|
21864
22232
|
...combinedMeta ? { _meta: combinedMeta } : {}
|
|
21865
|
-
},
|
|
22233
|
+
}, {
|
|
21866
22234
|
timeout: this.timeout,
|
|
21867
22235
|
signal: context?.abortSignal
|
|
21868
22236
|
});
|
|
@@ -21881,7 +22249,8 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21881
22249
|
});
|
|
21882
22250
|
}
|
|
21883
22251
|
this.log("debug", `Tool executed successfully: ${tool.name}`);
|
|
21884
|
-
if (res.structuredContent !== void 0) return res.structuredContent;
|
|
22252
|
+
if (res.structuredContent !== void 0) return attachMcpCallToolContent(res.structuredContent, res.content, scalarMcpContentQueue, scalarMcpContentReservation);
|
|
22253
|
+
removeScalarMcpContentReservation(scalarMcpContentQueue, scalarMcpContentReservation);
|
|
21885
22254
|
return res;
|
|
21886
22255
|
};
|
|
21887
22256
|
const failedTransport = this.transport;
|
|
@@ -21889,7 +22258,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21889
22258
|
try {
|
|
21890
22259
|
return await executeToolCall();
|
|
21891
22260
|
} catch (e) {
|
|
21892
|
-
if (isReconnectableMCPError(e)) {
|
|
22261
|
+
if (!(e instanceof _mastra_core_error.MastraError && e.id === "MCP_CLIENT_TOOL_EXECUTION_FAILED") && isReconnectableMCPError(e)) {
|
|
21893
22262
|
this.log("debug", `Session error detected for tool ${tool.name}, attempting reconnection...`, { error: e instanceof Error ? e.message : String(e) });
|
|
21894
22263
|
try {
|
|
21895
22264
|
await this.reconnectAfterTransportFailure(failedTransport, lifecycleGeneration);
|
|
@@ -21901,13 +22270,15 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
21901
22270
|
reconnectError: reconnectError instanceof Error ? reconnectError.stack : String(reconnectError),
|
|
21902
22271
|
toolArgs: input
|
|
21903
22272
|
});
|
|
21904
|
-
|
|
22273
|
+
removeScalarMcpContentReservation(scalarMcpContentQueue, scalarMcpContentReservation);
|
|
22274
|
+
throw reconnectError;
|
|
21905
22275
|
}
|
|
21906
22276
|
}
|
|
21907
22277
|
this.log("error", `Error calling tool: ${tool.name}`, {
|
|
21908
22278
|
error: e instanceof Error ? e.stack : JSON.stringify(e, null, 2),
|
|
21909
22279
|
toolArgs: input
|
|
21910
22280
|
});
|
|
22281
|
+
removeScalarMcpContentReservation(scalarMcpContentQueue, scalarMcpContentReservation);
|
|
21911
22282
|
throw e;
|
|
21912
22283
|
}
|
|
21913
22284
|
});
|
|
@@ -22643,7 +23014,7 @@ var MCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
22643
23014
|
*/
|
|
22644
23015
|
constructor(args) {
|
|
22645
23016
|
super({ name: "MCPClient" });
|
|
22646
|
-
this.defaultTimeout = args.timeout ??
|
|
23017
|
+
this.defaultTimeout = args.timeout ?? _modelcontextprotocol_client.DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
22647
23018
|
this.serverConfigs = args.servers;
|
|
22648
23019
|
this.id = args.id ?? this.makeId();
|
|
22649
23020
|
if (args.id) {
|
|
@@ -23285,14 +23656,14 @@ onListChanged: async (serverName, handler) => {
|
|
|
23285
23656
|
await client.connect();
|
|
23286
23657
|
return;
|
|
23287
23658
|
} catch (error) {
|
|
23288
|
-
if (!(error instanceof
|
|
23659
|
+
if (!(error instanceof _modelcontextprotocol_client.UnauthorizedError)) throw this.handleConnectError(serverName, error);
|
|
23289
23660
|
}
|
|
23290
23661
|
const { code } = await callbackServer.waitForCode(options);
|
|
23291
23662
|
await client.finishAuth(code);
|
|
23292
23663
|
try {
|
|
23293
23664
|
await client.connect();
|
|
23294
23665
|
} catch (error) {
|
|
23295
|
-
throw error instanceof
|
|
23666
|
+
throw error instanceof _modelcontextprotocol_client.UnauthorizedError ? error : this.handleConnectError(serverName, error);
|
|
23296
23667
|
}
|
|
23297
23668
|
} finally {
|
|
23298
23669
|
this.authCallbackServersByServer.delete(serverName);
|
|
@@ -23612,7 +23983,7 @@ onListChanged: async (serverName, handler) => {
|
|
|
23612
23983
|
}, error);
|
|
23613
23984
|
this.logger.trackException(mastraError);
|
|
23614
23985
|
this.logger.error("MCPClient errored connecting to MCP server:", { error: mastraError.toString() });
|
|
23615
|
-
if (!(error instanceof
|
|
23986
|
+
if (!(error instanceof _modelcontextprotocol_client.UnauthorizedError)) this.mcpClientsById.delete(name);
|
|
23616
23987
|
return mastraError;
|
|
23617
23988
|
}
|
|
23618
23989
|
async getConnectedClientForServer(serverName) {
|
|
@@ -23804,142 +24175,1973 @@ var streamSSE = (c, cb, onError) => {
|
|
|
23804
24175
|
return c.newResponse(stream.responseReadable);
|
|
23805
24176
|
};
|
|
23806
24177
|
//#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
|
|
24178
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@modelcontextprotocol/sdk/1.29.0/989ce0cb833930f9ef8da3e25bac11110cfeac46669bc69ae9534a6aa55b0aa7/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
24179
|
+
const RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
23883
24180
|
/**
|
|
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.
|
|
24181
|
+
* Assert 'object' type schema.
|
|
23893
24182
|
*
|
|
23894
24183
|
* @internal
|
|
23895
24184
|
*/
|
|
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
|
|
24185
|
+
const AssertObjectSchema = custom$1((v) => v !== null && (typeof v === "object" || typeof v === "function"));
|
|
23923
24186
|
/**
|
|
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.
|
|
24187
|
+
* A progress token, used to associate progress notifications with the original request.
|
|
23933
24188
|
*/
|
|
23934
|
-
|
|
23935
|
-
|
|
23936
|
-
|
|
23937
|
-
|
|
24189
|
+
const ProgressTokenSchema = union([string(), number().int()]);
|
|
24190
|
+
/**
|
|
24191
|
+
* An opaque token used to represent a cursor for pagination.
|
|
24192
|
+
*/
|
|
24193
|
+
const CursorSchema = string();
|
|
24194
|
+
looseObject({
|
|
23938
24195
|
/**
|
|
23939
|
-
*
|
|
24196
|
+
* Requested duration in milliseconds to retain task from creation.
|
|
23940
24197
|
*/
|
|
23941
|
-
|
|
23942
|
-
|
|
24198
|
+
ttl: number().optional(),
|
|
24199
|
+
/**
|
|
24200
|
+
* Time in milliseconds to wait between task status requests.
|
|
24201
|
+
*/
|
|
24202
|
+
pollInterval: number().optional()
|
|
24203
|
+
});
|
|
24204
|
+
const TaskMetadataSchema = object$1({ ttl: number().optional() });
|
|
24205
|
+
/**
|
|
24206
|
+
* Metadata for associating messages with a task.
|
|
24207
|
+
* Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
|
|
24208
|
+
*/
|
|
24209
|
+
const RelatedTaskMetadataSchema = object$1({ taskId: string() });
|
|
24210
|
+
const RequestMetaSchema = looseObject({
|
|
24211
|
+
/**
|
|
24212
|
+
* 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.
|
|
24213
|
+
*/
|
|
24214
|
+
progressToken: ProgressTokenSchema.optional(),
|
|
24215
|
+
/**
|
|
24216
|
+
* If specified, this request is related to the provided task.
|
|
24217
|
+
*/
|
|
24218
|
+
[RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
|
|
24219
|
+
});
|
|
24220
|
+
/**
|
|
24221
|
+
* Common params for any request.
|
|
24222
|
+
*/
|
|
24223
|
+
const BaseRequestParamsSchema = object$1({
|
|
24224
|
+
/**
|
|
24225
|
+
* See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
|
|
24226
|
+
*/
|
|
24227
|
+
_meta: RequestMetaSchema.optional() });
|
|
24228
|
+
/**
|
|
24229
|
+
* Common params for any task-augmented request.
|
|
24230
|
+
*/
|
|
24231
|
+
const TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24232
|
+
/**
|
|
24233
|
+
* If specified, the caller is requesting task-augmented execution for this request.
|
|
24234
|
+
* The request will return a CreateTaskResult immediately, and the actual result can be
|
|
24235
|
+
* retrieved later via tasks/result.
|
|
24236
|
+
*
|
|
24237
|
+
* Task augmentation is subject to capability negotiation - receivers MUST declare support
|
|
24238
|
+
* for task augmentation of specific request types in their capabilities.
|
|
24239
|
+
*/
|
|
24240
|
+
task: TaskMetadataSchema.optional() });
|
|
24241
|
+
const RequestSchema = object$1({
|
|
24242
|
+
method: string(),
|
|
24243
|
+
params: BaseRequestParamsSchema.loose().optional()
|
|
24244
|
+
});
|
|
24245
|
+
const NotificationsParamsSchema = object$1({
|
|
24246
|
+
/**
|
|
24247
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24248
|
+
* for notes on _meta usage.
|
|
24249
|
+
*/
|
|
24250
|
+
_meta: RequestMetaSchema.optional() });
|
|
24251
|
+
const NotificationSchema = object$1({
|
|
24252
|
+
method: string(),
|
|
24253
|
+
params: NotificationsParamsSchema.loose().optional()
|
|
24254
|
+
});
|
|
24255
|
+
const ResultSchema = looseObject({
|
|
24256
|
+
/**
|
|
24257
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24258
|
+
* for notes on _meta usage.
|
|
24259
|
+
*/
|
|
24260
|
+
_meta: RequestMetaSchema.optional() });
|
|
24261
|
+
/**
|
|
24262
|
+
* A uniquely identifying ID for a request in JSON-RPC.
|
|
24263
|
+
*/
|
|
24264
|
+
const RequestIdSchema = union([string(), number().int()]);
|
|
24265
|
+
/**
|
|
24266
|
+
* A request that expects a response.
|
|
24267
|
+
*/
|
|
24268
|
+
const JSONRPCRequestSchema = object$1({
|
|
24269
|
+
jsonrpc: literal("2.0"),
|
|
24270
|
+
id: RequestIdSchema,
|
|
24271
|
+
...RequestSchema.shape
|
|
24272
|
+
}).strict();
|
|
24273
|
+
/**
|
|
24274
|
+
* A notification which does not expect a response.
|
|
24275
|
+
*/
|
|
24276
|
+
const JSONRPCNotificationSchema = object$1({
|
|
24277
|
+
jsonrpc: literal("2.0"),
|
|
24278
|
+
...NotificationSchema.shape
|
|
24279
|
+
}).strict();
|
|
24280
|
+
/**
|
|
24281
|
+
* A successful (non-error) response to a request.
|
|
24282
|
+
*/
|
|
24283
|
+
const JSONRPCResultResponseSchema = object$1({
|
|
24284
|
+
jsonrpc: literal("2.0"),
|
|
24285
|
+
id: RequestIdSchema,
|
|
24286
|
+
result: ResultSchema
|
|
24287
|
+
}).strict();
|
|
24288
|
+
/**
|
|
24289
|
+
* Error codes defined by the JSON-RPC specification.
|
|
24290
|
+
*/
|
|
24291
|
+
var ErrorCode;
|
|
24292
|
+
(function(ErrorCode) {
|
|
24293
|
+
ErrorCode[ErrorCode["ConnectionClosed"] = -32e3] = "ConnectionClosed";
|
|
24294
|
+
ErrorCode[ErrorCode["RequestTimeout"] = -32001] = "RequestTimeout";
|
|
24295
|
+
ErrorCode[ErrorCode["ParseError"] = -32700] = "ParseError";
|
|
24296
|
+
ErrorCode[ErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
24297
|
+
ErrorCode[ErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
24298
|
+
ErrorCode[ErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
24299
|
+
ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError";
|
|
24300
|
+
ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
|
|
24301
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
24302
|
+
/**
|
|
24303
|
+
* A response to a request that indicates an error occurred.
|
|
24304
|
+
*/
|
|
24305
|
+
const JSONRPCErrorResponseSchema = object$1({
|
|
24306
|
+
jsonrpc: literal("2.0"),
|
|
24307
|
+
id: RequestIdSchema.optional(),
|
|
24308
|
+
error: object$1({
|
|
24309
|
+
/**
|
|
24310
|
+
* The error type that occurred.
|
|
24311
|
+
*/
|
|
24312
|
+
code: number().int(),
|
|
24313
|
+
/**
|
|
24314
|
+
* A short description of the error. The message SHOULD be limited to a concise single sentence.
|
|
24315
|
+
*/
|
|
24316
|
+
message: string(),
|
|
24317
|
+
/**
|
|
24318
|
+
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
24319
|
+
*/
|
|
24320
|
+
data: unknown().optional()
|
|
24321
|
+
})
|
|
24322
|
+
}).strict();
|
|
24323
|
+
const JSONRPCMessageSchema = union([
|
|
24324
|
+
JSONRPCRequestSchema,
|
|
24325
|
+
JSONRPCNotificationSchema,
|
|
24326
|
+
JSONRPCResultResponseSchema,
|
|
24327
|
+
JSONRPCErrorResponseSchema
|
|
24328
|
+
]);
|
|
24329
|
+
union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
|
|
24330
|
+
/**
|
|
24331
|
+
* A response that indicates success but carries no data.
|
|
24332
|
+
*/
|
|
24333
|
+
const EmptyResultSchema = ResultSchema.strict();
|
|
24334
|
+
const CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
24335
|
+
/**
|
|
24336
|
+
* The ID of the request to cancel.
|
|
24337
|
+
*
|
|
24338
|
+
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
24339
|
+
*/
|
|
24340
|
+
requestId: RequestIdSchema.optional(),
|
|
24341
|
+
/**
|
|
24342
|
+
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
24343
|
+
*/
|
|
24344
|
+
reason: string().optional()
|
|
24345
|
+
});
|
|
24346
|
+
/**
|
|
24347
|
+
* This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
|
|
24348
|
+
*
|
|
24349
|
+
* 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.
|
|
24350
|
+
*
|
|
24351
|
+
* This notification indicates that the result will be unused, so any associated processing SHOULD cease.
|
|
24352
|
+
*
|
|
24353
|
+
* A client MUST NOT attempt to cancel its `initialize` request.
|
|
24354
|
+
*/
|
|
24355
|
+
const CancelledNotificationSchema = NotificationSchema.extend({
|
|
24356
|
+
method: literal("notifications/cancelled"),
|
|
24357
|
+
params: CancelledNotificationParamsSchema
|
|
24358
|
+
});
|
|
24359
|
+
/**
|
|
24360
|
+
* Base schema to add `icons` property.
|
|
24361
|
+
*
|
|
24362
|
+
*/
|
|
24363
|
+
const IconsSchema = object$1({
|
|
24364
|
+
/**
|
|
24365
|
+
* Optional set of sized icons that the client can display in a user interface.
|
|
24366
|
+
*
|
|
24367
|
+
* Clients that support rendering icons MUST support at least the following MIME types:
|
|
24368
|
+
* - `image/png` - PNG images (safe, universal compatibility)
|
|
24369
|
+
* - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
|
|
24370
|
+
*
|
|
24371
|
+
* Clients that support rendering icons SHOULD also support:
|
|
24372
|
+
* - `image/svg+xml` - SVG images (scalable but requires security precautions)
|
|
24373
|
+
* - `image/webp` - WebP images (modern, efficient format)
|
|
24374
|
+
*/
|
|
24375
|
+
icons: array(object$1({
|
|
24376
|
+
/**
|
|
24377
|
+
* URL or data URI for the icon.
|
|
24378
|
+
*/
|
|
24379
|
+
src: string(),
|
|
24380
|
+
/**
|
|
24381
|
+
* Optional MIME type for the icon.
|
|
24382
|
+
*/
|
|
24383
|
+
mimeType: string().optional(),
|
|
24384
|
+
/**
|
|
24385
|
+
* Optional array of strings that specify sizes at which the icon can be used.
|
|
24386
|
+
* Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
|
|
24387
|
+
*
|
|
24388
|
+
* If not provided, the client should assume that the icon can be used at any size.
|
|
24389
|
+
*/
|
|
24390
|
+
sizes: array(string()).optional(),
|
|
24391
|
+
/**
|
|
24392
|
+
* Optional specifier for the theme this icon is designed for. `light` indicates
|
|
24393
|
+
* the icon is designed to be used with a light background, and `dark` indicates
|
|
24394
|
+
* the icon is designed to be used with a dark background.
|
|
24395
|
+
*
|
|
24396
|
+
* If not provided, the client should assume the icon can be used with any theme.
|
|
24397
|
+
*/
|
|
24398
|
+
theme: _enum(["light", "dark"]).optional()
|
|
24399
|
+
})).optional() });
|
|
24400
|
+
/**
|
|
24401
|
+
* Base metadata interface for common properties across resources, tools, prompts, and implementations.
|
|
24402
|
+
*/
|
|
24403
|
+
const BaseMetadataSchema = object$1({
|
|
24404
|
+
/** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
|
|
24405
|
+
name: string(),
|
|
24406
|
+
/**
|
|
24407
|
+
* Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
|
|
24408
|
+
* even by those unfamiliar with domain-specific terminology.
|
|
24409
|
+
*
|
|
24410
|
+
* If not provided, the name should be used for display (except for Tool,
|
|
24411
|
+
* where `annotations.title` should be given precedence over using `name`,
|
|
24412
|
+
* if present).
|
|
24413
|
+
*/
|
|
24414
|
+
title: string().optional()
|
|
24415
|
+
});
|
|
24416
|
+
/**
|
|
24417
|
+
* Describes the name and version of an MCP implementation.
|
|
24418
|
+
*/
|
|
24419
|
+
const ImplementationSchema = BaseMetadataSchema.extend({
|
|
24420
|
+
...BaseMetadataSchema.shape,
|
|
24421
|
+
...IconsSchema.shape,
|
|
24422
|
+
version: string(),
|
|
24423
|
+
/**
|
|
24424
|
+
* An optional URL of the website for this implementation.
|
|
24425
|
+
*/
|
|
24426
|
+
websiteUrl: string().optional(),
|
|
24427
|
+
/**
|
|
24428
|
+
* An optional human-readable description of what this implementation does.
|
|
24429
|
+
*
|
|
24430
|
+
* This can be used by clients or servers to provide context about their purpose
|
|
24431
|
+
* and capabilities. For example, a server might describe the types of resources
|
|
24432
|
+
* or tools it provides, while a client might describe its intended use case.
|
|
24433
|
+
*/
|
|
24434
|
+
description: string().optional()
|
|
24435
|
+
});
|
|
24436
|
+
const ElicitationCapabilitySchema = preprocess((value) => {
|
|
24437
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
24438
|
+
if (Object.keys(value).length === 0) return { form: {} };
|
|
24439
|
+
}
|
|
24440
|
+
return value;
|
|
24441
|
+
}, intersection(object$1({
|
|
24442
|
+
form: intersection(object$1({ applyDefaults: boolean().optional() }), record(string(), unknown())).optional(),
|
|
24443
|
+
url: AssertObjectSchema.optional()
|
|
24444
|
+
}), record(string(), unknown()).optional()));
|
|
24445
|
+
/**
|
|
24446
|
+
* Task capabilities for clients, indicating which request types support task creation.
|
|
24447
|
+
*/
|
|
24448
|
+
const ClientTasksCapabilitySchema = looseObject({
|
|
24449
|
+
/**
|
|
24450
|
+
* Present if the client supports listing tasks.
|
|
24451
|
+
*/
|
|
24452
|
+
list: AssertObjectSchema.optional(),
|
|
24453
|
+
/**
|
|
24454
|
+
* Present if the client supports cancelling tasks.
|
|
24455
|
+
*/
|
|
24456
|
+
cancel: AssertObjectSchema.optional(),
|
|
24457
|
+
/**
|
|
24458
|
+
* Capabilities for task creation on specific request types.
|
|
24459
|
+
*/
|
|
24460
|
+
requests: looseObject({
|
|
24461
|
+
/**
|
|
24462
|
+
* Task support for sampling requests.
|
|
24463
|
+
*/
|
|
24464
|
+
sampling: looseObject({ createMessage: AssertObjectSchema.optional() }).optional(),
|
|
24465
|
+
/**
|
|
24466
|
+
* Task support for elicitation requests.
|
|
24467
|
+
*/
|
|
24468
|
+
elicitation: looseObject({ create: AssertObjectSchema.optional() }).optional()
|
|
24469
|
+
}).optional()
|
|
24470
|
+
});
|
|
24471
|
+
/**
|
|
24472
|
+
* Task capabilities for servers, indicating which request types support task creation.
|
|
24473
|
+
*/
|
|
24474
|
+
const ServerTasksCapabilitySchema = looseObject({
|
|
24475
|
+
/**
|
|
24476
|
+
* Present if the server supports listing tasks.
|
|
24477
|
+
*/
|
|
24478
|
+
list: AssertObjectSchema.optional(),
|
|
24479
|
+
/**
|
|
24480
|
+
* Present if the server supports cancelling tasks.
|
|
24481
|
+
*/
|
|
24482
|
+
cancel: AssertObjectSchema.optional(),
|
|
24483
|
+
/**
|
|
24484
|
+
* Capabilities for task creation on specific request types.
|
|
24485
|
+
*/
|
|
24486
|
+
requests: looseObject({
|
|
24487
|
+
/**
|
|
24488
|
+
* Task support for tool requests.
|
|
24489
|
+
*/
|
|
24490
|
+
tools: looseObject({ call: AssertObjectSchema.optional() }).optional() }).optional()
|
|
24491
|
+
});
|
|
24492
|
+
/**
|
|
24493
|
+
* 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.
|
|
24494
|
+
*/
|
|
24495
|
+
const ClientCapabilitiesSchema = object$1({
|
|
24496
|
+
/**
|
|
24497
|
+
* Experimental, non-standard capabilities that the client supports.
|
|
24498
|
+
*/
|
|
24499
|
+
experimental: record(string(), AssertObjectSchema).optional(),
|
|
24500
|
+
/**
|
|
24501
|
+
* Present if the client supports sampling from an LLM.
|
|
24502
|
+
*/
|
|
24503
|
+
sampling: object$1({
|
|
24504
|
+
/**
|
|
24505
|
+
* Present if the client supports context inclusion via includeContext parameter.
|
|
24506
|
+
* If not declared, servers SHOULD only use `includeContext: "none"` (or omit it).
|
|
24507
|
+
*/
|
|
24508
|
+
context: AssertObjectSchema.optional(),
|
|
24509
|
+
/**
|
|
24510
|
+
* Present if the client supports tool use via tools and toolChoice parameters.
|
|
24511
|
+
*/
|
|
24512
|
+
tools: AssertObjectSchema.optional()
|
|
24513
|
+
}).optional(),
|
|
24514
|
+
/**
|
|
24515
|
+
* Present if the client supports eliciting user input.
|
|
24516
|
+
*/
|
|
24517
|
+
elicitation: ElicitationCapabilitySchema.optional(),
|
|
24518
|
+
/**
|
|
24519
|
+
* Present if the client supports listing roots.
|
|
24520
|
+
*/
|
|
24521
|
+
roots: object$1({
|
|
24522
|
+
/**
|
|
24523
|
+
* Whether the client supports issuing notifications for changes to the roots list.
|
|
24524
|
+
*/
|
|
24525
|
+
listChanged: boolean().optional() }).optional(),
|
|
24526
|
+
/**
|
|
24527
|
+
* Present if the client supports task creation.
|
|
24528
|
+
*/
|
|
24529
|
+
tasks: ClientTasksCapabilitySchema.optional(),
|
|
24530
|
+
/**
|
|
24531
|
+
* Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
|
|
24532
|
+
*/
|
|
24533
|
+
extensions: record(string(), AssertObjectSchema).optional()
|
|
24534
|
+
});
|
|
24535
|
+
const InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24536
|
+
/**
|
|
24537
|
+
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
|
|
24538
|
+
*/
|
|
24539
|
+
protocolVersion: string(),
|
|
24540
|
+
capabilities: ClientCapabilitiesSchema,
|
|
24541
|
+
clientInfo: ImplementationSchema
|
|
24542
|
+
});
|
|
24543
|
+
/**
|
|
24544
|
+
* This request is sent from the client to the server when it first connects, asking it to begin initialization.
|
|
24545
|
+
*/
|
|
24546
|
+
const InitializeRequestSchema = RequestSchema.extend({
|
|
24547
|
+
method: literal("initialize"),
|
|
24548
|
+
params: InitializeRequestParamsSchema
|
|
24549
|
+
});
|
|
24550
|
+
/**
|
|
24551
|
+
* 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.
|
|
24552
|
+
*/
|
|
24553
|
+
const ServerCapabilitiesSchema = object$1({
|
|
24554
|
+
/**
|
|
24555
|
+
* Experimental, non-standard capabilities that the server supports.
|
|
24556
|
+
*/
|
|
24557
|
+
experimental: record(string(), AssertObjectSchema).optional(),
|
|
24558
|
+
/**
|
|
24559
|
+
* Present if the server supports sending log messages to the client.
|
|
24560
|
+
*/
|
|
24561
|
+
logging: AssertObjectSchema.optional(),
|
|
24562
|
+
/**
|
|
24563
|
+
* Present if the server supports sending completions to the client.
|
|
24564
|
+
*/
|
|
24565
|
+
completions: AssertObjectSchema.optional(),
|
|
24566
|
+
/**
|
|
24567
|
+
* Present if the server offers any prompt templates.
|
|
24568
|
+
*/
|
|
24569
|
+
prompts: object$1({
|
|
24570
|
+
/**
|
|
24571
|
+
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
24572
|
+
*/
|
|
24573
|
+
listChanged: boolean().optional() }).optional(),
|
|
24574
|
+
/**
|
|
24575
|
+
* Present if the server offers any resources to read.
|
|
24576
|
+
*/
|
|
24577
|
+
resources: object$1({
|
|
24578
|
+
/**
|
|
24579
|
+
* Whether this server supports clients subscribing to resource updates.
|
|
24580
|
+
*/
|
|
24581
|
+
subscribe: boolean().optional(),
|
|
24582
|
+
/**
|
|
24583
|
+
* Whether this server supports issuing notifications for changes to the resource list.
|
|
24584
|
+
*/
|
|
24585
|
+
listChanged: boolean().optional()
|
|
24586
|
+
}).optional(),
|
|
24587
|
+
/**
|
|
24588
|
+
* Present if the server offers any tools to call.
|
|
24589
|
+
*/
|
|
24590
|
+
tools: object$1({
|
|
24591
|
+
/**
|
|
24592
|
+
* Whether this server supports issuing notifications for changes to the tool list.
|
|
24593
|
+
*/
|
|
24594
|
+
listChanged: boolean().optional() }).optional(),
|
|
24595
|
+
/**
|
|
24596
|
+
* Present if the server supports task creation.
|
|
24597
|
+
*/
|
|
24598
|
+
tasks: ServerTasksCapabilitySchema.optional(),
|
|
24599
|
+
/**
|
|
24600
|
+
* Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
|
|
24601
|
+
*/
|
|
24602
|
+
extensions: record(string(), AssertObjectSchema).optional()
|
|
24603
|
+
});
|
|
24604
|
+
/**
|
|
24605
|
+
* After receiving an initialize request from the client, the server sends this response.
|
|
24606
|
+
*/
|
|
24607
|
+
const InitializeResultSchema = ResultSchema.extend({
|
|
24608
|
+
/**
|
|
24609
|
+
* 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.
|
|
24610
|
+
*/
|
|
24611
|
+
protocolVersion: string(),
|
|
24612
|
+
capabilities: ServerCapabilitiesSchema,
|
|
24613
|
+
serverInfo: ImplementationSchema,
|
|
24614
|
+
/**
|
|
24615
|
+
* Instructions describing how to use the server and its features.
|
|
24616
|
+
*
|
|
24617
|
+
* 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.
|
|
24618
|
+
*/
|
|
24619
|
+
instructions: string().optional()
|
|
24620
|
+
});
|
|
24621
|
+
/**
|
|
24622
|
+
* This notification is sent from the client to the server after initialization has finished.
|
|
24623
|
+
*/
|
|
24624
|
+
const InitializedNotificationSchema = NotificationSchema.extend({
|
|
24625
|
+
method: literal("notifications/initialized"),
|
|
24626
|
+
params: NotificationsParamsSchema.optional()
|
|
24627
|
+
});
|
|
24628
|
+
/**
|
|
24629
|
+
* 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.
|
|
24630
|
+
*/
|
|
24631
|
+
const PingRequestSchema = RequestSchema.extend({
|
|
24632
|
+
method: literal("ping"),
|
|
24633
|
+
params: BaseRequestParamsSchema.optional()
|
|
24634
|
+
});
|
|
24635
|
+
const ProgressSchema = object$1({
|
|
24636
|
+
/**
|
|
24637
|
+
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
24638
|
+
*/
|
|
24639
|
+
progress: number(),
|
|
24640
|
+
/**
|
|
24641
|
+
* Total number of items to process (or total progress required), if known.
|
|
24642
|
+
*/
|
|
24643
|
+
total: optional(number()),
|
|
24644
|
+
/**
|
|
24645
|
+
* An optional message describing the current progress.
|
|
24646
|
+
*/
|
|
24647
|
+
message: optional(string())
|
|
24648
|
+
});
|
|
24649
|
+
const ProgressNotificationParamsSchema = object$1({
|
|
24650
|
+
...NotificationsParamsSchema.shape,
|
|
24651
|
+
...ProgressSchema.shape,
|
|
24652
|
+
/**
|
|
24653
|
+
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
|
|
24654
|
+
*/
|
|
24655
|
+
progressToken: ProgressTokenSchema
|
|
24656
|
+
});
|
|
24657
|
+
/**
|
|
24658
|
+
* An out-of-band notification used to inform the receiver of a progress update for a long-running request.
|
|
24659
|
+
*
|
|
24660
|
+
* @category notifications/progress
|
|
24661
|
+
*/
|
|
24662
|
+
const ProgressNotificationSchema = NotificationSchema.extend({
|
|
24663
|
+
method: literal("notifications/progress"),
|
|
24664
|
+
params: ProgressNotificationParamsSchema
|
|
24665
|
+
});
|
|
24666
|
+
const PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24667
|
+
/**
|
|
24668
|
+
* An opaque token representing the current pagination position.
|
|
24669
|
+
* If provided, the server should return results starting after this cursor.
|
|
24670
|
+
*/
|
|
24671
|
+
cursor: CursorSchema.optional() });
|
|
24672
|
+
const PaginatedRequestSchema = RequestSchema.extend({ params: PaginatedRequestParamsSchema.optional() });
|
|
24673
|
+
const PaginatedResultSchema = ResultSchema.extend({
|
|
24674
|
+
/**
|
|
24675
|
+
* An opaque token representing the pagination position after the last returned result.
|
|
24676
|
+
* If present, there may be more results available.
|
|
24677
|
+
*/
|
|
24678
|
+
nextCursor: CursorSchema.optional() });
|
|
24679
|
+
/**
|
|
24680
|
+
* The status of a task.
|
|
24681
|
+
* */
|
|
24682
|
+
const TaskStatusSchema = _enum([
|
|
24683
|
+
"working",
|
|
24684
|
+
"input_required",
|
|
24685
|
+
"completed",
|
|
24686
|
+
"failed",
|
|
24687
|
+
"cancelled"
|
|
24688
|
+
]);
|
|
24689
|
+
/**
|
|
24690
|
+
* A pollable state object associated with a request.
|
|
24691
|
+
*/
|
|
24692
|
+
const TaskSchema = object$1({
|
|
24693
|
+
taskId: string(),
|
|
24694
|
+
status: TaskStatusSchema,
|
|
24695
|
+
/**
|
|
24696
|
+
* Time in milliseconds to keep task results available after completion.
|
|
24697
|
+
* If null, the task has unlimited lifetime until manually cleaned up.
|
|
24698
|
+
*/
|
|
24699
|
+
ttl: union([number(), _null()]),
|
|
24700
|
+
/**
|
|
24701
|
+
* ISO 8601 timestamp when the task was created.
|
|
24702
|
+
*/
|
|
24703
|
+
createdAt: string(),
|
|
24704
|
+
/**
|
|
24705
|
+
* ISO 8601 timestamp when the task was last updated.
|
|
24706
|
+
*/
|
|
24707
|
+
lastUpdatedAt: string(),
|
|
24708
|
+
pollInterval: optional(number()),
|
|
24709
|
+
/**
|
|
24710
|
+
* Optional diagnostic message for failed tasks or other status information.
|
|
24711
|
+
*/
|
|
24712
|
+
statusMessage: optional(string())
|
|
24713
|
+
});
|
|
24714
|
+
/**
|
|
24715
|
+
* Result returned when a task is created, containing the task data wrapped in a task field.
|
|
24716
|
+
*/
|
|
24717
|
+
const CreateTaskResultSchema = ResultSchema.extend({ task: TaskSchema });
|
|
24718
|
+
/**
|
|
24719
|
+
* Parameters for task status notification.
|
|
24720
|
+
*/
|
|
24721
|
+
const TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
|
|
24722
|
+
/**
|
|
24723
|
+
* A notification sent when a task's status changes.
|
|
24724
|
+
*/
|
|
24725
|
+
const TaskStatusNotificationSchema = NotificationSchema.extend({
|
|
24726
|
+
method: literal("notifications/tasks/status"),
|
|
24727
|
+
params: TaskStatusNotificationParamsSchema
|
|
24728
|
+
});
|
|
24729
|
+
/**
|
|
24730
|
+
* A request to get the state of a specific task.
|
|
24731
|
+
*/
|
|
24732
|
+
const GetTaskRequestSchema = RequestSchema.extend({
|
|
24733
|
+
method: literal("tasks/get"),
|
|
24734
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
24735
|
+
});
|
|
24736
|
+
/**
|
|
24737
|
+
* The response to a tasks/get request.
|
|
24738
|
+
*/
|
|
24739
|
+
const GetTaskResultSchema = ResultSchema.merge(TaskSchema);
|
|
24740
|
+
/**
|
|
24741
|
+
* A request to get the result of a specific task.
|
|
24742
|
+
*/
|
|
24743
|
+
const GetTaskPayloadRequestSchema = RequestSchema.extend({
|
|
24744
|
+
method: literal("tasks/result"),
|
|
24745
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
24746
|
+
});
|
|
24747
|
+
ResultSchema.loose();
|
|
24748
|
+
/**
|
|
24749
|
+
* A request to list tasks.
|
|
24750
|
+
*/
|
|
24751
|
+
const ListTasksRequestSchema = PaginatedRequestSchema.extend({ method: literal("tasks/list") });
|
|
24752
|
+
/**
|
|
24753
|
+
* The response to a tasks/list request.
|
|
24754
|
+
*/
|
|
24755
|
+
const ListTasksResultSchema = PaginatedResultSchema.extend({ tasks: array(TaskSchema) });
|
|
24756
|
+
/**
|
|
24757
|
+
* A request to cancel a specific task.
|
|
24758
|
+
*/
|
|
24759
|
+
const CancelTaskRequestSchema = RequestSchema.extend({
|
|
24760
|
+
method: literal("tasks/cancel"),
|
|
24761
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
24762
|
+
});
|
|
24763
|
+
ResultSchema.merge(TaskSchema);
|
|
24764
|
+
/**
|
|
24765
|
+
* The contents of a specific resource or sub-resource.
|
|
24766
|
+
*/
|
|
24767
|
+
const ResourceContentsSchema = object$1({
|
|
24768
|
+
/**
|
|
24769
|
+
* The URI of this resource.
|
|
24770
|
+
*/
|
|
24771
|
+
uri: string(),
|
|
24772
|
+
/**
|
|
24773
|
+
* The MIME type of this resource, if known.
|
|
24774
|
+
*/
|
|
24775
|
+
mimeType: optional(string()),
|
|
24776
|
+
/**
|
|
24777
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24778
|
+
* for notes on _meta usage.
|
|
24779
|
+
*/
|
|
24780
|
+
_meta: record(string(), unknown()).optional()
|
|
24781
|
+
});
|
|
24782
|
+
const TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
24783
|
+
/**
|
|
24784
|
+
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
|
|
24785
|
+
*/
|
|
24786
|
+
text: string() });
|
|
24787
|
+
/**
|
|
24788
|
+
* A Zod schema for validating Base64 strings that is more performant and
|
|
24789
|
+
* robust for very large inputs than the default regex-based check. It avoids
|
|
24790
|
+
* stack overflows by using the native `atob` function for validation.
|
|
24791
|
+
*/
|
|
24792
|
+
const Base64Schema = string().refine((val) => {
|
|
24793
|
+
try {
|
|
24794
|
+
atob(val);
|
|
24795
|
+
return true;
|
|
24796
|
+
} catch {
|
|
24797
|
+
return false;
|
|
24798
|
+
}
|
|
24799
|
+
}, { message: "Invalid Base64 string" });
|
|
24800
|
+
const BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
24801
|
+
/**
|
|
24802
|
+
* A base64-encoded string representing the binary data of the item.
|
|
24803
|
+
*/
|
|
24804
|
+
blob: Base64Schema });
|
|
24805
|
+
/**
|
|
24806
|
+
* The sender or recipient of messages and data in a conversation.
|
|
24807
|
+
*/
|
|
24808
|
+
const RoleSchema = _enum(["user", "assistant"]);
|
|
24809
|
+
/**
|
|
24810
|
+
* Optional annotations providing clients additional context about a resource.
|
|
24811
|
+
*/
|
|
24812
|
+
const AnnotationsSchema = object$1({
|
|
24813
|
+
/**
|
|
24814
|
+
* Intended audience(s) for the resource.
|
|
24815
|
+
*/
|
|
24816
|
+
audience: array(RoleSchema).optional(),
|
|
24817
|
+
/**
|
|
24818
|
+
* Importance hint for the resource, from 0 (least) to 1 (most).
|
|
24819
|
+
*/
|
|
24820
|
+
priority: number().min(0).max(1).optional(),
|
|
24821
|
+
/**
|
|
24822
|
+
* ISO 8601 timestamp for the most recent modification.
|
|
24823
|
+
*/
|
|
24824
|
+
lastModified: datetime({ offset: true }).optional()
|
|
24825
|
+
});
|
|
24826
|
+
/**
|
|
24827
|
+
* A known resource that the server is capable of reading.
|
|
24828
|
+
*/
|
|
24829
|
+
const ResourceSchema = object$1({
|
|
24830
|
+
...BaseMetadataSchema.shape,
|
|
24831
|
+
...IconsSchema.shape,
|
|
24832
|
+
/**
|
|
24833
|
+
* The URI of this resource.
|
|
24834
|
+
*/
|
|
24835
|
+
uri: string(),
|
|
24836
|
+
/**
|
|
24837
|
+
* A description of what this resource represents.
|
|
24838
|
+
*
|
|
24839
|
+
* 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.
|
|
24840
|
+
*/
|
|
24841
|
+
description: optional(string()),
|
|
24842
|
+
/**
|
|
24843
|
+
* The MIME type of this resource, if known.
|
|
24844
|
+
*/
|
|
24845
|
+
mimeType: optional(string()),
|
|
24846
|
+
/**
|
|
24847
|
+
* The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
|
|
24848
|
+
*
|
|
24849
|
+
* This can be used by Hosts to display file sizes and estimate context window usage.
|
|
24850
|
+
*/
|
|
24851
|
+
size: optional(number()),
|
|
24852
|
+
/**
|
|
24853
|
+
* Optional annotations for the client.
|
|
24854
|
+
*/
|
|
24855
|
+
annotations: AnnotationsSchema.optional(),
|
|
24856
|
+
/**
|
|
24857
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24858
|
+
* for notes on _meta usage.
|
|
24859
|
+
*/
|
|
24860
|
+
_meta: optional(looseObject({}))
|
|
24861
|
+
});
|
|
24862
|
+
/**
|
|
24863
|
+
* A template description for resources available on the server.
|
|
24864
|
+
*/
|
|
24865
|
+
const ResourceTemplateSchema = object$1({
|
|
24866
|
+
...BaseMetadataSchema.shape,
|
|
24867
|
+
...IconsSchema.shape,
|
|
24868
|
+
/**
|
|
24869
|
+
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
|
|
24870
|
+
*/
|
|
24871
|
+
uriTemplate: string(),
|
|
24872
|
+
/**
|
|
24873
|
+
* A description of what this template is for.
|
|
24874
|
+
*
|
|
24875
|
+
* 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.
|
|
24876
|
+
*/
|
|
24877
|
+
description: optional(string()),
|
|
24878
|
+
/**
|
|
24879
|
+
* 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.
|
|
24880
|
+
*/
|
|
24881
|
+
mimeType: optional(string()),
|
|
24882
|
+
/**
|
|
24883
|
+
* Optional annotations for the client.
|
|
24884
|
+
*/
|
|
24885
|
+
annotations: AnnotationsSchema.optional(),
|
|
24886
|
+
/**
|
|
24887
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24888
|
+
* for notes on _meta usage.
|
|
24889
|
+
*/
|
|
24890
|
+
_meta: optional(looseObject({}))
|
|
24891
|
+
});
|
|
24892
|
+
/**
|
|
24893
|
+
* Sent from the client to request a list of resources the server has.
|
|
24894
|
+
*/
|
|
24895
|
+
const ListResourcesRequestSchema = PaginatedRequestSchema.extend({ method: literal("resources/list") });
|
|
24896
|
+
/**
|
|
24897
|
+
* The server's response to a resources/list request from the client.
|
|
24898
|
+
*/
|
|
24899
|
+
const ListResourcesResultSchema = PaginatedResultSchema.extend({ resources: array(ResourceSchema) });
|
|
24900
|
+
/**
|
|
24901
|
+
* Sent from the client to request a list of resource templates the server has.
|
|
24902
|
+
*/
|
|
24903
|
+
const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({ method: literal("resources/templates/list") });
|
|
24904
|
+
/**
|
|
24905
|
+
* The server's response to a resources/templates/list request from the client.
|
|
24906
|
+
*/
|
|
24907
|
+
const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({ resourceTemplates: array(ResourceTemplateSchema) });
|
|
24908
|
+
const ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24909
|
+
/**
|
|
24910
|
+
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
|
|
24911
|
+
*
|
|
24912
|
+
* @format uri
|
|
24913
|
+
*/
|
|
24914
|
+
uri: string() });
|
|
24915
|
+
/**
|
|
24916
|
+
* Parameters for a `resources/read` request.
|
|
24917
|
+
*/
|
|
24918
|
+
const ReadResourceRequestParamsSchema = ResourceRequestParamsSchema;
|
|
24919
|
+
/**
|
|
24920
|
+
* Sent from the client to the server, to read a specific resource URI.
|
|
24921
|
+
*/
|
|
24922
|
+
const ReadResourceRequestSchema = RequestSchema.extend({
|
|
24923
|
+
method: literal("resources/read"),
|
|
24924
|
+
params: ReadResourceRequestParamsSchema
|
|
24925
|
+
});
|
|
24926
|
+
/**
|
|
24927
|
+
* The server's response to a resources/read request from the client.
|
|
24928
|
+
*/
|
|
24929
|
+
const ReadResourceResultSchema = ResultSchema.extend({ contents: array(union([TextResourceContentsSchema, BlobResourceContentsSchema])) });
|
|
24930
|
+
/**
|
|
24931
|
+
* 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.
|
|
24932
|
+
*/
|
|
24933
|
+
const ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
24934
|
+
method: literal("notifications/resources/list_changed"),
|
|
24935
|
+
params: NotificationsParamsSchema.optional()
|
|
24936
|
+
});
|
|
24937
|
+
const SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
24938
|
+
/**
|
|
24939
|
+
* Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
|
|
24940
|
+
*/
|
|
24941
|
+
const SubscribeRequestSchema = RequestSchema.extend({
|
|
24942
|
+
method: literal("resources/subscribe"),
|
|
24943
|
+
params: SubscribeRequestParamsSchema
|
|
24944
|
+
});
|
|
24945
|
+
const UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
24946
|
+
/**
|
|
24947
|
+
* Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
|
|
24948
|
+
*/
|
|
24949
|
+
const UnsubscribeRequestSchema = RequestSchema.extend({
|
|
24950
|
+
method: literal("resources/unsubscribe"),
|
|
24951
|
+
params: UnsubscribeRequestParamsSchema
|
|
24952
|
+
});
|
|
24953
|
+
/**
|
|
24954
|
+
* Parameters for a `notifications/resources/updated` notification.
|
|
24955
|
+
*/
|
|
24956
|
+
const ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
24957
|
+
/**
|
|
24958
|
+
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
|
|
24959
|
+
*/
|
|
24960
|
+
uri: string() });
|
|
24961
|
+
/**
|
|
24962
|
+
* 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.
|
|
24963
|
+
*/
|
|
24964
|
+
const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
24965
|
+
method: literal("notifications/resources/updated"),
|
|
24966
|
+
params: ResourceUpdatedNotificationParamsSchema
|
|
24967
|
+
});
|
|
24968
|
+
/**
|
|
24969
|
+
* Describes an argument that a prompt can accept.
|
|
24970
|
+
*/
|
|
24971
|
+
const PromptArgumentSchema = object$1({
|
|
24972
|
+
/**
|
|
24973
|
+
* The name of the argument.
|
|
24974
|
+
*/
|
|
24975
|
+
name: string(),
|
|
24976
|
+
/**
|
|
24977
|
+
* A human-readable description of the argument.
|
|
24978
|
+
*/
|
|
24979
|
+
description: optional(string()),
|
|
24980
|
+
/**
|
|
24981
|
+
* Whether this argument must be provided.
|
|
24982
|
+
*/
|
|
24983
|
+
required: optional(boolean())
|
|
24984
|
+
});
|
|
24985
|
+
/**
|
|
24986
|
+
* A prompt or prompt template that the server offers.
|
|
24987
|
+
*/
|
|
24988
|
+
const PromptSchema$1 = object$1({
|
|
24989
|
+
...BaseMetadataSchema.shape,
|
|
24990
|
+
...IconsSchema.shape,
|
|
24991
|
+
/**
|
|
24992
|
+
* An optional description of what this prompt provides
|
|
24993
|
+
*/
|
|
24994
|
+
description: optional(string()),
|
|
24995
|
+
/**
|
|
24996
|
+
* A list of arguments to use for templating the prompt.
|
|
24997
|
+
*/
|
|
24998
|
+
arguments: optional(array(PromptArgumentSchema)),
|
|
24999
|
+
/**
|
|
25000
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25001
|
+
* for notes on _meta usage.
|
|
25002
|
+
*/
|
|
25003
|
+
_meta: optional(looseObject({}))
|
|
25004
|
+
});
|
|
25005
|
+
/**
|
|
25006
|
+
* Sent from the client to request a list of prompts and prompt templates the server has.
|
|
25007
|
+
*/
|
|
25008
|
+
const ListPromptsRequestSchema = PaginatedRequestSchema.extend({ method: literal("prompts/list") });
|
|
25009
|
+
/**
|
|
25010
|
+
* The server's response to a prompts/list request from the client.
|
|
25011
|
+
*/
|
|
25012
|
+
const ListPromptsResultSchema = PaginatedResultSchema.extend({ prompts: array(PromptSchema$1) });
|
|
25013
|
+
/**
|
|
25014
|
+
* Parameters for a `prompts/get` request.
|
|
25015
|
+
*/
|
|
25016
|
+
const GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
25017
|
+
/**
|
|
25018
|
+
* The name of the prompt or prompt template.
|
|
25019
|
+
*/
|
|
25020
|
+
name: string(),
|
|
25021
|
+
/**
|
|
25022
|
+
* Arguments to use for templating the prompt.
|
|
25023
|
+
*/
|
|
25024
|
+
arguments: record(string(), string()).optional()
|
|
25025
|
+
});
|
|
25026
|
+
/**
|
|
25027
|
+
* Used by the client to get a prompt provided by the server.
|
|
25028
|
+
*/
|
|
25029
|
+
const GetPromptRequestSchema = RequestSchema.extend({
|
|
25030
|
+
method: literal("prompts/get"),
|
|
25031
|
+
params: GetPromptRequestParamsSchema
|
|
25032
|
+
});
|
|
25033
|
+
/**
|
|
25034
|
+
* Text provided to or from an LLM.
|
|
25035
|
+
*/
|
|
25036
|
+
const TextContentSchema = object$1({
|
|
25037
|
+
type: literal("text"),
|
|
25038
|
+
/**
|
|
25039
|
+
* The text content of the message.
|
|
25040
|
+
*/
|
|
25041
|
+
text: string(),
|
|
25042
|
+
/**
|
|
25043
|
+
* Optional annotations for the client.
|
|
25044
|
+
*/
|
|
25045
|
+
annotations: AnnotationsSchema.optional(),
|
|
25046
|
+
/**
|
|
25047
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25048
|
+
* for notes on _meta usage.
|
|
25049
|
+
*/
|
|
25050
|
+
_meta: record(string(), unknown()).optional()
|
|
25051
|
+
});
|
|
25052
|
+
/**
|
|
25053
|
+
* An image provided to or from an LLM.
|
|
25054
|
+
*/
|
|
25055
|
+
const ImageContentSchema = object$1({
|
|
25056
|
+
type: literal("image"),
|
|
25057
|
+
/**
|
|
25058
|
+
* The base64-encoded image data.
|
|
25059
|
+
*/
|
|
25060
|
+
data: Base64Schema,
|
|
25061
|
+
/**
|
|
25062
|
+
* The MIME type of the image. Different providers may support different image types.
|
|
25063
|
+
*/
|
|
25064
|
+
mimeType: string(),
|
|
25065
|
+
/**
|
|
25066
|
+
* Optional annotations for the client.
|
|
25067
|
+
*/
|
|
25068
|
+
annotations: AnnotationsSchema.optional(),
|
|
25069
|
+
/**
|
|
25070
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25071
|
+
* for notes on _meta usage.
|
|
25072
|
+
*/
|
|
25073
|
+
_meta: record(string(), unknown()).optional()
|
|
25074
|
+
});
|
|
25075
|
+
/**
|
|
25076
|
+
* An Audio provided to or from an LLM.
|
|
25077
|
+
*/
|
|
25078
|
+
const AudioContentSchema = object$1({
|
|
25079
|
+
type: literal("audio"),
|
|
25080
|
+
/**
|
|
25081
|
+
* The base64-encoded audio data.
|
|
25082
|
+
*/
|
|
25083
|
+
data: Base64Schema,
|
|
25084
|
+
/**
|
|
25085
|
+
* The MIME type of the audio. Different providers may support different audio types.
|
|
25086
|
+
*/
|
|
25087
|
+
mimeType: string(),
|
|
25088
|
+
/**
|
|
25089
|
+
* Optional annotations for the client.
|
|
25090
|
+
*/
|
|
25091
|
+
annotations: AnnotationsSchema.optional(),
|
|
25092
|
+
/**
|
|
25093
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25094
|
+
* for notes on _meta usage.
|
|
25095
|
+
*/
|
|
25096
|
+
_meta: record(string(), unknown()).optional()
|
|
25097
|
+
});
|
|
25098
|
+
/**
|
|
25099
|
+
* A tool call request from an assistant (LLM).
|
|
25100
|
+
* Represents the assistant's request to use a tool.
|
|
25101
|
+
*/
|
|
25102
|
+
const ToolUseContentSchema = object$1({
|
|
25103
|
+
type: literal("tool_use"),
|
|
25104
|
+
/**
|
|
25105
|
+
* The name of the tool to invoke.
|
|
25106
|
+
* Must match a tool name from the request's tools array.
|
|
25107
|
+
*/
|
|
25108
|
+
name: string(),
|
|
25109
|
+
/**
|
|
25110
|
+
* Unique identifier for this tool call.
|
|
25111
|
+
* Used to correlate with ToolResultContent in subsequent messages.
|
|
25112
|
+
*/
|
|
25113
|
+
id: string(),
|
|
25114
|
+
/**
|
|
25115
|
+
* Arguments to pass to the tool.
|
|
25116
|
+
* Must conform to the tool's inputSchema.
|
|
25117
|
+
*/
|
|
25118
|
+
input: record(string(), unknown()),
|
|
25119
|
+
/**
|
|
25120
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25121
|
+
* for notes on _meta usage.
|
|
25122
|
+
*/
|
|
25123
|
+
_meta: record(string(), unknown()).optional()
|
|
25124
|
+
});
|
|
25125
|
+
/**
|
|
25126
|
+
* The contents of a resource, embedded into a prompt or tool call result.
|
|
25127
|
+
*/
|
|
25128
|
+
const EmbeddedResourceSchema = object$1({
|
|
25129
|
+
type: literal("resource"),
|
|
25130
|
+
resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
|
|
25131
|
+
/**
|
|
25132
|
+
* Optional annotations for the client.
|
|
25133
|
+
*/
|
|
25134
|
+
annotations: AnnotationsSchema.optional(),
|
|
25135
|
+
/**
|
|
25136
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25137
|
+
* for notes on _meta usage.
|
|
25138
|
+
*/
|
|
25139
|
+
_meta: record(string(), unknown()).optional()
|
|
25140
|
+
});
|
|
25141
|
+
/**
|
|
25142
|
+
* A content block that can be used in prompts and tool results.
|
|
25143
|
+
*/
|
|
25144
|
+
const ContentBlockSchema = union([
|
|
25145
|
+
TextContentSchema,
|
|
25146
|
+
ImageContentSchema,
|
|
25147
|
+
AudioContentSchema,
|
|
25148
|
+
ResourceSchema.extend({ type: literal("resource_link") }),
|
|
25149
|
+
EmbeddedResourceSchema
|
|
25150
|
+
]);
|
|
25151
|
+
/**
|
|
25152
|
+
* Describes a message returned as part of a prompt.
|
|
25153
|
+
*/
|
|
25154
|
+
const PromptMessageSchema = object$1({
|
|
25155
|
+
role: RoleSchema,
|
|
25156
|
+
content: ContentBlockSchema
|
|
25157
|
+
});
|
|
25158
|
+
/**
|
|
25159
|
+
* The server's response to a prompts/get request from the client.
|
|
25160
|
+
*/
|
|
25161
|
+
const GetPromptResultSchema = ResultSchema.extend({
|
|
25162
|
+
/**
|
|
25163
|
+
* An optional description for the prompt.
|
|
25164
|
+
*/
|
|
25165
|
+
description: string().optional(),
|
|
25166
|
+
messages: array(PromptMessageSchema)
|
|
25167
|
+
});
|
|
25168
|
+
/**
|
|
25169
|
+
* 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.
|
|
25170
|
+
*/
|
|
25171
|
+
const PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
25172
|
+
method: literal("notifications/prompts/list_changed"),
|
|
25173
|
+
params: NotificationsParamsSchema.optional()
|
|
25174
|
+
});
|
|
25175
|
+
/**
|
|
25176
|
+
* Additional properties describing a Tool to clients.
|
|
25177
|
+
*
|
|
25178
|
+
* NOTE: all properties in ToolAnnotations are **hints**.
|
|
25179
|
+
* They are not guaranteed to provide a faithful description of
|
|
25180
|
+
* tool behavior (including descriptive properties like `title`).
|
|
25181
|
+
*
|
|
25182
|
+
* Clients should never make tool use decisions based on ToolAnnotations
|
|
25183
|
+
* received from untrusted servers.
|
|
25184
|
+
*/
|
|
25185
|
+
const ToolAnnotationsSchema = object$1({
|
|
25186
|
+
/**
|
|
25187
|
+
* A human-readable title for the tool.
|
|
25188
|
+
*/
|
|
25189
|
+
title: string().optional(),
|
|
25190
|
+
/**
|
|
25191
|
+
* If true, the tool does not modify its environment.
|
|
25192
|
+
*
|
|
25193
|
+
* Default: false
|
|
25194
|
+
*/
|
|
25195
|
+
readOnlyHint: boolean().optional(),
|
|
25196
|
+
/**
|
|
25197
|
+
* If true, the tool may perform destructive updates to its environment.
|
|
25198
|
+
* If false, the tool performs only additive updates.
|
|
25199
|
+
*
|
|
25200
|
+
* (This property is meaningful only when `readOnlyHint == false`)
|
|
25201
|
+
*
|
|
25202
|
+
* Default: true
|
|
25203
|
+
*/
|
|
25204
|
+
destructiveHint: boolean().optional(),
|
|
25205
|
+
/**
|
|
25206
|
+
* If true, calling the tool repeatedly with the same arguments
|
|
25207
|
+
* will have no additional effect on the its environment.
|
|
25208
|
+
*
|
|
25209
|
+
* (This property is meaningful only when `readOnlyHint == false`)
|
|
25210
|
+
*
|
|
25211
|
+
* Default: false
|
|
25212
|
+
*/
|
|
25213
|
+
idempotentHint: boolean().optional(),
|
|
25214
|
+
/**
|
|
25215
|
+
* If true, this tool may interact with an "open world" of external
|
|
25216
|
+
* entities. If false, the tool's domain of interaction is closed.
|
|
25217
|
+
* For example, the world of a web search tool is open, whereas that
|
|
25218
|
+
* of a memory tool is not.
|
|
25219
|
+
*
|
|
25220
|
+
* Default: true
|
|
25221
|
+
*/
|
|
25222
|
+
openWorldHint: boolean().optional()
|
|
25223
|
+
});
|
|
25224
|
+
/**
|
|
25225
|
+
* Execution-related properties for a tool.
|
|
25226
|
+
*/
|
|
25227
|
+
const ToolExecutionSchema = object$1({
|
|
25228
|
+
/**
|
|
25229
|
+
* Indicates the tool's preference for task-augmented execution.
|
|
25230
|
+
* - "required": Clients MUST invoke the tool as a task
|
|
25231
|
+
* - "optional": Clients MAY invoke the tool as a task or normal request
|
|
25232
|
+
* - "forbidden": Clients MUST NOT attempt to invoke the tool as a task
|
|
25233
|
+
*
|
|
25234
|
+
* If not present, defaults to "forbidden".
|
|
25235
|
+
*/
|
|
25236
|
+
taskSupport: _enum([
|
|
25237
|
+
"required",
|
|
25238
|
+
"optional",
|
|
25239
|
+
"forbidden"
|
|
25240
|
+
]).optional() });
|
|
25241
|
+
/**
|
|
25242
|
+
* Definition for a tool the client can call.
|
|
25243
|
+
*/
|
|
25244
|
+
const ToolSchema = object$1({
|
|
25245
|
+
...BaseMetadataSchema.shape,
|
|
25246
|
+
...IconsSchema.shape,
|
|
25247
|
+
/**
|
|
25248
|
+
* A human-readable description of the tool.
|
|
25249
|
+
*/
|
|
25250
|
+
description: string().optional(),
|
|
25251
|
+
/**
|
|
25252
|
+
* A JSON Schema 2020-12 object defining the expected parameters for the tool.
|
|
25253
|
+
* Must have type: 'object' at the root level per MCP spec.
|
|
25254
|
+
*/
|
|
25255
|
+
inputSchema: object$1({
|
|
25256
|
+
type: literal("object"),
|
|
25257
|
+
properties: record(string(), AssertObjectSchema).optional(),
|
|
25258
|
+
required: array(string()).optional()
|
|
25259
|
+
}).catchall(unknown()),
|
|
25260
|
+
/**
|
|
25261
|
+
* An optional JSON Schema 2020-12 object defining the structure of the tool's output
|
|
25262
|
+
* returned in the structuredContent field of a CallToolResult.
|
|
25263
|
+
* Must have type: 'object' at the root level per MCP spec.
|
|
25264
|
+
*/
|
|
25265
|
+
outputSchema: object$1({
|
|
25266
|
+
type: literal("object"),
|
|
25267
|
+
properties: record(string(), AssertObjectSchema).optional(),
|
|
25268
|
+
required: array(string()).optional()
|
|
25269
|
+
}).catchall(unknown()).optional(),
|
|
25270
|
+
/**
|
|
25271
|
+
* Optional additional tool information.
|
|
25272
|
+
*/
|
|
25273
|
+
annotations: ToolAnnotationsSchema.optional(),
|
|
25274
|
+
/**
|
|
25275
|
+
* Execution-related properties for this tool.
|
|
25276
|
+
*/
|
|
25277
|
+
execution: ToolExecutionSchema.optional(),
|
|
25278
|
+
/**
|
|
25279
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25280
|
+
* for notes on _meta usage.
|
|
25281
|
+
*/
|
|
25282
|
+
_meta: record(string(), unknown()).optional()
|
|
25283
|
+
});
|
|
25284
|
+
/**
|
|
25285
|
+
* Sent from the client to request a list of tools the server has.
|
|
25286
|
+
*/
|
|
25287
|
+
const ListToolsRequestSchema = PaginatedRequestSchema.extend({ method: literal("tools/list") });
|
|
25288
|
+
/**
|
|
25289
|
+
* The server's response to a tools/list request from the client.
|
|
25290
|
+
*/
|
|
25291
|
+
const ListToolsResultSchema = PaginatedResultSchema.extend({ tools: array(ToolSchema) });
|
|
25292
|
+
/**
|
|
25293
|
+
* The server's response to a tool call.
|
|
25294
|
+
*/
|
|
25295
|
+
const CallToolResultSchema = ResultSchema.extend({
|
|
25296
|
+
/**
|
|
25297
|
+
* A list of content objects that represent the result of the tool call.
|
|
25298
|
+
*
|
|
25299
|
+
* If the Tool does not define an outputSchema, this field MUST be present in the result.
|
|
25300
|
+
* For backwards compatibility, this field is always present, but it may be empty.
|
|
25301
|
+
*/
|
|
25302
|
+
content: array(ContentBlockSchema).default([]),
|
|
25303
|
+
/**
|
|
25304
|
+
* An object containing structured tool output.
|
|
25305
|
+
*
|
|
25306
|
+
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
|
|
25307
|
+
*/
|
|
25308
|
+
structuredContent: record(string(), unknown()).optional(),
|
|
25309
|
+
/**
|
|
25310
|
+
* Whether the tool call ended in an error.
|
|
25311
|
+
*
|
|
25312
|
+
* If not set, this is assumed to be false (the call was successful).
|
|
25313
|
+
*
|
|
25314
|
+
* Any errors that originate from the tool SHOULD be reported inside the result
|
|
25315
|
+
* object, with `isError` set to true, _not_ as an MCP protocol-level error
|
|
25316
|
+
* response. Otherwise, the LLM would not be able to see that an error occurred
|
|
25317
|
+
* and self-correct.
|
|
25318
|
+
*
|
|
25319
|
+
* However, any errors in _finding_ the tool, an error indicating that the
|
|
25320
|
+
* server does not support tool calls, or any other exceptional conditions,
|
|
25321
|
+
* should be reported as an MCP error response.
|
|
25322
|
+
*/
|
|
25323
|
+
isError: boolean().optional()
|
|
25324
|
+
});
|
|
25325
|
+
CallToolResultSchema.or(ResultSchema.extend({ toolResult: unknown() }));
|
|
25326
|
+
/**
|
|
25327
|
+
* Parameters for a `tools/call` request.
|
|
25328
|
+
*/
|
|
25329
|
+
const CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
25330
|
+
/**
|
|
25331
|
+
* The name of the tool to call.
|
|
25332
|
+
*/
|
|
25333
|
+
name: string(),
|
|
25334
|
+
/**
|
|
25335
|
+
* Arguments to pass to the tool.
|
|
25336
|
+
*/
|
|
25337
|
+
arguments: record(string(), unknown()).optional()
|
|
25338
|
+
});
|
|
25339
|
+
/**
|
|
25340
|
+
* Used by the client to invoke a tool provided by the server.
|
|
25341
|
+
*/
|
|
25342
|
+
const CallToolRequestSchema = RequestSchema.extend({
|
|
25343
|
+
method: literal("tools/call"),
|
|
25344
|
+
params: CallToolRequestParamsSchema
|
|
25345
|
+
});
|
|
25346
|
+
/**
|
|
25347
|
+
* 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.
|
|
25348
|
+
*/
|
|
25349
|
+
const ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
25350
|
+
method: literal("notifications/tools/list_changed"),
|
|
25351
|
+
params: NotificationsParamsSchema.optional()
|
|
25352
|
+
});
|
|
25353
|
+
object$1({
|
|
25354
|
+
/**
|
|
25355
|
+
* If true, the list will be refreshed automatically when a list changed notification is received.
|
|
25356
|
+
* The callback will be called with the updated list.
|
|
25357
|
+
*
|
|
25358
|
+
* If false, the callback will be called with null items, allowing manual refresh.
|
|
25359
|
+
*
|
|
25360
|
+
* @default true
|
|
25361
|
+
*/
|
|
25362
|
+
autoRefresh: boolean().default(true),
|
|
25363
|
+
/**
|
|
25364
|
+
* Debounce time in milliseconds for list changed notification processing.
|
|
25365
|
+
*
|
|
25366
|
+
* Multiple notifications received within this timeframe will only trigger one refresh.
|
|
25367
|
+
* Set to 0 to disable debouncing.
|
|
25368
|
+
*
|
|
25369
|
+
* @default 300
|
|
25370
|
+
*/
|
|
25371
|
+
debounceMs: number().int().nonnegative().default(300)
|
|
25372
|
+
});
|
|
25373
|
+
/**
|
|
25374
|
+
* The severity of a log message.
|
|
25375
|
+
*/
|
|
25376
|
+
const LoggingLevelSchema = _enum([
|
|
25377
|
+
"debug",
|
|
25378
|
+
"info",
|
|
25379
|
+
"notice",
|
|
25380
|
+
"warning",
|
|
25381
|
+
"error",
|
|
25382
|
+
"critical",
|
|
25383
|
+
"alert",
|
|
25384
|
+
"emergency"
|
|
25385
|
+
]);
|
|
25386
|
+
/**
|
|
25387
|
+
* Parameters for a `logging/setLevel` request.
|
|
25388
|
+
*/
|
|
25389
|
+
const SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
25390
|
+
/**
|
|
25391
|
+
* 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.
|
|
25392
|
+
*/
|
|
25393
|
+
level: LoggingLevelSchema });
|
|
25394
|
+
/**
|
|
25395
|
+
* A request from the client to the server, to enable or adjust logging.
|
|
25396
|
+
*/
|
|
25397
|
+
const SetLevelRequestSchema = RequestSchema.extend({
|
|
25398
|
+
method: literal("logging/setLevel"),
|
|
25399
|
+
params: SetLevelRequestParamsSchema
|
|
25400
|
+
});
|
|
25401
|
+
/**
|
|
25402
|
+
* Parameters for a `notifications/message` notification.
|
|
25403
|
+
*/
|
|
25404
|
+
const LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
25405
|
+
/**
|
|
25406
|
+
* The severity of this log message.
|
|
25407
|
+
*/
|
|
25408
|
+
level: LoggingLevelSchema,
|
|
25409
|
+
/**
|
|
25410
|
+
* An optional name of the logger issuing this message.
|
|
25411
|
+
*/
|
|
25412
|
+
logger: string().optional(),
|
|
25413
|
+
/**
|
|
25414
|
+
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
|
|
25415
|
+
*/
|
|
25416
|
+
data: unknown()
|
|
25417
|
+
});
|
|
25418
|
+
/**
|
|
25419
|
+
* 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.
|
|
25420
|
+
*/
|
|
25421
|
+
const LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
25422
|
+
method: literal("notifications/message"),
|
|
25423
|
+
params: LoggingMessageNotificationParamsSchema
|
|
25424
|
+
});
|
|
25425
|
+
/**
|
|
25426
|
+
* The server's preferences for model selection, requested of the client during sampling.
|
|
25427
|
+
*/
|
|
25428
|
+
const ModelPreferencesSchema = object$1({
|
|
25429
|
+
/**
|
|
25430
|
+
* Optional hints to use for model selection.
|
|
25431
|
+
*/
|
|
25432
|
+
hints: array(object$1({
|
|
25433
|
+
/**
|
|
25434
|
+
* A hint for a model name.
|
|
25435
|
+
*/
|
|
25436
|
+
name: string().optional() })).optional(),
|
|
25437
|
+
/**
|
|
25438
|
+
* How much to prioritize cost when selecting a model.
|
|
25439
|
+
*/
|
|
25440
|
+
costPriority: number().min(0).max(1).optional(),
|
|
25441
|
+
/**
|
|
25442
|
+
* How much to prioritize sampling speed (latency) when selecting a model.
|
|
25443
|
+
*/
|
|
25444
|
+
speedPriority: number().min(0).max(1).optional(),
|
|
25445
|
+
/**
|
|
25446
|
+
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
25447
|
+
*/
|
|
25448
|
+
intelligencePriority: number().min(0).max(1).optional()
|
|
25449
|
+
});
|
|
25450
|
+
/**
|
|
25451
|
+
* Controls tool usage behavior in sampling requests.
|
|
25452
|
+
*/
|
|
25453
|
+
const ToolChoiceSchema = object$1({
|
|
25454
|
+
/**
|
|
25455
|
+
* Controls when tools are used:
|
|
25456
|
+
* - "auto": Model decides whether to use tools (default)
|
|
25457
|
+
* - "required": Model MUST use at least one tool before completing
|
|
25458
|
+
* - "none": Model MUST NOT use any tools
|
|
25459
|
+
*/
|
|
25460
|
+
mode: _enum([
|
|
25461
|
+
"auto",
|
|
25462
|
+
"required",
|
|
25463
|
+
"none"
|
|
25464
|
+
]).optional() });
|
|
25465
|
+
/**
|
|
25466
|
+
* The result of a tool execution, provided by the user (server).
|
|
25467
|
+
* Represents the outcome of invoking a tool requested via ToolUseContent.
|
|
25468
|
+
*/
|
|
25469
|
+
const ToolResultContentSchema = object$1({
|
|
25470
|
+
type: literal("tool_result"),
|
|
25471
|
+
toolUseId: string().describe("The unique identifier for the corresponding tool call."),
|
|
25472
|
+
content: array(ContentBlockSchema).default([]),
|
|
25473
|
+
structuredContent: object$1({}).loose().optional(),
|
|
25474
|
+
isError: boolean().optional(),
|
|
25475
|
+
/**
|
|
25476
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25477
|
+
* for notes on _meta usage.
|
|
25478
|
+
*/
|
|
25479
|
+
_meta: record(string(), unknown()).optional()
|
|
25480
|
+
});
|
|
25481
|
+
/**
|
|
25482
|
+
* Basic content types for sampling responses (without tool use).
|
|
25483
|
+
* Used for backwards-compatible CreateMessageResult when tools are not used.
|
|
25484
|
+
*/
|
|
25485
|
+
const SamplingContentSchema = discriminatedUnion("type", [
|
|
25486
|
+
TextContentSchema,
|
|
25487
|
+
ImageContentSchema,
|
|
25488
|
+
AudioContentSchema
|
|
25489
|
+
]);
|
|
25490
|
+
/**
|
|
25491
|
+
* Content block types allowed in sampling messages.
|
|
25492
|
+
* This includes text, image, audio, tool use requests, and tool results.
|
|
25493
|
+
*/
|
|
25494
|
+
const SamplingMessageContentBlockSchema = discriminatedUnion("type", [
|
|
25495
|
+
TextContentSchema,
|
|
25496
|
+
ImageContentSchema,
|
|
25497
|
+
AudioContentSchema,
|
|
25498
|
+
ToolUseContentSchema,
|
|
25499
|
+
ToolResultContentSchema
|
|
25500
|
+
]);
|
|
25501
|
+
/**
|
|
25502
|
+
* Describes a message issued to or received from an LLM API.
|
|
25503
|
+
*/
|
|
25504
|
+
const SamplingMessageSchema = object$1({
|
|
25505
|
+
role: RoleSchema,
|
|
25506
|
+
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)]),
|
|
25507
|
+
/**
|
|
25508
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25509
|
+
* for notes on _meta usage.
|
|
25510
|
+
*/
|
|
25511
|
+
_meta: record(string(), unknown()).optional()
|
|
25512
|
+
});
|
|
25513
|
+
/**
|
|
25514
|
+
* Parameters for a `sampling/createMessage` request.
|
|
25515
|
+
*/
|
|
25516
|
+
const CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
25517
|
+
messages: array(SamplingMessageSchema),
|
|
25518
|
+
/**
|
|
25519
|
+
* The server's preferences for which model to select. The client MAY modify or omit this request.
|
|
25520
|
+
*/
|
|
25521
|
+
modelPreferences: ModelPreferencesSchema.optional(),
|
|
25522
|
+
/**
|
|
25523
|
+
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
|
|
25524
|
+
*/
|
|
25525
|
+
systemPrompt: string().optional(),
|
|
25526
|
+
/**
|
|
25527
|
+
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt.
|
|
25528
|
+
* The client MAY ignore this request.
|
|
25529
|
+
*
|
|
25530
|
+
* Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client
|
|
25531
|
+
* declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
|
|
25532
|
+
*/
|
|
25533
|
+
includeContext: _enum([
|
|
25534
|
+
"none",
|
|
25535
|
+
"thisServer",
|
|
25536
|
+
"allServers"
|
|
25537
|
+
]).optional(),
|
|
25538
|
+
temperature: number().optional(),
|
|
25539
|
+
/**
|
|
25540
|
+
* The requested maximum number of tokens to sample (to prevent runaway completions).
|
|
25541
|
+
*
|
|
25542
|
+
* The client MAY choose to sample fewer tokens than the requested maximum.
|
|
25543
|
+
*/
|
|
25544
|
+
maxTokens: number().int(),
|
|
25545
|
+
stopSequences: array(string()).optional(),
|
|
25546
|
+
/**
|
|
25547
|
+
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
25548
|
+
*/
|
|
25549
|
+
metadata: AssertObjectSchema.optional(),
|
|
25550
|
+
/**
|
|
25551
|
+
* Tools that the model may use during generation.
|
|
25552
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
25553
|
+
*/
|
|
25554
|
+
tools: array(ToolSchema).optional(),
|
|
25555
|
+
/**
|
|
25556
|
+
* Controls how the model uses tools.
|
|
25557
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
25558
|
+
* Default is `{ mode: "auto" }`.
|
|
25559
|
+
*/
|
|
25560
|
+
toolChoice: ToolChoiceSchema.optional()
|
|
25561
|
+
});
|
|
25562
|
+
/**
|
|
25563
|
+
* 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.
|
|
25564
|
+
*/
|
|
25565
|
+
const CreateMessageRequestSchema = RequestSchema.extend({
|
|
25566
|
+
method: literal("sampling/createMessage"),
|
|
25567
|
+
params: CreateMessageRequestParamsSchema
|
|
25568
|
+
});
|
|
25569
|
+
/**
|
|
25570
|
+
* The client's response to a sampling/create_message request from the server.
|
|
25571
|
+
* This is the backwards-compatible version that returns single content (no arrays).
|
|
25572
|
+
* Used when the request does not include tools.
|
|
25573
|
+
*/
|
|
25574
|
+
const CreateMessageResultSchema = ResultSchema.extend({
|
|
25575
|
+
/**
|
|
25576
|
+
* The name of the model that generated the message.
|
|
25577
|
+
*/
|
|
25578
|
+
model: string(),
|
|
25579
|
+
/**
|
|
25580
|
+
* The reason why sampling stopped, if known.
|
|
25581
|
+
*
|
|
25582
|
+
* Standard values:
|
|
25583
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
25584
|
+
* - "stopSequence": A stop sequence was encountered
|
|
25585
|
+
* - "maxTokens": Maximum token limit was reached
|
|
25586
|
+
*
|
|
25587
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
25588
|
+
*/
|
|
25589
|
+
stopReason: optional(_enum([
|
|
25590
|
+
"endTurn",
|
|
25591
|
+
"stopSequence",
|
|
25592
|
+
"maxTokens"
|
|
25593
|
+
]).or(string())),
|
|
25594
|
+
role: RoleSchema,
|
|
25595
|
+
/**
|
|
25596
|
+
* Response content. Single content block (text, image, or audio).
|
|
25597
|
+
*/
|
|
25598
|
+
content: SamplingContentSchema
|
|
25599
|
+
});
|
|
25600
|
+
/**
|
|
25601
|
+
* The client's response to a sampling/create_message request when tools were provided.
|
|
25602
|
+
* This version supports array content for tool use flows.
|
|
25603
|
+
*/
|
|
25604
|
+
const CreateMessageResultWithToolsSchema = ResultSchema.extend({
|
|
25605
|
+
/**
|
|
25606
|
+
* The name of the model that generated the message.
|
|
25607
|
+
*/
|
|
25608
|
+
model: string(),
|
|
25609
|
+
/**
|
|
25610
|
+
* The reason why sampling stopped, if known.
|
|
25611
|
+
*
|
|
25612
|
+
* Standard values:
|
|
25613
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
25614
|
+
* - "stopSequence": A stop sequence was encountered
|
|
25615
|
+
* - "maxTokens": Maximum token limit was reached
|
|
25616
|
+
* - "toolUse": The model wants to use one or more tools
|
|
25617
|
+
*
|
|
25618
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
25619
|
+
*/
|
|
25620
|
+
stopReason: optional(_enum([
|
|
25621
|
+
"endTurn",
|
|
25622
|
+
"stopSequence",
|
|
25623
|
+
"maxTokens",
|
|
25624
|
+
"toolUse"
|
|
25625
|
+
]).or(string())),
|
|
25626
|
+
role: RoleSchema,
|
|
25627
|
+
/**
|
|
25628
|
+
* Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
|
|
25629
|
+
*/
|
|
25630
|
+
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)])
|
|
25631
|
+
});
|
|
25632
|
+
/**
|
|
25633
|
+
* Primitive schema definition for boolean fields.
|
|
25634
|
+
*/
|
|
25635
|
+
const BooleanSchemaSchema = object$1({
|
|
25636
|
+
type: literal("boolean"),
|
|
25637
|
+
title: string().optional(),
|
|
25638
|
+
description: string().optional(),
|
|
25639
|
+
default: boolean().optional()
|
|
25640
|
+
});
|
|
25641
|
+
/**
|
|
25642
|
+
* Primitive schema definition for string fields.
|
|
25643
|
+
*/
|
|
25644
|
+
const StringSchemaSchema = object$1({
|
|
25645
|
+
type: literal("string"),
|
|
25646
|
+
title: string().optional(),
|
|
25647
|
+
description: string().optional(),
|
|
25648
|
+
minLength: number().optional(),
|
|
25649
|
+
maxLength: number().optional(),
|
|
25650
|
+
format: _enum([
|
|
25651
|
+
"email",
|
|
25652
|
+
"uri",
|
|
25653
|
+
"date",
|
|
25654
|
+
"date-time"
|
|
25655
|
+
]).optional(),
|
|
25656
|
+
default: string().optional()
|
|
25657
|
+
});
|
|
25658
|
+
/**
|
|
25659
|
+
* Primitive schema definition for number fields.
|
|
25660
|
+
*/
|
|
25661
|
+
const NumberSchemaSchema = object$1({
|
|
25662
|
+
type: _enum(["number", "integer"]),
|
|
25663
|
+
title: string().optional(),
|
|
25664
|
+
description: string().optional(),
|
|
25665
|
+
minimum: number().optional(),
|
|
25666
|
+
maximum: number().optional(),
|
|
25667
|
+
default: number().optional()
|
|
25668
|
+
});
|
|
25669
|
+
/**
|
|
25670
|
+
* Schema for single-selection enumeration without display titles for options.
|
|
25671
|
+
*/
|
|
25672
|
+
const UntitledSingleSelectEnumSchemaSchema = object$1({
|
|
25673
|
+
type: literal("string"),
|
|
25674
|
+
title: string().optional(),
|
|
25675
|
+
description: string().optional(),
|
|
25676
|
+
enum: array(string()),
|
|
25677
|
+
default: string().optional()
|
|
25678
|
+
});
|
|
25679
|
+
/**
|
|
25680
|
+
* Schema for single-selection enumeration with display titles for each option.
|
|
25681
|
+
*/
|
|
25682
|
+
const TitledSingleSelectEnumSchemaSchema = object$1({
|
|
25683
|
+
type: literal("string"),
|
|
25684
|
+
title: string().optional(),
|
|
25685
|
+
description: string().optional(),
|
|
25686
|
+
oneOf: array(object$1({
|
|
25687
|
+
const: string(),
|
|
25688
|
+
title: string()
|
|
25689
|
+
})),
|
|
25690
|
+
default: string().optional()
|
|
25691
|
+
});
|
|
25692
|
+
/**
|
|
25693
|
+
* Union of all primitive schema definitions.
|
|
25694
|
+
*/
|
|
25695
|
+
const PrimitiveSchemaDefinitionSchema = union([
|
|
25696
|
+
union([
|
|
25697
|
+
object$1({
|
|
25698
|
+
type: literal("string"),
|
|
25699
|
+
title: string().optional(),
|
|
25700
|
+
description: string().optional(),
|
|
25701
|
+
enum: array(string()),
|
|
25702
|
+
enumNames: array(string()).optional(),
|
|
25703
|
+
default: string().optional()
|
|
25704
|
+
}),
|
|
25705
|
+
union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]),
|
|
25706
|
+
union([object$1({
|
|
25707
|
+
type: literal("array"),
|
|
25708
|
+
title: string().optional(),
|
|
25709
|
+
description: string().optional(),
|
|
25710
|
+
minItems: number().optional(),
|
|
25711
|
+
maxItems: number().optional(),
|
|
25712
|
+
items: object$1({
|
|
25713
|
+
type: literal("string"),
|
|
25714
|
+
enum: array(string())
|
|
25715
|
+
}),
|
|
25716
|
+
default: array(string()).optional()
|
|
25717
|
+
}), object$1({
|
|
25718
|
+
type: literal("array"),
|
|
25719
|
+
title: string().optional(),
|
|
25720
|
+
description: string().optional(),
|
|
25721
|
+
minItems: number().optional(),
|
|
25722
|
+
maxItems: number().optional(),
|
|
25723
|
+
items: object$1({ anyOf: array(object$1({
|
|
25724
|
+
const: string(),
|
|
25725
|
+
title: string()
|
|
25726
|
+
})) }),
|
|
25727
|
+
default: array(string()).optional()
|
|
25728
|
+
})])
|
|
25729
|
+
]),
|
|
25730
|
+
BooleanSchemaSchema,
|
|
25731
|
+
StringSchemaSchema,
|
|
25732
|
+
NumberSchemaSchema
|
|
25733
|
+
]);
|
|
25734
|
+
/**
|
|
25735
|
+
* The parameters for a request to elicit additional information from the user via the client.
|
|
25736
|
+
*/
|
|
25737
|
+
const ElicitRequestParamsSchema = union([TaskAugmentedRequestParamsSchema.extend({
|
|
25738
|
+
/**
|
|
25739
|
+
* The elicitation mode.
|
|
25740
|
+
*
|
|
25741
|
+
* Optional for backward compatibility. Clients MUST treat missing mode as "form".
|
|
25742
|
+
*/
|
|
25743
|
+
mode: literal("form").optional(),
|
|
25744
|
+
/**
|
|
25745
|
+
* The message to present to the user describing what information is being requested.
|
|
25746
|
+
*/
|
|
25747
|
+
message: string(),
|
|
25748
|
+
/**
|
|
25749
|
+
* A restricted subset of JSON Schema.
|
|
25750
|
+
* Only top-level properties are allowed, without nesting.
|
|
25751
|
+
*/
|
|
25752
|
+
requestedSchema: object$1({
|
|
25753
|
+
type: literal("object"),
|
|
25754
|
+
properties: record(string(), PrimitiveSchemaDefinitionSchema),
|
|
25755
|
+
required: array(string()).optional()
|
|
25756
|
+
})
|
|
25757
|
+
}), TaskAugmentedRequestParamsSchema.extend({
|
|
25758
|
+
/**
|
|
25759
|
+
* The elicitation mode.
|
|
25760
|
+
*/
|
|
25761
|
+
mode: literal("url"),
|
|
25762
|
+
/**
|
|
25763
|
+
* The message to present to the user explaining why the interaction is needed.
|
|
25764
|
+
*/
|
|
25765
|
+
message: string(),
|
|
25766
|
+
/**
|
|
25767
|
+
* The ID of the elicitation, which must be unique within the context of the server.
|
|
25768
|
+
* The client MUST treat this ID as an opaque value.
|
|
25769
|
+
*/
|
|
25770
|
+
elicitationId: string(),
|
|
25771
|
+
/**
|
|
25772
|
+
* The URL that the user should navigate to.
|
|
25773
|
+
*/
|
|
25774
|
+
url: string().url()
|
|
25775
|
+
})]);
|
|
25776
|
+
/**
|
|
25777
|
+
* A request from the server to elicit user input via the client.
|
|
25778
|
+
* The client should present the message and form fields to the user (form mode)
|
|
25779
|
+
* or navigate to a URL (URL mode).
|
|
25780
|
+
*/
|
|
25781
|
+
const ElicitRequestSchema = RequestSchema.extend({
|
|
25782
|
+
method: literal("elicitation/create"),
|
|
25783
|
+
params: ElicitRequestParamsSchema
|
|
25784
|
+
});
|
|
25785
|
+
/**
|
|
25786
|
+
* Parameters for a `notifications/elicitation/complete` notification.
|
|
25787
|
+
*
|
|
25788
|
+
* @category notifications/elicitation/complete
|
|
25789
|
+
*/
|
|
25790
|
+
const ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
25791
|
+
/**
|
|
25792
|
+
* The ID of the elicitation that completed.
|
|
25793
|
+
*/
|
|
25794
|
+
elicitationId: string() });
|
|
25795
|
+
/**
|
|
25796
|
+
* A notification from the server to the client, informing it of a completion of an out-of-band elicitation request.
|
|
25797
|
+
*
|
|
25798
|
+
* @category notifications/elicitation/complete
|
|
25799
|
+
*/
|
|
25800
|
+
const ElicitationCompleteNotificationSchema = NotificationSchema.extend({
|
|
25801
|
+
method: literal("notifications/elicitation/complete"),
|
|
25802
|
+
params: ElicitationCompleteNotificationParamsSchema
|
|
25803
|
+
});
|
|
25804
|
+
/**
|
|
25805
|
+
* The client's response to an elicitation/create request from the server.
|
|
25806
|
+
*/
|
|
25807
|
+
const ElicitResultSchema = ResultSchema.extend({
|
|
25808
|
+
/**
|
|
25809
|
+
* The user action in response to the elicitation.
|
|
25810
|
+
* - "accept": User submitted the form/confirmed the action
|
|
25811
|
+
* - "decline": User explicitly decline the action
|
|
25812
|
+
* - "cancel": User dismissed without making an explicit choice
|
|
25813
|
+
*/
|
|
25814
|
+
action: _enum([
|
|
25815
|
+
"accept",
|
|
25816
|
+
"decline",
|
|
25817
|
+
"cancel"
|
|
25818
|
+
]),
|
|
25819
|
+
/**
|
|
25820
|
+
* The submitted form data, only present when action is "accept".
|
|
25821
|
+
* Contains values matching the requested schema.
|
|
25822
|
+
* Per MCP spec, content is "typically omitted" for decline/cancel actions.
|
|
25823
|
+
* We normalize null to undefined for leniency while maintaining type compatibility.
|
|
25824
|
+
*/
|
|
25825
|
+
content: preprocess((val) => val === null ? void 0 : val, record(string(), union([
|
|
25826
|
+
string(),
|
|
25827
|
+
number(),
|
|
25828
|
+
boolean(),
|
|
25829
|
+
array(string())
|
|
25830
|
+
])).optional())
|
|
25831
|
+
});
|
|
25832
|
+
/**
|
|
25833
|
+
* A reference to a resource or resource template definition.
|
|
25834
|
+
*/
|
|
25835
|
+
const ResourceTemplateReferenceSchema = object$1({
|
|
25836
|
+
type: literal("ref/resource"),
|
|
25837
|
+
/**
|
|
25838
|
+
* The URI or URI template of the resource.
|
|
25839
|
+
*/
|
|
25840
|
+
uri: string()
|
|
25841
|
+
});
|
|
25842
|
+
/**
|
|
25843
|
+
* Identifies a prompt.
|
|
25844
|
+
*/
|
|
25845
|
+
const PromptReferenceSchema = object$1({
|
|
25846
|
+
type: literal("ref/prompt"),
|
|
25847
|
+
/**
|
|
25848
|
+
* The name of the prompt or prompt template
|
|
25849
|
+
*/
|
|
25850
|
+
name: string()
|
|
25851
|
+
});
|
|
25852
|
+
/**
|
|
25853
|
+
* Parameters for a `completion/complete` request.
|
|
25854
|
+
*/
|
|
25855
|
+
const CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
25856
|
+
ref: union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
|
|
25857
|
+
/**
|
|
25858
|
+
* The argument's information
|
|
25859
|
+
*/
|
|
25860
|
+
argument: object$1({
|
|
25861
|
+
/**
|
|
25862
|
+
* The name of the argument
|
|
25863
|
+
*/
|
|
25864
|
+
name: string(),
|
|
25865
|
+
/**
|
|
25866
|
+
* The value of the argument to use for completion matching.
|
|
25867
|
+
*/
|
|
25868
|
+
value: string()
|
|
25869
|
+
}),
|
|
25870
|
+
context: object$1({
|
|
25871
|
+
/**
|
|
25872
|
+
* Previously-resolved variables in a URI template or prompt.
|
|
25873
|
+
*/
|
|
25874
|
+
arguments: record(string(), string()).optional() }).optional()
|
|
25875
|
+
});
|
|
25876
|
+
/**
|
|
25877
|
+
* A request from the client to the server, to ask for completion options.
|
|
25878
|
+
*/
|
|
25879
|
+
const CompleteRequestSchema = RequestSchema.extend({
|
|
25880
|
+
method: literal("completion/complete"),
|
|
25881
|
+
params: CompleteRequestParamsSchema
|
|
25882
|
+
});
|
|
25883
|
+
/**
|
|
25884
|
+
* The server's response to a completion/complete request
|
|
25885
|
+
*/
|
|
25886
|
+
const CompleteResultSchema = ResultSchema.extend({ completion: looseObject({
|
|
25887
|
+
/**
|
|
25888
|
+
* An array of completion values. Must not exceed 100 items.
|
|
25889
|
+
*/
|
|
25890
|
+
values: array(string()).max(100),
|
|
25891
|
+
/**
|
|
25892
|
+
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
25893
|
+
*/
|
|
25894
|
+
total: optional(number().int()),
|
|
25895
|
+
/**
|
|
25896
|
+
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
25897
|
+
*/
|
|
25898
|
+
hasMore: optional(boolean())
|
|
25899
|
+
}) });
|
|
25900
|
+
/**
|
|
25901
|
+
* Represents a root directory or file that the server can operate on.
|
|
25902
|
+
*/
|
|
25903
|
+
const RootSchema = object$1({
|
|
25904
|
+
/**
|
|
25905
|
+
* The URI identifying the root. This *must* start with file:// for now.
|
|
25906
|
+
*/
|
|
25907
|
+
uri: string().startsWith("file://"),
|
|
25908
|
+
/**
|
|
25909
|
+
* An optional name for the root.
|
|
25910
|
+
*/
|
|
25911
|
+
name: string().optional(),
|
|
25912
|
+
/**
|
|
25913
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25914
|
+
* for notes on _meta usage.
|
|
25915
|
+
*/
|
|
25916
|
+
_meta: record(string(), unknown()).optional()
|
|
25917
|
+
});
|
|
25918
|
+
/**
|
|
25919
|
+
* Sent from the server to request a list of root URIs from the client.
|
|
25920
|
+
*/
|
|
25921
|
+
const ListRootsRequestSchema = RequestSchema.extend({
|
|
25922
|
+
method: literal("roots/list"),
|
|
25923
|
+
params: BaseRequestParamsSchema.optional()
|
|
25924
|
+
});
|
|
25925
|
+
/**
|
|
25926
|
+
* The client's response to a roots/list request from the server.
|
|
25927
|
+
*/
|
|
25928
|
+
const ListRootsResultSchema = ResultSchema.extend({ roots: array(RootSchema) });
|
|
25929
|
+
/**
|
|
25930
|
+
* A notification from the client to the server, informing it that the list of roots has changed.
|
|
25931
|
+
*/
|
|
25932
|
+
const RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
25933
|
+
method: literal("notifications/roots/list_changed"),
|
|
25934
|
+
params: NotificationsParamsSchema.optional()
|
|
25935
|
+
});
|
|
25936
|
+
union([
|
|
25937
|
+
PingRequestSchema,
|
|
25938
|
+
InitializeRequestSchema,
|
|
25939
|
+
CompleteRequestSchema,
|
|
25940
|
+
SetLevelRequestSchema,
|
|
25941
|
+
GetPromptRequestSchema,
|
|
25942
|
+
ListPromptsRequestSchema,
|
|
25943
|
+
ListResourcesRequestSchema,
|
|
25944
|
+
ListResourceTemplatesRequestSchema,
|
|
25945
|
+
ReadResourceRequestSchema,
|
|
25946
|
+
SubscribeRequestSchema,
|
|
25947
|
+
UnsubscribeRequestSchema,
|
|
25948
|
+
CallToolRequestSchema,
|
|
25949
|
+
ListToolsRequestSchema,
|
|
25950
|
+
GetTaskRequestSchema,
|
|
25951
|
+
GetTaskPayloadRequestSchema,
|
|
25952
|
+
ListTasksRequestSchema,
|
|
25953
|
+
CancelTaskRequestSchema
|
|
25954
|
+
]);
|
|
25955
|
+
union([
|
|
25956
|
+
CancelledNotificationSchema,
|
|
25957
|
+
ProgressNotificationSchema,
|
|
25958
|
+
InitializedNotificationSchema,
|
|
25959
|
+
RootsListChangedNotificationSchema,
|
|
25960
|
+
TaskStatusNotificationSchema
|
|
25961
|
+
]);
|
|
25962
|
+
union([
|
|
25963
|
+
EmptyResultSchema,
|
|
25964
|
+
CreateMessageResultSchema,
|
|
25965
|
+
CreateMessageResultWithToolsSchema,
|
|
25966
|
+
ElicitResultSchema,
|
|
25967
|
+
ListRootsResultSchema,
|
|
25968
|
+
GetTaskResultSchema,
|
|
25969
|
+
ListTasksResultSchema,
|
|
25970
|
+
CreateTaskResultSchema
|
|
25971
|
+
]);
|
|
25972
|
+
union([
|
|
25973
|
+
PingRequestSchema,
|
|
25974
|
+
CreateMessageRequestSchema,
|
|
25975
|
+
ElicitRequestSchema,
|
|
25976
|
+
ListRootsRequestSchema,
|
|
25977
|
+
GetTaskRequestSchema,
|
|
25978
|
+
GetTaskPayloadRequestSchema,
|
|
25979
|
+
ListTasksRequestSchema,
|
|
25980
|
+
CancelTaskRequestSchema
|
|
25981
|
+
]);
|
|
25982
|
+
union([
|
|
25983
|
+
CancelledNotificationSchema,
|
|
25984
|
+
ProgressNotificationSchema,
|
|
25985
|
+
LoggingMessageNotificationSchema,
|
|
25986
|
+
ResourceUpdatedNotificationSchema,
|
|
25987
|
+
ResourceListChangedNotificationSchema,
|
|
25988
|
+
ToolListChangedNotificationSchema,
|
|
25989
|
+
PromptListChangedNotificationSchema,
|
|
25990
|
+
TaskStatusNotificationSchema,
|
|
25991
|
+
ElicitationCompleteNotificationSchema
|
|
25992
|
+
]);
|
|
25993
|
+
union([
|
|
25994
|
+
EmptyResultSchema,
|
|
25995
|
+
InitializeResultSchema,
|
|
25996
|
+
CompleteResultSchema,
|
|
25997
|
+
GetPromptResultSchema,
|
|
25998
|
+
ListPromptsResultSchema,
|
|
25999
|
+
ListResourcesResultSchema,
|
|
26000
|
+
ListResourceTemplatesResultSchema,
|
|
26001
|
+
ReadResourceResultSchema,
|
|
26002
|
+
CallToolResultSchema,
|
|
26003
|
+
ListToolsResultSchema,
|
|
26004
|
+
GetTaskResultSchema,
|
|
26005
|
+
ListTasksResultSchema,
|
|
26006
|
+
CreateTaskResultSchema
|
|
26007
|
+
]);
|
|
26008
|
+
//#endregion
|
|
26009
|
+
//#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
|
|
26010
|
+
const MAXIMUM_MESSAGE_SIZE = 4 * 1024 * 1024;
|
|
26011
|
+
var SSETransport = class {
|
|
26012
|
+
messageUrl;
|
|
26013
|
+
stream;
|
|
26014
|
+
_sessionId;
|
|
26015
|
+
onclose;
|
|
26016
|
+
onerror;
|
|
26017
|
+
onmessage;
|
|
26018
|
+
/**
|
|
26019
|
+
* Creates a new SSETransport, which will direct the MPC client to POST messages to messageUrl
|
|
26020
|
+
*/
|
|
26021
|
+
constructor(messageUrl, stream) {
|
|
26022
|
+
this.messageUrl = messageUrl;
|
|
26023
|
+
this.stream = stream;
|
|
26024
|
+
this._sessionId = crypto.randomUUID();
|
|
26025
|
+
this.stream.onAbort(() => {
|
|
26026
|
+
this.close();
|
|
26027
|
+
});
|
|
26028
|
+
}
|
|
26029
|
+
get sessionId() {
|
|
26030
|
+
return this._sessionId;
|
|
26031
|
+
}
|
|
26032
|
+
async start() {
|
|
26033
|
+
if (this.stream == null) throw new Error("Stream not initialized");
|
|
26034
|
+
if (this.stream.closed) throw new Error("SSE transport already closed!");
|
|
26035
|
+
await this.stream.writeSSE({
|
|
26036
|
+
event: "ping",
|
|
26037
|
+
data: ""
|
|
26038
|
+
});
|
|
26039
|
+
await this.stream.writeSSE({
|
|
26040
|
+
event: "endpoint",
|
|
26041
|
+
data: `${this.messageUrl}?sessionId=${this.sessionId}`
|
|
26042
|
+
});
|
|
26043
|
+
}
|
|
26044
|
+
async handlePostMessage(context) {
|
|
26045
|
+
if (this.stream?.closed == null) return context.text("SSE connection not established", 500);
|
|
26046
|
+
try {
|
|
26047
|
+
const contentType = context.req.header("content-type") || "";
|
|
26048
|
+
if (!contentType.includes("application/json")) throw new Error(`Unsupported content-type: ${contentType}`);
|
|
26049
|
+
const contentLength = Number.parseInt(context.req.header("content-length") || "0", 10);
|
|
26050
|
+
if (contentLength > MAXIMUM_MESSAGE_SIZE) throw new Error(`Request body too large: ${contentLength} bytes`);
|
|
26051
|
+
const body = await context.req.json();
|
|
26052
|
+
await this.handleMessage(body);
|
|
26053
|
+
return context.text("Accepted", 202);
|
|
26054
|
+
} catch (error) {
|
|
26055
|
+
this.onerror?.(error);
|
|
26056
|
+
return context.text("Error", 400);
|
|
26057
|
+
}
|
|
26058
|
+
}
|
|
26059
|
+
/**
|
|
26060
|
+
* 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.
|
|
26061
|
+
*/
|
|
26062
|
+
async handleMessage(message) {
|
|
26063
|
+
let parsedMessage;
|
|
26064
|
+
try {
|
|
26065
|
+
parsedMessage = JSONRPCMessageSchema.parse(message);
|
|
26066
|
+
} catch (error) {
|
|
26067
|
+
this.onerror?.(error);
|
|
26068
|
+
throw error;
|
|
26069
|
+
}
|
|
26070
|
+
this.onmessage?.(parsedMessage);
|
|
26071
|
+
}
|
|
26072
|
+
async close() {
|
|
26073
|
+
if (this.stream?.closed) this.stream.abort();
|
|
26074
|
+
}
|
|
26075
|
+
async send(message) {
|
|
26076
|
+
if (this.stream?.closed) throw new Error("Not connected");
|
|
26077
|
+
await this.stream.writeSSE({
|
|
26078
|
+
event: "message",
|
|
26079
|
+
data: JSON.stringify(message)
|
|
26080
|
+
});
|
|
26081
|
+
}
|
|
26082
|
+
};
|
|
26083
|
+
//#endregion
|
|
26084
|
+
//#region src/server/notificationBroadcast.ts
|
|
26085
|
+
/**
|
|
26086
|
+
* Sends a notification to every active server instance (the main stdio/SSE
|
|
26087
|
+
* instance plus each streamable HTTP session instance).
|
|
26088
|
+
*
|
|
26089
|
+
* Failures are aggregated: if only some instances fail, the failure is logged
|
|
26090
|
+
* and the broadcast is considered best-effort. A `MastraError` is thrown only
|
|
26091
|
+
* when every send fails.
|
|
26092
|
+
*
|
|
26093
|
+
* Note: clients connected in stateless/serverless mode cannot receive
|
|
26094
|
+
* notifications because each request uses a transient server instance.
|
|
26095
|
+
*
|
|
26096
|
+
* @internal
|
|
26097
|
+
*/
|
|
26098
|
+
async function broadcastNotification({ servers, send, logger, errorId, errorText, errorDetails }) {
|
|
26099
|
+
const errors = [];
|
|
26100
|
+
for (const server of servers) try {
|
|
26101
|
+
await send(server);
|
|
26102
|
+
} catch (error) {
|
|
26103
|
+
errors.push(error);
|
|
26104
|
+
}
|
|
26105
|
+
if (errors.length === 0) return;
|
|
26106
|
+
const mastraError = new _mastra_core_error.MastraError({
|
|
26107
|
+
id: errorId,
|
|
26108
|
+
domain: _mastra_core_error.ErrorDomain.MCP,
|
|
26109
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
26110
|
+
text: errorText,
|
|
26111
|
+
details: {
|
|
26112
|
+
...errorDetails,
|
|
26113
|
+
failedInstances: errors.length,
|
|
26114
|
+
totalInstances: servers.length
|
|
26115
|
+
}
|
|
26116
|
+
}, errors[0]);
|
|
26117
|
+
logger.error(`${errorText}:`, { error: mastraError.toString() });
|
|
26118
|
+
if (errors.length === servers.length) {
|
|
26119
|
+
logger.trackException(mastraError);
|
|
26120
|
+
throw mastraError;
|
|
26121
|
+
}
|
|
26122
|
+
}
|
|
26123
|
+
//#endregion
|
|
26124
|
+
//#region src/server/promptActions.ts
|
|
26125
|
+
/**
|
|
26126
|
+
* Server-side prompt actions for notifying clients about prompt changes.
|
|
26127
|
+
*
|
|
26128
|
+
* This class provides methods for MCP servers to notify connected clients when
|
|
26129
|
+
* the list of available prompts changes.
|
|
26130
|
+
*
|
|
26131
|
+
* Notifications are broadcast to every active server instance (the main
|
|
26132
|
+
* stdio/SSE instance plus each streamable HTTP session). Clients connected in
|
|
26133
|
+
* stateless/serverless mode cannot receive notifications because each request
|
|
26134
|
+
* uses a transient server instance.
|
|
26135
|
+
*/
|
|
26136
|
+
var ServerPromptActions = class {
|
|
26137
|
+
getLogger;
|
|
26138
|
+
getSdkServers;
|
|
26139
|
+
clearDefinedPrompts;
|
|
26140
|
+
/**
|
|
26141
|
+
* @internal
|
|
26142
|
+
*/
|
|
26143
|
+
constructor(dependencies) {
|
|
26144
|
+
this.getLogger = dependencies.getLogger;
|
|
23943
26145
|
this.getSdkServers = dependencies.getSdkServers;
|
|
23944
26146
|
this.clearDefinedPrompts = dependencies.clearDefinedPrompts;
|
|
23945
26147
|
}
|
|
@@ -24146,6 +26348,25 @@ var ServerToolActions = class {
|
|
|
24146
26348
|
};
|
|
24147
26349
|
//#endregion
|
|
24148
26350
|
//#region src/server/server.ts
|
|
26351
|
+
/**
|
|
26352
|
+
* Flattens the MCP `ServerContext` into the shape Mastra tools receive as `extra`.
|
|
26353
|
+
*
|
|
26354
|
+
* MCP 2.0 nests per-request plumbing under `ctx.mcpReq` and transport details under
|
|
26355
|
+
* `ctx.http`, while Mastra tools have always read `signal`, `requestId`, `authInfo`,
|
|
26356
|
+
* `sendNotification`, `sendRequest`, and `_meta` off the top level. Both the nested and
|
|
26357
|
+
* flattened members are kept so tools written against either shape keep working.
|
|
26358
|
+
*/
|
|
26359
|
+
const toMCPRequestHandlerExtra = (ctx) => {
|
|
26360
|
+
return {
|
|
26361
|
+
...ctx,
|
|
26362
|
+
signal: ctx.mcpReq.signal,
|
|
26363
|
+
requestId: ctx.mcpReq.id,
|
|
26364
|
+
authInfo: ctx.http?.authInfo,
|
|
26365
|
+
sendNotification: ctx.mcpReq.notify,
|
|
26366
|
+
sendRequest: ctx.mcpReq.send,
|
|
26367
|
+
_meta: ctx.mcpReq._meta
|
|
26368
|
+
};
|
|
26369
|
+
};
|
|
24149
26370
|
const LOG_LEVEL_SEVERITY = {
|
|
24150
26371
|
debug: 0,
|
|
24151
26372
|
info: 1,
|
|
@@ -24292,11 +26513,11 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24292
26513
|
return this.sseHonoTransports.get(sessionId);
|
|
24293
26514
|
}
|
|
24294
26515
|
/**
|
|
24295
|
-
* Gets the underlying MCP
|
|
26516
|
+
* Gets the underlying MCP Server instance.
|
|
24296
26517
|
*
|
|
24297
26518
|
* This provides access to the low-level server instance for advanced use cases.
|
|
24298
26519
|
*
|
|
24299
|
-
* @returns The Server instance from @modelcontextprotocol/
|
|
26520
|
+
* @returns The Server instance from @modelcontextprotocol/server
|
|
24300
26521
|
*/
|
|
24301
26522
|
getServer() {
|
|
24302
26523
|
return this.server;
|
|
@@ -24370,7 +26591,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24370
26591
|
...capabilities.extensions,
|
|
24371
26592
|
"io.modelcontextprotocol/ui": {}
|
|
24372
26593
|
};
|
|
24373
|
-
this.server = new
|
|
26594
|
+
this.server = new _modelcontextprotocol_server.Server({
|
|
24374
26595
|
name: this.name,
|
|
24375
26596
|
version: this.version
|
|
24376
26597
|
}, {
|
|
@@ -24650,7 +26871,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24650
26871
|
...capabilities.extensions,
|
|
24651
26872
|
"io.modelcontextprotocol/ui": {}
|
|
24652
26873
|
};
|
|
24653
|
-
const serverInstance = new
|
|
26874
|
+
const serverInstance = new _modelcontextprotocol_server.Server({
|
|
24654
26875
|
name: this.name,
|
|
24655
26876
|
version: this.version
|
|
24656
26877
|
}, {
|
|
@@ -24666,8 +26887,8 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24666
26887
|
* This allows us to create multiple server instances with identical functionality.
|
|
24667
26888
|
*/
|
|
24668
26889
|
registerHandlersOnServer(serverInstance) {
|
|
24669
|
-
serverInstance.setRequestHandler(
|
|
24670
|
-
const proxiedContext = await this.createProxiedRequestContext(
|
|
26890
|
+
serverInstance.setRequestHandler("tools/list", async (_request, ctx) => {
|
|
26891
|
+
const proxiedContext = await this.createProxiedRequestContext(toMCPRequestHandlerExtra(ctx));
|
|
24671
26892
|
return { tools: (await this.getAuthorizedConvertedToolEntries(proxiedContext)).map(([, tool]) => {
|
|
24672
26893
|
const toolSpec = {
|
|
24673
26894
|
name: tool.id || "unknown",
|
|
@@ -24696,8 +26917,9 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24696
26917
|
return toolSpec;
|
|
24697
26918
|
}) };
|
|
24698
26919
|
});
|
|
24699
|
-
serverInstance.setRequestHandler(
|
|
26920
|
+
serverInstance.setRequestHandler("tools/call", async (request, ctx) => {
|
|
24700
26921
|
const startTime = Date.now();
|
|
26922
|
+
const extra = toMCPRequestHandlerExtra(ctx);
|
|
24701
26923
|
try {
|
|
24702
26924
|
const tool = this.convertedTools[request.params.name];
|
|
24703
26925
|
if (!tool) {
|
|
@@ -24819,11 +27041,13 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24819
27041
|
}
|
|
24820
27042
|
response.structuredContent = structuredContent;
|
|
24821
27043
|
}
|
|
24822
|
-
if (response.structuredContent
|
|
24823
|
-
|
|
24824
|
-
|
|
24825
|
-
|
|
24826
|
-
|
|
27044
|
+
if (response.structuredContent !== void 0) {
|
|
27045
|
+
const authorContent = result && typeof result === "object" && "content" in result && Array.isArray(result.content) ? result.content : void 0;
|
|
27046
|
+
response.content = authorContent && authorContent.length > 0 ? authorContent : [{
|
|
27047
|
+
type: "text",
|
|
27048
|
+
text: JSON.stringify(response.structuredContent)
|
|
27049
|
+
}];
|
|
27050
|
+
} else response.content = [{
|
|
24827
27051
|
type: "text",
|
|
24828
27052
|
text: typeof result === "string" ? result : JSON.stringify(result)
|
|
24829
27053
|
}];
|
|
@@ -24865,7 +27089,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24865
27089
|
};
|
|
24866
27090
|
}
|
|
24867
27091
|
});
|
|
24868
|
-
serverInstance.setRequestHandler(
|
|
27092
|
+
serverInstance.setRequestHandler("logging/setLevel", async (request) => {
|
|
24869
27093
|
this.loggingLevels.set(serverInstance, request.params.level);
|
|
24870
27094
|
this.logger.debug("Logging level set", { level: request.params.level });
|
|
24871
27095
|
return {};
|
|
@@ -24879,9 +27103,9 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24879
27103
|
registerResourceHandlersOnServer(serverInstance) {
|
|
24880
27104
|
const capturedResourceOptions = this.resourceOptions;
|
|
24881
27105
|
if (!capturedResourceOptions) return;
|
|
24882
|
-
if (capturedResourceOptions.listResources) serverInstance.setRequestHandler(
|
|
27106
|
+
if (capturedResourceOptions.listResources) serverInstance.setRequestHandler("resources/list", async (_request, ctx) => {
|
|
24883
27107
|
try {
|
|
24884
|
-
const resources = await capturedResourceOptions.listResources({ extra });
|
|
27108
|
+
const resources = await capturedResourceOptions.listResources({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24885
27109
|
this.logger.debug("Fetched resources", { count: resources.length });
|
|
24886
27110
|
return { resources };
|
|
24887
27111
|
} catch (error) {
|
|
@@ -24889,21 +27113,21 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24889
27113
|
throw error;
|
|
24890
27114
|
}
|
|
24891
27115
|
});
|
|
24892
|
-
if (capturedResourceOptions.getResourceContent) serverInstance.setRequestHandler(
|
|
27116
|
+
if (capturedResourceOptions.getResourceContent) serverInstance.setRequestHandler("resources/read", async (request, ctx) => {
|
|
24893
27117
|
const startTime = Date.now();
|
|
24894
27118
|
const uri = request.params.uri;
|
|
24895
27119
|
this.logger.debug("Handling ReadResource request", { uri });
|
|
24896
|
-
const resources = await capturedResourceOptions.listResources?.({ extra });
|
|
27120
|
+
const resources = await capturedResourceOptions.listResources?.({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24897
27121
|
if (!resources) throw new Error("Failed to load resources");
|
|
24898
27122
|
const resource = resources.find((r) => r.uri === uri);
|
|
24899
27123
|
if (!resource) {
|
|
24900
27124
|
this.logger.warn("Unknown resource URI requested", { uri });
|
|
24901
|
-
throw new
|
|
27125
|
+
throw new _modelcontextprotocol_server.ProtocolError(_modelcontextprotocol_server.ProtocolErrorCode.InvalidParams, `Resource not found: ${uri}`);
|
|
24902
27126
|
}
|
|
24903
27127
|
try {
|
|
24904
27128
|
const resourcesOrResourceContent = await capturedResourceOptions.getResourceContent({
|
|
24905
27129
|
uri,
|
|
24906
|
-
extra
|
|
27130
|
+
extra: toMCPRequestHandlerExtra(ctx)
|
|
24907
27131
|
});
|
|
24908
27132
|
const resourcesContent = Array.isArray(resourcesOrResourceContent) ? resourcesOrResourceContent : [resourcesOrResourceContent];
|
|
24909
27133
|
const resourceMeta = resource._meta ? { _meta: resource._meta } : {};
|
|
@@ -24939,9 +27163,9 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24939
27163
|
throw error;
|
|
24940
27164
|
}
|
|
24941
27165
|
});
|
|
24942
|
-
if (capturedResourceOptions.resourceTemplates) serverInstance.setRequestHandler(
|
|
27166
|
+
if (capturedResourceOptions.resourceTemplates) serverInstance.setRequestHandler("resources/templates/list", async (_request, ctx) => {
|
|
24943
27167
|
try {
|
|
24944
|
-
const templates = await capturedResourceOptions.resourceTemplates({ extra });
|
|
27168
|
+
const templates = await capturedResourceOptions.resourceTemplates({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24945
27169
|
this.logger.debug("Fetched resource templates", { count: templates.length });
|
|
24946
27170
|
return { resourceTemplates: templates };
|
|
24947
27171
|
} catch (error) {
|
|
@@ -24949,7 +27173,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24949
27173
|
throw error;
|
|
24950
27174
|
}
|
|
24951
27175
|
});
|
|
24952
|
-
serverInstance.setRequestHandler(
|
|
27176
|
+
serverInstance.setRequestHandler("resources/subscribe", async (request) => {
|
|
24953
27177
|
const uri = request.params.uri;
|
|
24954
27178
|
this.logger.info("Received resources/subscribe request", { uri });
|
|
24955
27179
|
let subscriptions = this.subscriptionsByInstance.get(serverInstance);
|
|
@@ -24960,7 +27184,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24960
27184
|
subscriptions.add(uri);
|
|
24961
27185
|
return {};
|
|
24962
27186
|
});
|
|
24963
|
-
serverInstance.setRequestHandler(
|
|
27187
|
+
serverInstance.setRequestHandler("resources/unsubscribe", async (request) => {
|
|
24964
27188
|
const uri = request.params.uri;
|
|
24965
27189
|
this.logger.info("Received resources/unsubscribe request", { uri });
|
|
24966
27190
|
this.subscriptionsByInstance.get(serverInstance)?.delete(uri);
|
|
@@ -24973,12 +27197,12 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24973
27197
|
registerPromptHandlersOnServer(serverInstance) {
|
|
24974
27198
|
const capturedPromptOptions = this.promptOptions;
|
|
24975
27199
|
if (!capturedPromptOptions) return;
|
|
24976
|
-
if (capturedPromptOptions.listPrompts) serverInstance.setRequestHandler(
|
|
27200
|
+
if (capturedPromptOptions.listPrompts) serverInstance.setRequestHandler("prompts/list", async (_request, ctx) => {
|
|
24977
27201
|
this.logger.debug("Handling ListPrompts request");
|
|
24978
27202
|
if (this.definedPrompts) return { prompts: this.definedPrompts };
|
|
24979
27203
|
else try {
|
|
24980
|
-
const prompts = await capturedPromptOptions.listPrompts({ extra });
|
|
24981
|
-
for (const prompt of prompts)
|
|
27204
|
+
const prompts = await capturedPromptOptions.listPrompts({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
27205
|
+
for (const prompt of prompts) _modelcontextprotocol_core.PromptSchema.parse(prompt);
|
|
24982
27206
|
this.definedPrompts = prompts;
|
|
24983
27207
|
this.logger.debug("Fetched and cached prompts", { count: this.definedPrompts.length });
|
|
24984
27208
|
return { prompts: this.definedPrompts };
|
|
@@ -24987,18 +27211,18 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24987
27211
|
throw error;
|
|
24988
27212
|
}
|
|
24989
27213
|
});
|
|
24990
|
-
if (capturedPromptOptions.getPromptMessages) serverInstance.setRequestHandler(
|
|
27214
|
+
if (capturedPromptOptions.getPromptMessages) serverInstance.setRequestHandler("prompts/get", async (request, ctx) => {
|
|
24991
27215
|
const startTime = Date.now();
|
|
24992
27216
|
const { name, arguments: args } = request.params;
|
|
24993
27217
|
if (!this.definedPrompts) {
|
|
24994
|
-
const prompts = await this.promptOptions?.listPrompts?.({ extra });
|
|
27218
|
+
const prompts = await this.promptOptions?.listPrompts?.({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24995
27219
|
if (!prompts) throw new Error("Failed to load prompts");
|
|
24996
27220
|
this.definedPrompts = prompts;
|
|
24997
27221
|
}
|
|
24998
27222
|
const prompt = this.definedPrompts?.find((p) => p.name === name);
|
|
24999
27223
|
if (!prompt) throw new Error(`Prompt "${name}" not found`);
|
|
25000
27224
|
if (prompt.arguments) {
|
|
25001
|
-
for (const arg of prompt.arguments) if (arg.required && (args?.[arg.name] === void 0 || args?.[arg.name] === null)) throw new
|
|
27225
|
+
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
27226
|
}
|
|
25003
27227
|
try {
|
|
25004
27228
|
let messages = [];
|
|
@@ -25006,7 +27230,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25006
27230
|
name,
|
|
25007
27231
|
version: prompt.version,
|
|
25008
27232
|
args,
|
|
25009
|
-
extra
|
|
27233
|
+
extra: toMCPRequestHandlerExtra(ctx)
|
|
25010
27234
|
});
|
|
25011
27235
|
const duration = Date.now() - startTime;
|
|
25012
27236
|
this.logger.info("Prompt retrieved successfully", {
|
|
@@ -25244,7 +27468,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25244
27468
|
* ```
|
|
25245
27469
|
*/
|
|
25246
27470
|
async startStdio() {
|
|
25247
|
-
this.stdioTransport = new
|
|
27471
|
+
this.stdioTransport = new _modelcontextprotocol_server_stdio.StdioServerTransport();
|
|
25248
27472
|
try {
|
|
25249
27473
|
await this.server.connect(this.stdioTransport);
|
|
25250
27474
|
} catch (error) {
|
|
@@ -25517,11 +27741,11 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25517
27741
|
this.logger.debug("No session ID provided", { method: req.method });
|
|
25518
27742
|
if (req.method === "POST") {
|
|
25519
27743
|
const body = await this.readJsonBody(req);
|
|
25520
|
-
const { isInitializeRequest } = await import("@modelcontextprotocol/
|
|
27744
|
+
const { isInitializeRequest } = await import("@modelcontextprotocol/server");
|
|
25521
27745
|
if (isInitializeRequest(body)) {
|
|
25522
27746
|
this.logger.debug("Received initialize request, creating new transport");
|
|
25523
27747
|
const sessionServerInstance = this.createServerInstance();
|
|
25524
|
-
transport = new
|
|
27748
|
+
transport = new _modelcontextprotocol_node.NodeStreamableHTTPServerTransport({
|
|
25525
27749
|
...mergedOptions,
|
|
25526
27750
|
sessionIdGenerator: mergedOptions.sessionIdGenerator,
|
|
25527
27751
|
onsessioninitialized: (id) => {
|
|
@@ -25618,7 +27842,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25618
27842
|
enableJsonResponse
|
|
25619
27843
|
});
|
|
25620
27844
|
const transientServer = this.createServerInstance();
|
|
25621
|
-
const tempTransport = new
|
|
27845
|
+
const tempTransport = new _modelcontextprotocol_node.NodeStreamableHTTPServerTransport({
|
|
25622
27846
|
sessionIdGenerator: void 0,
|
|
25623
27847
|
enableJsonResponse
|
|
25624
27848
|
});
|
|
@@ -25678,7 +27902,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25678
27902
|
await this.sseTransport.close?.();
|
|
25679
27903
|
this.sseTransport = void 0;
|
|
25680
27904
|
}
|
|
25681
|
-
this.sseTransport = new
|
|
27905
|
+
this.sseTransport = new _modelcontextprotocol_server_legacy_sse.SSEServerTransport(messagePath, res);
|
|
25682
27906
|
await this.server.connect(this.sseTransport);
|
|
25683
27907
|
this.server.onclose = async () => {
|
|
25684
27908
|
this.sseTransport = void 0;
|
|
@@ -25859,8 +28083,12 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25859
28083
|
};
|
|
25860
28084
|
}
|
|
25861
28085
|
convertSchema(schema) {
|
|
25862
|
-
|
|
25863
|
-
|
|
28086
|
+
const jsonSchema = (0, _mastra_core_schema.isStandardSchemaWithJSON)(schema) ? (0, _mastra_core_schema.standardSchemaToJSONSchema)(schema) : schema?.jsonSchema ?? schema;
|
|
28087
|
+
if (jsonSchema && typeof jsonSchema === "object" && "$schema" in jsonSchema) {
|
|
28088
|
+
const { $schema: _dialect, ...rest } = jsonSchema;
|
|
28089
|
+
return rest;
|
|
28090
|
+
}
|
|
28091
|
+
return jsonSchema;
|
|
25864
28092
|
}
|
|
25865
28093
|
/**
|
|
25866
28094
|
* Gets a list of all tools provided by this MCP server with their schemas.
|
|
@@ -25950,6 +28178,8 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
25950
28178
|
Object.entries(extraRecord).forEach(([key, value]) => {
|
|
25951
28179
|
proxiedContext.set(key, value);
|
|
25952
28180
|
});
|
|
28181
|
+
const http = extraRecord.http;
|
|
28182
|
+
if (http && typeof http === "object" && "authInfo" in http) proxiedContext.set("authInfo", http.authInfo);
|
|
25953
28183
|
}
|
|
25954
28184
|
await this.resolveMappedFGAUser(proxiedContext, extraRecord);
|
|
25955
28185
|
return proxiedContext;
|
|
@@ -26422,22 +28652,23 @@ exports.MCPClient = MCPClient;
|
|
|
26422
28652
|
exports.MCPClientServerProxy = MCPClientServerProxy;
|
|
26423
28653
|
exports.MCPOAuthClientProvider = MCPOAuthClientProvider;
|
|
26424
28654
|
exports.MCPServer = MCPServer;
|
|
28655
|
+
exports.MCP_CALL_TOOL_CONTENT = MCP_CALL_TOOL_CONTENT;
|
|
26425
28656
|
Object.defineProperty(exports, "UnauthorizedError", {
|
|
26426
28657
|
enumerable: true,
|
|
26427
28658
|
get: function() {
|
|
26428
|
-
return
|
|
28659
|
+
return _modelcontextprotocol_client.UnauthorizedError;
|
|
26429
28660
|
}
|
|
26430
28661
|
});
|
|
26431
28662
|
Object.defineProperty(exports, "auth", {
|
|
26432
28663
|
enumerable: true,
|
|
26433
28664
|
get: function() {
|
|
26434
|
-
return
|
|
28665
|
+
return _modelcontextprotocol_client.auth;
|
|
26435
28666
|
}
|
|
26436
28667
|
});
|
|
26437
28668
|
Object.defineProperty(exports, "buildDiscoveryUrls", {
|
|
26438
28669
|
enumerable: true,
|
|
26439
28670
|
get: function() {
|
|
26440
|
-
return
|
|
28671
|
+
return _modelcontextprotocol_client.buildDiscoveryUrls;
|
|
26441
28672
|
}
|
|
26442
28673
|
});
|
|
26443
28674
|
exports.createIntrospectionValidator = createIntrospectionValidator;
|
|
@@ -26448,32 +28679,32 @@ exports.createStaticTokenValidator = createStaticTokenValidator;
|
|
|
26448
28679
|
Object.defineProperty(exports, "discoverAuthorizationServerMetadata", {
|
|
26449
28680
|
enumerable: true,
|
|
26450
28681
|
get: function() {
|
|
26451
|
-
return
|
|
28682
|
+
return _modelcontextprotocol_client.discoverAuthorizationServerMetadata;
|
|
26452
28683
|
}
|
|
26453
28684
|
});
|
|
26454
28685
|
Object.defineProperty(exports, "discoverOAuthMetadata", {
|
|
26455
28686
|
enumerable: true,
|
|
26456
28687
|
get: function() {
|
|
26457
|
-
return
|
|
28688
|
+
return _modelcontextprotocol_client.discoverOAuthMetadata;
|
|
26458
28689
|
}
|
|
26459
28690
|
});
|
|
26460
28691
|
Object.defineProperty(exports, "discoverOAuthProtectedResourceMetadata", {
|
|
26461
28692
|
enumerable: true,
|
|
26462
28693
|
get: function() {
|
|
26463
|
-
return
|
|
28694
|
+
return _modelcontextprotocol_client.discoverOAuthProtectedResourceMetadata;
|
|
26464
28695
|
}
|
|
26465
28696
|
});
|
|
26466
28697
|
Object.defineProperty(exports, "exchangeAuthorization", {
|
|
26467
28698
|
enumerable: true,
|
|
26468
28699
|
get: function() {
|
|
26469
|
-
return
|
|
28700
|
+
return _modelcontextprotocol_client.exchangeAuthorization;
|
|
26470
28701
|
}
|
|
26471
28702
|
});
|
|
26472
28703
|
exports.extractBearerToken = extractBearerToken;
|
|
26473
28704
|
Object.defineProperty(exports, "extractResourceMetadataUrl", {
|
|
26474
28705
|
enumerable: true,
|
|
26475
28706
|
get: function() {
|
|
26476
|
-
return
|
|
28707
|
+
return _modelcontextprotocol_client.extractResourceMetadataUrl;
|
|
26477
28708
|
}
|
|
26478
28709
|
});
|
|
26479
28710
|
exports.generateProtectedResourceMetadata = generateProtectedResourceMetadata;
|
|
@@ -26482,31 +28713,31 @@ exports.getCallbackUrlCandidates = getCallbackUrlCandidates;
|
|
|
26482
28713
|
Object.defineProperty(exports, "parseErrorResponse", {
|
|
26483
28714
|
enumerable: true,
|
|
26484
28715
|
get: function() {
|
|
26485
|
-
return
|
|
28716
|
+
return _modelcontextprotocol_client.parseErrorResponse;
|
|
26486
28717
|
}
|
|
26487
28718
|
});
|
|
26488
28719
|
Object.defineProperty(exports, "refreshAuthorization", {
|
|
26489
28720
|
enumerable: true,
|
|
26490
28721
|
get: function() {
|
|
26491
|
-
return
|
|
28722
|
+
return _modelcontextprotocol_client.refreshAuthorization;
|
|
26492
28723
|
}
|
|
26493
28724
|
});
|
|
26494
28725
|
Object.defineProperty(exports, "registerClient", {
|
|
26495
28726
|
enumerable: true,
|
|
26496
28727
|
get: function() {
|
|
26497
|
-
return
|
|
28728
|
+
return _modelcontextprotocol_client.registerClient;
|
|
26498
28729
|
}
|
|
26499
28730
|
});
|
|
26500
28731
|
Object.defineProperty(exports, "selectResourceURL", {
|
|
26501
28732
|
enumerable: true,
|
|
26502
28733
|
get: function() {
|
|
26503
|
-
return
|
|
28734
|
+
return _modelcontextprotocol_client.selectResourceURL;
|
|
26504
28735
|
}
|
|
26505
28736
|
});
|
|
26506
28737
|
Object.defineProperty(exports, "startAuthorization", {
|
|
26507
28738
|
enumerable: true,
|
|
26508
28739
|
get: function() {
|
|
26509
|
-
return
|
|
28740
|
+
return _modelcontextprotocol_client.startAuthorization;
|
|
26510
28741
|
}
|
|
26511
28742
|
});
|
|
26512
28743
|
|