@zuplo/cli 7.8.5 → 7.8.7
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/node_modules/@modelcontextprotocol/client/dist/{index-CHhhk6PQ.d.cts → index-BCtJi0p5.d.mts} +38 -6
- package/node_modules/@modelcontextprotocol/client/dist/index-BCtJi0p5.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/client/dist/{index-D4xIIEF6.d.mts → index-CEk3qkZM.d.cts} +41 -3
- package/node_modules/@modelcontextprotocol/client/dist/index-CEk3qkZM.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/client/dist/index.cjs +375 -60
- package/node_modules/@modelcontextprotocol/client/dist/index.cjs.map +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/index.d.cts +227 -11
- package/node_modules/@modelcontextprotocol/client/dist/index.d.cts.map +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/index.d.mts +227 -11
- package/node_modules/@modelcontextprotocol/client/dist/index.d.mts.map +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/index.mjs +369 -61
- package/node_modules/@modelcontextprotocol/client/dist/index.mjs.map +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.cjs +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.mjs +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/{src-NAgB4Mp8.cjs → src-D0qEN74R.cjs} +111 -38
- package/node_modules/@modelcontextprotocol/client/dist/src-D0qEN74R.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/client/dist/{src-D_zzAWoS.mjs → src-DDAAhLnO.mjs} +106 -33
- package/node_modules/@modelcontextprotocol/client/dist/src-DDAAhLnO.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/client/dist/stdio.cjs +8 -2
- package/node_modules/@modelcontextprotocol/client/dist/stdio.cjs.map +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/stdio.d.cts +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/stdio.d.cts.map +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/stdio.d.mts +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/stdio.d.mts.map +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/stdio.mjs +8 -2
- package/node_modules/@modelcontextprotocol/client/dist/stdio.mjs.map +1 -1
- package/node_modules/@modelcontextprotocol/client/package.json +4 -4
- package/node_modules/@modelcontextprotocol/core/dist/{auth-BWdKR39I.d.mts → auth--n_Yzytt.d.cts} +6 -1
- package/node_modules/@modelcontextprotocol/core/dist/{auth-BWdKR39I.d.mts.map → auth--n_Yzytt.d.cts.map} +1 -1
- package/node_modules/@modelcontextprotocol/core/dist/{auth-CfDMXiII.cjs → auth-4-zilcqg.cjs} +3 -2
- package/node_modules/@modelcontextprotocol/core/dist/{auth-CfDMXiII.cjs.map → auth-4-zilcqg.cjs.map} +1 -1
- package/node_modules/@modelcontextprotocol/core/dist/{auth-CUe6YdwF.mjs → auth-CGP0BDVq.mjs} +3 -2
- package/node_modules/@modelcontextprotocol/core/dist/{auth-CUe6YdwF.mjs.map → auth-CGP0BDVq.mjs.map} +1 -1
- package/node_modules/@modelcontextprotocol/core/dist/{auth-hYtaIUZm.d.cts → auth-YUQV3RRv.d.mts} +6 -1
- package/node_modules/@modelcontextprotocol/core/dist/{auth-hYtaIUZm.d.cts.map → auth-YUQV3RRv.d.mts.map} +1 -1
- package/node_modules/@modelcontextprotocol/core/dist/index.cjs +1 -1
- package/node_modules/@modelcontextprotocol/core/dist/index.d.cts +1 -1
- package/node_modules/@modelcontextprotocol/core/dist/index.d.mts +1 -1
- package/node_modules/@modelcontextprotocol/core/dist/index.mjs +1 -1
- package/node_modules/@modelcontextprotocol/core/dist/internal.cjs +1 -1
- package/node_modules/@modelcontextprotocol/core/dist/internal.d.cts +1 -1
- package/node_modules/@modelcontextprotocol/core/dist/internal.d.mts +1 -1
- package/node_modules/@modelcontextprotocol/core/dist/internal.mjs +1 -1
- package/node_modules/@modelcontextprotocol/core/package.json +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/auth.d.ts +15 -4
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/auth.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/auth.js +22 -3
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/auth.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/express.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/express.js +3 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/express.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/requestBody.d.ts +25 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/requestBody.d.ts.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/requestBody.js +64 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/requestBody.js.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.d.ts +10 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.js +13 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.d.ts +15 -4
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js +22 -3
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js +3 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/requestBody.d.ts +25 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/requestBody.d.ts.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/requestBody.js +58 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/requestBody.js.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.d.ts +10 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js +13 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/package.json +1 -1
- package/node_modules/@modelcontextprotocol/server/dist/{createMcpHandler-dBHMsxwf.d.cts → createMcpHandler-BLVe3qmU.d.cts} +110 -7
- package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-BLVe3qmU.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/{createMcpHandler-CLhGwQTn.d.mts → createMcpHandler-Bt6U_Fqb.d.mts} +110 -7
- package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-Bt6U_Fqb.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/index.cjs +144 -248
- package/node_modules/@modelcontextprotocol/server/dist/index.cjs.map +1 -1
- package/node_modules/@modelcontextprotocol/server/dist/index.d.cts +38 -3
- package/node_modules/@modelcontextprotocol/server/dist/index.d.cts.map +1 -1
- package/node_modules/@modelcontextprotocol/server/dist/index.d.mts +38 -3
- package/node_modules/@modelcontextprotocol/server/dist/index.d.mts.map +1 -1
- package/node_modules/@modelcontextprotocol/server/dist/index.mjs +136 -243
- package/node_modules/@modelcontextprotocol/server/dist/index.mjs.map +1 -1
- package/node_modules/@modelcontextprotocol/server/dist/{mcp-D7GmuPnv.cjs → mcp-DUcCQSTW.cjs} +426 -21
- package/node_modules/@modelcontextprotocol/server/dist/mcp-DUcCQSTW.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/{mcp-DXXb3Vv3.mjs → mcp-Dw2OlZ1f.mjs} +367 -22
- package/node_modules/@modelcontextprotocol/server/dist/mcp-Dw2OlZ1f.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.cjs +1 -1
- package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.mjs +1 -1
- package/node_modules/@modelcontextprotocol/server/dist/{src-STyD_Vvf.cjs → src-CgFsfg3E.cjs} +114 -36
- package/node_modules/@modelcontextprotocol/server/dist/src-CgFsfg3E.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/{src-CX2iR2pK.mjs → src-D-y6h4N7.mjs} +114 -36
- package/node_modules/@modelcontextprotocol/server/dist/src-D-y6h4N7.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/stdio.cjs +30 -3
- package/node_modules/@modelcontextprotocol/server/dist/stdio.cjs.map +1 -1
- package/node_modules/@modelcontextprotocol/server/dist/stdio.d.cts +9 -1
- package/node_modules/@modelcontextprotocol/server/dist/stdio.d.cts.map +1 -1
- package/node_modules/@modelcontextprotocol/server/dist/stdio.d.mts +9 -1
- package/node_modules/@modelcontextprotocol/server/dist/stdio.d.mts.map +1 -1
- package/node_modules/@modelcontextprotocol/server/dist/stdio.mjs +30 -3
- package/node_modules/@modelcontextprotocol/server/dist/stdio.mjs.map +1 -1
- package/node_modules/@modelcontextprotocol/server/package.json +3 -3
- package/node_modules/@posthog/core/dist/featureFlagLocalEvaluation.d.ts +12 -1
- package/node_modules/@posthog/core/dist/featureFlagLocalEvaluation.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/featureFlagLocalEvaluation.js +16 -2
- package/node_modules/@posthog/core/dist/featureFlagLocalEvaluation.mjs +14 -3
- package/node_modules/@posthog/core/dist/index.d.ts +1 -1
- package/node_modules/@posthog/core/dist/index.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/index.js +15 -6
- package/node_modules/@posthog/core/dist/index.mjs +1 -1
- package/node_modules/@posthog/core/package.json +2 -2
- package/node_modules/@posthog/core/src/featureFlagLocalEvaluation.ts +45 -2
- package/node_modules/@posthog/core/src/index.ts +1 -0
- package/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/package.json +12 -12
- package/node_modules/@modelcontextprotocol/client/dist/index-CHhhk6PQ.d.cts.map +0 -1
- package/node_modules/@modelcontextprotocol/client/dist/index-D4xIIEF6.d.mts.map +0 -1
- package/node_modules/@modelcontextprotocol/client/dist/src-D_zzAWoS.mjs.map +0 -1
- package/node_modules/@modelcontextprotocol/client/dist/src-NAgB4Mp8.cjs.map +0 -1
- package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-CLhGwQTn.d.mts.map +0 -1
- package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-dBHMsxwf.d.cts.map +0 -1
- package/node_modules/@modelcontextprotocol/server/dist/mcp-D7GmuPnv.cjs.map +0 -1
- package/node_modules/@modelcontextprotocol/server/dist/mcp-DXXb3Vv3.mjs.map +0 -1
- package/node_modules/@modelcontextprotocol/server/dist/src-CX2iR2pK.mjs.map +0 -1
- package/node_modules/@modelcontextprotocol/server/dist/src-STyD_Vvf.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-Bnu9O96Y.cjs');
|
|
2
|
-
const require_mcp = require('./mcp-
|
|
3
|
-
const require_src = require('./src-
|
|
2
|
+
const require_mcp = require('./mcp-DUcCQSTW.cjs');
|
|
3
|
+
const require_src = require('./src-CgFsfg3E.cjs');
|
|
4
4
|
let _modelcontextprotocol_server__shims = require("@modelcontextprotocol/server/_shims");
|
|
5
5
|
let _modelcontextprotocol_core_internal = require("@modelcontextprotocol/core/internal");
|
|
6
6
|
|
|
@@ -248,6 +248,59 @@ async function invoke(server, message, ctx) {
|
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/server/requestBody.ts
|
|
253
|
+
/** Default upper bound, in bytes, on a request body read by the HTTP entry points (4 MiB). */
|
|
254
|
+
const DEFAULT_MAX_REQUEST_BODY_SIZE = 4 * 1024 * 1024;
|
|
255
|
+
/** Upper bound on the number of messages accepted in one JSON-RPC batch array. */
|
|
256
|
+
const MAX_BATCH_SIZE = 100;
|
|
257
|
+
/** The message answered with 413 for a request body over `maxBytes`. */
|
|
258
|
+
function requestBodyTooLargeMessage(maxBytes) {
|
|
259
|
+
return `Payload Too Large: Request body must not exceed ${maxBytes} bytes`;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Resolves a `maxRequestBodySize` option to the bound to apply: the default when
|
|
263
|
+
* omitted, otherwise the value itself, which must be a positive finite number of
|
|
264
|
+
* bytes (a `RangeError` is thrown at configuration time for anything else).
|
|
265
|
+
*/
|
|
266
|
+
function resolveMaxRequestBodySize(value) {
|
|
267
|
+
if (value === void 0) return DEFAULT_MAX_REQUEST_BODY_SIZE;
|
|
268
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) throw new RangeError(`maxRequestBodySize must be a positive number of bytes, got ${String(value)}`);
|
|
269
|
+
return value;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Reads a request body as text, up to `maxBytes` (default
|
|
273
|
+
* {@linkcode DEFAULT_MAX_REQUEST_BODY_SIZE}). A declared `Content-Length` over the
|
|
274
|
+
* limit is refused without reading anything; otherwise the read stops as soon as
|
|
275
|
+
* more than the limit has arrived. Stream failures propagate.
|
|
276
|
+
*/
|
|
277
|
+
async function readRequestBody(request, maxBytes = DEFAULT_MAX_REQUEST_BODY_SIZE) {
|
|
278
|
+
if (Number(request.headers.get("content-length")) > maxBytes) return { tooLarge: true };
|
|
279
|
+
if (request.body === null) return {
|
|
280
|
+
tooLarge: false,
|
|
281
|
+
text: ""
|
|
282
|
+
};
|
|
283
|
+
const reader = request.body.getReader();
|
|
284
|
+
const decoder = new TextDecoder();
|
|
285
|
+
let received = 0;
|
|
286
|
+
let text = "";
|
|
287
|
+
try {
|
|
288
|
+
for (;;) {
|
|
289
|
+
const { done, value } = await reader.read();
|
|
290
|
+
if (done) break;
|
|
291
|
+
received += value.byteLength;
|
|
292
|
+
if (received > maxBytes) return { tooLarge: true };
|
|
293
|
+
text += decoder.decode(value, { stream: true });
|
|
294
|
+
}
|
|
295
|
+
} finally {
|
|
296
|
+
reader.releaseLock();
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
tooLarge: false,
|
|
300
|
+
text: text + decoder.decode()
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
251
304
|
//#endregion
|
|
252
305
|
//#region src/server/streamableHttp.ts
|
|
253
306
|
/**
|
|
@@ -320,6 +373,8 @@ var WebStandardStreamableHTTPServerTransport = class {
|
|
|
320
373
|
_retryInterval;
|
|
321
374
|
_supportedProtocolVersions;
|
|
322
375
|
_keepAliveMs;
|
|
376
|
+
_maxRequestBodySize;
|
|
377
|
+
_scopeChallengeResolver;
|
|
323
378
|
sessionId;
|
|
324
379
|
onclose;
|
|
325
380
|
onerror;
|
|
@@ -336,6 +391,7 @@ var WebStandardStreamableHTTPServerTransport = class {
|
|
|
336
391
|
this._retryInterval = options.retryInterval;
|
|
337
392
|
this._supportedProtocolVersions = options.supportedProtocolVersions ?? _modelcontextprotocol_core_internal.SUPPORTED_PROTOCOL_VERSIONS;
|
|
338
393
|
this._keepAliveMs = options.keepAliveMs ?? require_mcp.DEFAULT_SSE_KEEP_ALIVE_MS;
|
|
394
|
+
this._maxRequestBodySize = resolveMaxRequestBodySize(options.maxRequestBodySize);
|
|
339
395
|
}
|
|
340
396
|
startKeepAlive(controller, encoder) {
|
|
341
397
|
if (this._closed) return void 0;
|
|
@@ -348,6 +404,10 @@ var WebStandardStreamableHTTPServerTransport = class {
|
|
|
348
404
|
});
|
|
349
405
|
return timer;
|
|
350
406
|
}
|
|
407
|
+
/** Sets the scope challenge resolver for parsed JSON-RPC requests. */
|
|
408
|
+
setScopeChallengeResolver(resolver) {
|
|
409
|
+
this._scopeChallengeResolver = resolver;
|
|
410
|
+
}
|
|
351
411
|
/**
|
|
352
412
|
* Starts the transport. This is required by the {@linkcode Transport} interface but is a no-op
|
|
353
413
|
* for the Streamable HTTP transport as connections are managed per-request.
|
|
@@ -384,6 +444,11 @@ var WebStandardStreamableHTTPServerTransport = class {
|
|
|
384
444
|
}
|
|
385
445
|
});
|
|
386
446
|
}
|
|
447
|
+
async _checkScopeChallenge(messages, authInfo) {
|
|
448
|
+
if (!this._scopeChallengeResolver) return;
|
|
449
|
+
const challenge = await require_mcp.findScopeChallenge(messages.filter((message) => require_src.isJSONRPCRequest(message)), authInfo, this._scopeChallengeResolver);
|
|
450
|
+
return challenge === void 0 ? void 0 : require_mcp.createScopeChallengeResponse(challenge, require_mcp.scopeChallengeResourceMetadataUrl(authInfo));
|
|
451
|
+
}
|
|
387
452
|
/**
|
|
388
453
|
* Validates request headers for DNS rebinding protection.
|
|
389
454
|
* @returns Error response if validation fails, `undefined` if validation passes.
|
|
@@ -641,12 +706,22 @@ var WebStandardStreamableHTTPServerTransport = class {
|
|
|
641
706
|
const request = req;
|
|
642
707
|
let rawMessage;
|
|
643
708
|
if (options?.parsedBody === void 0) try {
|
|
644
|
-
|
|
709
|
+
const body = await readRequestBody(req, this._maxRequestBodySize);
|
|
710
|
+
if (body.tooLarge) {
|
|
711
|
+
const message = requestBodyTooLargeMessage(this._maxRequestBodySize);
|
|
712
|
+
this.onerror?.(new Error(message));
|
|
713
|
+
return this.createJsonErrorResponse(413, -32e3, message);
|
|
714
|
+
}
|
|
715
|
+
rawMessage = JSON.parse(body.text);
|
|
645
716
|
} catch (error) {
|
|
646
717
|
this.onerror?.(error);
|
|
647
718
|
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
|
|
648
719
|
}
|
|
649
720
|
else rawMessage = options.parsedBody;
|
|
721
|
+
if (Array.isArray(rawMessage) && rawMessage.length > MAX_BATCH_SIZE) {
|
|
722
|
+
this.onerror?.(/* @__PURE__ */ new Error(`Invalid Request: Batch must not exceed ${MAX_BATCH_SIZE} messages`));
|
|
723
|
+
return this.createJsonErrorResponse(400, -32600, `Invalid Request: Batch must not exceed ${MAX_BATCH_SIZE} messages`);
|
|
724
|
+
}
|
|
650
725
|
let messages;
|
|
651
726
|
try {
|
|
652
727
|
messages = Array.isArray(rawMessage) ? rawMessage.map((msg) => _modelcontextprotocol_core_internal.JSONRPCMessageSchema.parse(msg)) : [_modelcontextprotocol_core_internal.JSONRPCMessageSchema.parse(rawMessage)];
|
|
@@ -676,6 +751,14 @@ var WebStandardStreamableHTTPServerTransport = class {
|
|
|
676
751
|
if (protocolError) return protocolError;
|
|
677
752
|
}
|
|
678
753
|
if (this._closed) return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
754
|
+
let scopeChallengeResponse;
|
|
755
|
+
try {
|
|
756
|
+
scopeChallengeResponse = await this._checkScopeChallenge(messages, options?.authInfo);
|
|
757
|
+
} catch (error) {
|
|
758
|
+
this.onerror?.(error);
|
|
759
|
+
return this.createJsonErrorResponse(500, -32603, "Internal server error");
|
|
760
|
+
}
|
|
761
|
+
if (scopeChallengeResponse) return scopeChallengeResponse;
|
|
679
762
|
if (!messages.some((element) => require_src.isJSONRPCRequest(element))) {
|
|
680
763
|
for (const message of messages) this.onmessage?.(message, {
|
|
681
764
|
authInfo: options?.authInfo,
|
|
@@ -965,7 +1048,7 @@ function internalServerErrorResponse(id = null) {
|
|
|
965
1048
|
* The entry passes its own `onerror` here when expanding the default, so
|
|
966
1049
|
* legacy-leg failures are never silently swallowed.
|
|
967
1050
|
*/
|
|
968
|
-
function createLegacyStatelessFallback(factory, onerror, keepAliveMs) {
|
|
1051
|
+
function createLegacyStatelessFallback(factory, onerror, keepAliveMs, maxRequestBodySize) {
|
|
969
1052
|
return async (request, options) => {
|
|
970
1053
|
if (request.method.toUpperCase() !== "POST") return jsonRpcErrorResponse(405, -32e3, "Method not allowed.");
|
|
971
1054
|
try {
|
|
@@ -976,7 +1059,8 @@ function createLegacyStatelessFallback(factory, onerror, keepAliveMs) {
|
|
|
976
1059
|
});
|
|
977
1060
|
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
978
1061
|
sessionIdGenerator: void 0,
|
|
979
|
-
...keepAliveMs !== void 0 && { keepAliveMs }
|
|
1062
|
+
...keepAliveMs !== void 0 && { keepAliveMs },
|
|
1063
|
+
...maxRequestBodySize !== void 0 && { maxRequestBodySize }
|
|
980
1064
|
});
|
|
981
1065
|
await product.connect(transport);
|
|
982
1066
|
const teardown = () => {
|
|
@@ -1033,8 +1117,26 @@ function createLegacyStatelessFallback(factory, onerror, keepAliveMs) {
|
|
|
1033
1117
|
}
|
|
1034
1118
|
};
|
|
1035
1119
|
}
|
|
1036
|
-
function legacyStatelessFallback(factory, onerror) {
|
|
1037
|
-
return createLegacyStatelessFallback(factory, onerror);
|
|
1120
|
+
function legacyStatelessFallback(factory, onerror, options) {
|
|
1121
|
+
return createLegacyStatelessFallback(factory, onerror, void 0, resolveMaxRequestBodySize(options?.maxRequestBodySize));
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Read the SEP-2243 standard request headers off the inbound request.
|
|
1125
|
+
*
|
|
1126
|
+
* Both halves of the standard-header story need them — the body-primary
|
|
1127
|
+
* classifier for its cross-check cells, and
|
|
1128
|
+
* {@linkcode validateStandardRequestHeaders} for the presence half — and a
|
|
1129
|
+
* header read at one site but not the other is precisely how a required header
|
|
1130
|
+
* goes unenforced: that divergence is what let a modern POST omitting
|
|
1131
|
+
* `MCP-Protocol-Version` be served. Read them here once so a header added to
|
|
1132
|
+
* {@linkcode InboundHttpRequest} reaches both sites together.
|
|
1133
|
+
*/
|
|
1134
|
+
function standardHeadersOf(request) {
|
|
1135
|
+
return {
|
|
1136
|
+
protocolVersionHeader: request.headers.get("mcp-protocol-version") ?? void 0,
|
|
1137
|
+
mcpMethodHeader: request.headers.get("mcp-method") ?? void 0,
|
|
1138
|
+
mcpNameHeader: request.headers.get("mcp-name") ?? void 0
|
|
1139
|
+
};
|
|
1038
1140
|
}
|
|
1039
1141
|
/**
|
|
1040
1142
|
* The entry's classification step: read the request body exactly once (unless
|
|
@@ -1047,7 +1149,7 @@ function legacyStatelessFallback(factory, onerror) {
|
|
|
1047
1149
|
* the body-preserving clone is then skipped and `forwardRequest` is the
|
|
1048
1150
|
* (consumed) input request.
|
|
1049
1151
|
*/
|
|
1050
|
-
async function classifyEntryRequest(request, providedParsedBody, needsForward = true) {
|
|
1152
|
+
async function classifyEntryRequest(request, providedParsedBody, needsForward = true, maxRequestBodySize = DEFAULT_MAX_REQUEST_BODY_SIZE) {
|
|
1051
1153
|
const httpMethod = request.method.toUpperCase();
|
|
1052
1154
|
let body;
|
|
1053
1155
|
let parsedBody = providedParsedBody;
|
|
@@ -1058,7 +1160,9 @@ async function classifyEntryRequest(request, providedParsedBody, needsForward =
|
|
|
1058
1160
|
if (needsForward) forwardRequest = request.clone();
|
|
1059
1161
|
let bodyText;
|
|
1060
1162
|
try {
|
|
1061
|
-
|
|
1163
|
+
const read = await readRequestBody(request, maxRequestBodySize);
|
|
1164
|
+
if (read.tooLarge) return { step: "body-too-large" };
|
|
1165
|
+
bodyText = read.text;
|
|
1062
1166
|
} catch {
|
|
1063
1167
|
return { step: "unreadable-body" };
|
|
1064
1168
|
}
|
|
@@ -1078,9 +1182,7 @@ async function classifyEntryRequest(request, providedParsedBody, needsForward =
|
|
|
1078
1182
|
step: "classified",
|
|
1079
1183
|
outcome: require_src.classifyInboundRequest({
|
|
1080
1184
|
httpMethod,
|
|
1081
|
-
|
|
1082
|
-
mcpMethodHeader: request.headers.get("mcp-method") ?? void 0,
|
|
1083
|
-
mcpNameHeader: request.headers.get("mcp-name") ?? void 0,
|
|
1185
|
+
...standardHeadersOf(request),
|
|
1084
1186
|
...body !== void 0 && { body }
|
|
1085
1187
|
}),
|
|
1086
1188
|
body,
|
|
@@ -1148,7 +1250,8 @@ async function classifyEntryRequest(request, providedParsedBody, needsForward =
|
|
|
1148
1250
|
* answers it with the unsupported-protocol-version error), a malformed
|
|
1149
1251
|
* envelope behind a present claim (answered `-32602`), a request whose
|
|
1150
1252
|
* `MCP-Protocol-Version` header names a modern revision but that lacks the
|
|
1151
|
-
* envelope (`-32602`),
|
|
1253
|
+
* envelope (`-32602`), header/body mismatches (`-32020`), and a POST body
|
|
1254
|
+
* over the size limit (413). Consumers
|
|
1152
1255
|
* routing on the predicate must send `false` traffic to the modern handler,
|
|
1153
1256
|
* never to a legacy handler — the modern path owns those error answers.
|
|
1154
1257
|
* - `server/discover` probes sent by negotiating clients always carry the
|
|
@@ -1156,8 +1259,9 @@ async function classifyEntryRequest(request, providedParsedBody, needsForward =
|
|
|
1156
1259
|
* a method named `server/discover` has no claim and classifies legacy,
|
|
1157
1260
|
* exactly as the entry itself routes it.
|
|
1158
1261
|
*/
|
|
1159
|
-
async function isLegacyRequest(request, parsedBody) {
|
|
1160
|
-
const
|
|
1262
|
+
async function isLegacyRequest(request, parsedBody, options) {
|
|
1263
|
+
const maxRequestBodySize = resolveMaxRequestBodySize(options?.maxRequestBodySize);
|
|
1264
|
+
const classified = await classifyEntryRequest(parsedBody === void 0 && request.method.toUpperCase() === "POST" ? request.clone() : request, parsedBody, false, maxRequestBodySize);
|
|
1161
1265
|
return classified.step === "no-json-body" || classified.step === "classified" && classified.outcome.kind === "legacy";
|
|
1162
1266
|
}
|
|
1163
1267
|
/**
|
|
@@ -1206,6 +1310,7 @@ async function isLegacyRequest(request, parsedBody) {
|
|
|
1206
1310
|
*/
|
|
1207
1311
|
function createMcpHandler(factory, options = {}) {
|
|
1208
1312
|
const { legacy, onerror, responseMode } = options;
|
|
1313
|
+
const maxRequestBodySize = resolveMaxRequestBodySize(options.maxRequestBodySize);
|
|
1209
1314
|
if (typeof legacy === "function") throw new TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");
|
|
1210
1315
|
/** Modern per-request instances with an exchange still in flight (close() tears these down). */
|
|
1211
1316
|
const inflight = /* @__PURE__ */ new Set();
|
|
@@ -1224,7 +1329,7 @@ function createMcpHandler(factory, options = {}) {
|
|
|
1224
1329
|
onerror: reportError
|
|
1225
1330
|
});
|
|
1226
1331
|
if (responseMode === "json") console.warn("responseMode: 'json' drops mid-call notifications. subscriptions/listen streams are always served over SSE regardless; other notifications emitted before a result are dropped.");
|
|
1227
|
-
const legacyHandler = legacy === "reject" ? void 0 : createLegacyStatelessFallback(factory, reportError, options.keepAliveMs);
|
|
1332
|
+
const legacyHandler = legacy === "reject" ? void 0 : createLegacyStatelessFallback(factory, reportError, options.keepAliveMs, maxRequestBodySize);
|
|
1228
1333
|
async function serveModern(route, request, authInfo) {
|
|
1229
1334
|
const claimedRevision = route.classification.revision;
|
|
1230
1335
|
if (claimedRevision === void 0 || !require_src.SUPPORTED_MODERN_PROTOCOL_VERSIONS.includes(claimedRevision)) {
|
|
@@ -1237,8 +1342,7 @@ function createMcpHandler(factory, options = {}) {
|
|
|
1237
1342
|
}
|
|
1238
1343
|
const stdHeaderRejection = require_src.validateStandardRequestHeaders({
|
|
1239
1344
|
httpMethod: request.method,
|
|
1240
|
-
|
|
1241
|
-
mcpNameHeader: request.headers.get("mcp-name") ?? void 0
|
|
1345
|
+
...standardHeadersOf(request)
|
|
1242
1346
|
}, route);
|
|
1243
1347
|
if (stdHeaderRejection !== void 0) {
|
|
1244
1348
|
reportError(/* @__PURE__ */ new Error(`Rejected inbound request (${stdHeaderRejection.cell}): ${stdHeaderRejection.message}`));
|
|
@@ -1285,6 +1389,17 @@ function createMcpHandler(factory, options = {}) {
|
|
|
1285
1389
|
}
|
|
1286
1390
|
}
|
|
1287
1391
|
}
|
|
1392
|
+
if (route.messageKind === "request" && product instanceof require_mcp.McpServer) try {
|
|
1393
|
+
const challenge = await require_mcp.findScopeChallenge([route.message], authInfo, (context) => product.resolveScopeChallenge(context));
|
|
1394
|
+
if (challenge !== void 0) {
|
|
1395
|
+
product.close().catch(reportError);
|
|
1396
|
+
return require_mcp.createScopeChallengeResponse(challenge, require_mcp.scopeChallengeResourceMetadataUrl(authInfo));
|
|
1397
|
+
}
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
product.close().catch(reportError);
|
|
1400
|
+
reportError(toError(error));
|
|
1401
|
+
return internalServerErrorResponse(route.message.id);
|
|
1402
|
+
}
|
|
1288
1403
|
require_src.setNegotiatedProtocolVersion(server, claimedRevision);
|
|
1289
1404
|
require_mcp.installModernOnlyHandlers(server, require_src.SUPPORTED_MODERN_PROTOCOL_VERSIONS);
|
|
1290
1405
|
if (meta !== void 0) require_mcp.seedClientIdentityFromEnvelope(server, {
|
|
@@ -1331,8 +1446,9 @@ function createMcpHandler(factory, options = {}) {
|
|
|
1331
1446
|
reportError(/* @__PURE__ */ new Error("Unsupported Media Type: Content-Type must be application/json"));
|
|
1332
1447
|
return jsonRpcErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
|
|
1333
1448
|
}
|
|
1334
|
-
const classified = await classifyEntryRequest(request, requestOptions?.parsedBody);
|
|
1449
|
+
const classified = await classifyEntryRequest(request, requestOptions?.parsedBody, true, maxRequestBodySize);
|
|
1335
1450
|
if (classified.step === "unreadable-body") return jsonRpcErrorResponse(400, -32700, "Parse error: the request body could not be read");
|
|
1451
|
+
if (classified.step === "body-too-large") return jsonRpcErrorResponse(413, -32e3, requestBodyTooLargeMessage(maxRequestBodySize));
|
|
1336
1452
|
if (classified.step === "no-json-body") {
|
|
1337
1453
|
if (legacyHandler !== void 0) return legacyHandler(classified.forwardRequest, { ...authInfo !== void 0 && { authInfo } });
|
|
1338
1454
|
return jsonRpcErrorResponse(400, -32700, "Parse error: the request body is not valid JSON");
|
|
@@ -1374,115 +1490,6 @@ function createMcpHandler(factory, options = {}) {
|
|
|
1374
1490
|
};
|
|
1375
1491
|
}
|
|
1376
1492
|
|
|
1377
|
-
//#endregion
|
|
1378
|
-
//#region src/server/middleware/bearerAuth.ts
|
|
1379
|
-
function headerQuotedValue(value) {
|
|
1380
|
-
return value.replaceAll(/[\\"]/g, String.raw`\$&`).replaceAll(/[^\u0020-\u007E]/g, " ");
|
|
1381
|
-
}
|
|
1382
|
-
function buildWwwAuthenticateHeader(errorCode, description, requiredScopes, resourceMetadataUrl) {
|
|
1383
|
-
let header = `Bearer error="${headerQuotedValue(errorCode)}", error_description="${headerQuotedValue(description)}"`;
|
|
1384
|
-
if (requiredScopes.length > 0) header += `, scope="${requiredScopes.join(" ")}"`;
|
|
1385
|
-
if (resourceMetadataUrl) header += `, resource_metadata="${resourceMetadataUrl}"`;
|
|
1386
|
-
return header;
|
|
1387
|
-
}
|
|
1388
|
-
/**
|
|
1389
|
-
* Validate a raw `Authorization` header value as a Bearer token and return
|
|
1390
|
-
* the verified {@link AuthInfo}.
|
|
1391
|
-
*
|
|
1392
|
-
* The runtime-neutral core of Bearer authentication: it parses the header,
|
|
1393
|
-
* runs the verifier, enforces `requiredScopes`, and rejects tokens without an
|
|
1394
|
-
* expiration or past it. On any failure it throws an {@link OAuthError} —
|
|
1395
|
-
* pass that to {@link bearerAuthChallengeResponse} for the matching HTTP
|
|
1396
|
-
* answer, or use {@link requireBearerAuth} to get both steps as one call.
|
|
1397
|
-
*
|
|
1398
|
-
* Framework adapters build on this: `requireBearerAuth` from
|
|
1399
|
-
* `@modelcontextprotocol/express` feeds it `req.headers.authorization`.
|
|
1400
|
-
*/
|
|
1401
|
-
async function verifyBearerToken(authorizationHeader, options) {
|
|
1402
|
-
const { verifier, requiredScopes = [] } = options;
|
|
1403
|
-
if (!authorizationHeader) throw new require_src.OAuthError(require_src.OAuthErrorCode.InvalidToken, "Missing Authorization header");
|
|
1404
|
-
const [type, token] = authorizationHeader.split(" ");
|
|
1405
|
-
if (type?.toLowerCase() !== "bearer" || !token) throw new require_src.OAuthError(require_src.OAuthErrorCode.InvalidToken, "Invalid Authorization header format, expected 'Bearer TOKEN'");
|
|
1406
|
-
const authInfo = await verifier.verifyAccessToken(token);
|
|
1407
|
-
if (requiredScopes.length > 0) {
|
|
1408
|
-
if (!requiredScopes.every((scope) => authInfo.scopes.includes(scope))) throw new require_src.OAuthError(require_src.OAuthErrorCode.InsufficientScope, "Insufficient scope");
|
|
1409
|
-
}
|
|
1410
|
-
if (typeof authInfo.expiresAt !== "number" || Number.isNaN(authInfo.expiresAt)) throw new require_src.OAuthError(require_src.OAuthErrorCode.InvalidToken, "Token has no expiration time");
|
|
1411
|
-
else if (authInfo.expiresAt < Date.now() / 1e3) throw new require_src.OAuthError(require_src.OAuthErrorCode.InvalidToken, "Token has expired");
|
|
1412
|
-
return authInfo;
|
|
1413
|
-
}
|
|
1414
|
-
/**
|
|
1415
|
-
* Build the HTTP answer for a Bearer authentication failure.
|
|
1416
|
-
*
|
|
1417
|
-
* Maps an {@link OAuthError} to its status — `401` for `invalid_token` and
|
|
1418
|
-
* `403` for `insufficient_scope` (both carrying the `WWW-Authenticate: Bearer …`
|
|
1419
|
-
* challenge, with `resource_metadata` when configured so clients can discover
|
|
1420
|
-
* the Authorization Server), `500` for `server_error`, `400` for anything
|
|
1421
|
-
* else. A non-`OAuthError` value answers `500 server_error`. The body is the
|
|
1422
|
-
* OAuth error JSON.
|
|
1423
|
-
*/
|
|
1424
|
-
function bearerAuthChallengeResponse(error, options) {
|
|
1425
|
-
const { requiredScopes = [], resourceMetadataUrl } = options ?? {};
|
|
1426
|
-
if (!(error instanceof require_src.OAuthError)) {
|
|
1427
|
-
const serverError = new require_src.OAuthError(require_src.OAuthErrorCode.ServerError, "Internal Server Error");
|
|
1428
|
-
return Response.json(serverError.toResponseObject(), { status: 500 });
|
|
1429
|
-
}
|
|
1430
|
-
switch (error.code) {
|
|
1431
|
-
case require_src.OAuthErrorCode.InvalidToken: {
|
|
1432
|
-
const challenge = buildWwwAuthenticateHeader(error.code, error.message, requiredScopes, resourceMetadataUrl);
|
|
1433
|
-
return Response.json(error.toResponseObject(), {
|
|
1434
|
-
status: 401,
|
|
1435
|
-
headers: { "WWW-Authenticate": challenge }
|
|
1436
|
-
});
|
|
1437
|
-
}
|
|
1438
|
-
case require_src.OAuthErrorCode.InsufficientScope: {
|
|
1439
|
-
const challenge = buildWwwAuthenticateHeader(error.code, error.message, requiredScopes, resourceMetadataUrl);
|
|
1440
|
-
return Response.json(error.toResponseObject(), {
|
|
1441
|
-
status: 403,
|
|
1442
|
-
headers: { "WWW-Authenticate": challenge }
|
|
1443
|
-
});
|
|
1444
|
-
}
|
|
1445
|
-
case require_src.OAuthErrorCode.ServerError: return Response.json(error.toResponseObject(), { status: 500 });
|
|
1446
|
-
default: return Response.json(error.toResponseObject(), { status: 400 });
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
/**
|
|
1450
|
-
* Require a valid Bearer token on web-standard requests.
|
|
1451
|
-
*
|
|
1452
|
-
* The framework-free counterpart of `requireBearerAuth` from
|
|
1453
|
-
* `@modelcontextprotocol/express`, for hosts whose HTTP surface is a
|
|
1454
|
-
* `fetch(request)` handler — Cloudflare Workers, Deno, Bun, Hono. The
|
|
1455
|
-
* returned gate resolves to the verified {@link AuthInfo}, or to the
|
|
1456
|
-
* ready-to-return challenge `Response` when the request must be refused.
|
|
1457
|
-
*
|
|
1458
|
-
* @example
|
|
1459
|
-
* ```ts source="./bearerAuth.examples.ts#requireBearerAuth_fetchGate"
|
|
1460
|
-
* const gate = requireBearerAuth({ verifier, requiredScopes: ['mcp'] });
|
|
1461
|
-
*
|
|
1462
|
-
* async function fetchHandler(request: Request): Promise<Response> {
|
|
1463
|
-
* const auth: AuthInfo | Response = await gate(request);
|
|
1464
|
-
* if (auth instanceof Response) return auth;
|
|
1465
|
-
* return handler.fetch(request, { authInfo: auth });
|
|
1466
|
-
* }
|
|
1467
|
-
* ```
|
|
1468
|
-
*/
|
|
1469
|
-
function requireBearerAuth(options) {
|
|
1470
|
-
const { verifier, requiredScopes = [], resourceMetadataUrl } = options;
|
|
1471
|
-
const resolved = {
|
|
1472
|
-
verifier,
|
|
1473
|
-
requiredScopes,
|
|
1474
|
-
resourceMetadataUrl
|
|
1475
|
-
};
|
|
1476
|
-
return async (request) => {
|
|
1477
|
-
const [authorizationHeader] = (request.headers.get("authorization") ?? "").split(",");
|
|
1478
|
-
try {
|
|
1479
|
-
return await verifyBearerToken(authorizationHeader || void 0, resolved);
|
|
1480
|
-
} catch (error) {
|
|
1481
|
-
return bearerAuthChallengeResponse(error, resolved);
|
|
1482
|
-
}
|
|
1483
|
-
};
|
|
1484
|
-
}
|
|
1485
|
-
|
|
1486
1493
|
//#endregion
|
|
1487
1494
|
//#region src/server/middleware/hostHeaderValidation.ts
|
|
1488
1495
|
/**
|
|
@@ -1553,120 +1560,6 @@ function hostHeaderValidationResponse(req, allowedHostnames) {
|
|
|
1553
1560
|
});
|
|
1554
1561
|
}
|
|
1555
1562
|
|
|
1556
|
-
//#endregion
|
|
1557
|
-
//#region src/server/middleware/oauthMetadata.ts
|
|
1558
|
-
function checkIssuerUrl(issuer, allowInsecure) {
|
|
1559
|
-
if (issuer.protocol !== "https:" && issuer.hostname !== "localhost" && issuer.hostname !== "127.0.0.1" && !allowInsecure) throw new Error("Issuer URL must be HTTPS");
|
|
1560
|
-
if (issuer.hash) throw new Error(`Issuer URL must not have a fragment: ${issuer}`);
|
|
1561
|
-
if (issuer.search) throw new Error(`Issuer URL must not have a query string: ${issuer}`);
|
|
1562
|
-
}
|
|
1563
|
-
/**
|
|
1564
|
-
* Derive the RFC 9728 Protected Resource Metadata document from
|
|
1565
|
-
* {@link AuthMetadataOptions}, validating the Authorization Server issuer URL
|
|
1566
|
-
* (HTTPS required outside localhost) in the process.
|
|
1567
|
-
*
|
|
1568
|
-
* `oauthMetadataResponse` and the Express `mcpAuthMetadataRouter` both build
|
|
1569
|
-
* on this; use it directly when serving the document through your own
|
|
1570
|
-
* routing — or call it once at startup to fail fast on a misconfigured
|
|
1571
|
-
* issuer before any request arrives.
|
|
1572
|
-
*/
|
|
1573
|
-
function buildOAuthProtectedResourceMetadata(options) {
|
|
1574
|
-
checkIssuerUrl(new URL(options.oauthMetadata.issuer), options.dangerouslyAllowInsecureIssuerUrl);
|
|
1575
|
-
return {
|
|
1576
|
-
resource: options.resourceServerUrl.href,
|
|
1577
|
-
authorization_servers: [options.oauthMetadata.issuer],
|
|
1578
|
-
scopes_supported: options.scopesSupported,
|
|
1579
|
-
resource_name: options.resourceName,
|
|
1580
|
-
resource_documentation: options.serviceDocumentationUrl?.href
|
|
1581
|
-
};
|
|
1582
|
-
}
|
|
1583
|
-
/**
|
|
1584
|
-
* Builds the RFC 9728 Protected Resource Metadata URL for a given MCP server
|
|
1585
|
-
* URL by inserting `/.well-known/oauth-protected-resource` ahead of the path.
|
|
1586
|
-
*
|
|
1587
|
-
* @example
|
|
1588
|
-
* ```ts
|
|
1589
|
-
* getOAuthProtectedResourceMetadataUrl(new URL('https://api.example.com/mcp'))
|
|
1590
|
-
* // → 'https://api.example.com/.well-known/oauth-protected-resource/mcp'
|
|
1591
|
-
* ```
|
|
1592
|
-
*/
|
|
1593
|
-
function getOAuthProtectedResourceMetadataUrl(serverUrl) {
|
|
1594
|
-
return new URL(protectedResourceMetadataPath(serverUrl), serverUrl).href;
|
|
1595
|
-
}
|
|
1596
|
-
/** The RFC 9728 path-aware well-known path for a resource URL. */
|
|
1597
|
-
function protectedResourceMetadataPath(resourceServerUrl) {
|
|
1598
|
-
const rsPath = stripTrailingSlash(resourceServerUrl.pathname);
|
|
1599
|
-
return `/.well-known/oauth-protected-resource${rsPath === "/" ? "" : rsPath}`;
|
|
1600
|
-
}
|
|
1601
|
-
function stripTrailingSlash(path) {
|
|
1602
|
-
return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
|
|
1603
|
-
}
|
|
1604
|
-
const ALLOWED_METHODS = "GET, HEAD, OPTIONS";
|
|
1605
|
-
function metadataDocumentResponse(request, metadata) {
|
|
1606
|
-
if (request.method === "OPTIONS") {
|
|
1607
|
-
const requestedHeaders = request.headers.get("access-control-request-headers");
|
|
1608
|
-
return new Response(null, {
|
|
1609
|
-
status: 204,
|
|
1610
|
-
headers: {
|
|
1611
|
-
"Access-Control-Allow-Origin": "*",
|
|
1612
|
-
"Access-Control-Allow-Methods": ALLOWED_METHODS,
|
|
1613
|
-
...requestedHeaders === null ? {} : {
|
|
1614
|
-
"Access-Control-Allow-Headers": requestedHeaders,
|
|
1615
|
-
Vary: "Access-Control-Request-Headers"
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
});
|
|
1619
|
-
}
|
|
1620
|
-
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
1621
|
-
const error = new require_src.OAuthError(require_src.OAuthErrorCode.MethodNotAllowed, `The method ${request.method} is not allowed for this endpoint`);
|
|
1622
|
-
return Response.json(error.toResponseObject(), {
|
|
1623
|
-
status: 405,
|
|
1624
|
-
headers: {
|
|
1625
|
-
Allow: ALLOWED_METHODS,
|
|
1626
|
-
"Access-Control-Allow-Origin": "*"
|
|
1627
|
-
}
|
|
1628
|
-
});
|
|
1629
|
-
}
|
|
1630
|
-
const response = Response.json(metadata, { headers: { "Access-Control-Allow-Origin": "*" } });
|
|
1631
|
-
return request.method === "HEAD" ? new Response(null, {
|
|
1632
|
-
status: response.status,
|
|
1633
|
-
headers: response.headers
|
|
1634
|
-
}) : response;
|
|
1635
|
-
}
|
|
1636
|
-
/**
|
|
1637
|
-
* Serve the two OAuth discovery documents an MCP server acting as a Resource
|
|
1638
|
-
* Server exposes, from a web-standard `fetch(request)` handler:
|
|
1639
|
-
*
|
|
1640
|
-
* - `/.well-known/oauth-protected-resource[/<path>]` — RFC 9728 Protected
|
|
1641
|
-
* Resource Metadata, derived from the supplied options (path-aware: the
|
|
1642
|
-
* resource URL's path is reflected in the route).
|
|
1643
|
-
* - `/.well-known/oauth-authorization-server` — RFC 8414 Authorization
|
|
1644
|
-
* Server Metadata, passed through verbatim.
|
|
1645
|
-
*
|
|
1646
|
-
* Returns the matched document `Response` (JSON with permissive CORS, `405`
|
|
1647
|
-
* with an `Allow` header for non-GET methods, `204` for CORS preflight), or
|
|
1648
|
-
* `undefined` when the request path is neither well-known route — fall
|
|
1649
|
-
* through to your own routing. The framework-free counterpart of
|
|
1650
|
-
* `mcpAuthMetadataRouter` from `@modelcontextprotocol/express`; pair it with
|
|
1651
|
-
* `requireBearerAuth` and `getOAuthProtectedResourceMetadataUrl` so
|
|
1652
|
-
* unauthenticated clients can discover the AS from the `401` challenge.
|
|
1653
|
-
*
|
|
1654
|
-
* @example
|
|
1655
|
-
* ```ts source="./oauthMetadata.examples.ts#oauthMetadataResponse_fetchHandler"
|
|
1656
|
-
* async function fetchHandler(request: Request): Promise<Response> {
|
|
1657
|
-
* return oauthMetadataResponse(request, options) ?? serveMcp(request);
|
|
1658
|
-
* }
|
|
1659
|
-
* ```
|
|
1660
|
-
*/
|
|
1661
|
-
function oauthMetadataResponse(request, options) {
|
|
1662
|
-
const requestPath = stripTrailingSlash(new URL(request.url).pathname);
|
|
1663
|
-
if (requestPath === protectedResourceMetadataPath(options.resourceServerUrl)) return metadataDocumentResponse(request, buildOAuthProtectedResourceMetadata(options));
|
|
1664
|
-
if (requestPath === "/.well-known/oauth-authorization-server") {
|
|
1665
|
-
buildOAuthProtectedResourceMetadata(options);
|
|
1666
|
-
return metadataDocumentResponse(request, options.oauthMetadata);
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
1563
|
//#endregion
|
|
1671
1564
|
//#region src/server/middleware/originValidation.ts
|
|
1672
1565
|
/**
|
|
@@ -1886,6 +1779,7 @@ Object.defineProperty(exports, 'CLIENT_INFO_META_KEY', {
|
|
|
1886
1779
|
return _modelcontextprotocol_core_internal.CLIENT_INFO_META_KEY;
|
|
1887
1780
|
}
|
|
1888
1781
|
});
|
|
1782
|
+
exports.DEFAULT_MAX_REQUEST_BODY_SIZE = DEFAULT_MAX_REQUEST_BODY_SIZE;
|
|
1889
1783
|
Object.defineProperty(exports, 'DEFAULT_NEGOTIATED_PROTOCOL_VERSION', {
|
|
1890
1784
|
enumerable: true,
|
|
1891
1785
|
get: function () {
|
|
@@ -2008,8 +1902,8 @@ exports.WebStandardStreamableHTTPServerTransport = WebStandardStreamableHTTPServ
|
|
|
2008
1902
|
exports.acceptedContent = require_src.acceptedContent;
|
|
2009
1903
|
exports.assertCompleteRequestPrompt = require_src.assertCompleteRequestPrompt;
|
|
2010
1904
|
exports.assertCompleteRequestResourceTemplate = require_src.assertCompleteRequestResourceTemplate;
|
|
2011
|
-
exports.bearerAuthChallengeResponse = bearerAuthChallengeResponse;
|
|
2012
|
-
exports.buildOAuthProtectedResourceMetadata = buildOAuthProtectedResourceMetadata;
|
|
1905
|
+
exports.bearerAuthChallengeResponse = require_mcp.bearerAuthChallengeResponse;
|
|
1906
|
+
exports.buildOAuthProtectedResourceMetadata = require_mcp.buildOAuthProtectedResourceMetadata;
|
|
2013
1907
|
exports.checkResourceAllowed = require_src.checkResourceAllowed;
|
|
2014
1908
|
exports.classifyInboundRequest = require_src.classifyInboundRequest;
|
|
2015
1909
|
exports.completable = require_mcp.completable;
|
|
@@ -2019,7 +1913,7 @@ exports.createRequestStateCodec = createRequestStateCodec;
|
|
|
2019
1913
|
exports.deserializeMessage = require_src.deserializeMessage;
|
|
2020
1914
|
exports.fromJsonSchema = fromJsonSchema;
|
|
2021
1915
|
exports.getDisplayName = require_src.getDisplayName;
|
|
2022
|
-
exports.getOAuthProtectedResourceMetadataUrl = getOAuthProtectedResourceMetadataUrl;
|
|
1916
|
+
exports.getOAuthProtectedResourceMetadataUrl = require_mcp.getOAuthProtectedResourceMetadataUrl;
|
|
2023
1917
|
exports.hostHeaderValidationResponse = hostHeaderValidationResponse;
|
|
2024
1918
|
exports.inputRequired = require_src.inputRequired;
|
|
2025
1919
|
exports.inputResponse = require_src.inputResponse;
|
|
@@ -2041,15 +1935,17 @@ exports.legacyStatelessFallback = legacyStatelessFallback;
|
|
|
2041
1935
|
exports.localhostAllowedHostnames = localhostAllowedHostnames;
|
|
2042
1936
|
exports.localhostAllowedOrigins = localhostAllowedOrigins;
|
|
2043
1937
|
exports.mergeCapabilities = require_src.mergeCapabilities;
|
|
2044
|
-
exports.oauthMetadataResponse = oauthMetadataResponse;
|
|
1938
|
+
exports.oauthMetadataResponse = require_mcp.oauthMetadataResponse;
|
|
2045
1939
|
exports.originValidationResponse = originValidationResponse;
|
|
2046
1940
|
exports.parseJSONRPCMessage = require_src.parseJSONRPCMessage;
|
|
2047
1941
|
exports.preloadSchemas = require_src.preloadSchemas;
|
|
2048
|
-
exports.
|
|
1942
|
+
exports.readRequestBody = readRequestBody;
|
|
1943
|
+
exports.requireBearerAuth = require_mcp.requireBearerAuth;
|
|
1944
|
+
exports.requireScopes = require_mcp.requireScopes;
|
|
2049
1945
|
exports.resourceUrlFromServerUrl = require_src.resourceUrlFromServerUrl;
|
|
2050
1946
|
exports.serializeMessage = require_src.serializeMessage;
|
|
2051
1947
|
exports.specTypeSchemas = require_src.specTypeSchemas;
|
|
2052
1948
|
exports.validateHostHeader = validateHostHeader;
|
|
2053
1949
|
exports.validateOriginHeader = validateOriginHeader;
|
|
2054
|
-
exports.verifyBearerToken = verifyBearerToken;
|
|
1950
|
+
exports.verifyBearerToken = require_mcp.verifyBearerToken;
|
|
2055
1951
|
//# sourceMappingURL=index.cjs.map
|