MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / syncToolAvailability

Function syncToolAvailability

packages/hosts/mcp/src/tool-server.ts:2212–2262  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2210 // fires on the `notifications/initialized` notification, which is never
2211 // persisted. `appsSupported()` is what makes the restored case correct.
2212 const syncToolAvailability = () => {
2213 const clientCapabilities = server.server.getClientCapabilities();
2214 const uiCapability = getUiCapability(
2215 clientCapabilities as
2216 | (ClientCapabilities & { extensions?: Record<string, unknown> })
2217 | null,
2218 );
2219 // Absent capabilities (the SDK returns `undefined`) mean `initialize`
2220 // hasn't happened on THIS server instance — the construction-time call
2221 // below, or a cold restore that resumed mid-conversation. Neither is
2222 // evidence the client lost apps support, so the restored value stands
2223 // until a real `initialize` replaces it. Reading `false` off an absent
2224 // value here is exactly what made a cold-restored session fall back to
2225 // deep links.
2226 const negotiated = clientCapabilities
2227 ? Boolean(uiCapability?.mimeTypes?.includes(RESOURCE_MIME_TYPE))
2228 : appsEnabled;
2229 const changed = negotiated !== appsEnabled;
2230 applyAppsEnabled(negotiated);
2231
2232 // Persist only a real negotiation that moved the value, so the next cold
2233 // restore seeds itself. Best-effort: the session must not fail on it.
2234 // The `clientCapabilities` guard matters beyond skipping a no-op write:
2235 // persisting an absent-capability reading would make a downgrade durable
2236 // for every future restore of the session.
2237 const onAppsEnabledChange = config.onAppsEnabledChange;
2238 if (clientCapabilities && changed && onAppsEnabledChange) {
2239 // 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
2240 void Effect.runPromiseWith(context)(
2241 onAppsEnabledChange(negotiated).pipe(Effect.ignoreCause({ log: false })),
2242 );
2243 }
2244
2245 console.error(
2246 "[executor] MCP session mode",
2247 JSON.stringify({
2248 ...capabilitySnapshot(server),
2249 elicitationMode: elicitationMode.mode,
2250 resumeEnabled: elicitationMode.mode !== "native",
2251 }),
2252 );
2253 debugLog("tool.visibility", {
2254 clientCapabilities: clientCapabilities ?? null,
2255 elicitationSupport: getElicitationSupport(server),
2256 elicitationMode: elicitationMode.mode,
2257 resumeEnabled: elicitationMode.mode !== "native",
2258 appsSupport: uiCapability ?? null,
2259 appsEnabled,
2260 executeActionEnabled: appsEnabled,
2261 });
2262 };
2263
2264 yield* Effect.sync(() => {
2265 syncToolAvailability();

Callers 1

createExecutorMcpServerFunction · 0.85

Calls 5

applyAppsEnabledFunction · 0.85
capabilitySnapshotFunction · 0.85
debugLogFunction · 0.85
getElicitationSupportFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected