()
| 2330 | // fires on the `notifications/initialized` notification, which is never |
| 2331 | // persisted. `appsSupported()` is what makes the restored case correct. |
| 2332 | const syncToolAvailability = () => { |
| 2333 | const clientCapabilities = server.server.getClientCapabilities(); |
| 2334 | const uiCapability = getUiCapability( |
| 2335 | clientCapabilities as |
| 2336 | | (ClientCapabilities & { extensions?: Record<string, unknown> }) |
| 2337 | | null, |
| 2338 | ); |
| 2339 | // Absent capabilities (the SDK returns `undefined`) mean `initialize` |
| 2340 | // hasn't happened on THIS server instance — the construction-time call |
| 2341 | // below, or a cold restore that resumed mid-conversation. Neither is |
| 2342 | // evidence the client lost apps support, so the restored value stands |
| 2343 | // until a real `initialize` replaces it. Reading `false` off an absent |
| 2344 | // value here is exactly what made a cold-restored session fall back to |
| 2345 | // deep links. |
| 2346 | const negotiated = clientCapabilities |
| 2347 | ? Boolean(uiCapability?.mimeTypes?.includes(RESOURCE_MIME_TYPE)) |
| 2348 | : appsEnabled; |
| 2349 | const changed = negotiated !== appsEnabled; |
| 2350 | applyAppsEnabled(negotiated); |
| 2351 | |
| 2352 | // Persist only a real negotiation that moved the value, so the next cold |
| 2353 | // restore seeds itself. Best-effort: the session must not fail on it. |
| 2354 | // The `clientCapabilities` guard matters beyond skipping a no-op write: |
| 2355 | // persisting an absent-capability reading would make a downgrade durable |
| 2356 | // for every future restore of the session. |
| 2357 | const onAppsEnabledChange = config.onAppsEnabledChange; |
| 2358 | if (clientCapabilities && changed && onAppsEnabledChange) { |
| 2359 | // 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 |
| 2360 | void Effect.runPromiseWith(context)( |
| 2361 | onAppsEnabledChange(negotiated).pipe(Effect.ignoreCause({ log: false })), |
| 2362 | ); |
| 2363 | } |
| 2364 | |
| 2365 | console.error( |
| 2366 | "[executor] MCP session mode", |
| 2367 | JSON.stringify({ |
| 2368 | ...capabilitySnapshot(server), |
| 2369 | elicitationMode: elicitationMode.mode, |
| 2370 | resumeEnabled: elicitationMode.mode !== "native", |
| 2371 | }), |
| 2372 | ); |
| 2373 | debugLog("tool.visibility", { |
| 2374 | clientCapabilities: clientCapabilities ?? null, |
| 2375 | elicitationSupport: getElicitationSupport(server), |
| 2376 | elicitationMode: elicitationMode.mode, |
| 2377 | resumeEnabled: elicitationMode.mode !== "native", |
| 2378 | appsSupport: uiCapability ?? null, |
| 2379 | appsEnabled, |
| 2380 | executeActionEnabled: appsEnabled, |
| 2381 | }); |
| 2382 | }; |
| 2383 | |
| 2384 | yield* Effect.sync(() => { |
| 2385 | syncToolAvailability(); |
no test coverage detected