@mastra/mcp 1.15.1 → 1.16.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -0
- package/dist/client/actions/elicitation.d.ts +1 -1
- package/dist/client/actions/elicitation.d.ts.map +1 -1
- package/dist/client/actions/progress.d.ts +1 -1
- package/dist/client/actions/progress.d.ts.map +1 -1
- package/dist/client/actions/prompt.d.ts +1 -1
- package/dist/client/actions/prompt.d.ts.map +1 -1
- package/dist/client/actions/resource.d.ts +38 -11
- package/dist/client/actions/resource.d.ts.map +1 -1
- package/dist/client/client.d.ts +3 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +50 -14
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/client/types.d.ts +65 -10
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/url-policy.d.ts +67 -0
- package/dist/client/url-policy.d.ts.map +1 -0
- package/dist/docs/SKILL.md +3 -3
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-connections-overview.md +94 -0
- package/dist/docs/references/docs-mcp-overview.md +229 -278
- package/dist/docs/references/reference-tools-mcp-client.md +54 -0
- package/dist/docs/references/reference-tools-mcp-server.md +1 -1
- package/dist/index.cjs +2435 -275
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2403 -243
- package/dist/index.js.map +1 -1
- package/dist/server/__tests__/mock-extra.d.ts +15 -0
- package/dist/server/__tests__/mock-extra.d.ts.map +1 -0
- package/dist/server/notificationBroadcast.d.ts +1 -1
- package/dist/server/notificationBroadcast.d.ts.map +1 -1
- package/dist/server/promptActions.d.ts +1 -1
- package/dist/server/promptActions.d.ts.map +1 -1
- package/dist/server/resourceActions.d.ts +1 -1
- package/dist/server/resourceActions.d.ts.map +1 -1
- package/dist/server/server.d.ts +10 -12
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/toolActions.d.ts +1 -1
- package/dist/server/toolActions.d.ts.map +1 -1
- package/dist/server/types.d.ts +7 -7
- package/dist/server/types.d.ts.map +1 -1
- package/dist/shared/oauth-types.d.ts +8 -6
- package/dist/shared/oauth-types.d.ts.map +1 -1
- package/package.json +18 -14
- package/dist/docs/references/docs-mcp-mcp-apps.md +0 -306
package/dist/index.js
CHANGED
|
@@ -3,14 +3,9 @@ import { AsyncLocalStorage } from "async_hooks";
|
|
|
3
3
|
import { MastraBase } from "@mastra/core/base";
|
|
4
4
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
5
5
|
import { createTool, isValidationError } from "@mastra/core/tools";
|
|
6
|
-
import { Client } from "@modelcontextprotocol/
|
|
7
|
-
import {
|
|
8
|
-
import { StdioClientTransport, getDefaultEnvironment } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
9
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
10
|
-
import { DEFAULT_REQUEST_TIMEOUT_MSEC } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
11
|
-
import { CallToolRequestSchema, CallToolResultSchema, ElicitRequestSchema, EmptyResultSchema, ErrorCode, GetPromptRequestSchema, GetPromptResultSchema, JSONRPCMessageSchema, ListPromptsRequestSchema, ListPromptsResultSchema, ListResourceTemplatesRequestSchema, ListResourceTemplatesResultSchema, ListResourcesRequestSchema, ListResourcesResultSchema, ListRootsRequestSchema, ListToolsRequestSchema, LoggingMessageNotificationSchema, McpError, ProgressNotificationSchema, PromptListChangedNotificationSchema, PromptSchema, ReadResourceRequestSchema, ReadResourceResultSchema, ResourceListChangedNotificationSchema, ResourceUpdatedNotificationSchema, SetLevelRequestSchema, SubscribeRequestSchema, ToolListChangedNotificationSchema, UnsubscribeRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import { Client, DEFAULT_REQUEST_TIMEOUT_MSEC, ProtocolErrorCode, SSEClientTransport, SdkHttpError, StreamableHTTPClientTransport, UnauthorizedError, auth, buildDiscoveryUrls, discoverAuthorizationServerMetadata, discoverOAuthMetadata, discoverOAuthProtectedResourceMetadata, exchangeAuthorization, extractResourceMetadataUrl, parseErrorResponse, refreshAuthorization, registerClient, selectResourceURL, startAuthorization } from "@modelcontextprotocol/client";
|
|
7
|
+
import { StdioClientTransport, getDefaultEnvironment } from "@modelcontextprotocol/client/stdio";
|
|
12
8
|
import { asyncExitHook, gracefulExit } from "exit-hook";
|
|
13
|
-
import { UnauthorizedError, auth, buildDiscoveryUrls, discoverAuthorizationServerMetadata, discoverOAuthMetadata, discoverOAuthProtectedResourceMetadata, exchangeAuthorization, extractResourceMetadataUrl, parseErrorResponse, refreshAuthorization, registerClient, selectResourceURL, startAuthorization } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
14
9
|
import { createHash, randomUUID, timingSafeEqual } from "crypto";
|
|
15
10
|
import equal from "fast-deep-equal";
|
|
16
11
|
import { createServer } from "http";
|
|
@@ -19,11 +14,12 @@ import { isStandardSchemaWithJSON, standardSchemaToJSONSchema } from "@mastra/co
|
|
|
19
14
|
import { readFileSync } from "fs";
|
|
20
15
|
import { RequestContext } from "@mastra/core/request-context";
|
|
21
16
|
import { makeCoreTool } from "@mastra/core/utils";
|
|
17
|
+
import { PromptSchema } from "@modelcontextprotocol/core";
|
|
22
18
|
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import { StdioServerTransport } from "@modelcontextprotocol/
|
|
26
|
-
import {
|
|
19
|
+
import { NodeStreamableHTTPServerTransport } from "@modelcontextprotocol/node";
|
|
20
|
+
import { ProtocolError, ProtocolErrorCode as ProtocolErrorCode$1, Server } from "@modelcontextprotocol/server";
|
|
21
|
+
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
|
22
|
+
import { SSEServerTransport } from "@modelcontextprotocol/server-legacy/sse";
|
|
27
23
|
//#region \0rolldown/runtime.js
|
|
28
24
|
var __defProp$3 = Object.defineProperty;
|
|
29
25
|
var __exportAll = (all, no_symbols) => {
|
|
@@ -1990,6 +1986,62 @@ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
|
|
|
1990
1986
|
});
|
|
1991
1987
|
};
|
|
1992
1988
|
});
|
|
1989
|
+
const $ZodDiscriminatedUnion = /*@__PURE__*/ $constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
|
1990
|
+
def.inclusive = false;
|
|
1991
|
+
$ZodUnion.init(inst, def);
|
|
1992
|
+
const _super = inst._zod.parse;
|
|
1993
|
+
defineLazy(inst._zod, "propValues", () => {
|
|
1994
|
+
const propValues = {};
|
|
1995
|
+
for (const option of def.options) {
|
|
1996
|
+
const pv = option._zod.propValues;
|
|
1997
|
+
if (!pv || Object.keys(pv).length === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
1998
|
+
for (const [k, v] of Object.entries(pv)) {
|
|
1999
|
+
if (!propValues[k]) propValues[k] = /* @__PURE__ */ new Set();
|
|
2000
|
+
for (const val of v) propValues[k].add(val);
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
return propValues;
|
|
2004
|
+
});
|
|
2005
|
+
const disc = cached(() => {
|
|
2006
|
+
const opts = def.options;
|
|
2007
|
+
const map = /* @__PURE__ */ new Map();
|
|
2008
|
+
for (const o of opts) {
|
|
2009
|
+
const values = o._zod.propValues?.[def.discriminator];
|
|
2010
|
+
if (!values || values.size === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
|
|
2011
|
+
for (const v of values) {
|
|
2012
|
+
if (map.has(v)) throw new Error(`Duplicate discriminator value "${String(v)}"`);
|
|
2013
|
+
map.set(v, o);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
return map;
|
|
2017
|
+
});
|
|
2018
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2019
|
+
const input = payload.value;
|
|
2020
|
+
if (!isObject(input)) {
|
|
2021
|
+
payload.issues.push({
|
|
2022
|
+
code: "invalid_type",
|
|
2023
|
+
expected: "object",
|
|
2024
|
+
input,
|
|
2025
|
+
inst
|
|
2026
|
+
});
|
|
2027
|
+
return payload;
|
|
2028
|
+
}
|
|
2029
|
+
const opt = disc.value.get(input?.[def.discriminator]);
|
|
2030
|
+
if (opt) return opt._zod.run(payload, ctx);
|
|
2031
|
+
if (def.unionFallback || ctx.direction === "backward") return _super(payload, ctx);
|
|
2032
|
+
payload.issues.push({
|
|
2033
|
+
code: "invalid_union",
|
|
2034
|
+
errors: [],
|
|
2035
|
+
note: "No matching discriminator",
|
|
2036
|
+
discriminator: def.discriminator,
|
|
2037
|
+
options: Array.from(disc.value.keys()),
|
|
2038
|
+
input,
|
|
2039
|
+
path: [def.discriminator],
|
|
2040
|
+
inst
|
|
2041
|
+
});
|
|
2042
|
+
return payload;
|
|
2043
|
+
};
|
|
2044
|
+
});
|
|
1993
2045
|
const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
|
|
1994
2046
|
$ZodType.init(inst, def);
|
|
1995
2047
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -2525,6 +2577,9 @@ function handlePipeResult(left, next, ctx) {
|
|
|
2525
2577
|
fallback: left.fallback
|
|
2526
2578
|
}, ctx);
|
|
2527
2579
|
}
|
|
2580
|
+
const $ZodPreprocess = /*@__PURE__*/ $constructor("$ZodPreprocess", (inst, def) => {
|
|
2581
|
+
$ZodPipe.init(inst, def);
|
|
2582
|
+
});
|
|
2528
2583
|
const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
|
|
2529
2584
|
$ZodType.init(inst, def);
|
|
2530
2585
|
defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
@@ -4544,6 +4599,14 @@ function object$1(shape, params) {
|
|
|
4544
4599
|
};
|
|
4545
4600
|
return new ZodObject$1(def);
|
|
4546
4601
|
}
|
|
4602
|
+
function looseObject(shape, params) {
|
|
4603
|
+
return new ZodObject$1({
|
|
4604
|
+
type: "object",
|
|
4605
|
+
shape,
|
|
4606
|
+
catchall: unknown(),
|
|
4607
|
+
...normalizeParams(params)
|
|
4608
|
+
});
|
|
4609
|
+
}
|
|
4547
4610
|
const ZodUnion$1 = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
|
|
4548
4611
|
$ZodUnion.init(inst, def);
|
|
4549
4612
|
ZodType$1.init(inst, def);
|
|
@@ -4557,6 +4620,18 @@ function union(options, params) {
|
|
|
4557
4620
|
...normalizeParams(params)
|
|
4558
4621
|
});
|
|
4559
4622
|
}
|
|
4623
|
+
const ZodDiscriminatedUnion$1 = /*@__PURE__*/ $constructor("ZodDiscriminatedUnion", (inst, def) => {
|
|
4624
|
+
ZodUnion$1.init(inst, def);
|
|
4625
|
+
$ZodDiscriminatedUnion.init(inst, def);
|
|
4626
|
+
});
|
|
4627
|
+
function discriminatedUnion(discriminator, options, params) {
|
|
4628
|
+
return new ZodDiscriminatedUnion$1({
|
|
4629
|
+
type: "union",
|
|
4630
|
+
options,
|
|
4631
|
+
discriminator,
|
|
4632
|
+
...normalizeParams(params)
|
|
4633
|
+
});
|
|
4634
|
+
}
|
|
4560
4635
|
const ZodIntersection$1 = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
|
|
4561
4636
|
$ZodIntersection.init(inst, def);
|
|
4562
4637
|
ZodType$1.init(inst, def);
|
|
@@ -4816,6 +4891,10 @@ function pipe(in_, out) {
|
|
|
4816
4891
|
out
|
|
4817
4892
|
});
|
|
4818
4893
|
}
|
|
4894
|
+
const ZodPreprocess = /*@__PURE__*/ $constructor("ZodPreprocess", (inst, def) => {
|
|
4895
|
+
ZodPipe.init(inst, def);
|
|
4896
|
+
$ZodPreprocess.init(inst, def);
|
|
4897
|
+
});
|
|
4819
4898
|
const ZodReadonly$1 = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
|
|
4820
4899
|
$ZodReadonly.init(inst, def);
|
|
4821
4900
|
ZodType$1.init(inst, def);
|
|
@@ -4874,6 +4953,13 @@ function _instanceof(cls, params = {}) {
|
|
|
4874
4953
|
};
|
|
4875
4954
|
return inst;
|
|
4876
4955
|
}
|
|
4956
|
+
function preprocess(fn, schema) {
|
|
4957
|
+
return new ZodPreprocess({
|
|
4958
|
+
type: "pipe",
|
|
4959
|
+
in: transform(fn),
|
|
4960
|
+
out: schema
|
|
4961
|
+
});
|
|
4962
|
+
}
|
|
4877
4963
|
//#endregion
|
|
4878
4964
|
//#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
|
|
4879
4965
|
const ignoreOverride$1 = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
@@ -20391,12 +20477,12 @@ var ClientOrServerImplementationSchema = object$1({
|
|
|
20391
20477
|
version: string()
|
|
20392
20478
|
}).passthrough();
|
|
20393
20479
|
var BaseParamsSchema = object$1({ _meta: optional(object$1({}).passthrough()) }).passthrough();
|
|
20394
|
-
var ResultSchema = BaseParamsSchema;
|
|
20395
|
-
var RequestSchema = object$1({
|
|
20480
|
+
var ResultSchema$1 = BaseParamsSchema;
|
|
20481
|
+
var RequestSchema$1 = object$1({
|
|
20396
20482
|
method: string(),
|
|
20397
20483
|
params: optional(BaseParamsSchema)
|
|
20398
20484
|
});
|
|
20399
|
-
var ServerCapabilitiesSchema = object$1({
|
|
20485
|
+
var ServerCapabilitiesSchema$1 = object$1({
|
|
20400
20486
|
experimental: optional(object$1({}).passthrough()),
|
|
20401
20487
|
logging: optional(object$1({}).passthrough()),
|
|
20402
20488
|
prompts: optional(object$1({ listChanged: optional(boolean()) }).passthrough()),
|
|
@@ -20406,14 +20492,14 @@ var ServerCapabilitiesSchema = object$1({
|
|
|
20406
20492
|
}).passthrough()),
|
|
20407
20493
|
tools: optional(object$1({ listChanged: optional(boolean()) }).passthrough())
|
|
20408
20494
|
}).passthrough();
|
|
20409
|
-
ResultSchema.extend({
|
|
20495
|
+
ResultSchema$1.extend({
|
|
20410
20496
|
protocolVersion: string(),
|
|
20411
|
-
capabilities: ServerCapabilitiesSchema,
|
|
20497
|
+
capabilities: ServerCapabilitiesSchema$1,
|
|
20412
20498
|
serverInfo: ClientOrServerImplementationSchema,
|
|
20413
20499
|
instructions: optional(string())
|
|
20414
20500
|
});
|
|
20415
|
-
var PaginatedResultSchema = ResultSchema.extend({ nextCursor: optional(string()) });
|
|
20416
|
-
var ToolSchema = object$1({
|
|
20501
|
+
var PaginatedResultSchema$1 = ResultSchema$1.extend({ nextCursor: optional(string()) });
|
|
20502
|
+
var ToolSchema$1 = object$1({
|
|
20417
20503
|
name: string(),
|
|
20418
20504
|
description: optional(string()),
|
|
20419
20505
|
inputSchema: object$1({
|
|
@@ -20421,17 +20507,17 @@ var ToolSchema = object$1({
|
|
|
20421
20507
|
properties: optional(object$1({}).passthrough())
|
|
20422
20508
|
}).passthrough()
|
|
20423
20509
|
}).passthrough();
|
|
20424
|
-
PaginatedResultSchema.extend({ tools: array(ToolSchema) });
|
|
20425
|
-
var TextContentSchema = object$1({
|
|
20510
|
+
PaginatedResultSchema$1.extend({ tools: array(ToolSchema$1) });
|
|
20511
|
+
var TextContentSchema$1 = object$1({
|
|
20426
20512
|
type: literal("text"),
|
|
20427
20513
|
text: string()
|
|
20428
20514
|
}).passthrough();
|
|
20429
|
-
var ImageContentSchema = object$1({
|
|
20515
|
+
var ImageContentSchema$1 = object$1({
|
|
20430
20516
|
type: literal("image"),
|
|
20431
20517
|
data: string().base64(),
|
|
20432
20518
|
mimeType: string()
|
|
20433
20519
|
}).passthrough();
|
|
20434
|
-
var ResourceContentsSchema = object$1({
|
|
20520
|
+
var ResourceContentsSchema$1 = object$1({
|
|
20435
20521
|
/**
|
|
20436
20522
|
* The URI of this resource.
|
|
20437
20523
|
*/
|
|
@@ -20441,32 +20527,32 @@ var ResourceContentsSchema = object$1({
|
|
|
20441
20527
|
*/
|
|
20442
20528
|
mimeType: optional(string())
|
|
20443
20529
|
}).passthrough();
|
|
20444
|
-
var TextResourceContentsSchema = ResourceContentsSchema.extend({ text: string() });
|
|
20445
|
-
var BlobResourceContentsSchema = ResourceContentsSchema.extend({ blob: string().base64() });
|
|
20446
|
-
var EmbeddedResourceSchema = object$1({
|
|
20530
|
+
var TextResourceContentsSchema$1 = ResourceContentsSchema$1.extend({ text: string() });
|
|
20531
|
+
var BlobResourceContentsSchema$1 = ResourceContentsSchema$1.extend({ blob: string().base64() });
|
|
20532
|
+
var EmbeddedResourceSchema$1 = object$1({
|
|
20447
20533
|
type: literal("resource"),
|
|
20448
|
-
resource: union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
|
20534
|
+
resource: union([TextResourceContentsSchema$1, BlobResourceContentsSchema$1])
|
|
20449
20535
|
}).passthrough();
|
|
20450
|
-
ResultSchema.extend({
|
|
20536
|
+
ResultSchema$1.extend({
|
|
20451
20537
|
content: array(union([
|
|
20452
|
-
TextContentSchema,
|
|
20453
|
-
ImageContentSchema,
|
|
20454
|
-
EmbeddedResourceSchema
|
|
20538
|
+
TextContentSchema$1,
|
|
20539
|
+
ImageContentSchema$1,
|
|
20540
|
+
EmbeddedResourceSchema$1
|
|
20455
20541
|
])),
|
|
20456
20542
|
isError: boolean().default(false).optional()
|
|
20457
|
-
}).or(ResultSchema.extend({ toolResult: unknown() }));
|
|
20458
|
-
var JSONRPC_VERSION = "2.0";
|
|
20459
|
-
var JSONRPCRequestSchema = object$1({
|
|
20460
|
-
jsonrpc: literal(JSONRPC_VERSION),
|
|
20543
|
+
}).or(ResultSchema$1.extend({ toolResult: unknown() }));
|
|
20544
|
+
var JSONRPC_VERSION$1 = "2.0";
|
|
20545
|
+
var JSONRPCRequestSchema$1 = object$1({
|
|
20546
|
+
jsonrpc: literal(JSONRPC_VERSION$1),
|
|
20461
20547
|
id: union([string(), number().int()])
|
|
20462
|
-
}).merge(RequestSchema).strict();
|
|
20463
|
-
var JSONRPCResponseSchema = object$1({
|
|
20464
|
-
jsonrpc: literal(JSONRPC_VERSION),
|
|
20548
|
+
}).merge(RequestSchema$1).strict();
|
|
20549
|
+
var JSONRPCResponseSchema$1 = object$1({
|
|
20550
|
+
jsonrpc: literal(JSONRPC_VERSION$1),
|
|
20465
20551
|
id: union([string(), number().int()]),
|
|
20466
|
-
result: ResultSchema
|
|
20552
|
+
result: ResultSchema$1
|
|
20467
20553
|
}).strict();
|
|
20468
20554
|
var JSONRPCErrorSchema = object$1({
|
|
20469
|
-
jsonrpc: literal(JSONRPC_VERSION),
|
|
20555
|
+
jsonrpc: literal(JSONRPC_VERSION$1),
|
|
20470
20556
|
id: union([string(), number().int()]),
|
|
20471
20557
|
error: object$1({
|
|
20472
20558
|
code: number().int(),
|
|
@@ -20475,12 +20561,12 @@ var JSONRPCErrorSchema = object$1({
|
|
|
20475
20561
|
})
|
|
20476
20562
|
}).strict();
|
|
20477
20563
|
union([
|
|
20478
|
-
JSONRPCRequestSchema,
|
|
20479
|
-
object$1({ jsonrpc: literal(JSONRPC_VERSION) }).merge(object$1({
|
|
20564
|
+
JSONRPCRequestSchema$1,
|
|
20565
|
+
object$1({ jsonrpc: literal(JSONRPC_VERSION$1) }).merge(object$1({
|
|
20480
20566
|
method: string(),
|
|
20481
20567
|
params: optional(BaseParamsSchema)
|
|
20482
20568
|
})).strict(),
|
|
20483
|
-
JSONRPCResponseSchema,
|
|
20569
|
+
JSONRPCResponseSchema$1,
|
|
20484
20570
|
JSONRPCErrorSchema
|
|
20485
20571
|
]);
|
|
20486
20572
|
__export({}, {
|
|
@@ -20803,7 +20889,7 @@ var PromptClientActions = class {
|
|
|
20803
20889
|
return [];
|
|
20804
20890
|
}
|
|
20805
20891
|
} catch (e) {
|
|
20806
|
-
if (e.code ===
|
|
20892
|
+
if (e.code === ProtocolErrorCode.MethodNotFound) return [];
|
|
20807
20893
|
this.logger.error("Error getting prompts from server", {
|
|
20808
20894
|
server: this.client.name,
|
|
20809
20895
|
error: e instanceof Error ? e.message : String(e)
|
|
@@ -20910,7 +20996,7 @@ var ResourceClientActions = class {
|
|
|
20910
20996
|
return [];
|
|
20911
20997
|
}
|
|
20912
20998
|
} catch (e) {
|
|
20913
|
-
if (e.code ===
|
|
20999
|
+
if (e.code === ProtocolErrorCode.MethodNotFound) return [];
|
|
20914
21000
|
this.logger.error("Error getting resources from server", {
|
|
20915
21001
|
server: this.client.name,
|
|
20916
21002
|
error: e instanceof Error ? e.message : String(e)
|
|
@@ -20947,7 +21033,7 @@ var ResourceClientActions = class {
|
|
|
20947
21033
|
return [];
|
|
20948
21034
|
}
|
|
20949
21035
|
} catch (e) {
|
|
20950
|
-
if (e.code ===
|
|
21036
|
+
if (e.code === ProtocolErrorCode.MethodNotFound) return [];
|
|
20951
21037
|
this.logger.error("Error getting resource templates from server", {
|
|
20952
21038
|
server: this.client.name,
|
|
20953
21039
|
error: e instanceof Error ? e.message : String(e)
|
|
@@ -21055,6 +21141,202 @@ function isReconnectableMCPError(error) {
|
|
|
21055
21141
|
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");
|
|
21056
21142
|
}
|
|
21057
21143
|
//#endregion
|
|
21144
|
+
//#region src/client/url-policy.ts
|
|
21145
|
+
/**
|
|
21146
|
+
* Redirect status codes the manual redirect loop follows. Other 3xx statuses
|
|
21147
|
+
* (e.g. 304) are not redirects and are returned to the caller as-is.
|
|
21148
|
+
*/
|
|
21149
|
+
const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
|
|
21150
|
+
301,
|
|
21151
|
+
302,
|
|
21152
|
+
303,
|
|
21153
|
+
307,
|
|
21154
|
+
308
|
|
21155
|
+
]);
|
|
21156
|
+
/** Maximum number of redirect hops followed before failing. */
|
|
21157
|
+
const MAX_REDIRECT_HOPS = 5;
|
|
21158
|
+
function normalizeHost(host) {
|
|
21159
|
+
return host.toLowerCase();
|
|
21160
|
+
}
|
|
21161
|
+
/** Best-effort release of a discarded response body so its socket is not left undrained. */
|
|
21162
|
+
function cancelResponseBody(response) {
|
|
21163
|
+
const body = response.body;
|
|
21164
|
+
if (typeof body?.cancel !== "function") return;
|
|
21165
|
+
try {
|
|
21166
|
+
Promise.resolve(body.cancel()).catch(() => {});
|
|
21167
|
+
} catch {}
|
|
21168
|
+
}
|
|
21169
|
+
function isHostAllowed(host, allowedHosts) {
|
|
21170
|
+
const normalized = normalizeHost(host);
|
|
21171
|
+
return allowedHosts.some((allowed) => normalizeHost(allowed) === normalized);
|
|
21172
|
+
}
|
|
21173
|
+
/**
|
|
21174
|
+
* Marker phrase embedded in every policy error's message. The `eventsource`
|
|
21175
|
+
* package flattens errors thrown from the SSE stream's fetch into a plain
|
|
21176
|
+
* message string (its internal `flattenError`), and the SDK re-wraps that
|
|
21177
|
+
* string as `SseError` — the `MastraError` identity does not survive that
|
|
21178
|
+
* boundary, but the message text does. {@link isUrlPolicyError} falls back to
|
|
21179
|
+
* matching this marker.
|
|
21180
|
+
*/
|
|
21181
|
+
const URL_POLICY_ERROR_MARKER = "allowedHosts policy";
|
|
21182
|
+
/**
|
|
21183
|
+
* Build the policy-violation error. The message deliberately avoids every
|
|
21184
|
+
* substring matched by `isReconnectableMCPError` (see ./error-utils.ts) so a
|
|
21185
|
+
* policy violation is never treated as a transient transport failure and fed
|
|
21186
|
+
* into the reconnect machinery — a blocked host must not be retried.
|
|
21187
|
+
*/
|
|
21188
|
+
function hostNotAllowedError(host, allowedHosts, detail) {
|
|
21189
|
+
const allowedList = allowedHosts.length > 0 ? allowedHosts.map((h) => `"${h}"`).join(", ") : "(empty list — all hosts are denied)";
|
|
21190
|
+
return new MastraError({
|
|
21191
|
+
id: "MCP_CLIENT_HOST_NOT_ALLOWED",
|
|
21192
|
+
domain: ErrorDomain.MCP,
|
|
21193
|
+
category: ErrorCategory.USER,
|
|
21194
|
+
text: `Host "${host}" is blocked by the allowedHosts policy. Allowed hosts: ${allowedList}. ${detail}`,
|
|
21195
|
+
details: {
|
|
21196
|
+
host,
|
|
21197
|
+
allowedHosts: allowedHosts.join(",")
|
|
21198
|
+
}
|
|
21199
|
+
});
|
|
21200
|
+
}
|
|
21201
|
+
/**
|
|
21202
|
+
* Assert that the URL's host is in the allowlist.
|
|
21203
|
+
*
|
|
21204
|
+
* Matching is exact and case-insensitive against `URL.host` (hostname plus
|
|
21205
|
+
* port when the URL carries a non-default port — WHATWG URL elides default
|
|
21206
|
+
* ports, so `https://x.com:443` has host `x.com`). No wildcards. An empty
|
|
21207
|
+
* allowlist denies every host. The URL scheme is not checked.
|
|
21208
|
+
*
|
|
21209
|
+
* @returns the parsed URL, for callers that need it.
|
|
21210
|
+
* @throws {MastraError} `MCP_CLIENT_HOST_NOT_ALLOWED` when the host is not allowed.
|
|
21211
|
+
*/
|
|
21212
|
+
function assertHostAllowed(url, allowedHosts, detail = "The request was not sent.") {
|
|
21213
|
+
const parsed = typeof url === "string" ? new URL(url) : url;
|
|
21214
|
+
if (!isHostAllowed(parsed.host, allowedHosts)) throw hostNotAllowedError(parsed.host, allowedHosts, detail);
|
|
21215
|
+
return parsed;
|
|
21216
|
+
}
|
|
21217
|
+
/**
|
|
21218
|
+
* Post-hoc validation for responses produced by a caller-supplied fetch.
|
|
21219
|
+
*
|
|
21220
|
+
* A custom fetch may auto-follow redirects, so the final URL can differ from
|
|
21221
|
+
* the (already validated) request URL. When `response.url` lands on a
|
|
21222
|
+
* disallowed host the response is discarded by throwing — the outbound hop
|
|
21223
|
+
* already happened, but the data never reaches the caller or the model.
|
|
21224
|
+
*
|
|
21225
|
+
* Limitation (fail-open by design): a hand-built or proxied `Response` with an
|
|
21226
|
+
* empty `response.url` skips this check, because custom fetch implementations
|
|
21227
|
+
* legitimately construct such responses.
|
|
21228
|
+
*/
|
|
21229
|
+
function assertResponseHostAllowed(response, allowedHosts) {
|
|
21230
|
+
if (!response.url) return response;
|
|
21231
|
+
const parsed = new URL(response.url);
|
|
21232
|
+
if (!isHostAllowed(parsed.host, allowedHosts)) {
|
|
21233
|
+
cancelResponseBody(response);
|
|
21234
|
+
throw hostNotAllowedError(parsed.host, allowedHosts, "A custom fetch implementation followed a redirect to this host; the response was discarded.");
|
|
21235
|
+
}
|
|
21236
|
+
return response;
|
|
21237
|
+
}
|
|
21238
|
+
/**
|
|
21239
|
+
* True when the error is one of the allowedHosts policy errors. Policy
|
|
21240
|
+
* violations are final: they must never trigger the SSE fallback or the
|
|
21241
|
+
* reconnect machinery, because retrying a blocked host cannot succeed.
|
|
21242
|
+
*
|
|
21243
|
+
* Matches by `MastraError` id when the identity is intact, and by the
|
|
21244
|
+
* {@link URL_POLICY_ERROR_MARKER} message marker for errors that crossed the
|
|
21245
|
+
* eventsource boundary (which flattens thrown errors to message strings) or
|
|
21246
|
+
* were re-wrapped by another layer.
|
|
21247
|
+
*/
|
|
21248
|
+
const URL_POLICY_ERROR_IDS = /* @__PURE__ */ new Set([
|
|
21249
|
+
"MCP_CLIENT_HOST_NOT_ALLOWED",
|
|
21250
|
+
"MCP_CLIENT_TOO_MANY_REDIRECTS",
|
|
21251
|
+
"MCP_CLIENT_REDIRECT_MISSING_LOCATION",
|
|
21252
|
+
"MCP_CLIENT_REDIRECT_BODY_NOT_REPLAYABLE"
|
|
21253
|
+
]);
|
|
21254
|
+
function isUrlPolicyError(error) {
|
|
21255
|
+
if (!(error instanceof Error)) return false;
|
|
21256
|
+
if (error instanceof MastraError && URL_POLICY_ERROR_IDS.has(error.id)) return true;
|
|
21257
|
+
return error.message.includes(URL_POLICY_ERROR_MARKER);
|
|
21258
|
+
}
|
|
21259
|
+
/**
|
|
21260
|
+
* Wrap a caller-supplied fetch with the allowedHosts policy: the request URL is
|
|
21261
|
+
* validated before the wrapped fetch runs, and the response is validated
|
|
21262
|
+
* post-hoc via {@link assertResponseHostAllowed}.
|
|
21263
|
+
*
|
|
21264
|
+
* Variadic over the trailing arguments deliberately: the same wrapper serves
|
|
21265
|
+
* the 3-arg `MastraFetchLike` (url, init, requestContext) and the 2-arg
|
|
21266
|
+
* eventsource stream fetch (url, init).
|
|
21267
|
+
*/
|
|
21268
|
+
function wrapFetchWithHostPolicy(fetchImpl, allowedHosts) {
|
|
21269
|
+
return async (...args) => {
|
|
21270
|
+
assertHostAllowed(args[0], allowedHosts);
|
|
21271
|
+
return assertResponseHostAllowed(await fetchImpl(...args), allowedHosts);
|
|
21272
|
+
};
|
|
21273
|
+
}
|
|
21274
|
+
/**
|
|
21275
|
+
* Fetch with manual redirect handling so every redirect hop is validated
|
|
21276
|
+
* against the allowlist BEFORE the hop request is sent. Platform fetch follows
|
|
21277
|
+
* redirects transparently, which would bypass a per-call host check.
|
|
21278
|
+
*
|
|
21279
|
+
* Semantics follow platform conventions:
|
|
21280
|
+
* - `Location` is resolved against the current hop's URL (relative Locations are legal).
|
|
21281
|
+
* - 303 switches the method to GET and drops the body; 301/302 on POST do the same.
|
|
21282
|
+
* - 307/308 preserve method and body; a non-replayable body (anything other
|
|
21283
|
+
* than a string) throws rather than silently re-sending an empty body.
|
|
21284
|
+
* - 301/302 on non-POST methods preserve the method and body, matching
|
|
21285
|
+
* platform behavior.
|
|
21286
|
+
* - The `Authorization` header is not carried across hops to a different
|
|
21287
|
+
* origin (scheme, host, or port change), matching the WHATWG Fetch
|
|
21288
|
+
* credential-stripping rule — same host over a downgraded scheme still
|
|
21289
|
+
* drops the header.
|
|
21290
|
+
* - A redirect status with no `Location` header throws.
|
|
21291
|
+
* - More than {@link MAX_REDIRECT_HOPS} hops throws.
|
|
21292
|
+
*/
|
|
21293
|
+
async function fetchFollowingAllowedRedirects(fetchImpl, url, init, allowedHosts) {
|
|
21294
|
+
let currentUrl = assertHostAllowed(url, allowedHosts);
|
|
21295
|
+
let method = init?.method ?? "GET";
|
|
21296
|
+
let body = init?.body;
|
|
21297
|
+
const headers = new Headers(init?.headers);
|
|
21298
|
+
for (let redirectsFollowed = 0;; redirectsFollowed++) {
|
|
21299
|
+
const response = await fetchImpl(currentUrl, {
|
|
21300
|
+
...init,
|
|
21301
|
+
method,
|
|
21302
|
+
body,
|
|
21303
|
+
headers,
|
|
21304
|
+
redirect: "manual"
|
|
21305
|
+
});
|
|
21306
|
+
if (!REDIRECT_STATUS_CODES.has(response.status)) return response;
|
|
21307
|
+
const location = response.headers.get("location");
|
|
21308
|
+
if (!location) throw new MastraError({
|
|
21309
|
+
id: "MCP_CLIENT_REDIRECT_MISSING_LOCATION",
|
|
21310
|
+
domain: ErrorDomain.MCP,
|
|
21311
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
21312
|
+
text: `Received a ${response.status} redirect with no Location header from "${currentUrl.host}" while following redirects under the allowedHosts policy.`
|
|
21313
|
+
});
|
|
21314
|
+
if (redirectsFollowed >= MAX_REDIRECT_HOPS) throw new MastraError({
|
|
21315
|
+
id: "MCP_CLIENT_TOO_MANY_REDIRECTS",
|
|
21316
|
+
domain: ErrorDomain.MCP,
|
|
21317
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
21318
|
+
text: `Exceeded the maximum of ${MAX_REDIRECT_HOPS} redirect hops while requesting host "${currentUrl.host}" under the allowedHosts policy.`
|
|
21319
|
+
});
|
|
21320
|
+
cancelResponseBody(response);
|
|
21321
|
+
const nextUrl = new URL(location, currentUrl);
|
|
21322
|
+
assertHostAllowed(nextUrl, allowedHosts, `A redirect from "${currentUrl.host}" pointed at it; the hop was not followed.`);
|
|
21323
|
+
const methodUpper = method.toUpperCase();
|
|
21324
|
+
if (response.status === 303 || (response.status === 301 || response.status === 302) && methodUpper === "POST") {
|
|
21325
|
+
method = "GET";
|
|
21326
|
+
body = void 0;
|
|
21327
|
+
headers.delete("content-type");
|
|
21328
|
+
headers.delete("content-length");
|
|
21329
|
+
} else if (body != null && typeof body !== "string") throw new MastraError({
|
|
21330
|
+
id: "MCP_CLIENT_REDIRECT_BODY_NOT_REPLAYABLE",
|
|
21331
|
+
domain: ErrorDomain.MCP,
|
|
21332
|
+
category: ErrorCategory.USER,
|
|
21333
|
+
text: `Cannot follow a ${response.status} redirect under the allowedHosts policy: the request body is not replayable (only string bodies can be re-sent).`
|
|
21334
|
+
});
|
|
21335
|
+
if (nextUrl.origin !== currentUrl.origin) headers.delete("authorization");
|
|
21336
|
+
currentUrl = nextUrl;
|
|
21337
|
+
}
|
|
21338
|
+
}
|
|
21339
|
+
//#endregion
|
|
21058
21340
|
//#region src/client/client.ts
|
|
21059
21341
|
const DEFAULT_SERVER_CONNECT_TIMEOUT_MSEC = 3e3;
|
|
21060
21342
|
const DEFAULT_INSTRUCTIONS_MAX_LENGTH = 512;
|
|
@@ -21238,7 +21520,7 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21238
21520
|
});
|
|
21239
21521
|
}
|
|
21240
21522
|
setupLogging() {
|
|
21241
|
-
if (this.enableServerLogs) this.client.setNotificationHandler(
|
|
21523
|
+
if (this.enableServerLogs) this.client.setNotificationHandler("notifications/message", (notification) => {
|
|
21242
21524
|
const { level, ...params } = notification.params;
|
|
21243
21525
|
this.log(level, "[MCP SERVER LOG]", params);
|
|
21244
21526
|
});
|
|
@@ -21251,7 +21533,7 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21251
21533
|
*/
|
|
21252
21534
|
setupRootsHandler() {
|
|
21253
21535
|
this.log("debug", "Setting up roots/list request handler");
|
|
21254
|
-
this.client.setRequestHandler(
|
|
21536
|
+
this.client.setRequestHandler("roots/list", async () => {
|
|
21255
21537
|
this.log("debug", `Responding to roots/list request with ${this._roots.length} roots`);
|
|
21256
21538
|
return { roots: this._roots };
|
|
21257
21539
|
});
|
|
@@ -21300,16 +21582,28 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21300
21582
|
this.log("debug", "Sending notifications/roots/list_changed");
|
|
21301
21583
|
await this.client.notification({ method: "notifications/roots/list_changed" });
|
|
21302
21584
|
}
|
|
21585
|
+
buildStdioEnv() {
|
|
21586
|
+
const configured = this.serverConfig.env || {};
|
|
21587
|
+
if (this.serverConfig.inheritDefaultEnv === false) {
|
|
21588
|
+
const suppressed = {};
|
|
21589
|
+
for (const key of Object.keys(getDefaultEnvironment())) suppressed[key] = void 0;
|
|
21590
|
+
return {
|
|
21591
|
+
...suppressed,
|
|
21592
|
+
...configured
|
|
21593
|
+
};
|
|
21594
|
+
}
|
|
21595
|
+
return {
|
|
21596
|
+
...getDefaultEnvironment(),
|
|
21597
|
+
...configured
|
|
21598
|
+
};
|
|
21599
|
+
}
|
|
21303
21600
|
async connectStdio(command) {
|
|
21304
21601
|
this.log("debug", `Using Stdio transport for command: ${command}`);
|
|
21305
21602
|
try {
|
|
21306
21603
|
this.transport = new StdioClientTransport({
|
|
21307
21604
|
command,
|
|
21308
21605
|
args: this.serverConfig.args,
|
|
21309
|
-
env:
|
|
21310
|
-
...getDefaultEnvironment(),
|
|
21311
|
-
...this.serverConfig.env || {}
|
|
21312
|
-
},
|
|
21606
|
+
env: this.buildStdioEnv(),
|
|
21313
21607
|
stderr: this.serverConfig.stderr,
|
|
21314
21608
|
cwd: this.serverConfig.cwd
|
|
21315
21609
|
});
|
|
@@ -21321,10 +21615,16 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21321
21615
|
}
|
|
21322
21616
|
}
|
|
21323
21617
|
async connectHttp(url) {
|
|
21324
|
-
const { requestInit, eventSourceInit, authProvider, connectTimeout, fetch: userFetch } = this.serverConfig;
|
|
21618
|
+
const { requestInit, eventSourceInit, authProvider, connectTimeout, fetch: userFetch, allowedHosts } = this.serverConfig;
|
|
21619
|
+
if (allowedHosts !== void 0) assertHostAllowed(url, allowedHosts);
|
|
21620
|
+
const policyUserFetch = userFetch && allowedHosts !== void 0 ? wrapFetchWithHostPolicy(userFetch, allowedHosts) : void 0;
|
|
21325
21621
|
const fetch = (requestUrl, init) => {
|
|
21326
21622
|
const requestContext = this.operationContextStore.getStore() ?? null;
|
|
21327
|
-
const executeFetch = () =>
|
|
21623
|
+
const executeFetch = () => {
|
|
21624
|
+
if (allowedHosts === void 0) return userFetch ? userFetch(requestUrl, init, requestContext) : globalThis.fetch(requestUrl, init);
|
|
21625
|
+
if (policyUserFetch) return policyUserFetch(requestUrl, init, requestContext);
|
|
21626
|
+
return fetchFollowingAllowedRedirects((u, i) => globalThis.fetch(u, i), requestUrl, init, allowedHosts);
|
|
21627
|
+
};
|
|
21328
21628
|
return shouldDetachPersistentTransportRequest(init) ? runOutsideDatadogTraceScope(executeFetch) : executeFetch();
|
|
21329
21629
|
};
|
|
21330
21630
|
this.log("debug", `Attempting to connect to URL: ${url}`);
|
|
@@ -21347,7 +21647,8 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21347
21647
|
this.markNeedsAuth(streamableTransport);
|
|
21348
21648
|
throw error;
|
|
21349
21649
|
}
|
|
21350
|
-
|
|
21650
|
+
if (isUrlPolicyError(error)) throw error;
|
|
21651
|
+
const status = error instanceof SdkHttpError ? error.status : void 0;
|
|
21351
21652
|
if (status !== void 0 && !SSE_FALLBACK_STATUS_CODES.includes(status)) throw error;
|
|
21352
21653
|
shouldTrySSE = true;
|
|
21353
21654
|
}
|
|
@@ -21355,11 +21656,12 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21355
21656
|
if (shouldTrySSE) {
|
|
21356
21657
|
await this.detachStaleClientTransport();
|
|
21357
21658
|
this.log("debug", "Falling back to deprecated HTTP+SSE transport...");
|
|
21659
|
+
const callerSseFetch = eventSourceInit?.fetch;
|
|
21358
21660
|
const sseTransport = new SSEClientTransport(url, {
|
|
21359
21661
|
requestInit,
|
|
21360
21662
|
eventSourceInit: {
|
|
21361
21663
|
...eventSourceInit,
|
|
21362
|
-
fetch:
|
|
21664
|
+
fetch: callerSseFetch && allowedHosts !== void 0 ? wrapFetchWithHostPolicy(callerSseFetch, allowedHosts) : callerSseFetch ?? fetch
|
|
21363
21665
|
},
|
|
21364
21666
|
authProvider,
|
|
21365
21667
|
fetch
|
|
@@ -21373,6 +21675,7 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21373
21675
|
this.markNeedsAuth(sseTransport);
|
|
21374
21676
|
throw sseError;
|
|
21375
21677
|
}
|
|
21678
|
+
if (isUrlPolicyError(sseError)) throw sseError;
|
|
21376
21679
|
this.log("error", `Failed to connect with SSE transport after failing to connect to Streamable HTTP transport first. SSE error: ${sseError}`);
|
|
21377
21680
|
throw new Error("Could not connect to server with any available HTTP transport");
|
|
21378
21681
|
}
|
|
@@ -21665,39 +21968,39 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21665
21968
|
}
|
|
21666
21969
|
async listResources() {
|
|
21667
21970
|
this.log("debug", `Requesting resources from MCP server`);
|
|
21668
|
-
return await this.client.request({ method: "resources/list" },
|
|
21971
|
+
return await this.client.request({ method: "resources/list" }, { timeout: this.timeout });
|
|
21669
21972
|
}
|
|
21670
21973
|
async readResource(uri) {
|
|
21671
21974
|
this.log("debug", `Reading resource from MCP server: ${uri}`);
|
|
21672
21975
|
return await this.client.request({
|
|
21673
21976
|
method: "resources/read",
|
|
21674
21977
|
params: { uri }
|
|
21675
|
-
},
|
|
21978
|
+
}, { timeout: this.timeout });
|
|
21676
21979
|
}
|
|
21677
21980
|
async subscribeResource(uri) {
|
|
21678
21981
|
this.log("debug", `Subscribing to resource on MCP server: ${uri}`);
|
|
21679
21982
|
return await this.client.request({
|
|
21680
21983
|
method: "resources/subscribe",
|
|
21681
21984
|
params: { uri }
|
|
21682
|
-
},
|
|
21985
|
+
}, { timeout: this.timeout });
|
|
21683
21986
|
}
|
|
21684
21987
|
async unsubscribeResource(uri) {
|
|
21685
21988
|
this.log("debug", `Unsubscribing from resource on MCP server: ${uri}`);
|
|
21686
21989
|
return await this.client.request({
|
|
21687
21990
|
method: "resources/unsubscribe",
|
|
21688
21991
|
params: { uri }
|
|
21689
|
-
},
|
|
21992
|
+
}, { timeout: this.timeout });
|
|
21690
21993
|
}
|
|
21691
21994
|
async listResourceTemplates() {
|
|
21692
21995
|
this.log("debug", `Requesting resource templates from MCP server`);
|
|
21693
|
-
return await this.client.request({ method: "resources/templates/list" },
|
|
21996
|
+
return await this.client.request({ method: "resources/templates/list" }, { timeout: this.timeout });
|
|
21694
21997
|
}
|
|
21695
21998
|
/**
|
|
21696
21999
|
* Fetch the list of available prompts from the MCP server.
|
|
21697
22000
|
*/
|
|
21698
22001
|
async listPrompts() {
|
|
21699
22002
|
this.log("debug", `Requesting prompts from MCP server`);
|
|
21700
|
-
return await this.client.request({ method: "prompts/list" },
|
|
22003
|
+
return await this.client.request({ method: "prompts/list" }, { timeout: this.timeout });
|
|
21701
22004
|
}
|
|
21702
22005
|
/**
|
|
21703
22006
|
* Get a prompt and its dynamic messages from the server.
|
|
@@ -21712,7 +22015,7 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21712
22015
|
name,
|
|
21713
22016
|
arguments: args
|
|
21714
22017
|
}
|
|
21715
|
-
},
|
|
22018
|
+
}, { timeout: this.timeout });
|
|
21716
22019
|
}
|
|
21717
22020
|
/**
|
|
21718
22021
|
* Register a handler to be called when the prompt list changes on the server.
|
|
@@ -21720,7 +22023,7 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21720
22023
|
*/
|
|
21721
22024
|
setPromptListChangedNotificationHandler(handler) {
|
|
21722
22025
|
this.log("debug", "Setting prompt list changed notification handler");
|
|
21723
|
-
this.client.setNotificationHandler(
|
|
22026
|
+
this.client.setNotificationHandler("notifications/prompts/list_changed", () => {
|
|
21724
22027
|
handler();
|
|
21725
22028
|
});
|
|
21726
22029
|
}
|
|
@@ -21730,19 +22033,19 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21730
22033
|
*/
|
|
21731
22034
|
setToolListChangedNotificationHandler(handler) {
|
|
21732
22035
|
this.log("debug", "Setting tool list changed notification handler");
|
|
21733
|
-
this.client.setNotificationHandler(
|
|
22036
|
+
this.client.setNotificationHandler("notifications/tools/list_changed", () => {
|
|
21734
22037
|
handler();
|
|
21735
22038
|
});
|
|
21736
22039
|
}
|
|
21737
22040
|
setResourceUpdatedNotificationHandler(handler) {
|
|
21738
22041
|
this.log("debug", "Setting resource updated notification handler");
|
|
21739
|
-
this.client.setNotificationHandler(
|
|
22042
|
+
this.client.setNotificationHandler("notifications/resources/updated", (notification) => {
|
|
21740
22043
|
handler(notification.params);
|
|
21741
22044
|
});
|
|
21742
22045
|
}
|
|
21743
22046
|
setResourceListChangedNotificationHandler(handler) {
|
|
21744
22047
|
this.log("debug", "Setting resource list changed notification handler");
|
|
21745
|
-
this.client.setNotificationHandler(
|
|
22048
|
+
this.client.setNotificationHandler("notifications/resources/list_changed", () => {
|
|
21746
22049
|
handler();
|
|
21747
22050
|
});
|
|
21748
22051
|
}
|
|
@@ -21754,14 +22057,14 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21754
22057
|
} catch (error) {
|
|
21755
22058
|
throw new Error("Cannot register an elicitation handler after connecting unless elicitation capability was configured before initialization.", { cause: error });
|
|
21756
22059
|
}
|
|
21757
|
-
this.client.setRequestHandler(
|
|
22060
|
+
this.client.setRequestHandler("elicitation/create", async (request) => {
|
|
21758
22061
|
this.log("debug", `Received elicitation request: ${request.params.message}`);
|
|
21759
22062
|
return handler(request.params);
|
|
21760
22063
|
});
|
|
21761
22064
|
}
|
|
21762
22065
|
setProgressNotificationHandler(handler) {
|
|
21763
22066
|
this.log("debug", "Setting progress notification handler");
|
|
21764
|
-
this.client.setNotificationHandler(
|
|
22067
|
+
this.client.setNotificationHandler("notifications/progress", (notification) => {
|
|
21765
22068
|
handler(notification.params);
|
|
21766
22069
|
});
|
|
21767
22070
|
}
|
|
@@ -21769,7 +22072,7 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21769
22072
|
return "jsonSchema" in inputSchema ? inputSchema.jsonSchema : inputSchema;
|
|
21770
22073
|
}
|
|
21771
22074
|
/**
|
|
21772
|
-
* Wraps the output schema with a validator that always succeeds. The MCP
|
|
22075
|
+
* Wraps the output schema with a validator that always succeeds. The MCP client validates
|
|
21773
22076
|
* structuredContent via AJV; the JSON schema is surfaced here for documentation only.
|
|
21774
22077
|
*/
|
|
21775
22078
|
convertOutputSchema(outputSchema) {
|
|
@@ -21841,7 +22144,7 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
21841
22144
|
name: tool.name,
|
|
21842
22145
|
arguments: input,
|
|
21843
22146
|
...combinedMeta ? { _meta: combinedMeta } : {}
|
|
21844
|
-
},
|
|
22147
|
+
}, {
|
|
21845
22148
|
timeout: this.timeout,
|
|
21846
22149
|
signal: context?.abortSignal
|
|
21847
22150
|
});
|
|
@@ -23783,162 +24086,1993 @@ var streamSSE = (c, cb, onError) => {
|
|
|
23783
24086
|
return c.newResponse(stream.responseReadable);
|
|
23784
24087
|
};
|
|
23785
24088
|
//#endregion
|
|
23786
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links
|
|
23787
|
-
const
|
|
23788
|
-
var SSETransport = class {
|
|
23789
|
-
messageUrl;
|
|
23790
|
-
stream;
|
|
23791
|
-
_sessionId;
|
|
23792
|
-
onclose;
|
|
23793
|
-
onerror;
|
|
23794
|
-
onmessage;
|
|
23795
|
-
/**
|
|
23796
|
-
* Creates a new SSETransport, which will direct the MPC client to POST messages to messageUrl
|
|
23797
|
-
*/
|
|
23798
|
-
constructor(messageUrl, stream) {
|
|
23799
|
-
this.messageUrl = messageUrl;
|
|
23800
|
-
this.stream = stream;
|
|
23801
|
-
this._sessionId = crypto.randomUUID();
|
|
23802
|
-
this.stream.onAbort(() => {
|
|
23803
|
-
this.close();
|
|
23804
|
-
});
|
|
23805
|
-
}
|
|
23806
|
-
get sessionId() {
|
|
23807
|
-
return this._sessionId;
|
|
23808
|
-
}
|
|
23809
|
-
async start() {
|
|
23810
|
-
if (this.stream == null) throw new Error("Stream not initialized");
|
|
23811
|
-
if (this.stream.closed) throw new Error("SSE transport already closed!");
|
|
23812
|
-
await this.stream.writeSSE({
|
|
23813
|
-
event: "ping",
|
|
23814
|
-
data: ""
|
|
23815
|
-
});
|
|
23816
|
-
await this.stream.writeSSE({
|
|
23817
|
-
event: "endpoint",
|
|
23818
|
-
data: `${this.messageUrl}?sessionId=${this.sessionId}`
|
|
23819
|
-
});
|
|
23820
|
-
}
|
|
23821
|
-
async handlePostMessage(context) {
|
|
23822
|
-
if (this.stream?.closed == null) return context.text("SSE connection not established", 500);
|
|
23823
|
-
try {
|
|
23824
|
-
const contentType = context.req.header("content-type") || "";
|
|
23825
|
-
if (!contentType.includes("application/json")) throw new Error(`Unsupported content-type: ${contentType}`);
|
|
23826
|
-
const contentLength = Number.parseInt(context.req.header("content-length") || "0", 10);
|
|
23827
|
-
if (contentLength > MAXIMUM_MESSAGE_SIZE) throw new Error(`Request body too large: ${contentLength} bytes`);
|
|
23828
|
-
const body = await context.req.json();
|
|
23829
|
-
await this.handleMessage(body);
|
|
23830
|
-
return context.text("Accepted", 202);
|
|
23831
|
-
} catch (error) {
|
|
23832
|
-
this.onerror?.(error);
|
|
23833
|
-
return context.text("Error", 400);
|
|
23834
|
-
}
|
|
23835
|
-
}
|
|
23836
|
-
/**
|
|
23837
|
-
* 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.
|
|
23838
|
-
*/
|
|
23839
|
-
async handleMessage(message) {
|
|
23840
|
-
let parsedMessage;
|
|
23841
|
-
try {
|
|
23842
|
-
parsedMessage = JSONRPCMessageSchema.parse(message);
|
|
23843
|
-
} catch (error) {
|
|
23844
|
-
this.onerror?.(error);
|
|
23845
|
-
throw error;
|
|
23846
|
-
}
|
|
23847
|
-
this.onmessage?.(parsedMessage);
|
|
23848
|
-
}
|
|
23849
|
-
async close() {
|
|
23850
|
-
if (this.stream?.closed) this.stream.abort();
|
|
23851
|
-
}
|
|
23852
|
-
async send(message) {
|
|
23853
|
-
if (this.stream?.closed) throw new Error("Not connected");
|
|
23854
|
-
await this.stream.writeSSE({
|
|
23855
|
-
event: "message",
|
|
23856
|
-
data: JSON.stringify(message)
|
|
23857
|
-
});
|
|
23858
|
-
}
|
|
23859
|
-
};
|
|
23860
|
-
//#endregion
|
|
23861
|
-
//#region src/server/notificationBroadcast.ts
|
|
24089
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@modelcontextprotocol/sdk/1.29.0/989ce0cb833930f9ef8da3e25bac11110cfeac46669bc69ae9534a6aa55b0aa7/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
24090
|
+
const RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
23862
24091
|
/**
|
|
23863
|
-
*
|
|
23864
|
-
* instance plus each streamable HTTP session instance).
|
|
23865
|
-
*
|
|
23866
|
-
* Failures are aggregated: if only some instances fail, the failure is logged
|
|
23867
|
-
* and the broadcast is considered best-effort. A `MastraError` is thrown only
|
|
23868
|
-
* when every send fails.
|
|
23869
|
-
*
|
|
23870
|
-
* Note: clients connected in stateless/serverless mode cannot receive
|
|
23871
|
-
* notifications because each request uses a transient server instance.
|
|
24092
|
+
* Assert 'object' type schema.
|
|
23872
24093
|
*
|
|
23873
24094
|
* @internal
|
|
23874
24095
|
*/
|
|
23875
|
-
|
|
23876
|
-
const errors = [];
|
|
23877
|
-
for (const server of servers) try {
|
|
23878
|
-
await send(server);
|
|
23879
|
-
} catch (error) {
|
|
23880
|
-
errors.push(error);
|
|
23881
|
-
}
|
|
23882
|
-
if (errors.length === 0) return;
|
|
23883
|
-
const mastraError = new MastraError({
|
|
23884
|
-
id: errorId,
|
|
23885
|
-
domain: ErrorDomain.MCP,
|
|
23886
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
23887
|
-
text: errorText,
|
|
23888
|
-
details: {
|
|
23889
|
-
...errorDetails,
|
|
23890
|
-
failedInstances: errors.length,
|
|
23891
|
-
totalInstances: servers.length
|
|
23892
|
-
}
|
|
23893
|
-
}, errors[0]);
|
|
23894
|
-
logger.error(`${errorText}:`, { error: mastraError.toString() });
|
|
23895
|
-
if (errors.length === servers.length) {
|
|
23896
|
-
logger.trackException(mastraError);
|
|
23897
|
-
throw mastraError;
|
|
23898
|
-
}
|
|
23899
|
-
}
|
|
23900
|
-
//#endregion
|
|
23901
|
-
//#region src/server/promptActions.ts
|
|
24096
|
+
const AssertObjectSchema = custom$1((v) => v !== null && (typeof v === "object" || typeof v === "function"));
|
|
23902
24097
|
/**
|
|
23903
|
-
*
|
|
23904
|
-
*
|
|
23905
|
-
* This class provides methods for MCP servers to notify connected clients when
|
|
23906
|
-
* the list of available prompts changes.
|
|
23907
|
-
*
|
|
23908
|
-
* Notifications are broadcast to every active server instance (the main
|
|
23909
|
-
* stdio/SSE instance plus each streamable HTTP session). Clients connected in
|
|
23910
|
-
* stateless/serverless mode cannot receive notifications because each request
|
|
23911
|
-
* uses a transient server instance.
|
|
24098
|
+
* A progress token, used to associate progress notifications with the original request.
|
|
23912
24099
|
*/
|
|
23913
|
-
|
|
23914
|
-
|
|
23915
|
-
|
|
23916
|
-
|
|
24100
|
+
const ProgressTokenSchema = union([string(), number().int()]);
|
|
24101
|
+
/**
|
|
24102
|
+
* An opaque token used to represent a cursor for pagination.
|
|
24103
|
+
*/
|
|
24104
|
+
const CursorSchema = string();
|
|
24105
|
+
looseObject({
|
|
23917
24106
|
/**
|
|
23918
|
-
*
|
|
24107
|
+
* Requested duration in milliseconds to retain task from creation.
|
|
23919
24108
|
*/
|
|
23920
|
-
|
|
23921
|
-
this.getLogger = dependencies.getLogger;
|
|
23922
|
-
this.getSdkServers = dependencies.getSdkServers;
|
|
23923
|
-
this.clearDefinedPrompts = dependencies.clearDefinedPrompts;
|
|
23924
|
-
}
|
|
24109
|
+
ttl: number().optional(),
|
|
23925
24110
|
/**
|
|
23926
|
-
*
|
|
23927
|
-
*
|
|
23928
|
-
* This clears the internal prompt cache and sends a `notifications/prompts/list_changed`
|
|
23929
|
-
* message to all clients, prompting them to re-fetch the prompt list.
|
|
23930
|
-
*
|
|
23931
|
-
* @throws {MastraError} If sending the notification fails on all server instances
|
|
23932
|
-
*
|
|
23933
|
-
* @example
|
|
23934
|
-
* ```typescript
|
|
23935
|
-
* // After adding or modifying prompts
|
|
23936
|
-
* await server.prompts.notifyListChanged();
|
|
23937
|
-
* ```
|
|
24111
|
+
* Time in milliseconds to wait between task status requests.
|
|
23938
24112
|
*/
|
|
23939
|
-
|
|
23940
|
-
|
|
23941
|
-
|
|
24113
|
+
pollInterval: number().optional()
|
|
24114
|
+
});
|
|
24115
|
+
const TaskMetadataSchema = object$1({ ttl: number().optional() });
|
|
24116
|
+
/**
|
|
24117
|
+
* Metadata for associating messages with a task.
|
|
24118
|
+
* Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
|
|
24119
|
+
*/
|
|
24120
|
+
const RelatedTaskMetadataSchema = object$1({ taskId: string() });
|
|
24121
|
+
const RequestMetaSchema = looseObject({
|
|
24122
|
+
/**
|
|
24123
|
+
* 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.
|
|
24124
|
+
*/
|
|
24125
|
+
progressToken: ProgressTokenSchema.optional(),
|
|
24126
|
+
/**
|
|
24127
|
+
* If specified, this request is related to the provided task.
|
|
24128
|
+
*/
|
|
24129
|
+
[RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
|
|
24130
|
+
});
|
|
24131
|
+
/**
|
|
24132
|
+
* Common params for any request.
|
|
24133
|
+
*/
|
|
24134
|
+
const BaseRequestParamsSchema = object$1({
|
|
24135
|
+
/**
|
|
24136
|
+
* See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
|
|
24137
|
+
*/
|
|
24138
|
+
_meta: RequestMetaSchema.optional() });
|
|
24139
|
+
/**
|
|
24140
|
+
* Common params for any task-augmented request.
|
|
24141
|
+
*/
|
|
24142
|
+
const TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24143
|
+
/**
|
|
24144
|
+
* If specified, the caller is requesting task-augmented execution for this request.
|
|
24145
|
+
* The request will return a CreateTaskResult immediately, and the actual result can be
|
|
24146
|
+
* retrieved later via tasks/result.
|
|
24147
|
+
*
|
|
24148
|
+
* Task augmentation is subject to capability negotiation - receivers MUST declare support
|
|
24149
|
+
* for task augmentation of specific request types in their capabilities.
|
|
24150
|
+
*/
|
|
24151
|
+
task: TaskMetadataSchema.optional() });
|
|
24152
|
+
const RequestSchema = object$1({
|
|
24153
|
+
method: string(),
|
|
24154
|
+
params: BaseRequestParamsSchema.loose().optional()
|
|
24155
|
+
});
|
|
24156
|
+
const NotificationsParamsSchema = object$1({
|
|
24157
|
+
/**
|
|
24158
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24159
|
+
* for notes on _meta usage.
|
|
24160
|
+
*/
|
|
24161
|
+
_meta: RequestMetaSchema.optional() });
|
|
24162
|
+
const NotificationSchema = object$1({
|
|
24163
|
+
method: string(),
|
|
24164
|
+
params: NotificationsParamsSchema.loose().optional()
|
|
24165
|
+
});
|
|
24166
|
+
const ResultSchema = looseObject({
|
|
24167
|
+
/**
|
|
24168
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24169
|
+
* for notes on _meta usage.
|
|
24170
|
+
*/
|
|
24171
|
+
_meta: RequestMetaSchema.optional() });
|
|
24172
|
+
/**
|
|
24173
|
+
* A uniquely identifying ID for a request in JSON-RPC.
|
|
24174
|
+
*/
|
|
24175
|
+
const RequestIdSchema = union([string(), number().int()]);
|
|
24176
|
+
/**
|
|
24177
|
+
* A request that expects a response.
|
|
24178
|
+
*/
|
|
24179
|
+
const JSONRPCRequestSchema = object$1({
|
|
24180
|
+
jsonrpc: literal("2.0"),
|
|
24181
|
+
id: RequestIdSchema,
|
|
24182
|
+
...RequestSchema.shape
|
|
24183
|
+
}).strict();
|
|
24184
|
+
/**
|
|
24185
|
+
* A notification which does not expect a response.
|
|
24186
|
+
*/
|
|
24187
|
+
const JSONRPCNotificationSchema = object$1({
|
|
24188
|
+
jsonrpc: literal("2.0"),
|
|
24189
|
+
...NotificationSchema.shape
|
|
24190
|
+
}).strict();
|
|
24191
|
+
/**
|
|
24192
|
+
* A successful (non-error) response to a request.
|
|
24193
|
+
*/
|
|
24194
|
+
const JSONRPCResultResponseSchema = object$1({
|
|
24195
|
+
jsonrpc: literal("2.0"),
|
|
24196
|
+
id: RequestIdSchema,
|
|
24197
|
+
result: ResultSchema
|
|
24198
|
+
}).strict();
|
|
24199
|
+
/**
|
|
24200
|
+
* Error codes defined by the JSON-RPC specification.
|
|
24201
|
+
*/
|
|
24202
|
+
var ErrorCode;
|
|
24203
|
+
(function(ErrorCode) {
|
|
24204
|
+
ErrorCode[ErrorCode["ConnectionClosed"] = -32e3] = "ConnectionClosed";
|
|
24205
|
+
ErrorCode[ErrorCode["RequestTimeout"] = -32001] = "RequestTimeout";
|
|
24206
|
+
ErrorCode[ErrorCode["ParseError"] = -32700] = "ParseError";
|
|
24207
|
+
ErrorCode[ErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
24208
|
+
ErrorCode[ErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
24209
|
+
ErrorCode[ErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
24210
|
+
ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError";
|
|
24211
|
+
ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
|
|
24212
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
24213
|
+
/**
|
|
24214
|
+
* A response to a request that indicates an error occurred.
|
|
24215
|
+
*/
|
|
24216
|
+
const JSONRPCErrorResponseSchema = object$1({
|
|
24217
|
+
jsonrpc: literal("2.0"),
|
|
24218
|
+
id: RequestIdSchema.optional(),
|
|
24219
|
+
error: object$1({
|
|
24220
|
+
/**
|
|
24221
|
+
* The error type that occurred.
|
|
24222
|
+
*/
|
|
24223
|
+
code: number().int(),
|
|
24224
|
+
/**
|
|
24225
|
+
* A short description of the error. The message SHOULD be limited to a concise single sentence.
|
|
24226
|
+
*/
|
|
24227
|
+
message: string(),
|
|
24228
|
+
/**
|
|
24229
|
+
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
24230
|
+
*/
|
|
24231
|
+
data: unknown().optional()
|
|
24232
|
+
})
|
|
24233
|
+
}).strict();
|
|
24234
|
+
const JSONRPCMessageSchema = union([
|
|
24235
|
+
JSONRPCRequestSchema,
|
|
24236
|
+
JSONRPCNotificationSchema,
|
|
24237
|
+
JSONRPCResultResponseSchema,
|
|
24238
|
+
JSONRPCErrorResponseSchema
|
|
24239
|
+
]);
|
|
24240
|
+
union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
|
|
24241
|
+
/**
|
|
24242
|
+
* A response that indicates success but carries no data.
|
|
24243
|
+
*/
|
|
24244
|
+
const EmptyResultSchema = ResultSchema.strict();
|
|
24245
|
+
const CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
24246
|
+
/**
|
|
24247
|
+
* The ID of the request to cancel.
|
|
24248
|
+
*
|
|
24249
|
+
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
24250
|
+
*/
|
|
24251
|
+
requestId: RequestIdSchema.optional(),
|
|
24252
|
+
/**
|
|
24253
|
+
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
24254
|
+
*/
|
|
24255
|
+
reason: string().optional()
|
|
24256
|
+
});
|
|
24257
|
+
/**
|
|
24258
|
+
* This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
|
|
24259
|
+
*
|
|
24260
|
+
* 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.
|
|
24261
|
+
*
|
|
24262
|
+
* This notification indicates that the result will be unused, so any associated processing SHOULD cease.
|
|
24263
|
+
*
|
|
24264
|
+
* A client MUST NOT attempt to cancel its `initialize` request.
|
|
24265
|
+
*/
|
|
24266
|
+
const CancelledNotificationSchema = NotificationSchema.extend({
|
|
24267
|
+
method: literal("notifications/cancelled"),
|
|
24268
|
+
params: CancelledNotificationParamsSchema
|
|
24269
|
+
});
|
|
24270
|
+
/**
|
|
24271
|
+
* Base schema to add `icons` property.
|
|
24272
|
+
*
|
|
24273
|
+
*/
|
|
24274
|
+
const IconsSchema = object$1({
|
|
24275
|
+
/**
|
|
24276
|
+
* Optional set of sized icons that the client can display in a user interface.
|
|
24277
|
+
*
|
|
24278
|
+
* Clients that support rendering icons MUST support at least the following MIME types:
|
|
24279
|
+
* - `image/png` - PNG images (safe, universal compatibility)
|
|
24280
|
+
* - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
|
|
24281
|
+
*
|
|
24282
|
+
* Clients that support rendering icons SHOULD also support:
|
|
24283
|
+
* - `image/svg+xml` - SVG images (scalable but requires security precautions)
|
|
24284
|
+
* - `image/webp` - WebP images (modern, efficient format)
|
|
24285
|
+
*/
|
|
24286
|
+
icons: array(object$1({
|
|
24287
|
+
/**
|
|
24288
|
+
* URL or data URI for the icon.
|
|
24289
|
+
*/
|
|
24290
|
+
src: string(),
|
|
24291
|
+
/**
|
|
24292
|
+
* Optional MIME type for the icon.
|
|
24293
|
+
*/
|
|
24294
|
+
mimeType: string().optional(),
|
|
24295
|
+
/**
|
|
24296
|
+
* Optional array of strings that specify sizes at which the icon can be used.
|
|
24297
|
+
* Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
|
|
24298
|
+
*
|
|
24299
|
+
* If not provided, the client should assume that the icon can be used at any size.
|
|
24300
|
+
*/
|
|
24301
|
+
sizes: array(string()).optional(),
|
|
24302
|
+
/**
|
|
24303
|
+
* Optional specifier for the theme this icon is designed for. `light` indicates
|
|
24304
|
+
* the icon is designed to be used with a light background, and `dark` indicates
|
|
24305
|
+
* the icon is designed to be used with a dark background.
|
|
24306
|
+
*
|
|
24307
|
+
* If not provided, the client should assume the icon can be used with any theme.
|
|
24308
|
+
*/
|
|
24309
|
+
theme: _enum(["light", "dark"]).optional()
|
|
24310
|
+
})).optional() });
|
|
24311
|
+
/**
|
|
24312
|
+
* Base metadata interface for common properties across resources, tools, prompts, and implementations.
|
|
24313
|
+
*/
|
|
24314
|
+
const BaseMetadataSchema = object$1({
|
|
24315
|
+
/** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
|
|
24316
|
+
name: string(),
|
|
24317
|
+
/**
|
|
24318
|
+
* Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
|
|
24319
|
+
* even by those unfamiliar with domain-specific terminology.
|
|
24320
|
+
*
|
|
24321
|
+
* If not provided, the name should be used for display (except for Tool,
|
|
24322
|
+
* where `annotations.title` should be given precedence over using `name`,
|
|
24323
|
+
* if present).
|
|
24324
|
+
*/
|
|
24325
|
+
title: string().optional()
|
|
24326
|
+
});
|
|
24327
|
+
/**
|
|
24328
|
+
* Describes the name and version of an MCP implementation.
|
|
24329
|
+
*/
|
|
24330
|
+
const ImplementationSchema = BaseMetadataSchema.extend({
|
|
24331
|
+
...BaseMetadataSchema.shape,
|
|
24332
|
+
...IconsSchema.shape,
|
|
24333
|
+
version: string(),
|
|
24334
|
+
/**
|
|
24335
|
+
* An optional URL of the website for this implementation.
|
|
24336
|
+
*/
|
|
24337
|
+
websiteUrl: string().optional(),
|
|
24338
|
+
/**
|
|
24339
|
+
* An optional human-readable description of what this implementation does.
|
|
24340
|
+
*
|
|
24341
|
+
* This can be used by clients or servers to provide context about their purpose
|
|
24342
|
+
* and capabilities. For example, a server might describe the types of resources
|
|
24343
|
+
* or tools it provides, while a client might describe its intended use case.
|
|
24344
|
+
*/
|
|
24345
|
+
description: string().optional()
|
|
24346
|
+
});
|
|
24347
|
+
const ElicitationCapabilitySchema = preprocess((value) => {
|
|
24348
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
24349
|
+
if (Object.keys(value).length === 0) return { form: {} };
|
|
24350
|
+
}
|
|
24351
|
+
return value;
|
|
24352
|
+
}, intersection(object$1({
|
|
24353
|
+
form: intersection(object$1({ applyDefaults: boolean().optional() }), record(string(), unknown())).optional(),
|
|
24354
|
+
url: AssertObjectSchema.optional()
|
|
24355
|
+
}), record(string(), unknown()).optional()));
|
|
24356
|
+
/**
|
|
24357
|
+
* Task capabilities for clients, indicating which request types support task creation.
|
|
24358
|
+
*/
|
|
24359
|
+
const ClientTasksCapabilitySchema = looseObject({
|
|
24360
|
+
/**
|
|
24361
|
+
* Present if the client supports listing tasks.
|
|
24362
|
+
*/
|
|
24363
|
+
list: AssertObjectSchema.optional(),
|
|
24364
|
+
/**
|
|
24365
|
+
* Present if the client supports cancelling tasks.
|
|
24366
|
+
*/
|
|
24367
|
+
cancel: AssertObjectSchema.optional(),
|
|
24368
|
+
/**
|
|
24369
|
+
* Capabilities for task creation on specific request types.
|
|
24370
|
+
*/
|
|
24371
|
+
requests: looseObject({
|
|
24372
|
+
/**
|
|
24373
|
+
* Task support for sampling requests.
|
|
24374
|
+
*/
|
|
24375
|
+
sampling: looseObject({ createMessage: AssertObjectSchema.optional() }).optional(),
|
|
24376
|
+
/**
|
|
24377
|
+
* Task support for elicitation requests.
|
|
24378
|
+
*/
|
|
24379
|
+
elicitation: looseObject({ create: AssertObjectSchema.optional() }).optional()
|
|
24380
|
+
}).optional()
|
|
24381
|
+
});
|
|
24382
|
+
/**
|
|
24383
|
+
* Task capabilities for servers, indicating which request types support task creation.
|
|
24384
|
+
*/
|
|
24385
|
+
const ServerTasksCapabilitySchema = looseObject({
|
|
24386
|
+
/**
|
|
24387
|
+
* Present if the server supports listing tasks.
|
|
24388
|
+
*/
|
|
24389
|
+
list: AssertObjectSchema.optional(),
|
|
24390
|
+
/**
|
|
24391
|
+
* Present if the server supports cancelling tasks.
|
|
24392
|
+
*/
|
|
24393
|
+
cancel: AssertObjectSchema.optional(),
|
|
24394
|
+
/**
|
|
24395
|
+
* Capabilities for task creation on specific request types.
|
|
24396
|
+
*/
|
|
24397
|
+
requests: looseObject({
|
|
24398
|
+
/**
|
|
24399
|
+
* Task support for tool requests.
|
|
24400
|
+
*/
|
|
24401
|
+
tools: looseObject({ call: AssertObjectSchema.optional() }).optional() }).optional()
|
|
24402
|
+
});
|
|
24403
|
+
/**
|
|
24404
|
+
* 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.
|
|
24405
|
+
*/
|
|
24406
|
+
const ClientCapabilitiesSchema = object$1({
|
|
24407
|
+
/**
|
|
24408
|
+
* Experimental, non-standard capabilities that the client supports.
|
|
24409
|
+
*/
|
|
24410
|
+
experimental: record(string(), AssertObjectSchema).optional(),
|
|
24411
|
+
/**
|
|
24412
|
+
* Present if the client supports sampling from an LLM.
|
|
24413
|
+
*/
|
|
24414
|
+
sampling: object$1({
|
|
24415
|
+
/**
|
|
24416
|
+
* Present if the client supports context inclusion via includeContext parameter.
|
|
24417
|
+
* If not declared, servers SHOULD only use `includeContext: "none"` (or omit it).
|
|
24418
|
+
*/
|
|
24419
|
+
context: AssertObjectSchema.optional(),
|
|
24420
|
+
/**
|
|
24421
|
+
* Present if the client supports tool use via tools and toolChoice parameters.
|
|
24422
|
+
*/
|
|
24423
|
+
tools: AssertObjectSchema.optional()
|
|
24424
|
+
}).optional(),
|
|
24425
|
+
/**
|
|
24426
|
+
* Present if the client supports eliciting user input.
|
|
24427
|
+
*/
|
|
24428
|
+
elicitation: ElicitationCapabilitySchema.optional(),
|
|
24429
|
+
/**
|
|
24430
|
+
* Present if the client supports listing roots.
|
|
24431
|
+
*/
|
|
24432
|
+
roots: object$1({
|
|
24433
|
+
/**
|
|
24434
|
+
* Whether the client supports issuing notifications for changes to the roots list.
|
|
24435
|
+
*/
|
|
24436
|
+
listChanged: boolean().optional() }).optional(),
|
|
24437
|
+
/**
|
|
24438
|
+
* Present if the client supports task creation.
|
|
24439
|
+
*/
|
|
24440
|
+
tasks: ClientTasksCapabilitySchema.optional(),
|
|
24441
|
+
/**
|
|
24442
|
+
* Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
|
|
24443
|
+
*/
|
|
24444
|
+
extensions: record(string(), AssertObjectSchema).optional()
|
|
24445
|
+
});
|
|
24446
|
+
const InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24447
|
+
/**
|
|
24448
|
+
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
|
|
24449
|
+
*/
|
|
24450
|
+
protocolVersion: string(),
|
|
24451
|
+
capabilities: ClientCapabilitiesSchema,
|
|
24452
|
+
clientInfo: ImplementationSchema
|
|
24453
|
+
});
|
|
24454
|
+
/**
|
|
24455
|
+
* This request is sent from the client to the server when it first connects, asking it to begin initialization.
|
|
24456
|
+
*/
|
|
24457
|
+
const InitializeRequestSchema = RequestSchema.extend({
|
|
24458
|
+
method: literal("initialize"),
|
|
24459
|
+
params: InitializeRequestParamsSchema
|
|
24460
|
+
});
|
|
24461
|
+
/**
|
|
24462
|
+
* 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.
|
|
24463
|
+
*/
|
|
24464
|
+
const ServerCapabilitiesSchema = object$1({
|
|
24465
|
+
/**
|
|
24466
|
+
* Experimental, non-standard capabilities that the server supports.
|
|
24467
|
+
*/
|
|
24468
|
+
experimental: record(string(), AssertObjectSchema).optional(),
|
|
24469
|
+
/**
|
|
24470
|
+
* Present if the server supports sending log messages to the client.
|
|
24471
|
+
*/
|
|
24472
|
+
logging: AssertObjectSchema.optional(),
|
|
24473
|
+
/**
|
|
24474
|
+
* Present if the server supports sending completions to the client.
|
|
24475
|
+
*/
|
|
24476
|
+
completions: AssertObjectSchema.optional(),
|
|
24477
|
+
/**
|
|
24478
|
+
* Present if the server offers any prompt templates.
|
|
24479
|
+
*/
|
|
24480
|
+
prompts: object$1({
|
|
24481
|
+
/**
|
|
24482
|
+
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
24483
|
+
*/
|
|
24484
|
+
listChanged: boolean().optional() }).optional(),
|
|
24485
|
+
/**
|
|
24486
|
+
* Present if the server offers any resources to read.
|
|
24487
|
+
*/
|
|
24488
|
+
resources: object$1({
|
|
24489
|
+
/**
|
|
24490
|
+
* Whether this server supports clients subscribing to resource updates.
|
|
24491
|
+
*/
|
|
24492
|
+
subscribe: boolean().optional(),
|
|
24493
|
+
/**
|
|
24494
|
+
* Whether this server supports issuing notifications for changes to the resource list.
|
|
24495
|
+
*/
|
|
24496
|
+
listChanged: boolean().optional()
|
|
24497
|
+
}).optional(),
|
|
24498
|
+
/**
|
|
24499
|
+
* Present if the server offers any tools to call.
|
|
24500
|
+
*/
|
|
24501
|
+
tools: object$1({
|
|
24502
|
+
/**
|
|
24503
|
+
* Whether this server supports issuing notifications for changes to the tool list.
|
|
24504
|
+
*/
|
|
24505
|
+
listChanged: boolean().optional() }).optional(),
|
|
24506
|
+
/**
|
|
24507
|
+
* Present if the server supports task creation.
|
|
24508
|
+
*/
|
|
24509
|
+
tasks: ServerTasksCapabilitySchema.optional(),
|
|
24510
|
+
/**
|
|
24511
|
+
* Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
|
|
24512
|
+
*/
|
|
24513
|
+
extensions: record(string(), AssertObjectSchema).optional()
|
|
24514
|
+
});
|
|
24515
|
+
/**
|
|
24516
|
+
* After receiving an initialize request from the client, the server sends this response.
|
|
24517
|
+
*/
|
|
24518
|
+
const InitializeResultSchema = ResultSchema.extend({
|
|
24519
|
+
/**
|
|
24520
|
+
* 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.
|
|
24521
|
+
*/
|
|
24522
|
+
protocolVersion: string(),
|
|
24523
|
+
capabilities: ServerCapabilitiesSchema,
|
|
24524
|
+
serverInfo: ImplementationSchema,
|
|
24525
|
+
/**
|
|
24526
|
+
* Instructions describing how to use the server and its features.
|
|
24527
|
+
*
|
|
24528
|
+
* 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.
|
|
24529
|
+
*/
|
|
24530
|
+
instructions: string().optional()
|
|
24531
|
+
});
|
|
24532
|
+
/**
|
|
24533
|
+
* This notification is sent from the client to the server after initialization has finished.
|
|
24534
|
+
*/
|
|
24535
|
+
const InitializedNotificationSchema = NotificationSchema.extend({
|
|
24536
|
+
method: literal("notifications/initialized"),
|
|
24537
|
+
params: NotificationsParamsSchema.optional()
|
|
24538
|
+
});
|
|
24539
|
+
/**
|
|
24540
|
+
* 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.
|
|
24541
|
+
*/
|
|
24542
|
+
const PingRequestSchema = RequestSchema.extend({
|
|
24543
|
+
method: literal("ping"),
|
|
24544
|
+
params: BaseRequestParamsSchema.optional()
|
|
24545
|
+
});
|
|
24546
|
+
const ProgressSchema = object$1({
|
|
24547
|
+
/**
|
|
24548
|
+
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
24549
|
+
*/
|
|
24550
|
+
progress: number(),
|
|
24551
|
+
/**
|
|
24552
|
+
* Total number of items to process (or total progress required), if known.
|
|
24553
|
+
*/
|
|
24554
|
+
total: optional(number()),
|
|
24555
|
+
/**
|
|
24556
|
+
* An optional message describing the current progress.
|
|
24557
|
+
*/
|
|
24558
|
+
message: optional(string())
|
|
24559
|
+
});
|
|
24560
|
+
const ProgressNotificationParamsSchema = object$1({
|
|
24561
|
+
...NotificationsParamsSchema.shape,
|
|
24562
|
+
...ProgressSchema.shape,
|
|
24563
|
+
/**
|
|
24564
|
+
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
|
|
24565
|
+
*/
|
|
24566
|
+
progressToken: ProgressTokenSchema
|
|
24567
|
+
});
|
|
24568
|
+
/**
|
|
24569
|
+
* An out-of-band notification used to inform the receiver of a progress update for a long-running request.
|
|
24570
|
+
*
|
|
24571
|
+
* @category notifications/progress
|
|
24572
|
+
*/
|
|
24573
|
+
const ProgressNotificationSchema = NotificationSchema.extend({
|
|
24574
|
+
method: literal("notifications/progress"),
|
|
24575
|
+
params: ProgressNotificationParamsSchema
|
|
24576
|
+
});
|
|
24577
|
+
const PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24578
|
+
/**
|
|
24579
|
+
* An opaque token representing the current pagination position.
|
|
24580
|
+
* If provided, the server should return results starting after this cursor.
|
|
24581
|
+
*/
|
|
24582
|
+
cursor: CursorSchema.optional() });
|
|
24583
|
+
const PaginatedRequestSchema = RequestSchema.extend({ params: PaginatedRequestParamsSchema.optional() });
|
|
24584
|
+
const PaginatedResultSchema = ResultSchema.extend({
|
|
24585
|
+
/**
|
|
24586
|
+
* An opaque token representing the pagination position after the last returned result.
|
|
24587
|
+
* If present, there may be more results available.
|
|
24588
|
+
*/
|
|
24589
|
+
nextCursor: CursorSchema.optional() });
|
|
24590
|
+
/**
|
|
24591
|
+
* The status of a task.
|
|
24592
|
+
* */
|
|
24593
|
+
const TaskStatusSchema = _enum([
|
|
24594
|
+
"working",
|
|
24595
|
+
"input_required",
|
|
24596
|
+
"completed",
|
|
24597
|
+
"failed",
|
|
24598
|
+
"cancelled"
|
|
24599
|
+
]);
|
|
24600
|
+
/**
|
|
24601
|
+
* A pollable state object associated with a request.
|
|
24602
|
+
*/
|
|
24603
|
+
const TaskSchema = object$1({
|
|
24604
|
+
taskId: string(),
|
|
24605
|
+
status: TaskStatusSchema,
|
|
24606
|
+
/**
|
|
24607
|
+
* Time in milliseconds to keep task results available after completion.
|
|
24608
|
+
* If null, the task has unlimited lifetime until manually cleaned up.
|
|
24609
|
+
*/
|
|
24610
|
+
ttl: union([number(), _null()]),
|
|
24611
|
+
/**
|
|
24612
|
+
* ISO 8601 timestamp when the task was created.
|
|
24613
|
+
*/
|
|
24614
|
+
createdAt: string(),
|
|
24615
|
+
/**
|
|
24616
|
+
* ISO 8601 timestamp when the task was last updated.
|
|
24617
|
+
*/
|
|
24618
|
+
lastUpdatedAt: string(),
|
|
24619
|
+
pollInterval: optional(number()),
|
|
24620
|
+
/**
|
|
24621
|
+
* Optional diagnostic message for failed tasks or other status information.
|
|
24622
|
+
*/
|
|
24623
|
+
statusMessage: optional(string())
|
|
24624
|
+
});
|
|
24625
|
+
/**
|
|
24626
|
+
* Result returned when a task is created, containing the task data wrapped in a task field.
|
|
24627
|
+
*/
|
|
24628
|
+
const CreateTaskResultSchema = ResultSchema.extend({ task: TaskSchema });
|
|
24629
|
+
/**
|
|
24630
|
+
* Parameters for task status notification.
|
|
24631
|
+
*/
|
|
24632
|
+
const TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
|
|
24633
|
+
/**
|
|
24634
|
+
* A notification sent when a task's status changes.
|
|
24635
|
+
*/
|
|
24636
|
+
const TaskStatusNotificationSchema = NotificationSchema.extend({
|
|
24637
|
+
method: literal("notifications/tasks/status"),
|
|
24638
|
+
params: TaskStatusNotificationParamsSchema
|
|
24639
|
+
});
|
|
24640
|
+
/**
|
|
24641
|
+
* A request to get the state of a specific task.
|
|
24642
|
+
*/
|
|
24643
|
+
const GetTaskRequestSchema = RequestSchema.extend({
|
|
24644
|
+
method: literal("tasks/get"),
|
|
24645
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
24646
|
+
});
|
|
24647
|
+
/**
|
|
24648
|
+
* The response to a tasks/get request.
|
|
24649
|
+
*/
|
|
24650
|
+
const GetTaskResultSchema = ResultSchema.merge(TaskSchema);
|
|
24651
|
+
/**
|
|
24652
|
+
* A request to get the result of a specific task.
|
|
24653
|
+
*/
|
|
24654
|
+
const GetTaskPayloadRequestSchema = RequestSchema.extend({
|
|
24655
|
+
method: literal("tasks/result"),
|
|
24656
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
24657
|
+
});
|
|
24658
|
+
ResultSchema.loose();
|
|
24659
|
+
/**
|
|
24660
|
+
* A request to list tasks.
|
|
24661
|
+
*/
|
|
24662
|
+
const ListTasksRequestSchema = PaginatedRequestSchema.extend({ method: literal("tasks/list") });
|
|
24663
|
+
/**
|
|
24664
|
+
* The response to a tasks/list request.
|
|
24665
|
+
*/
|
|
24666
|
+
const ListTasksResultSchema = PaginatedResultSchema.extend({ tasks: array(TaskSchema) });
|
|
24667
|
+
/**
|
|
24668
|
+
* A request to cancel a specific task.
|
|
24669
|
+
*/
|
|
24670
|
+
const CancelTaskRequestSchema = RequestSchema.extend({
|
|
24671
|
+
method: literal("tasks/cancel"),
|
|
24672
|
+
params: BaseRequestParamsSchema.extend({ taskId: string() })
|
|
24673
|
+
});
|
|
24674
|
+
ResultSchema.merge(TaskSchema);
|
|
24675
|
+
/**
|
|
24676
|
+
* The contents of a specific resource or sub-resource.
|
|
24677
|
+
*/
|
|
24678
|
+
const ResourceContentsSchema = object$1({
|
|
24679
|
+
/**
|
|
24680
|
+
* The URI of this resource.
|
|
24681
|
+
*/
|
|
24682
|
+
uri: string(),
|
|
24683
|
+
/**
|
|
24684
|
+
* The MIME type of this resource, if known.
|
|
24685
|
+
*/
|
|
24686
|
+
mimeType: optional(string()),
|
|
24687
|
+
/**
|
|
24688
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24689
|
+
* for notes on _meta usage.
|
|
24690
|
+
*/
|
|
24691
|
+
_meta: record(string(), unknown()).optional()
|
|
24692
|
+
});
|
|
24693
|
+
const TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
24694
|
+
/**
|
|
24695
|
+
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
|
|
24696
|
+
*/
|
|
24697
|
+
text: string() });
|
|
24698
|
+
/**
|
|
24699
|
+
* A Zod schema for validating Base64 strings that is more performant and
|
|
24700
|
+
* robust for very large inputs than the default regex-based check. It avoids
|
|
24701
|
+
* stack overflows by using the native `atob` function for validation.
|
|
24702
|
+
*/
|
|
24703
|
+
const Base64Schema = string().refine((val) => {
|
|
24704
|
+
try {
|
|
24705
|
+
atob(val);
|
|
24706
|
+
return true;
|
|
24707
|
+
} catch {
|
|
24708
|
+
return false;
|
|
24709
|
+
}
|
|
24710
|
+
}, { message: "Invalid Base64 string" });
|
|
24711
|
+
const BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
24712
|
+
/**
|
|
24713
|
+
* A base64-encoded string representing the binary data of the item.
|
|
24714
|
+
*/
|
|
24715
|
+
blob: Base64Schema });
|
|
24716
|
+
/**
|
|
24717
|
+
* The sender or recipient of messages and data in a conversation.
|
|
24718
|
+
*/
|
|
24719
|
+
const RoleSchema = _enum(["user", "assistant"]);
|
|
24720
|
+
/**
|
|
24721
|
+
* Optional annotations providing clients additional context about a resource.
|
|
24722
|
+
*/
|
|
24723
|
+
const AnnotationsSchema = object$1({
|
|
24724
|
+
/**
|
|
24725
|
+
* Intended audience(s) for the resource.
|
|
24726
|
+
*/
|
|
24727
|
+
audience: array(RoleSchema).optional(),
|
|
24728
|
+
/**
|
|
24729
|
+
* Importance hint for the resource, from 0 (least) to 1 (most).
|
|
24730
|
+
*/
|
|
24731
|
+
priority: number().min(0).max(1).optional(),
|
|
24732
|
+
/**
|
|
24733
|
+
* ISO 8601 timestamp for the most recent modification.
|
|
24734
|
+
*/
|
|
24735
|
+
lastModified: datetime({ offset: true }).optional()
|
|
24736
|
+
});
|
|
24737
|
+
/**
|
|
24738
|
+
* A known resource that the server is capable of reading.
|
|
24739
|
+
*/
|
|
24740
|
+
const ResourceSchema = object$1({
|
|
24741
|
+
...BaseMetadataSchema.shape,
|
|
24742
|
+
...IconsSchema.shape,
|
|
24743
|
+
/**
|
|
24744
|
+
* The URI of this resource.
|
|
24745
|
+
*/
|
|
24746
|
+
uri: string(),
|
|
24747
|
+
/**
|
|
24748
|
+
* A description of what this resource represents.
|
|
24749
|
+
*
|
|
24750
|
+
* 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.
|
|
24751
|
+
*/
|
|
24752
|
+
description: optional(string()),
|
|
24753
|
+
/**
|
|
24754
|
+
* The MIME type of this resource, if known.
|
|
24755
|
+
*/
|
|
24756
|
+
mimeType: optional(string()),
|
|
24757
|
+
/**
|
|
24758
|
+
* The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
|
|
24759
|
+
*
|
|
24760
|
+
* This can be used by Hosts to display file sizes and estimate context window usage.
|
|
24761
|
+
*/
|
|
24762
|
+
size: optional(number()),
|
|
24763
|
+
/**
|
|
24764
|
+
* Optional annotations for the client.
|
|
24765
|
+
*/
|
|
24766
|
+
annotations: AnnotationsSchema.optional(),
|
|
24767
|
+
/**
|
|
24768
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24769
|
+
* for notes on _meta usage.
|
|
24770
|
+
*/
|
|
24771
|
+
_meta: optional(looseObject({}))
|
|
24772
|
+
});
|
|
24773
|
+
/**
|
|
24774
|
+
* A template description for resources available on the server.
|
|
24775
|
+
*/
|
|
24776
|
+
const ResourceTemplateSchema = object$1({
|
|
24777
|
+
...BaseMetadataSchema.shape,
|
|
24778
|
+
...IconsSchema.shape,
|
|
24779
|
+
/**
|
|
24780
|
+
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
|
|
24781
|
+
*/
|
|
24782
|
+
uriTemplate: string(),
|
|
24783
|
+
/**
|
|
24784
|
+
* A description of what this template is for.
|
|
24785
|
+
*
|
|
24786
|
+
* 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.
|
|
24787
|
+
*/
|
|
24788
|
+
description: optional(string()),
|
|
24789
|
+
/**
|
|
24790
|
+
* 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.
|
|
24791
|
+
*/
|
|
24792
|
+
mimeType: optional(string()),
|
|
24793
|
+
/**
|
|
24794
|
+
* Optional annotations for the client.
|
|
24795
|
+
*/
|
|
24796
|
+
annotations: AnnotationsSchema.optional(),
|
|
24797
|
+
/**
|
|
24798
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24799
|
+
* for notes on _meta usage.
|
|
24800
|
+
*/
|
|
24801
|
+
_meta: optional(looseObject({}))
|
|
24802
|
+
});
|
|
24803
|
+
/**
|
|
24804
|
+
* Sent from the client to request a list of resources the server has.
|
|
24805
|
+
*/
|
|
24806
|
+
const ListResourcesRequestSchema = PaginatedRequestSchema.extend({ method: literal("resources/list") });
|
|
24807
|
+
/**
|
|
24808
|
+
* The server's response to a resources/list request from the client.
|
|
24809
|
+
*/
|
|
24810
|
+
const ListResourcesResultSchema = PaginatedResultSchema.extend({ resources: array(ResourceSchema) });
|
|
24811
|
+
/**
|
|
24812
|
+
* Sent from the client to request a list of resource templates the server has.
|
|
24813
|
+
*/
|
|
24814
|
+
const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({ method: literal("resources/templates/list") });
|
|
24815
|
+
/**
|
|
24816
|
+
* The server's response to a resources/templates/list request from the client.
|
|
24817
|
+
*/
|
|
24818
|
+
const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({ resourceTemplates: array(ResourceTemplateSchema) });
|
|
24819
|
+
const ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24820
|
+
/**
|
|
24821
|
+
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
|
|
24822
|
+
*
|
|
24823
|
+
* @format uri
|
|
24824
|
+
*/
|
|
24825
|
+
uri: string() });
|
|
24826
|
+
/**
|
|
24827
|
+
* Parameters for a `resources/read` request.
|
|
24828
|
+
*/
|
|
24829
|
+
const ReadResourceRequestParamsSchema = ResourceRequestParamsSchema;
|
|
24830
|
+
/**
|
|
24831
|
+
* Sent from the client to the server, to read a specific resource URI.
|
|
24832
|
+
*/
|
|
24833
|
+
const ReadResourceRequestSchema = RequestSchema.extend({
|
|
24834
|
+
method: literal("resources/read"),
|
|
24835
|
+
params: ReadResourceRequestParamsSchema
|
|
24836
|
+
});
|
|
24837
|
+
/**
|
|
24838
|
+
* The server's response to a resources/read request from the client.
|
|
24839
|
+
*/
|
|
24840
|
+
const ReadResourceResultSchema = ResultSchema.extend({ contents: array(union([TextResourceContentsSchema, BlobResourceContentsSchema])) });
|
|
24841
|
+
/**
|
|
24842
|
+
* 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.
|
|
24843
|
+
*/
|
|
24844
|
+
const ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
24845
|
+
method: literal("notifications/resources/list_changed"),
|
|
24846
|
+
params: NotificationsParamsSchema.optional()
|
|
24847
|
+
});
|
|
24848
|
+
const SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
24849
|
+
/**
|
|
24850
|
+
* Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
|
|
24851
|
+
*/
|
|
24852
|
+
const SubscribeRequestSchema = RequestSchema.extend({
|
|
24853
|
+
method: literal("resources/subscribe"),
|
|
24854
|
+
params: SubscribeRequestParamsSchema
|
|
24855
|
+
});
|
|
24856
|
+
const UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
24857
|
+
/**
|
|
24858
|
+
* Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
|
|
24859
|
+
*/
|
|
24860
|
+
const UnsubscribeRequestSchema = RequestSchema.extend({
|
|
24861
|
+
method: literal("resources/unsubscribe"),
|
|
24862
|
+
params: UnsubscribeRequestParamsSchema
|
|
24863
|
+
});
|
|
24864
|
+
/**
|
|
24865
|
+
* Parameters for a `notifications/resources/updated` notification.
|
|
24866
|
+
*/
|
|
24867
|
+
const ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
24868
|
+
/**
|
|
24869
|
+
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
|
|
24870
|
+
*/
|
|
24871
|
+
uri: string() });
|
|
24872
|
+
/**
|
|
24873
|
+
* 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.
|
|
24874
|
+
*/
|
|
24875
|
+
const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
24876
|
+
method: literal("notifications/resources/updated"),
|
|
24877
|
+
params: ResourceUpdatedNotificationParamsSchema
|
|
24878
|
+
});
|
|
24879
|
+
/**
|
|
24880
|
+
* Describes an argument that a prompt can accept.
|
|
24881
|
+
*/
|
|
24882
|
+
const PromptArgumentSchema = object$1({
|
|
24883
|
+
/**
|
|
24884
|
+
* The name of the argument.
|
|
24885
|
+
*/
|
|
24886
|
+
name: string(),
|
|
24887
|
+
/**
|
|
24888
|
+
* A human-readable description of the argument.
|
|
24889
|
+
*/
|
|
24890
|
+
description: optional(string()),
|
|
24891
|
+
/**
|
|
24892
|
+
* Whether this argument must be provided.
|
|
24893
|
+
*/
|
|
24894
|
+
required: optional(boolean())
|
|
24895
|
+
});
|
|
24896
|
+
/**
|
|
24897
|
+
* A prompt or prompt template that the server offers.
|
|
24898
|
+
*/
|
|
24899
|
+
const PromptSchema$1 = object$1({
|
|
24900
|
+
...BaseMetadataSchema.shape,
|
|
24901
|
+
...IconsSchema.shape,
|
|
24902
|
+
/**
|
|
24903
|
+
* An optional description of what this prompt provides
|
|
24904
|
+
*/
|
|
24905
|
+
description: optional(string()),
|
|
24906
|
+
/**
|
|
24907
|
+
* A list of arguments to use for templating the prompt.
|
|
24908
|
+
*/
|
|
24909
|
+
arguments: optional(array(PromptArgumentSchema)),
|
|
24910
|
+
/**
|
|
24911
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24912
|
+
* for notes on _meta usage.
|
|
24913
|
+
*/
|
|
24914
|
+
_meta: optional(looseObject({}))
|
|
24915
|
+
});
|
|
24916
|
+
/**
|
|
24917
|
+
* Sent from the client to request a list of prompts and prompt templates the server has.
|
|
24918
|
+
*/
|
|
24919
|
+
const ListPromptsRequestSchema = PaginatedRequestSchema.extend({ method: literal("prompts/list") });
|
|
24920
|
+
/**
|
|
24921
|
+
* The server's response to a prompts/list request from the client.
|
|
24922
|
+
*/
|
|
24923
|
+
const ListPromptsResultSchema = PaginatedResultSchema.extend({ prompts: array(PromptSchema$1) });
|
|
24924
|
+
/**
|
|
24925
|
+
* Parameters for a `prompts/get` request.
|
|
24926
|
+
*/
|
|
24927
|
+
const GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
24928
|
+
/**
|
|
24929
|
+
* The name of the prompt or prompt template.
|
|
24930
|
+
*/
|
|
24931
|
+
name: string(),
|
|
24932
|
+
/**
|
|
24933
|
+
* Arguments to use for templating the prompt.
|
|
24934
|
+
*/
|
|
24935
|
+
arguments: record(string(), string()).optional()
|
|
24936
|
+
});
|
|
24937
|
+
/**
|
|
24938
|
+
* Used by the client to get a prompt provided by the server.
|
|
24939
|
+
*/
|
|
24940
|
+
const GetPromptRequestSchema = RequestSchema.extend({
|
|
24941
|
+
method: literal("prompts/get"),
|
|
24942
|
+
params: GetPromptRequestParamsSchema
|
|
24943
|
+
});
|
|
24944
|
+
/**
|
|
24945
|
+
* Text provided to or from an LLM.
|
|
24946
|
+
*/
|
|
24947
|
+
const TextContentSchema = object$1({
|
|
24948
|
+
type: literal("text"),
|
|
24949
|
+
/**
|
|
24950
|
+
* The text content of the message.
|
|
24951
|
+
*/
|
|
24952
|
+
text: string(),
|
|
24953
|
+
/**
|
|
24954
|
+
* Optional annotations for the client.
|
|
24955
|
+
*/
|
|
24956
|
+
annotations: AnnotationsSchema.optional(),
|
|
24957
|
+
/**
|
|
24958
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24959
|
+
* for notes on _meta usage.
|
|
24960
|
+
*/
|
|
24961
|
+
_meta: record(string(), unknown()).optional()
|
|
24962
|
+
});
|
|
24963
|
+
/**
|
|
24964
|
+
* An image provided to or from an LLM.
|
|
24965
|
+
*/
|
|
24966
|
+
const ImageContentSchema = object$1({
|
|
24967
|
+
type: literal("image"),
|
|
24968
|
+
/**
|
|
24969
|
+
* The base64-encoded image data.
|
|
24970
|
+
*/
|
|
24971
|
+
data: Base64Schema,
|
|
24972
|
+
/**
|
|
24973
|
+
* The MIME type of the image. Different providers may support different image types.
|
|
24974
|
+
*/
|
|
24975
|
+
mimeType: string(),
|
|
24976
|
+
/**
|
|
24977
|
+
* Optional annotations for the client.
|
|
24978
|
+
*/
|
|
24979
|
+
annotations: AnnotationsSchema.optional(),
|
|
24980
|
+
/**
|
|
24981
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
24982
|
+
* for notes on _meta usage.
|
|
24983
|
+
*/
|
|
24984
|
+
_meta: record(string(), unknown()).optional()
|
|
24985
|
+
});
|
|
24986
|
+
/**
|
|
24987
|
+
* An Audio provided to or from an LLM.
|
|
24988
|
+
*/
|
|
24989
|
+
const AudioContentSchema = object$1({
|
|
24990
|
+
type: literal("audio"),
|
|
24991
|
+
/**
|
|
24992
|
+
* The base64-encoded audio data.
|
|
24993
|
+
*/
|
|
24994
|
+
data: Base64Schema,
|
|
24995
|
+
/**
|
|
24996
|
+
* The MIME type of the audio. Different providers may support different audio types.
|
|
24997
|
+
*/
|
|
24998
|
+
mimeType: string(),
|
|
24999
|
+
/**
|
|
25000
|
+
* Optional annotations for the client.
|
|
25001
|
+
*/
|
|
25002
|
+
annotations: AnnotationsSchema.optional(),
|
|
25003
|
+
/**
|
|
25004
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25005
|
+
* for notes on _meta usage.
|
|
25006
|
+
*/
|
|
25007
|
+
_meta: record(string(), unknown()).optional()
|
|
25008
|
+
});
|
|
25009
|
+
/**
|
|
25010
|
+
* A tool call request from an assistant (LLM).
|
|
25011
|
+
* Represents the assistant's request to use a tool.
|
|
25012
|
+
*/
|
|
25013
|
+
const ToolUseContentSchema = object$1({
|
|
25014
|
+
type: literal("tool_use"),
|
|
25015
|
+
/**
|
|
25016
|
+
* The name of the tool to invoke.
|
|
25017
|
+
* Must match a tool name from the request's tools array.
|
|
25018
|
+
*/
|
|
25019
|
+
name: string(),
|
|
25020
|
+
/**
|
|
25021
|
+
* Unique identifier for this tool call.
|
|
25022
|
+
* Used to correlate with ToolResultContent in subsequent messages.
|
|
25023
|
+
*/
|
|
25024
|
+
id: string(),
|
|
25025
|
+
/**
|
|
25026
|
+
* Arguments to pass to the tool.
|
|
25027
|
+
* Must conform to the tool's inputSchema.
|
|
25028
|
+
*/
|
|
25029
|
+
input: record(string(), unknown()),
|
|
25030
|
+
/**
|
|
25031
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25032
|
+
* for notes on _meta usage.
|
|
25033
|
+
*/
|
|
25034
|
+
_meta: record(string(), unknown()).optional()
|
|
25035
|
+
});
|
|
25036
|
+
/**
|
|
25037
|
+
* The contents of a resource, embedded into a prompt or tool call result.
|
|
25038
|
+
*/
|
|
25039
|
+
const EmbeddedResourceSchema = object$1({
|
|
25040
|
+
type: literal("resource"),
|
|
25041
|
+
resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
|
|
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
|
+
* A content block that can be used in prompts and tool results.
|
|
25054
|
+
*/
|
|
25055
|
+
const ContentBlockSchema = union([
|
|
25056
|
+
TextContentSchema,
|
|
25057
|
+
ImageContentSchema,
|
|
25058
|
+
AudioContentSchema,
|
|
25059
|
+
ResourceSchema.extend({ type: literal("resource_link") }),
|
|
25060
|
+
EmbeddedResourceSchema
|
|
25061
|
+
]);
|
|
25062
|
+
/**
|
|
25063
|
+
* Describes a message returned as part of a prompt.
|
|
25064
|
+
*/
|
|
25065
|
+
const PromptMessageSchema = object$1({
|
|
25066
|
+
role: RoleSchema,
|
|
25067
|
+
content: ContentBlockSchema
|
|
25068
|
+
});
|
|
25069
|
+
/**
|
|
25070
|
+
* The server's response to a prompts/get request from the client.
|
|
25071
|
+
*/
|
|
25072
|
+
const GetPromptResultSchema = ResultSchema.extend({
|
|
25073
|
+
/**
|
|
25074
|
+
* An optional description for the prompt.
|
|
25075
|
+
*/
|
|
25076
|
+
description: string().optional(),
|
|
25077
|
+
messages: array(PromptMessageSchema)
|
|
25078
|
+
});
|
|
25079
|
+
/**
|
|
25080
|
+
* 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.
|
|
25081
|
+
*/
|
|
25082
|
+
const PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
25083
|
+
method: literal("notifications/prompts/list_changed"),
|
|
25084
|
+
params: NotificationsParamsSchema.optional()
|
|
25085
|
+
});
|
|
25086
|
+
/**
|
|
25087
|
+
* Additional properties describing a Tool to clients.
|
|
25088
|
+
*
|
|
25089
|
+
* NOTE: all properties in ToolAnnotations are **hints**.
|
|
25090
|
+
* They are not guaranteed to provide a faithful description of
|
|
25091
|
+
* tool behavior (including descriptive properties like `title`).
|
|
25092
|
+
*
|
|
25093
|
+
* Clients should never make tool use decisions based on ToolAnnotations
|
|
25094
|
+
* received from untrusted servers.
|
|
25095
|
+
*/
|
|
25096
|
+
const ToolAnnotationsSchema = object$1({
|
|
25097
|
+
/**
|
|
25098
|
+
* A human-readable title for the tool.
|
|
25099
|
+
*/
|
|
25100
|
+
title: string().optional(),
|
|
25101
|
+
/**
|
|
25102
|
+
* If true, the tool does not modify its environment.
|
|
25103
|
+
*
|
|
25104
|
+
* Default: false
|
|
25105
|
+
*/
|
|
25106
|
+
readOnlyHint: boolean().optional(),
|
|
25107
|
+
/**
|
|
25108
|
+
* If true, the tool may perform destructive updates to its environment.
|
|
25109
|
+
* If false, the tool performs only additive updates.
|
|
25110
|
+
*
|
|
25111
|
+
* (This property is meaningful only when `readOnlyHint == false`)
|
|
25112
|
+
*
|
|
25113
|
+
* Default: true
|
|
25114
|
+
*/
|
|
25115
|
+
destructiveHint: boolean().optional(),
|
|
25116
|
+
/**
|
|
25117
|
+
* If true, calling the tool repeatedly with the same arguments
|
|
25118
|
+
* will have no additional effect on the its environment.
|
|
25119
|
+
*
|
|
25120
|
+
* (This property is meaningful only when `readOnlyHint == false`)
|
|
25121
|
+
*
|
|
25122
|
+
* Default: false
|
|
25123
|
+
*/
|
|
25124
|
+
idempotentHint: boolean().optional(),
|
|
25125
|
+
/**
|
|
25126
|
+
* If true, this tool may interact with an "open world" of external
|
|
25127
|
+
* entities. If false, the tool's domain of interaction is closed.
|
|
25128
|
+
* For example, the world of a web search tool is open, whereas that
|
|
25129
|
+
* of a memory tool is not.
|
|
25130
|
+
*
|
|
25131
|
+
* Default: true
|
|
25132
|
+
*/
|
|
25133
|
+
openWorldHint: boolean().optional()
|
|
25134
|
+
});
|
|
25135
|
+
/**
|
|
25136
|
+
* Execution-related properties for a tool.
|
|
25137
|
+
*/
|
|
25138
|
+
const ToolExecutionSchema = object$1({
|
|
25139
|
+
/**
|
|
25140
|
+
* Indicates the tool's preference for task-augmented execution.
|
|
25141
|
+
* - "required": Clients MUST invoke the tool as a task
|
|
25142
|
+
* - "optional": Clients MAY invoke the tool as a task or normal request
|
|
25143
|
+
* - "forbidden": Clients MUST NOT attempt to invoke the tool as a task
|
|
25144
|
+
*
|
|
25145
|
+
* If not present, defaults to "forbidden".
|
|
25146
|
+
*/
|
|
25147
|
+
taskSupport: _enum([
|
|
25148
|
+
"required",
|
|
25149
|
+
"optional",
|
|
25150
|
+
"forbidden"
|
|
25151
|
+
]).optional() });
|
|
25152
|
+
/**
|
|
25153
|
+
* Definition for a tool the client can call.
|
|
25154
|
+
*/
|
|
25155
|
+
const ToolSchema = object$1({
|
|
25156
|
+
...BaseMetadataSchema.shape,
|
|
25157
|
+
...IconsSchema.shape,
|
|
25158
|
+
/**
|
|
25159
|
+
* A human-readable description of the tool.
|
|
25160
|
+
*/
|
|
25161
|
+
description: string().optional(),
|
|
25162
|
+
/**
|
|
25163
|
+
* A JSON Schema 2020-12 object defining the expected parameters for the tool.
|
|
25164
|
+
* Must have type: 'object' at the root level per MCP spec.
|
|
25165
|
+
*/
|
|
25166
|
+
inputSchema: object$1({
|
|
25167
|
+
type: literal("object"),
|
|
25168
|
+
properties: record(string(), AssertObjectSchema).optional(),
|
|
25169
|
+
required: array(string()).optional()
|
|
25170
|
+
}).catchall(unknown()),
|
|
25171
|
+
/**
|
|
25172
|
+
* An optional JSON Schema 2020-12 object defining the structure of the tool's output
|
|
25173
|
+
* returned in the structuredContent field of a CallToolResult.
|
|
25174
|
+
* Must have type: 'object' at the root level per MCP spec.
|
|
25175
|
+
*/
|
|
25176
|
+
outputSchema: object$1({
|
|
25177
|
+
type: literal("object"),
|
|
25178
|
+
properties: record(string(), AssertObjectSchema).optional(),
|
|
25179
|
+
required: array(string()).optional()
|
|
25180
|
+
}).catchall(unknown()).optional(),
|
|
25181
|
+
/**
|
|
25182
|
+
* Optional additional tool information.
|
|
25183
|
+
*/
|
|
25184
|
+
annotations: ToolAnnotationsSchema.optional(),
|
|
25185
|
+
/**
|
|
25186
|
+
* Execution-related properties for this tool.
|
|
25187
|
+
*/
|
|
25188
|
+
execution: ToolExecutionSchema.optional(),
|
|
25189
|
+
/**
|
|
25190
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25191
|
+
* for notes on _meta usage.
|
|
25192
|
+
*/
|
|
25193
|
+
_meta: record(string(), unknown()).optional()
|
|
25194
|
+
});
|
|
25195
|
+
/**
|
|
25196
|
+
* Sent from the client to request a list of tools the server has.
|
|
25197
|
+
*/
|
|
25198
|
+
const ListToolsRequestSchema = PaginatedRequestSchema.extend({ method: literal("tools/list") });
|
|
25199
|
+
/**
|
|
25200
|
+
* The server's response to a tools/list request from the client.
|
|
25201
|
+
*/
|
|
25202
|
+
const ListToolsResultSchema = PaginatedResultSchema.extend({ tools: array(ToolSchema) });
|
|
25203
|
+
/**
|
|
25204
|
+
* The server's response to a tool call.
|
|
25205
|
+
*/
|
|
25206
|
+
const CallToolResultSchema = ResultSchema.extend({
|
|
25207
|
+
/**
|
|
25208
|
+
* A list of content objects that represent the result of the tool call.
|
|
25209
|
+
*
|
|
25210
|
+
* If the Tool does not define an outputSchema, this field MUST be present in the result.
|
|
25211
|
+
* For backwards compatibility, this field is always present, but it may be empty.
|
|
25212
|
+
*/
|
|
25213
|
+
content: array(ContentBlockSchema).default([]),
|
|
25214
|
+
/**
|
|
25215
|
+
* An object containing structured tool output.
|
|
25216
|
+
*
|
|
25217
|
+
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
|
|
25218
|
+
*/
|
|
25219
|
+
structuredContent: record(string(), unknown()).optional(),
|
|
25220
|
+
/**
|
|
25221
|
+
* Whether the tool call ended in an error.
|
|
25222
|
+
*
|
|
25223
|
+
* If not set, this is assumed to be false (the call was successful).
|
|
25224
|
+
*
|
|
25225
|
+
* Any errors that originate from the tool SHOULD be reported inside the result
|
|
25226
|
+
* object, with `isError` set to true, _not_ as an MCP protocol-level error
|
|
25227
|
+
* response. Otherwise, the LLM would not be able to see that an error occurred
|
|
25228
|
+
* and self-correct.
|
|
25229
|
+
*
|
|
25230
|
+
* However, any errors in _finding_ the tool, an error indicating that the
|
|
25231
|
+
* server does not support tool calls, or any other exceptional conditions,
|
|
25232
|
+
* should be reported as an MCP error response.
|
|
25233
|
+
*/
|
|
25234
|
+
isError: boolean().optional()
|
|
25235
|
+
});
|
|
25236
|
+
CallToolResultSchema.or(ResultSchema.extend({ toolResult: unknown() }));
|
|
25237
|
+
/**
|
|
25238
|
+
* Parameters for a `tools/call` request.
|
|
25239
|
+
*/
|
|
25240
|
+
const CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
25241
|
+
/**
|
|
25242
|
+
* The name of the tool to call.
|
|
25243
|
+
*/
|
|
25244
|
+
name: string(),
|
|
25245
|
+
/**
|
|
25246
|
+
* Arguments to pass to the tool.
|
|
25247
|
+
*/
|
|
25248
|
+
arguments: record(string(), unknown()).optional()
|
|
25249
|
+
});
|
|
25250
|
+
/**
|
|
25251
|
+
* Used by the client to invoke a tool provided by the server.
|
|
25252
|
+
*/
|
|
25253
|
+
const CallToolRequestSchema = RequestSchema.extend({
|
|
25254
|
+
method: literal("tools/call"),
|
|
25255
|
+
params: CallToolRequestParamsSchema
|
|
25256
|
+
});
|
|
25257
|
+
/**
|
|
25258
|
+
* 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.
|
|
25259
|
+
*/
|
|
25260
|
+
const ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
25261
|
+
method: literal("notifications/tools/list_changed"),
|
|
25262
|
+
params: NotificationsParamsSchema.optional()
|
|
25263
|
+
});
|
|
25264
|
+
object$1({
|
|
25265
|
+
/**
|
|
25266
|
+
* If true, the list will be refreshed automatically when a list changed notification is received.
|
|
25267
|
+
* The callback will be called with the updated list.
|
|
25268
|
+
*
|
|
25269
|
+
* If false, the callback will be called with null items, allowing manual refresh.
|
|
25270
|
+
*
|
|
25271
|
+
* @default true
|
|
25272
|
+
*/
|
|
25273
|
+
autoRefresh: boolean().default(true),
|
|
25274
|
+
/**
|
|
25275
|
+
* Debounce time in milliseconds for list changed notification processing.
|
|
25276
|
+
*
|
|
25277
|
+
* Multiple notifications received within this timeframe will only trigger one refresh.
|
|
25278
|
+
* Set to 0 to disable debouncing.
|
|
25279
|
+
*
|
|
25280
|
+
* @default 300
|
|
25281
|
+
*/
|
|
25282
|
+
debounceMs: number().int().nonnegative().default(300)
|
|
25283
|
+
});
|
|
25284
|
+
/**
|
|
25285
|
+
* The severity of a log message.
|
|
25286
|
+
*/
|
|
25287
|
+
const LoggingLevelSchema = _enum([
|
|
25288
|
+
"debug",
|
|
25289
|
+
"info",
|
|
25290
|
+
"notice",
|
|
25291
|
+
"warning",
|
|
25292
|
+
"error",
|
|
25293
|
+
"critical",
|
|
25294
|
+
"alert",
|
|
25295
|
+
"emergency"
|
|
25296
|
+
]);
|
|
25297
|
+
/**
|
|
25298
|
+
* Parameters for a `logging/setLevel` request.
|
|
25299
|
+
*/
|
|
25300
|
+
const SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
25301
|
+
/**
|
|
25302
|
+
* 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.
|
|
25303
|
+
*/
|
|
25304
|
+
level: LoggingLevelSchema });
|
|
25305
|
+
/**
|
|
25306
|
+
* A request from the client to the server, to enable or adjust logging.
|
|
25307
|
+
*/
|
|
25308
|
+
const SetLevelRequestSchema = RequestSchema.extend({
|
|
25309
|
+
method: literal("logging/setLevel"),
|
|
25310
|
+
params: SetLevelRequestParamsSchema
|
|
25311
|
+
});
|
|
25312
|
+
/**
|
|
25313
|
+
* Parameters for a `notifications/message` notification.
|
|
25314
|
+
*/
|
|
25315
|
+
const LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
25316
|
+
/**
|
|
25317
|
+
* The severity of this log message.
|
|
25318
|
+
*/
|
|
25319
|
+
level: LoggingLevelSchema,
|
|
25320
|
+
/**
|
|
25321
|
+
* An optional name of the logger issuing this message.
|
|
25322
|
+
*/
|
|
25323
|
+
logger: string().optional(),
|
|
25324
|
+
/**
|
|
25325
|
+
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
|
|
25326
|
+
*/
|
|
25327
|
+
data: unknown()
|
|
25328
|
+
});
|
|
25329
|
+
/**
|
|
25330
|
+
* 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.
|
|
25331
|
+
*/
|
|
25332
|
+
const LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
25333
|
+
method: literal("notifications/message"),
|
|
25334
|
+
params: LoggingMessageNotificationParamsSchema
|
|
25335
|
+
});
|
|
25336
|
+
/**
|
|
25337
|
+
* The server's preferences for model selection, requested of the client during sampling.
|
|
25338
|
+
*/
|
|
25339
|
+
const ModelPreferencesSchema = object$1({
|
|
25340
|
+
/**
|
|
25341
|
+
* Optional hints to use for model selection.
|
|
25342
|
+
*/
|
|
25343
|
+
hints: array(object$1({
|
|
25344
|
+
/**
|
|
25345
|
+
* A hint for a model name.
|
|
25346
|
+
*/
|
|
25347
|
+
name: string().optional() })).optional(),
|
|
25348
|
+
/**
|
|
25349
|
+
* How much to prioritize cost when selecting a model.
|
|
25350
|
+
*/
|
|
25351
|
+
costPriority: number().min(0).max(1).optional(),
|
|
25352
|
+
/**
|
|
25353
|
+
* How much to prioritize sampling speed (latency) when selecting a model.
|
|
25354
|
+
*/
|
|
25355
|
+
speedPriority: number().min(0).max(1).optional(),
|
|
25356
|
+
/**
|
|
25357
|
+
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
25358
|
+
*/
|
|
25359
|
+
intelligencePriority: number().min(0).max(1).optional()
|
|
25360
|
+
});
|
|
25361
|
+
/**
|
|
25362
|
+
* Controls tool usage behavior in sampling requests.
|
|
25363
|
+
*/
|
|
25364
|
+
const ToolChoiceSchema = object$1({
|
|
25365
|
+
/**
|
|
25366
|
+
* Controls when tools are used:
|
|
25367
|
+
* - "auto": Model decides whether to use tools (default)
|
|
25368
|
+
* - "required": Model MUST use at least one tool before completing
|
|
25369
|
+
* - "none": Model MUST NOT use any tools
|
|
25370
|
+
*/
|
|
25371
|
+
mode: _enum([
|
|
25372
|
+
"auto",
|
|
25373
|
+
"required",
|
|
25374
|
+
"none"
|
|
25375
|
+
]).optional() });
|
|
25376
|
+
/**
|
|
25377
|
+
* The result of a tool execution, provided by the user (server).
|
|
25378
|
+
* Represents the outcome of invoking a tool requested via ToolUseContent.
|
|
25379
|
+
*/
|
|
25380
|
+
const ToolResultContentSchema = object$1({
|
|
25381
|
+
type: literal("tool_result"),
|
|
25382
|
+
toolUseId: string().describe("The unique identifier for the corresponding tool call."),
|
|
25383
|
+
content: array(ContentBlockSchema).default([]),
|
|
25384
|
+
structuredContent: object$1({}).loose().optional(),
|
|
25385
|
+
isError: boolean().optional(),
|
|
25386
|
+
/**
|
|
25387
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25388
|
+
* for notes on _meta usage.
|
|
25389
|
+
*/
|
|
25390
|
+
_meta: record(string(), unknown()).optional()
|
|
25391
|
+
});
|
|
25392
|
+
/**
|
|
25393
|
+
* Basic content types for sampling responses (without tool use).
|
|
25394
|
+
* Used for backwards-compatible CreateMessageResult when tools are not used.
|
|
25395
|
+
*/
|
|
25396
|
+
const SamplingContentSchema = discriminatedUnion("type", [
|
|
25397
|
+
TextContentSchema,
|
|
25398
|
+
ImageContentSchema,
|
|
25399
|
+
AudioContentSchema
|
|
25400
|
+
]);
|
|
25401
|
+
/**
|
|
25402
|
+
* Content block types allowed in sampling messages.
|
|
25403
|
+
* This includes text, image, audio, tool use requests, and tool results.
|
|
25404
|
+
*/
|
|
25405
|
+
const SamplingMessageContentBlockSchema = discriminatedUnion("type", [
|
|
25406
|
+
TextContentSchema,
|
|
25407
|
+
ImageContentSchema,
|
|
25408
|
+
AudioContentSchema,
|
|
25409
|
+
ToolUseContentSchema,
|
|
25410
|
+
ToolResultContentSchema
|
|
25411
|
+
]);
|
|
25412
|
+
/**
|
|
25413
|
+
* Describes a message issued to or received from an LLM API.
|
|
25414
|
+
*/
|
|
25415
|
+
const SamplingMessageSchema = object$1({
|
|
25416
|
+
role: RoleSchema,
|
|
25417
|
+
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)]),
|
|
25418
|
+
/**
|
|
25419
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25420
|
+
* for notes on _meta usage.
|
|
25421
|
+
*/
|
|
25422
|
+
_meta: record(string(), unknown()).optional()
|
|
25423
|
+
});
|
|
25424
|
+
/**
|
|
25425
|
+
* Parameters for a `sampling/createMessage` request.
|
|
25426
|
+
*/
|
|
25427
|
+
const CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
25428
|
+
messages: array(SamplingMessageSchema),
|
|
25429
|
+
/**
|
|
25430
|
+
* The server's preferences for which model to select. The client MAY modify or omit this request.
|
|
25431
|
+
*/
|
|
25432
|
+
modelPreferences: ModelPreferencesSchema.optional(),
|
|
25433
|
+
/**
|
|
25434
|
+
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
|
|
25435
|
+
*/
|
|
25436
|
+
systemPrompt: string().optional(),
|
|
25437
|
+
/**
|
|
25438
|
+
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt.
|
|
25439
|
+
* The client MAY ignore this request.
|
|
25440
|
+
*
|
|
25441
|
+
* Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client
|
|
25442
|
+
* declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
|
|
25443
|
+
*/
|
|
25444
|
+
includeContext: _enum([
|
|
25445
|
+
"none",
|
|
25446
|
+
"thisServer",
|
|
25447
|
+
"allServers"
|
|
25448
|
+
]).optional(),
|
|
25449
|
+
temperature: number().optional(),
|
|
25450
|
+
/**
|
|
25451
|
+
* The requested maximum number of tokens to sample (to prevent runaway completions).
|
|
25452
|
+
*
|
|
25453
|
+
* The client MAY choose to sample fewer tokens than the requested maximum.
|
|
25454
|
+
*/
|
|
25455
|
+
maxTokens: number().int(),
|
|
25456
|
+
stopSequences: array(string()).optional(),
|
|
25457
|
+
/**
|
|
25458
|
+
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
25459
|
+
*/
|
|
25460
|
+
metadata: AssertObjectSchema.optional(),
|
|
25461
|
+
/**
|
|
25462
|
+
* Tools that the model may use during generation.
|
|
25463
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
25464
|
+
*/
|
|
25465
|
+
tools: array(ToolSchema).optional(),
|
|
25466
|
+
/**
|
|
25467
|
+
* Controls how the model uses tools.
|
|
25468
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
25469
|
+
* Default is `{ mode: "auto" }`.
|
|
25470
|
+
*/
|
|
25471
|
+
toolChoice: ToolChoiceSchema.optional()
|
|
25472
|
+
});
|
|
25473
|
+
/**
|
|
25474
|
+
* 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.
|
|
25475
|
+
*/
|
|
25476
|
+
const CreateMessageRequestSchema = RequestSchema.extend({
|
|
25477
|
+
method: literal("sampling/createMessage"),
|
|
25478
|
+
params: CreateMessageRequestParamsSchema
|
|
25479
|
+
});
|
|
25480
|
+
/**
|
|
25481
|
+
* The client's response to a sampling/create_message request from the server.
|
|
25482
|
+
* This is the backwards-compatible version that returns single content (no arrays).
|
|
25483
|
+
* Used when the request does not include tools.
|
|
25484
|
+
*/
|
|
25485
|
+
const CreateMessageResultSchema = ResultSchema.extend({
|
|
25486
|
+
/**
|
|
25487
|
+
* The name of the model that generated the message.
|
|
25488
|
+
*/
|
|
25489
|
+
model: string(),
|
|
25490
|
+
/**
|
|
25491
|
+
* The reason why sampling stopped, if known.
|
|
25492
|
+
*
|
|
25493
|
+
* Standard values:
|
|
25494
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
25495
|
+
* - "stopSequence": A stop sequence was encountered
|
|
25496
|
+
* - "maxTokens": Maximum token limit was reached
|
|
25497
|
+
*
|
|
25498
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
25499
|
+
*/
|
|
25500
|
+
stopReason: optional(_enum([
|
|
25501
|
+
"endTurn",
|
|
25502
|
+
"stopSequence",
|
|
25503
|
+
"maxTokens"
|
|
25504
|
+
]).or(string())),
|
|
25505
|
+
role: RoleSchema,
|
|
25506
|
+
/**
|
|
25507
|
+
* Response content. Single content block (text, image, or audio).
|
|
25508
|
+
*/
|
|
25509
|
+
content: SamplingContentSchema
|
|
25510
|
+
});
|
|
25511
|
+
/**
|
|
25512
|
+
* The client's response to a sampling/create_message request when tools were provided.
|
|
25513
|
+
* This version supports array content for tool use flows.
|
|
25514
|
+
*/
|
|
25515
|
+
const CreateMessageResultWithToolsSchema = ResultSchema.extend({
|
|
25516
|
+
/**
|
|
25517
|
+
* The name of the model that generated the message.
|
|
25518
|
+
*/
|
|
25519
|
+
model: string(),
|
|
25520
|
+
/**
|
|
25521
|
+
* The reason why sampling stopped, if known.
|
|
25522
|
+
*
|
|
25523
|
+
* Standard values:
|
|
25524
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
25525
|
+
* - "stopSequence": A stop sequence was encountered
|
|
25526
|
+
* - "maxTokens": Maximum token limit was reached
|
|
25527
|
+
* - "toolUse": The model wants to use one or more tools
|
|
25528
|
+
*
|
|
25529
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
25530
|
+
*/
|
|
25531
|
+
stopReason: optional(_enum([
|
|
25532
|
+
"endTurn",
|
|
25533
|
+
"stopSequence",
|
|
25534
|
+
"maxTokens",
|
|
25535
|
+
"toolUse"
|
|
25536
|
+
]).or(string())),
|
|
25537
|
+
role: RoleSchema,
|
|
25538
|
+
/**
|
|
25539
|
+
* Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
|
|
25540
|
+
*/
|
|
25541
|
+
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)])
|
|
25542
|
+
});
|
|
25543
|
+
/**
|
|
25544
|
+
* Primitive schema definition for boolean fields.
|
|
25545
|
+
*/
|
|
25546
|
+
const BooleanSchemaSchema = object$1({
|
|
25547
|
+
type: literal("boolean"),
|
|
25548
|
+
title: string().optional(),
|
|
25549
|
+
description: string().optional(),
|
|
25550
|
+
default: boolean().optional()
|
|
25551
|
+
});
|
|
25552
|
+
/**
|
|
25553
|
+
* Primitive schema definition for string fields.
|
|
25554
|
+
*/
|
|
25555
|
+
const StringSchemaSchema = object$1({
|
|
25556
|
+
type: literal("string"),
|
|
25557
|
+
title: string().optional(),
|
|
25558
|
+
description: string().optional(),
|
|
25559
|
+
minLength: number().optional(),
|
|
25560
|
+
maxLength: number().optional(),
|
|
25561
|
+
format: _enum([
|
|
25562
|
+
"email",
|
|
25563
|
+
"uri",
|
|
25564
|
+
"date",
|
|
25565
|
+
"date-time"
|
|
25566
|
+
]).optional(),
|
|
25567
|
+
default: string().optional()
|
|
25568
|
+
});
|
|
25569
|
+
/**
|
|
25570
|
+
* Primitive schema definition for number fields.
|
|
25571
|
+
*/
|
|
25572
|
+
const NumberSchemaSchema = object$1({
|
|
25573
|
+
type: _enum(["number", "integer"]),
|
|
25574
|
+
title: string().optional(),
|
|
25575
|
+
description: string().optional(),
|
|
25576
|
+
minimum: number().optional(),
|
|
25577
|
+
maximum: number().optional(),
|
|
25578
|
+
default: number().optional()
|
|
25579
|
+
});
|
|
25580
|
+
/**
|
|
25581
|
+
* Schema for single-selection enumeration without display titles for options.
|
|
25582
|
+
*/
|
|
25583
|
+
const UntitledSingleSelectEnumSchemaSchema = object$1({
|
|
25584
|
+
type: literal("string"),
|
|
25585
|
+
title: string().optional(),
|
|
25586
|
+
description: string().optional(),
|
|
25587
|
+
enum: array(string()),
|
|
25588
|
+
default: string().optional()
|
|
25589
|
+
});
|
|
25590
|
+
/**
|
|
25591
|
+
* Schema for single-selection enumeration with display titles for each option.
|
|
25592
|
+
*/
|
|
25593
|
+
const TitledSingleSelectEnumSchemaSchema = object$1({
|
|
25594
|
+
type: literal("string"),
|
|
25595
|
+
title: string().optional(),
|
|
25596
|
+
description: string().optional(),
|
|
25597
|
+
oneOf: array(object$1({
|
|
25598
|
+
const: string(),
|
|
25599
|
+
title: string()
|
|
25600
|
+
})),
|
|
25601
|
+
default: string().optional()
|
|
25602
|
+
});
|
|
25603
|
+
/**
|
|
25604
|
+
* Union of all primitive schema definitions.
|
|
25605
|
+
*/
|
|
25606
|
+
const PrimitiveSchemaDefinitionSchema = union([
|
|
25607
|
+
union([
|
|
25608
|
+
object$1({
|
|
25609
|
+
type: literal("string"),
|
|
25610
|
+
title: string().optional(),
|
|
25611
|
+
description: string().optional(),
|
|
25612
|
+
enum: array(string()),
|
|
25613
|
+
enumNames: array(string()).optional(),
|
|
25614
|
+
default: string().optional()
|
|
25615
|
+
}),
|
|
25616
|
+
union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]),
|
|
25617
|
+
union([object$1({
|
|
25618
|
+
type: literal("array"),
|
|
25619
|
+
title: string().optional(),
|
|
25620
|
+
description: string().optional(),
|
|
25621
|
+
minItems: number().optional(),
|
|
25622
|
+
maxItems: number().optional(),
|
|
25623
|
+
items: object$1({
|
|
25624
|
+
type: literal("string"),
|
|
25625
|
+
enum: array(string())
|
|
25626
|
+
}),
|
|
25627
|
+
default: array(string()).optional()
|
|
25628
|
+
}), object$1({
|
|
25629
|
+
type: literal("array"),
|
|
25630
|
+
title: string().optional(),
|
|
25631
|
+
description: string().optional(),
|
|
25632
|
+
minItems: number().optional(),
|
|
25633
|
+
maxItems: number().optional(),
|
|
25634
|
+
items: object$1({ anyOf: array(object$1({
|
|
25635
|
+
const: string(),
|
|
25636
|
+
title: string()
|
|
25637
|
+
})) }),
|
|
25638
|
+
default: array(string()).optional()
|
|
25639
|
+
})])
|
|
25640
|
+
]),
|
|
25641
|
+
BooleanSchemaSchema,
|
|
25642
|
+
StringSchemaSchema,
|
|
25643
|
+
NumberSchemaSchema
|
|
25644
|
+
]);
|
|
25645
|
+
/**
|
|
25646
|
+
* The parameters for a request to elicit additional information from the user via the client.
|
|
25647
|
+
*/
|
|
25648
|
+
const ElicitRequestParamsSchema = union([TaskAugmentedRequestParamsSchema.extend({
|
|
25649
|
+
/**
|
|
25650
|
+
* The elicitation mode.
|
|
25651
|
+
*
|
|
25652
|
+
* Optional for backward compatibility. Clients MUST treat missing mode as "form".
|
|
25653
|
+
*/
|
|
25654
|
+
mode: literal("form").optional(),
|
|
25655
|
+
/**
|
|
25656
|
+
* The message to present to the user describing what information is being requested.
|
|
25657
|
+
*/
|
|
25658
|
+
message: string(),
|
|
25659
|
+
/**
|
|
25660
|
+
* A restricted subset of JSON Schema.
|
|
25661
|
+
* Only top-level properties are allowed, without nesting.
|
|
25662
|
+
*/
|
|
25663
|
+
requestedSchema: object$1({
|
|
25664
|
+
type: literal("object"),
|
|
25665
|
+
properties: record(string(), PrimitiveSchemaDefinitionSchema),
|
|
25666
|
+
required: array(string()).optional()
|
|
25667
|
+
})
|
|
25668
|
+
}), TaskAugmentedRequestParamsSchema.extend({
|
|
25669
|
+
/**
|
|
25670
|
+
* The elicitation mode.
|
|
25671
|
+
*/
|
|
25672
|
+
mode: literal("url"),
|
|
25673
|
+
/**
|
|
25674
|
+
* The message to present to the user explaining why the interaction is needed.
|
|
25675
|
+
*/
|
|
25676
|
+
message: string(),
|
|
25677
|
+
/**
|
|
25678
|
+
* The ID of the elicitation, which must be unique within the context of the server.
|
|
25679
|
+
* The client MUST treat this ID as an opaque value.
|
|
25680
|
+
*/
|
|
25681
|
+
elicitationId: string(),
|
|
25682
|
+
/**
|
|
25683
|
+
* The URL that the user should navigate to.
|
|
25684
|
+
*/
|
|
25685
|
+
url: string().url()
|
|
25686
|
+
})]);
|
|
25687
|
+
/**
|
|
25688
|
+
* A request from the server to elicit user input via the client.
|
|
25689
|
+
* The client should present the message and form fields to the user (form mode)
|
|
25690
|
+
* or navigate to a URL (URL mode).
|
|
25691
|
+
*/
|
|
25692
|
+
const ElicitRequestSchema = RequestSchema.extend({
|
|
25693
|
+
method: literal("elicitation/create"),
|
|
25694
|
+
params: ElicitRequestParamsSchema
|
|
25695
|
+
});
|
|
25696
|
+
/**
|
|
25697
|
+
* Parameters for a `notifications/elicitation/complete` notification.
|
|
25698
|
+
*
|
|
25699
|
+
* @category notifications/elicitation/complete
|
|
25700
|
+
*/
|
|
25701
|
+
const ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
25702
|
+
/**
|
|
25703
|
+
* The ID of the elicitation that completed.
|
|
25704
|
+
*/
|
|
25705
|
+
elicitationId: string() });
|
|
25706
|
+
/**
|
|
25707
|
+
* A notification from the server to the client, informing it of a completion of an out-of-band elicitation request.
|
|
25708
|
+
*
|
|
25709
|
+
* @category notifications/elicitation/complete
|
|
25710
|
+
*/
|
|
25711
|
+
const ElicitationCompleteNotificationSchema = NotificationSchema.extend({
|
|
25712
|
+
method: literal("notifications/elicitation/complete"),
|
|
25713
|
+
params: ElicitationCompleteNotificationParamsSchema
|
|
25714
|
+
});
|
|
25715
|
+
/**
|
|
25716
|
+
* The client's response to an elicitation/create request from the server.
|
|
25717
|
+
*/
|
|
25718
|
+
const ElicitResultSchema = ResultSchema.extend({
|
|
25719
|
+
/**
|
|
25720
|
+
* The user action in response to the elicitation.
|
|
25721
|
+
* - "accept": User submitted the form/confirmed the action
|
|
25722
|
+
* - "decline": User explicitly decline the action
|
|
25723
|
+
* - "cancel": User dismissed without making an explicit choice
|
|
25724
|
+
*/
|
|
25725
|
+
action: _enum([
|
|
25726
|
+
"accept",
|
|
25727
|
+
"decline",
|
|
25728
|
+
"cancel"
|
|
25729
|
+
]),
|
|
25730
|
+
/**
|
|
25731
|
+
* The submitted form data, only present when action is "accept".
|
|
25732
|
+
* Contains values matching the requested schema.
|
|
25733
|
+
* Per MCP spec, content is "typically omitted" for decline/cancel actions.
|
|
25734
|
+
* We normalize null to undefined for leniency while maintaining type compatibility.
|
|
25735
|
+
*/
|
|
25736
|
+
content: preprocess((val) => val === null ? void 0 : val, record(string(), union([
|
|
25737
|
+
string(),
|
|
25738
|
+
number(),
|
|
25739
|
+
boolean(),
|
|
25740
|
+
array(string())
|
|
25741
|
+
])).optional())
|
|
25742
|
+
});
|
|
25743
|
+
/**
|
|
25744
|
+
* A reference to a resource or resource template definition.
|
|
25745
|
+
*/
|
|
25746
|
+
const ResourceTemplateReferenceSchema = object$1({
|
|
25747
|
+
type: literal("ref/resource"),
|
|
25748
|
+
/**
|
|
25749
|
+
* The URI or URI template of the resource.
|
|
25750
|
+
*/
|
|
25751
|
+
uri: string()
|
|
25752
|
+
});
|
|
25753
|
+
/**
|
|
25754
|
+
* Identifies a prompt.
|
|
25755
|
+
*/
|
|
25756
|
+
const PromptReferenceSchema = object$1({
|
|
25757
|
+
type: literal("ref/prompt"),
|
|
25758
|
+
/**
|
|
25759
|
+
* The name of the prompt or prompt template
|
|
25760
|
+
*/
|
|
25761
|
+
name: string()
|
|
25762
|
+
});
|
|
25763
|
+
/**
|
|
25764
|
+
* Parameters for a `completion/complete` request.
|
|
25765
|
+
*/
|
|
25766
|
+
const CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
25767
|
+
ref: union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
|
|
25768
|
+
/**
|
|
25769
|
+
* The argument's information
|
|
25770
|
+
*/
|
|
25771
|
+
argument: object$1({
|
|
25772
|
+
/**
|
|
25773
|
+
* The name of the argument
|
|
25774
|
+
*/
|
|
25775
|
+
name: string(),
|
|
25776
|
+
/**
|
|
25777
|
+
* The value of the argument to use for completion matching.
|
|
25778
|
+
*/
|
|
25779
|
+
value: string()
|
|
25780
|
+
}),
|
|
25781
|
+
context: object$1({
|
|
25782
|
+
/**
|
|
25783
|
+
* Previously-resolved variables in a URI template or prompt.
|
|
25784
|
+
*/
|
|
25785
|
+
arguments: record(string(), string()).optional() }).optional()
|
|
25786
|
+
});
|
|
25787
|
+
/**
|
|
25788
|
+
* A request from the client to the server, to ask for completion options.
|
|
25789
|
+
*/
|
|
25790
|
+
const CompleteRequestSchema = RequestSchema.extend({
|
|
25791
|
+
method: literal("completion/complete"),
|
|
25792
|
+
params: CompleteRequestParamsSchema
|
|
25793
|
+
});
|
|
25794
|
+
/**
|
|
25795
|
+
* The server's response to a completion/complete request
|
|
25796
|
+
*/
|
|
25797
|
+
const CompleteResultSchema = ResultSchema.extend({ completion: looseObject({
|
|
25798
|
+
/**
|
|
25799
|
+
* An array of completion values. Must not exceed 100 items.
|
|
25800
|
+
*/
|
|
25801
|
+
values: array(string()).max(100),
|
|
25802
|
+
/**
|
|
25803
|
+
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
25804
|
+
*/
|
|
25805
|
+
total: optional(number().int()),
|
|
25806
|
+
/**
|
|
25807
|
+
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
25808
|
+
*/
|
|
25809
|
+
hasMore: optional(boolean())
|
|
25810
|
+
}) });
|
|
25811
|
+
/**
|
|
25812
|
+
* Represents a root directory or file that the server can operate on.
|
|
25813
|
+
*/
|
|
25814
|
+
const RootSchema = object$1({
|
|
25815
|
+
/**
|
|
25816
|
+
* The URI identifying the root. This *must* start with file:// for now.
|
|
25817
|
+
*/
|
|
25818
|
+
uri: string().startsWith("file://"),
|
|
25819
|
+
/**
|
|
25820
|
+
* An optional name for the root.
|
|
25821
|
+
*/
|
|
25822
|
+
name: string().optional(),
|
|
25823
|
+
/**
|
|
25824
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
25825
|
+
* for notes on _meta usage.
|
|
25826
|
+
*/
|
|
25827
|
+
_meta: record(string(), unknown()).optional()
|
|
25828
|
+
});
|
|
25829
|
+
/**
|
|
25830
|
+
* Sent from the server to request a list of root URIs from the client.
|
|
25831
|
+
*/
|
|
25832
|
+
const ListRootsRequestSchema = RequestSchema.extend({
|
|
25833
|
+
method: literal("roots/list"),
|
|
25834
|
+
params: BaseRequestParamsSchema.optional()
|
|
25835
|
+
});
|
|
25836
|
+
/**
|
|
25837
|
+
* The client's response to a roots/list request from the server.
|
|
25838
|
+
*/
|
|
25839
|
+
const ListRootsResultSchema = ResultSchema.extend({ roots: array(RootSchema) });
|
|
25840
|
+
/**
|
|
25841
|
+
* A notification from the client to the server, informing it that the list of roots has changed.
|
|
25842
|
+
*/
|
|
25843
|
+
const RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
25844
|
+
method: literal("notifications/roots/list_changed"),
|
|
25845
|
+
params: NotificationsParamsSchema.optional()
|
|
25846
|
+
});
|
|
25847
|
+
union([
|
|
25848
|
+
PingRequestSchema,
|
|
25849
|
+
InitializeRequestSchema,
|
|
25850
|
+
CompleteRequestSchema,
|
|
25851
|
+
SetLevelRequestSchema,
|
|
25852
|
+
GetPromptRequestSchema,
|
|
25853
|
+
ListPromptsRequestSchema,
|
|
25854
|
+
ListResourcesRequestSchema,
|
|
25855
|
+
ListResourceTemplatesRequestSchema,
|
|
25856
|
+
ReadResourceRequestSchema,
|
|
25857
|
+
SubscribeRequestSchema,
|
|
25858
|
+
UnsubscribeRequestSchema,
|
|
25859
|
+
CallToolRequestSchema,
|
|
25860
|
+
ListToolsRequestSchema,
|
|
25861
|
+
GetTaskRequestSchema,
|
|
25862
|
+
GetTaskPayloadRequestSchema,
|
|
25863
|
+
ListTasksRequestSchema,
|
|
25864
|
+
CancelTaskRequestSchema
|
|
25865
|
+
]);
|
|
25866
|
+
union([
|
|
25867
|
+
CancelledNotificationSchema,
|
|
25868
|
+
ProgressNotificationSchema,
|
|
25869
|
+
InitializedNotificationSchema,
|
|
25870
|
+
RootsListChangedNotificationSchema,
|
|
25871
|
+
TaskStatusNotificationSchema
|
|
25872
|
+
]);
|
|
25873
|
+
union([
|
|
25874
|
+
EmptyResultSchema,
|
|
25875
|
+
CreateMessageResultSchema,
|
|
25876
|
+
CreateMessageResultWithToolsSchema,
|
|
25877
|
+
ElicitResultSchema,
|
|
25878
|
+
ListRootsResultSchema,
|
|
25879
|
+
GetTaskResultSchema,
|
|
25880
|
+
ListTasksResultSchema,
|
|
25881
|
+
CreateTaskResultSchema
|
|
25882
|
+
]);
|
|
25883
|
+
union([
|
|
25884
|
+
PingRequestSchema,
|
|
25885
|
+
CreateMessageRequestSchema,
|
|
25886
|
+
ElicitRequestSchema,
|
|
25887
|
+
ListRootsRequestSchema,
|
|
25888
|
+
GetTaskRequestSchema,
|
|
25889
|
+
GetTaskPayloadRequestSchema,
|
|
25890
|
+
ListTasksRequestSchema,
|
|
25891
|
+
CancelTaskRequestSchema
|
|
25892
|
+
]);
|
|
25893
|
+
union([
|
|
25894
|
+
CancelledNotificationSchema,
|
|
25895
|
+
ProgressNotificationSchema,
|
|
25896
|
+
LoggingMessageNotificationSchema,
|
|
25897
|
+
ResourceUpdatedNotificationSchema,
|
|
25898
|
+
ResourceListChangedNotificationSchema,
|
|
25899
|
+
ToolListChangedNotificationSchema,
|
|
25900
|
+
PromptListChangedNotificationSchema,
|
|
25901
|
+
TaskStatusNotificationSchema,
|
|
25902
|
+
ElicitationCompleteNotificationSchema
|
|
25903
|
+
]);
|
|
25904
|
+
union([
|
|
25905
|
+
EmptyResultSchema,
|
|
25906
|
+
InitializeResultSchema,
|
|
25907
|
+
CompleteResultSchema,
|
|
25908
|
+
GetPromptResultSchema,
|
|
25909
|
+
ListPromptsResultSchema,
|
|
25910
|
+
ListResourcesResultSchema,
|
|
25911
|
+
ListResourceTemplatesResultSchema,
|
|
25912
|
+
ReadResourceResultSchema,
|
|
25913
|
+
CallToolResultSchema,
|
|
25914
|
+
ListToolsResultSchema,
|
|
25915
|
+
GetTaskResultSchema,
|
|
25916
|
+
ListTasksResultSchema,
|
|
25917
|
+
CreateTaskResultSchema
|
|
25918
|
+
]);
|
|
25919
|
+
//#endregion
|
|
25920
|
+
//#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
|
|
25921
|
+
const MAXIMUM_MESSAGE_SIZE = 4 * 1024 * 1024;
|
|
25922
|
+
var SSETransport = class {
|
|
25923
|
+
messageUrl;
|
|
25924
|
+
stream;
|
|
25925
|
+
_sessionId;
|
|
25926
|
+
onclose;
|
|
25927
|
+
onerror;
|
|
25928
|
+
onmessage;
|
|
25929
|
+
/**
|
|
25930
|
+
* Creates a new SSETransport, which will direct the MPC client to POST messages to messageUrl
|
|
25931
|
+
*/
|
|
25932
|
+
constructor(messageUrl, stream) {
|
|
25933
|
+
this.messageUrl = messageUrl;
|
|
25934
|
+
this.stream = stream;
|
|
25935
|
+
this._sessionId = crypto.randomUUID();
|
|
25936
|
+
this.stream.onAbort(() => {
|
|
25937
|
+
this.close();
|
|
25938
|
+
});
|
|
25939
|
+
}
|
|
25940
|
+
get sessionId() {
|
|
25941
|
+
return this._sessionId;
|
|
25942
|
+
}
|
|
25943
|
+
async start() {
|
|
25944
|
+
if (this.stream == null) throw new Error("Stream not initialized");
|
|
25945
|
+
if (this.stream.closed) throw new Error("SSE transport already closed!");
|
|
25946
|
+
await this.stream.writeSSE({
|
|
25947
|
+
event: "ping",
|
|
25948
|
+
data: ""
|
|
25949
|
+
});
|
|
25950
|
+
await this.stream.writeSSE({
|
|
25951
|
+
event: "endpoint",
|
|
25952
|
+
data: `${this.messageUrl}?sessionId=${this.sessionId}`
|
|
25953
|
+
});
|
|
25954
|
+
}
|
|
25955
|
+
async handlePostMessage(context) {
|
|
25956
|
+
if (this.stream?.closed == null) return context.text("SSE connection not established", 500);
|
|
25957
|
+
try {
|
|
25958
|
+
const contentType = context.req.header("content-type") || "";
|
|
25959
|
+
if (!contentType.includes("application/json")) throw new Error(`Unsupported content-type: ${contentType}`);
|
|
25960
|
+
const contentLength = Number.parseInt(context.req.header("content-length") || "0", 10);
|
|
25961
|
+
if (contentLength > MAXIMUM_MESSAGE_SIZE) throw new Error(`Request body too large: ${contentLength} bytes`);
|
|
25962
|
+
const body = await context.req.json();
|
|
25963
|
+
await this.handleMessage(body);
|
|
25964
|
+
return context.text("Accepted", 202);
|
|
25965
|
+
} catch (error) {
|
|
25966
|
+
this.onerror?.(error);
|
|
25967
|
+
return context.text("Error", 400);
|
|
25968
|
+
}
|
|
25969
|
+
}
|
|
25970
|
+
/**
|
|
25971
|
+
* 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.
|
|
25972
|
+
*/
|
|
25973
|
+
async handleMessage(message) {
|
|
25974
|
+
let parsedMessage;
|
|
25975
|
+
try {
|
|
25976
|
+
parsedMessage = JSONRPCMessageSchema.parse(message);
|
|
25977
|
+
} catch (error) {
|
|
25978
|
+
this.onerror?.(error);
|
|
25979
|
+
throw error;
|
|
25980
|
+
}
|
|
25981
|
+
this.onmessage?.(parsedMessage);
|
|
25982
|
+
}
|
|
25983
|
+
async close() {
|
|
25984
|
+
if (this.stream?.closed) this.stream.abort();
|
|
25985
|
+
}
|
|
25986
|
+
async send(message) {
|
|
25987
|
+
if (this.stream?.closed) throw new Error("Not connected");
|
|
25988
|
+
await this.stream.writeSSE({
|
|
25989
|
+
event: "message",
|
|
25990
|
+
data: JSON.stringify(message)
|
|
25991
|
+
});
|
|
25992
|
+
}
|
|
25993
|
+
};
|
|
25994
|
+
//#endregion
|
|
25995
|
+
//#region src/server/notificationBroadcast.ts
|
|
25996
|
+
/**
|
|
25997
|
+
* Sends a notification to every active server instance (the main stdio/SSE
|
|
25998
|
+
* instance plus each streamable HTTP session instance).
|
|
25999
|
+
*
|
|
26000
|
+
* Failures are aggregated: if only some instances fail, the failure is logged
|
|
26001
|
+
* and the broadcast is considered best-effort. A `MastraError` is thrown only
|
|
26002
|
+
* when every send fails.
|
|
26003
|
+
*
|
|
26004
|
+
* Note: clients connected in stateless/serverless mode cannot receive
|
|
26005
|
+
* notifications because each request uses a transient server instance.
|
|
26006
|
+
*
|
|
26007
|
+
* @internal
|
|
26008
|
+
*/
|
|
26009
|
+
async function broadcastNotification({ servers, send, logger, errorId, errorText, errorDetails }) {
|
|
26010
|
+
const errors = [];
|
|
26011
|
+
for (const server of servers) try {
|
|
26012
|
+
await send(server);
|
|
26013
|
+
} catch (error) {
|
|
26014
|
+
errors.push(error);
|
|
26015
|
+
}
|
|
26016
|
+
if (errors.length === 0) return;
|
|
26017
|
+
const mastraError = new MastraError({
|
|
26018
|
+
id: errorId,
|
|
26019
|
+
domain: ErrorDomain.MCP,
|
|
26020
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
26021
|
+
text: errorText,
|
|
26022
|
+
details: {
|
|
26023
|
+
...errorDetails,
|
|
26024
|
+
failedInstances: errors.length,
|
|
26025
|
+
totalInstances: servers.length
|
|
26026
|
+
}
|
|
26027
|
+
}, errors[0]);
|
|
26028
|
+
logger.error(`${errorText}:`, { error: mastraError.toString() });
|
|
26029
|
+
if (errors.length === servers.length) {
|
|
26030
|
+
logger.trackException(mastraError);
|
|
26031
|
+
throw mastraError;
|
|
26032
|
+
}
|
|
26033
|
+
}
|
|
26034
|
+
//#endregion
|
|
26035
|
+
//#region src/server/promptActions.ts
|
|
26036
|
+
/**
|
|
26037
|
+
* Server-side prompt actions for notifying clients about prompt changes.
|
|
26038
|
+
*
|
|
26039
|
+
* This class provides methods for MCP servers to notify connected clients when
|
|
26040
|
+
* the list of available prompts changes.
|
|
26041
|
+
*
|
|
26042
|
+
* Notifications are broadcast to every active server instance (the main
|
|
26043
|
+
* stdio/SSE instance plus each streamable HTTP session). Clients connected in
|
|
26044
|
+
* stateless/serverless mode cannot receive notifications because each request
|
|
26045
|
+
* uses a transient server instance.
|
|
26046
|
+
*/
|
|
26047
|
+
var ServerPromptActions = class {
|
|
26048
|
+
getLogger;
|
|
26049
|
+
getSdkServers;
|
|
26050
|
+
clearDefinedPrompts;
|
|
26051
|
+
/**
|
|
26052
|
+
* @internal
|
|
26053
|
+
*/
|
|
26054
|
+
constructor(dependencies) {
|
|
26055
|
+
this.getLogger = dependencies.getLogger;
|
|
26056
|
+
this.getSdkServers = dependencies.getSdkServers;
|
|
26057
|
+
this.clearDefinedPrompts = dependencies.clearDefinedPrompts;
|
|
26058
|
+
}
|
|
26059
|
+
/**
|
|
26060
|
+
* Notifies clients that the overall list of available prompts has changed.
|
|
26061
|
+
*
|
|
26062
|
+
* This clears the internal prompt cache and sends a `notifications/prompts/list_changed`
|
|
26063
|
+
* message to all clients, prompting them to re-fetch the prompt list.
|
|
26064
|
+
*
|
|
26065
|
+
* @throws {MastraError} If sending the notification fails on all server instances
|
|
26066
|
+
*
|
|
26067
|
+
* @example
|
|
26068
|
+
* ```typescript
|
|
26069
|
+
* // After adding or modifying prompts
|
|
26070
|
+
* await server.prompts.notifyListChanged();
|
|
26071
|
+
* ```
|
|
26072
|
+
*/
|
|
26073
|
+
async notifyListChanged() {
|
|
26074
|
+
this.getLogger().info("Prompt list change externally notified. Clearing definedPrompts and sending notification.");
|
|
26075
|
+
this.clearDefinedPrompts();
|
|
23942
26076
|
await broadcastNotification({
|
|
23943
26077
|
servers: this.getSdkServers(),
|
|
23944
26078
|
send: (server) => server.sendPromptListChanged(),
|
|
@@ -24125,6 +26259,25 @@ var ServerToolActions = class {
|
|
|
24125
26259
|
};
|
|
24126
26260
|
//#endregion
|
|
24127
26261
|
//#region src/server/server.ts
|
|
26262
|
+
/**
|
|
26263
|
+
* Flattens the MCP `ServerContext` into the shape Mastra tools receive as `extra`.
|
|
26264
|
+
*
|
|
26265
|
+
* MCP 2.0 nests per-request plumbing under `ctx.mcpReq` and transport details under
|
|
26266
|
+
* `ctx.http`, while Mastra tools have always read `signal`, `requestId`, `authInfo`,
|
|
26267
|
+
* `sendNotification`, `sendRequest`, and `_meta` off the top level. Both the nested and
|
|
26268
|
+
* flattened members are kept so tools written against either shape keep working.
|
|
26269
|
+
*/
|
|
26270
|
+
const toMCPRequestHandlerExtra = (ctx) => {
|
|
26271
|
+
return {
|
|
26272
|
+
...ctx,
|
|
26273
|
+
signal: ctx.mcpReq.signal,
|
|
26274
|
+
requestId: ctx.mcpReq.id,
|
|
26275
|
+
authInfo: ctx.http?.authInfo,
|
|
26276
|
+
sendNotification: ctx.mcpReq.notify,
|
|
26277
|
+
sendRequest: ctx.mcpReq.send,
|
|
26278
|
+
_meta: ctx.mcpReq._meta
|
|
26279
|
+
};
|
|
26280
|
+
};
|
|
24128
26281
|
const LOG_LEVEL_SEVERITY = {
|
|
24129
26282
|
debug: 0,
|
|
24130
26283
|
info: 1,
|
|
@@ -24271,11 +26424,11 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24271
26424
|
return this.sseHonoTransports.get(sessionId);
|
|
24272
26425
|
}
|
|
24273
26426
|
/**
|
|
24274
|
-
* Gets the underlying MCP
|
|
26427
|
+
* Gets the underlying MCP Server instance.
|
|
24275
26428
|
*
|
|
24276
26429
|
* This provides access to the low-level server instance for advanced use cases.
|
|
24277
26430
|
*
|
|
24278
|
-
* @returns The Server instance from @modelcontextprotocol/
|
|
26431
|
+
* @returns The Server instance from @modelcontextprotocol/server
|
|
24279
26432
|
*/
|
|
24280
26433
|
getServer() {
|
|
24281
26434
|
return this.server;
|
|
@@ -24645,8 +26798,8 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24645
26798
|
* This allows us to create multiple server instances with identical functionality.
|
|
24646
26799
|
*/
|
|
24647
26800
|
registerHandlersOnServer(serverInstance) {
|
|
24648
|
-
serverInstance.setRequestHandler(
|
|
24649
|
-
const proxiedContext = await this.createProxiedRequestContext(
|
|
26801
|
+
serverInstance.setRequestHandler("tools/list", async (_request, ctx) => {
|
|
26802
|
+
const proxiedContext = await this.createProxiedRequestContext(toMCPRequestHandlerExtra(ctx));
|
|
24650
26803
|
return { tools: (await this.getAuthorizedConvertedToolEntries(proxiedContext)).map(([, tool]) => {
|
|
24651
26804
|
const toolSpec = {
|
|
24652
26805
|
name: tool.id || "unknown",
|
|
@@ -24675,8 +26828,9 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24675
26828
|
return toolSpec;
|
|
24676
26829
|
}) };
|
|
24677
26830
|
});
|
|
24678
|
-
serverInstance.setRequestHandler(
|
|
26831
|
+
serverInstance.setRequestHandler("tools/call", async (request, ctx) => {
|
|
24679
26832
|
const startTime = Date.now();
|
|
26833
|
+
const extra = toMCPRequestHandlerExtra(ctx);
|
|
24680
26834
|
try {
|
|
24681
26835
|
const tool = this.convertedTools[request.params.name];
|
|
24682
26836
|
if (!tool) {
|
|
@@ -24844,7 +26998,7 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24844
26998
|
};
|
|
24845
26999
|
}
|
|
24846
27000
|
});
|
|
24847
|
-
serverInstance.setRequestHandler(
|
|
27001
|
+
serverInstance.setRequestHandler("logging/setLevel", async (request) => {
|
|
24848
27002
|
this.loggingLevels.set(serverInstance, request.params.level);
|
|
24849
27003
|
this.logger.debug("Logging level set", { level: request.params.level });
|
|
24850
27004
|
return {};
|
|
@@ -24858,9 +27012,9 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24858
27012
|
registerResourceHandlersOnServer(serverInstance) {
|
|
24859
27013
|
const capturedResourceOptions = this.resourceOptions;
|
|
24860
27014
|
if (!capturedResourceOptions) return;
|
|
24861
|
-
if (capturedResourceOptions.listResources) serverInstance.setRequestHandler(
|
|
27015
|
+
if (capturedResourceOptions.listResources) serverInstance.setRequestHandler("resources/list", async (_request, ctx) => {
|
|
24862
27016
|
try {
|
|
24863
|
-
const resources = await capturedResourceOptions.listResources({ extra });
|
|
27017
|
+
const resources = await capturedResourceOptions.listResources({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24864
27018
|
this.logger.debug("Fetched resources", { count: resources.length });
|
|
24865
27019
|
return { resources };
|
|
24866
27020
|
} catch (error) {
|
|
@@ -24868,21 +27022,21 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24868
27022
|
throw error;
|
|
24869
27023
|
}
|
|
24870
27024
|
});
|
|
24871
|
-
if (capturedResourceOptions.getResourceContent) serverInstance.setRequestHandler(
|
|
27025
|
+
if (capturedResourceOptions.getResourceContent) serverInstance.setRequestHandler("resources/read", async (request, ctx) => {
|
|
24872
27026
|
const startTime = Date.now();
|
|
24873
27027
|
const uri = request.params.uri;
|
|
24874
27028
|
this.logger.debug("Handling ReadResource request", { uri });
|
|
24875
|
-
const resources = await capturedResourceOptions.listResources?.({ extra });
|
|
27029
|
+
const resources = await capturedResourceOptions.listResources?.({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24876
27030
|
if (!resources) throw new Error("Failed to load resources");
|
|
24877
27031
|
const resource = resources.find((r) => r.uri === uri);
|
|
24878
27032
|
if (!resource) {
|
|
24879
27033
|
this.logger.warn("Unknown resource URI requested", { uri });
|
|
24880
|
-
throw new
|
|
27034
|
+
throw new ProtocolError(ProtocolErrorCode$1.InvalidParams, `Resource not found: ${uri}`);
|
|
24881
27035
|
}
|
|
24882
27036
|
try {
|
|
24883
27037
|
const resourcesOrResourceContent = await capturedResourceOptions.getResourceContent({
|
|
24884
27038
|
uri,
|
|
24885
|
-
extra
|
|
27039
|
+
extra: toMCPRequestHandlerExtra(ctx)
|
|
24886
27040
|
});
|
|
24887
27041
|
const resourcesContent = Array.isArray(resourcesOrResourceContent) ? resourcesOrResourceContent : [resourcesOrResourceContent];
|
|
24888
27042
|
const resourceMeta = resource._meta ? { _meta: resource._meta } : {};
|
|
@@ -24918,9 +27072,9 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24918
27072
|
throw error;
|
|
24919
27073
|
}
|
|
24920
27074
|
});
|
|
24921
|
-
if (capturedResourceOptions.resourceTemplates) serverInstance.setRequestHandler(
|
|
27075
|
+
if (capturedResourceOptions.resourceTemplates) serverInstance.setRequestHandler("resources/templates/list", async (_request, ctx) => {
|
|
24922
27076
|
try {
|
|
24923
|
-
const templates = await capturedResourceOptions.resourceTemplates({ extra });
|
|
27077
|
+
const templates = await capturedResourceOptions.resourceTemplates({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24924
27078
|
this.logger.debug("Fetched resource templates", { count: templates.length });
|
|
24925
27079
|
return { resourceTemplates: templates };
|
|
24926
27080
|
} catch (error) {
|
|
@@ -24928,7 +27082,7 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24928
27082
|
throw error;
|
|
24929
27083
|
}
|
|
24930
27084
|
});
|
|
24931
|
-
serverInstance.setRequestHandler(
|
|
27085
|
+
serverInstance.setRequestHandler("resources/subscribe", async (request) => {
|
|
24932
27086
|
const uri = request.params.uri;
|
|
24933
27087
|
this.logger.info("Received resources/subscribe request", { uri });
|
|
24934
27088
|
let subscriptions = this.subscriptionsByInstance.get(serverInstance);
|
|
@@ -24939,7 +27093,7 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24939
27093
|
subscriptions.add(uri);
|
|
24940
27094
|
return {};
|
|
24941
27095
|
});
|
|
24942
|
-
serverInstance.setRequestHandler(
|
|
27096
|
+
serverInstance.setRequestHandler("resources/unsubscribe", async (request) => {
|
|
24943
27097
|
const uri = request.params.uri;
|
|
24944
27098
|
this.logger.info("Received resources/unsubscribe request", { uri });
|
|
24945
27099
|
this.subscriptionsByInstance.get(serverInstance)?.delete(uri);
|
|
@@ -24952,11 +27106,11 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24952
27106
|
registerPromptHandlersOnServer(serverInstance) {
|
|
24953
27107
|
const capturedPromptOptions = this.promptOptions;
|
|
24954
27108
|
if (!capturedPromptOptions) return;
|
|
24955
|
-
if (capturedPromptOptions.listPrompts) serverInstance.setRequestHandler(
|
|
27109
|
+
if (capturedPromptOptions.listPrompts) serverInstance.setRequestHandler("prompts/list", async (_request, ctx) => {
|
|
24956
27110
|
this.logger.debug("Handling ListPrompts request");
|
|
24957
27111
|
if (this.definedPrompts) return { prompts: this.definedPrompts };
|
|
24958
27112
|
else try {
|
|
24959
|
-
const prompts = await capturedPromptOptions.listPrompts({ extra });
|
|
27113
|
+
const prompts = await capturedPromptOptions.listPrompts({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24960
27114
|
for (const prompt of prompts) PromptSchema.parse(prompt);
|
|
24961
27115
|
this.definedPrompts = prompts;
|
|
24962
27116
|
this.logger.debug("Fetched and cached prompts", { count: this.definedPrompts.length });
|
|
@@ -24966,18 +27120,18 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24966
27120
|
throw error;
|
|
24967
27121
|
}
|
|
24968
27122
|
});
|
|
24969
|
-
if (capturedPromptOptions.getPromptMessages) serverInstance.setRequestHandler(
|
|
27123
|
+
if (capturedPromptOptions.getPromptMessages) serverInstance.setRequestHandler("prompts/get", async (request, ctx) => {
|
|
24970
27124
|
const startTime = Date.now();
|
|
24971
27125
|
const { name, arguments: args } = request.params;
|
|
24972
27126
|
if (!this.definedPrompts) {
|
|
24973
|
-
const prompts = await this.promptOptions?.listPrompts?.({ extra });
|
|
27127
|
+
const prompts = await this.promptOptions?.listPrompts?.({ extra: toMCPRequestHandlerExtra(ctx) });
|
|
24974
27128
|
if (!prompts) throw new Error("Failed to load prompts");
|
|
24975
27129
|
this.definedPrompts = prompts;
|
|
24976
27130
|
}
|
|
24977
27131
|
const prompt = this.definedPrompts?.find((p) => p.name === name);
|
|
24978
27132
|
if (!prompt) throw new Error(`Prompt "${name}" not found`);
|
|
24979
27133
|
if (prompt.arguments) {
|
|
24980
|
-
for (const arg of prompt.arguments) if (arg.required && (args?.[arg.name] === void 0 || args?.[arg.name] === null)) throw new
|
|
27134
|
+
for (const arg of prompt.arguments) if (arg.required && (args?.[arg.name] === void 0 || args?.[arg.name] === null)) throw new ProtocolError(ProtocolErrorCode$1.InvalidParams, `Missing required argument: ${arg.name}`);
|
|
24981
27135
|
}
|
|
24982
27136
|
try {
|
|
24983
27137
|
let messages = [];
|
|
@@ -24985,7 +27139,7 @@ var MCPServer = class extends MCPServerBase {
|
|
|
24985
27139
|
name,
|
|
24986
27140
|
version: prompt.version,
|
|
24987
27141
|
args,
|
|
24988
|
-
extra
|
|
27142
|
+
extra: toMCPRequestHandlerExtra(ctx)
|
|
24989
27143
|
});
|
|
24990
27144
|
const duration = Date.now() - startTime;
|
|
24991
27145
|
this.logger.info("Prompt retrieved successfully", {
|
|
@@ -25496,11 +27650,11 @@ var MCPServer = class extends MCPServerBase {
|
|
|
25496
27650
|
this.logger.debug("No session ID provided", { method: req.method });
|
|
25497
27651
|
if (req.method === "POST") {
|
|
25498
27652
|
const body = await this.readJsonBody(req);
|
|
25499
|
-
const { isInitializeRequest } = await import("@modelcontextprotocol/
|
|
27653
|
+
const { isInitializeRequest } = await import("@modelcontextprotocol/server");
|
|
25500
27654
|
if (isInitializeRequest(body)) {
|
|
25501
27655
|
this.logger.debug("Received initialize request, creating new transport");
|
|
25502
27656
|
const sessionServerInstance = this.createServerInstance();
|
|
25503
|
-
transport = new
|
|
27657
|
+
transport = new NodeStreamableHTTPServerTransport({
|
|
25504
27658
|
...mergedOptions,
|
|
25505
27659
|
sessionIdGenerator: mergedOptions.sessionIdGenerator,
|
|
25506
27660
|
onsessioninitialized: (id) => {
|
|
@@ -25597,7 +27751,7 @@ var MCPServer = class extends MCPServerBase {
|
|
|
25597
27751
|
enableJsonResponse
|
|
25598
27752
|
});
|
|
25599
27753
|
const transientServer = this.createServerInstance();
|
|
25600
|
-
const tempTransport = new
|
|
27754
|
+
const tempTransport = new NodeStreamableHTTPServerTransport({
|
|
25601
27755
|
sessionIdGenerator: void 0,
|
|
25602
27756
|
enableJsonResponse
|
|
25603
27757
|
});
|
|
@@ -25838,8 +27992,12 @@ var MCPServer = class extends MCPServerBase {
|
|
|
25838
27992
|
};
|
|
25839
27993
|
}
|
|
25840
27994
|
convertSchema(schema) {
|
|
25841
|
-
|
|
25842
|
-
|
|
27995
|
+
const jsonSchema = isStandardSchemaWithJSON(schema) ? standardSchemaToJSONSchema(schema) : schema?.jsonSchema ?? schema;
|
|
27996
|
+
if (jsonSchema && typeof jsonSchema === "object" && "$schema" in jsonSchema) {
|
|
27997
|
+
const { $schema: _dialect, ...rest } = jsonSchema;
|
|
27998
|
+
return rest;
|
|
27999
|
+
}
|
|
28000
|
+
return jsonSchema;
|
|
25843
28001
|
}
|
|
25844
28002
|
/**
|
|
25845
28003
|
* Gets a list of all tools provided by this MCP server with their schemas.
|
|
@@ -25929,6 +28087,8 @@ var MCPServer = class extends MCPServerBase {
|
|
|
25929
28087
|
Object.entries(extraRecord).forEach(([key, value]) => {
|
|
25930
28088
|
proxiedContext.set(key, value);
|
|
25931
28089
|
});
|
|
28090
|
+
const http = extraRecord.http;
|
|
28091
|
+
if (http && typeof http === "object" && "authInfo" in http) proxiedContext.set("authInfo", http.authInfo);
|
|
25932
28092
|
}
|
|
25933
28093
|
await this.resolveMappedFGAUser(proxiedContext, extraRecord);
|
|
25934
28094
|
return proxiedContext;
|