refactor(mcp): make analysis states unrepresentable (#468)
* refactor(config): parse capability settings into exact states * refactor(runtime): encode replay and process outcomes exactly * refactor: make analysis states unrepresentable * refactor(mcp): register canonical schemas with SDK * fix: preserve capability and catalog invariants * fix(build): remove stale compiled modules * fix(replay): update real verifier policy dependency * fix(package): verify the complete MCP catalog * fix(test): supply complete replay reload policy * refactor(contracts): centralize output schema lookup * refactor(mcp): delegate protocol boundaries to SDK * fix(browser): approve real source capture * fix(mcp): preserve catalog guidance
This commit is contained in:
@@ -1,29 +1,24 @@
|
||||
import type { McpServer } from "@modelcontextprotocol/server";
|
||||
|
||||
import {
|
||||
authorizeFileReadWithDeferredWrite,
|
||||
authorizeRootPermission,
|
||||
} from "../../application/DeferredFileAuthorization.js";
|
||||
import {
|
||||
commitReconstructionCoverage,
|
||||
queryReconstructionCoverage,
|
||||
} from "../../application/ReconstructionCoverageService.js";
|
||||
import { readReconstructionCoverageWorkspace } from "../../application/ReconstructionCoverageWorkspaceStore.js";
|
||||
import {
|
||||
authorizeFileReadWithDeferredWrite,
|
||||
authorizeRootPermission,
|
||||
} from "../../application/DeferredFileAuthorization.js";
|
||||
import { applicationToolContract } from "../../contracts/applicationToolContracts.js";
|
||||
import {
|
||||
reconstructionCoverageCommitInputSchema,
|
||||
reconstructionCoverageQueryInputSchema,
|
||||
} from "../../application/ReconstructionCoverageService.js";
|
||||
import { reconstructionClosureResultSchema } from "../../domain/reconstructionCoverage.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
EvidenceIntegrityError,
|
||||
} from "../../domain/errors.js";
|
||||
import { reconstructionClosureResultSchema } from "../../domain/reconstructionCoverage.js";
|
||||
import { err } from "../../domain/result.js";
|
||||
import { logToolExecution } from "../toolLogging.js";
|
||||
import { toCallToolResult } from "../toolResult.js";
|
||||
import { toolRegistrationOptions } from "../toolRegistrationOptions.js";
|
||||
import { safeParseToolInput } from "../toolInputValidation.js";
|
||||
import { toCallToolResult } from "../toolResult.js";
|
||||
import { coverageWorkspaceUri } from "./helpers.js";
|
||||
import type { ApplicationToolRegistration } from "./types.js";
|
||||
|
||||
@@ -49,12 +44,6 @@ const registerCommitTool = (
|
||||
commitContract.name,
|
||||
toolRegistrationOptions(commitContract),
|
||||
async (input, context) => {
|
||||
const parsed = safeParseToolInput(
|
||||
reconstructionCoverageCommitInputSchema,
|
||||
input,
|
||||
commitContract.name,
|
||||
);
|
||||
if (!parsed.ok) return toCallToolResult(parsed, commitContract);
|
||||
if (options.permissionAuthority === undefined)
|
||||
return toCallToolResult(
|
||||
err(
|
||||
@@ -69,7 +58,7 @@ const registerCommitTool = (
|
||||
const authorization = await authorizeFileReadWithDeferredWrite(
|
||||
options.permissionAuthority,
|
||||
{
|
||||
path: parsed.value.workspace_path,
|
||||
path: input.workspace_path,
|
||||
readCapability: "investigation_workspace_read",
|
||||
writeCapability: "investigation_workspace_write",
|
||||
operation: commitContract.name,
|
||||
@@ -83,22 +72,20 @@ const registerCommitTool = (
|
||||
options.logger,
|
||||
commitContract.name,
|
||||
() =>
|
||||
commitReconstructionCoverage(
|
||||
parsed.value,
|
||||
options.evidenceFilePolicy,
|
||||
{ signal: context.mcpReq.signal },
|
||||
),
|
||||
commitReconstructionCoverage(input, options.evidenceFilePolicy, {
|
||||
signal: context.mcpReq.signal,
|
||||
}),
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, commitContract);
|
||||
options.retainCoverageWorkspace?.(parsed.value.workspace);
|
||||
options.retainCoverageWorkspace?.(input.workspace);
|
||||
return toCallToolResult(result, commitContract, {
|
||||
resourceLinks:
|
||||
options.retainCoverageWorkspace === undefined
|
||||
? []
|
||||
: [
|
||||
{
|
||||
uri: coverageWorkspaceUri(parsed.value.workspace),
|
||||
name: parsed.value.workspace.workspace_id,
|
||||
uri: coverageWorkspaceUri(input.workspace),
|
||||
name: input.workspace.workspace_id,
|
||||
description:
|
||||
"Session-retained reconstruction coverage workspace revision",
|
||||
},
|
||||
@@ -116,12 +103,6 @@ const registerQueryTool = (
|
||||
queryContract.name,
|
||||
toolRegistrationOptions(queryContract),
|
||||
async (input, context) => {
|
||||
const parsed = safeParseToolInput(
|
||||
reconstructionCoverageQueryInputSchema,
|
||||
input,
|
||||
queryContract.name,
|
||||
);
|
||||
if (!parsed.ok) return toCallToolResult(parsed, queryContract);
|
||||
if (options.permissionAuthority === undefined)
|
||||
return toCallToolResult(
|
||||
err(
|
||||
@@ -137,7 +118,7 @@ const registerQueryTool = (
|
||||
options.permissionAuthority,
|
||||
{
|
||||
capability: "investigation_workspace_read",
|
||||
roots: [parsed.value.workspace_path],
|
||||
roots: [input.workspace_path],
|
||||
access: "read",
|
||||
operation: queryContract.name,
|
||||
},
|
||||
@@ -148,7 +129,7 @@ const registerQueryTool = (
|
||||
queryContract.name,
|
||||
() =>
|
||||
queryReconstructionCoverage(
|
||||
parsed.value,
|
||||
input,
|
||||
options.evidenceFilePolicy,
|
||||
Date.now(),
|
||||
{ signal: context.mcpReq.signal },
|
||||
@@ -157,7 +138,7 @@ const registerQueryTool = (
|
||||
if (result.ok && options.retainCoverageWorkspace !== undefined) {
|
||||
const closure = reconstructionClosureResultSchema.parse(result.value);
|
||||
const loaded = await readReconstructionCoverageWorkspace(
|
||||
parsed.value.workspace_path,
|
||||
input.workspace_path,
|
||||
options.evidenceFilePolicy,
|
||||
);
|
||||
if (!loaded.ok) return toCallToolResult(loaded, queryContract);
|
||||
|
||||
Reference in New Issue
Block a user