fix(mcp): preserve retained evidence on oversized delivery
This commit is contained in:
@@ -7,7 +7,7 @@ import type { AndroidOperation } from "../domain/android/androidAnalysis.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Bind Android handlers to their exact named contracts through shared workflows. */
|
||||
export const registerAndroidTools = (
|
||||
@@ -24,9 +24,7 @@ export const registerAndroidTools = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
};
|
||||
};
|
||||
const packageContract = toolContract("inspect_android_package");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { APPLICATION_TOOL_CONTRACTS } from "../../contracts/applicationToolContracts.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import { toCallToolResult } from "../toolResult.js";
|
||||
import { toEvidenceToolResult } from "../toolResult.js";
|
||||
import type { ApplicationToolRegistration } from "./types.js";
|
||||
|
||||
export const recordResult = (
|
||||
@@ -19,15 +19,7 @@ export const recordResult = (
|
||||
evidence,
|
||||
unknownRegistration(evidence, unknownKind),
|
||||
);
|
||||
if (recorded !== undefined && !recorded.ok)
|
||||
return toCallToolResult(recorded, contract);
|
||||
return toCallToolResult(
|
||||
{ ok: true, value: evidence },
|
||||
contract,
|
||||
recorded === undefined
|
||||
? undefined
|
||||
: { retainedEvidenceId: evidence.evidence_id },
|
||||
);
|
||||
return toEvidenceToolResult(evidence, contract, recorded);
|
||||
};
|
||||
|
||||
const unknownRegistration = (
|
||||
|
||||
@@ -10,7 +10,7 @@ import { recordDerivedEvidence } from "./recordDerivedEvidence.js";
|
||||
import { runDerivedOperation } from "./runDerivedOperation.js";
|
||||
import { ARTIFACT_COMPARISON_PROVIDER } from "./sessionToolPolicies.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Register Evidence-backed deterministic artifact comparison. */
|
||||
export const registerArtifactComparisonTool = (
|
||||
@@ -50,13 +50,14 @@ export const registerArtifactComparisonTool = (
|
||||
limitations: comparison.limitations,
|
||||
evidenceLinks: [...leftEvidenceIds, ...rightEvidenceIds],
|
||||
});
|
||||
return toCallToolResult(
|
||||
return toEvidenceToolResult(
|
||||
evidence,
|
||||
contract,
|
||||
recordDerivedEvidence(
|
||||
session,
|
||||
evidence,
|
||||
artifactUnknownInput(left, right, comparison.status),
|
||||
),
|
||||
contract,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Bind offline layout inspection to its named contract and session Evidence owner. */
|
||||
export const registerBinaryDiagnosticsTools = (
|
||||
@@ -24,9 +24,7 @@ export const registerBinaryDiagnosticsTools = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ import { browserScenarioSchema } from "../domain/browserScenario.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
interface BrowserScenarioToolRegistration {
|
||||
readonly logger: Logger;
|
||||
@@ -45,9 +45,7 @@ export const registerBrowserScenarioTool = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = options.recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult({ ok: true, value: result.value }, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ import type { Logger } from "../logger.js";
|
||||
import { mcpProgressReporter } from "./mcpProgress.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
interface BrowserToolRegistration {
|
||||
readonly logger: Logger;
|
||||
@@ -206,13 +206,5 @@ const evidenceResult = (
|
||||
evidence: Evidence,
|
||||
) => {
|
||||
const recorded = options.recordEvidence?.(evidence);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(
|
||||
{ ok: true, value: evidence },
|
||||
contract,
|
||||
recorded === undefined
|
||||
? undefined
|
||||
: { retainedEvidenceId: evidence.evidence_id },
|
||||
);
|
||||
return toEvidenceToolResult(evidence, contract, recorded);
|
||||
};
|
||||
|
||||
@@ -6,11 +6,10 @@ import { toolContract } from "../contracts/toolContracts.js";
|
||||
import { compareBundles } from "../domain/bundleComparison.js";
|
||||
import { createEvidence } from "../domain/evidence.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { ok } from "../domain/result.js";
|
||||
import { runDerivedOperation } from "./runDerivedOperation.js";
|
||||
import { BUNDLE_COMPARISON_PROVIDER } from "./sessionToolPolicies.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Register canonical Evidence bundle comparison. */
|
||||
export const registerBundleComparisonTool = (
|
||||
@@ -47,7 +46,7 @@ export const registerBundleComparisonTool = (
|
||||
limitations: comparison.limitations,
|
||||
});
|
||||
const recorded = session.recordEvidence(evidence);
|
||||
return toCallToolResult(recorded.ok ? ok(evidence) : recorded, contract);
|
||||
return toEvidenceToolResult(evidence, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ import type { Logger } from "../logger.js";
|
||||
import { mcpProgressReporter } from "./mcpProgress.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
interface ElectronToolRegistration {
|
||||
readonly logger: Logger;
|
||||
@@ -166,13 +166,5 @@ const evidenceResult = (
|
||||
evidence: Evidence,
|
||||
) => {
|
||||
const recorded = options.recordEvidence?.(evidence);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(
|
||||
{ ok: true, value: evidence },
|
||||
contract,
|
||||
recorded === undefined
|
||||
? undefined
|
||||
: { retainedEvidenceId: evidence.evidence_id },
|
||||
);
|
||||
return toEvidenceToolResult(evidence, contract, recorded);
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@ import type { Logger } from "../logger.js";
|
||||
import { mcpProgressReporter } from "./mcpProgress.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
import { executeFunctionAnalysisEvidence } from "../application/FunctionAnalysisEvidence.js";
|
||||
|
||||
/** Optional session services used by enhanced tool registration. */
|
||||
@@ -271,7 +271,7 @@ const executeEnhancedTool = async (
|
||||
recordUnknown: registration.recordUnknown,
|
||||
});
|
||||
if (!unknowns.ok) return toCallToolResult(unknowns, contract);
|
||||
return toCallToolResult({ ok: true, value: evidence }, contract);
|
||||
return toEvidenceToolResult(evidence, contract, recorded);
|
||||
}
|
||||
return toCallToolResult(result, contract);
|
||||
};
|
||||
@@ -308,12 +308,12 @@ const executeFunctionTool = async (
|
||||
message: result.ok ? "completed" : "failed",
|
||||
terminal: true,
|
||||
});
|
||||
if (result.ok) {
|
||||
const recorded = registration.recordEvidence?.(result.value);
|
||||
if (recorded !== undefined && !recorded.ok)
|
||||
return toCallToolResult(recorded, contract);
|
||||
}
|
||||
return toCallToolResult(result, contract);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(
|
||||
result.value,
|
||||
contract,
|
||||
registration.recordEvidence?.(result.value),
|
||||
);
|
||||
};
|
||||
|
||||
const jsonParameters = (
|
||||
|
||||
@@ -13,7 +13,7 @@ import type { Logger } from "../logger.js";
|
||||
import { mcpProgressReporter } from "./mcpProgress.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
import { createArtifactExtractionDestination } from "../application/artifacts/ArtifactExtractionDestination.js";
|
||||
|
||||
interface EvidenceToolRegistration {
|
||||
@@ -94,9 +94,7 @@ export const registerEvidenceTools = (
|
||||
return toCallToolResult(sourceRecorded, contract);
|
||||
}
|
||||
const recorded = options.recordEvidence?.(evidence);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult({ ok: true, value: evidence }, contract);
|
||||
return toEvidenceToolResult(evidence, contract, recorded);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Bind the named EVM contract to shared validation and session Evidence recording. */
|
||||
export const registerEvmTools = (
|
||||
@@ -24,9 +24,7 @@ export const registerEvmTools = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { FirmwareOperation } from "../domain/firmware/firmwareAnalysis.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Bind firmware handlers to their exact named schemas. */
|
||||
export const registerFirmwareTools = (
|
||||
@@ -26,9 +26,7 @@ export const registerFirmwareTools = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
};
|
||||
const inspect = toolContract("inspect_firmware_regions");
|
||||
server.registerTool(
|
||||
|
||||
@@ -17,7 +17,7 @@ import { recordSessionEvidenceSources } from "./sessionEvidence.js";
|
||||
import { runDerivedOperation } from "./runDerivedOperation.js";
|
||||
import { FUNCTION_COMPARISON_PROVIDER } from "./sessionToolPolicies.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Register explicit Evidence-backed function comparison. */
|
||||
export const registerFunctionComparisonTool = (
|
||||
@@ -89,7 +89,7 @@ export const registerFunctionComparisonTool = (
|
||||
rightIds,
|
||||
}),
|
||||
);
|
||||
return toCallToolResult(recorded, contract);
|
||||
return toEvidenceToolResult(evidence, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
STATIC_RUNTIME_PROVIDER,
|
||||
} from "./sessionToolPolicies.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Register Evidence-composed differential investigation workflows. */
|
||||
export const registerInvestigationTools = (
|
||||
@@ -101,7 +101,7 @@ const registerChangedBehavior = (
|
||||
],
|
||||
},
|
||||
);
|
||||
return toCallToolResult(recorded, contract);
|
||||
return toEvidenceToolResult(evidence, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -158,7 +158,7 @@ const registerCallPath = (
|
||||
],
|
||||
},
|
||||
);
|
||||
return toCallToolResult(recorded, contract);
|
||||
return toEvidenceToolResult(evidence, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -198,7 +198,9 @@ const registerStaticRuntime = (
|
||||
limitations: result.limitations,
|
||||
evidenceLinks: links,
|
||||
});
|
||||
return toCallToolResult(
|
||||
return toEvidenceToolResult(
|
||||
evidence,
|
||||
contract,
|
||||
recordWorkflowEvidence(
|
||||
session,
|
||||
evidence,
|
||||
@@ -218,7 +220,6 @@ const registerStaticRuntime = (
|
||||
],
|
||||
},
|
||||
),
|
||||
contract,
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -255,7 +256,9 @@ const registerReconstruction = (
|
||||
limitations: result.limitations,
|
||||
evidenceLinks: links,
|
||||
});
|
||||
return toCallToolResult(
|
||||
return toEvidenceToolResult(
|
||||
evidence,
|
||||
contract,
|
||||
recordWorkflowEvidence(session, evidence, result.status === "unknown", {
|
||||
question: "Does the reconstruction satisfy every declared claim?",
|
||||
domain: "reconstruction-verification",
|
||||
@@ -266,7 +269,6 @@ const registerReconstruction = (
|
||||
rationale,
|
||||
})),
|
||||
}),
|
||||
contract,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Bind optional recovery to its exact named contract without acquiring an engine. */
|
||||
export const registerJavaScriptRecoveryTool = (
|
||||
@@ -24,9 +24,7 @@ export const registerJavaScriptRecoveryTool = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ import { observeJavaScriptRuntimeInputSchema } from "../domain/javascript/javasc
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
interface RuntimeToolRegistration {
|
||||
readonly logger: Logger;
|
||||
@@ -83,7 +83,5 @@ const runRuntimeTool = async <Input>(
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = options.recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult({ ok: true, value: result.value }, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ import { compareManagedMembersEvidenceValidated } from "../../application/manage
|
||||
import { managedMemberComparisonResultSchema } from "../../domain/managed/managedMemberComparison.js";
|
||||
import { logToolExecution } from "../toolLogging.js";
|
||||
import { toolRegistrationOptions } from "../toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "../toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "../toolResult.js";
|
||||
import { managedWorkflowContract } from "./contract.js";
|
||||
import { resolveManagedEvidence } from "./evidence.js";
|
||||
import type { ManagedWorkflowToolRegistration } from "./types.js";
|
||||
@@ -68,12 +68,7 @@ export const registerCompareManagedMembers = (
|
||||
relationships: [],
|
||||
})
|
||||
: options.recordEvidence?.(result.value);
|
||||
if (output !== undefined && !output.ok)
|
||||
return toCallToolResult(output, compareContract);
|
||||
return toCallToolResult(
|
||||
{ ok: true, value: result.value },
|
||||
compareContract,
|
||||
);
|
||||
return toEvidenceToolResult(result.value, compareContract, output);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { McpServer } from "@modelcontextprotocol/server";
|
||||
import { importManagedReconstructionEvidenceValidated } from "../../application/managed/ManagedReconstructionService.js";
|
||||
import { logToolExecution } from "../toolLogging.js";
|
||||
import { toolRegistrationOptions } from "../toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "../toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "../toolResult.js";
|
||||
import { managedWorkflowContract } from "./contract.js";
|
||||
import { resolveManagedEvidence } from "./evidence.js";
|
||||
import type { ManagedWorkflowToolRegistration } from "./types.js";
|
||||
@@ -41,9 +41,11 @@ export const registerImportManagedReconstruction = (
|
||||
if (recordedSource !== undefined && !recordedSource.ok)
|
||||
return toCallToolResult(recordedSource, reconstructionContract);
|
||||
const recorded = options.recordEvidence?.(result.value);
|
||||
if (recorded !== undefined && !recorded.ok)
|
||||
return toCallToolResult(recorded, reconstructionContract);
|
||||
return toCallToolResult(result, reconstructionContract);
|
||||
return toEvidenceToolResult(
|
||||
result.value,
|
||||
reconstructionContract,
|
||||
recorded,
|
||||
);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { McpServer } from "@modelcontextprotocol/server";
|
||||
import { projectManagedApplicationGraphEvidence } from "../../application/managed/ManagedApplicationGraphService.js";
|
||||
import { logToolExecution } from "../toolLogging.js";
|
||||
import { toolRegistrationOptions } from "../toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "../toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "../toolResult.js";
|
||||
import { managedWorkflowContract } from "./contract.js";
|
||||
import {
|
||||
resolveManagedArtifactEvidence,
|
||||
@@ -63,9 +63,7 @@ export const registerProjectManagedApplicationGraph = (
|
||||
if (!recordedSources.ok)
|
||||
return toCallToolResult(recordedSources, graphContract);
|
||||
const recorded = options.recordEvidence?.(result.value);
|
||||
if (recorded !== undefined && !recorded.ok)
|
||||
return toCallToolResult(recorded, graphContract);
|
||||
return toCallToolResult(result, graphContract);
|
||||
return toEvidenceToolResult(result.value, graphContract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ import { verifyManagedNativeBoundariesEvidence } from "../../application/managed
|
||||
import { managedNativeVerificationResultSchema } from "../../domain/managed/managedNativeVerification.js";
|
||||
import { logToolExecution } from "../toolLogging.js";
|
||||
import { toolRegistrationOptions } from "../toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "../toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "../toolResult.js";
|
||||
import { managedWorkflowContract } from "./contract.js";
|
||||
import {
|
||||
resolveManagedBoundaryEvidence,
|
||||
@@ -90,9 +90,11 @@ export const registerVerifyManagedNativeBoundaries = (
|
||||
relationships: [],
|
||||
})
|
||||
: options.recordEvidence?.(result.value);
|
||||
if (output !== undefined && !output.ok)
|
||||
return toCallToolResult(output, nativeVerificationContract);
|
||||
return toCallToolResult(result, nativeVerificationContract);
|
||||
return toEvidenceToolResult(
|
||||
result.value,
|
||||
nativeVerificationContract,
|
||||
output,
|
||||
);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ import type { Logger } from "../logger.js";
|
||||
import { mcpProgressReporter } from "./mcpProgress.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Optional session services used by direct tool registration. */
|
||||
export interface OfficialToolRegistration {
|
||||
@@ -91,9 +91,7 @@ const registerOfficialTool = (
|
||||
},
|
||||
);
|
||||
const recorded = registration.recordEvidence?.(evidence);
|
||||
if (recorded !== undefined && !recorded.ok)
|
||||
return toCallToolResult(recorded, contract);
|
||||
return toCallToolResult({ ok: true, value: evidence }, contract);
|
||||
return toEvidenceToolResult(evidence, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ import { recordSessionEvidenceSources } from "./sessionEvidence.js";
|
||||
import { runDerivedOperation } from "./runDerivedOperation.js";
|
||||
import { PROCESS_PROVIDER } from "./sessionToolPolicies.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
const PROCESS_CAPTURE_EVIDENCE = {
|
||||
operation: "capture_process_scenario",
|
||||
@@ -143,7 +143,9 @@ export const registerProcessComparisonTool = (
|
||||
);
|
||||
if (!recordedSources.ok)
|
||||
return toCallToolResult(recordedSources, contract);
|
||||
return toCallToolResult(
|
||||
return toEvidenceToolResult(
|
||||
evidence,
|
||||
contract,
|
||||
recordDerivedEvidence(
|
||||
session,
|
||||
evidence,
|
||||
@@ -156,7 +158,6 @@ export const registerProcessComparisonTool = (
|
||||
comparison,
|
||||
),
|
||||
),
|
||||
contract,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Bind recorded crash inspection to its named contract and session Evidence owner. */
|
||||
export const registerRecordedCrashTools = (
|
||||
@@ -24,9 +24,7 @@ export const registerRecordedCrashTools = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ import {
|
||||
} from "./sessionAvailabilityPolicy.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
const recordProcessResidualUnknowns = (
|
||||
session: BinarySessionPort,
|
||||
@@ -122,7 +122,7 @@ const registerProcessTools = ({
|
||||
captured.value.residual_unknowns,
|
||||
);
|
||||
if (!unknowns.ok) return toCallToolResult(unknowns, captureContract);
|
||||
return toCallToolResult(ok(evidence), captureContract);
|
||||
return toEvidenceToolResult(evidence, captureContract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Bind the module relationship workflow to its exact canonical contract. */
|
||||
export const registerWebModuleTool = (
|
||||
@@ -24,9 +24,7 @@ export const registerWebModuleTool = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Bind historical inspection to its named contract and caller-owned Evidence writer. */
|
||||
export const registerWebNetworkCaptureTool = (
|
||||
@@ -38,9 +38,7 @@ export const registerWebNetworkCaptureTool = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { Logger } from "../logger.js";
|
||||
import { mcpProgressReporter } from "./mcpProgress.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Bind distinct runtime operations to named contracts and the session's Evidence owner. */
|
||||
export const registerWebRuntimeTools = (
|
||||
@@ -29,9 +29,7 @@ export const registerWebRuntimeTools = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, execution);
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, execution)
|
||||
: toCallToolResult(result, execution);
|
||||
return toEvidenceToolResult(result.value, execution, recorded);
|
||||
},
|
||||
);
|
||||
server.registerTool(
|
||||
@@ -43,9 +41,7 @@ export const registerWebRuntimeTools = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, listeners);
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, listeners)
|
||||
: toCallToolResult(result, listeners);
|
||||
return toEvidenceToolResult(result.value, listeners, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Register local script export without requiring a live browser provider. */
|
||||
export const registerWebScriptTool = (
|
||||
@@ -26,9 +26,7 @@ export const registerWebScriptTool = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = options.recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
|
||||
|
||||
/** Bind source point tracing to its exact named contract and session Evidence owner. */
|
||||
export const registerWebSourceLocationTool = (
|
||||
@@ -24,9 +24,7 @@ export const registerWebSourceLocationTool = (
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return recorded !== undefined && !recorded.ok
|
||||
? toCallToolResult(recorded, contract)
|
||||
: toCallToolResult(result, contract);
|
||||
return toEvidenceToolResult(result.value, contract, recorded);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
import { STDIO_DEFAULT_MAX_BUFFER_SIZE } from "@modelcontextprotocol/server";
|
||||
|
||||
import type { ToolContract } from "../contracts/toolContracts.js";
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { type AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
@@ -28,6 +29,22 @@ export const toCallToolResult = (
|
||||
? successResult(result.value, contract, context)
|
||||
: errorResult(result.error);
|
||||
|
||||
/** Deliver Evidence using the producer's explicit recording acknowledgment. */
|
||||
export const toEvidenceToolResult = (
|
||||
evidence: Evidence,
|
||||
contract: ToolContract,
|
||||
recorded: Result<unknown, AnalysisError> | undefined,
|
||||
): CallToolResult =>
|
||||
recorded !== undefined && !recorded.ok
|
||||
? errorResult(recorded.error)
|
||||
: toCallToolResult(
|
||||
{ ok: true, value: evidence },
|
||||
contract,
|
||||
recorded === undefined
|
||||
? undefined
|
||||
: { retainedEvidenceId: evidence.evidence_id },
|
||||
);
|
||||
|
||||
const errorResult = (error: AnalysisError): CallToolResult => {
|
||||
const projected = projectAnalysisError(error);
|
||||
const structuredContent = { error: projected };
|
||||
@@ -66,8 +83,8 @@ const successResult = (
|
||||
contract.name,
|
||||
"transport",
|
||||
encoded.constraint === "string-length"
|
||||
? "The complete MCP response exceeds Node's single-string representation limit. Use a focused retained-Evidence query or export to consume the complete analysis."
|
||||
: "The complete MCP response exceeds the stdio response budget. The analysis result was not truncated; use a focused retained-Evidence query or export to consume it.",
|
||||
? "The operation completed, but its complete MCP response exceeds Node's single-string representation limit. Export retained evidence to consume the complete analysis, or use complete CLI JSON output."
|
||||
: "The operation completed, but its complete MCP response exceeds the stdio response budget. The analysis result was not truncated; export retained evidence to consume it, or use complete CLI JSON output.",
|
||||
{
|
||||
boundary: "mcp-response",
|
||||
default_receive_buffer_bytes: STDIO_DEFAULT_MAX_BUFFER_SIZE,
|
||||
|
||||
Reference in New Issue
Block a user