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

Function syncToolAvailability

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

Source from the content-addressed store, hash-verified

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