fix(mcp): provide native evidence paging continuation
Supply schema-validated inspect_analysis_view arguments after completed native function Evidence is recorded and exceeds MCP delivery capacity. Preserve the full canonical result and its provenance. Verify exact source paging, export and following-call usability through real Ghidra stdio MCP. Fixes #1849 Co-authored-by: Minghang Chamling <133689405+cold-atom@users.noreply.github.com> Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
co-authored by
factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Kaoru0822
parent
7cdb7981c3
commit
1449e8e051
@@ -3,12 +3,16 @@ import { STDIO_DEFAULT_MAX_BUFFER_SIZE } from "@modelcontextprotocol/server";
|
||||
|
||||
import type { ToolContract } from "../contracts/toolContractTypes.js";
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
import {
|
||||
INSPECT_ANALYSIS_VIEW_OPERATION,
|
||||
inspectAnalysisViewInputSchema,
|
||||
} from "../domain/analysisView/analysisView.js";
|
||||
import {
|
||||
projectAnalysisError,
|
||||
type AnalysisErrorProjection,
|
||||
} from "../domain/analysisErrorProjection.js";
|
||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";
|
||||
import type { Result } from "../domain/result.js";
|
||||
import { AnalysisResourceConstraintError } from "../domain/analysisErrorCore.js";
|
||||
import {
|
||||
@@ -22,6 +26,24 @@ export const createToolResultDelivery = (
|
||||
): ToolResultDelivery =>
|
||||
new ToolResultDelivery(maximumResponseBytes ?? STDIO_DEFAULT_MAX_BUFFER_SIZE);
|
||||
|
||||
/** Offer a named, schema-validated source page only for retained native analysis. */
|
||||
const nativeEvidenceContinuation = (
|
||||
evidence: Evidence,
|
||||
): Readonly<Record<string, JsonValue>> => {
|
||||
if (evidence.operation !== "analyze_function") return {};
|
||||
const input = inspectAnalysisViewInputSchema.safeParse({
|
||||
source: { kind: "retained-evidence", evidence_id: evidence.evidence_id },
|
||||
view: { kind: "native", facet: "pseudocode", offset: 0 },
|
||||
});
|
||||
if (!input.success) return {};
|
||||
return {
|
||||
continuation: {
|
||||
name: INSPECT_ANALYSIS_VIEW_OPERATION,
|
||||
arguments: jsonValueSchema.parse(input.data),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/** Immutable encoding and recovery policy shared by one MCP server. */
|
||||
export class ToolResultDelivery {
|
||||
readonly resultBudgetBytes: number;
|
||||
@@ -61,6 +83,7 @@ export class ToolResultDelivery {
|
||||
kind: "retained-evidence",
|
||||
evidence_id: evidence.evidence_id,
|
||||
},
|
||||
...nativeEvidenceContinuation(evidence),
|
||||
}),
|
||||
});
|
||||
}
|
||||
@@ -122,11 +145,14 @@ export class ToolResultDelivery {
|
||||
structuredContent: value,
|
||||
};
|
||||
const retainedEvidence = recovery.evidence_reference !== undefined;
|
||||
const recoveryAdvice = retainedEvidence
|
||||
? "Export retained evidence to consume the complete analysis, or use complete CLI JSON output."
|
||||
: encoded.constraint === "string-length"
|
||||
? "Use complete CLI JSON output to consume the analysis."
|
||||
: "Use a larger MCP response budget with a matching client receive buffer, or use complete CLI JSON output to consume the analysis.";
|
||||
const recoveryAdvice =
|
||||
recovery.continuation !== undefined
|
||||
? "Call inspect_analysis_view with the supplied continuation arguments to read retained pseudocode. Follow coverage.next_offset for subsequent pages; reduce the page limit if needed, or export the complete retained Evidence."
|
||||
: retainedEvidence
|
||||
? "Export retained evidence to consume the complete analysis, or use complete CLI JSON output."
|
||||
: encoded.constraint === "string-length"
|
||||
? "Use complete CLI JSON output to consume the analysis."
|
||||
: "Use a larger MCP response budget with a matching client receive buffer, or use complete CLI JSON output to consume the analysis.";
|
||||
return this.toErrorToolResult(
|
||||
new AnalysisResourceConstraintError(
|
||||
contract.name,
|
||||
@@ -144,6 +170,9 @@ export class ToolResultDelivery {
|
||||
constraint: encoded.constraint,
|
||||
...recovery,
|
||||
},
|
||||
recovery.continuation === undefined
|
||||
? undefined
|
||||
: { remediationAction: recoveryAdvice },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user