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

Function syncToolAvailability

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

Source from the content-addressed store, hash-verified

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

Callers 1

createExecutorMcpServerFunction · 0.85

Calls 4

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

Tested by

no test coverage detected