feat(server): advertise available tools dynamically
This commit is contained in:
@@ -38,7 +38,7 @@ describe("browser MCP tools", () => {
|
||||
const connected = await connectBrowser(browser);
|
||||
|
||||
const tools = await connected.client.listTools();
|
||||
expect(tools.tools).toHaveLength(TOOL_CONTRACTS.length);
|
||||
expect(tools.tools.length).toBeLessThan(TOOL_CONTRACTS.length);
|
||||
expect(tools.tools.map(({ name }) => name)).toEqual(
|
||||
expect.arrayContaining([
|
||||
"list_browser_targets",
|
||||
@@ -49,8 +49,6 @@ describe("browser MCP tools", () => {
|
||||
"compare_web_captures",
|
||||
"capture_web_screenshot",
|
||||
"compare_web_screenshots",
|
||||
"list_electron_targets",
|
||||
"inspect_electron_page",
|
||||
]),
|
||||
);
|
||||
const status = await connected.client.callTool({
|
||||
|
||||
@@ -7,7 +7,9 @@ const enabledPolicy: Parameters<typeof buildCapabilityInventory>[1] = {
|
||||
evidenceFileRoots: 1,
|
||||
investigationInputRoots: 1,
|
||||
browserObservationEnabled: true,
|
||||
browserScenarioEnabled: true,
|
||||
electronObservationEnabled: true,
|
||||
v8InspectorObservationEnabled: true,
|
||||
javascriptReplayEnabled: true,
|
||||
managedRuntimeEnabled: true,
|
||||
};
|
||||
@@ -129,7 +131,9 @@ describe("capability inventory", () => {
|
||||
it.each([
|
||||
["capture_process_scenario", { processCaptureEnabled: false }],
|
||||
["inspect_web_page", { browserObservationEnabled: false }],
|
||||
["capture_browser_scenario", { browserScenarioEnabled: false }],
|
||||
["inspect_electron_page", { electronObservationEnabled: false }],
|
||||
["observe_javascript_runtime", { v8InspectorObservationEnabled: false }],
|
||||
["run_controlled_replay", { javascriptReplayEnabled: false }],
|
||||
["plan_managed_runtime_correlation", { managedRuntimeEnabled: false }],
|
||||
] as const)("reports stable policy denial for %s", (name, override) => {
|
||||
@@ -153,6 +157,7 @@ describe("capability inventory", () => {
|
||||
investigationInputRoots: 0,
|
||||
browserObservationEnabled: false,
|
||||
electronObservationEnabled: false,
|
||||
v8InspectorObservationEnabled: false,
|
||||
javascriptReplayEnabled: false,
|
||||
managedRuntimeEnabled: false,
|
||||
});
|
||||
@@ -163,4 +168,30 @@ describe("capability inventory", () => {
|
||||
expect(availability.remediation?.length).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
it("projects negotiated client features into per-tool requirements", () => {
|
||||
const withoutElicitation = buildCapabilityInventory(
|
||||
status(),
|
||||
enabledPolicy,
|
||||
).find(({ name }) => name === "capture_process_scenario");
|
||||
const withElicitation = buildCapabilityInventory(status(), enabledPolicy, {
|
||||
elicitation_form: true,
|
||||
elicitation_url: false,
|
||||
roots: false,
|
||||
sampling: false,
|
||||
}).find(({ name }) => name === "capture_process_scenario");
|
||||
|
||||
expect(withoutElicitation?.client_requirements).toEqual({
|
||||
required: [],
|
||||
optional: ["elicitation_form"],
|
||||
missing_required: [],
|
||||
missing_optional: ["elicitation_form"],
|
||||
});
|
||||
expect(withElicitation?.client_requirements).toEqual({
|
||||
required: [],
|
||||
optional: ["elicitation_form"],
|
||||
missing_required: [],
|
||||
missing_optional: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,9 +32,20 @@ describe("runtime configuration", () => {
|
||||
expect(result.value.browserObservationEnabled).toBe(false);
|
||||
expect(result.value.browserCdpEndpoints).toEqual([]);
|
||||
expect(result.value.browserAllowedOrigins).toEqual([]);
|
||||
expect(result.value.browserScenarioPolicy).toEqual({
|
||||
enabled: false,
|
||||
executableRoots: [],
|
||||
cdpEndpoints: [],
|
||||
allowedOrigins: [],
|
||||
allowedEnvironment: [],
|
||||
});
|
||||
expect(result.value.electronObservationEnabled).toBe(false);
|
||||
expect(result.value.electronCdpEndpoints).toEqual([]);
|
||||
expect(result.value.electronFileRoots).toEqual([]);
|
||||
expect(result.value.v8InspectorObservationEnabled).toBe(false);
|
||||
expect(result.value.v8InspectorEndpoints).toEqual([]);
|
||||
expect(result.value.v8InspectorFileRoots).toEqual([]);
|
||||
expect(result.value.v8InspectorAllowedOrigins).toEqual([]);
|
||||
expect(result.value.javascriptReplayPolicy).toMatchObject({
|
||||
enabled: false,
|
||||
roots: [],
|
||||
@@ -112,6 +123,26 @@ describe("runtime configuration", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("builds a separate V8 Inspector endpoint, root, and origin ceiling", () => {
|
||||
const result = parseConfig({
|
||||
REA_V8_INSPECTOR_OBSERVE_ENABLED: "true",
|
||||
REA_V8_INSPECTOR_ENDPOINTS_JSON: '["http://127.0.0.1:9229"]',
|
||||
REA_V8_INSPECTOR_FILE_ROOTS_JSON: '["/tmp/node-app"]',
|
||||
REA_V8_INSPECTOR_ALLOWED_ORIGINS_JSON: '["http://127.0.0.1:3000"]',
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) return;
|
||||
expect(result.value.permissionCeilings).toContainEqual({
|
||||
capability: "v8_inspector_observe",
|
||||
roots: ["/tmp/node-app"],
|
||||
executables: [],
|
||||
environment_names: [],
|
||||
origins: ["http://127.0.0.1:9229", "http://127.0.0.1:3000"],
|
||||
network: "loopback",
|
||||
mount: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("can configure a process-capture ceiling without an implicit grant", () => {
|
||||
const result = parseConfig({
|
||||
REA_PROCESS_CAPTURE_ENABLED: "true",
|
||||
@@ -414,6 +445,48 @@ describe("runtime configuration", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("requires an explicit grant for exact-scope browser automation", () => {
|
||||
const environment = {
|
||||
REA_BROWSER_SCENARIO_ENABLED: "true",
|
||||
REA_BROWSER_SCENARIO_EXECUTABLE_ROOTS_JSON: '["/opt/chromium"]',
|
||||
REA_BROWSER_SCENARIO_CDP_ENDPOINTS_JSON: '["http://127.0.0.1:9222"]',
|
||||
REA_BROWSER_SCENARIO_ALLOWED_ORIGINS_JSON: '["https://app.example.test"]',
|
||||
REA_BROWSER_SCENARIO_ALLOWED_ENV_JSON: '["REA_TEST_PASSWORD"]',
|
||||
};
|
||||
const result = parseConfig(environment);
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.browserScenarioPolicy).toEqual({
|
||||
enabled: true,
|
||||
executableRoots: ["/opt/chromium"],
|
||||
cdpEndpoints: ["http://127.0.0.1:9222"],
|
||||
allowedOrigins: ["https://app.example.test"],
|
||||
allowedEnvironment: ["REA_TEST_PASSWORD"],
|
||||
});
|
||||
expect(result.value.permissionCeilings).toContainEqual({
|
||||
capability: "browser_automate",
|
||||
roots: [],
|
||||
executables: ["/opt/chromium"],
|
||||
environment_names: ["REA_TEST_PASSWORD"],
|
||||
origins: ["http://127.0.0.1:9222", "https://app.example.test"],
|
||||
network: "external",
|
||||
mount: false,
|
||||
});
|
||||
expect(result.value.administratorPermissionGrants).not.toContainEqual(
|
||||
expect.objectContaining({ capability: "browser_automate" }),
|
||||
);
|
||||
const automatic = parseConfig({
|
||||
...environment,
|
||||
REA_BROWSER_SCENARIO_AUTO_GRANT: "true",
|
||||
});
|
||||
if (!automatic.ok) throw automatic.error;
|
||||
expect(automatic.value.administratorPermissionGrants).toContainEqual(
|
||||
expect.objectContaining({
|
||||
capability: "browser_automate",
|
||||
lifetime: "administrator",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'["http://localhost:9222"]',
|
||||
'["http://192.168.1.5:9222"]',
|
||||
|
||||
@@ -12,7 +12,9 @@ import { ARTIFACT_TOOL_CONTRACTS } from "../src/contracts/artifactToolContracts.
|
||||
import { MANAGED_TOOL_CONTRACTS } from "../src/contracts/managedToolContracts.js";
|
||||
import { MANAGED_WORKFLOW_TOOL_CONTRACTS } from "../src/contracts/managedWorkflowToolContracts.js";
|
||||
import { BROWSER_TOOL_CONTRACTS } from "../src/contracts/browserToolContracts.js";
|
||||
import { BROWSER_SCENARIO_TOOL_CONTRACTS } from "../src/contracts/browserScenarioToolContracts.js";
|
||||
import { ELECTRON_TOOL_CONTRACTS } from "../src/contracts/electronToolContracts.js";
|
||||
import { JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS } from "../src/contracts/javascriptRuntimeObservationToolContracts.js";
|
||||
import { APPLICATION_TOOL_CONTRACTS } from "../src/contracts/applicationToolContracts.js";
|
||||
import {
|
||||
enhancedOutputSchemas,
|
||||
@@ -119,7 +121,9 @@ describe("tool contract surface", () => {
|
||||
...MANAGED_TOOL_CONTRACTS,
|
||||
...MANAGED_WORKFLOW_TOOL_CONTRACTS,
|
||||
...BROWSER_TOOL_CONTRACTS,
|
||||
...BROWSER_SCENARIO_TOOL_CONTRACTS,
|
||||
...ELECTRON_TOOL_CONTRACTS,
|
||||
...JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS,
|
||||
...APPLICATION_TOOL_CONTRACTS,
|
||||
...SESSION_TOOL_CONTRACTS,
|
||||
].map(({ name }) => name);
|
||||
@@ -214,7 +218,9 @@ describe("tool contract surface", () => {
|
||||
...MANAGED_TOOL_CONTRACTS,
|
||||
...MANAGED_WORKFLOW_TOOL_CONTRACTS,
|
||||
...BROWSER_TOOL_CONTRACTS,
|
||||
...BROWSER_SCENARIO_TOOL_CONTRACTS,
|
||||
...ELECTRON_TOOL_CONTRACTS,
|
||||
...JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS,
|
||||
...APPLICATION_TOOL_CONTRACTS,
|
||||
...SESSION_TOOL_CONTRACTS,
|
||||
];
|
||||
|
||||
@@ -336,28 +336,11 @@ describe("Electron MCP tools", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const denied = await client.callTool({
|
||||
name: "analyze_javascript_application",
|
||||
arguments: { input_path: root, approved: true },
|
||||
});
|
||||
expect(denied).toMatchObject({
|
||||
isError: true,
|
||||
structuredContent: {
|
||||
error: {
|
||||
code: "permission_required",
|
||||
remediation: {
|
||||
action: expect.stringContaining("administrator configuration"),
|
||||
elicitation_supported: false,
|
||||
restart_required: true,
|
||||
},
|
||||
details: {
|
||||
capability: "investigation_input",
|
||||
missing: { roots: [root] },
|
||||
ceiling: expect.objectContaining({ roots: [] }),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(
|
||||
(await client.listTools()).tools.some(
|
||||
({ name }) => name === "analyze_javascript_application",
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
const evidenceFor = (session: BinarySession, value: unknown) => {
|
||||
|
||||
@@ -219,14 +219,10 @@ describe("Ghidra MCP and shared CLI composition", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const unsupported = await mcp.callTool({
|
||||
name: "set_comment",
|
||||
arguments: { address: "0x401000", comment: "not allowed" },
|
||||
});
|
||||
expect(unsupported.isError).toBe(true);
|
||||
expect(unsupported.structuredContent).toMatchObject({
|
||||
error: { code: "capability_unavailable" },
|
||||
});
|
||||
const availableNames = (await mcp.listTools()).tools.map(
|
||||
({ name }) => name,
|
||||
);
|
||||
expect(availableNames).not.toContain("set_comment");
|
||||
expect(calls).not.toContain("set_comment");
|
||||
|
||||
const status = await mcp.callTool({
|
||||
@@ -265,6 +261,10 @@ describe("Ghidra MCP and shared CLI composition", () => {
|
||||
name: "find_xrefs_to_name",
|
||||
available: true,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
name: "set_comment",
|
||||
available: false,
|
||||
}),
|
||||
]),
|
||||
},
|
||||
});
|
||||
@@ -272,7 +272,7 @@ describe("Ghidra MCP and shared CLI composition", () => {
|
||||
await Promise.allSettled([mcp.close(), server.close()]);
|
||||
await session.close();
|
||||
}
|
||||
});
|
||||
}, 10_000);
|
||||
});
|
||||
|
||||
const sessionEvidence = (session: BinarySession, value: unknown) => {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { BinarySession } from "../../src/application/BinarySession.js";
|
||||
import type {
|
||||
AnalysisClient,
|
||||
AnalysisOperationPort,
|
||||
AnalysisProvider,
|
||||
CapabilityDescriptor,
|
||||
} from "../../src/application/AnalysisProvider.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
@@ -47,6 +50,47 @@ const connect = async (analysis: AnalysisOperationPort) => {
|
||||
return client;
|
||||
};
|
||||
|
||||
const providerWithCapabilities = (
|
||||
operations: readonly CapabilityDescriptor["operation"][],
|
||||
): AnalysisProvider => {
|
||||
const identity = { id: "fixture", name: "Fixture", version: "1" };
|
||||
const capabilities: readonly CapabilityDescriptor[] = operations.map(
|
||||
(operation) => ({
|
||||
provider: identity,
|
||||
operation,
|
||||
inputContractVersion: 1,
|
||||
outputContractVersion: 1,
|
||||
available: true,
|
||||
reason: null,
|
||||
pagination: "none",
|
||||
exhaustive: true,
|
||||
effects: {
|
||||
mutatesArtifact: false,
|
||||
launchesProcess: false,
|
||||
mayShowUi: false,
|
||||
mayAccessNetwork: false,
|
||||
mayWriteFilesystem: false,
|
||||
changesPermissions: false,
|
||||
requiresRoot: false,
|
||||
},
|
||||
limits: {
|
||||
maxResults: null,
|
||||
maxPayloadBytes: null,
|
||||
timeoutMs: null,
|
||||
},
|
||||
limitations: [],
|
||||
}),
|
||||
);
|
||||
return {
|
||||
identity: () => identity,
|
||||
capabilities: () => capabilities,
|
||||
createClient: () => ({
|
||||
execute: () => Promise.resolve(ok(null)),
|
||||
close: () => Promise.resolve(),
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
const text = (result: CallToolResult): string => {
|
||||
const content = result.content.find((item) => item.type === "text");
|
||||
if (content?.type !== "text") throw new Error("missing text result");
|
||||
@@ -189,7 +233,7 @@ describe("full MCP integration with multi-tool sequences", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves the complete canonical inventory with a session", async () => {
|
||||
it("advertises the complete currently available inventory with a session", async () => {
|
||||
const session = new BinarySession(
|
||||
(_path) =>
|
||||
({
|
||||
@@ -212,13 +256,32 @@ describe("full MCP integration with multi-tool sequences", () => {
|
||||
await client.connect(clientTransport);
|
||||
|
||||
const listed = await client.listTools();
|
||||
expect(listed.tools).toHaveLength(TOOL_CONTRACTS.length);
|
||||
const names = listed.tools.map((t) => t.name);
|
||||
expect(names).toContain("open_binary");
|
||||
expect(names).toContain("close_binary");
|
||||
expect(names).toContain("binary_session");
|
||||
expect(names).toContain("binary_overview");
|
||||
expect(names).toContain("batch_decompile");
|
||||
expect(names).not.toContain("binary_overview");
|
||||
expect(names).not.toContain("batch_decompile");
|
||||
const status = structured(
|
||||
await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: { detail: "full" },
|
||||
}),
|
||||
);
|
||||
const available = new Set(
|
||||
z
|
||||
.object({
|
||||
result: z.object({
|
||||
tool_availability: z.array(
|
||||
z.object({ name: z.string(), available: z.boolean() }),
|
||||
),
|
||||
}),
|
||||
})
|
||||
.parse(status)
|
||||
.result.tool_availability.filter((item) => item.available)
|
||||
.map(({ name }) => name),
|
||||
);
|
||||
expect(new Set(names)).toEqual(available);
|
||||
|
||||
const contracts = new Map<string, (typeof TOOL_CONTRACTS)[number]>(
|
||||
TOOL_CONTRACTS.map((contract) => [contract.name, contract]),
|
||||
@@ -237,7 +300,7 @@ describe("full MCP integration with multi-tool sequences", () => {
|
||||
);
|
||||
assertDescribedRootObject(tool.outputSchema, `${tool.name}.output`);
|
||||
}
|
||||
});
|
||||
}, 10_000);
|
||||
|
||||
it("records approved trace truncation as a deduplicated residual unknown", async () => {
|
||||
const analysis: AnalysisOperationPort = {
|
||||
@@ -254,11 +317,12 @@ describe("full MCP integration with multi-tool sequences", () => {
|
||||
),
|
||||
};
|
||||
const session = new BinarySession(
|
||||
() =>
|
||||
({
|
||||
execute: () => Promise.resolve(ok(null)),
|
||||
close: () => Promise.resolve(),
|
||||
}) satisfies AnalysisClient,
|
||||
providerWithCapabilities([
|
||||
"list_strings",
|
||||
"list_procedures",
|
||||
"xrefs",
|
||||
"resolve_containing_procedure",
|
||||
]),
|
||||
);
|
||||
const server = createServer(analysis, session);
|
||||
const client = new Client({ name: "unknown-workflow", version: "1.0.0" });
|
||||
@@ -267,6 +331,10 @@ describe("full MCP integration with multi-tool sequences", () => {
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: process.execPath },
|
||||
});
|
||||
|
||||
for (let attempt = 0; attempt < 2; attempt += 1) {
|
||||
const traced = await client.callTool({
|
||||
@@ -310,11 +378,7 @@ describe("full MCP integration with multi-tool sequences", () => {
|
||||
},
|
||||
};
|
||||
const session = new BinarySession(
|
||||
() =>
|
||||
({
|
||||
execute: () => Promise.resolve(ok(null)),
|
||||
close: () => Promise.resolve(),
|
||||
}) satisfies AnalysisClient,
|
||||
providerWithCapabilities(["procedure_pseudo_code"]),
|
||||
);
|
||||
const server = createServer(analysis, session);
|
||||
const client = new Client({ name: "unavailable-unknown", version: "1" });
|
||||
@@ -323,6 +387,10 @@ describe("full MCP integration with multi-tool sequences", () => {
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: process.execPath },
|
||||
});
|
||||
|
||||
const unavailable = await client.callTool({
|
||||
name: "procedure_pseudo_code",
|
||||
|
||||
@@ -32,14 +32,20 @@ describe("production MCP doctor", () => {
|
||||
adapter: "production-stdio",
|
||||
inventory: {
|
||||
tools: {
|
||||
expected: CATALOG_IDENTITY.counts.mcp_tools,
|
||||
observed: CATALOG_IDENTITY.counts.mcp_tools,
|
||||
expected: expect.any(Number),
|
||||
observed: expect.any(Number),
|
||||
missing: [],
|
||||
unexpected: [],
|
||||
},
|
||||
},
|
||||
request_flow: { tool: "binary_session", ok: true },
|
||||
});
|
||||
expect(result.inventory?.tools.expected).toBe(
|
||||
result.inventory?.tools.observed,
|
||||
);
|
||||
expect(result.inventory?.tools.expected).toBeLessThan(
|
||||
CATALOG_IDENTITY.counts.mcp_tools,
|
||||
);
|
||||
}, 30_000);
|
||||
|
||||
it("reports exact missing, unexpected, and duplicate inventory names", () => {
|
||||
|
||||
@@ -18,6 +18,8 @@ import {
|
||||
} from "../src/application/InvestigationProviders.js";
|
||||
import { CDP_BROWSER_PROVIDER_IDENTITY } from "../src/browser/CdpBrowserProvider.js";
|
||||
import { CDP_ELECTRON_PROVIDER_IDENTITY } from "../src/browser/CdpElectronProvider.js";
|
||||
import { PLAYWRIGHT_BROWSER_SCENARIO_PROVIDER_IDENTITY } from "../src/browser/PlaywrightBrowserScenarioProvider.js";
|
||||
import { V8_INSPECTOR_PROVIDER_IDENTITY } from "../src/browser/V8InspectorProvider.js";
|
||||
import { CLI_COMMAND_NAMES } from "../src/cliCommandNames.js";
|
||||
import { createCli } from "../src/cli.js";
|
||||
import { TOOL_CONTRACTS } from "../src/contracts/toolContracts.js";
|
||||
@@ -76,7 +78,9 @@ describe("canonical product catalog", () => {
|
||||
MANAGED_STATIC_PROVIDER,
|
||||
MANAGED_WORKFLOW_PROVIDER,
|
||||
CDP_BROWSER_PROVIDER_IDENTITY,
|
||||
PLAYWRIGHT_BROWSER_SCENARIO_PROVIDER_IDENTITY,
|
||||
CDP_ELECTRON_PROVIDER_IDENTITY,
|
||||
V8_INSPECTOR_PROVIDER_IDENTITY,
|
||||
JAVASCRIPT_APPLICATION_PROVIDER,
|
||||
JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER,
|
||||
JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER,
|
||||
@@ -112,9 +116,12 @@ describe("canonical product catalog", () => {
|
||||
({ id }) => id === JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER.id,
|
||||
)?.capabilities,
|
||||
).toEqual([
|
||||
"build_reconstruction_obligation_ledger",
|
||||
"commit_reconstruction_coverage",
|
||||
"compare_application_versions",
|
||||
"compare_javascript_export_shapes",
|
||||
"compare_source_to_bundle",
|
||||
"evaluate_reconstruction_readiness",
|
||||
"execute_node_characterization",
|
||||
"prepare_node_characterization",
|
||||
"query_reconstruction_coverage",
|
||||
|
||||
@@ -10,7 +10,6 @@ import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
import type { AnalysisClient } from "../src/application/AnalysisProvider.js";
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { PROMPT_CONTRACTS } from "../src/contracts/promptContracts.js";
|
||||
import { TOOL_CONTRACTS } from "../src/contracts/toolContracts.js";
|
||||
import { createEvidence } from "../src/domain/evidence.js";
|
||||
import { createServer } from "../src/server/createServer.js";
|
||||
import { registerGuidedPrompts } from "../src/server/registerPrompts.js";
|
||||
@@ -36,6 +35,7 @@ describe("guided prompts over MCP", () => {
|
||||
const client = await connect(createServer(session, session));
|
||||
resources.push(session);
|
||||
|
||||
const toolsBeforePrompts = (await client.listTools()).tools;
|
||||
const prompts = await client.listPrompts();
|
||||
expect(prompts.prompts.map(({ name }) => name)).toEqual(
|
||||
PROMPT_CONTRACTS.map(({ name }) => name),
|
||||
@@ -56,9 +56,7 @@ describe("guided prompts over MCP", () => {
|
||||
),
|
||||
);
|
||||
}
|
||||
expect((await client.listTools()).tools).toHaveLength(
|
||||
TOOL_CONTRACTS.length,
|
||||
);
|
||||
expect((await client.listTools()).tools).toEqual(toolsBeforePrompts);
|
||||
const result = await client.getPrompt({
|
||||
name: "investigate_feature",
|
||||
arguments: {
|
||||
|
||||
@@ -11,8 +11,9 @@ import { NATIVE_TOOL_CONTRACTS } from "../src/contracts/nativeToolContracts.js";
|
||||
import { ARTIFACT_TOOL_CONTRACTS } from "../src/contracts/artifactToolContracts.js";
|
||||
import { MANAGED_TOOL_CONTRACTS } from "../src/contracts/managedToolContracts.js";
|
||||
import { MANAGED_WORKFLOW_TOOL_CONTRACTS } from "../src/contracts/managedWorkflowToolContracts.js";
|
||||
import { BROWSER_TOOL_CONTRACTS } from "../src/contracts/browserToolContracts.js";
|
||||
import { BROWSER_PROVIDER_TOOL_CONTRACTS } from "../src/contracts/browserProviderToolContracts.js";
|
||||
import { ELECTRON_TOOL_CONTRACTS } from "../src/contracts/electronToolContracts.js";
|
||||
import { JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS } from "../src/contracts/javascriptRuntimeObservationToolContracts.js";
|
||||
import { APPLICATION_TOOL_CONTRACTS } from "../src/contracts/applicationToolContracts.js";
|
||||
import { SUPPORTED_CLIENT_DEFINITIONS } from "../src/application/SupportedClients.js";
|
||||
import { PRODUCT_IDENTITY } from "../src/identity.js";
|
||||
@@ -31,8 +32,9 @@ const expectedToolCounts = [
|
||||
NATIVE_TOOL_CONTRACTS.length,
|
||||
ARTIFACT_TOOL_CONTRACTS.length,
|
||||
MANAGED_TOOL_CONTRACTS.length + MANAGED_WORKFLOW_TOOL_CONTRACTS.length,
|
||||
BROWSER_TOOL_CONTRACTS.length,
|
||||
BROWSER_PROVIDER_TOOL_CONTRACTS.length,
|
||||
ELECTRON_TOOL_CONTRACTS.length,
|
||||
JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS.length,
|
||||
APPLICATION_TOOL_CONTRACTS.length,
|
||||
SESSION_TOOL_CONTRACTS.length,
|
||||
] as const;
|
||||
|
||||
+26
-5
@@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { CATALOG_IDENTITY } from "../src/catalogIdentity.js";
|
||||
|
||||
@@ -11,6 +12,29 @@ const fixturePath = fileURLToPath(
|
||||
new URL("./fixtures/fakeLauncher.mjs", import.meta.url),
|
||||
);
|
||||
|
||||
const expectAvailableToolInventory = async (client: Client): Promise<void> => {
|
||||
const listed = await client.listTools();
|
||||
const status = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: { detail: "full" },
|
||||
});
|
||||
const availability = z
|
||||
.object({
|
||||
result: z.object({
|
||||
tool_availability: z.array(
|
||||
z.object({ name: z.string(), available: z.boolean() }),
|
||||
),
|
||||
}),
|
||||
})
|
||||
.parse(status.structuredContent).result.tool_availability;
|
||||
expect(availability).toHaveLength(CATALOG_IDENTITY.counts.mcp_tools);
|
||||
expect(new Set(listed.tools.map(({ name }) => name))).toEqual(
|
||||
new Set(
|
||||
availability.filter(({ available }) => available).map(({ name }) => name),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
describe("production stdio runtime", () => {
|
||||
it("starts the built entrypoint, lists the catalog, calls one, and shuts down", async () => {
|
||||
const transport = new StdioClientTransport({
|
||||
@@ -33,8 +57,7 @@ describe("production stdio runtime", () => {
|
||||
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const tools = await client.listTools();
|
||||
expect(tools.tools).toHaveLength(CATALOG_IDENTITY.counts.mcp_tools);
|
||||
await expectAvailableToolInventory(client);
|
||||
const result = await client.callTool({
|
||||
name: "current_document",
|
||||
arguments: {},
|
||||
@@ -80,9 +103,7 @@ describe("production stdio runtime", () => {
|
||||
|
||||
try {
|
||||
await client.connect(transport);
|
||||
expect((await client.listTools()).tools).toHaveLength(
|
||||
CATALOG_IDENTITY.counts.mcp_tools,
|
||||
);
|
||||
await expectAvailableToolInventory(client);
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
|
||||
@@ -13,6 +13,48 @@ import { createServer } from "../src/server/createServer.js";
|
||||
import { createServerIdentity } from "../src/serverIdentity.js";
|
||||
import { observed } from "./fixtures/analysisExecution.js";
|
||||
import { buildCapabilityInventory } from "../src/application/CapabilityInventory.js";
|
||||
import type {
|
||||
AnalysisProvider,
|
||||
CapabilityDescriptor,
|
||||
} from "../src/application/AnalysisProvider.js";
|
||||
|
||||
const availabilityProvider = (): AnalysisProvider => {
|
||||
const identity = { id: "fixture", name: "Fixture", version: "1" };
|
||||
const capability: CapabilityDescriptor = {
|
||||
provider: identity,
|
||||
operation: "current_address",
|
||||
inputContractVersion: 1,
|
||||
outputContractVersion: 1,
|
||||
available: true,
|
||||
reason: null,
|
||||
pagination: "none",
|
||||
exhaustive: true,
|
||||
effects: {
|
||||
mutatesArtifact: false,
|
||||
launchesProcess: false,
|
||||
mayShowUi: false,
|
||||
mayAccessNetwork: false,
|
||||
mayWriteFilesystem: false,
|
||||
changesPermissions: false,
|
||||
requiresRoot: false,
|
||||
},
|
||||
limits: {
|
||||
maxResults: null,
|
||||
maxPayloadBytes: null,
|
||||
timeoutMs: null,
|
||||
},
|
||||
limitations: [],
|
||||
};
|
||||
return {
|
||||
identity: () => identity,
|
||||
capabilities: () => [capability],
|
||||
createClient: () => ({
|
||||
health: () => Promise.resolve(),
|
||||
execute: () => Promise.resolve(observed(null)),
|
||||
close: () => Promise.resolve(),
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
describe("server and catalog identity", () => {
|
||||
it("derives package and SDK versions from canonical package metadata", async () => {
|
||||
@@ -26,14 +68,14 @@ describe("server and catalog identity", () => {
|
||||
});
|
||||
expect(PRODUCT_IDENTITY.packageVersion).toBe(packageJson.version);
|
||||
expect(SDK_IDENTITY.server).toBe("2.0.0-beta.4");
|
||||
expect(CLI_COMMAND_NAMES).toHaveLength(59);
|
||||
expect(new Set(CLI_COMMAND_NAMES).size).toBe(59);
|
||||
expect(CLI_COMMAND_NAMES).toHaveLength(66);
|
||||
expect(new Set(CLI_COMMAND_NAMES).size).toBe(66);
|
||||
expect(CATALOG_IDENTITY.counts).toEqual({
|
||||
cli_commands: 59,
|
||||
cli_commands: 66,
|
||||
mcp_tools: TOOL_CONTRACTS.length,
|
||||
mcp_prompts: 6,
|
||||
mcp_resources: 2,
|
||||
mcp_resource_templates: 9,
|
||||
mcp_resource_templates: 11,
|
||||
});
|
||||
expect(CATALOG_IDENTITY.digests.combined_sha256).toMatch(/^[a-f0-9]{64}$/u);
|
||||
});
|
||||
@@ -132,13 +174,16 @@ describe("server and catalog identity", () => {
|
||||
});
|
||||
|
||||
it("exposes live identity, labeled inventories, availability, and list changes", async () => {
|
||||
const session = new BinarySession(() => ({
|
||||
health: () => Promise.resolve(),
|
||||
execute: () => Promise.resolve(observed(null)),
|
||||
close: () => Promise.resolve(),
|
||||
}));
|
||||
const session = new BinarySession(availabilityProvider());
|
||||
const server = createServer(session, session);
|
||||
const client = new Client({ name: "identity-test", version: "9" });
|
||||
const client = new Client(
|
||||
{ name: "identity-test", version: "9" },
|
||||
{
|
||||
capabilities: {
|
||||
elicitation: { form: {} },
|
||||
},
|
||||
},
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
let toolListChanges = 0;
|
||||
@@ -149,7 +194,7 @@ describe("server and catalog identity", () => {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const instructions = client.getInstructions();
|
||||
expect(instructions?.length).toBeLessThanOrEqual(512);
|
||||
expect(instructions?.length).toBeLessThanOrEqual(640);
|
||||
expect(instructions).toContain(
|
||||
"ASAR/JavaScript -> analyze_javascript_application",
|
||||
);
|
||||
@@ -200,6 +245,12 @@ describe("server and catalog identity", () => {
|
||||
name: "capture_process_scenario",
|
||||
available: false,
|
||||
reason: "policy_disabled",
|
||||
client_requirements: {
|
||||
required: [],
|
||||
optional: ["elicitation_form"],
|
||||
missing_required: [],
|
||||
missing_optional: [],
|
||||
},
|
||||
}),
|
||||
expect.objectContaining({
|
||||
name: "inspect_web_page",
|
||||
@@ -216,7 +267,7 @@ describe("server and catalog identity", () => {
|
||||
}),
|
||||
]),
|
||||
client_features: {
|
||||
elicitation_form: false,
|
||||
elicitation_form: true,
|
||||
elicitation_url: false,
|
||||
roots: false,
|
||||
sampling: false,
|
||||
@@ -260,6 +311,12 @@ describe("server and catalog identity", () => {
|
||||
next_cursor: expect.any(Number),
|
||||
has_more: true,
|
||||
},
|
||||
client_features: {
|
||||
elicitation_form: true,
|
||||
elicitation_url: false,
|
||||
roots: false,
|
||||
sampling: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
for (const capabilityFamily of TOOL_KINDS) {
|
||||
@@ -284,8 +341,17 @@ describe("server and catalog identity", () => {
|
||||
},
|
||||
});
|
||||
}
|
||||
await client.callTool({ name: "close_binary", arguments: {} });
|
||||
expect(
|
||||
(await client.listTools()).tools.map(({ name }) => name),
|
||||
).not.toContain("current_address");
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: process.execPath },
|
||||
});
|
||||
await expect.poll(() => toolListChanges).toBeGreaterThan(0);
|
||||
expect(
|
||||
(await client.listTools()).tools.map(({ name }) => name),
|
||||
).toContain("current_address");
|
||||
} finally {
|
||||
await Promise.allSettled([
|
||||
client.close(),
|
||||
@@ -293,5 +359,5 @@ describe("server and catalog identity", () => {
|
||||
session.close(),
|
||||
]);
|
||||
}
|
||||
});
|
||||
}, 10_000);
|
||||
});
|
||||
|
||||
+54
-28
@@ -9,8 +9,11 @@ import { z } from "zod";
|
||||
import { createTestTempDirectory } from "./fixtures/temporaryDirectory.js";
|
||||
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { TOOL_CONTRACTS } from "../src/contracts/toolContracts.js";
|
||||
import type { AnalysisClient } from "../src/application/AnalysisProvider.js";
|
||||
import type {
|
||||
AnalysisClient,
|
||||
AnalysisProvider,
|
||||
CapabilityDescriptor,
|
||||
} from "../src/application/AnalysisProvider.js";
|
||||
import { probeProcessCaptureCapability } from "../src/application/ProcessHarness.js";
|
||||
import { observed as ok } from "./fixtures/analysisExecution.js";
|
||||
import { createServer } from "../src/server/createServer.js";
|
||||
@@ -47,7 +50,7 @@ describe("target-free MCP lifecycle", () => {
|
||||
const targetPath = join(directory, "mutable.hop");
|
||||
await writeFile(targetPath, "first");
|
||||
const closed: string[] = [];
|
||||
const session = new BinarySession((target) => client(target.path, closed), {
|
||||
const session = new BinarySession(provider(closed), {
|
||||
resolveAnalysisProfile: () =>
|
||||
Promise.resolve(
|
||||
resultOk({ profile: SNAPSHOT_PROFILE, compatibility: {} }),
|
||||
@@ -106,7 +109,7 @@ describe("target-free MCP lifecycle", () => {
|
||||
await writeFile(first, "one");
|
||||
await writeFile(second, "two");
|
||||
const closed: string[] = [];
|
||||
const session = new BinarySession((target) => client(target.path, closed), {
|
||||
const session = new BinarySession(provider(closed), {
|
||||
resolveAnalysisProfile: () =>
|
||||
Promise.resolve(
|
||||
resultOk({ profile: SNAPSHOT_PROFILE, compatibility: {} }),
|
||||
@@ -140,34 +143,23 @@ describe("target-free MCP lifecycle", () => {
|
||||
await server.connect(serverTransport);
|
||||
await mcp.connect(clientTransport);
|
||||
|
||||
const before = await mcp.callTool({
|
||||
name: "current_document",
|
||||
arguments: {},
|
||||
});
|
||||
expect(before.isError).toBe(true);
|
||||
expect(text(before)).toBe(JSON.stringify(before.structuredContent));
|
||||
expect((await mcp.listTools()).tools).toHaveLength(TOOL_CONTRACTS.length);
|
||||
const deniedCapture = await mcp.callTool({
|
||||
name: "capture_process_scenario",
|
||||
arguments: {
|
||||
approved: true,
|
||||
executable: "/bin/sh",
|
||||
working_directory: "/tmp",
|
||||
},
|
||||
});
|
||||
expect(deniedCapture.isError).toBe(true);
|
||||
expect(structured(deniedCapture)).toMatchObject({
|
||||
error: {
|
||||
category: "permission_required",
|
||||
},
|
||||
});
|
||||
expect(text(deniedCapture)).toBe(
|
||||
JSON.stringify(deniedCapture.structuredContent),
|
||||
);
|
||||
const beforeNames = (await mcp.listTools()).tools.map(({ name }) => name);
|
||||
expect(beforeNames).toContain("open_binary");
|
||||
expect(beforeNames).toContain("binary_session");
|
||||
expect(beforeNames).not.toContain("current_document");
|
||||
expect(beforeNames).not.toContain("capture_process_scenario");
|
||||
expect(
|
||||
(await mcp.callTool({ name: "open_binary", arguments: { path: first } }))
|
||||
.isError,
|
||||
).not.toBe(true);
|
||||
expect(
|
||||
structured(
|
||||
await mcp.callTool({
|
||||
name: "binary_session",
|
||||
arguments: { detail: "full" },
|
||||
}),
|
||||
),
|
||||
).toMatchObject({ result: { path: await realpath(first) } });
|
||||
expect(
|
||||
text(await mcp.callTool({ name: "current_document", arguments: {} })),
|
||||
).toContain("first.hop");
|
||||
@@ -391,6 +383,40 @@ const client = (path: string, closed: string[]): AnalysisClient => ({
|
||||
},
|
||||
});
|
||||
|
||||
const provider = (closed: string[]): AnalysisProvider => {
|
||||
const identity = { id: "fixture", name: "Fixture", version: "1" };
|
||||
const capability: CapabilityDescriptor = {
|
||||
provider: identity,
|
||||
operation: "current_document",
|
||||
inputContractVersion: 1,
|
||||
outputContractVersion: 1,
|
||||
available: true,
|
||||
reason: null,
|
||||
pagination: "none",
|
||||
exhaustive: true,
|
||||
effects: {
|
||||
mutatesArtifact: false,
|
||||
launchesProcess: false,
|
||||
mayShowUi: false,
|
||||
mayAccessNetwork: false,
|
||||
mayWriteFilesystem: false,
|
||||
changesPermissions: false,
|
||||
requiresRoot: false,
|
||||
},
|
||||
limits: {
|
||||
maxResults: null,
|
||||
maxPayloadBytes: null,
|
||||
timeoutMs: null,
|
||||
},
|
||||
limitations: [],
|
||||
};
|
||||
return {
|
||||
identity: () => identity,
|
||||
capabilities: () => [capability],
|
||||
createClient: (target) => client(target.path, closed),
|
||||
};
|
||||
};
|
||||
|
||||
const text = (result: CallToolResult): string => {
|
||||
const content = result.content.find((item) => item.type === "text");
|
||||
if (content?.type !== "text") throw new Error("missing text result");
|
||||
|
||||
@@ -16,10 +16,14 @@ import { APPLICATION_TOOL_CONTRACTS } from "../src/contracts/applicationToolCont
|
||||
|
||||
describe("tool contract inventory", () => {
|
||||
it("publishes the canonical analysis and session tool inventory", () => {
|
||||
expect(OFFICIAL_TOOL_CONTRACTS).toHaveLength(34);
|
||||
expect(ENHANCED_TOOL_CONTRACTS).toHaveLength(10);
|
||||
expect(OFFICIAL_TOOL_CONTRACTS).toHaveLength(36);
|
||||
expect(ENHANCED_TOOL_CONTRACTS).toHaveLength(12);
|
||||
expect(NATIVE_TOOL_CONTRACTS).toHaveLength(5);
|
||||
expect(ARTIFACT_TOOL_CONTRACTS).toHaveLength(2);
|
||||
expect(ARTIFACT_TOOL_CONTRACTS.map(({ name }) => name)).toEqual([
|
||||
"inventory_artifact",
|
||||
"inspect_artifact",
|
||||
"extract_artifact",
|
||||
]);
|
||||
expect(MANAGED_TOOL_CONTRACTS.map(({ name }) => name)).toEqual([
|
||||
"inspect_managed_artifact",
|
||||
"inspect_managed_members",
|
||||
@@ -52,10 +56,13 @@ describe("tool contract inventory", () => {
|
||||
"trace_application_feature",
|
||||
"trace_javascript_semantics",
|
||||
"compare_application_versions",
|
||||
"compare_source_to_bundle",
|
||||
"compare_javascript_export_shapes",
|
||||
"run_controlled_replay",
|
||||
"prepare_node_characterization",
|
||||
"execute_node_characterization",
|
||||
"build_reconstruction_obligation_ledger",
|
||||
"evaluate_reconstruction_readiness",
|
||||
"commit_reconstruction_coverage",
|
||||
"query_reconstruction_coverage",
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user