Skip to content

Commit 80de314

Browse files
committed
fix(mcp): align advertised contracts and retain workflow evidence
Use one named input-schema projection for clients and catalog identity, preserve dialect declarations, and bound compact schema depth. Keep canonical SDK output validation when output advertisements are disabled. Release request-owned state on cancellation and carry upstream limitations through composed workflows. Preserve doctor full-output envelopes and validate navigation facts at their owner. Reviewed fixes: #2088, #2108, #2513, #2684, #2693, #2695, #2836, #2864, #2868, #2877, #2933, #2998, #3002, #3015. Validation: focused schema, SDK output-validation, context, and workflow tests passed; no schema dialect or canonical output validation was relaxed.
1 parent f690571 commit 80de314

42 files changed

Lines changed: 1798 additions & 315 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/mcp-contracts.md‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ after target content was read.
193193
## Retained application Evidence inputs
194194

195195
`analyze_javascript_application`, `inspect_binary_layout`, `inspect_artifact`,
196-
`inspect_wasm_artifact`, and `inspect_macho` accept `detail`:
196+
`inspect_wasm_artifact`, `inspect_macho`, and `decode_interface_builder`
197+
accept `detail`:
197198
`complete` (default) returns the complete analysis Evidence; `summary` records
198199
that complete Evidence in the session and returns the derived
199200
`inspect_analysis_view` summary Evidence instead. Its
@@ -276,6 +277,17 @@ symbols (Electron Framework: 2.5 MB of imports and exports, 3.3 KB as a
276277
summary), so select `detail: "summary"` on the first call. Delivery detail
277278
never reaches the native tools or changes the source Evidence ID.
278279

280+
Completed `decode_interface_builder` Evidence supports a summary and
281+
`view: {kind: "interface-builder", collection: "nodes", offset: 0, limit: 64}`.
282+
Collections are `documents`, `nodes`, `edges`, and `coverage`; for nodes and
283+
edges an optional `document` keeps rows whose evidence names that exact decoded
284+
`relative_path`, and an undecoded path is refused. The summary keeps every
285+
decoded document, the provider, node-kind, edge-relation and coverage-status
286+
counts, and whether the decoded graph is incomplete. Each page repeats
287+
`source_truncated`. A complete app graph often exceeds the default MCP response
288+
budget (XLD.app: 6.7 MB), so select `detail: "summary"` on the first call.
289+
Delivery detail never reaches the decoder or changes the source Evidence ID.
290+
279291
`trace_application_feature`, `trace_javascript_semantics`,
280292
`compare_application_versions`, `compare_source_to_bundle`, and
281293
`compare_javascript_export_shapes` accept complete inline application Evidence
@@ -671,7 +683,13 @@ advertised input schema within a 13,312-byte budget, measured to sit below
671683
Moonshot's observed cap (community measurements: a 13.7 KB schema is accepted
672684
while a ~15 KB one is rejected). The setting is read at startup; restart the
673685
server to apply changes, as with `REA_MCP_MAX_RESPONSE_BYTES`. The default
674-
value `full` keeps the complete advertisement unchanged.
686+
value `full` keeps the complete advertisement unchanged. Compact presentation
687+
also reduces schemas whose expanded JSON tree exceeds ten levels, the limit
688+
reported by strict-depth MCP clients in [#2813](https://github.com/morluto/rea/issues/2813).
689+
WorkBuddy/CodeBuddy gateways have also rejected full REA catalogs with an
690+
opaque `11133` error while accepting the compact profile
691+
([#2999](https://github.com/morluto/rea/issues/2999)); compatibility depends on
692+
the selected gateway and model.
675693

676694
The compact profile renders the same tool set, output schemas, annotations,
677695
and canonical server-side validation. It changes only the advertised input
@@ -696,6 +714,9 @@ JSON Schema:
696714
canonical schema still rejects malformed calls server-side, so callers
697715
following the reduced advertisement receive the canonical typed error
698716
instead of silent acceptance.
717+
- Schemas deeper than ten nodes use the same reduced projection, with
718+
root-property names, types, guidance, and required fields retained. The
719+
server continues to enforce the full canonical input contract.
699720

700721
Boundary tests pin every advertised compact schema to the budget, keep them
701722
valid JSON Schema that still accepts every canonical example. Client verification
@@ -711,6 +732,30 @@ identity. Explicit schema IDs and relative external reference bases are
711732
preserved. This keeps every tool and validation rule in discovery and does not
712733
change the SDK's catalog invalidation or availability checks.
713734

735+
Some stdio hosts reject a complete `tools/list` frame before they load any
736+
tools. The opt-in `REA_MCP_OUTPUT_SCHEMA_PROFILE=off` setting omits `outputSchema`
737+
from the advertised catalog for hosts with a small frame limit (the measured
738+
pi-web-ui failure and catalog breakdown are in [#2512](https://github.com/morluto/rea/issues/2512)).
739+
The default `full` profile is unchanged. With `off`, REA validates successful
740+
structured results against the same named canonical tool contract before
741+
delivery; it still returns complete `structuredContent` and text results.
742+
Only client-side schema discovery and validation are omitted, so hosts using
743+
this profile should rely on REA's validation and retain their usual response
744+
size limits.
745+
746+
### Function comparison limitations
747+
748+
`compare_functions` compares the `pseudocode` and `assembly` dimensions as
749+
exact provider text. A `changed` status establishes a textual difference, not a
750+
behavior change. Addresses and generated names are not normalized, so relocated
751+
labels can change these dimensions while `cfg` remains unchanged. Both text
752+
dimensions carry this limitation inline. Numeric constants remain part of the
753+
exact comparison. Reconstruction verification and static/runtime correlation
754+
retain limitations from the selected dimension; an overall function claim
755+
includes all dimension limitations. Equal CFGs establish only equal observed
756+
block sizes and successor relationships. Text from different provider
757+
identities remains unknown.
758+
714759
### Comparison input shapes
715760

716761
`compare_web_captures` accepts exactly one of two input shapes:

‎src/application/AnalysisContextQueries.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,43 @@ import {
1010
} from "./AnalysisProvider.js";
1111
import {
1212
AnalysisCancelledError,
13+
AnalysisOutputError,
1314
AnalysisProtocolError,
1415
} from "../domain/analysisErrorCore.js";
1516
import { err, ok } from "../domain/result.js";
1617

1718
const provider = { id: "fixture", name: "Fixture", version: "1" };
1819

1920
describe("analysis context queries: navigation", () => {
21+
it.each([
22+
[null, "0x401000", "current_document"],
23+
["fixture", null, "current_address"],
24+
] as const)(
25+
"rejects malformed %s / %s provider selection before returning success",
26+
async (document, address, operation) => {
27+
const analysis: AnalysisOperationPort = {
28+
execute: async (name) =>
29+
ok(
30+
createAnalysisExecution(
31+
name === "current_document" ? document : address,
32+
provider,
33+
),
34+
),
35+
};
36+
const result = await getNavigationContext(analysis, {});
37+
expect(result).toEqual(
38+
err(
39+
new AnalysisOutputError(
40+
operation,
41+
operation === "current_document"
42+
? "expected a document identity string"
43+
: "expected an address string",
44+
),
45+
),
46+
);
47+
},
48+
);
49+
2050
it("aggregates volatile navigation and treats a missing procedure as null", async () => {
2151
const calls: {
2252
operation: string;
@@ -70,6 +100,23 @@ describe("analysis context queries: navigation", () => {
70100
});
71101
});
72102

103+
it("preserves empty string selections accepted by the output contract", async () => {
104+
const analysis: AnalysisOperationPort = {
105+
execute: async (operation) =>
106+
ok(
107+
createAnalysisExecution(
108+
operation === "resolve_containing_procedure"
109+
? { found: false, procedure: null, reason: "not_in_procedure" }
110+
: "",
111+
provider,
112+
),
113+
),
114+
};
115+
await expect(getNavigationContext(analysis, {})).resolves.toEqual(
116+
ok({ document: "", address: "", procedure: null }),
117+
);
118+
});
119+
73120
it("uses an explicit document without passing it to current_document and preserves procedure failures", async () => {
74121
const calls: string[] = [];
75122
const failure = new AnalysisProtocolError("provider response malformed");

‎src/application/AnalysisContextQueries.ts‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import type {
44
AnalysisOperationPort,
55
} from "./AnalysisProvider.js";
66
import type { AnalysisError } from "../domain/analysisErrorBase.js";
7+
import { AnalysisOutputError } from "../domain/analysisErrorCore.js";
78
import type { JsonValue } from "../domain/jsonValue.js";
89
import { analysisBookmarkSchema } from "../domain/hopperValues.js";
910
import { resolveAnalysisDocument } from "./AnalysisDocument.js";
10-
import { ok, type Result } from "../domain/result.js";
11+
import { err, ok, type Result } from "../domain/result.js";
1112

1213
type Facet =
1314
| { readonly state: "available"; readonly value: JsonValue }
@@ -42,26 +43,27 @@ export const getNavigationContext = async (
4243
if (typeof document !== "string" && !document.ok) return document;
4344
const documentName =
4445
typeof document === "string" ? document : document.value.result;
45-
const documentArgs =
46-
typeof documentName === "string" ? parameters(documentName) : {};
46+
if (typeof documentName !== "string")
47+
return err(
48+
new AnalysisOutputError(
49+
"current_document",
50+
"expected a document identity string",
51+
),
52+
);
53+
const documentArgs = parameters(documentName);
4754
const address = await analysis.execute(
4855
"current_address",
4956
documentArgs,
5057
executionOptions(signal),
5158
);
5259
if (!address.ok) return address;
5360
if (typeof address.value.result !== "string")
54-
return ok({
55-
document: documentName,
56-
address: address.value.result,
57-
procedure: null,
58-
});
61+
return err(
62+
new AnalysisOutputError("current_address", "expected an address string"),
63+
);
5964
const procedure = await analysis.execute(
6065
"resolve_containing_procedure",
61-
parameters(
62-
typeof documentName === "string" ? documentName : undefined,
63-
address.value.result,
64-
),
66+
parameters(documentName, address.value.result),
6567
executionOptions(signal),
6668
);
6769
if (!procedure.ok) {

‎src/application/DirectAnalysis.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
workflowAnalysisProfile,
4343
} from "./InvestigationProviders.js";
4444
import {
45+
executeComposedWorkflow,
4546
createWorkflowEvidence,
4647
workflowSnapshotRecord,
4748
recordWorkflowUnknowns,
@@ -401,18 +402,17 @@ const executeAnalysisTool = async (input: {
401402
tool === "trace_native_ui_action"
402403
) {
403404
const { EnhancedTools } = await import("./EnhancedTools.js");
404-
const result = await new EnhancedTools(session).execute(
405-
tool,
406-
input.arguments,
407-
signal,
405+
const result = await executeComposedWorkflow(session, (observed) =>
406+
new EnhancedTools(observed).execute(tool, input.arguments, signal),
408407
);
409408
if (!result.ok) return { output: cliError(result.error) };
410409
const evidence = createWorkflowEvidence({
411410
target: input.openedTarget,
412411
operation: tool,
413412
parameters: input.arguments,
414-
result: result.value,
413+
result: result.value.result,
415414
upstreamProfile: evidenceProfile,
415+
upstreamLimitations: result.value.limitations,
416416
});
417417
return { output: evidence, evidence };
418418
}

0 commit comments

Comments
 (0)