mirror of
https://github.com/morluto/rea.git
synced 2026-11-07 05:56:19 -10:00
refactor(mcp): reuse reverse engineering admission
This commit is contained in:
1 parent
3c0e021cb3
commit
e58feb48c3
2 files changed
+11
-33
No files matched your search
@@ -13,7 +13,7 @@ import type { WithAdmittedAnalysis } from "./analysisAdmission.js";
|
||||
* that tool's target-content provenance like any other of its results.
|
||||
*/
|
||||
export const runAdmittedToolOperation = async (
|
||||
server: EvidenceMcpServer,
|
||||
server: Pick<EvidenceMcpServer, "delivery">,
|
||||
admission: WithAdmittedAnalysis | undefined,
|
||||
operationName: string,
|
||||
signal: ServerContext["mcpReq"]["signal"],
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import type {
|
||||
CallToolResult,
|
||||
McpServer,
|
||||
ServerContext,
|
||||
} from "@modelcontextprotocol/server";
|
||||
import type { McpServer, ServerContext } from "@modelcontextprotocol/server";
|
||||
import type { Logger } from "pino";
|
||||
|
||||
import {
|
||||
@@ -13,11 +9,11 @@ import {
|
||||
import type { EvidenceLookup } from "../application/EvidenceInputResolver.js";
|
||||
import type { EvidenceWriter } from "../application/investigation/InvestigationRecordPort.js";
|
||||
import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { ToolContract } from "../contracts/toolContractTypes.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import type { ToolResultDelivery } from "./ToolResultDelivery.js";
|
||||
import type { WithAdmittedAnalysis } from "./analysisAdmission.js";
|
||||
import { runAdmittedToolOperation } from "./admittedToolOperation.js";
|
||||
import { AnalysisOutputError } from "../domain/analysisErrorCore.js";
|
||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import type { Result } from "../domain/result.js";
|
||||
@@ -48,11 +44,11 @@ export const registerReverseEngineeringTools = (
|
||||
objdump.name,
|
||||
toolRegistrationOptions(objdump),
|
||||
(input, context: ServerContext) =>
|
||||
runAdmitted(
|
||||
objdump,
|
||||
context,
|
||||
runAdmittedToolOperation(
|
||||
{ delivery },
|
||||
withAdmittedAnalysis,
|
||||
delivery,
|
||||
objdump.name,
|
||||
context.mcpReq.signal,
|
||||
async () => {
|
||||
const result = await logToolExecution(logger, objdump.name, () =>
|
||||
service.inspectWithObjdump(
|
||||
@@ -144,11 +140,11 @@ export const registerReverseEngineeringTools = (
|
||||
recordEvidence?.(result.value),
|
||||
);
|
||||
}
|
||||
return runAdmitted(
|
||||
rizin,
|
||||
context,
|
||||
return runAdmittedToolOperation(
|
||||
{ delivery },
|
||||
withAdmittedAnalysis,
|
||||
delivery,
|
||||
rizin.name,
|
||||
context.mcpReq.signal,
|
||||
async () => {
|
||||
if (invalidateSnapshotForExternalMutation !== undefined && parsed.ok)
|
||||
invalidateSnapshotForExternalMutation();
|
||||
@@ -175,21 +171,3 @@ export const registerReverseEngineeringTools = (
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const runAdmitted = async (
|
||||
contract: ToolContract,
|
||||
context: ServerContext,
|
||||
admission: WithAdmittedAnalysis | undefined,
|
||||
delivery: ToolResultDelivery,
|
||||
operation: () => Promise<CallToolResult>,
|
||||
): Promise<CallToolResult> => {
|
||||
if (admission === undefined) return operation();
|
||||
const admitted = await admission(
|
||||
contract.name,
|
||||
context.mcpReq.signal,
|
||||
async () => operation(),
|
||||
);
|
||||
return admitted.ok
|
||||
? admitted.value
|
||||
: delivery.toErrorToolResult(admitted.error, contract.returnsTargetContent);
|
||||
};
|
||||
Reference in new issue
Block a user