Repository navigation
fix(mcp): express inspect_analysis_view selector constraints in the contract schema - #1705
Conversation
…ontract schema The item view advertised its four selector alternatives independently of the selected collection, while collection-specific constraints lived only in a superRefine that does not survive JSON Schema conversion. Clients validating against tools/list could not discover that modules accept only path/node_id and sections/symbols accept only index/name. Replace the refined object with a discriminated union on collection so the converted draft-2020-12 schema rejects the same combinations the MCP server rejects. Runtime selection semantics are unchanged. Fixes morluto#1695
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
TL;DR: The fix works. The schema now rejects all four bad combinations from #1695. I found no request where the schema and the server disagree. One small cost: over MCP, the server's message for a wrong selector is now the generic "Invalid input". I compared head e1dbe0f with its base 13e03e9 (#1694). I used real stdio MCP. I checked requests with Ajv. It used the schema each tree lists on tools/list.
The 4 bad requests are modules with index, modules with name, sections with path and symbols with node_id. The valid ones are sections and symbols by index or name, and modules by node_id. The 10 base disagreements fit the pattern in the issue. The server still rejects every bad request, but the message changed. Base said which selectors the collection takes. Head says only "view.selector: Invalid input" over MCP. The hint now lives in the schema. A client that reads just the error no longer learns the rule. The exact text is in the first fold below. The command line tool is richer. For modules with index, head lists index as an unknown argument and path and node_id as missing. This matches the PR text. I ran that one request on Node 24 only. Not run
Thanks, sx4im, for the fix and its test. Thanks, N0zoM1z0, for the clear report with the table. Exact error textModules with index or name, base, over MCP: Sections or symbols with path or node_id, base, over MCP: Both cases on head, over MCP: Modules with index on head, command line tool: A bad collection name also gets a new MCP message on head. It says "Invalid discriminator value" and lists the three names. How the 372 requests were builtThe item requests used 6 collection values: modules, sections, symbols, a bad name, a missing one and a number. Each went out with every selector key combination, bad values and odd selector shapes. Each also went out with and without one extra key. The script set the Ajv verdict beside the server's input verdict. The server took or refused the same requests on base and head. Only the message text differed, on 212 requests. Of those, 186 are the new bad-collection wording. Schema diffHead splits the item entry into two choices. One is modules with a path or node_id selector. The other is sections or symbols with an index or name selector. The three diff hunks all sit in that area, plus the removal of the shared definitions for the old item entry. The pretty-printed JSON goes from 755 to 772 lines. Test setup
Commands# build each tree, Node 24
npm ci && npm run build && npm run test:prepare
# focused tests on head, once per Node
node node_modules/vitest/vitest.mjs run \
tests/boundary/mcp/toolSchemaValidity.test.ts \
src/domain/analysisView/analysisView.test.ts \
src/application/analysisView/AnalysisViewService.test.ts \
tests/boundary/mcp/analysisViewMcp.test.ts \
tests/boundary/cli/analysisViewCli.test.ts
# head's new test run on the base tree, Node 24
node node_modules/vitest/vitest.mjs run tests/boundary/mcp/toolSchemaValidity.test.ts
# stdio MCP client: node scripts/rea.mjs mcp, then tools/list and an Ajv check,
# then inspect_binary_layout and analyze_javascript_application with detail summary,
# then inspect_analysis_view with each request
# python for the ELF layout tool (env var set on every server)
REA_PWNTOOLS_PYTHON=/path/to/throwaway-venv/bin/python
# command line check, one request
node scripts/rea.mjs inspect-analysis-view '<request json>' --format jsonA request the base schema accepted and the head schema rejects: {"source":{"kind":"retained-evidence","evidence_id":"ev_..."},
"view":{"kind":"item","collection":"modules","selector":{"index":0}}}🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fixes #1695.
The item view of
inspect_analysis_viewdeclared its four selector alternatives independently of the selected collection, and only asuperRefineenforced which selectors each collection accepts. Refinements don't survive JSON Schema conversion, so the draft-2020-12 schema advertised ontools/listaccepted combinations the MCP server rejects:moduleswithindex/name,sectionswithpath,symbolswithnode_id.This moves the collection/selector alternatives into the contract itself: a discriminated union on
collectionwheremodulestakespath/node_idandsections/symbolstakeindex/name. Runtime behavior is unchanged; the same inputs are rejected and accepted as before. A mismatched selector now surfaces as selector-level union issues (e.g.view.selector.indexflagged as an unknown argument) instead of the old custom refinement message.Verification:
tools/list, and asserts all four invalid combinations are rejected by both the runtime schema and the advertised JSON Schema while the six valid ones are accepted by both. It failed before the fix (the advertised schema acceptedmodules+index) and passes now.npm run check:fast(typecheck, lint) andnpm run verify:test-discoveryare green.