feat(application): wire Android and Apple inventory graph tools (#852)

* feat(application): wire Android and Apple inventory graph tools

Expose project_android_application_graph and project_apple_application_graph
through CLI and MCP so authenticated inventory Evidence can be projected
without a provider launch.

* fix(application): use producer root occurrence IDs in graph examples

Catalog examples constructed root occurrence IDs from artifact_id +
logical_path, but inventory validation authenticates "." with
{ root: root_artifact_id }. Align the examples and regenerate catalogs
after rebasing onto main (application family count 11).

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
morluto
2026-10-07 13:34:48 +08:00
committed by GitHub
co-authored by Cursor Agent
parent da0970672d
commit e0fd8207a1
24 changed files with 501 additions and 35 deletions
@@ -0,0 +1,73 @@
import type { McpServer } from "@modelcontextprotocol/server";
import { projectAndroidApplicationEvidence } from "../../application/AndroidApplicationService.js";
import { projectAppleApplicationEvidence } from "../../application/AppleApplicationService.js";
import {
APPLICATION_TOOL_CONTRACTS,
applicationToolContract,
} from "../../contracts/applicationToolContracts.js";
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
import type { Evidence } from "../../domain/evidence.js";
import type { Result } from "../../domain/result.js";
import { recordSessionEvidenceSources } from "../sessionEvidence.js";
import { logToolExecution } from "../toolLogging.js";
import { toolRegistrationOptions } from "../toolRegistrationOptions.js";
import { toCallToolResult } from "../toolResult.js";
import { recordResult } from "./helpers.js";
import type { ApplicationToolRegistration } from "./types.js";
/** Register execution-free Android and Apple inventory projection tools. */
export const registerProjectMobileApplicationGraphTools = (
server: McpServer,
options: ApplicationToolRegistration,
): void => {
registerProjection({
server,
options,
contract: applicationToolContract("project_android_application_graph"),
project: projectAndroidApplicationEvidence,
});
registerProjection({
server,
options,
contract: applicationToolContract("project_apple_application_graph"),
project: projectAppleApplicationEvidence,
});
};
const registerProjection = (context: {
readonly server: McpServer;
readonly options: ApplicationToolRegistration;
readonly contract: (typeof APPLICATION_TOOL_CONTRACTS)[number];
readonly project: (input: unknown) => Result<Evidence, AnalysisError>;
}): void => {
const { server, options, contract, project } = context;
server.registerTool(
contract.name,
toolRegistrationOptions(contract),
async (input: unknown) => {
const result = await logToolExecution(options.logger, contract.name, () =>
Promise.resolve(project(input)),
);
if (!result.ok) return toCallToolResult(result, contract);
const recordedSources = recordSessionEvidenceSources(
options.recordEvidence,
inventoryEvidenceSources(input),
);
if (!recordedSources.ok)
return toCallToolResult(recordedSources, contract);
return recordResult(options, contract, result.value);
},
);
};
const inventoryEvidenceSources = (input: unknown): readonly Evidence[] => {
if (
typeof input !== "object" ||
input === null ||
!("inventory_evidence" in input) ||
!Array.isArray(input.inventory_evidence)
)
return [];
return input.inventory_evidence as readonly Evidence[];
};