feat(server): advertise available tools dynamically

This commit is contained in:
morluto
2026-07-24 13:18:58 +00:00
parent 38ff7418ef
commit 035e1144b0
50 changed files with 1433 additions and 311 deletions
+104
View File
@@ -1,10 +1,13 @@
import { applicationVersionComparisonResultSchema } from "../domain/javascriptApplicationVersionComparisonSchemas.js";
import { z } from "zod";
import { applicationFeatureTraceResultSchema } from "../domain/javascriptFeatureTraceSchemas.js";
import { javaScriptSemanticTraceResultSchema } from "../domain/javascriptSemanticTraceSchemas.js";
import { javaScriptExportShapeComparisonResultSchema } from "../domain/javascriptExportShapeComparisonSchemas.js";
import { sourceToBundleComparisonResultSchema } from "../domain/sourceToBundleComparisonSchemas.js";
import {
compareApplicationVersionsRequestSchema,
compareJavaScriptExportShapesRequestSchema,
compareSourceToBundleRequestSchema,
traceApplicationFeatureRequestSchema,
traceJavaScriptSemanticsRequestSchema,
} from "./applicationWorkflowInputContracts.js";
@@ -24,6 +27,14 @@ import {
reconstructionCoverageQueryInputSchema,
} from "../application/ReconstructionCoverageService.js";
import { reconstructionClosureResultSchema } from "../domain/reconstructionCoverage.js";
import {
reconstructionObligationLedgerInputSchema,
reconstructionObligationLedgerPageSchema,
} from "../domain/reconstructionObligationLedgerSchemas.js";
import {
reconstructionReadinessInputSchema,
reconstructionReadinessReportSchema,
} from "../domain/reconstructionReadinessSchemas.js";
import { jsonObjectSchema } from "../domain/jsonValue.js";
import type { ToolContract } from "./toolContracts.js";
import { toolContractMetadata } from "./toolEffects.js";
@@ -32,7 +43,9 @@ import {
JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE,
JAVASCRIPT_EXPORT_SHAPE_COMPARISON_EXAMPLE,
JAVASCRIPT_FEATURE_TRACE_EXAMPLE,
SOURCE_TO_BUNDLE_COMPARISON_EXAMPLE,
} from "./javascriptApplicationWorkflowExamples.js";
import { RECONSTRUCTION_READINESS_EXAMPLE } from "./reconstructionReadinessExample.js";
const traceOutputSchema = evidenceResultOf(applicationFeatureTraceResultSchema);
const semanticTraceOutputSchema = evidenceResultOf(
@@ -41,9 +54,35 @@ const semanticTraceOutputSchema = evidenceResultOf(
const comparisonOutputSchema = evidenceResultOf(
applicationVersionComparisonResultSchema,
);
const sourceToBundleOutputSchema = evidenceResultOf(
sourceToBundleComparisonResultSchema,
);
const exportShapeComparisonOutputSchema = evidenceResultOf(
javaScriptExportShapeComparisonResultSchema,
);
const reconstructionObligationLedgerOutputSchema = evidenceResultOf(
reconstructionObligationLedgerPageSchema,
);
const reconstructionReadinessOutputSchema = evidenceResultOf(
reconstructionReadinessReportSchema
.pick({
schema: true,
schema_version: true,
report_id: true,
source_digest: true,
report_digest: true,
status: true,
summary: true,
metrics: true,
})
.extend({
report_resource_uri: z
.string()
.regex(
/^rea:\/\/evidence\/ev_[a-f0-9]{64}\/reconstruction-readiness-report$/u,
),
}),
);
const HASH = "0".repeat(64);
const NODE_PREPARATION_EXAMPLE = jsonObjectSchema.parse({
preparation_approved: true,
@@ -162,6 +201,22 @@ export const APPLICATION_TOOL_CONTRACTS = [
},
],
},
{
name: "compare_source_to_bundle",
...toolContractMetadata("compare_source_to_bundle"),
description:
"Compare a cryptographically committed HistoricalSourceGraph/v1 with authenticated JavaScript Application Graph Evidence supplied directly or by session Evidence ID. Uses explicit exact-digest, source-map path, current-path, suffix, and basename signals with stable weights. Classifies unchanged, modified, removed, split, merged, duplicated, and unknown; incomplete coverage and ambiguous weak signals never become absence or forced matches.",
kind: "application",
inputSchema: compareSourceToBundleRequestSchema,
outputSchema: sourceToBundleOutputSchema,
examples: [
{
title:
"Compare committed historical source with a shipped bundle graph",
input: SOURCE_TO_BUNDLE_COMPARISON_EXAMPLE,
},
],
},
{
name: "compare_javascript_export_shapes",
...toolContractMetadata("compare_javascript_export_shapes"),
@@ -264,6 +319,55 @@ export const APPLICATION_TOOL_CONTRACTS = [
},
],
},
{
name: "build_reconstruction_obligation_ledger",
...toolContractMetadata("build_reconstruction_obligation_ledger"),
description:
"Generate one deterministic page of a ReconstructionObligationLedger/v1 from an authenticated Evidence v2 bundle, reviewed obligations, and an explicit reconstruction manifest. Static candidates remain candidates; duplicate ownership, missing original or reconstruction cases, missing parser/type, weak verifier authority, unenumerated claims, contradictions, dependencies, and residual unknowns fail closed. Every page carries the same full-ledger closure digest and typed per-obligation diagnostics.",
kind: "application",
inputSchema: reconstructionObligationLedgerInputSchema,
outputSchema: reconstructionObligationLedgerOutputSchema,
examples: [
{
title: "Generate the first obligation-ledger page",
input: {
evidence_bundle: {
bundle_version: 2,
artifacts: [],
providers: [],
environments: [],
scenarios: [],
captures: [],
unknowns: [],
records: [],
},
reviewed_obligations: [],
manifest: {
schema_version: 1,
bindings: [],
contradictions: [],
},
limits: { max_obligations: 1_000 },
page: { offset: 0, limit: 50 },
},
},
],
},
{
name: "evaluate_reconstruction_readiness",
...toolContractMetadata("evaluate_reconstruction_readiness"),
description:
"Evaluate the fixed nine-stage public reconstruction journey into a deterministic ReconstructionReadinessReport/v1. Exact capability limits, provider routing, CLI/MCP status parity, bounded authority, partial-order comparison, contradictions, obligation closure, cleanup, and replay digests fail closed. Aggregate pass is emitted only when every required stage and check passes with attributable Evidence.",
kind: "application",
inputSchema: reconstructionReadinessInputSchema,
outputSchema: reconstructionReadinessOutputSchema,
examples: [
{
title: "Evaluate the complete synthetic reconstruction journey",
input: RECONSTRUCTION_READINESS_EXAMPLE,
},
],
},
{
name: "commit_reconstruction_coverage",
...toolContractMetadata("commit_reconstruction_coverage"),
+4
View File
@@ -18,6 +18,8 @@ export const TOOL_EXAMPLE_OVERRIDES: Readonly<
procedure_callers: { procedure: "main" },
procedure_info: { procedure: "main" },
read_function_instructions: { procedure: "main" },
read_bytes: { address: "0x1000", length: 16 },
address_to_file_offset: { address: "0x1000" },
procedure_references: { procedure: "main" },
procedure_pseudo_code: { procedure: "main" },
resolve_containing_procedure: { address: "0x1000" },
@@ -34,6 +36,8 @@ export const TOOL_EXAMPLE_OVERRIDES: Readonly<
find_xrefs_to_name: { name: "malloc" },
analyze_function: { procedure: "main" },
trace_feature: { query: "license" },
find_code_for_string: { query: "authorization failed" },
trace_call_path: { start: "0x1000", goal: "0x1100" },
open_binary: { path: "/tmp/fixture" },
import_evidence_bundle: { path: "evidence.json" },
capture_process_scenario: {
+1
View File
@@ -26,6 +26,7 @@ export const TOOL_KINDS = [
"managed-provider",
"browser-provider",
"electron-provider",
"runtime-provider",
"application",
"session",
] as const;
+21 -21
View File
@@ -27,8 +27,9 @@ import { NATIVE_TOOL_CONTRACTS } from "./nativeToolContracts.js";
import { ARTIFACT_TOOL_CONTRACTS } from "./artifactToolContracts.js";
import { MANAGED_TOOL_CONTRACTS } from "./managedToolContracts.js";
import { MANAGED_WORKFLOW_TOOL_CONTRACTS } from "./managedWorkflowToolContracts.js";
import { BROWSER_TOOL_CONTRACTS } from "./browserToolContracts.js";
import { BROWSER_PROVIDER_TOOL_CONTRACTS } from "./browserProviderToolContracts.js";
import { ELECTRON_TOOL_CONTRACTS } from "./electronToolContracts.js";
import { JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS } from "./javascriptRuntimeObservationToolContracts.js";
import { APPLICATION_TOOL_CONTRACTS } from "./applicationToolContracts.js";
import {
closeBinaryInputSchema,
@@ -38,6 +39,8 @@ import type { ToolContract, ToolExample } from "./toolContractTypes.js";
import { toolContractMetadata } from "./toolEffects.js";
import { binarySessionInputSchema } from "./sessionStatusContract.js";
import { functionInstructionInputSchema } from "./functionInstructionContract.js";
import { HOPPER_MEMORY_TOOL_DEFINITIONS } from "./hopperMemoryContracts.js";
import { analysisSearchInput } from "./analysisSearchContract.js";
export { binarySessionInputSchema } from "./sessionStatusContract.js";
@@ -51,27 +54,10 @@ const address = z
);
const optionalAddress = address.optional();
const procedure = z.string().describe("The procedure name or address");
const searchPattern = z
.string()
.min(1)
.max(256)
.describe("The literal text or bounded regex pattern to search for");
const caseSensitive = z
.boolean()
.default(false)
.describe("Whether to match case");
const pagination = {
offset: z.number().int().min(0).default(0),
limit: z.number().int().min(1).max(500).default(100),
};
const searchInput = {
pattern: searchPattern,
mode: z.enum(["literal", "regex"]).default("literal"),
case_sensitive: caseSensitive,
offset: z.number().int().min(0).default(0),
limit: z.number().int().min(1).max(100).default(100),
document,
};
const exampleInputSchema = z.record(z.string(), jsonValueSchema);
const examplesFor = (
@@ -246,6 +232,9 @@ export const OFFICIAL_TOOL_CONTRACTS = [
"Read one offset-paginated window of raw instructions for an analyzed procedure without decompilation, caller discovery, or whole-program string/name scans. Use this fast path for instruction-level orientation; follow next_offset when truncated.",
functionInstructionInputSchema,
),
...HOPPER_MEMORY_TOOL_DEFINITIONS.map(({ name, description, inputSchema }) =>
official(name, description, inputSchema),
),
official(
"procedure_references",
"Return a bounded set of raw incoming or outgoing reference edges for one procedure. Endpoint procedures are resolved only from provider containment; Ghidra preserves observed reference kinds while providers without kind authority mark them unavailable.",
@@ -271,12 +260,12 @@ export const OFFICIAL_TOOL_CONTRACTS = [
official(
"search_procedures",
"Search analyzed procedure names using literal matching by default or regex opt-in. Providers bound search work and reject regex constructs, paths, candidates, or cumulative work outside their finite budgets. Results are deterministic and offset-paginated.",
z.object(searchInput),
z.object(analysisSearchInput),
),
official(
"search_strings",
"Search analyzed strings using literal matching by default or regex opt-in. Providers bound search work and reject regex constructs, paths, candidates, or cumulative work outside their finite budgets. Results are deterministic, offset-paginated, and explicitly truncated.",
z.object(searchInput),
z.object(analysisSearchInput),
),
official(
"set_address_name",
@@ -375,6 +364,16 @@ export const ENHANCED_TOOL_CONTRACTS = [
"Trace a bounded literal feature query through matching strings and procedures, xrefs, and truthful containing-procedure resolution. Returns the operation budget, truncation, and residual unknowns; unknown_registry_approved: true records them durably without inferring reference kinds.",
enhancedInputSchemas.trace_feature,
),
enhanced(
"find_code_for_string",
"Resolve one literal string query to bounded analyzed string entries, xrefs, and truthful containing-procedure candidates. Returns an Evidence ID, exact operation budget, truncation, and residual unknowns; it never infers reference kinds or runtime reachability.",
enhancedInputSchemas.find_code_for_string,
),
enhanced(
"trace_call_path",
"Trace a deterministic bounded caller or callee path from one exact procedure address, optionally stopping at a goal. Returns visited nodes, direct-call edges, one shortest traversal path, failures, frontier, consumed limits, an Evidence ID, and explicit residual unknowns without claiming unresolved indirect calls are absent.",
enhancedInputSchemas.trace_call_path,
),
] as const satisfies readonly ToolContract[];
/** Session-owned Evidence bundle export options. */
@@ -521,8 +520,9 @@ export const TOOL_CONTRACTS = [
...ARTIFACT_TOOL_CONTRACTS,
...MANAGED_TOOL_CONTRACTS,
...MANAGED_WORKFLOW_TOOL_CONTRACTS,
...BROWSER_TOOL_CONTRACTS,
...BROWSER_PROVIDER_TOOL_CONTRACTS,
...ELECTRON_TOOL_CONTRACTS,
...JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS,
...APPLICATION_TOOL_CONTRACTS,
...SESSION_TOOL_CONTRACTS,
] as const;
+20
View File
@@ -61,6 +61,8 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
procedure_callers: evidence,
procedure_info: evidence,
read_function_instructions: evidence,
read_bytes: evidence,
address_to_file_offset: evidence,
procedure_references: evidence,
procedure_pseudo_code: evidence,
resolve_containing_procedure: evidence,
@@ -88,12 +90,15 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
binary_overview: evidence,
analyze_function: evidence,
trace_feature: effects({ mutatesSession: true, idempotent: false }),
find_code_for_string: effects({ mutatesSession: true, idempotent: false }),
trace_call_path: effects({ mutatesSession: true, idempotent: false }),
inspect_macho: nativeEvidence,
inspect_signature: nativeEvidence,
inspect_plist: nativeEvidence,
list_architectures: nativeEvidence,
demangle_swift: nativeEvidence,
inventory_artifact: evidence,
inspect_artifact: evidence,
extract_artifact: effects({ mutatesSession: true, writesFilesystem: true }),
inspect_managed_artifact: evidence,
inspect_managed_members: evidence,
@@ -111,14 +116,29 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
compare_web_captures: browserEvidence,
capture_web_screenshot: browserEvidence,
compare_web_screenshots: browserEvidence,
capture_browser_scenario: effects({
mutatesTarget: true,
mutatesSession: true,
writesFilesystem: true,
launchesProcess: true,
accessesNetwork: true,
changesUiState: true,
mayDiscardData: true,
idempotent: false,
}),
list_electron_targets: browserEvidence,
inspect_electron_page: browserEvidence,
list_javascript_runtime_targets: browserEvidence,
observe_javascript_runtime: browserEvidence,
analyze_javascript_application: evidence,
reconcile_javascript_runtime: evidence,
trace_application_feature: evidence,
trace_javascript_semantics: evidence,
compare_application_versions: evidence,
compare_source_to_bundle: evidence,
compare_javascript_export_shapes: evidence,
build_reconstruction_obligation_ledger: evidence,
evaluate_reconstruction_readiness: evidence,
run_replay_machine: effects(),
run_controlled_replay: effects({
mutatesSession: true,
+87 -24
View File
@@ -21,6 +21,7 @@ import {
artifactExtractionResultSchema,
artifactInventoryResultSchema,
} from "../domain/artifactGraph.js";
import { artifactInspectionResultSchema } from "../domain/artifactInspection.js";
import {
managedArtifactInspectionSchema,
managedMemberInspectionSchema,
@@ -46,6 +47,7 @@ import {
addressedEntry,
bounded,
containingProcedureResolution,
clientFeatureAvailabilitySchema,
functionDossierOutput,
graphNode,
lifecycleResultOf,
@@ -87,6 +89,21 @@ export const officialOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
procedure_callers: resultOf(addressList),
procedure_info: procedureInfoOutput,
read_function_instructions: resultOf(functionInstructionWindowSchema),
read_bytes: resultOf(
z.object({
address: z.string(),
requested_bytes: z.number().int().min(1).max(4_096),
returned_bytes: z.number().int().min(0).max(4_096),
bytes_hex: z.string().regex(/^(?:[a-f0-9]{2})*$/u),
complete: z.boolean(),
}),
),
address_to_file_offset: resultOf(
z.object({
address: z.string(),
file_offset: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
}),
),
procedure_references: resultOf(
z.object({
procedure: procedureIdentity,
@@ -118,6 +135,71 @@ export const officialOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
xrefs: resultOf(addressList),
};
const literalTraceOutput = resultOf(
z.object({
query: z.string(),
search_mode: z.literal("literal"),
operations_used: z.number().int().min(0),
operation_budget: z.number().int().min(1),
matches: z.array(
z.object({
type: z.enum(["string", "procedure"]),
address: z.string(),
value: z.string(),
}),
),
references: z.array(
z.object({
target_address: z.string(),
source_address: z.string(),
containing_procedure: containingProcedureResolution,
}),
),
truncated: z.boolean(),
residual_unknowns: z.array(z.string()),
}),
);
const callPathTraceOutput = resultOf(
z.object({
start: z.string(),
goal: z.string().nullable(),
direction: z.enum(["forward", "backward"]),
goal_status: z.enum(["not_requested", "reached", "not_reached"]),
nodes: z.array(
z.object({
address: z.string(),
depth: z.number().int().min(0),
}),
),
edges: z.array(
z.object({
source_address: z.string(),
target_address: z.string(),
discovery_depth: z.number().int().min(1),
}),
),
traversal_path: z.array(z.string()),
failures: z.array(
z.object({
address: z.string(),
error: analysisErrorProjectionSchema,
}),
),
frontier: z.array(z.string()),
limits: z.object({
max_depth: z.number().int().min(1),
max_nodes: z.number().int().min(1),
max_operations: z.number().int().min(1),
nodes_visited: z.number().int().min(1),
operations_used: z.number().int().min(0),
}),
truncated: z.boolean(),
residual_unknowns: z.array(z.string()),
limitations: z.array(z.string()),
}),
);
/** Exact structured-content schemas for composed analysis workflows. */
export const enhancedOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
swift_classes: symbolDiscoveryOutput("classes"),
@@ -190,30 +272,9 @@ export const enhancedOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
}),
),
analyze_function: functionDossierOutput,
trace_feature: resultOf(
z.object({
query: z.string(),
search_mode: z.literal("literal"),
operations_used: z.number().int().min(0),
operation_budget: z.number().int().min(1),
matches: z.array(
z.object({
type: z.enum(["string", "procedure"]),
address: z.string(),
value: z.string(),
}),
),
references: z.array(
z.object({
target_address: z.string(),
source_address: z.string(),
containing_procedure: containingProcedureResolution,
}),
),
truncated: z.boolean(),
residual_unknowns: z.array(z.string()),
}),
),
trace_feature: literalTraceOutput,
find_code_for_string: literalTraceOutput,
trace_call_path: callPathTraceOutput,
};
/** Exact Evidence v2 schemas for provider-neutral native inspection. */
@@ -228,6 +289,7 @@ export const nativeOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
/** Exact Evidence v2 schemas for provider-neutral artifact graph operations. */
export const artifactOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
inventory_artifact: resultOf(artifactInventoryResultSchema),
inspect_artifact: resultOf(artifactInspectionResultSchema),
extract_artifact: resultOf(artifactExtractionResultSchema),
};
@@ -319,6 +381,7 @@ export const sessionOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
next_cursor: z.number().int().min(0).nullable(),
has_more: z.boolean(),
}),
client_features: clientFeatureAvailabilitySchema,
}),
z.union([
sessionProvider.extend({
@@ -207,12 +207,31 @@ const providerTargetSupport = z.discriminatedUnion("status", [
}),
]);
const clientFeatureNameSchema = z.enum([
"elicitation_form",
"elicitation_url",
"roots",
"sampling",
]);
/** Negotiated MCP client features that affect REA workflow availability. */
export const clientFeatureAvailabilitySchema = z.object({
elicitation_form: z.boolean(),
elicitation_url: z.boolean(),
roots: z.boolean(),
sampling: z.boolean(),
});
export type ClientFeatureAvailability = z.infer<
typeof clientFeatureAvailabilitySchema
>;
export const toolAvailability = z.object({
name: z.string(),
surface: z.string(),
available: z.boolean(),
reason: z.enum([
"available",
"client_capability_missing",
"target_required",
"provider_missing",
"provider_unavailable",
@@ -221,6 +240,12 @@ export const toolAvailability = z.object({
"policy_disabled",
]),
remediation: z.string().nullable(),
client_requirements: z.object({
required: z.array(clientFeatureNameSchema),
optional: z.array(clientFeatureNameSchema),
missing_required: z.array(clientFeatureNameSchema),
missing_optional: z.array(clientFeatureNameSchema),
}),
effects: z.strictObject({
mutatesTarget: z.boolean(),
mutatesSession: z.boolean(),