refactor(server): admit complete evidence workflows and share handlers

Validation: integrated changes passed formatting, typecheck, lint, resolved module-boundary verification and git diff --check. Tests and real-provider workflows were not run.
This commit is contained in:
morluto
2026-10-11 00:03:24 +08:00
parent 5f30ea6ff2
commit c1b5ccf0a4
43 changed files with 1482 additions and 915 deletions
+29 -14
View File
@@ -30,6 +30,8 @@ import type { Logger } from "pino";
import { mcpProgressReporter } from "./mcpProgress.js";
import { logToolExecution } from "./toolLogging.js";
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
import type { WithAdmittedAnalysis } from "./analysisAdmission.js";
import { runAdmittedToolOperation } from "./admittedToolOperation.js";
interface ElectronToolRegistration {
readonly logger: Logger;
@@ -39,6 +41,7 @@ interface ElectronToolRegistration {
readonly electronActive: ElectronActiveObservationPort | undefined;
readonly recordEvidence: EvidenceWriter["recordEvidence"] | undefined;
readonly evidenceById: EvidenceLookup | undefined;
readonly withAdmittedAnalysis?: WithAdmittedAnalysis;
}
interface ElectronToolContext {
@@ -52,7 +55,7 @@ export const registerElectronTools = (
server: EvidenceMcpServer,
options: ElectronToolRegistration,
): void => {
const registration = { ...options, delivery: server.delivery };
const registration = { ...options, delivery: server.delivery, server };
const listContract = toolContract("list_electron_targets");
const inspectContract = toolContract("inspect_electron_page");
const analyzeContract = toolContract("analyze_javascript_application");
@@ -139,7 +142,10 @@ export const registerElectronTools = (
};
const runElectronTool = async <Input>(
options: ElectronToolRegistration & { readonly delivery: ToolResultDelivery },
options: ElectronToolRegistration & {
readonly delivery: ToolResultDelivery;
readonly server: EvidenceMcpServer;
},
contract: ToolContract,
request: {
readonly input: Input;
@@ -163,17 +169,26 @@ const runElectronTool = async <Input>(
err(optionalProviderUnavailable(failure, contract.name)),
contract,
);
const result = await logToolExecution(options.logger, contract.name, () =>
execute(input, {
signal: context.mcpReq.signal,
progress: mcpProgressReporter(context),
}),
);
if (!result.ok) return options.delivery.toCallToolResult(result, contract);
const recorded = options.recordEvidence?.(result.value);
return options.delivery.toEvidenceToolResult(
result.value,
contract,
recorded,
return runAdmittedToolOperation(
options.server,
options.withAdmittedAnalysis,
contract.name,
context.mcpReq.signal,
async () => {
const result = await logToolExecution(options.logger, contract.name, () =>
execute(input, {
signal: context.mcpReq.signal,
progress: mcpProgressReporter(context),
}),
);
if (!result.ok)
return options.delivery.toCallToolResult(result, contract);
const recorded = options.recordEvidence?.(result.value);
return options.delivery.toEvidenceToolResult(
result.value,
contract,
recorded,
);
},
);
};