@frontmcp/sdk 1.12.2 → 1.13.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/agent/agent.instance.d.ts +2 -0
  2. package/agent/agent.instance.d.ts.map +1 -1
  3. package/app/instances/app.lazy.instance.d.ts.map +1 -1
  4. package/app/lazy/lazy-app.rules.d.ts +5 -0
  5. package/app/lazy/lazy-app.rules.d.ts.map +1 -1
  6. package/auth/flows/auth.verify.flow.d.ts.map +1 -1
  7. package/auth/flows/oauth.authorize.flow.d.ts +2 -0
  8. package/auth/flows/oauth.authorize.flow.d.ts.map +1 -1
  9. package/auth/flows/oauth.callback.flow.d.ts +1 -0
  10. package/auth/flows/oauth.callback.flow.d.ts.map +1 -1
  11. package/auth/flows/oauth.provider-callback.flow.d.ts +1 -0
  12. package/auth/flows/oauth.provider-callback.flow.d.ts.map +1 -1
  13. package/auth/flows/session.verify.flow.d.ts +2 -0
  14. package/auth/flows/session.verify.flow.d.ts.map +1 -1
  15. package/auth/instances/instance.local-primary-auth.d.ts +9 -4
  16. package/auth/instances/instance.local-primary-auth.d.ts.map +1 -1
  17. package/auth/instances/instance.remote-primary-auth.d.ts +3 -0
  18. package/auth/instances/instance.remote-primary-auth.d.ts.map +1 -1
  19. package/auth/session-scope-identity.d.ts +5 -3
  20. package/auth/session-scope-identity.d.ts.map +1 -1
  21. package/auth/transparent-audience.d.ts +21 -0
  22. package/auth/transparent-audience.d.ts.map +1 -0
  23. package/browser/agent/agent.instance.mjs +9 -1
  24. package/browser/app/instances/app.lazy.instance.mjs +10 -2
  25. package/browser/app/lazy/lazy-app.rules.mjs +11 -1
  26. package/browser/auth/flows/oauth.authorize.flow.mjs +7 -1
  27. package/browser/auth/flows/oauth.callback.flow.mjs +6 -2
  28. package/browser/auth/flows/oauth.provider-callback.flow.mjs +8 -4
  29. package/browser/auth/flows/session.verify.flow.mjs +27 -18
  30. package/browser/auth/instances/instance.local-primary-auth.mjs +46 -12
  31. package/browser/auth/instances/instance.remote-primary-auth.mjs +21 -1
  32. package/browser/auth/session-scope-identity.mjs +6 -1
  33. package/browser/auth/transparent-audience.mjs +52 -0
  34. package/browser/common/interfaces/flow.interface.mjs +7 -1
  35. package/browser/common/interfaces/tool.interface.mjs +4 -0
  36. package/browser/common/metadata/app.metadata.mjs +2 -0
  37. package/browser/common/metadata/front-mcp.metadata.mjs +4 -0
  38. package/browser/common/metadata/input-policy.mjs +12 -0
  39. package/browser/common/metadata/output-policy.mjs +1 -0
  40. package/browser/common/metadata/tool.metadata.mjs +3 -1
  41. package/browser/common/tokens/app.tokens.mjs +1 -0
  42. package/browser/common/tokens/front-mcp.tokens.mjs +1 -0
  43. package/browser/common/tokens/tool.tokens.mjs +2 -1
  44. package/browser/common/types/auth/session.types.mjs +2 -1
  45. package/browser/common/utils/auth-info.utils.mjs +3 -2
  46. package/browser/context/frontmcp-context.mjs +2 -2
  47. package/browser/elicitation/questions/ask-question.mjs +1 -2
  48. package/browser/elicitation/questions/question.store.mjs +22 -8
  49. package/browser/elicitation/send-elicitation-result.tool.mjs +11 -6
  50. package/browser/flows/flow.instance.mjs +43 -5
  51. package/browser/hooks/hooks.utils.mjs +10 -4
  52. package/browser/index.cjs +6138 -5052
  53. package/browser/notification/notification.service.mjs +29 -4
  54. package/browser/notification/resource-update-access.mjs +22 -0
  55. package/browser/plugin/enforced-metadata.check.mjs +2 -1
  56. package/browser/prompt/flows/get-prompt.flow.mjs +13 -0
  57. package/browser/remote-mcp/factories/record-builders.mjs +2 -0
  58. package/browser/remote-mcp/mcp-client.service.mjs +26 -13
  59. package/browser/remote-mcp/remote-request-headers.mjs +6 -3
  60. package/browser/resource/flows/read-resource.flow.mjs +52 -32
  61. package/browser/resource/flows/subscribe-resource.flow.mjs +9 -4
  62. package/browser/scope/scope.instance.mjs +3 -1
  63. package/browser/server/security/resolve-allowed-hosts.mjs +3 -2
  64. package/browser/task/store/storage-task.store.mjs +69 -20
  65. package/browser/task/store/task-session-index.mjs +300 -0
  66. package/browser/task/store/task-store.factory.mjs +4 -1
  67. package/browser/tool/flows/call-tool.flow.mjs +103 -21
  68. package/browser/tool/flows/tools-list.flow.mjs +49 -8
  69. package/browser/tool/tool-output-policy.mjs +14 -3
  70. package/browser/tool/tool.instance.mjs +9 -2
  71. package/browser/tool/tool.utils.mjs +90 -3
  72. package/browser/tool/ui/app-only-tools.mjs +17 -0
  73. package/browser/tool/ui/ui-shared.mjs +9 -0
  74. package/browser/tool/undeclared-arguments-message.mjs +61 -0
  75. package/browser/tool/undeclared-arguments.mjs +35 -0
  76. package/browser/transport/flows/handle.mcp-20260728.flow.mjs +21 -19
  77. package/browser/transport/mcp-20260728/index.mjs +1 -1
  78. package/browser/transport/mcp-20260728/subscriptions.mjs +8 -6
  79. package/common/entries/tool.entry.d.ts +12 -1
  80. package/common/entries/tool.entry.d.ts.map +1 -1
  81. package/common/interfaces/flow.interface.d.ts +4 -1
  82. package/common/interfaces/flow.interface.d.ts.map +1 -1
  83. package/common/interfaces/tool.interface.d.ts +17 -0
  84. package/common/interfaces/tool.interface.d.ts.map +1 -1
  85. package/common/metadata/app.metadata.d.ts +35 -16
  86. package/common/metadata/app.metadata.d.ts.map +1 -1
  87. package/common/metadata/front-mcp.metadata.d.ts +198 -46
  88. package/common/metadata/front-mcp.metadata.d.ts.map +1 -1
  89. package/common/metadata/index.d.ts +1 -0
  90. package/common/metadata/index.d.ts.map +1 -1
  91. package/common/metadata/input-policy.d.ts +22 -0
  92. package/common/metadata/input-policy.d.ts.map +1 -0
  93. package/common/metadata/output-policy.d.ts +21 -3
  94. package/common/metadata/output-policy.d.ts.map +1 -1
  95. package/common/metadata/tool.metadata.d.ts +20 -1
  96. package/common/metadata/tool.metadata.d.ts.map +1 -1
  97. package/common/records/app.record.d.ts +2 -1
  98. package/common/records/app.record.d.ts.map +1 -1
  99. package/common/tokens/app.tokens.d.ts.map +1 -1
  100. package/common/tokens/front-mcp.tokens.d.ts.map +1 -1
  101. package/common/tokens/tool.tokens.d.ts +1 -0
  102. package/common/tokens/tool.tokens.d.ts.map +1 -1
  103. package/common/types/auth/session.types.d.ts +6 -0
  104. package/common/types/auth/session.types.d.ts.map +1 -1
  105. package/common/types/options/http/interfaces.d.ts +4 -1
  106. package/common/types/options/http/interfaces.d.ts.map +1 -1
  107. package/common/utils/auth-info.utils.d.ts +1 -0
  108. package/common/utils/auth-info.utils.d.ts.map +1 -1
  109. package/elicitation/elicitation.types.d.ts +2 -0
  110. package/elicitation/elicitation.types.d.ts.map +1 -1
  111. package/elicitation/questions/ask-question.d.ts.map +1 -1
  112. package/elicitation/questions/question.store.d.ts +5 -0
  113. package/elicitation/questions/question.store.d.ts.map +1 -1
  114. package/esm/index.mjs +32 -32
  115. package/flows/flow.instance.d.ts.map +1 -1
  116. package/hooks/hooks.utils.d.ts +2 -4
  117. package/hooks/hooks.utils.d.ts.map +1 -1
  118. package/index.d.ts +20 -20
  119. package/index.js +42 -42
  120. package/notification/notification.service.d.ts +7 -2
  121. package/notification/notification.service.d.ts.map +1 -1
  122. package/notification/resource-update-access.d.ts +9 -0
  123. package/notification/resource-update-access.d.ts.map +1 -0
  124. package/package.json +10 -10
  125. package/plugin/enforced-metadata.check.d.ts +3 -1
  126. package/plugin/enforced-metadata.check.d.ts.map +1 -1
  127. package/prompt/flows/get-prompt.flow.d.ts +3 -1
  128. package/prompt/flows/get-prompt.flow.d.ts.map +1 -1
  129. package/remote-mcp/factories/record-builders.d.ts.map +1 -1
  130. package/remote-mcp/mcp-client.service.d.ts.map +1 -1
  131. package/remote-mcp/mcp-client.types.d.ts.map +1 -1
  132. package/remote-mcp/remote-request-headers.d.ts +22 -8
  133. package/remote-mcp/remote-request-headers.d.ts.map +1 -1
  134. package/resource/flows/read-resource.flow.d.ts +15 -1
  135. package/resource/flows/read-resource.flow.d.ts.map +1 -1
  136. package/resource/flows/subscribe-resource.flow.d.ts.map +1 -1
  137. package/scope/flows/http.request.flow.d.ts +1 -0
  138. package/scope/flows/http.request.flow.d.ts.map +1 -1
  139. package/scope/scope.instance.d.ts.map +1 -1
  140. package/server/adapters/express.host.adapter.d.ts +3 -2
  141. package/server/adapters/express.host.adapter.d.ts.map +1 -1
  142. package/server/security/resolve-allowed-hosts.d.ts +4 -2
  143. package/server/security/resolve-allowed-hosts.d.ts.map +1 -1
  144. package/shared/shared-endpoint.d.ts +5 -1
  145. package/shared/shared-endpoint.d.ts.map +1 -1
  146. package/shared/unix-socket-fetch.d.ts +7 -0
  147. package/shared/unix-socket-fetch.d.ts.map +1 -1
  148. package/task/store/storage-task.store.d.ts +19 -2
  149. package/task/store/storage-task.store.d.ts.map +1 -1
  150. package/task/store/task-session-index.d.ts +100 -0
  151. package/task/store/task-session-index.d.ts.map +1 -0
  152. package/task/store/task-store.factory.d.ts +5 -0
  153. package/task/store/task-store.factory.d.ts.map +1 -1
  154. package/task/task.types.d.ts +6 -0
  155. package/task/task.types.d.ts.map +1 -1
  156. package/tool/flows/call-tool.flow.d.ts +13 -1
  157. package/tool/flows/call-tool.flow.d.ts.map +1 -1
  158. package/tool/flows/tools-list.flow.d.ts +8 -1
  159. package/tool/flows/tools-list.flow.d.ts.map +1 -1
  160. package/tool/tool-output-policy.d.ts +6 -1
  161. package/tool/tool-output-policy.d.ts.map +1 -1
  162. package/tool/tool.instance.d.ts +2 -0
  163. package/tool/tool.instance.d.ts.map +1 -1
  164. package/tool/tool.utils.d.ts +12 -0
  165. package/tool/tool.utils.d.ts.map +1 -1
  166. package/tool/ui/app-only-tools.d.ts +9 -0
  167. package/tool/ui/app-only-tools.d.ts.map +1 -0
  168. package/tool/ui/ui-shared.d.ts +4 -0
  169. package/tool/ui/ui-shared.d.ts.map +1 -1
  170. package/tool/undeclared-arguments-message.d.ts +13 -0
  171. package/tool/undeclared-arguments-message.d.ts.map +1 -0
  172. package/tool/undeclared-arguments.d.ts +7 -0
  173. package/tool/undeclared-arguments.d.ts.map +1 -0
  174. package/transport/flows/handle.mcp-20260728.flow.d.ts.map +1 -1
  175. package/transport/mcp-20260728/subscriptions.d.ts +5 -3
  176. package/transport/mcp-20260728/subscriptions.d.ts.map +1 -1
@@ -19,7 +19,6 @@ import {
19
19
  httpRequestInputSchema,
20
20
  isOrchestratedMode,
21
21
  isPublicMode,
22
- isPublicUrlPinned,
23
22
  isStaticMode,
24
23
  isTransparentMode,
25
24
  normalizeEntryPrefix,
@@ -34,12 +33,12 @@ import {
34
33
  buildInsufficientScopeHeader,
35
34
  buildInvalidTokenHeader,
36
35
  buildUnauthorizedHeader,
37
- deriveExpectedAudience,
38
36
  deriveTypedUser,
39
37
  encryptJson,
40
38
  extractBearerToken,
41
39
  isJwt,
42
40
  JwksService,
41
+ normalizeIssuer,
43
42
  scopesFromClaims,
44
43
  validateAudience
45
44
  } from "@frontmcp/auth";
@@ -48,6 +47,7 @@ import { getMachineId, randomUUID, sha256, sha256Hex, timingSafeEqual } from "@f
48
47
  import { detectPlatformFromUserAgent } from "../../notification/notification.service.mjs";
49
48
  import { detectSkillsOnlyMode } from "../../skill/skill-mode.utils.mjs";
50
49
  import { decryptPublicSession, parseSessionHeader } from "../session/utils/session-id.utils.mjs";
50
+ import { transparentTokenAudiences } from "../transparent-audience.mjs";
51
51
  var inputSchema = httpRequestInputSchema.extend({
52
52
  /**
53
53
  * The request is served without a session (MCP 2026-07-28): an anonymous or static-key caller is
@@ -72,7 +72,8 @@ var stateSchema = z.object({
72
72
  // Full PRM URL for header builder functions
73
73
  jwtPayload: z.object({}).passthrough().optional(),
74
74
  user: userClaimSchema.optional(),
75
- session: sessionIdSchema.optional()
75
+ session: sessionIdSchema.optional(),
76
+ principalIssuer: z.string().optional()
76
77
  });
77
78
  var UnauthorizedSchema = z.object({
78
79
  kind: z.literal("unauthorized"),
@@ -100,7 +101,6 @@ var plan = {
100
101
  };
101
102
  var name = "session:verify";
102
103
  var Stage = StageHookOf(name);
103
- var warnedUnpinnedAudience = false;
104
104
  function constantTimeEquals(a, b) {
105
105
  const encoder = new TextEncoder();
106
106
  return timingSafeEqual(sha256(encoder.encode(a)), sha256(encoder.encode(b)));
@@ -117,6 +117,7 @@ function buildStaticChallenge(options, description) {
117
117
  }
118
118
  return parts.join(", ");
119
119
  }
120
+ var DEFAULT_PUBLIC_SESSION_TTL_SECONDS = 3600;
120
121
  var SessionVerifyFlow = class extends FlowBase {
121
122
  logger = this.scopeLogger.child("SessionVerifyFlow");
122
123
  maskSub(sub) {
@@ -129,7 +130,7 @@ var SessionVerifyFlow = class extends FlowBase {
129
130
  * Encapsulates the shared logic for session creation, payload encryption, and user derivation.
130
131
  */
131
132
  createAnonymousSession(options) {
132
- const { authMode, subject, sessionIdHeader } = options;
133
+ const { authMode, subject, sessionIdHeader, sessionTtlSeconds } = options;
133
134
  this.logger.verbose("createAnonymousSession", { authMode, hasExistingSession: !!sessionIdHeader });
134
135
  if (this.rawInput.sessionless) {
135
136
  this.respond({
@@ -144,7 +145,8 @@ var SessionVerifyFlow = class extends FlowBase {
144
145
  const body = this.rawInput.request.body;
145
146
  const isInitialize = typeof body === "object" && body !== null && "method" in body && body.method === "initialize";
146
147
  const decrypted = decryptPublicSession(sessionIdHeader, authSignature);
147
- const existingPayload = decrypted && isInitialize && decrypted.nodeId !== machineId ? void 0 : decrypted;
148
+ const outlived = !!decrypted && sessionTtlSeconds !== void 0 && decrypted.iat + sessionTtlSeconds <= Date.now() / 1e3;
149
+ const existingPayload = outlived || decrypted && isInitialize && decrypted.nodeId !== machineId ? void 0 : decrypted;
148
150
  if (existingPayload) {
149
151
  const anonId = existingPayload.uuid ?? `${existingPayload.iat * 1e3}`;
150
152
  const user2 = anonymousCallerClaims(options, anonId);
@@ -286,7 +288,8 @@ var SessionVerifyFlow = class extends FlowBase {
286
288
  authMode: "public",
287
289
  issuer: "public",
288
290
  scopes: authOptions.anonymousScopes ?? ["anonymous"],
289
- sessionIdHeader: this.state.sessionIdHeader
291
+ sessionIdHeader: this.state.sessionIdHeader,
292
+ sessionTtlSeconds: authOptions.sessionTtl ?? DEFAULT_PUBLIC_SESSION_TTL_SECONDS
290
293
  });
291
294
  }
292
295
  async handleAnonymousFallback() {
@@ -362,15 +365,16 @@ var SessionVerifyFlow = class extends FlowBase {
362
365
  const result = await verify;
363
366
  if (result.ok) {
364
367
  this.state.set({ jwtPayload: result.payload });
368
+ const tokenIssuer = normalizeIssuer(result.issuer);
369
+ if (isTransparentMode(authOptions) && tokenIssuer !== normalizeIssuer(auth.issuer)) {
370
+ this.state.set("principalIssuer", tokenIssuer);
371
+ }
365
372
  if (isTransparentMode(authOptions)) {
366
- const configuredAudience = authOptions.expectedAudience;
367
- if (!configuredAudience && !isPublicUrlPinned() && !warnedUnpinnedAudience) {
368
- warnedUnpinnedAudience = true;
369
- this.logger.warn(
370
- "transparent audience validation is deriving the expected audience from the request Host: set auth.expectedAudience or FRONTMCP_PUBLIC_URL to bind tokens to a fixed resource. X-Forwarded-Host is ignored unless FRONTMCP_TRUST_PROXY is enabled."
371
- );
372
- }
373
- const expectedAudiences = configuredAudience ? Array.isArray(configuredAudience) ? configuredAudience : [configuredAudience] : deriveExpectedAudience(this.state.required.baseUrl);
373
+ const expectedAudiences = transparentTokenAudiences(
374
+ authOptions,
375
+ this.state.required.baseUrl,
376
+ this.scope
377
+ );
374
378
  const audResult = validateAudience(result.payload?.["aud"], {
375
379
  expectedAudiences,
376
380
  // By default accept tokens with no `aud` claim: many IdPs omit it, and
@@ -382,7 +386,10 @@ var SessionVerifyFlow = class extends FlowBase {
382
386
  allowNoAudience: authOptions.requireAudience !== true
383
387
  });
384
388
  if (!audResult.valid) {
385
- this.logger.warn("verifyIfJwt: audience validation failed", { error: audResult.error });
389
+ this.logger.warn(
390
+ expectedAudiences.length > 0 ? "verifyIfJwt: audience validation failed" : "verifyIfJwt: no token audience is configured, so a token with an aud claim is refused: set auth.expectedAudience (or FRONTMCP_PUBLIC_URL, or allowed hosts), or auth.audienceFromRequestHost: true while migrating",
391
+ { error: audResult.error }
392
+ );
386
393
  this.respond({
387
394
  kind: "unauthorized",
388
395
  prmMetadataHeader: buildInvalidTokenHeader(
@@ -449,7 +456,8 @@ var SessionVerifyFlow = class extends FlowBase {
449
456
  async buildAuthorizedOutput() {
450
457
  const {
451
458
  required: { token, user },
452
- session
459
+ session,
460
+ principalIssuer
453
461
  } = this.state;
454
462
  this.logger.verbose("Session verified successfully", {
455
463
  sub: this.maskSub(user.sub),
@@ -460,7 +468,8 @@ var SessionVerifyFlow = class extends FlowBase {
460
468
  authorization: {
461
469
  token,
462
470
  user,
463
- session
471
+ session,
472
+ ...principalIssuer !== void 0 && { principalIssuer }
464
473
  }
465
474
  });
466
475
  }
@@ -10,6 +10,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
10
10
 
11
11
  // libs/sdk/src/auth/instances/instance.local-primary-auth.ts
12
12
  import {
13
+ clientAuthMethodToRecord,
13
14
  createSecureStore,
14
15
  createTokenStorageAdapter,
15
16
  DcrClientRegistry,
@@ -24,6 +25,7 @@ import {
24
25
  isSqliteTokenStorage,
25
26
  JwksService,
26
27
  LocalTokenKeys,
28
+ meetsRecordedClientAuth,
27
29
  resolveUpstreamClient,
28
30
  SessionCredentialVault,
29
31
  StorageAuthorizationStore,
@@ -436,8 +438,9 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
436
438
  * adapter-backed equivalents. For `'memory'` (or unset) this is a no-op, so
437
439
  * the default behavior is preserved exactly.
438
440
  *
439
- * The orchestrated-token store keeps using the JWT secret as its encryption
440
- * key, so upstream provider tokens stay encrypted at rest in every backend.
441
+ * The orchestrated-token and federated-session stores use the JWT secret as
442
+ * their encryption key, so upstream provider tokens stay encrypted at rest in
443
+ * every backend.
441
444
  */
442
445
  async initializeStores() {
443
446
  if (!isPersistentTokenStorage(this.tokenStorage)) {
@@ -449,10 +452,11 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
449
452
  this.storageClosers.push(() => adapter.disconnect());
450
453
  this.disposeInMemoryStores();
451
454
  this.authorizationStoreImpl = new StorageAuthorizationStore(adapter);
452
- this.federatedSessionStoreImpl = new StorageFederatedAuthSessionStore(adapter);
455
+ this.federatedSessionStoreImpl = new StorageFederatedAuthSessionStore(adapter, { encryptionKey: this.secret });
453
456
  this.orchestratedTokenStoreImpl = new StorageOrchestratedTokenStore(adapter, {
454
457
  encryptionKey: this.secret,
455
- refreshSkewMs: this.providerRefreshSkewMs()
458
+ refreshSkewMs: this.providerRefreshSkewMs(),
459
+ providerIssuer: (providerId) => this.providerAuthorizationServer(providerId)
456
460
  });
457
461
  this.consentStoreImpl = new StorageConsentStore(adapter);
458
462
  const backend = isSqliteTokenStorage(this.tokenStorage) ? "sqlite" : isRedisTokenStorage(this.tokenStorage) ? "redis" : "unknown";
@@ -821,6 +825,10 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
821
825
  error_description: "Client ID does not match"
822
826
  };
823
827
  }
828
+ if (!meetsRecordedClientAuth(codeRecord.clientAuthMethod, declared.authMethod)) {
829
+ this.logger.warn("Authorization code needs client authentication this client did not provide");
830
+ return { error: "invalid_client", error_description: "Client authentication failed" };
831
+ }
824
832
  if (codeRecord.redirectUri !== redirectUri) {
825
833
  this.logger.warn(`Redirect URI mismatch`);
826
834
  return {
@@ -886,7 +894,8 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
886
894
  federatedLoginUsed: codeRecord.federatedLoginUsed,
887
895
  selectedProviderIds: codeRecord.selectedProviderIds,
888
896
  skippedProviderIds: codeRecord.skippedProviderIds,
889
- providerTokensId
897
+ providerTokensId,
898
+ clientAuthMethod: clientAuthMethodToRecord(codeRecord.clientAuthMethod, declared.authMethod)
890
899
  });
891
900
  await this.authorizationStore.storeRefreshToken(refreshTokenRecord);
892
901
  await this.authorizationStore.markCodeUsed(code, refreshTokenRecord.token);
@@ -895,11 +904,13 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
895
904
  /**
896
905
  * Refuse a grant the client did not declare in its `grant_types` (RFC 7591): in its registration, its
897
906
  * `dcr.clients` entry or its client ID metadata document. A client that declared nothing (an unregistered
898
- * id under `requireRegisteredClients: false`) is not limited, and gets `grantTypes: undefined`. A CIMD client
899
- * whose document declares `private_key_jwt` must also present a valid client assertion.
907
+ * id under `requireRegisteredClients: false`, or one registered on another instance or before a restart)
908
+ * is not limited, and gets `grantTypes: undefined` and `authMethod: undefined`. A CIMD client whose document
909
+ * declares `private_key_jwt` must also present a valid client assertion.
900
910
  */
901
911
  async checkDeclaredGrant(clientId, grantType, clientAssertion) {
902
912
  let grantTypes;
913
+ let authMethod;
903
914
  try {
904
915
  const cimd = this.cimdService;
905
916
  if (cimd?.enabled && cimd.isCimdClientId(clientId)) {
@@ -913,8 +924,11 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
913
924
  });
914
925
  }
915
926
  grantTypes = metadata?.grant_types;
927
+ authMethod = metadata?.token_endpoint_auth_method ?? "none";
916
928
  } else {
917
- grantTypes = this.dcrClientRegistryImpl.get(clientId)?.grant_types;
929
+ const registered = this.dcrClientRegistryImpl.get(clientId);
930
+ grantTypes = registered?.grant_types;
931
+ authMethod = registered?.token_endpoint_auth_method;
918
932
  }
919
933
  } catch (err) {
920
934
  this.logger.warn(`Client metadata refused at token endpoint (${grantType}): ${err.message}`);
@@ -924,7 +938,7 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
924
938
  this.logger.warn(`Client did not declare the ${grantType} grant`);
925
939
  return { error: "unauthorized_client", error_description: `This client may not use the ${grantType} grant` };
926
940
  }
927
- return { grantTypes };
941
+ return { grantTypes, authMethod };
928
942
  }
929
943
  /**
930
944
  * Move the upstream provider tokens stored under `fromAuthorizationId` to the authorization id of
@@ -996,6 +1010,10 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
996
1010
  error_description: "Client ID does not match"
997
1011
  };
998
1012
  }
1013
+ if (!meetsRecordedClientAuth(tokenRecord.clientAuthMethod, declared.authMethod)) {
1014
+ this.logger.warn("Refresh token needs client authentication this client did not provide");
1015
+ return { error: "invalid_client", error_description: "Client authentication failed" };
1016
+ }
999
1017
  const user = {
1000
1018
  sub: tokenRecord.userSub,
1001
1019
  email: tokenRecord.userEmail,
@@ -1035,7 +1053,8 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
1035
1053
  federatedLoginUsed: tokenRecord.federatedLoginUsed,
1036
1054
  selectedProviderIds: tokenRecord.selectedProviderIds,
1037
1055
  skippedProviderIds: tokenRecord.skippedProviderIds,
1038
- providerTokensId: copiedTo ?? sourceId
1056
+ providerTokensId: copiedTo ?? sourceId,
1057
+ clientAuthMethod: clientAuthMethodToRecord(tokenRecord.clientAuthMethod, declared.authMethod)
1039
1058
  });
1040
1059
  try {
1041
1060
  await this.authorizationStore.rotateRefreshToken(refreshToken, newRefreshRecord);
@@ -1086,7 +1105,8 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
1086
1105
  // Progressive/Incremental authorization: granted app-id set.
1087
1106
  authorizedAppIds: params.authorizedAppIds,
1088
1107
  // Custom claims from a local authenticate() verifier (Checkpoint 3a)
1089
- customClaims: params.customClaims
1108
+ customClaims: params.customClaims,
1109
+ clientAuthMethod: params.clientAuthMethod
1090
1110
  });
1091
1111
  await this.authorizationStore.storeAuthorizationCode(codeRecord);
1092
1112
  this.logger.info(`Authorization code created for user: ${params.userSub}`);
@@ -1158,6 +1178,14 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
1158
1178
  this.providerConfigs.set(config.id, config);
1159
1179
  this.logger.info(`Registered upstream provider: ${config.id}`);
1160
1180
  }
1181
+ /** The authorization server a provider's tokens come from: its issuer, else its token endpoint. */
1182
+ providerAuthorizationServer(providerId) {
1183
+ const config = this.providerConfigs.get(providerId);
1184
+ if (!config) {
1185
+ return void 0;
1186
+ }
1187
+ return config.issuer ? normalizeIssuer(config.issuer) : config.tokenEndpoint;
1188
+ }
1161
1189
  /**
1162
1190
  * Drop every stored credential for a provider whose authorization server changed.
1163
1191
  *
@@ -1559,6 +1587,7 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
1559
1587
  };
1560
1588
  }
1561
1589
  async renewProviderToken(providerId, refreshToken) {
1590
+ const issuer = this.providerAuthorizationServer(providerId);
1562
1591
  const result = await this.refreshProviderToken(providerId, refreshToken);
1563
1592
  if ("error" in result || typeof result.access_token !== "string" || !result.access_token) {
1564
1593
  this.logger.warn(
@@ -1568,7 +1597,12 @@ var LocalPrimaryAuth = class extends FrontMcpAuth {
1568
1597
  `Provider "${providerId}" did not refresh its token; the user has to sign in again`
1569
1598
  );
1570
1599
  }
1571
- return { accessToken: result.access_token, refreshToken: result.refresh_token, expiresIn: result.expires_in };
1600
+ return {
1601
+ accessToken: result.access_token,
1602
+ refreshToken: result.refresh_token,
1603
+ expiresIn: result.expires_in,
1604
+ issuer
1605
+ };
1572
1606
  }
1573
1607
  /** How long before its expiry a provider token is renewed: `refresh.skewSeconds` (default 60), none with `refresh` off. */
1574
1608
  providerRefreshSkewMs() {
@@ -1,10 +1,11 @@
1
1
  // libs/sdk/src/auth/instances/instance.remote-primary-auth.ts
2
2
  import { JwksService } from "@frontmcp/auth";
3
- import { FrontMcpAuth, ProviderScope } from "../../common/index.mjs";
3
+ import { FrontMcpAuth, isPublicUrlPinned, ProviderScope } from "../../common/index.mjs";
4
4
  import SessionVerifyFlow from "../flows/session.verify.flow.mjs";
5
5
  import WellKnownJwksFlow from "../flows/well-known.jwks.flow.mjs";
6
6
  import WellKnownAsFlow from "../flows/well-known.oauth-authorization-server.flow.mjs";
7
7
  import WellKnownPrmFlow from "../flows/well-known.prm.flow.mjs";
8
+ import { acceptsLoopbackAudience, checkedAllowedHosts } from "../transparent-audience.mjs";
8
9
  var RemotePrimaryAuth = class extends FrontMcpAuth {
9
10
  constructor(scope, providers, options) {
10
11
  super(options);
@@ -36,8 +37,27 @@ var RemotePrimaryAuth = class extends FrontMcpAuth {
36
37
  provide: JwksService
37
38
  });
38
39
  await this.registerAuthFlows(scope);
40
+ this.warnWithoutConfiguredAudience(scope);
39
41
  return Promise.resolve();
40
42
  }
43
+ /** Warn once at startup when nothing configures the token audience: say what this server accepts, and what to set. */
44
+ warnWithoutConfiguredAudience(scope) {
45
+ if (this.options.expectedAudience || isPublicUrlPinned() || checkedAllowedHosts(scope)?.length) {
46
+ return;
47
+ }
48
+ scope.logger.warn(
49
+ `Transparent auth has no configured token audience, so ${this.unconfiguredAudienceBehaviour()}. Set auth.expectedAudience to the audience your identity provider puts in tokens (or set FRONTMCP_PUBLIC_URL, or list the server host in security.dnsRebindingProtection.allowedHosts or FRONTMCP_ALLOWED_HOSTS).`
50
+ );
51
+ }
52
+ unconfiguredAudienceBehaviour() {
53
+ if (this.options.audienceFromRequestHost) {
54
+ return "each token is checked against the host the request names, which the client chooses (audienceFromRequestHost)";
55
+ }
56
+ if (acceptsLoopbackAudience()) {
57
+ return "tokens that carry an aud claim are accepted only for this server's loopback address (NODE_ENV is development or test)";
58
+ }
59
+ return "tokens that carry an aud claim are refused (NODE_ENV is not development or test)";
60
+ }
41
61
  async registerAuthFlows(scope) {
42
62
  await scope.registryFlows(
43
63
  WellKnownPrmFlow,
@@ -8,7 +8,12 @@ function sessionScopeIdentity(ctx) {
8
8
  const principal = [authInfo.user?.sub, extraUser?.sub, authInfo.clientId].find(
9
9
  (candidate) => !isAnonymousSubject(candidate)
10
10
  );
11
- return principal ? `principal:${principal}` : void 0;
11
+ if (!principal) return void 0;
12
+ const principalIssuer = authInfo.extra?.["principalIssuer"];
13
+ if (typeof principalIssuer === "string") {
14
+ return `issuer-principal:${encodeURIComponent(principalIssuer)}:${principal}`;
15
+ }
16
+ return `principal:${principal}`;
12
17
  }
13
18
  export {
14
19
  sessionScopeIdentity
@@ -0,0 +1,52 @@
1
+ // libs/sdk/src/auth/transparent-audience.ts
2
+ import { deriveExpectedAudience } from "@frontmcp/auth";
3
+ import { getNodeEnv } from "@frontmcp/utils";
4
+ import { defaultHttpPort, isPublicUrlPinned, normalizeEntryPrefix } from "../common/index.mjs";
5
+ import { normalizeHost } from "../server/security/host-validation.mjs";
6
+ import { allowedHostsFromEnv, LOOPBACK_NAMES } from "../server/security/resolve-allowed-hosts.mjs";
7
+ function checkedAllowedHosts(scope) {
8
+ const protection = scope.metadata.http?.security?.dnsRebindingProtection;
9
+ return protection?.enabled === false ? void 0 : protection?.allowedHosts ?? allowedHostsFromEnv();
10
+ }
11
+ function acceptsLoopbackAudience() {
12
+ let nodeEnv;
13
+ try {
14
+ nodeEnv = getNodeEnv();
15
+ } catch {
16
+ return false;
17
+ }
18
+ return nodeEnv === "development" || nodeEnv === "test";
19
+ }
20
+ function transparentTokenAudiences(options, requestBaseUrl, scope) {
21
+ const configured = options.expectedAudience;
22
+ if (configured) {
23
+ return Array.isArray(configured) ? configured : [configured];
24
+ }
25
+ if (isPublicUrlPinned() || options.audienceFromRequestHost || isAllowedHost(requestBaseUrl, scope)) {
26
+ return deriveExpectedAudience(requestBaseUrl);
27
+ }
28
+ if (!acceptsLoopbackAudience()) {
29
+ return [];
30
+ }
31
+ const port = scope.metadata.http?.port ?? defaultHttpPort();
32
+ const entryPath = normalizeEntryPrefix(scope.entryPath);
33
+ return LOOPBACK_NAMES.flatMap((host) => deriveExpectedAudience(`http://${host}:${port}${entryPath}`));
34
+ }
35
+ function isAllowedHost(requestBaseUrl, scope) {
36
+ const allowedHosts = checkedAllowedHosts(scope);
37
+ if (!allowedHosts?.length) {
38
+ return false;
39
+ }
40
+ let requestHost;
41
+ try {
42
+ requestHost = normalizeHost(new URL(requestBaseUrl).host);
43
+ } catch {
44
+ return false;
45
+ }
46
+ return allowedHosts.some((allowedHost) => normalizeHost(allowedHost) === requestHost);
47
+ }
48
+ export {
49
+ acceptsLoopbackAudience,
50
+ checkedAllowedHosts,
51
+ transparentTokenAudiences
52
+ };
@@ -50,12 +50,13 @@ var FlowControl = class _FlowControl extends Error {
50
50
  };
51
51
  brandClass(FlowControl, "@frontmcp/sdk:FlowControl");
52
52
  var FlowBase = class {
53
- constructor(metadata, rawInput, scope, appendContextHooks, deps = /* @__PURE__ */ new Map()) {
53
+ constructor(metadata, rawInput, scope, appendContextHooks, deps = /* @__PURE__ */ new Map(), retargetEntryHooks) {
54
54
  this.metadata = metadata;
55
55
  this.rawInput = rawInput;
56
56
  this.scope = scope;
57
57
  this.appendContextHooks = appendContextHooks;
58
58
  this.deps = deps;
59
+ this.retargetEntryHooks = retargetEntryHooks;
59
60
  this.input = metadata.inputSchema?.parse?.(rawInput);
60
61
  this.scopeLogger = scope.logger;
61
62
  }
@@ -64,6 +65,7 @@ var FlowBase = class {
64
65
  scope;
65
66
  appendContextHooks;
66
67
  deps;
68
+ retargetEntryHooks;
67
69
  /**
68
70
  * The id of the app that owns the entry a run targets, read from the raw input before hooks load.
69
71
  * Entries an app's adapters and plugins provide belong to that app. App-scoped hooks run only when it matches their app.
@@ -118,6 +120,10 @@ var FlowBase = class {
118
120
  set error(value) {
119
121
  shadowWithOwnValue(this, "error", value);
120
122
  }
123
+ /** Hand the stages still to come to the app and `static` hooks of the entry a hook switched to, in place of the first's. */
124
+ async useEntryHooks(ownerId, entryClass) {
125
+ await this.retargetEntryHooks?.(ownerId, entryClass);
126
+ }
121
127
  respond(output) {
122
128
  throw FlowControl.respond(this.metadata.outputSchema.parse(output));
123
129
  }
@@ -212,6 +212,10 @@ var ToolContext = class extends ExecutionContextBase {
212
212
  notifyResourceListChanged() {
213
213
  this.scope.notifications.broadcastNotification("notifications/resources/list_changed");
214
214
  }
215
+ /** Adds `count` records this call changed for the in-process dispatcher that counts them (CodeCall's budgets). */
216
+ reportRecordsChanged(count) {
217
+ this._onRecordsChangedInternal?.(count);
218
+ }
215
219
  // ============================================
216
220
  // Elicitation API
217
221
  // ============================================
@@ -19,6 +19,7 @@ import {
19
19
  } from "../schemas/index.mjs";
20
20
  import { appFilterConfigSchema } from "./app-filter.metadata.mjs";
21
21
  import { enabledOptionSchema } from "./enabled.metadata.mjs";
22
+ import { inputPolicySchema } from "./input-policy.mjs";
22
23
  import { outputPolicySchema } from "./output-policy.mjs";
23
24
  import { widgetServingModeSchema } from "./ui-serving-mode.mjs";
24
25
  var frontMcpLocalAppMetadataSchema = z.looseObject({
@@ -45,6 +46,7 @@ var frontMcpLocalAppMetadataSchema = z.looseObject({
45
46
  ).optional(),
46
47
  auth: authOptionsSchema.optional(),
47
48
  output: outputPolicySchema.optional(),
49
+ input: inputPolicySchema.optional(),
48
50
  ui: z.object({ servingMode: widgetServingModeSchema.optional() }).optional(),
49
51
  standalone: z.union([z.literal("includeInParent"), z.boolean()]).optional().default(false)
50
52
  });
@@ -40,6 +40,7 @@ import { legacySessionOptionsSchema } from "../types/options/session/schema.mjs"
40
40
  import { packageLoaderSchema } from "./app.metadata.mjs";
41
41
  import { channelsConfigSchema } from "./channel.metadata.mjs";
42
42
  import { eventsConfigSchema } from "./event.metadata.mjs";
43
+ import { inputPolicySchema } from "./input-policy.mjs";
43
44
  import { MAX_JOB_TIMER_MS, timerLimitMessage } from "./job.metadata.mjs";
44
45
  import { outputPolicySchema } from "./output-policy.mjs";
45
46
  import { widgetServingModeSchema } from "./ui-serving-mode.mjs";
@@ -98,6 +99,7 @@ var frontMcpBaseSchema = z.object({
98
99
  * numeric output throws `InvalidOutputError`.
99
100
  */
100
101
  output: outputPolicySchema.optional(),
102
+ input: inputPolicySchema.optional(),
101
103
  clients: clientProfilesOptionsSchema.optional(),
102
104
  jobs: z.object({
103
105
  enabled: z.boolean(),
@@ -156,6 +158,7 @@ var frontMcpBaseSchema = z.object({
156
158
  maxTtlMs: z.number().int().positive().optional(),
157
159
  defaultPollIntervalMs: z.number().int().positive().optional(),
158
160
  maxConcurrentPerSession: z.number().int().positive().max(MAX_CONCURRENT_TASKS_PER_SESSION).optional(),
161
+ listFrom: z.enum(["scan", "index"]).optional(),
159
162
  strict: z.boolean().optional(),
160
163
  runner: z.enum(["in-process", "cli"]).optional(),
161
164
  sqlite: z.object({
@@ -284,6 +287,7 @@ var frontMcpLiteSchema = z.object({
284
287
  // Output-validation policy (see `frontMcpBaseSchema.output`). CLI mode
285
288
  // honors the same `allowNonFinite` switch as the full server.
286
289
  output: outputPolicySchema.optional(),
290
+ input: inputPolicySchema.optional(),
287
291
  session: checkedAsServer("session"),
288
292
  clients: checkedAsServer("clients"),
289
293
  observability: checkedAsServer("observability"),
@@ -0,0 +1,12 @@
1
+ // libs/sdk/src/common/metadata/input-policy.ts
2
+ import { internalZ as z } from "@frontmcp/lazy-zod";
3
+ var inputPolicySchema = z.object({
4
+ undeclaredKeys: z.enum(["strip", "warn", "fail"]).optional()
5
+ });
6
+ function resolveInputUndeclaredKeysPolicy(tool, app, server) {
7
+ return tool?.undeclaredKeys ?? app?.undeclaredKeys ?? server?.undeclaredKeys ?? "warn";
8
+ }
9
+ export {
10
+ inputPolicySchema,
11
+ resolveInputUndeclaredKeysPolicy
12
+ };
@@ -13,6 +13,7 @@ var outputPolicySchema = z.object({
13
13
  schemaMode: z.enum(OUTPUT_SCHEMA_MODES).optional(),
14
14
  schemaDescriptionFormat: z.enum(SCHEMA_DESCRIPTION_FORMATS).optional(),
15
15
  undeclaredKeys: z.enum(UNDECLARED_KEYS_POLICIES).optional(),
16
+ validateStructuredContent: z.enum(["warn", "enforce"]).optional(),
16
17
  budget: z.union([
17
18
  z.literal(false),
18
19
  z.object({
@@ -14,6 +14,7 @@ import {
14
14
  } from "@frontmcp/protocol";
15
15
  import { entryAvailabilitySchema } from "@frontmcp/utils";
16
16
  import { enabledOptionSchema } from "./enabled.metadata.mjs";
17
+ import { inputPolicySchema } from "./input-policy.mjs";
17
18
  import { outputPolicySchema } from "./output-policy.mjs";
18
19
  var toolAuthProviderMappingSchema = z.union([
19
20
  z.string().min(1),
@@ -100,7 +101,8 @@ var frontMcpToolMetadataSchema = z.object({
100
101
  execution: z.object({
101
102
  taskSupport: z.enum(["required", "optional", "forbidden"]).optional()
102
103
  }).optional(),
103
- output: outputPolicySchema.optional()
104
+ output: outputPolicySchema.optional(),
105
+ input: inputPolicySchema.optional()
104
106
  }).passthrough();
105
107
  export {
106
108
  AudioOutputSchema,
@@ -21,6 +21,7 @@ var FrontMcpLocalAppTokens = {
21
21
  events: tokenFactory.meta("events"),
22
22
  routes: tokenFactory.meta("routes"),
23
23
  output: tokenFactory.meta("output"),
24
+ input: tokenFactory.meta("input"),
24
25
  // tool UI defaults (`ui.servingMode`) for the app's tools (#720)
25
26
  ui: tokenFactory.meta("ui"),
26
27
  standalone: tokenFactory.meta("standalone"),
@@ -75,6 +75,7 @@ var FrontMcpTokens = {
75
75
  tasks: tokenFactory.meta("tasks"),
76
76
  // output validation policy (e.g., reject non-finite numeric output)
77
77
  output: tokenFactory.meta("output"),
78
+ input: tokenFactory.meta("input"),
78
79
  // per-client answer shaping, keyed by a clientInfo.name glob
79
80
  clients: tokenFactory.meta("clients")
80
81
  };
@@ -33,8 +33,9 @@ var FrontMcpToolTokens = {
33
33
  enabled: tokenFactory.meta("enabled"),
34
34
  execution: tokenFactory.meta("execution"),
35
35
  // Execution hints (taskSupport, etc.)
36
- output: tokenFactory.meta("output")
36
+ output: tokenFactory.meta("output"),
37
37
  // Output policy (allowNonFinite, schemaMode, ...)
38
+ input: tokenFactory.meta("input")
38
39
  };
39
40
  var extendedToolMetadata = tokenFactory.meta("extendedToolMetadata");
40
41
  export {
@@ -13,7 +13,8 @@ var sessionIdSchema = z.object({
13
13
  var authorizationSchema = z.object({
14
14
  token: z.string(),
15
15
  session: sessionIdSchema.optional(),
16
- user: userClaimSchema
16
+ user: userClaimSchema,
17
+ principalIssuer: z.string().optional()
17
18
  });
18
19
  export {
19
20
  aiPlatformTypeSchema,
@@ -7,7 +7,7 @@ function sessionIdPresentedBy(request) {
7
7
  return typeof query === "string" && query.length > 0 ? query : void 0;
8
8
  }
9
9
  function authInfoFromAuthorization(authorization, presentedSessionId) {
10
- const { token, user, session } = authorization;
10
+ const { token, user, session, principalIssuer } = authorization;
11
11
  const verifiedSession = session !== void 0 && presentedSessionId !== void 0 && session.id === presentedSessionId ? session : void 0;
12
12
  return {
13
13
  token,
@@ -18,7 +18,8 @@ function authInfoFromAuthorization(authorization, presentedSessionId) {
18
18
  extra: {
19
19
  user,
20
20
  sessionId: verifiedSession?.id,
21
- sessionPayload: verifiedSession?.payload
21
+ sessionPayload: verifiedSession?.payload,
22
+ principalIssuer
22
23
  }
23
24
  };
24
25
  }
@@ -176,8 +176,8 @@ var FrontMcpContext = class {
176
176
  return this._platformType;
177
177
  }
178
178
  /**
179
- * Record the client info a request carries, and the platform detected from it.
180
- * An `'unknown'` platform is not recorded, so lookups fall back to the session's platform.
179
+ * Record the client info a request carries, if any, and the platform detected from it or from the capabilities the
180
+ * request declares. An `'unknown'` platform is not recorded, so lookups fall back to the session's platform.
181
181
  *
182
182
  * @internal
183
183
  */
@@ -5,7 +5,6 @@ import { ElicitationNotSupportedError, InvalidInputError } from "../../errors/in
5
5
  import { DEFAULT_ELICIT_TTL } from "../elicitation.types.mjs";
6
6
  import { questionSubjectOf } from "./question-subject.mjs";
7
7
  import { QuestionPendingError, QuestionSupersededError } from "./question.errors.mjs";
8
- import { QUESTIONS_TOPIC } from "./question.store.mjs";
9
8
  var RECHECK_MS = 5e3;
10
9
  var MAX_QUESTION_KEY_LENGTH = 256;
11
10
  async function delivered(answer, schema) {
@@ -86,7 +85,7 @@ async function askPersistentQuestion(deps, message, schema, options) {
86
85
  const onAbort = () => pending();
87
86
  const timer = setTimeout(giveUp, options.waitMs);
88
87
  const poll = setInterval(check, RECHECK_MS);
89
- const stop = store.subscribe(QUESTIONS_TOPIC, check);
88
+ const stop = store.subscribeToQuestion(subject, options.key, check);
90
89
  if (signal?.aborted) return onAbort();
91
90
  signal?.addEventListener("abort", onAbort, { once: true });
92
91
  check();