feat(server): advertise available tools dynamically
This commit is contained in:
+35
-31
@@ -3,6 +3,8 @@ import type { StdioServerHandle } from "@modelcontextprotocol/server/stdio";
|
||||
import type { BinarySession } from "../application/BinarySession.js";
|
||||
import type { CdpBrowserProvider } from "../browser/CdpBrowserProvider.js";
|
||||
import type { CdpElectronProvider } from "../browser/CdpElectronProvider.js";
|
||||
import type { V8InspectorProvider } from "../browser/V8InspectorProvider.js";
|
||||
import type { PlaywrightBrowserScenarioProvider } from "../browser/PlaywrightBrowserScenarioProvider.js";
|
||||
import type { PermissionAuthority } from "../application/PermissionAuthority.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { createServer } from "../server/createServer.js";
|
||||
@@ -19,7 +21,9 @@ interface ServerContext {
|
||||
readonly logger: Logger;
|
||||
readonly serverLogger: Logger;
|
||||
readonly browserObservation: CdpBrowserProvider;
|
||||
readonly browserScenarioCapture: PlaywrightBrowserScenarioProvider;
|
||||
readonly electronObservation: CdpElectronProvider;
|
||||
readonly javascriptRuntimeObservation: V8InspectorProvider;
|
||||
readonly permissionAuthority: PermissionAuthority;
|
||||
readonly runtimeState: RuntimeState;
|
||||
}
|
||||
@@ -55,7 +59,10 @@ export const startMcpTransport = async (
|
||||
serverContext.runtimeState.snapshotPolicy,
|
||||
permissionAuthority: serverContext.permissionAuthority,
|
||||
browserObservation: serverContext.browserObservation,
|
||||
browserScenarioCapture: serverContext.browserScenarioCapture,
|
||||
electronObservation: serverContext.electronObservation,
|
||||
javascriptRuntimeObservation:
|
||||
serverContext.javascriptRuntimeObservation,
|
||||
artifactIntegrityContinueEnabled: () =>
|
||||
serverContext.runtimeState.currentConfig
|
||||
.artifactIntegrityContinueEnabled,
|
||||
@@ -63,37 +70,8 @@ export const startMcpTransport = async (
|
||||
serverContext.runtimeState.javascriptReplayPolicy,
|
||||
managedRuntimePolicy:
|
||||
serverContext.runtimeState.managedRuntimePolicy,
|
||||
availabilityPolicy: () => ({
|
||||
processCaptureEnabled:
|
||||
serverContext.runtimeState.currentConfig.processExecutionPolicy
|
||||
.enabled,
|
||||
evidenceFileRoots:
|
||||
serverContext.runtimeState.currentConfig.evidenceFilePolicy
|
||||
.roots.length,
|
||||
investigationInputRoots:
|
||||
serverContext.runtimeState.currentConfig.investigationInputRoots
|
||||
.length,
|
||||
browserObservationEnabled:
|
||||
serverContext.runtimeState.currentConfig
|
||||
.browserObservationEnabled &&
|
||||
serverContext.runtimeState.currentConfig.browserCdpEndpoints
|
||||
.length > 0 &&
|
||||
serverContext.runtimeState.currentConfig.browserAllowedOrigins
|
||||
.length > 0,
|
||||
electronObservationEnabled:
|
||||
serverContext.runtimeState.currentConfig
|
||||
.electronObservationEnabled &&
|
||||
serverContext.runtimeState.currentConfig.electronCdpEndpoints
|
||||
.length > 0 &&
|
||||
serverContext.runtimeState.currentConfig.electronFileRoots
|
||||
.length > 0,
|
||||
javascriptReplayEnabled:
|
||||
serverContext.runtimeState.currentConfig.javascriptReplayPolicy
|
||||
.enabled,
|
||||
managedRuntimeEnabled:
|
||||
serverContext.runtimeState.currentConfig.managedRuntimePolicy
|
||||
.enabled,
|
||||
}),
|
||||
availabilityPolicy: () =>
|
||||
runtimeAvailability(serverContext.runtimeState),
|
||||
},
|
||||
);
|
||||
liveServers.add(server);
|
||||
@@ -114,3 +92,29 @@ export const startMcpTransport = async (
|
||||
}
|
||||
return { ok: true, handle, liveServers };
|
||||
};
|
||||
|
||||
const runtimeAvailability = (state: RuntimeState) => ({
|
||||
processCaptureEnabled: state.currentConfig.processExecutionPolicy.enabled,
|
||||
evidenceFileRoots: state.currentConfig.evidenceFilePolicy.roots.length,
|
||||
investigationInputRoots: state.currentConfig.investigationInputRoots.length,
|
||||
browserObservationEnabled:
|
||||
state.currentConfig.browserObservationEnabled &&
|
||||
state.currentConfig.browserCdpEndpoints.length > 0 &&
|
||||
state.currentConfig.browserAllowedOrigins.length > 0,
|
||||
browserScenarioEnabled:
|
||||
state.currentConfig.browserScenarioPolicy.enabled &&
|
||||
state.currentConfig.browserScenarioPolicy.allowedOrigins.length > 0 &&
|
||||
(state.currentConfig.browserScenarioPolicy.executableRoots.length > 0 ||
|
||||
state.currentConfig.browserScenarioPolicy.cdpEndpoints.length > 0),
|
||||
electronObservationEnabled:
|
||||
state.currentConfig.electronObservationEnabled &&
|
||||
state.currentConfig.electronCdpEndpoints.length > 0 &&
|
||||
state.currentConfig.electronFileRoots.length > 0,
|
||||
v8InspectorObservationEnabled:
|
||||
state.currentConfig.v8InspectorObservationEnabled &&
|
||||
state.currentConfig.v8InspectorEndpoints.length > 0 &&
|
||||
(state.currentConfig.v8InspectorFileRoots.length > 0 ||
|
||||
state.currentConfig.v8InspectorAllowedOrigins.length > 0),
|
||||
javascriptReplayEnabled: state.currentConfig.javascriptReplayPolicy.enabled,
|
||||
managedRuntimeEnabled: state.currentConfig.managedRuntimePolicy.enabled,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user