@forklaunch/core 4.1.1 → 4.3.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.
Files changed (44) hide show
  1. package/bin/gateway-mock/routes/payments.mjs +5 -2
  2. package/lib/agent/agent.d.ts +14 -0
  3. package/lib/agent/agent.d.ts.map +1 -1
  4. package/lib/agent/approvals.d.ts +52 -0
  5. package/lib/agent/approvals.d.ts.map +1 -0
  6. package/lib/agent/continuation.d.ts +28 -3
  7. package/lib/agent/continuation.d.ts.map +1 -1
  8. package/lib/agent/index.d.ts +4 -2
  9. package/lib/agent/index.d.ts.map +1 -1
  10. package/lib/agent/index.js +191 -50
  11. package/lib/agent/index.js.map +1 -1
  12. package/lib/agent/index.mjs +185 -49
  13. package/lib/agent/index.mjs.map +1 -1
  14. package/lib/agent/types.d.ts +22 -2
  15. package/lib/agent/types.d.ts.map +1 -1
  16. package/lib/http/index.d.ts +2 -0
  17. package/lib/http/index.d.ts.map +1 -1
  18. package/lib/http/index.js +610 -221
  19. package/lib/http/index.js.map +1 -1
  20. package/lib/http/index.mjs +607 -222
  21. package/lib/http/index.mjs.map +1 -1
  22. package/lib/http/mcpGenerator/mcpAuth.d.ts +52 -0
  23. package/lib/http/mcpGenerator/mcpAuth.d.ts.map +1 -0
  24. package/lib/http/mcpGenerator/mcpGenerator.d.ts +2 -1
  25. package/lib/http/mcpGenerator/mcpGenerator.d.ts.map +1 -1
  26. package/lib/http/mcpGenerator/mcpHttpHandler.d.ts +14 -1
  27. package/lib/http/mcpGenerator/mcpHttpHandler.d.ts.map +1 -1
  28. package/lib/http/mcpGenerator/mcpOAuth.d.ts +110 -0
  29. package/lib/http/mcpGenerator/mcpOAuth.d.ts.map +1 -0
  30. package/lib/http/paymentsClient.d.ts +6 -0
  31. package/lib/http/paymentsClient.d.ts.map +1 -1
  32. package/lib/http/telemetry/pinoLogger.d.ts +2 -1
  33. package/lib/http/telemetry/pinoLogger.d.ts.map +1 -1
  34. package/lib/http/types/expressLikeOptions.d.ts +8 -0
  35. package/lib/http/types/expressLikeOptions.d.ts.map +1 -1
  36. package/lib/persistence/index.d.ts +1 -0
  37. package/lib/persistence/index.d.ts.map +1 -1
  38. package/lib/persistence/index.js +39 -0
  39. package/lib/persistence/index.js.map +1 -1
  40. package/lib/persistence/index.mjs +38 -0
  41. package/lib/persistence/index.mjs.map +1 -1
  42. package/lib/persistence/migrationLock.d.ts +61 -0
  43. package/lib/persistence/migrationLock.d.ts.map +1 -0
  44. package/package.json +5 -4
package/lib/http/index.js CHANGED
@@ -50,6 +50,7 @@ __export(http_exports, {
50
50
  INSTANCE_GATEWAY_MOUNT: () => INSTANCE_GATEWAY_MOUNT,
51
51
  InMemoryHmacNonceStore: () => InMemoryHmacNonceStore,
52
52
  InstanceGatewayRequestError: () => InstanceGatewayRequestError,
53
+ McpInsufficientScopeError: () => McpInsufficientScopeError,
53
54
  ModelGatewayRequestError: () => ModelGatewayRequestError,
54
55
  OPENAPI_DEFAULT_VERSION: () => OPENAPI_DEFAULT_VERSION,
55
56
  OpenTelemetryCollector: () => OpenTelemetryCollector,
@@ -73,15 +74,18 @@ __export(http_exports, {
73
74
  auditEnabled: () => auditEnabled,
74
75
  auditEventType: () => auditEventType,
75
76
  bindRuntimeAuth: () => bindRuntimeAuth,
77
+ canonicalMcpResource: () => canonicalMcpResource,
76
78
  createContext: () => createContext,
77
79
  createEmailClient: () => createEmailClient,
78
80
  createHmacToken: () => createHmacToken,
79
81
  createInstanceGatewayTransport: () => createInstanceGatewayTransport,
80
82
  createLocalModelGatewayClient: () => createLocalModelGatewayClient,
81
83
  createMcpHttpHandler: () => createMcpHttpHandler,
84
+ createMcpOAuthAuthenticate: () => createMcpOAuthAuthenticate,
82
85
  createModelGatewayClient: () => createModelGatewayClient,
83
86
  createPaymentsClient: () => createPaymentsClient,
84
87
  createPreviewModelGatewayClient: () => createPreviewModelGatewayClient,
88
+ createRouteMcpAuthenticate: () => createRouteMcpAuthenticate,
85
89
  createSmsClient: () => createSmsClient,
86
90
  createStripeClient: () => createStripeClient,
87
91
  createVoiceClient: () => createVoiceClient,
@@ -127,6 +131,8 @@ __export(http_exports, {
127
131
  jwtAlgorithmsForSharedSecret: () => jwtAlgorithmsForSharedSecret,
128
132
  jwtClaimChecks: () => jwtClaimChecks,
129
133
  logger: () => logger,
134
+ mcpBearerChallenge: () => mcpBearerChallenge,
135
+ mcpProtectedResourceMetadata: () => mcpProtectedResourceMetadata,
130
136
  meta: () => meta,
131
137
  metricsDefinitions: () => metricsDefinitions,
132
138
  middleware: () => middleware,
@@ -140,6 +146,7 @@ __export(http_exports, {
140
146
  resetProcessHandlersForTesting: () => resetProcessHandlersForTesting,
141
147
  resolveHmacMaxSkewMs: () => resolveHmacMaxSkewMs,
142
148
  resolveHmacNonceStore: () => resolveHmacNonceStore,
149
+ resolveMcpOAuth: () => resolveMcpOAuth,
143
150
  signPlatformEvent: () => signPlatformEvent,
144
151
  smsSegments: () => smsSegments,
145
152
  stripeGatewayFetch: () => stripeGatewayFetch,
@@ -444,7 +451,6 @@ function isForklaunchRequest(request) {
444
451
  // src/http/telemetry/pinoLogger.ts
445
452
  var import_common2 = require("@forklaunch/common");
446
453
  var import_api = require("@opentelemetry/api");
447
- var import_api_logs = require("@opentelemetry/api-logs");
448
454
  var import_pino = __toESM(require("pino"));
449
455
 
450
456
  // src/http/guards/isLoggerMeta.ts
@@ -576,7 +582,7 @@ var PinoLogger = class _PinoLogger {
576
582
  this._pinoLogger[level](...normalizeLogArgs(filteredArgs));
577
583
  const formattedBody = safePrettyFormat(level, filteredArgs);
578
584
  try {
579
- import_api_logs.logs.getLogger(process.env.OTEL_SERVICE_NAME ?? "unknown").emit({
585
+ import_api.logs.getLogger(process.env.OTEL_SERVICE_NAME ?? "unknown").emit({
580
586
  severityText: level,
581
587
  severityNumber: mapSeverity(level),
582
588
  body: formattedBody,
@@ -1393,15 +1399,15 @@ var MAX_CLAIM_LENGTH = 128;
1393
1399
  function bounded(value) {
1394
1400
  return typeof value === "string" && value.length > 0 ? value.slice(0, MAX_CLAIM_LENGTH) : void 0;
1395
1401
  }
1396
- function authLogContext(headerValue) {
1397
- if (typeof headerValue !== "string" || headerValue.length === 0) {
1402
+ function authLogContext(headerValue2) {
1403
+ if (typeof headerValue2 !== "string" || headerValue2.length === 0) {
1398
1404
  return { hasToken: false };
1399
1405
  }
1400
1406
  const context2 = {
1401
1407
  hasToken: true,
1402
- tokenFingerprint: (0, import_crypto3.createHash)("sha256").update(headerValue).digest("hex").slice(0, FINGERPRINT_LENGTH)
1408
+ tokenFingerprint: (0, import_crypto3.createHash)("sha256").update(headerValue2).digest("hex").slice(0, FINGERPRINT_LENGTH)
1403
1409
  };
1404
- const parts = headerValue.trim().split(/\s+/);
1410
+ const parts = headerValue2.trim().split(/\s+/);
1405
1411
  const candidate = parts[parts.length - 1];
1406
1412
  if (candidate.split(".").length !== 3) {
1407
1413
  return context2;
@@ -3600,21 +3606,21 @@ function refuse(message) {
3600
3606
  }
3601
3607
  function addresses(value, field) {
3602
3608
  if (value === void 0) return void 0;
3603
- const list = Array.isArray(value) ? value : [value];
3604
- if (list.length === 0) refuse(`${field} must name at least one address`);
3605
- if (list.length > EMAIL_LIMITS.maxRecipients) {
3609
+ const list2 = Array.isArray(value) ? value : [value];
3610
+ if (list2.length === 0) refuse(`${field} must name at least one address`);
3611
+ if (list2.length > EMAIL_LIMITS.maxRecipients) {
3606
3612
  refuse(
3607
- `${field} has ${list.length} addresses; the limit is ${EMAIL_LIMITS.maxRecipients}`
3613
+ `${field} has ${list2.length} addresses; the limit is ${EMAIL_LIMITS.maxRecipients}`
3608
3614
  );
3609
3615
  }
3610
- for (const address of list) {
3616
+ for (const address of list2) {
3611
3617
  if (!isEmailAddress(address)) {
3612
3618
  refuse(
3613
3619
  `${field}: '${String(address).slice(0, 80)}' is not an email address`
3614
3620
  );
3615
3621
  }
3616
3622
  }
3617
- return list;
3623
+ return list2;
3618
3624
  }
3619
3625
  function fail(problem) {
3620
3626
  refuse(`listUnsubscribe: ${problem}`);
@@ -5306,16 +5312,314 @@ function unpackRouters(routers, recursiveBasePath = []) {
5306
5312
  }, []);
5307
5313
  }
5308
5314
 
5315
+ // src/http/mcpGenerator/mcpAuth.ts
5316
+ function mcpAuthHeaderNames(auth) {
5317
+ const names = /* @__PURE__ */ new Set(["authorization"]);
5318
+ if (auth?.headerName) {
5319
+ names.add(auth.headerName.toLowerCase());
5320
+ }
5321
+ return names;
5322
+ }
5323
+ function routeRequiresAuth(contractDetails) {
5324
+ return contractDetails.auth != null && contractDetails.access !== "public";
5325
+ }
5326
+ function headerValue(headers, name) {
5327
+ if (!headers) {
5328
+ return void 0;
5329
+ }
5330
+ if (typeof headers.get === "function") {
5331
+ return headers.get(name) ?? void 0;
5332
+ }
5333
+ const value = headers[name];
5334
+ return Array.isArray(value) ? value[0] : value;
5335
+ }
5336
+ function sameCredentialSource(a, b) {
5337
+ const fields = ["headerName", "tokenPrefix", "decodeResource"];
5338
+ if (fields.some((field) => a[field] !== b[field])) {
5339
+ return false;
5340
+ }
5341
+ if (isJwtAuthMethod(a) && isJwtAuthMethod(b)) {
5342
+ const ja = a.jwt;
5343
+ const jb = b.jwt;
5344
+ const keys = /* @__PURE__ */ new Set([...Object.keys(ja), ...Object.keys(jb)]);
5345
+ return [...keys].every(
5346
+ (key) => JSON.stringify(ja[key]) === JSON.stringify(jb[key])
5347
+ );
5348
+ }
5349
+ if (isBasicAuthMethod(a) && isBasicAuthMethod(b)) {
5350
+ return a.basic.login === b.basic.login;
5351
+ }
5352
+ return false;
5353
+ }
5354
+ function createRouteMcpAuthenticate(routeAuths) {
5355
+ const sources = [];
5356
+ for (const auth of routeAuths) {
5357
+ if (isHmacMethod(auth)) {
5358
+ continue;
5359
+ }
5360
+ if (!sources.some((source) => sameCredentialSource(source, auth))) {
5361
+ sources.push(auth);
5362
+ }
5363
+ }
5364
+ return async (request) => {
5365
+ for (const auth of sources) {
5366
+ const credential = headerValue(
5367
+ request.headers,
5368
+ (auth.headerName ?? "authorization").toLowerCase()
5369
+ );
5370
+ if (!credential) {
5371
+ continue;
5372
+ }
5373
+ const [prefix, ...parts] = credential.split(" ");
5374
+ const [token] = parts;
5375
+ if (!prefix || !token) {
5376
+ continue;
5377
+ }
5378
+ try {
5379
+ const method = await discriminateAuthMethod(
5380
+ auth
5381
+ );
5382
+ switch (method.type) {
5383
+ case "jwt": {
5384
+ if (prefix !== (auth.tokenPrefix ?? "Bearer")) {
5385
+ continue;
5386
+ }
5387
+ const payload = "decodeResource" in method.auth && method.auth.decodeResource ? await method.auth.decodeResource(token) : "verificationFunction" in method.auth ? await method.auth.verificationFunction(token) : void 0;
5388
+ if (payload) {
5389
+ return { ...payload };
5390
+ }
5391
+ break;
5392
+ }
5393
+ case "basic": {
5394
+ if (prefix !== (auth.tokenPrefix ?? "Basic")) {
5395
+ continue;
5396
+ }
5397
+ if (method.auth.decodeResource) {
5398
+ const payload = await method.auth.decodeResource(token);
5399
+ if (payload) {
5400
+ return { ...payload };
5401
+ }
5402
+ break;
5403
+ }
5404
+ const [username, password] = Buffer.from(token, "base64").toString("utf-8").split(":");
5405
+ if (username && password && method.auth.login(username, password)) {
5406
+ return { sub: username };
5407
+ }
5408
+ break;
5409
+ }
5410
+ case "hmac":
5411
+ break;
5412
+ }
5413
+ } catch {
5414
+ }
5415
+ }
5416
+ return void 0;
5417
+ };
5418
+ }
5419
+ var generatedAuthenticate = /* @__PURE__ */ new WeakMap();
5420
+ function setGeneratedMcpAuthenticate(mcpServer, authenticate) {
5421
+ if (authenticate) {
5422
+ generatedAuthenticate.set(mcpServer, authenticate);
5423
+ }
5424
+ }
5425
+ function getGeneratedMcpAuthenticate(mcpServer) {
5426
+ return generatedAuthenticate.get(mcpServer);
5427
+ }
5428
+
5309
5429
  // src/http/mcpGenerator/mcpHttpHandler.ts
5310
5430
  var import_webStandardStreamableHttp = require("@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js");
5311
5431
  var import_async_hooks = require("async_hooks");
5312
5432
  var import_crypto6 = require("crypto");
5433
+
5434
+ // src/http/mcpGenerator/mcpOAuth.ts
5435
+ var import_jose3 = require("jose");
5436
+ var WELL_KNOWN = "/.well-known/oauth-protected-resource";
5437
+ function trimTrailingSlashes2(path) {
5438
+ let end = path.length;
5439
+ while (end > 0 && path.charCodeAt(end - 1) === 47) {
5440
+ end--;
5441
+ }
5442
+ return path.slice(0, end);
5443
+ }
5444
+ var list = (value) => value?.split(/[\s,]+/).map((item) => item.trim()).filter(Boolean);
5445
+ function canonicalMcpResource(resource) {
5446
+ const url = new URL(resource);
5447
+ if (url.protocol !== "https:" && url.protocol !== "http:") {
5448
+ throw new Error(`MCP resource must be an http(s) URL: ${resource}`);
5449
+ }
5450
+ return `${url.origin}${trimTrailingSlashes2(url.pathname)}`;
5451
+ }
5452
+ function resolveMcpOAuth(options2, server) {
5453
+ const authorizationServers = options2?.authorizationServers ?? list(process.env.MCP_AUTHORIZATION_SERVERS);
5454
+ if (!authorizationServers || authorizationServers.length === 0) {
5455
+ if (options2) {
5456
+ throw new Error(
5457
+ "mcp.oauth needs at least one authorization server (mcp.oauth.authorizationServers or MCP_AUTHORIZATION_SERVERS)."
5458
+ );
5459
+ }
5460
+ return void 0;
5461
+ }
5462
+ const resource = canonicalMcpResource(
5463
+ options2?.resource ?? process.env.MCP_RESOURCE_URL ?? `${server.protocol}://${server.host}:${server.port}${server.path}`
5464
+ );
5465
+ const resourcePath = trimTrailingSlashes2(new URL(resource).pathname);
5466
+ const metadataUrl = `${new URL(resource).origin}${WELL_KNOWN}${resourcePath}`;
5467
+ const issuer = options2?.issuer ?? authorizationServers;
5468
+ return {
5469
+ resource,
5470
+ authorizationServers,
5471
+ jwksUrl: options2?.jwksUrl ?? process.env.MCP_JWKS_URL,
5472
+ issuer: Array.isArray(issuer) ? [...issuer] : [issuer],
5473
+ algorithms: options2?.algorithms,
5474
+ scopesSupported: options2?.scopesSupported ?? list(process.env.MCP_SCOPES_SUPPORTED),
5475
+ requiredScopes: options2?.requiredScopes ?? list(process.env.MCP_REQUIRED_SCOPES),
5476
+ resourceName: options2?.resourceName,
5477
+ metadataUrl,
5478
+ metadataPaths: [
5479
+ .../* @__PURE__ */ new Set([
5480
+ WELL_KNOWN,
5481
+ `${WELL_KNOWN}${resourcePath}`,
5482
+ `${WELL_KNOWN}${trimTrailingSlashes2(server.path)}`
5483
+ ])
5484
+ ]
5485
+ };
5486
+ }
5487
+ function mcpProtectedResourceMetadata(oauth) {
5488
+ return {
5489
+ resource: oauth.resource,
5490
+ authorization_servers: oauth.authorizationServers,
5491
+ bearer_methods_supported: ["header"],
5492
+ ...oauth.scopesSupported?.length ? { scopes_supported: oauth.scopesSupported } : {},
5493
+ ...oauth.resourceName ? { resource_name: oauth.resourceName } : {}
5494
+ };
5495
+ }
5496
+ function mcpProtectedResourceMetadataResponse(oauth) {
5497
+ return new Response(JSON.stringify(mcpProtectedResourceMetadata(oauth)), {
5498
+ status: 200,
5499
+ headers: {
5500
+ "Content-Type": "application/json",
5501
+ "Cache-Control": "public, max-age=3600"
5502
+ }
5503
+ });
5504
+ }
5505
+ var quoted = (value) => `"${value.replace(/["\\]/g, "\\$&")}"`;
5506
+ function mcpBearerChallenge(oauth, error) {
5507
+ const parts = [];
5508
+ if (error) {
5509
+ parts.push(`error=${quoted(error.code)}`);
5510
+ }
5511
+ if (oauth) {
5512
+ const scope = oauth.requiredScopes?.length ? oauth.requiredScopes : oauth.scopesSupported;
5513
+ if (scope?.length) {
5514
+ parts.push(`scope=${quoted(scope.join(" "))}`);
5515
+ }
5516
+ parts.push(`resource_metadata=${quoted(oauth.metadataUrl)}`);
5517
+ }
5518
+ if (error?.description) {
5519
+ parts.push(`error_description=${quoted(error.description)}`);
5520
+ }
5521
+ return parts.length ? `Bearer ${parts.join(", ")}` : "Bearer";
5522
+ }
5523
+ var McpInsufficientScopeError = class extends Error {
5524
+ constructor(missing) {
5525
+ super(`Missing scope: ${missing.join(" ")}`);
5526
+ this.missing = missing;
5527
+ this.name = "McpInsufficientScopeError";
5528
+ }
5529
+ missing;
5530
+ };
5531
+ function tokenScopes(payload) {
5532
+ const scopes = /* @__PURE__ */ new Set();
5533
+ if (typeof payload.scope === "string") {
5534
+ payload.scope.split(" ").forEach((scope) => scope && scopes.add(scope));
5535
+ }
5536
+ if (Array.isArray(payload.scp)) {
5537
+ payload.scp.forEach(
5538
+ (scope) => typeof scope === "string" && scopes.add(scope)
5539
+ );
5540
+ }
5541
+ return scopes;
5542
+ }
5543
+ async function discoverJwksUri(issuer) {
5544
+ const url = new URL(issuer);
5545
+ const path = trimTrailingSlashes2(url.pathname);
5546
+ const candidates = [
5547
+ `${url.origin}/.well-known/oauth-authorization-server${path}`,
5548
+ `${url.origin}/.well-known/openid-configuration${path}`,
5549
+ `${url.origin}${path}/.well-known/openid-configuration`
5550
+ ];
5551
+ for (const candidate of candidates) {
5552
+ try {
5553
+ const response = await fetch(candidate, {
5554
+ headers: { accept: "application/json" },
5555
+ signal: AbortSignal.timeout(5e3)
5556
+ });
5557
+ if (!response.ok) continue;
5558
+ const metadata = await response.json();
5559
+ if (metadata.issuer === issuer && metadata.jwks_uri) {
5560
+ return metadata.jwks_uri;
5561
+ }
5562
+ } catch {
5563
+ }
5564
+ }
5565
+ throw new Error(`No jwks_uri found in the metadata of ${issuer}`);
5566
+ }
5567
+ function createMcpOAuthAuthenticate(oauth, getKey) {
5568
+ let keys = getKey ? Promise.resolve(getKey) : void 0;
5569
+ const resolveKeys = () => {
5570
+ keys ??= (async () => (0, import_jose3.createRemoteJWKSet)(
5571
+ new URL(
5572
+ oauth.jwksUrl ?? await discoverJwksUri(oauth.authorizationServers[0])
5573
+ )
5574
+ ))().catch((error) => {
5575
+ keys = void 0;
5576
+ throw error;
5577
+ });
5578
+ return keys;
5579
+ };
5580
+ return async (request) => {
5581
+ const header = request.headers?.authorization;
5582
+ const value = Array.isArray(header) ? header[0] : header;
5583
+ const match = value?.match(/^Bearer +([^\s]+) *$/i);
5584
+ if (!match) {
5585
+ return void 0;
5586
+ }
5587
+ const { payload } = await (0, import_jose3.jwtVerify)(match[1], await resolveKeys(), {
5588
+ issuer: oauth.issuer,
5589
+ audience: oauth.resource,
5590
+ ...oauth.algorithms ? { algorithms: oauth.algorithms } : {}
5591
+ });
5592
+ if (oauth.requiredScopes?.length) {
5593
+ const granted = tokenScopes(payload);
5594
+ const missing = oauth.requiredScopes.filter(
5595
+ (scope) => !granted.has(scope)
5596
+ );
5597
+ if (missing.length) {
5598
+ throw new McpInsufficientScopeError(missing);
5599
+ }
5600
+ }
5601
+ return { ...payload };
5602
+ };
5603
+ }
5604
+ var generatedOAuth = /* @__PURE__ */ new WeakMap();
5605
+ function setGeneratedMcpOAuth(mcpServer, oauth) {
5606
+ if (oauth) {
5607
+ generatedOAuth.set(mcpServer, oauth);
5608
+ }
5609
+ }
5610
+ function getGeneratedMcpOAuth(mcpServer) {
5611
+ return generatedOAuth.get(mcpServer);
5612
+ }
5613
+
5614
+ // src/http/mcpGenerator/mcpHttpHandler.ts
5313
5615
  var DEFAULT_MCP_SESSION_IDLE_TIMEOUT_MS = 15 * 60 * 1e3;
5314
5616
  var mcpTransportHeaders = new import_async_hooks.AsyncLocalStorage();
5315
5617
  function getMcpTransportHeaders() {
5316
5618
  return mcpTransportHeaders.getStore();
5317
5619
  }
5318
5620
  function createMcpHttpHandler(mcpServer, options2) {
5621
+ const authenticate = options2?.authenticate ?? getGeneratedMcpAuthenticate(mcpServer);
5622
+ const oauth = options2?.oauth ?? getGeneratedMcpOAuth(mcpServer);
5319
5623
  const mode = options2?.sessions ?? "stateless";
5320
5624
  if (mode === "stateful" && (options2?.workerCount ?? 1) > 1) {
5321
5625
  throw new Error(
@@ -5348,16 +5652,32 @@ function createMcpHttpHandler(mcpServer, options2) {
5348
5652
  sweepTimer.unref();
5349
5653
  }
5350
5654
  async function authenticateRequest(authRequest) {
5351
- if (!options2?.authenticate) {
5655
+ if (!authenticate) {
5352
5656
  return { ok: true, auth: void 0 };
5353
5657
  }
5354
5658
  try {
5355
- const auth = await options2.authenticate(authRequest);
5659
+ const auth = await authenticate(authRequest);
5356
5660
  return auth ? { ok: true, auth } : { ok: false };
5357
- } catch {
5358
- return { ok: false };
5661
+ } catch (error) {
5662
+ return error instanceof McpInsufficientScopeError ? { ok: false, insufficientScope: error.missing } : { ok: false };
5359
5663
  }
5360
5664
  }
5665
+ function refuse2(authRequest, insufficientScope) {
5666
+ if (insufficientScope) {
5667
+ return jsonRpcError(403, -32001, "Forbidden", {
5668
+ "WWW-Authenticate": mcpBearerChallenge(oauth, {
5669
+ code: "insufficient_scope"
5670
+ })
5671
+ });
5672
+ }
5673
+ const presented = Boolean(authRequest.headers?.authorization);
5674
+ return jsonRpcError(401, -32001, "Unauthorized", {
5675
+ "WWW-Authenticate": mcpBearerChallenge(
5676
+ oauth,
5677
+ oauth && presented ? { code: "invalid_token" } : void 0
5678
+ )
5679
+ });
5680
+ }
5361
5681
  async function handleStateless(request, auth) {
5362
5682
  if (request.method !== "POST") {
5363
5683
  return jsonRpcError(405, -32e3, "Method not allowed", {
@@ -5430,9 +5750,7 @@ function createMcpHttpHandler(mcpServer, options2) {
5430
5750
  async function handle(request, authRequest) {
5431
5751
  const authResult = await authenticateRequest(authRequest);
5432
5752
  if (!authResult.ok) {
5433
- return jsonRpcError(401, -32001, "Unauthorized", {
5434
- "WWW-Authenticate": "Bearer"
5435
- });
5753
+ return refuse2(authRequest, authResult.insufficientScope);
5436
5754
  }
5437
5755
  return mode === "stateless" ? handleStateless(request, authResult.auth) : handleStateful(request, authResult.auth);
5438
5756
  }
@@ -5444,7 +5762,9 @@ function createMcpHttpHandler(mcpServer, options2) {
5444
5762
  sessions.clear();
5445
5763
  await Promise.all(entries.map(({ session }) => session.close()));
5446
5764
  }
5447
- return { handle, close, sessions };
5765
+ const metadataPaths = oauth?.metadataPaths ?? [];
5766
+ const protectedResourceMetadata = () => oauth ? mcpProtectedResourceMetadataResponse(oauth) : jsonRpcError(404, -32601, "Not found");
5767
+ return { handle, close, sessions, metadataPaths, protectedResourceMetadata };
5448
5768
  }
5449
5769
  function closeWhenBodyEnds(response, done) {
5450
5770
  if (!response.body) {
@@ -5484,6 +5804,7 @@ function isSeparateMcpListener(configuredPort) {
5484
5804
 
5485
5805
  // src/http/mcpGenerator/mcpGenerator.ts
5486
5806
  function generateInputSchema(schemaValidator, body, params, query, requestHeaders, auth) {
5807
+ const toolHeaders = toolInputHeaders(requestHeaders, auth);
5487
5808
  let discriminatedBody;
5488
5809
  if (body) {
5489
5810
  discriminatedBody = discriminateBody(schemaValidator, body);
@@ -5499,30 +5820,38 @@ function generateInputSchema(schemaValidator, body, params, query, requestHeader
5499
5820
  ...query ? {
5500
5821
  query: schemaValidator.schemify(query)
5501
5822
  } : {},
5502
- ...requestHeaders ? {
5503
- headers: schemaValidator.schemify({
5504
- ...requestHeaders,
5505
- ...auth ? {
5506
- [auth.headerName ?? "authorization"]: import_zod.string.startsWith(
5507
- auth.tokenPrefix ?? ("basic" in auth ? "Basic " : "Bearer ")
5508
- )
5509
- } : {}
5510
- })
5823
+ ...toolHeaders ? {
5824
+ headers: schemaValidator.schemify(toolHeaders)
5511
5825
  } : {}
5512
5826
  });
5513
5827
  }
5514
- function buildRouteHeaders(toolHeaders, contentType) {
5828
+ function toolInputHeaders(requestHeaders, auth) {
5829
+ if (!requestHeaders) {
5830
+ return void 0;
5831
+ }
5832
+ const credentialHeaders = mcpAuthHeaderNames(auth);
5833
+ const headers = Object.fromEntries(
5834
+ Object.entries(requestHeaders).filter(
5835
+ ([name]) => !credentialHeaders.has(name.toLowerCase())
5836
+ )
5837
+ );
5838
+ return Object.keys(headers).length > 0 ? headers : void 0;
5839
+ }
5840
+ function buildRouteHeaders(toolHeaders, contentType, auth) {
5515
5841
  const transportHeaders = getMcpTransportHeaders();
5516
5842
  const routeHeaders = new Headers();
5517
- const authorization = transportHeaders?.get("authorization");
5518
- if (authorization) {
5519
- routeHeaders.set("authorization", authorization);
5520
- }
5843
+ const credentialHeaders = mcpAuthHeaderNames(auth);
5521
5844
  for (const [name, value] of Object.entries(toolHeaders ?? {})) {
5522
- if (value != null) {
5845
+ if (value != null && !credentialHeaders.has(name.toLowerCase())) {
5523
5846
  routeHeaders.set(name, String(value));
5524
5847
  }
5525
5848
  }
5849
+ for (const name of credentialHeaders) {
5850
+ const credential = transportHeaders?.get(name);
5851
+ if (credential) {
5852
+ routeHeaders.set(name, credential);
5853
+ }
5854
+ }
5526
5855
  const correlationId = transportHeaders?.get("x-correlation-id");
5527
5856
  if (correlationId) {
5528
5857
  routeHeaders.set("x-correlation-id", correlationId);
@@ -5541,226 +5870,279 @@ function buildRouteHeaders(toolHeaders, contentType) {
5541
5870
  }
5542
5871
  return routeHeaders;
5543
5872
  }
5544
- function generateMcpServer(schemaValidator, protocol, host, port, version, application, appOptions, options2, contentTypeMap, authenticate) {
5873
+ function generateMcpServer(schemaValidator, protocol, host, port, version, application, appOptions, options2, contentTypeMap, authenticate, logger2) {
5545
5874
  if (!(schemaValidator instanceof import_zod.ZodSchemaValidator)) {
5546
5875
  throw new Error(
5547
5876
  "Schema validator must be an instance of ZodSchemaValidator"
5548
5877
  );
5549
5878
  }
5879
+ const exposedRoutes = collectMcpRoutes(application, appOptions);
5880
+ const oauth = resolveMcpOAuth(appOptions ? appOptions.oauth : void 0, {
5881
+ protocol,
5882
+ host,
5883
+ port,
5884
+ path: appOptions && appOptions.path || "/mcp"
5885
+ });
5886
+ const resolvedAuthenticate = oauth ? authenticate ?? createMcpOAuthAuthenticate(oauth) : resolveMcpAuthenticate(exposedRoutes, authenticate, logger2);
5887
+ if (oauth) {
5888
+ logger2?.info(
5889
+ "MCP: OAuth on; the endpoint accepts only access tokens issued for it and publishes its Protected Resource Metadata at /.well-known/oauth-protected-resource."
5890
+ );
5891
+ }
5550
5892
  const mcpServer = new import_fastmcp.FastMCP({
5551
5893
  ...options2,
5552
5894
  name: options2?.name ?? "mcp-server",
5553
5895
  version,
5554
- authenticate
5555
- });
5556
- [
5557
- {
5558
- fullPath: application.basePath === "/" ? "" : application.basePath,
5559
- router: application
5560
- },
5561
- ...unpackRouters(application.routers, [
5562
- application.basePath === "/" ? "" : application.basePath
5563
- ])
5564
- ].forEach(({ fullPath, router }) => {
5565
- router.routes.forEach((route) => {
5566
- if (!(route.contractDetails.options?.mcp ?? router.routerOptions?.mcp ?? appOptions !== false)) {
5567
- return;
5896
+ authenticate: resolvedAuthenticate,
5897
+ ...oauth ? {
5898
+ oauth: {
5899
+ ...options2?.oauth,
5900
+ enabled: true,
5901
+ protectedResource: {
5902
+ resource: oauth.resource,
5903
+ authorizationServers: oauth.authorizationServers,
5904
+ bearerMethodsSupported: ["header"],
5905
+ ...oauth.scopesSupported?.length ? { scopesSupported: oauth.scopesSupported } : {},
5906
+ ...oauth.resourceName ? { resourceName: oauth.resourceName } : {}
5907
+ }
5568
5908
  }
5569
- const inputSchemas = [];
5570
- if (route.contractDetails.versions) {
5571
- Object.values(route.contractDetails.versions).forEach((version2) => {
5572
- inputSchemas.push(
5573
- generateInputSchema(
5574
- schemaValidator,
5575
- version2.body,
5576
- route.contractDetails.params,
5577
- version2.query,
5578
- version2.requestHeaders,
5579
- route.contractDetails.auth
5580
- )
5581
- );
5582
- });
5583
- } else {
5909
+ } : {}
5910
+ });
5911
+ setGeneratedMcpAuthenticate(mcpServer, resolvedAuthenticate);
5912
+ setGeneratedMcpOAuth(mcpServer, oauth);
5913
+ exposedRoutes.forEach(({ fullPath, route }) => {
5914
+ const inputSchemas = [];
5915
+ if (route.contractDetails.versions) {
5916
+ Object.values(route.contractDetails.versions).forEach((version2) => {
5584
5917
  inputSchemas.push(
5585
5918
  generateInputSchema(
5586
5919
  schemaValidator,
5587
- route.contractDetails.body,
5920
+ version2.body,
5588
5921
  route.contractDetails.params,
5589
- route.contractDetails.query,
5590
- route.contractDetails.requestHeaders,
5922
+ version2.query,
5923
+ version2.requestHeaders,
5591
5924
  route.contractDetails.auth
5592
5925
  )
5593
5926
  );
5594
- }
5595
- inputSchemas.forEach((inputSchema, index) => {
5596
- mcpServer.addTool({
5597
- name: route.contractDetails.name + (Object.keys(route.contractDetails.versions ?? {}).length > 1 ? ` [v${Object.keys(route.contractDetails.versions ?? {})[index]}]` : ""),
5598
- description: route.contractDetails.summary,
5599
- parameters: inputSchema,
5600
- execute: async (args) => {
5601
- const { contentType, body, params, query, headers } = args;
5602
- let url = `${protocol}://${host}:${port}${fullPath}${route.path}`;
5603
- if (params) {
5604
- for (const key in params) {
5605
- url = url.replace(
5606
- `:${key}`,
5607
- encodeURIComponent(params[key])
5608
- );
5609
- }
5927
+ });
5928
+ } else {
5929
+ inputSchemas.push(
5930
+ generateInputSchema(
5931
+ schemaValidator,
5932
+ route.contractDetails.body,
5933
+ route.contractDetails.params,
5934
+ route.contractDetails.query,
5935
+ route.contractDetails.requestHeaders,
5936
+ route.contractDetails.auth
5937
+ )
5938
+ );
5939
+ }
5940
+ inputSchemas.forEach((inputSchema, index) => {
5941
+ mcpServer.addTool({
5942
+ name: route.contractDetails.name + (Object.keys(route.contractDetails.versions ?? {}).length > 1 ? ` [v${Object.keys(route.contractDetails.versions ?? {})[index]}]` : ""),
5943
+ description: route.contractDetails.summary,
5944
+ parameters: inputSchema,
5945
+ execute: async (args) => {
5946
+ const { contentType, body, params, query, headers } = args;
5947
+ let url = `${protocol}://${host}:${port}${fullPath}${route.path}`;
5948
+ if (params) {
5949
+ for (const key in params) {
5950
+ url = url.replace(
5951
+ `:${key}`,
5952
+ encodeURIComponent(params[key])
5953
+ );
5610
5954
  }
5611
- let bodySchema;
5612
- let responsesSchemas;
5613
- if (route.contractDetails.versions) {
5614
- const version2 = Object.values(route.contractDetails.versions)[index];
5615
- responsesSchemas = version2.responses;
5616
- if (version2.body && schemaValidator.parse(inputSchema, args).ok) {
5617
- bodySchema = version2.body;
5618
- }
5619
- } else {
5620
- bodySchema = route.contractDetails.body;
5621
- responsesSchemas = route.contractDetails.responses;
5955
+ }
5956
+ let bodySchema;
5957
+ let responsesSchemas;
5958
+ if (route.contractDetails.versions) {
5959
+ const version2 = Object.values(route.contractDetails.versions)[index];
5960
+ responsesSchemas = version2.responses;
5961
+ if (version2.body && schemaValidator.parse(inputSchema, args).ok) {
5962
+ bodySchema = version2.body;
5622
5963
  }
5623
- const discriminatedBody = bodySchema ? discriminateBody(schemaValidator, bodySchema) : void 0;
5624
- let parsedBody;
5625
- if (discriminatedBody) {
5626
- switch (discriminatedBody.parserType) {
5627
- case "json": {
5628
- parsedBody = body === void 0 ? void 0 : JSON.stringify(body);
5629
- break;
5630
- }
5631
- case "text": {
5632
- parsedBody = body;
5633
- break;
5634
- }
5635
- case "file": {
5636
- parsedBody = Buffer.from((0, import_common12.toPlainString)(body));
5637
- break;
5638
- }
5639
- case "multipart": {
5640
- const formData = new FormData();
5641
- if ((0, import_common12.isRecord)(body)) {
5642
- for (const key in body) {
5643
- if (typeof body[key] === "string") {
5644
- if (schemaValidator.isInstanceOf(
5645
- body[key],
5646
- schemaValidator.file
5647
- )) {
5648
- formData.append(
5649
- key,
5650
- new Blob([new Uint8Array(Buffer.from(body[key]))])
5651
- );
5652
- } else {
5653
- formData.append(key, body[key]);
5654
- }
5964
+ } else {
5965
+ bodySchema = route.contractDetails.body;
5966
+ responsesSchemas = route.contractDetails.responses;
5967
+ }
5968
+ const discriminatedBody = bodySchema ? discriminateBody(schemaValidator, bodySchema) : void 0;
5969
+ let parsedBody;
5970
+ if (discriminatedBody) {
5971
+ switch (discriminatedBody.parserType) {
5972
+ case "json": {
5973
+ parsedBody = body === void 0 ? void 0 : JSON.stringify(body);
5974
+ break;
5975
+ }
5976
+ case "text": {
5977
+ parsedBody = body;
5978
+ break;
5979
+ }
5980
+ case "file": {
5981
+ parsedBody = Buffer.from((0, import_common12.toPlainString)(body));
5982
+ break;
5983
+ }
5984
+ case "multipart": {
5985
+ const formData = new FormData();
5986
+ if ((0, import_common12.isRecord)(body)) {
5987
+ for (const key in body) {
5988
+ if (typeof body[key] === "string") {
5989
+ if (schemaValidator.isInstanceOf(
5990
+ body[key],
5991
+ schemaValidator.file
5992
+ )) {
5993
+ formData.append(
5994
+ key,
5995
+ new Blob([new Uint8Array(Buffer.from(body[key]))])
5996
+ );
5655
5997
  } else {
5656
- throw new Error("Body is not a valid multipart object");
5998
+ formData.append(key, body[key]);
5657
5999
  }
6000
+ } else {
6001
+ throw new Error("Body is not a valid multipart object");
5658
6002
  }
5659
- } else {
5660
- throw new Error("Body is not a valid multipart object");
5661
6003
  }
5662
- parsedBody = formData;
5663
- break;
6004
+ } else {
6005
+ throw new Error("Body is not a valid multipart object");
5664
6006
  }
5665
- case "urlEncoded": {
5666
- if ((0, import_common12.isRecord)(body)) {
5667
- parsedBody = new URLSearchParams(
5668
- Object.entries(body).map(([key, value]) => [
5669
- key,
5670
- (0, import_common12.toPlainString)(value)
5671
- ])
5672
- );
5673
- } else {
5674
- throw new Error("Body is not a valid url encoded object");
5675
- }
5676
- break;
5677
- }
5678
- default: {
5679
- (0, import_common12.isNever)(discriminatedBody.parserType);
5680
- parsedBody = (0, import_common12.safeStringify)(body);
5681
- break;
6007
+ parsedBody = formData;
6008
+ break;
6009
+ }
6010
+ case "urlEncoded": {
6011
+ if ((0, import_common12.isRecord)(body)) {
6012
+ parsedBody = new URLSearchParams(
6013
+ Object.entries(body).map(([key, value]) => [
6014
+ key,
6015
+ (0, import_common12.toPlainString)(value)
6016
+ ])
6017
+ );
6018
+ } else {
6019
+ throw new Error("Body is not a valid url encoded object");
5682
6020
  }
6021
+ break;
6022
+ }
6023
+ default: {
6024
+ (0, import_common12.isNever)(discriminatedBody.parserType);
6025
+ parsedBody = (0, import_common12.safeStringify)(body);
6026
+ break;
5683
6027
  }
5684
6028
  }
5685
- if (query) {
5686
- const queryString = new URLSearchParams(
5687
- Object.entries(query).map(([key, value]) => [
5688
- key,
5689
- (0, import_common12.toPlainString)(value)
5690
- ])
5691
- ).toString();
5692
- url += queryString ? `?${queryString}` : "";
5693
- }
5694
- const response = await fetch(url, {
5695
- method: route.method.toUpperCase(),
5696
- headers: buildRouteHeaders(
5697
- headers,
5698
- discriminatedBody?.contentType != "multipart/form-data" ? contentType ?? discriminatedBody?.contentType : void 0
5699
- ),
5700
- body: parsedBody
5701
- });
5702
- if (response.status >= 300) {
5703
- throw new Error(
5704
- `Error received while proxying request to ${url}: ${await response.text()}`
5705
- );
5706
- }
5707
- if (!responsesSchemas) {
5708
- throw new Error("No responses schemas found");
5709
- }
5710
- const contractContentType = discriminateResponseBodies(
5711
- schemaValidator,
5712
- responsesSchemas
5713
- )[response.status].contentType;
5714
- switch (contentTypeMap && contentTypeMap[contractContentType] ? contentTypeMap[contractContentType] : contractContentType) {
5715
- case "application/json":
5716
- return {
5717
- content: [
5718
- {
5719
- type: "text",
5720
- text: (0, import_common12.safeStringify)(await response.json())
5721
- }
5722
- ]
5723
- };
5724
- case "text/plain":
5725
- return {
5726
- content: [
5727
- { type: "text", text: await response.text() }
5728
- ]
5729
- };
5730
- case "application/octet-stream":
5731
- return {
5732
- content: [
5733
- {
5734
- type: "resource",
5735
- resource: {
5736
- uri: response.url,
5737
- blob: Buffer.from(
5738
- await (await response.blob()).arrayBuffer()
5739
- ).toString("base64")
5740
- }
6029
+ }
6030
+ if (query) {
6031
+ const queryString = new URLSearchParams(
6032
+ Object.entries(query).map(([key, value]) => [
6033
+ key,
6034
+ (0, import_common12.toPlainString)(value)
6035
+ ])
6036
+ ).toString();
6037
+ url += queryString ? `?${queryString}` : "";
6038
+ }
6039
+ const response = await fetch(url, {
6040
+ method: route.method.toUpperCase(),
6041
+ headers: buildRouteHeaders(
6042
+ headers,
6043
+ discriminatedBody?.contentType != "multipart/form-data" ? contentType ?? discriminatedBody?.contentType : void 0,
6044
+ route.contractDetails.auth
6045
+ ),
6046
+ body: parsedBody
6047
+ });
6048
+ if (response.status >= 300) {
6049
+ throw new Error(
6050
+ `Error received while proxying request to ${url}: ${await response.text()}`
6051
+ );
6052
+ }
6053
+ if (!responsesSchemas) {
6054
+ throw new Error("No responses schemas found");
6055
+ }
6056
+ const contractContentType = discriminateResponseBodies(
6057
+ schemaValidator,
6058
+ responsesSchemas
6059
+ )[response.status].contentType;
6060
+ switch (contentTypeMap && contentTypeMap[contractContentType] ? contentTypeMap[contractContentType] : contractContentType) {
6061
+ case "application/json":
6062
+ return {
6063
+ content: [
6064
+ {
6065
+ type: "text",
6066
+ text: (0, import_common12.safeStringify)(await response.json())
6067
+ }
6068
+ ]
6069
+ };
6070
+ case "text/plain":
6071
+ return {
6072
+ content: [
6073
+ { type: "text", text: await response.text() }
6074
+ ]
6075
+ };
6076
+ case "application/octet-stream":
6077
+ return {
6078
+ content: [
6079
+ {
6080
+ type: "resource",
6081
+ resource: {
6082
+ uri: response.url,
6083
+ blob: Buffer.from(
6084
+ await (await response.blob()).arrayBuffer()
6085
+ ).toString("base64")
5741
6086
  }
5742
- ]
5743
- };
5744
- case "text/event-stream":
5745
- return {
5746
- content: [
5747
- { type: "text", text: await response.text() }
5748
- ]
5749
- };
5750
- default:
5751
- return {
5752
- content: [
5753
- { type: "text", text: await response.text() }
5754
- ]
5755
- };
5756
- }
6087
+ }
6088
+ ]
6089
+ };
6090
+ case "text/event-stream":
6091
+ return {
6092
+ content: [
6093
+ { type: "text", text: await response.text() }
6094
+ ]
6095
+ };
6096
+ default:
6097
+ return {
6098
+ content: [
6099
+ { type: "text", text: await response.text() }
6100
+ ]
6101
+ };
5757
6102
  }
5758
- });
6103
+ }
5759
6104
  });
5760
6105
  });
5761
6106
  });
5762
6107
  return mcpServer;
5763
6108
  }
6109
+ function collectMcpRoutes(application, appOptions) {
6110
+ const routes = [];
6111
+ const basePath = application.basePath === "/" ? "" : application.basePath;
6112
+ [
6113
+ { fullPath: basePath, router: application },
6114
+ ...unpackRouters(application.routers, [basePath])
6115
+ ].forEach(({ fullPath, router }) => {
6116
+ router.routes.forEach((route) => {
6117
+ if (!(route.contractDetails.options?.mcp ?? router.routerOptions?.mcp ?? appOptions !== false)) {
6118
+ return;
6119
+ }
6120
+ const globalAuth = router.routerOptions?.auth;
6121
+ routes.push({
6122
+ fullPath,
6123
+ route,
6124
+ routeAuth: routeRequiresAuth(route.contractDetails) ? {
6125
+ ...globalAuth ? globalAuth : {},
6126
+ ...route.contractDetails.auth
6127
+ } : void 0
6128
+ });
6129
+ });
6130
+ });
6131
+ return routes;
6132
+ }
6133
+ function resolveMcpAuthenticate(routes, authenticate, logger2) {
6134
+ if (authenticate) {
6135
+ return authenticate;
6136
+ }
6137
+ const routeAuths = routes.map(({ routeAuth }) => routeAuth).filter((auth) => auth != null);
6138
+ if (routeAuths.length === 0) {
6139
+ return void 0;
6140
+ }
6141
+ logger2?.info(
6142
+ `MCP: ${routeAuths.length} tool(s) call routes that require a credential, so the MCP endpoint requires one too and verifies it like those routes do. Set mcp.authenticate to replace this check.`
6143
+ );
6144
+ return createRouteMcpAuthenticate(routeAuths);
6145
+ }
5764
6146
 
5765
6147
  // src/http/middleware/response/parse.middleware.ts
5766
6148
  var import_validator3 = require("@forklaunch/validator");
@@ -6668,6 +7050,7 @@ function createLocalModelGatewayClient(options2 = {}) {
6668
7050
  INSTANCE_GATEWAY_MOUNT,
6669
7051
  InMemoryHmacNonceStore,
6670
7052
  InstanceGatewayRequestError,
7053
+ McpInsufficientScopeError,
6671
7054
  ModelGatewayRequestError,
6672
7055
  OPENAPI_DEFAULT_VERSION,
6673
7056
  OpenTelemetryCollector,
@@ -6691,15 +7074,18 @@ function createLocalModelGatewayClient(options2 = {}) {
6691
7074
  auditEnabled,
6692
7075
  auditEventType,
6693
7076
  bindRuntimeAuth,
7077
+ canonicalMcpResource,
6694
7078
  createContext,
6695
7079
  createEmailClient,
6696
7080
  createHmacToken,
6697
7081
  createInstanceGatewayTransport,
6698
7082
  createLocalModelGatewayClient,
6699
7083
  createMcpHttpHandler,
7084
+ createMcpOAuthAuthenticate,
6700
7085
  createModelGatewayClient,
6701
7086
  createPaymentsClient,
6702
7087
  createPreviewModelGatewayClient,
7088
+ createRouteMcpAuthenticate,
6703
7089
  createSmsClient,
6704
7090
  createStripeClient,
6705
7091
  createVoiceClient,
@@ -6745,6 +7131,8 @@ function createLocalModelGatewayClient(options2 = {}) {
6745
7131
  jwtAlgorithmsForSharedSecret,
6746
7132
  jwtClaimChecks,
6747
7133
  logger,
7134
+ mcpBearerChallenge,
7135
+ mcpProtectedResourceMetadata,
6748
7136
  meta,
6749
7137
  metricsDefinitions,
6750
7138
  middleware,
@@ -6758,6 +7146,7 @@ function createLocalModelGatewayClient(options2 = {}) {
6758
7146
  resetProcessHandlersForTesting,
6759
7147
  resolveHmacMaxSkewMs,
6760
7148
  resolveHmacNonceStore,
7149
+ resolveMcpOAuth,
6761
7150
  signPlatformEvent,
6762
7151
  smsSegments,
6763
7152
  stripeGatewayFetch,