()
| 2289 | // fires on the `notifications/initialized` notification, which is never |
| 2290 | // persisted. `appsSupported()` is what makes the restored case correct. |
| 2291 | const syncToolAvailability = () => { |
| 2292 | const clientCapabilities = server.server.getClientCapabilities(); |
| 2293 | const uiCapability = getUiCapability( |
| 2294 | clientCapabilities as |
| 2295 | | (ClientCapabilities & { extensions?: Record<string, unknown> }) |
| 2296 | | null, |
| 2297 | ); |
| 2298 | // Absent capabilities (the SDK returns `undefined`) mean `initialize` |
| 2299 | // hasn't happened on THIS server instance — the construction-time call |
| 2300 | // below, or a cold restore that resumed mid-conversation. Neither is |
| 2301 | // evidence the client lost apps support, so the restored value stands |
| 2302 | // until a real `initialize` replaces it. Reading `false` off an absent |
| 2303 | // value here is exactly what made a cold-restored session fall back to |
| 2304 | // deep links. |
| 2305 | const negotiated = clientCapabilities |
| 2306 | ? Boolean(uiCapability?.mimeTypes?.includes(RESOURCE_MIME_TYPE)) |
| 2307 | : appsEnabled; |
| 2308 | const changed = negotiated !== appsEnabled; |
| 2309 | applyAppsEnabled(negotiated); |
| 2310 | |
| 2311 | // Persist only a real negotiation that moved the value, so the next cold |
| 2312 | // restore seeds itself. Best-effort: the session must not fail on it. |
| 2313 | // The `clientCapabilities` guard matters beyond skipping a no-op write: |
| 2314 | // persisting an absent-capability reading would make a downgrade durable |
| 2315 | // for every future restore of the session. |
| 2316 | const onAppsEnabledChange = config.onAppsEnabledChange; |
| 2317 | if (clientCapabilities && changed && onAppsEnabledChange) { |
| 2318 | // oxlint-disable-next-line executor/no-effect-escape-hatch -- boundary: `oninitialized` is a sync SDK hook; persistence is fire-and-forget and its failure must not fail the session |
| 2319 | void Effect.runPromiseWith(context)( |
| 2320 | onAppsEnabledChange(negotiated).pipe(Effect.ignoreCause({ log: false })), |
| 2321 | ); |
| 2322 | } |
| 2323 | |
| 2324 | console.error( |
| 2325 | "[executor] MCP session mode", |
| 2326 | JSON.stringify({ |
| 2327 | ...capabilitySnapshot(server), |
| 2328 | elicitationMode: elicitationMode.mode, |
| 2329 | resumeEnabled: elicitationMode.mode !== "native", |
| 2330 | }), |
| 2331 | ); |
| 2332 | debugLog("tool.visibility", { |
| 2333 | clientCapabilities: clientCapabilities ?? null, |
| 2334 | elicitationSupport: getElicitationSupport(server), |
| 2335 | elicitationMode: elicitationMode.mode, |
| 2336 | resumeEnabled: elicitationMode.mode !== "native", |
| 2337 | appsSupport: uiCapability ?? null, |
| 2338 | appsEnabled, |
| 2339 | executeActionEnabled: appsEnabled, |
| 2340 | }); |
| 2341 | }; |
| 2342 | |
| 2343 | yield* Effect.sync(() => { |
| 2344 | syncToolAvailability(); |
no test coverage detected