feat(server): advertise available tools dynamically
This commit is contained in:
@@ -34,13 +34,23 @@ export const toolFamilyCatalog = (sources) => {
|
||||
{
|
||||
id: "browser",
|
||||
surface: "browser-provider",
|
||||
contracts: sources.browserContracts.BROWSER_TOOL_CONTRACTS,
|
||||
contracts: [
|
||||
...sources.browserContracts.BROWSER_TOOL_CONTRACTS,
|
||||
...sources.browserScenarioContracts.BROWSER_SCENARIO_TOOL_CONTRACTS,
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "electron",
|
||||
surface: "electron-provider",
|
||||
contracts: sources.electronContracts.ELECTRON_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
id: "javascript-runtime",
|
||||
surface: "runtime-provider",
|
||||
contracts:
|
||||
sources.javascriptRuntimeObservationContracts
|
||||
.JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
id: "application",
|
||||
surface: "application-workflow",
|
||||
@@ -121,10 +131,23 @@ export const providerCatalog = (sources) => {
|
||||
identity: sources.browserProvider.CDP_BROWSER_PROVIDER_IDENTITY,
|
||||
contracts: sources.browserContracts.BROWSER_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity:
|
||||
sources.browserScenarioProvider
|
||||
.PLAYWRIGHT_BROWSER_SCENARIO_PROVIDER_IDENTITY,
|
||||
contracts:
|
||||
sources.browserScenarioContracts.BROWSER_SCENARIO_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.electronProvider.CDP_ELECTRON_PROVIDER_IDENTITY,
|
||||
contracts: observationContracts,
|
||||
},
|
||||
{
|
||||
identity: sources.v8InspectorProvider.V8_INSPECTOR_PROVIDER_IDENTITY,
|
||||
contracts:
|
||||
sources.javascriptRuntimeObservationContracts
|
||||
.JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.artifactProviders.JAVASCRIPT_APPLICATION_PROVIDER,
|
||||
contracts: applicationContracts,
|
||||
|
||||
@@ -31,7 +31,10 @@ const SOURCE_PATHS = {
|
||||
managedContracts: "dist/contracts/managedToolContracts.js",
|
||||
managedWorkflowContracts: "dist/contracts/managedWorkflowToolContracts.js",
|
||||
browserContracts: "dist/contracts/browserToolContracts.js",
|
||||
browserScenarioContracts: "dist/contracts/browserScenarioToolContracts.js",
|
||||
electronContracts: "dist/contracts/electronToolContracts.js",
|
||||
javascriptRuntimeObservationContracts:
|
||||
"dist/contracts/javascriptRuntimeObservationToolContracts.js",
|
||||
applicationContracts: "dist/contracts/applicationToolContracts.js",
|
||||
supportedClients: "dist/application/SupportedClients.js",
|
||||
hopperProvider: "dist/hopper/HopperProvider.js",
|
||||
@@ -39,7 +42,9 @@ const SOURCE_PATHS = {
|
||||
nativeProvider: "dist/native/NativeMacOSProvider.js",
|
||||
artifactProviders: "dist/application/InvestigationProviders.js",
|
||||
browserProvider: "dist/browser/CdpBrowserProvider.js",
|
||||
browserScenarioProvider: "dist/browser/PlaywrightBrowserScenarioProvider.js",
|
||||
electronProvider: "dist/browser/CdpElectronProvider.js",
|
||||
v8InspectorProvider: "dist/browser/V8InspectorProvider.js",
|
||||
evidence: "dist/domain/evidence.js",
|
||||
evidenceBundle: "dist/domain/evidenceBundle.js",
|
||||
evidenceCompletion: "dist/domain/evidenceCompletionLedger.js",
|
||||
@@ -49,8 +54,12 @@ const SOURCE_PATHS = {
|
||||
artifactGraph: "dist/domain/artifactGraph.js",
|
||||
investigationWorkspace: "dist/domain/investigationWorkspace.js",
|
||||
browserObservation: "dist/domain/browserObservation.js",
|
||||
browserScenario: "dist/domain/browserScenario.js",
|
||||
browserScenarioCapture: "dist/domain/browserScenarioCapture.js",
|
||||
browserScenarioDiff: "dist/domain/browserScenarioDiff.js",
|
||||
browserSession: "dist/domain/browserSession.js",
|
||||
electronObservation: "dist/domain/electronObservation.js",
|
||||
javascriptRuntimeObservation: "dist/domain/javascriptRuntimeObservation.js",
|
||||
webBundleAnalysis: "dist/domain/webBundleAnalysis.js",
|
||||
webCaptureDiff: "dist/domain/webCaptureDiff.js",
|
||||
managedArtifact: "dist/domain/managedArtifact.js",
|
||||
|
||||
@@ -23,7 +23,11 @@ const valuesAt = (node, path) => {
|
||||
|
||||
const versionAt = (schema, path) => {
|
||||
const versions = [
|
||||
...new Set(valuesAt(z.toJSONSchema(schema), path).map(String)),
|
||||
...new Set(
|
||||
valuesAt(z.toJSONSchema(schema, { unrepresentable: "any" }), path).map(
|
||||
String,
|
||||
),
|
||||
),
|
||||
];
|
||||
if (versions.length !== 1)
|
||||
throw new Error(
|
||||
@@ -50,6 +54,11 @@ const durableSchemaDefinitions = (sources) => [
|
||||
sources.artifactGraph.artifactExtractionResultSchema,
|
||||
["extraction_manifest", "schema_version"],
|
||||
],
|
||||
[
|
||||
"browser_scenario",
|
||||
sources.browserScenario.browserScenarioSchema,
|
||||
["schema_version"],
|
||||
],
|
||||
["evidence", sources.evidence.evidenceSchema, ["schema_version"]],
|
||||
[
|
||||
"evidence_bundle",
|
||||
@@ -129,6 +138,19 @@ const durableSchemaDefinitions = (sources) => [
|
||||
],
|
||||
];
|
||||
|
||||
const browserScenarioObservationSchemaDefinitions = (sources) => [
|
||||
[
|
||||
"browser_scenario_capture",
|
||||
sources.browserScenarioCapture.browserScenarioCaptureSchema,
|
||||
["schema_version"],
|
||||
],
|
||||
[
|
||||
"browser_scenario_diff",
|
||||
sources.browserScenarioDiff.browserScenarioDiffSchema,
|
||||
["schema_version"],
|
||||
],
|
||||
];
|
||||
|
||||
const observationSchemaDefinitions = (sources) => [
|
||||
[
|
||||
"managed_artifact_inspection",
|
||||
@@ -160,6 +182,7 @@ const observationSchemaDefinitions = (sources) => [
|
||||
sources.browserObservation.browserTargetListSchema,
|
||||
["schema_version"],
|
||||
],
|
||||
...browserScenarioObservationSchemaDefinitions(sources),
|
||||
[
|
||||
"electron_page_inspection",
|
||||
sources.electronObservation.electronPageInspectionSchema,
|
||||
@@ -176,6 +199,16 @@ const observationSchemaDefinitions = (sources) => [
|
||||
.javaScriptApplicationAnalysisResultV2Schema,
|
||||
["schema_version"],
|
||||
],
|
||||
[
|
||||
"javascript_runtime_observation",
|
||||
sources.javascriptRuntimeObservation.javascriptRuntimeObservationSchema,
|
||||
["schema_version"],
|
||||
],
|
||||
[
|
||||
"javascript_runtime_target_list",
|
||||
sources.javascriptRuntimeObservation.javascriptRuntimeTargetListSchema,
|
||||
["schema_version"],
|
||||
],
|
||||
[
|
||||
"web_bundle_analysis",
|
||||
sources.webBundleAnalysis.webBundleAnalysisSchema,
|
||||
|
||||
@@ -5,17 +5,26 @@ import { promisify } from "node:util";
|
||||
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js";
|
||||
import * as prompts from "./verify-package-prompts.mjs";
|
||||
import { json } from "./lib/verify-package-core.mjs";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
|
||||
const verifyMcpToolsAndPrompts = async (client, mcpOptions) => {
|
||||
if (
|
||||
(await client.listTools(undefined, mcpOptions)).tools.length !==
|
||||
TOOL_CONTRACTS.length
|
||||
)
|
||||
const listed = await client.listTools(undefined, mcpOptions);
|
||||
const status = await client.callTool(
|
||||
{ name: "binary_session", arguments: { detail: "full" } },
|
||||
mcpOptions,
|
||||
);
|
||||
const availability = status.structuredContent?.result?.tool_availability;
|
||||
if (!Array.isArray(availability))
|
||||
throw new Error("packaged MCP omitted tool availability");
|
||||
const expected = availability
|
||||
.filter(({ available }) => available === true)
|
||||
.map(({ name }) => name)
|
||||
.sort();
|
||||
const observed = listed.tools.map(({ name }) => name).sort();
|
||||
if (JSON.stringify(observed) !== JSON.stringify(expected))
|
||||
throw new Error("packaged MCP tool inventory diverged from contracts");
|
||||
await prompts.verifyPromptCatalog(client, mcpOptions, prompts.names);
|
||||
await prompts.verifyPromptCompletion(client, mcpOptions, false);
|
||||
@@ -44,12 +53,11 @@ const verifyMcpReplay = async (client, mcpOptions, investigationReplay) => {
|
||||
};
|
||||
|
||||
const verifyMcpTargetFree = async (client, mcpOptions) => {
|
||||
const result = await client.callTool(
|
||||
{ name: "current_document", arguments: {} },
|
||||
mcpOptions,
|
||||
const names = (await client.listTools(undefined, mcpOptions)).tools.map(
|
||||
({ name }) => name,
|
||||
);
|
||||
if (result.isError !== true)
|
||||
throw new Error("packaged target-free MCP omitted no-target error");
|
||||
if (names.includes("current_document"))
|
||||
throw new Error("packaged target-free MCP advertised a target-bound tool");
|
||||
};
|
||||
|
||||
const verifyMcpUnknownProvider = async (client, mcpOptions) => {
|
||||
@@ -97,14 +105,12 @@ const verifyMcpOpenAndBind = async (client, mcpOptions) => {
|
||||
throw new Error("packaged MCP omitted its explicit Hopper binding");
|
||||
};
|
||||
|
||||
const verifyMcpLinuxCurrentDocument = async (client, mcpOptions, current) => {
|
||||
if (
|
||||
current.isError !== true ||
|
||||
!prompts
|
||||
.mcpText(current)
|
||||
.includes("not supported for unattended Linux analysis")
|
||||
)
|
||||
throw new Error("packaged Linux MCP did not reject an unpinned Hopper");
|
||||
const verifyMcpLinuxToolAvailability = async (client, mcpOptions) => {
|
||||
const names = (await client.listTools(undefined, mcpOptions)).tools.map(
|
||||
({ name }) => name,
|
||||
);
|
||||
if (names.includes("current_document"))
|
||||
throw new Error("packaged Linux MCP advertised unavailable Hopper tools");
|
||||
};
|
||||
|
||||
const verifyMcpNonLinuxCurrentDocument = async (
|
||||
@@ -140,13 +146,13 @@ const verifyMcpBinaryLifecycle = async (client, mcpOptions) => {
|
||||
mcpOptions,
|
||||
process.platform !== "linux",
|
||||
);
|
||||
const current = await client.callTool(
|
||||
{ name: "current_document", arguments: {} },
|
||||
mcpOptions,
|
||||
);
|
||||
if (process.platform === "linux") {
|
||||
await verifyMcpLinuxCurrentDocument(client, mcpOptions, current);
|
||||
await verifyMcpLinuxToolAvailability(client, mcpOptions);
|
||||
} else {
|
||||
const current = await client.callTool(
|
||||
{ name: "current_document", arguments: {} },
|
||||
mcpOptions,
|
||||
);
|
||||
await verifyMcpNonLinuxCurrentDocument(client, mcpOptions, current);
|
||||
}
|
||||
const closed = await client.callTool(
|
||||
@@ -191,7 +197,8 @@ export async function verifyPackageMcp({
|
||||
);
|
||||
if (
|
||||
diagnosed.healthy !== true ||
|
||||
diagnosed.inventory?.tools?.observed !== TOOL_CONTRACTS.length
|
||||
diagnosed.inventory?.tools?.observed !==
|
||||
diagnosed.inventory?.tools?.expected
|
||||
)
|
||||
throw new Error("packaged production MCP doctor failed");
|
||||
const transport = new StdioClientTransport({
|
||||
|
||||
Reference in New Issue
Block a user