Skip to content

fix(mcp): refuse unreadable navigation selections before success - #2836

Closed
yasshmittal wants to merge 1 commit into
morluto:mainfrom
yasshmittal:fix/mcp-navigation-unreadable-selection
Closed

yasshmittal wants to merge 1 commit into
morluto:mainfrom
yasshmittal:fix/mcp-navigation-unreadable-selection

Conversation

@yasshmittal

Copy link
Copy Markdown
Contributor

Summary

Fixes #2516.

When a provider reported a null current document or current address, get_navigation_context returned success with that null, although its output contract requires both fields to be strings. Through MCP, the SDK then rejected the result and clients received a generic Output validation error with no structured diagnostic.

Problem and expected behavior

getNavigationContext (src/application/AnalysisContextQueries.ts) forwarded non-string observations into a successful result, and carried them through an explicit branch for a non-string address. An unreadable provider observation should become a typed provider-output failure before success delivery, consistent with resolveAnalysisDocument.

Change and scope

  • A non-string current document returns AnalysisOutputError("current_document", …).
  • A non-string current address returns AnalysisOutputError("current_address", …).
  • Both are refused before resolve_containing_procedure is called.
  • The branches that carried non-string selections into success are removed; they could only produce results the tool's own schema rejects.
  • The advertised string contract is unchanged, and empty strings remain valid as before.
  • An explicit document argument still skips current_document, and a cursor outside a procedure still returns procedure: null.

Contribution scope: an ordinary fix within existing boundaries; no maintainer scope decision applies.

Contract and boundary impact

  • Semantic owner and earliest changed stage: navigation composition in src/application/AnalysisContextQueries.ts.

  • Contribution scope fit and linked maintainer decision: not applicable (bug fix).

  • CLI and MCP/tool-catalog contract: output schema unchanged; unreadable selections now return a typed unreadable_output error instead of an SDK validation message.

  • Provider, bridge, target-format, or platform compatibility: providers that return string selections are unaffected.

  • Evidence, artifact, provenance, or reconstruction contract: unchanged.

  • Target selection, authority, upstream behavior, and cleanup details: unchanged.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

Evidence and regression coverage

  • Tests added or updated:

    • src/application/AnalysisContextQueries.test.ts: both null variants return AnalysisOutputError naming the unreadable operation, without calling resolve_containing_procedure.
    • tests/boundary/mcp/navigationContextMcp.test.ts (new): the production server and tool registration with a simulated provider and the in-memory MCP client. Both variants deliver a typed error (code: "unreadable_output", details.operation) and not Output validation error.
  • Base reproduction or other evidence: on the base revision all four tests fail. The MCP variants return Output validation error: … expected string, received null, as in the issue.

  • User-visible CLI/MCP output:

    {"error":{"code":"unreadable_output","details":{"operation":"current_address", …}}}
  • Remaining proof gaps: no live provider returning null was observed; the provider is simulated, as in the issue.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Host: Windows 11, Node.js 24.21.0.

  • npx vitest run src/application/AnalysisContextQueries.test.ts: 7 passed.
  • npx vitest run tests/boundary/mcp/navigationContextMcp.test.ts: 2 passed.
  • npx vitest run src/server src/application/CapabilityInventory.test.ts: 30 passed.
  • npm run check, npm run verify:test-discovery: passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Such calls previously failed with an SDK validation error; they now fail with a typed error.
  • Real Hopper/Ghidra, browser, or OS coverage: Windows only; simulated provider.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new I/O, process, or network behavior.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto morluto added bug Something isn't working area: mcp MCP server, transport, and tool registration area: domain Domain logic, errors, and pure functions P2: medium Medium priority issue labels Oct 13, 2026
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

getNavigationContext now returns AnalysisOutputError when the provider reports a non-string document or address, before asking for the containing procedure.

  • Navigation reports unreadable selections as typed errors.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[getNavigationContext] --> B[Explicit document or current_document]
  B --> C{Document is a string?}
  C -- No --> E[AnalysisOutputError]
  C -- Yes --> D[current_address]
  D --> F{Address is a string?}
  F -- No --> E
  F -- Yes --> G[resolve_containing_procedure]
  G --> H[Return navigation context]
Loading

Reviews (5) · Last reviewed commit: "fix(mcp): refuse unreadable navigation s..." · Reviewed by Greptile

@yasshmittal

Copy link
Copy Markdown
Contributor Author

The failing Build package job is compile stopping at src/android/JadxAnalysis.ts(366,3): error TS2322. That error also occurs on current main and is not touched by this PR, which changes only src/application/AnalysisContextQueries.ts and its tests. Those typecheck cleanly on the base this branch was cut from.

morluto added a commit to yasshmittal/rea that referenced this pull request Oct 13, 2026
@morluto
morluto force-pushed the fix/mcp-navigation-unreadable-selection branch 2 times, most recently from bbf972d to c57b107 Compare October 13, 2026 18:28
get_navigation_context forwarded a non-string current document or current
address into a successful result, which its own output contract rejects;
MCP clients then received a generic SDK output-validation error instead
of a typed diagnostic. Return an AnalysisOutputError naming the unreadable
observation, matching document resolution, and drop the branches that
carried non-string selections into success.

Fixes morluto#2516

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto
morluto force-pushed the fix/mcp-navigation-unreadable-selection branch 2 times, most recently from c57b107 to 08b6344 Compare October 13, 2026 18:59
morluto added a commit that referenced this pull request Oct 14, 2026
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.
@CassieFox23

Copy link
Copy Markdown
Contributor

Heads up: main already has this change in 80de314. The code is in src/application/AnalysisContextQueries.ts. It is listed on tracker #3582. If this PR still adds something main doesn't have, please say so here and I'll take it off the list. Thanks for the fix!

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Superseded by the delivered behavior on main: 80de3145e. Navigation selection rejects malformed document/address inputs through typed shared validation; both application and MCP tests cover the invalid selections. Closing this earlier proposal; the linked report is already resolved. Current main qualification passed: https://github.com/morluto/rea/actions/runs/38690953281.

@morluto morluto closed this Oct 15, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @yasshmittal for covering invalid navigation documents and addresses. Main returns typed navigation errors for those inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions area: mcp MCP server, transport, and tool registration bug Something isn't working P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(mcp): navigation query returns invalid success for malformed selection

3 participants