()
| 2172 | // fires on the `notifications/initialized` notification, which is never |
| 2173 | // persisted. `appsSupported()` is what makes the restored case correct. |
| 2174 | const syncToolAvailability = () => { |
| 2175 | const clientCapabilities = server.server.getClientCapabilities(); |
| 2176 | const uiCapability = getUiCapability( |
| 2177 | clientCapabilities as |
| 2178 | | (ClientCapabilities & { extensions?: Record<string, unknown> }) |
| 2179 | | null, |
| 2180 | ); |
| 2181 | // Absent capabilities (the SDK returns `undefined`) mean `initialize` |
| 2182 | // hasn't happened on THIS server instance — the construction-time call |
| 2183 | // below, or a cold restore that resumed mid-conversation. Neither is |
| 2184 | // evidence the client lost apps support, so the restored value stands |
| 2185 | // until a real `initialize` replaces it. Reading `false` off an absent |
| 2186 | // value here is exactly what made a cold-restored session fall back to |
| 2187 | // deep links. |
| 2188 | const negotiated = clientCapabilities |
| 2189 | ? Boolean(uiCapability?.mimeTypes?.includes(RESOURCE_MIME_TYPE)) |
| 2190 | : appsEnabled; |
| 2191 | const changed = negotiated !== appsEnabled; |
| 2192 | applyAppsEnabled(negotiated); |
| 2193 | |
| 2194 | // Persist only a real negotiation that moved the value, so the next cold |
| 2195 | // restore seeds itself. Best-effort: the session must not fail on it. |
| 2196 | // The `clientCapabilities` guard matters beyond skipping a no-op write: |
| 2197 | // persisting an absent-capability reading would make a downgrade durable |
| 2198 | // for every future restore of the session. |
| 2199 | const onAppsEnabledChange = config.onAppsEnabledChange; |
| 2200 | if (clientCapabilities && changed && onAppsEnabledChange) { |
| 2201 | // 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 |
| 2202 | void Effect.runPromiseWith(context)( |
| 2203 | onAppsEnabledChange(negotiated).pipe(Effect.ignoreCause({ log: false })), |
| 2204 | ); |
| 2205 | } |
| 2206 | |
| 2207 | console.error( |
| 2208 | "[executor] MCP session mode", |
| 2209 | JSON.stringify({ |
| 2210 | ...capabilitySnapshot(server), |
| 2211 | elicitationMode: elicitationMode.mode, |
| 2212 | resumeEnabled: elicitationMode.mode !== "native", |
| 2213 | }), |
| 2214 | ); |
| 2215 | debugLog("tool.visibility", { |
| 2216 | clientCapabilities: clientCapabilities ?? null, |
| 2217 | elicitationSupport: getElicitationSupport(server), |
| 2218 | elicitationMode: elicitationMode.mode, |
| 2219 | resumeEnabled: elicitationMode.mode !== "native", |
| 2220 | appsSupport: uiCapability ?? null, |
| 2221 | appsEnabled, |
| 2222 | executeActionEnabled: appsEnabled, |
| 2223 | }); |
| 2224 | }; |
| 2225 | |
| 2226 | yield* Effect.sync(() => { |
| 2227 | syncToolAvailability(); |
no test coverage detected