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

Function syncToolAvailability

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

Source from the content-addressed store, hash-verified

2014 // fires on the `notifications/initialized` notification, which is never
2015 // persisted. `appsSupported()` is what makes the restored case correct.
2016 const syncToolAvailability = () => {
2017 const clientCapabilities = server.server.getClientCapabilities();
2018 const uiCapability = getUiCapability(
2019 clientCapabilities as
2020 | (ClientCapabilities & { extensions?: Record<string, unknown> })
2021 | null,
2022 );
2023 // Absent capabilities (the SDK returns `undefined`) mean `initialize`
2024 // hasn't happened on THIS server instance — the construction-time call
2025 // below, or a cold restore that resumed mid-conversation. Neither is
2026 // evidence the client lost apps support, so the restored value stands
2027 // until a real `initialize` replaces it. Reading `false` off an absent
2028 // value here is exactly what made a cold-restored session fall back to
2029 // deep links.
2030 const negotiated = clientCapabilities
2031 ? Boolean(uiCapability?.mimeTypes?.includes(RESOURCE_MIME_TYPE))
2032 : appsEnabled;
2033 const changed = negotiated !== appsEnabled;
2034 applyAppsEnabled(negotiated);
2035
2036 // Persist only a real negotiation that moved the value, so the next cold
2037 // restore seeds itself. Best-effort: the session must not fail on it.
2038 // The `clientCapabilities` guard matters beyond skipping a no-op write:
2039 // persisting an absent-capability reading would make a downgrade durable
2040 // for every future restore of the session.
2041 const onAppsEnabledChange = config.onAppsEnabledChange;
2042 if (clientCapabilities && changed && onAppsEnabledChange) {
2043 // 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
2044 void Effect.runPromiseWith(context)(
2045 onAppsEnabledChange(negotiated).pipe(Effect.ignoreCause({ log: false })),
2046 );
2047 }
2048
2049 console.error(
2050 "[executor] MCP session mode",
2051 JSON.stringify({
2052 ...capabilitySnapshot(server),
2053 elicitationMode: elicitationMode.mode,
2054 resumeEnabled: elicitationMode.mode !== "native",
2055 }),
2056 );
2057 debugLog("tool.visibility", {
2058 clientCapabilities: clientCapabilities ?? null,
2059 elicitationSupport: getElicitationSupport(server),
2060 elicitationMode: elicitationMode.mode,
2061 resumeEnabled: elicitationMode.mode !== "native",
2062 appsSupport: uiCapability ?? null,
2063 appsEnabled,
2064 executeActionEnabled: appsEnabled,
2065 });
2066 };
2067
2068 yield* Effect.sync(() => {
2069 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