feat: streamline agent integration and MCP routing
This commit is contained in:
@@ -29,6 +29,12 @@ import { registerBrowserTools } from "./registerBrowserTools.js";
|
||||
import type { ElectronObservationPort } from "../application/ElectronObservationPort.js";
|
||||
import { registerElectronTools } from "./registerElectronTools.js";
|
||||
import { registerApplicationTools } from "./registerApplicationTools.js";
|
||||
|
||||
const TARGET_FREE_INSTRUCTIONS =
|
||||
"REA analyzes shipped artifacts and approved runtime evidence; use repository tools for source. Route: ASAR/JavaScript -> analyze_javascript_application; archive/package -> inventory_artifact; managed PE/CLI -> inspect_managed_artifact; browser/Electron runtime -> list_browser_targets/list_electron_targets; native binary/database -> open_binary, then binary_overview. Start with summaries and cite Evidence IDs. Never repeat identical analysis or read full Evidence unless a missing detail requires it.";
|
||||
|
||||
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.";
|
||||
import type {
|
||||
JavaScriptReplayHost,
|
||||
JavaScriptReplayPolicy,
|
||||
@@ -102,8 +108,8 @@ export const createServer = (
|
||||
requestState: { verify: processCaptureStateCodec.verify },
|
||||
instructions:
|
||||
session === undefined
|
||||
? "Reverse-engineering tools for an active analysis target. Start with binary_overview."
|
||||
: "Reverse-engineering tools for configured analysis providers. Open a target with open_binary, then start with binary_overview.",
|
||||
? ACTIVE_TARGET_INSTRUCTIONS
|
||||
: TARGET_FREE_INSTRUCTIONS,
|
||||
},
|
||||
);
|
||||
server.server.onclose = () => {
|
||||
@@ -276,6 +282,7 @@ const registerBinaryAnalysisTools = ({
|
||||
logger,
|
||||
activeTarget,
|
||||
recordEvidence,
|
||||
session,
|
||||
});
|
||||
if (session !== undefined)
|
||||
registerManagedWorkflowTools(server, {
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../domain/javascriptApplicationAnalysis.js";
|
||||
import { compareCodePoints } from "../domain/javascriptApplicationGraph.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { javascriptApplicationAnalysisSummarySchema } from "../contracts/electronToolContracts.js";
|
||||
|
||||
const DEFAULT_GRAPH_PAGE_LIMIT = 100;
|
||||
const ROOT_SAMPLE_LIMIT = 10;
|
||||
const TOP_FINDING_LIMIT = 20;
|
||||
|
||||
const FINDING_PRIORITY: Readonly<Record<string, number>> = {
|
||||
"browser-window": 0,
|
||||
"electron-preload": 1,
|
||||
"context-bridge-api": 2,
|
||||
"ipc-channel": 3,
|
||||
"ipc-handler": 4,
|
||||
"electron-utility": 5,
|
||||
endpoint: 6,
|
||||
storage: 7,
|
||||
worker: 8,
|
||||
"service-worker": 9,
|
||||
"native-addon": 10,
|
||||
"native-export": 11,
|
||||
"source-map": 12,
|
||||
};
|
||||
|
||||
/** Project complete JavaScript application Evidence into a bounded agent result. */
|
||||
export const summarizeJavaScriptApplicationEvidence = (
|
||||
evidence: Evidence,
|
||||
): JsonValue => {
|
||||
const result = javascriptApplicationAnalysisResultSchema.parse(
|
||||
evidence.normalized_result,
|
||||
);
|
||||
const nodeKinds = new Map<string, number>();
|
||||
for (const node of result.graph.nodes)
|
||||
nodeKinds.set(node.kind, (nodeKinds.get(node.kind) ?? 0) + 1);
|
||||
const rootItems = result.graph.root_node_ids.slice(0, ROOT_SAMPLE_LIMIT);
|
||||
const pageRoot = `rea://evidence/${evidence.evidence_id}/application-graph`;
|
||||
const topFindings = [...result.graph.nodes]
|
||||
.sort(
|
||||
(left, right) =>
|
||||
(FINDING_PRIORITY[left.kind] ?? Number.MAX_SAFE_INTEGER) -
|
||||
(FINDING_PRIORITY[right.kind] ?? Number.MAX_SAFE_INTEGER) ||
|
||||
compareCodePoints(left.node_id, right.node_id),
|
||||
)
|
||||
.slice(0, TOP_FINDING_LIMIT)
|
||||
.map((node) => {
|
||||
const observation = node.observations[0];
|
||||
if (observation === undefined)
|
||||
throw new TypeError("Application graph node has no observation");
|
||||
return {
|
||||
node_id: node.node_id,
|
||||
kind: node.kind,
|
||||
label: observation.label,
|
||||
authority: observation.evidence.authority,
|
||||
state: observation.evidence.state,
|
||||
confidence: observation.evidence.confidence,
|
||||
location: observation.evidence.location,
|
||||
};
|
||||
});
|
||||
const { graph: _graph, ...summary } = result;
|
||||
const unknowns = new Set([
|
||||
...result.limitations,
|
||||
...result.graph.limitations,
|
||||
]);
|
||||
if (result.statistics.parse_failures > 0)
|
||||
unknowns.add(
|
||||
`${String(result.statistics.parse_failures)} JavaScript file(s) could not be parsed.`,
|
||||
);
|
||||
if (result.statistics.truncated_scopes > 0)
|
||||
unknowns.add(
|
||||
`${String(result.statistics.truncated_scopes)} analysis scope(s) were truncated.`,
|
||||
);
|
||||
if (result.graph.coverage.status !== "complete")
|
||||
unknowns.add(
|
||||
`Application graph coverage is ${result.graph.coverage.status}; omitted facts remain unknown.`,
|
||||
);
|
||||
return javascriptApplicationAnalysisSummarySchema.parse({
|
||||
...summary,
|
||||
unknowns: [...unknowns],
|
||||
graph: {
|
||||
graph_id: result.graph.graph_id,
|
||||
node_count: result.graph.nodes.length,
|
||||
edge_count: result.graph.edges.length,
|
||||
roots: {
|
||||
items: rootItems,
|
||||
total: result.graph.root_node_ids.length,
|
||||
truncated: rootItems.length < result.graph.root_node_ids.length,
|
||||
},
|
||||
node_kinds: [...nodeKinds]
|
||||
.sort(([left], [right]) => compareCodePoints(left, right))
|
||||
.map(([kind, count]) => ({ kind, count })),
|
||||
top_findings: topFindings,
|
||||
coverage: result.graph.coverage,
|
||||
limitations: result.graph.limitations,
|
||||
pages: {
|
||||
nodes: `${pageRoot}/nodes/offset/0/limit/${String(DEFAULT_GRAPH_PAGE_LIMIT)}`,
|
||||
edges: `${pageRoot}/edges/offset/0/limit/${String(DEFAULT_GRAPH_PAGE_LIMIT)}`,
|
||||
page_limit: DEFAULT_GRAPH_PAGE_LIMIT,
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -10,12 +10,14 @@ import {
|
||||
listElectronTargets,
|
||||
} from "../application/ElectronObservationService.js";
|
||||
import type { PermissionAuthority } from "../application/PermissionAuthority.js";
|
||||
import { ELECTRON_TOOL_CONTRACTS } from "../contracts/electronToolContracts.js";
|
||||
import {
|
||||
analyzeJavaScriptApplicationToolInputSchema,
|
||||
ELECTRON_TOOL_CONTRACTS,
|
||||
} from "../contracts/electronToolContracts.js";
|
||||
import {
|
||||
inspectElectronPageInputSchema,
|
||||
listElectronTargetsInputSchema,
|
||||
} from "../domain/electronObservation.js";
|
||||
import { analyzeJavaScriptApplicationInputSchema } from "../domain/javascriptApplicationAnalysis.js";
|
||||
import { reconcileJavaScriptRuntimeInputSchema } from "../domain/javascriptRuntimeReconciliationSchemas.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
@@ -28,6 +30,8 @@ import type { Evidence } from "../domain/evidence.js";
|
||||
import type { Result } from "../domain/result.js";
|
||||
import type { AnalysisError } from "../domain/errors.js";
|
||||
import type { ToolContract } from "../contracts/toolContracts.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { summarizeJavaScriptApplicationEvidence } from "./javascriptApplicationResult.js";
|
||||
|
||||
interface ElectronToolRegistration {
|
||||
readonly logger: Logger;
|
||||
@@ -48,6 +52,13 @@ interface ElectronToolSpec<Schema extends z.ZodType> {
|
||||
parsed: z.output<Schema>,
|
||||
context: ElectronToolContext,
|
||||
) => Promise<Result<Evidence, AnalysisError>>;
|
||||
readonly projectEvidence?: (
|
||||
evidence: Evidence,
|
||||
parsed: z.output<Schema>,
|
||||
) => {
|
||||
readonly structured: JsonValue;
|
||||
readonly text?: JsonValue;
|
||||
};
|
||||
}
|
||||
|
||||
/** Register Electron tools even when provider or permission policy is absent. */
|
||||
@@ -87,13 +98,19 @@ export const registerElectronTools = (
|
||||
});
|
||||
registerElectronTool(server, options, {
|
||||
contract: analyzeContract,
|
||||
schema: analyzeJavaScriptApplicationInputSchema,
|
||||
schema: analyzeJavaScriptApplicationToolInputSchema,
|
||||
execute: (parsed, { signal, progress }) =>
|
||||
analyzeJavaScriptApplicationValidated(
|
||||
options.permissionAuthority,
|
||||
parsed,
|
||||
{ signal, progress },
|
||||
),
|
||||
projectEvidence: (evidence, parsed) => {
|
||||
const summary = summarizeJavaScriptApplicationEvidence(evidence);
|
||||
return parsed.detail === "full"
|
||||
? { structured: evidence.normalized_result, text: summary }
|
||||
: { structured: summary };
|
||||
},
|
||||
});
|
||||
registerElectronTool(server, options, {
|
||||
contract: reconcileContract,
|
||||
@@ -128,7 +145,12 @@ const registerElectronTool = <Schema extends z.ZodType>(
|
||||
}),
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, spec.contract);
|
||||
return evidenceResult(options, spec.contract, result.value);
|
||||
return evidenceResult(
|
||||
options,
|
||||
spec.contract,
|
||||
result.value,
|
||||
spec.projectEvidence?.(result.value, parsedInput.value),
|
||||
);
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -137,11 +159,22 @@ const evidenceResult = (
|
||||
options: ElectronToolRegistration,
|
||||
contract: ToolContract,
|
||||
evidence: Evidence,
|
||||
projection:
|
||||
| { readonly structured: JsonValue; readonly text?: JsonValue }
|
||||
| undefined,
|
||||
) => {
|
||||
const recorded = options.recordEvidence?.(evidence);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult({ ok: true, value: evidence }, contract, {
|
||||
evidenceResourcesAvailable: recorded !== undefined,
|
||||
...(projection === undefined
|
||||
? {}
|
||||
: {
|
||||
evidenceResultProjection: projection.structured,
|
||||
...(projection.text === undefined
|
||||
? {}
|
||||
: { evidenceTextProjection: projection.text }),
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@ import canonicalize from "canonicalize";
|
||||
|
||||
import type { BinarySessionPort } from "../application/BinarySessionPort.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { registerJavaScriptApplicationGraphResource } from "./registerJavaScriptApplicationGraphResource.js";
|
||||
|
||||
const evidenceUri = (evidenceId: string): string =>
|
||||
`rea://evidence/${evidenceId}`;
|
||||
@@ -26,6 +27,7 @@ export const registerEvidenceResources = (
|
||||
registerArtifactPageResource(server, session);
|
||||
registerFunctionDossierResource(server, session);
|
||||
registerEvidenceSectionResource(server, session);
|
||||
registerJavaScriptApplicationGraphResource(server, session);
|
||||
registerResidualUnknownResource(server, session);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import {
|
||||
ResourceNotFoundError,
|
||||
ResourceTemplate,
|
||||
type McpServer,
|
||||
} from "@modelcontextprotocol/server";
|
||||
|
||||
import type { BinarySessionPort } from "../application/BinarySessionPort.js";
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../domain/javascriptApplicationAnalysis.js";
|
||||
|
||||
/** Register deterministic pages over one authenticated JavaScript graph. */
|
||||
export const registerJavaScriptApplicationGraphResource = (
|
||||
server: McpServer,
|
||||
session: BinarySessionPort,
|
||||
): void => {
|
||||
server.registerResource(
|
||||
"javascript-application-graph-page",
|
||||
new ResourceTemplate(
|
||||
"rea://evidence/{evidenceId}/application-graph/{collection}/offset/{offset}/limit/{limit}",
|
||||
{
|
||||
list: undefined,
|
||||
complete: {
|
||||
evidenceId: (prefix) =>
|
||||
session
|
||||
.exportEvidenceBundle()
|
||||
.records.map(({ evidence_id }) => evidence_id)
|
||||
.filter((evidenceId) => evidenceId.startsWith(prefix)),
|
||||
collection: (prefix) =>
|
||||
["nodes", "edges"].filter((name) => name.startsWith(prefix)),
|
||||
},
|
||||
},
|
||||
),
|
||||
{
|
||||
title: "JavaScript application graph page",
|
||||
description:
|
||||
"One deterministic bounded node or edge page from authenticated JavaScript application Evidence.",
|
||||
mimeType: "application/json",
|
||||
},
|
||||
(uri, variables) => {
|
||||
const evidenceId = stringVariable(variables.evidenceId, uri.href);
|
||||
const collection = stringVariable(variables.collection, uri.href);
|
||||
if (collection !== "nodes" && collection !== "edges")
|
||||
throw new ResourceNotFoundError(uri.href);
|
||||
const offset = pageInteger(variables.offset, uri.href, 0, 100_000);
|
||||
const limit = pageInteger(variables.limit, uri.href, 1, 500);
|
||||
const evidence = session.evidenceById(evidenceId);
|
||||
if (
|
||||
evidence === undefined ||
|
||||
evidence.operation !== "analyze_javascript_application"
|
||||
)
|
||||
throw new ResourceNotFoundError(uri.href);
|
||||
const analysis = javascriptApplicationAnalysisResultSchema.safeParse(
|
||||
evidence.normalized_result,
|
||||
);
|
||||
if (!analysis.success) throw new ResourceNotFoundError(uri.href);
|
||||
const values = analysis.data.graph[collection];
|
||||
const items = values.slice(offset, offset + limit);
|
||||
const nextOffset = offset + items.length;
|
||||
return {
|
||||
contents: [
|
||||
{
|
||||
uri: uri.href,
|
||||
mimeType: "application/json" as const,
|
||||
text: JSON.stringify(
|
||||
{
|
||||
evidence_id: evidence.evidence_id,
|
||||
graph_id: analysis.data.graph.graph_id,
|
||||
collection,
|
||||
items,
|
||||
offset,
|
||||
limit,
|
||||
total: values.length,
|
||||
next_offset: nextOffset < values.length ? nextOffset : null,
|
||||
has_more: nextOffset < values.length,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const stringVariable = (value: unknown, uri: string): string => {
|
||||
if (typeof value !== "string") throw new ResourceNotFoundError(uri);
|
||||
return value;
|
||||
};
|
||||
|
||||
const pageInteger = (
|
||||
value: unknown,
|
||||
uri: string,
|
||||
minimum: number,
|
||||
maximum: number,
|
||||
): number => {
|
||||
const text = stringVariable(value, uri);
|
||||
if (!/^\d+$/u.test(text)) throw new ResourceNotFoundError(uri);
|
||||
const parsed = Number(text);
|
||||
if (!Number.isSafeInteger(parsed) || parsed < minimum || parsed > maximum)
|
||||
throw new ResourceNotFoundError(uri);
|
||||
return parsed;
|
||||
};
|
||||
@@ -5,6 +5,7 @@ import type { BinarySessionPort } from "../application/BinarySession.js";
|
||||
import { MANAGED_TOOL_CONTRACTS } from "../contracts/managedToolContracts.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTarget.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { err } from "../domain/result.js";
|
||||
import { registerEvidenceTools } from "./registerEvidenceTools.js";
|
||||
|
||||
/** Register execution-free managed PE/CLI inspection. */
|
||||
@@ -15,7 +16,32 @@ export const registerManagedTools = (
|
||||
readonly logger: Logger;
|
||||
readonly activeTarget: (() => BinaryTarget | undefined) | undefined;
|
||||
readonly recordEvidence: BinarySessionPort["recordEvidence"] | undefined;
|
||||
readonly session: BinarySessionPort | undefined;
|
||||
},
|
||||
): void => {
|
||||
registerEvidenceTools(server, analysis, MANAGED_TOOL_CONTRACTS, options);
|
||||
const targetAwareAnalysis: AnalysisOperationPort = {
|
||||
execute: async (operation, parameters, executionOptions) => {
|
||||
const path =
|
||||
operation === "inspect_managed_artifact" &&
|
||||
typeof parameters.path === "string"
|
||||
? parameters.path
|
||||
: undefined;
|
||||
if (path !== undefined && options.session !== undefined) {
|
||||
const opened = await options.session.open(
|
||||
path,
|
||||
executionOptions?.signal === undefined
|
||||
? undefined
|
||||
: { signal: executionOptions.signal },
|
||||
);
|
||||
if (!opened.ok) return err(opened.error);
|
||||
}
|
||||
return analysis.execute(operation, parameters, executionOptions);
|
||||
},
|
||||
};
|
||||
registerEvidenceTools(
|
||||
server,
|
||||
targetAwareAnalysis,
|
||||
MANAGED_TOOL_CONTRACTS,
|
||||
options,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { McpServer } from "@modelcontextprotocol/server";
|
||||
import type { z } from "zod";
|
||||
|
||||
import type { BinarySessionPort } from "../application/BinarySession.js";
|
||||
import {
|
||||
@@ -12,6 +13,9 @@ import { buildCapabilityInventory } from "../application/CapabilityInventory.js"
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { safeParseToolInput } from "./toolInputValidation.js";
|
||||
|
||||
type BinarySessionInput = z.output<typeof binarySessionInputSchema>;
|
||||
type ToolAvailability = ReturnType<typeof buildCapabilityInventory>[number];
|
||||
|
||||
/** Inputs required to register the binary session status tool. */
|
||||
export interface SessionStatusToolOptions {
|
||||
readonly server: McpServer;
|
||||
@@ -47,16 +51,40 @@ export const registerSessionStatusTool = (
|
||||
const client = server.server.getClientVersion();
|
||||
const clientCapabilities = server.server.getClientCapabilities();
|
||||
const status = session.status();
|
||||
const statusObject = jsonObjectSchema.parse(status);
|
||||
const toolAvailability = buildCapabilityInventory(
|
||||
status,
|
||||
availabilityPolicy(),
|
||||
);
|
||||
const serverIdentity = createServerIdentity({
|
||||
startedAt,
|
||||
expected: {
|
||||
...(parsed.expected_package_version === undefined
|
||||
? {}
|
||||
: { package_version: parsed.expected_package_version }),
|
||||
...(parsed.expected_catalog_digest === undefined
|
||||
? {}
|
||||
: { catalog_digest: parsed.expected_catalog_digest }),
|
||||
...(parsed.expected_server_path === undefined
|
||||
? {}
|
||||
: { server_path: parsed.expected_server_path }),
|
||||
},
|
||||
...(client === undefined ? {} : { client }),
|
||||
...(server.server.getNegotiatedProtocolVersion() === undefined
|
||||
? {}
|
||||
: {
|
||||
protocolVersion: server.server.getNegotiatedProtocolVersion(),
|
||||
}),
|
||||
});
|
||||
return toCallToolResult(
|
||||
{
|
||||
ok: true,
|
||||
value: {
|
||||
...jsonObjectSchema.parse(status),
|
||||
tool_availability: buildCapabilityInventory(
|
||||
status,
|
||||
availabilityPolicy(),
|
||||
),
|
||||
client_features: {
|
||||
value: projectSessionStatus({
|
||||
input: parsed,
|
||||
status: statusObject,
|
||||
toolAvailability,
|
||||
serverIdentity,
|
||||
clientFeatures: {
|
||||
elicitation_form:
|
||||
clientCapabilities?.elicitation?.form !== undefined,
|
||||
elicitation_url:
|
||||
@@ -64,31 +92,104 @@ export const registerSessionStatusTool = (
|
||||
roots: clientCapabilities?.roots !== undefined,
|
||||
sampling: clientCapabilities?.sampling !== undefined,
|
||||
},
|
||||
server_identity: createServerIdentity({
|
||||
startedAt,
|
||||
expected: {
|
||||
...(parsed.expected_package_version === undefined
|
||||
? {}
|
||||
: { package_version: parsed.expected_package_version }),
|
||||
...(parsed.expected_catalog_digest === undefined
|
||||
? {}
|
||||
: { catalog_digest: parsed.expected_catalog_digest }),
|
||||
...(parsed.expected_server_path === undefined
|
||||
? {}
|
||||
: { server_path: parsed.expected_server_path }),
|
||||
},
|
||||
...(client === undefined ? {} : { client }),
|
||||
...(server.server.getNegotiatedProtocolVersion() === undefined
|
||||
? {}
|
||||
: {
|
||||
protocolVersion:
|
||||
server.server.getNegotiatedProtocolVersion(),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
},
|
||||
contract,
|
||||
);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const projectSessionStatus = (options: {
|
||||
readonly input: BinarySessionInput;
|
||||
readonly status: Readonly<
|
||||
Record<string, import("../domain/jsonValue.js").JsonValue>
|
||||
>;
|
||||
readonly toolAvailability: readonly ToolAvailability[];
|
||||
readonly serverIdentity: ReturnType<typeof createServerIdentity>;
|
||||
readonly clientFeatures: Readonly<Record<string, boolean>>;
|
||||
}) => {
|
||||
if (options.input.detail === "full")
|
||||
return jsonObjectSchema.parse({
|
||||
view: "full",
|
||||
...options.status,
|
||||
tool_availability: options.toolAvailability,
|
||||
client_features: options.clientFeatures,
|
||||
server_identity: options.serverIdentity,
|
||||
});
|
||||
const open = options.status.open === true;
|
||||
const activeProvider = activeProviderFrom(options.status);
|
||||
if (options.input.detail === "capabilities") {
|
||||
const filtered =
|
||||
options.input.capability_family === undefined
|
||||
? options.toolAvailability
|
||||
: options.toolAvailability.filter(
|
||||
({ surface }) => surface === options.input.capability_family,
|
||||
);
|
||||
const items = filtered.slice(
|
||||
options.input.cursor,
|
||||
options.input.cursor + options.input.limit,
|
||||
);
|
||||
const nextCursor = options.input.cursor + items.length;
|
||||
return jsonObjectSchema.parse({
|
||||
view: "capabilities",
|
||||
open,
|
||||
provider: options.status.provider,
|
||||
active_provider: activeProvider,
|
||||
capability_family: options.input.capability_family ?? null,
|
||||
capabilities: {
|
||||
items,
|
||||
cursor: options.input.cursor,
|
||||
limit: options.input.limit,
|
||||
total: filtered.length,
|
||||
next_cursor: nextCursor < filtered.length ? nextCursor : null,
|
||||
has_more: nextCursor < filtered.length,
|
||||
},
|
||||
});
|
||||
}
|
||||
return jsonObjectSchema.parse({
|
||||
view: "summary",
|
||||
open,
|
||||
provider: options.status.provider,
|
||||
active_provider: activeProvider,
|
||||
target: open ? targetFrom(options.status) : null,
|
||||
alignment: options.serverIdentity.alignment,
|
||||
recommended_actions: recommendedActions(
|
||||
open,
|
||||
options.serverIdentity.alignment.state,
|
||||
),
|
||||
});
|
||||
};
|
||||
|
||||
const activeProviderFrom = (
|
||||
status: Readonly<Record<string, import("../domain/jsonValue.js").JsonValue>>,
|
||||
) => {
|
||||
const binding = jsonObjectSchema.safeParse(status.analysis_provider_binding);
|
||||
return binding.success ? (binding.data.provider ?? null) : null;
|
||||
};
|
||||
|
||||
const targetFrom = (
|
||||
status: Readonly<Record<string, import("../domain/jsonValue.js").JsonValue>>,
|
||||
) => ({
|
||||
path: status.path,
|
||||
format: status.format,
|
||||
kind: status.kind,
|
||||
sha256: status.sha256,
|
||||
architecture: status.architecture ?? null,
|
||||
});
|
||||
|
||||
const recommendedActions = (
|
||||
open: boolean,
|
||||
alignment: string,
|
||||
): readonly string[] => [
|
||||
...(alignment === "mcp_server_restart_required"
|
||||
? ["Restart the registered MCP server or client before continuing."]
|
||||
: []),
|
||||
...(!open
|
||||
? [
|
||||
"Route the supplied target directly: ASAR/JavaScript to analyze_javascript_application, packages to inventory_artifact, managed PE/CLI to inspect_managed_artifact, browser/Electron runtimes to their list-target tools, and native binaries to open_binary.",
|
||||
]
|
||||
: [
|
||||
"Continue from the active target with binary_overview or a bounded target-specific query.",
|
||||
]),
|
||||
];
|
||||
|
||||
@@ -11,6 +11,8 @@ import type { ToolContract } from "../contracts/toolContracts.js";
|
||||
|
||||
interface ToolResultOptions {
|
||||
readonly evidenceResourcesAvailable?: boolean;
|
||||
readonly evidenceResultProjection?: JsonValue;
|
||||
readonly evidenceTextProjection?: JsonValue;
|
||||
readonly resourceLinks?: readonly {
|
||||
readonly uri: string;
|
||||
readonly name: string;
|
||||
@@ -53,7 +55,7 @@ const successResult = (
|
||||
options: ToolResultOptions,
|
||||
): CallToolResult => {
|
||||
const candidate =
|
||||
compactEvidence(value) ??
|
||||
compactEvidence(value, options.evidenceResultProjection) ??
|
||||
(contract.kind === "session" ? { result: value } : value);
|
||||
const parsed = contract.outputSchema.safeParse(candidate);
|
||||
if (!parsed.success) {
|
||||
@@ -78,7 +80,15 @@ const successResult = (
|
||||
}
|
||||
return {
|
||||
content: [
|
||||
{ type: "text", text: JSON.stringify(parsed.data) },
|
||||
{
|
||||
type: "text",
|
||||
text: JSON.stringify(
|
||||
options.evidenceTextProjection === undefined
|
||||
? parsed.data
|
||||
: (compactEvidence(value, options.evidenceTextProjection) ??
|
||||
options.evidenceTextProjection),
|
||||
),
|
||||
},
|
||||
...evidenceResourceLinks(
|
||||
value,
|
||||
contract.kind === "session" ||
|
||||
@@ -94,7 +104,10 @@ const successResult = (
|
||||
};
|
||||
};
|
||||
|
||||
const compactEvidence = (value: JsonValue): JsonValue | undefined => {
|
||||
const compactEvidence = (
|
||||
value: JsonValue,
|
||||
resultProjection: JsonValue | undefined,
|
||||
): JsonValue | undefined => {
|
||||
if (
|
||||
typeof value !== "object" ||
|
||||
value === null ||
|
||||
@@ -105,7 +118,7 @@ const compactEvidence = (value: JsonValue): JsonValue | undefined => {
|
||||
)
|
||||
return undefined;
|
||||
return {
|
||||
result: value.normalized_result,
|
||||
result: resultProjection ?? value.normalized_result,
|
||||
evidence_id: value.evidence_id,
|
||||
evidence_uri: `rea://evidence/${value.evidence_id}`,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user