Skip to content

fix(mcp): express inspect_analysis_view selector constraints in the contract schema - #1705

Merged
morluto merged 1 commit into
morluto:mainfrom
sx4im:fix/inspect-analysis-view-selector-schema
Oct 11, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
sx4im:fix/inspect-analysis-view-selector-schema

Conversation

@sx4im

@sx4im sx4im commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #1695.

The item view of inspect_analysis_view declared its four selector alternatives independently of the selected collection, and only a superRefine enforced which selectors each collection accepts. Refinements don't survive JSON Schema conversion, so the draft-2020-12 schema advertised on tools/list accepted combinations the MCP server rejects: modules with index/name, sections with path, symbols with node_id.

This moves the collection/selector alternatives into the contract itself: a discriminated union on collection where modules takes path/node_id and sections/symbols take index/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.index flagged as an unknown argument) instead of the old custom refinement message.

Verification:

  • New boundary test registers the tool the same way the MCP server does, reads the advertised schema back from 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 accepted modules+index) and passes now.
  • npm run check:fast (typecheck, lint) and npm run verify:test-discovery are green.
  • Surrounding suites all green: domain analysis view tests (17), MCP boundary tests for this tool (8), CLI boundary tests (7), service tests (11), contract schema reference tests (9).

…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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T11:30:16.218404Z e1dbe0f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@CassieFox23

Copy link
Copy Markdown
Contributor

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.

Check Base Head
Focused tests, 5 files, 51 tests, Node 22, 24 and 26 not run all pass
New boundary test run on base source, Node 24 fails passes
Tools listed 170 170
The 4 bad requests: schema accepts all 4 rejects all 4
The 4 bad requests: server rejects all 4 rejects all 4
Valid requests the schema accepts yes yes
Valid requests the server answers yes yes, identical reply text to base
372 varied requests where schema and server disagree 10 0, on Node 22, 24 and 26

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

  • A successful module select by path. In my two small fixtures, every path was shared by an asset and a module. Both trees gave the same "select one by node_id" answer. The domain tests in the focused set cover path selection and pass.
  • Base on Node 22 and 26. Base ran on Node 24 only.
  • Newer main 693ed33. Its diff touches none of the analysis view, tool contract or MCP server files. I did not build or run it.
  • Inline evidence as the source, native function views and the full test suite.
  • The command line error text for the other three bad requests.

Thanks, sx4im, for the fix and its test. Thanks, N0zoM1z0, for the clear report with the table.

Exact error text

Modules with index or name, base, over MCP:

view.selector: Module items are selected by exact path or node_id, not index or name.

Sections or symbols with path or node_id, base, over MCP:

view.selector: Section and symbol items are selected by index or exact name, not path or node_id.

Both cases on head, over MCP:

view.selector: Invalid input

Modules with index on head, command line tool:

issues: view.selector.path missing_argument (expected string),
        view.selector.index unknown_argument,
        view.selector.node_id missing_argument (expected string)

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 built

The 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 diff

Head 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
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head: e1dbe0f. Base: 13e03e9
  • Other: Ajv 8.20.0 (MIT) and Vitest 5.0.3 (MIT), both from the repo's lockfile. The ELF layout tool needs Python. I used 3.14.7 in a throwaway venv. It held pwntools 4.15.0 (MIT and others), pyelftools 0.33 and Unicorn 2.1.2. The documented python setting for REA points at it. Every server ran with a throwaway HOME. Targets were a tiny C program and a two-file JavaScript folder. This post has no timings.
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 json

A 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) 🦊

@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: e1dbe0f02f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@morluto
morluto merged commit a8a9c4d into morluto:main Oct 11, 2026
31 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added the area: mcp MCP server, transport, and tool registration label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] inspect_analysis_view advertises selector combinations rejected by input validation

3 participants