()
| 2861 | // fires on the `notifications/initialized` notification, which is never |
| 2862 | // persisted. `appsSupported()` is what makes the restored case correct. |
| 2863 | const syncToolAvailability = () => { |
| 2864 | const clientCapabilities = server.server.getClientCapabilities(); |
| 2865 | const uiCapability = getUiCapability( |
| 2866 | clientCapabilities as |
| 2867 | | (ClientCapabilities & { extensions?: Record<string, unknown> }) |
| 2868 | | null, |
| 2869 | ); |
| 2870 | // Absent capabilities (the SDK returns `undefined`) mean `initialize` |
| 2871 | // hasn't happened on THIS server instance — the construction-time call |
| 2872 | // below, or a cold restore that resumed mid-conversation. Neither is |
| 2873 | // evidence the client lost apps support, so the restored value stands |
| 2874 | // until a real `initialize` replaces it. Reading `false` off an absent |
| 2875 | // value here is exactly what made a cold-restored session fall back to |
| 2876 | // deep links. |
| 2877 | const negotiated = clientCapabilities |
| 2878 | ? Boolean(uiCapability?.mimeTypes?.includes(RESOURCE_MIME_TYPE)) |
| 2879 | : appsEnabled; |
| 2880 | const changed = negotiated !== appsEnabled; |
| 2881 | applyAppsEnabled(negotiated); |
| 2882 | |
| 2883 | // Persist only a real negotiation that moved the value, so the next cold |
| 2884 | // restore seeds itself. Best-effort: the session must not fail on it. |
| 2885 | // The `clientCapabilities` guard matters beyond skipping a no-op write: |
| 2886 | // persisting an absent-capability reading would make a downgrade durable |
| 2887 | // for every future restore of the session. |
| 2888 | const onAppsEnabledChange = config.onAppsEnabledChange; |
| 2889 | if (clientCapabilities && changed && onAppsEnabledChange) { |
| 2890 | // 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 |
| 2891 | void Effect.runPromiseWith(context)( |
| 2892 | onAppsEnabledChange(negotiated).pipe(Effect.ignoreCause({ log: false })), |
| 2893 | ); |
| 2894 | } |
| 2895 | |
| 2896 | console.error( |
| 2897 | "[executor] MCP session mode", |
| 2898 | JSON.stringify({ |
| 2899 | ...capabilitySnapshot(server), |
| 2900 | elicitationMode: elicitationMode.mode, |
| 2901 | resumeEnabled: elicitationMode.mode !== "native", |
| 2902 | }), |
| 2903 | ); |
| 2904 | debugLog("tool.visibility", { |
| 2905 | clientCapabilities: clientCapabilities ?? null, |
| 2906 | elicitationSupport: getElicitationSupport(server), |
| 2907 | elicitationMode: elicitationMode.mode, |
| 2908 | resumeEnabled: elicitationMode.mode !== "native", |
| 2909 | appsSupport: uiCapability ?? null, |
| 2910 | appsEnabled, |
| 2911 | executeActionEnabled: appsEnabled, |
| 2912 | }); |
| 2913 | }; |
| 2914 | |
| 2915 | yield* Effect.sync(() => { |
| 2916 | syncToolAvailability(); |
no test coverage detected