@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
@@ -119,6 +119,10 @@ function sessionCallerOf(authInfo) {
119
119
  const { clientId, scopes, user, claims } = authInfo;
120
120
  return { clientId, scopes, user, claims, expiresAt: authInfo.expiresAt ?? user?.exp };
121
121
  }
122
+ var MAX_CALLER_RECHECKS = 3;
123
+ function isSameCaller(left, right) {
124
+ return left === right || JSON.stringify(left) === JSON.stringify(right);
125
+ }
122
126
  function hasExpiredCaller(session) {
123
127
  const expiresAt = session.caller?.expiresAt;
124
128
  return expiresAt !== void 0 && expiresAt * 1e3 < Date.now();
@@ -361,13 +365,16 @@ var NotificationService = class _NotificationService {
361
365
  *
362
366
  * @param sessionId - The session to subscribe
363
367
  * @param uri - The resource URI to subscribe to
368
+ * @param platformEnv - The subscribing request's platform bindings, which each update's access check runs with
364
369
  * @returns true if this is a new subscription, false if already subscribed
365
370
  */
366
- subscribeResource(sessionId, uri) {
367
- if (!this.servers.has(sessionId)) {
371
+ subscribeResource(sessionId, uri, platformEnv) {
372
+ const registered = this.servers.get(sessionId);
373
+ if (!registered) {
368
374
  this.logger.warn(`Cannot subscribe unregistered session ${sessionId.slice(0, 20)}... to resource ${uri}`);
369
375
  return false;
370
376
  }
377
+ if (platformEnv !== void 0) registered.platformEnv = platformEnv;
371
378
  let sessionSubs = this.subscriptions.get(sessionId);
372
379
  if (!sessionSubs) {
373
380
  sessionSubs = /* @__PURE__ */ new Set();
@@ -429,7 +436,7 @@ var NotificationService = class _NotificationService {
429
436
  /**
430
437
  * Send a resource update notification to subscribed sessions only.
431
438
  * Per MCP 2025-11-25 spec, only sessions that have subscribed to this
432
- * resource via `resources/subscribe` will receive the notification.
439
+ * resource via `resources/subscribe` will receive the notification, and only while their caller may still read it.
433
440
  *
434
441
  * @param uri - The resource URI that was updated
435
442
  */
@@ -441,7 +448,24 @@ var NotificationService = class _NotificationService {
441
448
  }
442
449
  this.logger.verbose(`Notifying ${subscribers.length} subscriber(s) of resource update: ${uri}`);
443
450
  for (const sessionId of subscribers) {
444
- this.sendNotificationToSession(sessionId, "notifications/resources/updated", { uri });
451
+ void this.notifyIfStillReadable(sessionId, uri);
452
+ }
453
+ }
454
+ /** Tell a subscribed session of an update when `resources:subscribe` still admits its latest, unexpired caller. */
455
+ async notifyIfStillReadable(sessionId, uri) {
456
+ const registered = this.servers.get(sessionId);
457
+ if (!registered || hasExpiredCaller(registered)) return;
458
+ const { callerMayStillRead } = await import("./resource-update-access.mjs");
459
+ let checkedCaller = registered.caller;
460
+ for (let attempt = 0; attempt < MAX_CALLER_RECHECKS; attempt++) {
461
+ const mayRead = await callerMayStillRead(this.scope, registered, checkedCaller, uri);
462
+ const current = this.servers.get(sessionId);
463
+ if (current !== registered || !this.isSubscribed(sessionId, uri) || hasExpiredCaller(current)) return;
464
+ if (isSameCaller(current.caller, checkedCaller)) {
465
+ if (mayRead) this.sendNotificationToSession(sessionId, "notifications/resources/updated", { uri });
466
+ return;
467
+ }
468
+ checkedCaller = current.caller;
445
469
  }
446
470
  }
447
471
  // =====================================================
@@ -672,6 +696,7 @@ var NotificationService = class _NotificationService {
672
696
  return false;
673
697
  }
674
698
  registered.clientCapabilities = capabilities;
699
+ if (!registered.clientInfo) registered.platformType = detectPlatformFromCapabilities(capabilities);
675
700
  this.logger.verbose(
676
701
  `Set client capabilities for session ${sessionId.slice(0, 20)}...: roots.listChanged=${capabilities.roots?.listChanged ?? false}`
677
702
  );
@@ -0,0 +1,22 @@
1
+ // libs/sdk/src/notification/resource-update-access.ts
2
+ import { runRequestExclusive } from "@frontmcp/utils";
3
+ import { mcpRequestSurface } from "../transport/mcp-handlers/mcp-surface.mjs";
4
+ async function callerMayStillRead(scope, session, caller, uri) {
5
+ const request = { method: "resources/subscribe", params: { uri } };
6
+ const authInfo = { ...caller, sessionId: session.sessionId };
7
+ const { platformEnv } = session;
8
+ const ctx = {
9
+ authInfo,
10
+ surface: mcpRequestSurface(scope),
11
+ ownRequest: true,
12
+ checkOnly: true,
13
+ ...platformEnv !== void 0 ? { platformEnv } : {}
14
+ };
15
+ return runRequestExclusive(() => scope.runFlow("resources:subscribe", { request, ctx })).then(
16
+ () => true,
17
+ () => false
18
+ );
19
+ }
20
+ export {
21
+ callerMayStillRead
22
+ };
@@ -103,5 +103,6 @@ function findUnenforcedInScope(scope, agentPath, toolsUseFlow) {
103
103
  }
104
104
  export {
105
105
  agentToolMetadata,
106
- findUnenforcedMetadata
106
+ findUnenforcedMetadata,
107
+ keysEnforcedBy
107
108
  };
@@ -74,6 +74,8 @@ var plan = {
74
74
  "parseInput",
75
75
  "ensureRemoteCapabilities",
76
76
  "findPrompt",
77
+ // A hook that switched the prompt hands the run over to the hooks of the prompt that runs
78
+ "usePromptHooks",
77
79
  "checkEnabled",
78
80
  "checkAppLoaded",
79
81
  "checkPublicAccess",
@@ -198,6 +200,14 @@ var GetPromptFlow = class extends FlowBase {
198
200
  this.logger.verbose(`findPrompt: prompt "${prompt.name}" found`);
199
201
  this.logger.verbose("findPrompt:done");
200
202
  }
203
+ async usePromptHooks() {
204
+ const { prompt } = this.state;
205
+ if (!prompt) return;
206
+ await this.useEntryHooks(
207
+ appOwnerIdOf(this.scope.prompts.lineageOf(prompt) ?? [], prompt.owner),
208
+ prompt.record.provide
209
+ );
210
+ }
201
211
  async checkEnabled() {
202
212
  const { prompt } = this.state.required;
203
213
  await assertEntryEnabled("Prompt", prompt.name, prompt.metadata.enabled, this.tryGetContext(), this.logger);
@@ -357,6 +367,9 @@ __decorateClass([
357
367
  __decorateClass([
358
368
  Stage("findPrompt")
359
369
  ], GetPromptFlow.prototype, "findPrompt", 1);
370
+ __decorateClass([
371
+ Stage("usePromptHooks")
372
+ ], GetPromptFlow.prototype, "usePromptHooks", 1);
360
373
  __decorateClass([
361
374
  Stage("checkEnabled")
362
375
  ], GetPromptFlow.prototype, "checkEnabled", 1);
@@ -17,6 +17,8 @@ function buildRemoteToolRecord(remoteTool, mcpClient, remoteAppId, namespace) {
17
17
  name: toolName,
18
18
  id: toolName,
19
19
  ...remoteTool.title !== void 0 && { title: remoteTool.title },
20
+ // The remote tool's own `_meta`, such as an MCP Apps `ui.visibility` that keeps it from the model
21
+ ...remoteTool._meta !== void 0 && { _meta: remoteTool._meta },
20
22
  description: remoteTool.description || `Remote tool: ${remoteTool.name}`,
21
23
  inputSchema: {},
22
24
  rawInputSchema: remoteTool.inputSchema,
@@ -23,7 +23,11 @@ import {
23
23
  } from "../errors/transport.errors.mjs";
24
24
  import { McpStatelessClientAdapter, negotiateRemoteProtocol } from "./mcp-stateless-client.adapter.mjs";
25
25
  import { RemoteOAuthTokenSource } from "./remote-oauth.mjs";
26
- import { createRemoteRequestFetch, withRemoteRequestHeaders } from "./remote-request-headers.mjs";
26
+ import {
27
+ createRemoteRequestFetch,
28
+ createRemoteRequestScopes,
29
+ withRemoteRequestHeaders
30
+ } from "./remote-request-headers.mjs";
27
31
  import {
28
32
  CircuitBreakerManager,
29
33
  CircuitOpenError,
@@ -123,7 +127,8 @@ var McpClientService = class {
123
127
  this.updateConnectionStatus(appId, "connecting");
124
128
  try {
125
129
  const headers = await this.connectionHeaders(request);
126
- const connection2026 = await this.tryConnect2026(request, headers);
130
+ const requestScopes = createRemoteRequestScopes();
131
+ const connection2026 = await this.tryConnect2026(request, headers, requestScopes);
127
132
  if (connection2026) {
128
133
  this.connections.set(appId, connection2026);
129
134
  await this.discoverCapabilities(appId);
@@ -136,7 +141,7 @@ var McpClientService = class {
136
141
  return connection2026;
137
142
  }
138
143
  const protocolClient = await loadProtocolClient();
139
- let transport = this.createTransport(protocolClient, request, headers);
144
+ let transport = this.createTransport(protocolClient, request, headers, requestScopes);
140
145
  const client = new protocolClient.Client(
141
146
  {
142
147
  name: this.options.clientName,
@@ -155,7 +160,7 @@ var McpClientService = class {
155
160
  this.logger.debug(
156
161
  `Streamable HTTP connection failed for ${appId}: ${connectError.message}. Falling back to SSE transport.`
157
162
  );
158
- transport = this.createFallbackSSETransport(protocolClient, request, headers);
163
+ transport = this.createFallbackSSETransport(protocolClient, request, headers, requestScopes);
159
164
  await this.connectWithin(appId, client, transport);
160
165
  } else {
161
166
  throw connectError;
@@ -164,6 +169,7 @@ var McpClientService = class {
164
169
  const connection = {
165
170
  client,
166
171
  transport,
172
+ requestScopes,
167
173
  status: "connected",
168
174
  connectedAt: /* @__PURE__ */ new Date(),
169
175
  lastHeartbeat: /* @__PURE__ */ new Date(),
@@ -362,6 +368,7 @@ var McpClientService = class {
362
368
  appId,
363
369
  toolName,
364
370
  () => withRemoteRequestHeaders(
371
+ connection.requestScopes,
365
372
  callerHeaders,
366
373
  () => connection.client.callTool({ name: toolName, arguments: args })
367
374
  )
@@ -418,7 +425,11 @@ var McpClientService = class {
418
425
  const result = await this.withinTimeout(
419
426
  appId,
420
427
  uri,
421
- () => withRemoteRequestHeaders(callerHeaders, () => connection.client.readResource({ uri }))
428
+ () => withRemoteRequestHeaders(
429
+ connection.requestScopes,
430
+ callerHeaders,
431
+ () => connection.client.readResource({ uri })
432
+ )
422
433
  );
423
434
  connection.lastHeartbeat = /* @__PURE__ */ new Date();
424
435
  const durationMs = Date.now() - startTime;
@@ -451,6 +462,7 @@ var McpClientService = class {
451
462
  appId,
452
463
  promptName,
453
464
  () => withRemoteRequestHeaders(
465
+ connection.requestScopes,
454
466
  callerHeaders,
455
467
  () => connection.client.getPrompt({ name: promptName, arguments: args })
456
468
  )
@@ -595,8 +607,8 @@ var McpClientService = class {
595
607
  );
596
608
  }
597
609
  /** The `fetch` a transport to the remote sends through, with the connection's OAuth token when it has one. */
598
- remoteFetchOf(request, headers) {
599
- return createRemoteRequestFetch(headers !== void 0, this.oauthSources.get(request.appId));
610
+ remoteFetchOf(request, headers, requestScopes) {
611
+ return createRemoteRequestFetch(requestScopes, headers !== void 0, this.oauthSources.get(request.appId));
600
612
  }
601
613
  /** Milliseconds one request to `appId` may take: its `transportOptions.timeout`, else 30 seconds. */
602
614
  timeoutOf(appId) {
@@ -639,7 +651,7 @@ var McpClientService = class {
639
651
  * Returns `undefined` for every other case so the legacy path below runs
640
652
  * completely untouched \u2014 the default for an unconfigured remote.
641
653
  */
642
- async tryConnect2026(request, headers) {
654
+ async tryConnect2026(request, headers, requestScopes) {
643
655
  const httpOptions = request.transportOptions;
644
656
  if (request.transportType !== "http") {
645
657
  if (httpOptions?.protocolVersion === "2026-07-28") {
@@ -650,7 +662,7 @@ var McpClientService = class {
650
662
  }
651
663
  return void 0;
652
664
  }
653
- const remoteFetch = this.remoteFetchOf(request, headers);
665
+ const remoteFetch = this.remoteFetchOf(request, headers, requestScopes);
654
666
  const requestTimeoutMs = this.timeoutOf(request.appId);
655
667
  const negotiated = await negotiateRemoteProtocol(request.url, httpOptions?.protocolVersion, headers, remoteFetch, {
656
668
  requestTimeoutMs
@@ -671,17 +683,18 @@ var McpClientService = class {
671
683
  // that every consumer would then have to narrow.
672
684
  client: adapter,
673
685
  // No `transport`: this revision is stateless, so there is nothing to keep.
686
+ requestScopes,
674
687
  status: "connected",
675
688
  connectedAt: /* @__PURE__ */ new Date(),
676
689
  lastHeartbeat: /* @__PURE__ */ new Date(),
677
690
  capabilities: adapter.getServerCapabilities()
678
691
  };
679
692
  }
680
- createTransport(protocolClient, request, headers) {
693
+ createTransport(protocolClient, request, headers, requestScopes) {
681
694
  const { transportType, url } = request;
682
695
  const options = {
683
696
  requestInit: headers ? { headers } : void 0,
684
- fetch: this.remoteFetchOf(request, headers)
697
+ fetch: this.remoteFetchOf(request, headers, requestScopes)
685
698
  };
686
699
  switch (transportType) {
687
700
  case "http":
@@ -699,10 +712,10 @@ var McpClientService = class {
699
712
  /**
700
713
  * Create fallback SSE transport when Streamable HTTP fails
701
714
  */
702
- createFallbackSSETransport({ SSEClientTransport }, request, headers) {
715
+ createFallbackSSETransport({ SSEClientTransport }, request, headers, requestScopes) {
703
716
  return new SSEClientTransport(new URL(request.url), {
704
717
  requestInit: headers ? { headers } : void 0,
705
- fetch: this.remoteFetchOf(request, headers)
718
+ fetch: this.remoteFetchOf(request, headers, requestScopes)
706
719
  });
707
720
  }
708
721
  /**
@@ -2,8 +2,10 @@
2
2
  import { AsyncLocalStorage } from "@frontmcp/utils";
3
3
  import { retryAfterMsOf } from "../transport/mcp-20260728/client/mcp-stateless.client.mjs";
4
4
  import { remoteHttpFailureOf } from "./resilience/retry.mjs";
5
- var requestScopes = new AsyncLocalStorage();
6
- async function withRemoteRequestHeaders(headers, operation) {
5
+ function createRemoteRequestScopes() {
6
+ return new AsyncLocalStorage();
7
+ }
8
+ async function withRemoteRequestHeaders(requestScopes, headers, operation) {
7
9
  const scope = { headers };
8
10
  try {
9
11
  return await requestScopes.run(scope, operation);
@@ -18,7 +20,7 @@ function withRefusal(error, refusal) {
18
20
  }
19
21
  return Object.assign(error, { http: refusal });
20
22
  }
21
- function createRemoteRequestFetch(connectionCarriesHeaders, oauth) {
23
+ function createRemoteRequestFetch(requestScopes, connectionCarriesHeaders, oauth) {
22
24
  return async (input, init) => {
23
25
  const scope = requestScopes.getStore();
24
26
  const extra = scope?.headers ?? {};
@@ -47,5 +49,6 @@ function withHeaders(init, extra) {
47
49
  }
48
50
  export {
49
51
  createRemoteRequestFetch,
52
+ createRemoteRequestScopes,
50
53
  withRemoteRequestHeaders
51
54
  };
@@ -82,6 +82,8 @@ var plan = {
82
82
  "parseInput",
83
83
  "ensureRemoteCapabilities",
84
84
  "findResource",
85
+ // A hook that switched the resource, or handed one over, hands the run over to the hooks of the resource that runs
86
+ "useResourceHooks",
85
87
  "checkEnabled",
86
88
  "checkAppLoaded",
87
89
  "checkEntryAuthorities",
@@ -183,36 +185,31 @@ var ReadResourceFlow = class extends FlowBase {
183
185
  const { uri } = this.state.required.input;
184
186
  const loggedUri = escapeControlCharacters(uri);
185
187
  this.logger.verbose(`findResource: looking for resource with URI "${loggedUri}"`);
186
- if (isUIResourceUri(uri)) {
187
- this.logger.verbose(`findResource: detected UI resource URI "${loggedUri}"`);
188
- const { sessionId, authInfo } = this.state;
189
- const platformType = authInfo?.sessionIdPayload?.platformType ?? this.tryGetContext()?.platformType ?? (sessionId ? this.scope.notifications.getPlatformType(sessionId) : void 0);
190
- this.logger.verbose(`findResource: platform type for session: ${platformType ?? "unknown"}`);
191
- if (!this.scope.toolUI) {
192
- this.logger.verbose("findResource: toolUI not available, skipping UI resource handling");
193
- throw new ResourceNotFoundError(uri);
194
- }
195
- const { handleUIResourceRead } = await import("../../tool/ui/ui-resource.handler.mjs");
196
- const serverUrl = this.tryGetContext()?.metadata.serverUrl ?? getPinnedPublicUrl();
197
- const uiResult = handleUIResourceRead(uri, this.scope.toolUI, platformType, serverUrl);
198
- if (uiResult.handled) {
199
- if (uiResult.error) {
200
- this.logger.warn(`findResource: UI resource error - ${escapeControlCharacters(uiResult.error)}`);
201
- throw new ResourceNotFoundError(uri);
202
- }
203
- this.state.set("isUIResource", true);
204
- this.state.set("uiResourceResult", uiResult.result);
205
- this.logger.verbose(`findResource: UI resource "${loggedUri}" resolved from cache`);
206
- this.logger.verbose("findResource:done");
207
- return;
208
- }
188
+ if (isUIResourceUri(uri) && await this.resolveToolWidget(uri)) {
189
+ this.logger.verbose(`findResource: UI resource "${loggedUri}" resolved from cache`);
190
+ this.logger.verbose("findResource:done");
191
+ return;
209
192
  }
210
193
  const match = resolvedResources.take(this.rawInput, uri) ?? this.scope.resources.findResourceForUri(uri);
211
194
  if (!match) {
212
195
  this.logger.warn(`findResource: resource for URI "${loggedUri}" not found`);
213
196
  throw new ResourceNotFoundError(uri);
214
197
  }
215
- const { availableWhen } = match.instance.metadata;
198
+ this.settleResource(match.instance, match.params);
199
+ this.logger.verbose("findResource:done");
200
+ }
201
+ /**
202
+ * Hand over the resource a hook standing in for `findResource` found, settled as that stage settles one; its app and
203
+ * `static` hooks run from `useResourceHooks` on.
204
+ */
205
+ resolveResource({ resource, params = {} }) {
206
+ this.settleResource(resource, params);
207
+ }
208
+ /** Settle the resource this read gets, as `findResource` does: its `availableWhen` checked, the hook owner set. */
209
+ settleResource(resource, params = {}) {
210
+ const { uri } = this;
211
+ const loggedUri = escapeControlCharacters(uri);
212
+ const { availableWhen } = resource.metadata;
216
213
  const callSurface = callSurfaceOf(this.input.ctx);
217
214
  const availability = availabilityForCall(availableWhen, callSurface);
218
215
  if (availability === "not-offered") {
@@ -222,22 +219,42 @@ var ReadResourceFlow = class extends FlowBase {
222
219
  if (availability === "unavailable") {
223
220
  this.logger.warn(`findResource: resource for URI "${loggedUri}" is unavailable in this environment`);
224
221
  throw entryUnavailableError(
225
- match.instance.isTemplate ? "ResourceTemplate" : "Resource",
222
+ resource.isTemplate ? "ResourceTemplate" : "Resource",
226
223
  uri,
227
224
  availableWhen,
228
225
  callSurface
229
226
  );
230
227
  }
231
- if (match.instance.owner) {
232
- this.state.set("resourceOwnerId", match.instance.owner.id);
228
+ if (resource.owner) {
229
+ this.state.set("resourceOwnerId", resource.owner.id);
233
230
  }
234
231
  this.logger = this.logger.child(`ReadResourceFlow(${loggedUri})`);
235
- this.state.set("resource", match.instance);
236
- this.state.set("params", match.params);
237
- this.logger.verbose(
238
- `findResource: resource "${match.instance.name}" found (template: ${match.instance.isTemplate})`
232
+ this.state.set({ resource, params });
233
+ this.logger.verbose(`findResource: resource "${resource.name}" found (template: ${resource.isTemplate})`);
234
+ }
235
+ /** Whether `uri` names a tool's widget, kept for 'finalize'; any other `ui://` URI is looked up as a resource. */
236
+ async resolveToolWidget(uri) {
237
+ const toolUI = this.scope.toolUI;
238
+ if (!toolUI?.holdsWidgetUri(uri)) return false;
239
+ const { sessionId, authInfo } = this.state;
240
+ const platformType = authInfo?.sessionIdPayload?.platformType ?? this.tryGetContext()?.platformType ?? (sessionId ? this.scope.notifications.getPlatformType(sessionId) : void 0);
241
+ const { handleUIResourceRead } = await import("../../tool/ui/ui-resource.handler.mjs");
242
+ const serverUrl = this.tryGetContext()?.metadata.serverUrl ?? getPinnedPublicUrl();
243
+ const uiResult = handleUIResourceRead(uri, toolUI, platformType, serverUrl);
244
+ if (uiResult.error || !uiResult.result) {
245
+ this.logger.warn(`findResource: UI resource error - ${escapeControlCharacters(uiResult.error ?? "no result")}`);
246
+ throw new ResourceNotFoundError(uri);
247
+ }
248
+ this.state.set({ isUIResource: true, uiResourceResult: uiResult.result });
249
+ return true;
250
+ }
251
+ async useResourceHooks() {
252
+ const { resource } = this.state;
253
+ if (!resource) return;
254
+ await this.useEntryHooks(
255
+ appOwnerIdOf(this.scope.resources.lineageOf(resource) ?? [], resource.owner),
256
+ resource.record.provide
239
257
  );
240
- this.logger.verbose("findResource:done");
241
258
  }
242
259
  async checkEnabled() {
243
260
  const { resource } = this.state;
@@ -422,6 +439,9 @@ __decorateClass([
422
439
  __decorateClass([
423
440
  Stage("findResource")
424
441
  ], ReadResourceFlow.prototype, "findResource", 1);
442
+ __decorateClass([
443
+ Stage("useResourceHooks")
444
+ ], ReadResourceFlow.prototype, "useResourceHooks", 1);
425
445
  __decorateClass([
426
446
  Stage("checkEnabled")
427
447
  ], ReadResourceFlow.prototype, "checkEnabled", 1);
@@ -61,14 +61,19 @@ var SubscribeResourceFlow = class extends FlowBase {
61
61
  this.logger.warn(`parseInput: invalid method "${method}"`);
62
62
  throw new InvalidMethodError(method, "resources/subscribe");
63
63
  }
64
- const sessionId = mcpRequestSessionId(ctx);
64
+ const checkOnly = ctx?.checkOnly === true;
65
+ const sessionId = checkOnly ? void 0 : mcpRequestSessionId(ctx);
65
66
  this.state.set({ input: params, sessionId });
66
67
  this.logger.verbose("parseInput:done");
67
68
  }
68
69
  async validateResource() {
69
70
  this.logger.verbose("validateResource:start");
70
71
  const { uri } = this.state.required.input;
71
- if (isUIResourceUri(uri)) return;
72
+ const toolUI = this.scope.toolUI;
73
+ if (isUIResourceUri(uri) && toolUI?.holdsWidgetUri(uri)) {
74
+ if (toolUI.hasWidget(uri)) return;
75
+ throw new ResourceNotFoundError(uri);
76
+ }
72
77
  let match = this.scope.resources.findResourceForUri(uri);
73
78
  if (!match) {
74
79
  await loadRemoteAppCapabilities(this.scope);
@@ -116,10 +121,10 @@ var SubscribeResourceFlow = class extends FlowBase {
116
121
  const { uri } = this.state.required.input;
117
122
  const { sessionId } = this.state;
118
123
  if (!sessionId) {
119
- this.logger.verbose("subscribe: no session ID in the request context");
124
+ this.logger.verbose("subscribe: no session ID in the request context, or a check-only request");
120
125
  return;
121
126
  }
122
- const isNew = this.scope.notifications.subscribeResource(sessionId, uri);
127
+ const isNew = this.scope.notifications.subscribeResource(sessionId, uri, this.tryGetContext()?.platformEnv);
123
128
  if (isNew) {
124
129
  this.logger.info(`subscribe: session subscribed to resource ${uri}`);
125
130
  } else {
@@ -426,7 +426,9 @@ var Scope = class _Scope extends ScopeEntry {
426
426
  sqlite: tasksSqlite,
427
427
  keyPrefix: tasksConfig?.keyPrefix ?? "mcp:task:",
428
428
  logger: this.logger,
429
- isEdgeRuntime: onEdge
429
+ isEdgeRuntime: onEdge,
430
+ listFrom: tasksConfig?.listFrom,
431
+ maxTtlMs: tasksConfig?.maxTtlMs
430
432
  });
431
433
  this._taskStore = taskStore;
432
434
  this.onDispose(async () => {
@@ -90,13 +90,14 @@ function shouldEnforceDerivedHosts(input) {
90
90
  if (input.port === void 0) return false;
91
91
  return !isRoutableBind(input.bindAddress);
92
92
  }
93
- function allowedHostsFromEnv(env = process.env) {
94
- const raw = env["FRONTMCP_ALLOWED_HOSTS"]?.trim();
93
+ function allowedHostsFromEnv(env = typeof process !== "undefined" ? process.env : void 0) {
94
+ const raw = env?.["FRONTMCP_ALLOWED_HOSTS"]?.trim();
95
95
  if (!raw) return void 0;
96
96
  const hosts = raw.split(",").map((h) => h.trim()).filter(Boolean);
97
97
  return hosts.length > 0 ? hosts : void 0;
98
98
  }
99
99
  export {
100
+ LOOPBACK_NAMES,
100
101
  allowedHostsFromEnv,
101
102
  corsAllowedOrigins,
102
103
  deriveAllowedHosts,