Files
rea/src/server/registerAndroidTools.ts
T
akushonkamenandGitHub 7a0140b4aa fix(android): bound inline search Evidence with retained inventory provenance (#1890)
Focused and zero-match search_android_classes responses embedded every
examined class name: JadxSession records each raw list_classes page into
observed calls, those calls ride into Evidence raw_result on the
registration path, and the complete inline Evidence is serialized into
every tool response (issue #1850: 382,435 bytes for one match).

When the server session retains Evidence, record the complete raw-call
record first, then deliver a summary Evidence that keeps the pagination
audit (totals, offsets, page sizes, elided item counts), the unchanged
normalized matches and truthful coverage metadata, and links the
retained complete inventory by Evidence ID. Sessions without retention
keep the complete inline delivery, so complete CLI JSON output is
unchanged and no provenance is discarded.

🤖 Generated with AI assistance (disclosure voluntary per repo policy)
2026-10-12 01:07:22 +08:00

77 lines
2.8 KiB
TypeScript

import type { EvidenceMcpServer } from "./EvidenceMcpServer.js";
import type { EvidenceWriter } from "../application/investigation/InvestigationRecordPort.js";
import { AndroidAnalysisService } from "../application/android/AndroidAnalysisService.js";
import { summarizeRetainedAndroidSearch } from "../application/android/AndroidSearchEvidenceSummary.js";
import { toolContract } from "../contracts/toolContracts.js";
import type { Logger } from "pino";
import {
createContractToolHandler,
type ContractToolService,
} from "./contractToolHandler.js";
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
import type { WithAdmittedAnalysis } from "./analysisAdmission.js";
/** Bind Android handlers to their exact named contracts through shared workflows. */
export const registerAndroidTools = (
server: EvidenceMcpServer,
service: AndroidAnalysisService,
logger: Logger,
recordEvidence?: EvidenceWriter["recordEvidence"],
withAdmittedAnalysis?: WithAdmittedAnalysis,
): void => {
const handler = createContractToolHandler(
server,
service,
logger,
recordEvidence,
withAdmittedAnalysis,
);
// Focused class searches keep complete raw inventory in the retained
// record and deliver a bounded summary inline; the generic handler then
// records and delivers the summary as the search contract's Evidence.
const searchService: ContractToolService<"search_android_classes"> = {
execute: async (operation, input, options) => {
const executed = await service.execute(operation, input, options);
if (!executed.ok) return executed;
return summarizeRetainedAndroidSearch(executed.value, recordEvidence);
},
};
const searchHandler = createContractToolHandler(
server,
searchService,
logger,
recordEvidence,
withAdmittedAnalysis,
);
const packageContract = toolContract("inspect_android_package");
server.registerTool(
packageContract.name,
toolRegistrationOptions(packageContract),
handler(packageContract),
);
const searchContract = toolContract("search_android_classes");
server.registerTool(
searchContract.name,
toolRegistrationOptions(searchContract),
searchHandler(searchContract),
);
const classContract = toolContract("inspect_android_class");
server.registerTool(
classContract.name,
toolRegistrationOptions(classContract),
handler(classContract),
);
const methodContract = toolContract("inspect_android_method");
server.registerTool(
methodContract.name,
toolRegistrationOptions(methodContract),
handler(methodContract),
);
const referencesContract = toolContract("trace_android_references");
server.registerTool(
referencesContract.name,
toolRegistrationOptions(referencesContract),
handler(referencesContract),
);
};