fix(mcp): clarify routing and advertise input examples

This commit is contained in:
morluto
2026-07-29 07:18:09 +00:00
parent 222ce83967
commit 969519c00f
13 changed files with 77 additions and 23 deletions
+4
View File
@@ -20,6 +20,10 @@ also requires the agent to keep observations, inferences, and unknowns
distinct. Requested prompt arguments and completion choices are rendered as
untrusted selection data, not instructions or authorization.
For target paths in `compare_application_versions`, the rendered workflow
opens each target before calling `inventory_artifact`; artifact inventory and
inspection operate on the active target and do not accept a path themselves.
Use standard MCP discovery and retrieval:
```json
+3 -3
View File
@@ -668,10 +668,10 @@
"mcp_resource_templates": 11
},
"digests": {
"tools_sha256": "5a88bf598a1e0fe705761db6af92f1ceabaf026cb6efa425e87b9633f1d7a3de",
"prompts_sha256": "f6da3ad38a1000c11364d1710f122ac4990551f04efd8c53ffb2e819b5cf5707",
"tools_sha256": "092dd59990f61b1011ac0cd4f5b8d6a3e4a2cf7ade49c86892963c87b71dc65b",
"prompts_sha256": "2dd61fd4e29657e7faf739ef67be7b1f637ddf446e7d73acc0d2fd1d9f06b43e",
"resources_sha256": "339a984ea8cd8be5f234adf24395bf0295258d990492005cf6fe1f293d12cd46",
"combined_sha256": "861cd8618e793342daa8b149bc2944360d84b077fd19cf22f6e0a57b6b249c73",
"combined_sha256": "461b4dbea03ef60d637f4b74debca4dbea0e1dd423d7d9c9a631e62204528c05",
"providers_sha256": "918ccd6b8ae442cd5844dcfde55086f458176241c8d166c1e9dd0f242ccd2bb0"
}
}
+9 -2
View File
@@ -4,7 +4,7 @@ description: Reverse engineer native, managed, Electron/JavaScript, packaged, an
metadata:
version: "23"
tool_count: 111
catalog_digest: "861cd8618e793342daa8b149bc2944360d84b077fd19cf22f6e0a57b6b249c73"
catalog_digest: "461b4dbea03ef60d637f4b74debca4dbea0e1dd423d7d9c9a631e62204528c05"
---
# REA
@@ -23,7 +23,8 @@ Choose the first tool from the target the user supplied. Do not call
- ASAR or extracted JavaScript/Electron tree:
`analyze_javascript_application`.
- Archive, application package, ZIP/APK/IPA/MSIX/AppX, or DMG:
`inventory_artifact`.
`open_binary` with the supplied local path, then `inspect_artifact` or
`inventory_artifact` (both operate on the active target and accept no path).
- Managed PE/CLI assembly: `inspect_managed_artifact`.
- User-owned browser page already open: `list_browser_targets`.
- User-owned Electron runtime already open: `list_electron_targets`.
@@ -34,6 +35,12 @@ If the app is missing, ask which app to inspect. Resolve a human-readable app
name to one clear installed artifact when possible; ask only when matches are
ambiguous. Never choose an example app on the user's behalf.
In a target-free session, use `open_binary` to bind any archive/package or
native target whose analysis tool operates on the active target. Do not call a
tool hidden from `tools/list`; inspect `binary_session` with
`detail: "capabilities"` for the exact remediation when a desired capability
is unavailable.
## Work summary-first
Start with the default summary projection. Do not repeat an identical tool call.
+8 -3
View File
@@ -1,3 +1,4 @@
import { isAbsolute } from "node:path";
import { z } from "zod";
import type { ToolContract } from "./toolContracts.js";
@@ -59,7 +60,11 @@ export const artifactInventoryInputSchema = z
/** Exact caller boundary for approved artifact extraction. */
export const artifactExtractionInputSchema = z.object({
approved: z.literal(true),
output_root: z.string().min(1).max(4_096),
output_root: z
.string()
.min(1)
.max(4_096)
.refine(isAbsolute, "Extraction output root must be absolute"),
occurrence_ids: z
.array(z.string().regex(/^occ_[a-f0-9]{64}$/u))
.min(1)
@@ -130,12 +135,12 @@ const artifact = <Name extends string>(
export const ARTIFACT_TOOL_CONTRACTS = [
artifact(
"inventory_artifact",
"Inventory the active application or package as a deterministic, content-addressed artifact graph. Returns bounded node and edge pages without extracting or mounting by default.",
"After open_binary binds a local archive, application package, or other artifact—or when one is already active—inventory it as a deterministic, content-addressed artifact graph. This tool accepts no path; in a target-free session open the target first. Returns bounded node and edge pages without extracting or mounting by default.",
artifactInventoryInputSchema,
),
artifact(
"inspect_artifact",
"Inspect the active artifact through one bounded, cancellable inventory substep. Returns the full substep Evidence and its ID, observations, derived relationships, hypotheses, contradictions, unexplored branches, limitations, and format-specific next probes. Any substep failure fails the whole call.",
"After open_binary binds a local archive, application package, or other artifact—or when one is already active—inspect it through one bounded, cancellable inventory substep. This tool accepts no path; in a target-free session open the target first. Returns the full substep Evidence and its ID, observations, derived relationships, hypotheses, contradictions, unexplored branches, limitations, and format-specific next probes. Any substep failure fails the whole call.",
artifactInspectionInputSchema,
),
artifact(
+2 -2
View File
@@ -184,9 +184,9 @@ export const PROMPT_CONTRACTS = [
},
steps: [
{
tools: ["inventory_artifact"],
tools: ["open_binary", "inventory_artifact"],
instruction:
"Inventory each target independently before extraction. Follow nodes, occurrences, and edges to completion and retain every Evidence page for each manifest.",
"For each supplied target path, open that target before inventory because inventory_artifact uses the active target and accepts no path. Follow nodes, occurrences, and edges to completion and retain every Evidence page for each manifest.",
},
{
tools: [
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -29,7 +29,7 @@ import {
import { installDynamicToolAvailability } from "./DynamicToolAvailability.js";
const TARGET_FREE_INSTRUCTIONS =
"REA analyzes shipped artifacts. Route: ASAR/JavaScript -> analyze_javascript_application (configured root); archive/package -> inspect_artifact; managed PE/CLI -> inspect_managed_artifact; passive browser/Electron -> list_browser_targets/list_electron_targets; approved browser interaction -> capture_browser_scenario; Node/Electron Inspector -> list_javascript_runtime_targets; native binary/database -> open_binary, then binary_overview. Check binary_session policy. Start with summaries and cite Evidence IDs. Never repeat identical analysis or read full Evidence without need.";
"ASAR/JavaScript -> analyze_javascript_application; archive/package -> open_binary(path), then inspect_artifact/inventory_artifact (active target); managed PE/CLI -> inspect_managed_artifact; passive browser/Electron -> list_browser_targets/list_electron_targets; approved browser interaction -> capture_browser_scenario; Node/Electron Inspector -> list_javascript_runtime_targets; native binary/database -> open_binary, then binary_overview. Start with binary_session; call only tools in tools/list. Hidden routes: binary_session detail=capabilities. Use summaries, cite Evidence IDs. Never repeat identical analysis or read full Evidence.";
const ACTIVE_TARGET_INSTRUCTIONS =
"REA analyzes the active reverse-engineering target. Start native analysis with binary_overview, then narrow with analyze_function, literal search, callers, callees, and xrefs. Prefer summary views, never repeat an identical call, and read full Evidence only when the task requires it.";
+1 -1
View File
@@ -184,7 +184,7 @@ const recommendedActions = (
: []),
...(!open
? [
"Route the supplied target directly: ASAR/JavaScript to analyze_javascript_application, unfamiliar packages to inspect_artifact, managed PE/CLI to inspect_managed_artifact, browser/Electron runtimes to their list-target tools, and native binaries to open_binary.",
"For a supplied target, route by format: ASAR/JavaScript to analyze_javascript_application; archive/package to open_binary(path), then inspect_artifact or inventory_artifact on the active target; managed PE/CLI to inspect_managed_artifact; browser/Electron runtimes to their list-target tools; native binaries to open_binary.",
]
: [
"Continue from the active target with binary_overview or a bounded target-specific query.",
+11 -8
View File
@@ -15,7 +15,7 @@ const ADVERTISED_OUTPUT_SCHEMAS = new WeakMap<
export const toolRegistrationOptions = (contract: ToolContract) => ({
title: contract.title,
description: contract.description,
inputSchema: advertisedInputSchema(contract.inputSchema),
inputSchema: advertisedInputSchema(contract),
outputSchema: advertisedOutputSchema(contract.outputSchema),
annotations: contract.annotations,
});
@@ -25,14 +25,14 @@ export const toolRegistrationOptions = (contract: ToolContract) => ({
* The SDK otherwise converts validation failures to text-only JSON-RPC errors
* before REA can return its stable structured error envelope.
*/
const advertisedInputSchema = (schema: z.ZodObject) => ({
const advertisedInputSchema = (contract: ToolContract) => ({
"~standard": {
version: 1 as const,
vendor: "rea",
validate: (input: unknown) => ({ value: input }),
jsonSchema: {
input: () => advertisedInputJsonSchema(schema),
output: () => advertisedInputJsonSchema(schema),
input: () => advertisedInputJsonSchema(contract),
output: () => advertisedInputJsonSchema(contract),
},
},
});
@@ -56,11 +56,14 @@ const advertisedOutputSchema = (schema: z.ZodObject) => {
};
const advertisedInputJsonSchema = (
schema: z.ZodObject,
contract: ToolContract,
): Readonly<Record<string, unknown>> =>
cachedJsonSchema(ADVERTISED_INPUT_SCHEMAS, schema, () =>
describeProperties(closeObjectSchemas(inputJsonSchema(schema))),
);
cachedJsonSchema(ADVERTISED_INPUT_SCHEMAS, contract.inputSchema, () => ({
...describeProperties(
closeObjectSchemas(inputJsonSchema(contract.inputSchema)),
),
examples: contract.examples.map(({ input }) => input),
}));
const advertisedOutputJsonSchema = (
schema: z.ZodObject,
+22
View File
@@ -102,6 +102,28 @@ describe("tool contract surface", () => {
});
});
it("advertises the validated contract examples on the MCP input schema", () => {
for (const name of [
"record_unknown",
"run_replay_machine",
"build_reconstruction_obligation_ledger",
]) {
const contract = TOOL_CONTRACTS.find(
(candidate) => candidate.name === name,
);
expect(contract).toBeDefined();
if (contract === undefined) continue;
const schema =
toolRegistrationOptions(contract).inputSchema[
"~standard"
].jsonSchema.input();
expect(schema.examples).toEqual(
contract.examples.map(({ input }) => input),
);
}
});
it("advertises complete typed schemas and annotations for every public tool", () => {
const contracts = TOOL_CONTRACTS;
for (const contract of contracts) {
@@ -129,6 +129,7 @@ const assertDescribedStrictObjects = (
path = "$",
): void => {
for (const [key, value] of objectEntries(schema)) {
if (key === "examples") continue;
if (key === "properties") {
const properties = objectEntries(value);
for (const [property, propertySchema] of properties) {
+3 -1
View File
@@ -284,7 +284,9 @@ describe("server and catalog identity", () => {
open: false,
target: null,
alignment: { state: "mcp_server_restart_required" },
recommended_actions: expect.any(Array),
recommended_actions: expect.arrayContaining([
"For a supplied target, route by format: ASAR/JavaScript to analyze_javascript_application; archive/package to open_binary(path), then inspect_artifact or inventory_artifact on the active target; managed PE/CLI to inspect_managed_artifact; browser/Electron runtimes to their list-target tools; native binaries to open_binary.",
]),
},
});
expect(JSON.stringify(summary.structuredContent)).not.toContain(
+11 -1
View File
@@ -145,7 +145,17 @@ describe("target-free MCP lifecycle", () => {
await server.connect(serverTransport);
await mcp.connect(clientTransport);
const beforeNames = (await mcp.listTools()).tools.map(({ name }) => name);
const beforeTools = (await mcp.listTools()).tools;
const beforeNames = beforeTools.map(({ name }) => name);
expect(mcp.getInstructions()).toContain(
"archive/package -> open_binary(path), then inspect_artifact/inventory_artifact (active target)",
);
expect(
beforeTools.find(({ name }) => name === "inventory_artifact")
?.description,
).toContain(
"This tool accepts no path; in a target-free session open the target first.",
);
expect(beforeNames).toContain("open_binary");
expect(beforeNames).toContain("binary_session");
expect(beforeNames).not.toContain("current_document");