refactor!: enforce canonical evidence and provider boundaries
Deliver complete Evidence directly through MCP with required nullable analysis profiles and immutable per-server delivery settings. Bind selected environments at construction and require typed cleanup outcomes with retained retry ownership. Remove test-only routing, duplicate session and snapshot metadata, producer-field repairs, and ambiguous provider arguments. Separate artifact byte identity from occurrence classification and retain typed source-map and partial native facts across CLI, MCP, and verifier consumers. BREAKING CHANGE: obsolete Evidence envelopes, session aliases, incomplete snapshots, and missing normalized producer facts are no longer accepted.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import type { ToolResultDelivery } from "./toolResult.js";
|
||||
import type { EvidenceMcpServer } from "./EvidenceMcpServer.js";
|
||||
import type {
|
||||
EvidenceWriter,
|
||||
UnknownRegistryPort,
|
||||
} from "../application/investigation/InvestigationRecordPort.js";
|
||||
import type {
|
||||
CallToolResult,
|
||||
McpServer,
|
||||
ServerContext,
|
||||
} from "@modelcontextprotocol/server";
|
||||
|
||||
@@ -27,7 +28,6 @@ import type { Logger } from "../logger.js";
|
||||
import { mcpProgressReporter } from "./mcpProgress.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
import { executeFunctionAnalysisEvidence } from "../application/FunctionAnalysisEvidence.js";
|
||||
|
||||
/** Optional session services used by enhanced tool registration. */
|
||||
@@ -52,10 +52,11 @@ export interface EnhancedToolRegistration {
|
||||
/** Register composed workflows against the same port as direct bridge tools. */
|
||||
// oxlint-disable-next-line max-lines-per-function -- direct SDK calls retain each schema-handler type correlation.
|
||||
export const registerEnhancedTools = (
|
||||
server: McpServer,
|
||||
server: EvidenceMcpServer,
|
||||
analysis: AnalysisOperationPort,
|
||||
options: EnhancedToolRegistration,
|
||||
): void => {
|
||||
const registration = { ...options, delivery: server.delivery };
|
||||
const nativeDispatchMetadata = toolContract(
|
||||
"inspect_native_dispatch_metadata",
|
||||
);
|
||||
@@ -76,7 +77,7 @@ export const registerEnhancedTools = (
|
||||
traceNativeValues.name,
|
||||
toolRegistrationOptions(traceNativeValues),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, traceNativeValues, {
|
||||
executeEnhancedTool(analysis, registration, traceNativeValues, {
|
||||
validatedCall: { name: "trace_native_values", input },
|
||||
context,
|
||||
}),
|
||||
@@ -85,7 +86,7 @@ export const registerEnhancedTools = (
|
||||
nativeDispatchMetadata.name,
|
||||
toolRegistrationOptions(nativeDispatchMetadata),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, nativeDispatchMetadata, {
|
||||
executeEnhancedTool(analysis, registration, nativeDispatchMetadata, {
|
||||
validatedCall: { name: "inspect_native_dispatch_metadata", input },
|
||||
context,
|
||||
}),
|
||||
@@ -94,7 +95,7 @@ export const registerEnhancedTools = (
|
||||
objcClasses.name,
|
||||
toolRegistrationOptions(objcClasses),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, objcClasses, {
|
||||
executeEnhancedTool(analysis, registration, objcClasses, {
|
||||
validatedCall: { name: "get_objc_classes", input },
|
||||
context,
|
||||
}),
|
||||
@@ -103,7 +104,7 @@ export const registerEnhancedTools = (
|
||||
objcProtocols.name,
|
||||
toolRegistrationOptions(objcProtocols),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, objcProtocols, {
|
||||
executeEnhancedTool(analysis, registration, objcProtocols, {
|
||||
validatedCall: { name: "get_objc_protocols", input },
|
||||
context,
|
||||
}),
|
||||
@@ -112,7 +113,7 @@ export const registerEnhancedTools = (
|
||||
batchDecompile.name,
|
||||
toolRegistrationOptions(batchDecompile),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, batchDecompile, {
|
||||
executeEnhancedTool(analysis, registration, batchDecompile, {
|
||||
validatedCall: { name: "batch_decompile", input },
|
||||
context,
|
||||
}),
|
||||
@@ -121,7 +122,7 @@ export const registerEnhancedTools = (
|
||||
callGraph.name,
|
||||
toolRegistrationOptions(callGraph),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, callGraph, {
|
||||
executeEnhancedTool(analysis, registration, callGraph, {
|
||||
validatedCall: { name: "get_call_graph", input },
|
||||
context,
|
||||
}),
|
||||
@@ -130,7 +131,7 @@ export const registerEnhancedTools = (
|
||||
swiftTypes.name,
|
||||
toolRegistrationOptions(swiftTypes),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, swiftTypes, {
|
||||
executeEnhancedTool(analysis, registration, swiftTypes, {
|
||||
validatedCall: { name: "analyze_swift_types", input },
|
||||
context,
|
||||
}),
|
||||
@@ -139,7 +140,7 @@ export const registerEnhancedTools = (
|
||||
xrefsToName.name,
|
||||
toolRegistrationOptions(xrefsToName),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, xrefsToName, {
|
||||
executeEnhancedTool(analysis, registration, xrefsToName, {
|
||||
validatedCall: { name: "find_xrefs_to_name", input },
|
||||
context,
|
||||
}),
|
||||
@@ -148,7 +149,7 @@ export const registerEnhancedTools = (
|
||||
binaryOverview.name,
|
||||
toolRegistrationOptions(binaryOverview),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, binaryOverview, {
|
||||
executeEnhancedTool(analysis, registration, binaryOverview, {
|
||||
validatedCall: { name: "binary_overview", input },
|
||||
context,
|
||||
}),
|
||||
@@ -157,7 +158,7 @@ export const registerEnhancedTools = (
|
||||
analyzeFunction.name,
|
||||
toolRegistrationOptions(analyzeFunction),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, analyzeFunction, {
|
||||
executeEnhancedTool(analysis, registration, analyzeFunction, {
|
||||
validatedCall: { name: "analyze_function", input },
|
||||
context,
|
||||
}),
|
||||
@@ -166,7 +167,7 @@ export const registerEnhancedTools = (
|
||||
inspectNativeApi.name,
|
||||
toolRegistrationOptions(inspectNativeApi),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, inspectNativeApi, {
|
||||
executeEnhancedTool(analysis, registration, inspectNativeApi, {
|
||||
validatedCall: { name: "inspect_native_api", input },
|
||||
context,
|
||||
}),
|
||||
@@ -175,7 +176,7 @@ export const registerEnhancedTools = (
|
||||
traceFeature.name,
|
||||
toolRegistrationOptions(traceFeature),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, traceFeature, {
|
||||
executeEnhancedTool(analysis, registration, traceFeature, {
|
||||
validatedCall: { name: "trace_feature", input },
|
||||
context,
|
||||
}),
|
||||
@@ -184,7 +185,7 @@ export const registerEnhancedTools = (
|
||||
traceCallPath.name,
|
||||
toolRegistrationOptions(traceCallPath),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, traceCallPath, {
|
||||
executeEnhancedTool(analysis, registration, traceCallPath, {
|
||||
validatedCall: { name: "trace_call_path", input },
|
||||
context,
|
||||
}),
|
||||
@@ -193,7 +194,7 @@ export const registerEnhancedTools = (
|
||||
traceNativeUiAction.name,
|
||||
toolRegistrationOptions(traceNativeUiAction),
|
||||
(input, context) =>
|
||||
executeEnhancedTool(analysis, options, traceNativeUiAction, {
|
||||
executeEnhancedTool(analysis, registration, traceNativeUiAction, {
|
||||
validatedCall: { name: "trace_native_ui_action", input },
|
||||
context,
|
||||
}),
|
||||
@@ -202,7 +203,9 @@ export const registerEnhancedTools = (
|
||||
|
||||
const executeEnhancedTool = async (
|
||||
analysis: AnalysisOperationPort,
|
||||
registration: EnhancedToolRegistration,
|
||||
registration: EnhancedToolRegistration & {
|
||||
readonly delivery: ToolResultDelivery;
|
||||
},
|
||||
contract: ToolContract,
|
||||
request: {
|
||||
readonly validatedCall: ValidatedEnhancedCall;
|
||||
@@ -252,7 +255,7 @@ const executeEnhancedTool = async (
|
||||
});
|
||||
const recorded = registration.recordEvidence?.(evidence);
|
||||
if (recorded !== undefined && !recorded.ok)
|
||||
return toCallToolResult(recorded, contract);
|
||||
return registration.delivery.toCallToolResult(recorded, contract);
|
||||
if (
|
||||
name !== "trace_native_ui_action" &&
|
||||
registration.allowsSnapshotReplay?.(name) === true
|
||||
@@ -261,7 +264,7 @@ const executeEnhancedTool = async (
|
||||
if (workflowRecord !== undefined) {
|
||||
const snapshot = registration.recordWorkflowSnapshot?.(workflowRecord);
|
||||
if (snapshot !== undefined && !snapshot.ok)
|
||||
return toCallToolResult(snapshot, contract);
|
||||
return registration.delivery.toCallToolResult(snapshot, contract);
|
||||
}
|
||||
}
|
||||
const unknowns = recordWorkflowUnknowns({
|
||||
@@ -270,15 +273,22 @@ const executeEnhancedTool = async (
|
||||
evidenceId: evidence.evidence_id,
|
||||
recordUnknown: registration.recordUnknown,
|
||||
});
|
||||
if (!unknowns.ok) return toCallToolResult(unknowns, contract);
|
||||
return toEvidenceToolResult(evidence, contract, recorded);
|
||||
if (!unknowns.ok)
|
||||
return registration.delivery.toCallToolResult(unknowns, contract);
|
||||
return registration.delivery.toEvidenceToolResult(
|
||||
evidence,
|
||||
contract,
|
||||
recorded,
|
||||
);
|
||||
}
|
||||
return toCallToolResult(result, contract);
|
||||
return registration.delivery.toCallToolResult(result, contract);
|
||||
};
|
||||
|
||||
const executeFunctionTool = async (
|
||||
analysis: AnalysisOperationPort,
|
||||
registration: EnhancedToolRegistration,
|
||||
registration: EnhancedToolRegistration & {
|
||||
readonly delivery: ToolResultDelivery;
|
||||
},
|
||||
contract: ToolContract,
|
||||
request: {
|
||||
readonly context: ServerContext;
|
||||
@@ -308,8 +318,9 @@ const executeFunctionTool = async (
|
||||
message: result.ok ? "completed" : "failed",
|
||||
terminal: true,
|
||||
});
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(
|
||||
if (!result.ok)
|
||||
return registration.delivery.toCallToolResult(result, contract);
|
||||
return registration.delivery.toEvidenceToolResult(
|
||||
result.value,
|
||||
contract,
|
||||
registration.recordEvidence?.(result.value),
|
||||
|
||||
Reference in New Issue
Block a user