@agentcomms/resend 0.16.0 → 0.18.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/THIRD_PARTY_LICENSES +9 -9
- package/dist/cli.mjs +13 -5
- package/dist/{dist-COPefvtq-COGS2a-K.mjs → dist-C7DG2LdL-l0mj9_dH.mjs} +55 -33
- package/dist/index.d.mts +141 -33
- package/dist/index.mjs +2 -2
- package/dist/{mcp-DXXb3Vv3-kCxsVLO4.mjs → mcp-DIH4cS6P-CIWWZQbz.mjs} +181 -68
- package/dist/{send-BwyJM23a.mjs → send-D-SXJezp.mjs} +1255 -228
- package/dist/{server-BFAo5PpV.mjs → server-BZOLLDTu.mjs} +6 -6
- package/dist/{src-D_zzAWoS-BhK0GFdq-oo-8IJem.mjs → src-WCy6ifGf-DXrNj-15-D0oRtifb.mjs} +75 -41
- package/dist/{stdio-q4c3585j.mjs → stdio-B8UXEGiG.mjs} +28 -3
- package/dist/{stdio-CHZ2WRcx-B2_wGdA5.mjs → stdio-CyjIgrch-59zcjSEt.mjs} +9 -3
- package/dist/{stdio-entry-BGq1Q5V_.mjs → stdio-entry-DcVZBKOq.mjs} +1 -1
- package/package.json +5 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as unknown, E as toJSONSchema, O as NEVER, S as union, T as safeParse, _ as optional, a as _null, c as boolean, d as intersection, f as lazy, g as object, h as number, i as _enum, l as discriminatedUnion, m as looseObject, n as datetime, o as any, p as literal, s as array, t as date, u as email, v as preprocess, w as url, x as string, y as record } from "./iso-USuVU_sk.mjs";
|
|
2
2
|
import { n as ZodIssueCode, t as number$1 } from "./coerce-CqGigABD.mjs";
|
|
3
3
|
import process$1 from "node:process";
|
|
4
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+server@2.
|
|
4
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+server@2.3.1/node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
5
5
|
var __create = Object.create;
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
7
7
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -33,7 +33,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
33
|
enumerable: true
|
|
34
34
|
}) : target, mod));
|
|
35
35
|
//#endregion
|
|
36
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+server@2.
|
|
36
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+server@2.3.1/node_modules/@modelcontextprotocol/server/dist/dialects-DoSzNhcb.mjs
|
|
37
37
|
/**
|
|
38
38
|
* Canonical `$schema` URIs per supported dialect (http + https variants, trailing-`#` stripped).
|
|
39
39
|
*/
|
|
@@ -1552,7 +1552,8 @@ const OAuthMetadataSchema = looseObject({
|
|
|
1552
1552
|
introspection_endpoint_auth_signing_alg_values_supported: array(string()).optional(),
|
|
1553
1553
|
code_challenge_methods_supported: array(string()).optional(),
|
|
1554
1554
|
client_id_metadata_document_supported: boolean().optional(),
|
|
1555
|
-
authorization_response_iss_parameter_supported: boolean().optional().catch(void 0)
|
|
1555
|
+
authorization_response_iss_parameter_supported: boolean().optional().catch(void 0),
|
|
1556
|
+
dpop_signing_alg_values_supported: array(string()).optional()
|
|
1556
1557
|
});
|
|
1557
1558
|
/**
|
|
1558
1559
|
* OpenID Connect Discovery 1.0 Provider Metadata
|
|
@@ -1616,7 +1617,8 @@ const OAuthTokensSchema = object({
|
|
|
1616
1617
|
token_type: string(),
|
|
1617
1618
|
expires_in: number$1().optional(),
|
|
1618
1619
|
scope: string().optional(),
|
|
1619
|
-
refresh_token: string().optional()
|
|
1620
|
+
refresh_token: string().optional(),
|
|
1621
|
+
issuer: string().optional().catch(void 0)
|
|
1620
1622
|
}).strip();
|
|
1621
1623
|
/**
|
|
1622
1624
|
* RFC 8693 §2.2.1 Token Exchange response for ID-JAG tokens.
|
|
@@ -1673,7 +1675,8 @@ const OAuthClientInformationSchema = object({
|
|
|
1673
1675
|
client_id: string(),
|
|
1674
1676
|
client_secret: string().optional(),
|
|
1675
1677
|
client_id_issued_at: number().optional(),
|
|
1676
|
-
client_secret_expires_at: number().optional()
|
|
1678
|
+
client_secret_expires_at: number().optional(),
|
|
1679
|
+
issuer: string().optional().catch(void 0)
|
|
1677
1680
|
}).strip();
|
|
1678
1681
|
/**
|
|
1679
1682
|
* RFC 7591 OAuth 2.0 Dynamic Client Registration full response (client information plus metadata)
|
|
@@ -1694,7 +1697,7 @@ const OAuthTokenRevocationRequestSchema = object({
|
|
|
1694
1697
|
token_type_hint: string().optional()
|
|
1695
1698
|
}).strip();
|
|
1696
1699
|
//#endregion
|
|
1697
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+server@2.
|
|
1700
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+server@2.3.1/node_modules/@modelcontextprotocol/server/dist/src-Cqbh3MYc.mjs
|
|
1698
1701
|
/**
|
|
1699
1702
|
* Cross-bundle `instanceof` support for the SDK error classes.
|
|
1700
1703
|
*
|
|
@@ -1959,8 +1962,18 @@ var SdkError = class extends Error {
|
|
|
1959
1962
|
if (typeof this !== "function") throw new TypeError("isInstance must be called on the class (e.g. `SdkError.isInstance(value)`); for callbacks use `v => SdkError.isInstance(v)`");
|
|
1960
1963
|
return brandedHasInstance(this, value);
|
|
1961
1964
|
}
|
|
1962
|
-
|
|
1963
|
-
|
|
1965
|
+
/**
|
|
1966
|
+
* @param code - Stable string code identifying the failure ({@linkcode SdkErrorCode}).
|
|
1967
|
+
* @param message - Human-readable description.
|
|
1968
|
+
* @param data - Optional structured payload (for example the HTTP status carried by
|
|
1969
|
+
* {@linkcode SdkHttpError}). Opaque to the SDK: a `cause` key inside `data` is not
|
|
1970
|
+
* promoted to `Error.cause`.
|
|
1971
|
+
* @param options - Standard `ErrorOptions`, forwarded to `Error`. Pass the underlying
|
|
1972
|
+
* failure as `{ cause }` so it is reachable through the `Error.cause` chain that
|
|
1973
|
+
* loggers and error trackers walk.
|
|
1974
|
+
*/
|
|
1975
|
+
constructor(code, message, data, options) {
|
|
1976
|
+
super(message, options);
|
|
1964
1977
|
this.code = code;
|
|
1965
1978
|
this.data = data;
|
|
1966
1979
|
this.name = "SdkError";
|
|
@@ -1987,8 +2000,11 @@ var SdkHttpError = class extends SdkError {
|
|
|
1987
2000
|
static {
|
|
1988
2001
|
Object.defineProperty(this, "mcpBrand", { value: "mcp.SdkHttpError" });
|
|
1989
2002
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
2003
|
+
/**
|
|
2004
|
+
* @param options - Standard `ErrorOptions`, forwarded to `Error` (see {@linkcode SdkError}).
|
|
2005
|
+
*/
|
|
2006
|
+
constructor(code, message, data, options) {
|
|
2007
|
+
super(code, message, data, options);
|
|
1992
2008
|
this.name = "SdkHttpError";
|
|
1993
2009
|
}
|
|
1994
2010
|
get status() {
|
|
@@ -4643,7 +4659,7 @@ function build() {
|
|
|
4643
4659
|
const subscriptionsListenParamsShape = { notifications: SubscriptionFilterSchema$1 };
|
|
4644
4660
|
const SubscriptionsListenRequestSchema$1 = wireRequest("subscriptions/listen", subscriptionsListenParamsShape);
|
|
4645
4661
|
/**
|
|
4646
|
-
* Anchor
|
|
4662
|
+
* Anchor SubscriptionsListenResultMetaObject — required subscriptionId stamp on
|
|
4647
4663
|
* the graceful-close result. Extends `ResultMetaObject` since spec PR
|
|
4648
4664
|
* #3002 (composed, so the serverInfo key and its leniency stay single-sourced).
|
|
4649
4665
|
*/
|
|
@@ -4916,7 +4932,8 @@ function build() {
|
|
|
4916
4932
|
ListResourceTemplatesResultResponseSchema: wireResultResponse(ListResourceTemplatesResultSchema$1),
|
|
4917
4933
|
ReadResourceResultResponseSchema: wireResultResponse(union([ReadResourceResultSchema$1, InputRequiredResultSchema])),
|
|
4918
4934
|
CompleteResultResponseSchema: wireResultResponse(CompleteResultSchema$1),
|
|
4919
|
-
DiscoverResultResponseSchema: wireResultResponse(DiscoverResultSchema$1)
|
|
4935
|
+
DiscoverResultResponseSchema: wireResultResponse(DiscoverResultSchema$1),
|
|
4936
|
+
SubscriptionsListenResultResponseSchema: wireResultResponse(SubscriptionsListenResultSchema$1)
|
|
4920
4937
|
};
|
|
4921
4938
|
}
|
|
4922
4939
|
let memo;
|
|
@@ -5549,6 +5566,8 @@ const rev2026Codec = {
|
|
|
5549
5566
|
const rawInputRequests = raw["inputRequests"];
|
|
5550
5567
|
const inputRequests = isPlainObject$4(rawInputRequests) ? rawInputRequests : {};
|
|
5551
5568
|
const requestState = raw["requestState"];
|
|
5569
|
+
const metaParse = raw["_meta"] === void 0 ? void 0 : buildSchemas2026().ResultMetaSchema.safeParse(raw["_meta"]);
|
|
5570
|
+
const meta = metaParse?.success ? metaParse.data : void 0;
|
|
5552
5571
|
if (Object.keys(inputRequests).length === 0 && typeof requestState !== "string") return {
|
|
5553
5572
|
kind: "invalid",
|
|
5554
5573
|
error: new SdkError(SdkErrorCode.InvalidResult, `Invalid result for ${method}: input_required carries neither inputRequests nor requestState (every input_required result must include at least one of the two)`, {
|
|
@@ -5559,7 +5578,8 @@ const rev2026Codec = {
|
|
|
5559
5578
|
return {
|
|
5560
5579
|
kind: "input_required",
|
|
5561
5580
|
inputRequests,
|
|
5562
|
-
...typeof requestState === "string" && { requestState }
|
|
5581
|
+
...typeof requestState === "string" && { requestState },
|
|
5582
|
+
...meta !== void 0 && { _meta: meta }
|
|
5563
5583
|
};
|
|
5564
5584
|
}
|
|
5565
5585
|
if (rawResultType !== "complete") return {
|
|
@@ -5657,6 +5677,10 @@ function isSpecRequestMethod(method) {
|
|
|
5657
5677
|
function isSpecNotificationMethod(method) {
|
|
5658
5678
|
return ALL_CODECS.some((codec) => codec.hasNotificationMethod(method));
|
|
5659
5679
|
}
|
|
5680
|
+
/** The names SEP-2663 re-defines for the Tasks extension on the era that removed them from core. */
|
|
5681
|
+
function isExtensionReusedRequestMethod(method) {
|
|
5682
|
+
return method === "tasks/get" || method === "tasks/cancel";
|
|
5683
|
+
}
|
|
5660
5684
|
const ALL_CODECS = [rev2025Codec, rev2026Codec];
|
|
5661
5685
|
var schemas_exports = /* @__PURE__ */ __exportAll({
|
|
5662
5686
|
AnnotationsSchema: () => AnnotationsSchema,
|
|
@@ -6688,6 +6712,8 @@ var Protocol = class {
|
|
|
6688
6712
|
_transport;
|
|
6689
6713
|
_requestMessageId = 0;
|
|
6690
6714
|
_requestHandlers = /* @__PURE__ */ new Map();
|
|
6715
|
+
/** Methods registered with an explicit schema; the era gate in `_onrequest` reads it for the Tasks extension names. */
|
|
6716
|
+
_customSchemaRequestMethods = /* @__PURE__ */ new Set();
|
|
6691
6717
|
_requestHandlerAbortControllers = /* @__PURE__ */ new Map();
|
|
6692
6718
|
_notificationHandlers = /* @__PURE__ */ new Map();
|
|
6693
6719
|
_responseHandlers = /* @__PURE__ */ new Map();
|
|
@@ -6818,7 +6844,7 @@ var Protocol = class {
|
|
|
6818
6844
|
return this._requestHandlers.get(method);
|
|
6819
6845
|
}
|
|
6820
6846
|
async _oncancel(notification) {
|
|
6821
|
-
if (
|
|
6847
|
+
if (notification.params.requestId === void 0) return;
|
|
6822
6848
|
this._requestHandlerAbortControllers.get(notification.params.requestId)?.abort(notification.params.reason);
|
|
6823
6849
|
}
|
|
6824
6850
|
_setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
@@ -6965,7 +6991,7 @@ var Protocol = class {
|
|
|
6965
6991
|
return;
|
|
6966
6992
|
}
|
|
6967
6993
|
}
|
|
6968
|
-
if (isSpecRequestMethod(request.method) && !codec.hasRequestMethod(request.method)) {
|
|
6994
|
+
if (isSpecRequestMethod(request.method) && !codec.hasRequestMethod(request.method) && !(isExtensionReusedRequestMethod(request.method) && this._customSchemaRequestMethods.has(request.method))) {
|
|
6969
6995
|
sendErrorResponse(ProtocolErrorCode.MethodNotFound, "Method not found");
|
|
6970
6996
|
return;
|
|
6971
6997
|
}
|
|
@@ -7098,8 +7124,11 @@ var Protocol = class {
|
|
|
7098
7124
|
}
|
|
7099
7125
|
request(request, schemaOrOptions, maybeOptions) {
|
|
7100
7126
|
const codec = this._resolveOutboundCodec(request.method);
|
|
7127
|
+
if (isStandardSchema(schemaOrOptions)) {
|
|
7128
|
+
if (!isExtensionReusedRequestMethod(request.method)) this._assertOutboundRequestInEra(codec, request.method);
|
|
7129
|
+
return this._requestWithSchemaViaCodec(codec, request, schemaOrOptions, maybeOptions);
|
|
7130
|
+
}
|
|
7101
7131
|
this._assertOutboundRequestInEra(codec, request.method);
|
|
7102
|
-
if (isStandardSchema(schemaOrOptions)) return this._requestWithSchemaViaCodec(codec, request, schemaOrOptions, maybeOptions);
|
|
7103
7132
|
const validate = codecResultValidator(codec, request.method);
|
|
7104
7133
|
if (validate === void 0) throw new TypeError(`'${request.method}' is not a spec method; pass a result schema as the second argument to request().`);
|
|
7105
7134
|
return this._requestWithSchemaViaCodec(codec, request, validate, schemaOrOptions);
|
|
@@ -7217,19 +7246,20 @@ var Protocol = class {
|
|
|
7217
7246
|
const cancel = (reason) => {
|
|
7218
7247
|
if (responseReceived) return;
|
|
7219
7248
|
this._progressHandlers.delete(messageId);
|
|
7220
|
-
if (requestAbort === void 0)
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
|
|
7232
|
-
|
|
7249
|
+
if (requestAbort === void 0) {
|
|
7250
|
+
if (request.method !== "initialize") this._transport?.send(this._envelopeOutbound({
|
|
7251
|
+
jsonrpc: "2.0",
|
|
7252
|
+
method: "notifications/cancelled",
|
|
7253
|
+
params: {
|
|
7254
|
+
requestId: messageId,
|
|
7255
|
+
reason: String(reason)
|
|
7256
|
+
}
|
|
7257
|
+
}), {
|
|
7258
|
+
relatedRequestId,
|
|
7259
|
+
resumptionToken,
|
|
7260
|
+
onresumptiontoken
|
|
7261
|
+
}).catch((error) => this._onerror(/* @__PURE__ */ new Error(`Failed to send cancellation: ${error}`)));
|
|
7262
|
+
} else requestAbort.abort();
|
|
7233
7263
|
reject(reason instanceof SdkError ? reason : new SdkError(SdkErrorCode.RequestTimeout, String(reason)));
|
|
7234
7264
|
};
|
|
7235
7265
|
this._responseHandlers.set(messageId, (response) => {
|
|
@@ -7291,7 +7321,7 @@ var Protocol = class {
|
|
|
7291
7321
|
* Emits a notification, which is a one-way message that does not expect a response.
|
|
7292
7322
|
*/
|
|
7293
7323
|
async notification(notification, options) {
|
|
7294
|
-
return this._notificationViaCodec(this._resolveOutboundCodec(notification.method), notification, options);
|
|
7324
|
+
return await this._notificationViaCodec(this._resolveOutboundCodec(notification.method), notification, options);
|
|
7295
7325
|
}
|
|
7296
7326
|
/**
|
|
7297
7327
|
* The notification funnel proper, keyed by the resolved era codec —
|
|
@@ -7309,7 +7339,7 @@ var Protocol = class {
|
|
|
7309
7339
|
jsonrpc: "2.0",
|
|
7310
7340
|
...notification
|
|
7311
7341
|
});
|
|
7312
|
-
if ((this._options?.debouncedNotificationMethods ?? []).includes(notification.method) && !notification.params &&
|
|
7342
|
+
if ((this._options?.debouncedNotificationMethods ?? []).includes(notification.method) && !notification.params && options?.relatedRequestId === void 0) {
|
|
7313
7343
|
if (this._pendingDebouncedNotifications.has(notification.method)) return;
|
|
7314
7344
|
this._pendingDebouncedNotifications.add(notification.method);
|
|
7315
7345
|
Promise.resolve().then(() => {
|
|
@@ -7342,6 +7372,8 @@ var Protocol = class {
|
|
|
7342
7372
|
return maybeHandler(parsed.data, ctx);
|
|
7343
7373
|
};
|
|
7344
7374
|
else throw new TypeError("setRequestHandler: handler is required");
|
|
7375
|
+
if (typeof schemasOrHandler === "function") this._customSchemaRequestMethods.delete(method);
|
|
7376
|
+
else this._customSchemaRequestMethods.add(method);
|
|
7345
7377
|
this._requestHandlers.set(method, this._wrapHandler(method, stored));
|
|
7346
7378
|
}
|
|
7347
7379
|
/**
|
|
@@ -7370,6 +7402,7 @@ var Protocol = class {
|
|
|
7370
7402
|
*/
|
|
7371
7403
|
removeRequestHandler(method) {
|
|
7372
7404
|
this._requestHandlers.delete(method);
|
|
7405
|
+
this._customSchemaRequestMethods.delete(method);
|
|
7373
7406
|
}
|
|
7374
7407
|
/**
|
|
7375
7408
|
* Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed.
|
|
@@ -7460,7 +7493,8 @@ function manualInputRequiredValue(decoded) {
|
|
|
7460
7493
|
return {
|
|
7461
7494
|
resultType: "input_required",
|
|
7462
7495
|
inputRequests: decoded.inputRequests,
|
|
7463
|
-
...decoded.requestState !== void 0 && { requestState: decoded.requestState }
|
|
7496
|
+
...decoded.requestState !== void 0 && { requestState: decoded.requestState },
|
|
7497
|
+
...decoded._meta !== void 0 && { _meta: decoded._meta }
|
|
7464
7498
|
};
|
|
7465
7499
|
}
|
|
7466
7500
|
/*!
|
|
@@ -7712,7 +7746,7 @@ function normalizeRawShapeSchema(schema) {
|
|
|
7712
7746
|
return schema;
|
|
7713
7747
|
}
|
|
7714
7748
|
//#endregion
|
|
7715
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+server@2.
|
|
7749
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+server@2.3.1/node_modules/@modelcontextprotocol/server/dist/ajvProvider-CEoC__sr.mjs
|
|
7716
7750
|
var require_code$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
7717
7751
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7718
7752
|
exports.regexpCode = exports.getEsmExportName = exports.getProperty = exports.safeStringify = exports.stringify = exports.strConcat = exports.addCodeArg = exports.str = exports._ = exports.nil = exports._Code = exports.Name = exports.IDENTIFIER = exports._CodeOrName = void 0;
|
|
@@ -14847,7 +14881,7 @@ var AjvJsonSchemaValidator = class {
|
|
|
14847
14881
|
};
|
|
14848
14882
|
import_ajv.Ajv;
|
|
14849
14883
|
//#endregion
|
|
14850
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+server@2.
|
|
14884
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+server@2.3.1/node_modules/@modelcontextprotocol/server/dist/mcp-DIH4cS6P.mjs
|
|
14851
14885
|
const COMPLETABLE_SYMBOL = Symbol.for("mcp.completable");
|
|
14852
14886
|
/**
|
|
14853
14887
|
* Checks if a schema is completable (has completion metadata).
|
|
@@ -14861,6 +14895,10 @@ function isCompletable(schema) {
|
|
|
14861
14895
|
function getCompleter(schema) {
|
|
14862
14896
|
return schema[COMPLETABLE_SYMBOL]?.complete;
|
|
14863
14897
|
}
|
|
14898
|
+
/** @internal */
|
|
14899
|
+
function supportsScopeChallengeResolver(transport) {
|
|
14900
|
+
return typeof transport === "object" && transport !== null && "setScopeChallengeResolver" in transport && typeof transport.setScopeChallengeResolver === "function";
|
|
14901
|
+
}
|
|
14864
14902
|
/**
|
|
14865
14903
|
* Default handler re-entries per originating request — tighter than the
|
|
14866
14904
|
* client driver's 10 because the shim holds a live wire request open.
|
|
@@ -15069,6 +15107,11 @@ var Server = class extends Protocol {
|
|
|
15069
15107
|
if (modernProtocolVersions(this._supportedProtocolVersions).length > 0) this.setRequestHandler("server/discover", () => this._ondiscover());
|
|
15070
15108
|
if (this._capabilities.logging) this._registerLoggingHandler();
|
|
15071
15109
|
}
|
|
15110
|
+
/** Attaches to the given transport; rejects while this instance is connected to another one. */
|
|
15111
|
+
async connect(transport) {
|
|
15112
|
+
if (this.transport !== void 0) throw new SdkError(SdkErrorCode.AlreadyConnected, "Use a separate Server instance per connection: this instance is already connected to a transport. To connect it to a new transport, call close() first.");
|
|
15113
|
+
await super.connect(transport);
|
|
15114
|
+
}
|
|
15072
15115
|
/**
|
|
15073
15116
|
* Registers the built-in `logging/setLevel` request handler.
|
|
15074
15117
|
*
|
|
@@ -15614,6 +15657,30 @@ var Server = class extends Protocol {
|
|
|
15614
15657
|
function discoverAdvertisedCapabilities(capabilities) {
|
|
15615
15658
|
return { ...capabilities };
|
|
15616
15659
|
}
|
|
15660
|
+
function toolInputElementCount(value, max) {
|
|
15661
|
+
let count = 0;
|
|
15662
|
+
const stack = [value];
|
|
15663
|
+
while (stack.length > 0) {
|
|
15664
|
+
const node = stack.pop();
|
|
15665
|
+
if (node === null || typeof node !== "object") continue;
|
|
15666
|
+
if (Array.isArray(node)) for (const child of node) {
|
|
15667
|
+
if (++count > max) return count;
|
|
15668
|
+
if (child !== null && typeof child === "object") stack.push(child);
|
|
15669
|
+
}
|
|
15670
|
+
else for (const key in node) {
|
|
15671
|
+
if (!Object.prototype.hasOwnProperty.call(node, key)) continue;
|
|
15672
|
+
if (++count > max) return count;
|
|
15673
|
+
const child = node[key];
|
|
15674
|
+
if (child !== null && typeof child === "object") stack.push(child);
|
|
15675
|
+
}
|
|
15676
|
+
}
|
|
15677
|
+
return count;
|
|
15678
|
+
}
|
|
15679
|
+
function resolveMaxToolInputElements(value) {
|
|
15680
|
+
if (value === void 0 || value === Infinity) return void 0;
|
|
15681
|
+
if (typeof value !== "number" || Number.isNaN(value) || value < 1) throw new RangeError(`maxToolInputElements must be a number of at least 1, or Infinity, got ${String(value)}`);
|
|
15682
|
+
return value;
|
|
15683
|
+
}
|
|
15617
15684
|
/**
|
|
15618
15685
|
* High-level MCP server that provides a simpler API for working with resources, tools, and prompts.
|
|
15619
15686
|
* For advanced usage (like sending notifications or setting custom request handlers), use the underlying
|
|
@@ -15632,16 +15699,12 @@ var McpServer = class {
|
|
|
15632
15699
|
* The underlying {@linkcode Server} instance, useful for advanced operations like sending notifications.
|
|
15633
15700
|
*/
|
|
15634
15701
|
server;
|
|
15702
|
+
_maxToolInputElements;
|
|
15635
15703
|
_registeredResources = {};
|
|
15636
15704
|
_registeredResourceTemplates = {};
|
|
15637
15705
|
_registeredTools = {};
|
|
15638
15706
|
_registeredPrompts = {};
|
|
15639
|
-
/**
|
|
15640
|
-
* Per-tool JSON-converted `inputSchema`, memoized so the SEP-2243
|
|
15641
|
-
* registration-time scan and the pre-dispatch validation step share one
|
|
15642
|
-
* conversion instead of paying it twice per request under the
|
|
15643
|
-
* per-request-factory `createMcpHandler` model.
|
|
15644
|
-
*/
|
|
15707
|
+
/** Per-tool JSON-converted `inputSchema`, filled on first use by `toolInputSchemaJson()`. */
|
|
15645
15708
|
_toolInputSchemaJson = {};
|
|
15646
15709
|
/**
|
|
15647
15710
|
* The JSON-serialized `inputSchema` of a registered tool, or `undefined`
|
|
@@ -15666,6 +15729,7 @@ var McpServer = class {
|
|
|
15666
15729
|
}
|
|
15667
15730
|
constructor(serverInfo, options) {
|
|
15668
15731
|
this.server = new Server(serverInfo, options);
|
|
15732
|
+
this._maxToolInputElements = resolveMaxToolInputElements(options?.maxToolInputElements);
|
|
15669
15733
|
if (options?.capabilities?.tools) this.setToolRequestHandlers();
|
|
15670
15734
|
if (options?.capabilities?.resources) this.setResourceRequestHandlers();
|
|
15671
15735
|
if (options?.capabilities?.prompts) this.setPromptRequestHandlers();
|
|
@@ -15683,6 +15747,7 @@ var McpServer = class {
|
|
|
15683
15747
|
* ```
|
|
15684
15748
|
*/
|
|
15685
15749
|
async connect(transport) {
|
|
15750
|
+
if (supportsScopeChallengeResolver(transport)) transport.setScopeChallengeResolver((context) => this.resolveScopeChallenge(context));
|
|
15686
15751
|
return await this.server.connect(transport);
|
|
15687
15752
|
}
|
|
15688
15753
|
/**
|
|
@@ -15691,6 +15756,40 @@ var McpServer = class {
|
|
|
15691
15756
|
async close() {
|
|
15692
15757
|
await this.server.close();
|
|
15693
15758
|
}
|
|
15759
|
+
/** @internal */
|
|
15760
|
+
resolveScopeChallenge = (context) => {
|
|
15761
|
+
switch (context.request.method) {
|
|
15762
|
+
case "tools/call": {
|
|
15763
|
+
const toolName = context.request.params?.name;
|
|
15764
|
+
if (typeof toolName !== "string") return;
|
|
15765
|
+
const tool = this._registeredTools[toolName];
|
|
15766
|
+
if (tool === void 0 || !tool.enabled) return;
|
|
15767
|
+
return tool.scopeChallenge?.(context);
|
|
15768
|
+
}
|
|
15769
|
+
case "resources/read": {
|
|
15770
|
+
const resourceUri = context.request.params?.uri;
|
|
15771
|
+
if (typeof resourceUri !== "string") return;
|
|
15772
|
+
let uri;
|
|
15773
|
+
try {
|
|
15774
|
+
uri = new URL(resourceUri);
|
|
15775
|
+
} catch {
|
|
15776
|
+
return;
|
|
15777
|
+
}
|
|
15778
|
+
const resource = this._registeredResources[uri.toString()];
|
|
15779
|
+
if (resource !== void 0) return resource.enabled ? resource.scopeChallenge?.(context) : void 0;
|
|
15780
|
+
for (const template of Object.values(this._registeredResourceTemplates)) if (template.resourceTemplate.uriTemplate.match(uri.toString())) return template.enabled ? template.scopeChallenge?.(context) : void 0;
|
|
15781
|
+
return;
|
|
15782
|
+
}
|
|
15783
|
+
case "prompts/get": {
|
|
15784
|
+
const promptName = context.request.params?.name;
|
|
15785
|
+
if (typeof promptName !== "string") return;
|
|
15786
|
+
const prompt = this._registeredPrompts[promptName];
|
|
15787
|
+
if (prompt === void 0 || !prompt.enabled) return;
|
|
15788
|
+
return prompt.scopeChallenge?.(context);
|
|
15789
|
+
}
|
|
15790
|
+
default: return;
|
|
15791
|
+
}
|
|
15792
|
+
};
|
|
15694
15793
|
_toolHandlersInitialized = false;
|
|
15695
15794
|
setToolRequestHandlers() {
|
|
15696
15795
|
if (this._toolHandlersInitialized) return;
|
|
@@ -15702,7 +15801,7 @@ var McpServer = class {
|
|
|
15702
15801
|
name,
|
|
15703
15802
|
title: tool.title,
|
|
15704
15803
|
description: tool.description,
|
|
15705
|
-
inputSchema: tool.inputSchema ?
|
|
15804
|
+
inputSchema: tool.inputSchema ? convertListedInputSchema(name, tool.inputSchema) : EMPTY_OBJECT_JSON_SCHEMA,
|
|
15706
15805
|
annotations: tool.annotations,
|
|
15707
15806
|
icons: tool.icons,
|
|
15708
15807
|
execution: tool.execution,
|
|
@@ -15747,6 +15846,7 @@ var McpServer = class {
|
|
|
15747
15846
|
* Validates tool input arguments against the tool's input schema.
|
|
15748
15847
|
*/
|
|
15749
15848
|
async validateToolInput(tool, args, toolName) {
|
|
15849
|
+
if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for tool ${toolName}: arguments contain more than the maximum of ${this._maxToolInputElements} elements`);
|
|
15750
15850
|
if (!tool.inputSchema) return;
|
|
15751
15851
|
const parseResult = await validateStandardSchema(tool.inputSchema, args ?? {});
|
|
15752
15852
|
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName}: ${parseResult.error}`);
|
|
@@ -15856,7 +15956,10 @@ var McpServer = class {
|
|
|
15856
15956
|
}
|
|
15857
15957
|
for (const template of Object.values(this._registeredResourceTemplates)) {
|
|
15858
15958
|
const variables = template.resourceTemplate.uriTemplate.match(uri.toString());
|
|
15859
|
-
if (variables)
|
|
15959
|
+
if (variables) {
|
|
15960
|
+
if (!template.enabled) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Resource template ${template.resourceTemplate.uriTemplate} disabled`);
|
|
15961
|
+
return attachCacheHintFallback(await template.readCallback(uri, variables, ctx), template.cacheHint);
|
|
15962
|
+
}
|
|
15860
15963
|
}
|
|
15861
15964
|
throw new ResourceNotFoundError(request.params.uri);
|
|
15862
15965
|
});
|
|
@@ -15887,36 +15990,32 @@ var McpServer = class {
|
|
|
15887
15990
|
this._promptHandlersInitialized = true;
|
|
15888
15991
|
}
|
|
15889
15992
|
registerResource(name, uriOrTemplate, config, readCallback) {
|
|
15890
|
-
const cacheHint = config
|
|
15891
|
-
|
|
15892
|
-
if (cacheHint !== void 0) {
|
|
15893
|
-
assertValidCacheHint(cacheHint, `resource ${name}`);
|
|
15894
|
-
const rest = { ...config };
|
|
15895
|
-
delete rest.cacheHint;
|
|
15896
|
-
metadata = rest;
|
|
15897
|
-
}
|
|
15993
|
+
const { cacheHint, scopeChallenge, ...resourceMetadata } = config;
|
|
15994
|
+
const metadata = resourceMetadata;
|
|
15995
|
+
if (cacheHint !== void 0) assertValidCacheHint(cacheHint, `resource ${name}`);
|
|
15898
15996
|
if (typeof uriOrTemplate === "string") {
|
|
15899
15997
|
if (this._registeredResources[uriOrTemplate]) throw new Error(`Resource ${uriOrTemplate} is already registered`);
|
|
15900
|
-
const registeredResource = this._createRegisteredResource(name, config.title, uriOrTemplate, metadata, readCallback);
|
|
15998
|
+
const registeredResource = this._createRegisteredResource(name, config.title, uriOrTemplate, metadata, scopeChallenge, readCallback);
|
|
15901
15999
|
if (cacheHint !== void 0) registeredResource.cacheHint = cacheHint;
|
|
15902
16000
|
this.setResourceRequestHandlers();
|
|
15903
16001
|
this.sendResourceListChanged();
|
|
15904
16002
|
return registeredResource;
|
|
15905
16003
|
} else {
|
|
15906
16004
|
if (this._registeredResourceTemplates[name]) throw new Error(`Resource template ${name} is already registered`);
|
|
15907
|
-
const registeredResourceTemplate = this._createRegisteredResourceTemplate(name, config.title, uriOrTemplate, metadata, readCallback);
|
|
16005
|
+
const registeredResourceTemplate = this._createRegisteredResourceTemplate(name, config.title, uriOrTemplate, metadata, scopeChallenge, readCallback);
|
|
15908
16006
|
if (cacheHint !== void 0) registeredResourceTemplate.cacheHint = cacheHint;
|
|
15909
16007
|
this.setResourceRequestHandlers();
|
|
15910
16008
|
this.sendResourceListChanged();
|
|
15911
16009
|
return registeredResourceTemplate;
|
|
15912
16010
|
}
|
|
15913
16011
|
}
|
|
15914
|
-
_createRegisteredResource(name, title, uri, metadata, readCallback) {
|
|
16012
|
+
_createRegisteredResource(name, title, uri, metadata, scopeChallenge, readCallback) {
|
|
15915
16013
|
const registeredResource = {
|
|
15916
16014
|
name,
|
|
15917
16015
|
title,
|
|
15918
16016
|
metadata,
|
|
15919
16017
|
readCallback,
|
|
16018
|
+
scopeChallenge,
|
|
15920
16019
|
enabled: true,
|
|
15921
16020
|
disable: () => registeredResource.update({ enabled: false }),
|
|
15922
16021
|
enable: () => registeredResource.update({ enabled: true }),
|
|
@@ -15930,6 +16029,7 @@ var McpServer = class {
|
|
|
15930
16029
|
if (updates.title !== void 0) registeredResource.title = updates.title;
|
|
15931
16030
|
if (updates.metadata !== void 0) registeredResource.metadata = updates.metadata;
|
|
15932
16031
|
if (updates.callback !== void 0) registeredResource.readCallback = updates.callback;
|
|
16032
|
+
if (updates.scopeChallenge !== void 0) registeredResource.scopeChallenge = updates.scopeChallenge === null ? void 0 : updates.scopeChallenge;
|
|
15933
16033
|
if (updates.enabled !== void 0) registeredResource.enabled = updates.enabled;
|
|
15934
16034
|
this.sendResourceListChanged();
|
|
15935
16035
|
}
|
|
@@ -15937,12 +16037,13 @@ var McpServer = class {
|
|
|
15937
16037
|
this._registeredResources[uri] = registeredResource;
|
|
15938
16038
|
return registeredResource;
|
|
15939
16039
|
}
|
|
15940
|
-
_createRegisteredResourceTemplate(name, title, template, metadata, readCallback) {
|
|
16040
|
+
_createRegisteredResourceTemplate(name, title, template, metadata, scopeChallenge, readCallback) {
|
|
15941
16041
|
const registeredResourceTemplate = {
|
|
15942
16042
|
resourceTemplate: template,
|
|
15943
16043
|
title,
|
|
15944
16044
|
metadata,
|
|
15945
16045
|
readCallback,
|
|
16046
|
+
scopeChallenge,
|
|
15946
16047
|
enabled: true,
|
|
15947
16048
|
disable: () => registeredResourceTemplate.update({ enabled: false }),
|
|
15948
16049
|
enable: () => registeredResourceTemplate.update({ enabled: true }),
|
|
@@ -15956,6 +16057,7 @@ var McpServer = class {
|
|
|
15956
16057
|
if (updates.template !== void 0) registeredResourceTemplate.resourceTemplate = updates.template;
|
|
15957
16058
|
if (updates.metadata !== void 0) registeredResourceTemplate.metadata = updates.metadata;
|
|
15958
16059
|
if (updates.callback !== void 0) registeredResourceTemplate.readCallback = updates.callback;
|
|
16060
|
+
if (updates.scopeChallenge !== void 0) registeredResourceTemplate.scopeChallenge = updates.scopeChallenge === null ? void 0 : updates.scopeChallenge;
|
|
15959
16061
|
if (updates.enabled !== void 0) registeredResourceTemplate.enabled = updates.enabled;
|
|
15960
16062
|
this.sendResourceListChanged();
|
|
15961
16063
|
}
|
|
@@ -15965,7 +16067,7 @@ var McpServer = class {
|
|
|
15965
16067
|
if (Array.isArray(variableNames) && variableNames.some((v) => !!template.completeCallback(v))) this.setCompletionRequestHandler();
|
|
15966
16068
|
return registeredResourceTemplate;
|
|
15967
16069
|
}
|
|
15968
|
-
_createRegisteredPrompt(name, title, description, argsSchema, callback, icons, _meta) {
|
|
16070
|
+
_createRegisteredPrompt(name, title, description, argsSchema, callback, icons, scopeChallenge, _meta) {
|
|
15969
16071
|
let currentArgsSchema = argsSchema;
|
|
15970
16072
|
let currentCallback = callback;
|
|
15971
16073
|
const registeredPrompt = {
|
|
@@ -15973,6 +16075,7 @@ var McpServer = class {
|
|
|
15973
16075
|
description,
|
|
15974
16076
|
argsSchema,
|
|
15975
16077
|
icons,
|
|
16078
|
+
scopeChallenge,
|
|
15976
16079
|
_meta,
|
|
15977
16080
|
handler: createPromptHandler(name, argsSchema, callback),
|
|
15978
16081
|
enabled: true,
|
|
@@ -15987,6 +16090,7 @@ var McpServer = class {
|
|
|
15987
16090
|
if (updates.title !== void 0) registeredPrompt.title = updates.title;
|
|
15988
16091
|
if (updates.description !== void 0) registeredPrompt.description = updates.description;
|
|
15989
16092
|
if (updates.icons !== void 0) registeredPrompt.icons = updates.icons;
|
|
16093
|
+
if (updates.scopeChallenge !== void 0) registeredPrompt.scopeChallenge = updates.scopeChallenge === null ? void 0 : updates.scopeChallenge;
|
|
15990
16094
|
if (updates._meta !== void 0) registeredPrompt._meta = updates._meta;
|
|
15991
16095
|
let needsHandlerRegen = false;
|
|
15992
16096
|
if (updates.argsSchema !== void 0) {
|
|
@@ -16014,24 +16118,25 @@ var McpServer = class {
|
|
|
16014
16118
|
}
|
|
16015
16119
|
return registeredPrompt;
|
|
16016
16120
|
}
|
|
16017
|
-
_createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, icons, execution, _meta, handler) {
|
|
16121
|
+
_createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, icons, execution, scopeChallenge, _meta, handler) {
|
|
16018
16122
|
validateAndWarnToolName(name);
|
|
16019
|
-
if (inputSchema !== void 0) try {
|
|
16020
|
-
const json = standardSchemaToJsonSchema(inputSchema, "input");
|
|
16021
|
-
this._toolInputSchemaJson[name] = json;
|
|
16022
|
-
const scan = scanXMcpHeaderDeclarations(json);
|
|
16023
|
-
if (!scan.valid) console.warn(`[mcp-sdk] tool '${name}' carries an invalid x-mcp-header declaration and will be excluded by conforming Streamable HTTP clients: ${scan.reason}`);
|
|
16024
|
-
} catch {}
|
|
16025
16123
|
let currentHandler = handler;
|
|
16124
|
+
let outputSchemaJson;
|
|
16026
16125
|
const registeredTool = {
|
|
16027
16126
|
title,
|
|
16028
16127
|
description,
|
|
16029
16128
|
inputSchema,
|
|
16030
16129
|
outputSchema,
|
|
16031
|
-
outputSchemaJson
|
|
16130
|
+
get outputSchemaJson() {
|
|
16131
|
+
return outputSchemaJson ??= convertOutputSchemaJson(registeredTool.outputSchema);
|
|
16132
|
+
},
|
|
16133
|
+
set outputSchemaJson(value) {
|
|
16134
|
+
outputSchemaJson = value;
|
|
16135
|
+
},
|
|
16032
16136
|
annotations,
|
|
16033
16137
|
icons,
|
|
16034
16138
|
execution,
|
|
16139
|
+
scopeChallenge,
|
|
16035
16140
|
_meta,
|
|
16036
16141
|
handler,
|
|
16037
16142
|
executor: createToolExecutor(inputSchema, handler),
|
|
@@ -16070,6 +16175,7 @@ var McpServer = class {
|
|
|
16070
16175
|
}
|
|
16071
16176
|
if (updates.annotations !== void 0) registeredTool.annotations = updates.annotations;
|
|
16072
16177
|
if (updates.icons !== void 0) registeredTool.icons = updates.icons;
|
|
16178
|
+
if (updates.scopeChallenge !== void 0) registeredTool.scopeChallenge = updates.scopeChallenge === null ? void 0 : updates.scopeChallenge;
|
|
16073
16179
|
if (updates._meta !== void 0) registeredTool._meta = updates._meta;
|
|
16074
16180
|
if (updates.enabled !== void 0) registeredTool.enabled = updates.enabled;
|
|
16075
16181
|
this.sendToolListChanged();
|
|
@@ -16082,13 +16188,13 @@ var McpServer = class {
|
|
|
16082
16188
|
}
|
|
16083
16189
|
registerTool(name, config, cb) {
|
|
16084
16190
|
if (this._registeredTools[name]) throw new Error(`Tool ${name} is already registered`);
|
|
16085
|
-
const { title, description, inputSchema, outputSchema, annotations, icons, _meta } = config;
|
|
16086
|
-
return this._createRegisteredTool(name, title, description, normalizeRawShapeSchema(inputSchema), normalizeRawShapeSchema(outputSchema), annotations, icons, void 0, _meta, cb);
|
|
16191
|
+
const { title, description, inputSchema, outputSchema, annotations, icons, scopeChallenge, _meta } = config;
|
|
16192
|
+
return this._createRegisteredTool(name, title, description, normalizeRawShapeSchema(inputSchema), normalizeRawShapeSchema(outputSchema), annotations, icons, void 0, scopeChallenge, _meta, cb);
|
|
16087
16193
|
}
|
|
16088
16194
|
registerPrompt(name, config, cb) {
|
|
16089
16195
|
if (this._registeredPrompts[name]) throw new Error(`Prompt ${name} is already registered`);
|
|
16090
|
-
const { title, description, argsSchema, icons, _meta } = config;
|
|
16091
|
-
const registeredPrompt = this._createRegisteredPrompt(name, title, description, normalizeRawShapeSchema(argsSchema), cb, icons, _meta);
|
|
16196
|
+
const { title, description, argsSchema, icons, scopeChallenge, _meta } = config;
|
|
16197
|
+
const registeredPrompt = this._createRegisteredPrompt(name, title, description, normalizeRawShapeSchema(argsSchema), cb, icons, scopeChallenge, _meta);
|
|
16092
16198
|
this.setPromptRequestHandlers();
|
|
16093
16199
|
this.sendPromptListChanged();
|
|
16094
16200
|
return registeredPrompt;
|
|
@@ -16158,6 +16264,13 @@ const EMPTY_OBJECT_JSON_SCHEMA = {
|
|
|
16158
16264
|
type: "object",
|
|
16159
16265
|
properties: {}
|
|
16160
16266
|
};
|
|
16267
|
+
/** Converts a tool's `inputSchema` for `tools/list` and warns on an invalid SEP-2243 `x-mcp-header` declaration. */
|
|
16268
|
+
function convertListedInputSchema(name, inputSchema) {
|
|
16269
|
+
const json = standardSchemaToJsonSchema(inputSchema, "input");
|
|
16270
|
+
const scan = scanXMcpHeaderDeclarations(json);
|
|
16271
|
+
if (!scan.valid) console.warn(`[mcp-sdk] tool '${name}' carries an invalid x-mcp-header declaration and will be excluded by conforming Streamable HTTP clients: ${scan.reason}`);
|
|
16272
|
+
return json;
|
|
16273
|
+
}
|
|
16161
16274
|
/**
|
|
16162
16275
|
* Convert a registered `outputSchema` to JSON Schema, memoised on {@link RegisteredTool.outputSchemaJson}
|
|
16163
16276
|
* so `tools/call` passes the SAME advertised schema to the wire codec's `projectCallToolResult` that
|
|
@@ -16180,7 +16293,7 @@ function createPromptHandler(name, argsSchema, callback) {
|
|
|
16180
16293
|
if (argsSchema) {
|
|
16181
16294
|
const typedCallback = callback;
|
|
16182
16295
|
return async (args, ctx) => {
|
|
16183
|
-
const parseResult = await validateStandardSchema(argsSchema, args);
|
|
16296
|
+
const parseResult = await validateStandardSchema(argsSchema, args ?? {});
|
|
16184
16297
|
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for prompt ${name}: ${parseResult.error}`);
|
|
16185
16298
|
return typedCallback(parseResult.data, ctx);
|
|
16186
16299
|
};
|