Skip to content

feat(mcp): guide agents from argument-name mistakes in procedure and search tools (#2146) - #8649

Merged
morluto merged 6 commits into
morluto:mainfrom
HarsH-1877:feat/agent-argument-name-guidance-2146
Nov 6, 2026
Merged

morluto merged 6 commits into
morluto:mainfrom
HarsH-1877:feat/agent-argument-name-guidance-2146

Conversation

@HarsH-1877

@HarsH-1877 HarsH-1877 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2146.

Helps LLM agents recover in a single turn when they leak argument names from neighboring MCP tools (address instead of procedure on procedure tools, query instead of pattern on search tools, and their symmetric counterparts) by providing field-level recovery guidance (expected: "procedure", message: "Unrecognized argument 'address'; did you mean 'procedure'?") and targeted remediation actions without relaxing schema strictness, creating runtime aliases, or mutating canonical Evidence parameters.

Problem and expected behavior

In an empirical study across 40 runs with Claude Code (claude-sonnet-5-5) and Ghidra over MCP (321 calls), LLM agents suffered 18 input validation failures due to semantic priming / cross-tool parameter leakage:

  • Calling procedure_pseudo_code, procedure_assembly, and read_function_instructions with address instead of procedure (primed by preceding calls to resolve_containing_procedure, xrefs, or read_bytes).
  • Calling search_strings and search_procedures with query instead of pattern.

Generic Zod validation failures (pattern: Invalid input: expected string, received undefined, Unrecognized key: "query") caused the agent to drop the tool call completely (0 out of 4 runs recovered for search_strings).

Expected behavior:

  • Tool calls using known mistaken keys fail with actionable diagnostic guidance naming the right key (expected: "procedure", message: "Unrecognized argument 'address'; did you mean 'procedure'?") and a prepended remediation hint ("Use 'procedure' (a procedure name or address) instead of 'address'.").
  • Genuinely unknown keys (e.g. count, unexpected) remain rejected as plain unknown_argument issues without false suggestions.
  • Schema strictness (additionalProperties: false) and Zod/JSON Schema parity are strictly maintained.
  • Successful calls and recorded Evidence parameters remain canonical.

Change and scope

  1. Closed Domain Argument Guidance (src/domain/inputArgumentGuidance.ts):

    • Established a closed domain mapping for known argument-name confusion pairs (address ↔ procedure, query ↔ pattern).
    • Generates deterministic, format-safe diagnostic messages, expected canonical property names, and remediation action prefixes without fuzzy matching.
  2. Bounded Issue Projection (src/domain/inputIssueProjection.ts):

    • Attached field-level expected and message to matching root unknown_argument issues when operation is supplied.
    • Pre-calculates representation expansion inside chargeProjection before allocating guided issue objects to enforce conservative memory budget bounds.
  3. Remediation Action Presentation (src/domain/analysisErrorPresentation.ts):

    • Prepended targeted replacement advice to AnalysisInputError.remediationAction when known mistaken argument names are present in rejected issues.
  4. Single-Owner Normalization in IDA (src/ida/IdaInput.ts):

    • Refactored parseIdaInput to delegate schema failure construction to analysisInputErrorFromIssues instead of duplicating manual AnalysisInputError and projectInputIssues instantiation.
  5. MCP SDK Validation Error Partitioning (src/server/EvidenceMcpServerCore.ts):

    • Passed tool to projectInputIssueGroupsWithinBudget.
    • In partitionSdkDiagnostic, omitted the raw SDK Unrecognized key: ... slice from remaining when all unknown keys in that group carry their own field-level guidance message, ensuring each explanation appears exactly once in the MCP payload while preserving raw diagnostics for unexplained keys (e.g. { address: "0x401000", count: 10 }).
  6. Documentation (docs/mcp-contracts.md):

    • Documented the targeted argument-mistake recovery guidance on MCP SDK input validation errors.

Contract and boundary impact

  • Semantic owner and earliest changed stage:
    src/domain/inputArgumentGuidance.ts owns the guidance definitions; src/domain/inputIssueProjection.ts and src/server/EvidenceMcpServerCore.ts project and format them at the application/MCP boundaries.
  • Contribution scope fit and linked maintainer decision:
    Not applicable (ordinary enhancement within existing error-projection boundaries).
  • CLI and MCP/tool-catalog contract:
    Advertised JSON Schemas remain unchanged and strict (additionalProperties: false). MCP invalid_request error payloads carry targeted expected and message fields on guided unknown_argument issues and prepended remediation text.
  • Provider, bridge, target-format, or platform compatibility:
    Provider-neutral. Applies across all MCP and CLI invocations.
  • Evidence, artifact, provenance, or reconstruction contract:
    None. Successful tool operations and recorded Evidence parameters strictly retain their canonical keys.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable):
    Not applicable.
  • Generated metadata impact:
    None.

Expected effects:

  • Documentation or usability only; no target interaction.

Evidence and regression coverage

  • Tests added or updated:
    • src/domain/inputIssueProjection.test.ts: Unit tests covering bidirectional argument guidance (address ↔ procedure, query ↔ pattern), mixed known/unknown argument combinations, remediation action formatting, and pre-allocation budget accounting.
    • src/server/EvidenceMcpServer.test.ts: End-to-end MCP protocol tests verifyingwire serialization, diagnostic de-duplication, and error retention for procedure_pseudo_code, search_strings, and read_function_instructions.
  • Base reproduction or other evidence:
    Verified with unit tests that prior behavior returned plain Unrecognized key: ... without guidance.
  • User-visible CLI/MCP output:
    Calling procedure_pseudo_code with { address: "0x401000" } returns:
    {
      "error": {
        "code": "invalid_request",
        "remediation": {
          "action": "Use 'procedure' (a procedure name or address) instead of 'address'. Read the declared input schema or CLI usage for procedure_pseudo_code; if using MCP and the catalog may be stale, call tools/list. Correct the listed fields, then retry. Do not repeat the unchanged call."
        },
        "details": {
          "operation": "procedure_pseudo_code",
          "issues": [
            { "path": ["procedure"], "reason": "missing_argument", "expected": "string" },
            {
              "path": ["address"],
              "reason": "unknown_argument",
              "expected": "procedure",
              "message": "Unrecognized argument 'address'; did you mean 'procedure'?"
            }
          ]
        }
      }
    }
  • Remaining proof gaps:
    None.

For evidence-bearing changes:

  • 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

  • npm run test:local -- src/domain/inputIssueProjection.test.ts src/application/AnalysisInput.test.ts src/server/EvidenceMcpServer.test.ts — 21 passed (100%)
  • npm run test:local -- src/ida/IdaSessionClient.test.ts — 87 passed, 2 skipped
  • npm run docs:check — 6 turbo tasks passed, 9 readme conformance tests passed
  • npm run check:fast — typecheck and lint passed (0 errors)

Compatibility, safety, and release

  • Breaking changes or migration steps:
    None. Fully backward compatible.
  • Real Hopper/Ghidra, browser, or OS coverage:
    Tested on Windows x64 with Node.js 26.
  • Package or release metadata impact:
    None.
  • Security, privacy, process, or containment review:
    Guidance uses static, secret-safe strings without reflecting raw caller values or leaking private data.

Author readiness

Human owner: @HarsH-1877

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 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 ⚠️ Failed 2026-11-05T08:41:33.187324Z
We couldn’t complete this review. Comment @codex review to try again.
b3c61a0 New commits
ℹ️ 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.

@HarsH-1877
HarsH-1877 force-pushed the feat/agent-argument-name-guidance-2146 branch from 3695168 to cb6d7fc Compare November 2, 2026 07:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb6d7fc20e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/domain/inputIssueProjection.ts Resolved
@greptile-apps

greptile-apps Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; no new actionable issue was found.

Summary

Adds fixed recovery hints for known argument-name mistakes without accepting alternate argument names.

  • Known argument mix-ups now get a clear correction without being accepted.
  • MCP errors show each unknown-key explanation only once.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Strict input check rejects arguments"] --> B["Project rejected fields within budget"]
  B --> C{"Known mistake and correct key absent?"}
  C -- Yes --> D["Add expected key and fixed hint"]
  C -- No --> E["Keep ordinary field issue"]
  D --> F["Build correction advice"]
  E --> F
  F --> G["Send bounded error through existing overflow recovery"]
Loading

Reviews (5) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile

Comment thread src/domain/inputIssueProjection.test.ts Resolved
Comment thread src/domain/inputIssueProjection.test.ts Resolved
…sent (morluto#2146)

Suppress argument replacement guidance when the expected field is already present in the call input, preventing invalid suggestions such as advising procedure when procedure was already provided. Defrost explanatory prose assertions in tests and bind test cases to production toolContract schemas.
Comment thread src/domain/inputIssueProjection.test.ts Resolved
… in tests (morluto#2146)

Import named contract families (OFFICIAL_TOOL_CONTRACTS, APPLICATION_TOOL_CONTRACTS, ENHANCED_TOOL_CONTRACTS) instead of the full tool catalog per docs/testing.md. Replace hardcoded explanatory message and remediation strings with dynamic references to the owning guidance constants.
Comment thread src/domain/inputIssueProjection.test.ts Resolved
…to#2146)

Keep exact checks for expected replacement field names ('procedure', 'pattern', 'address', 'query') independent of the owning guidance helper per docs/testing.md, while retaining dynamic validation for message and remediation prose.
@morluto

morluto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Hey @HarsH-1877, thanks for putting this together, the addition looks useful. What's left: there is 1 unresolved review thread from Codex on an outdated line ("Suppress replacement guidance for already-present fields"); if it's already handled, resolving it is enough. Happy to get this in once that's sorted out.

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

@HarsH-1877

Copy link
Copy Markdown
Contributor Author

Hi @morluto,

The Codex review thread ("Suppress replacement guidance for already-present fields") was already addressed in commit d881881e6 (with projectUnrecognizedKeyIssues suppressing replacement guidance when the expected field is already present in the call input, along with unit test coverage). I've posted the explanation and marked the thread as resolved.

The branch has also been synced with upstream/main (b3c61a0fe), all tests and checks (check:fast, local tests) pass cleanly, and the PR is ready for merge!

@morluto
morluto merged commit 7e9cf83 into morluto:main Nov 6, 2026
49 checks passed
@morluto morluto mentioned this pull request Nov 11, 2026
3 tasks done
@morluto morluto added area: mcp MCP server, transport, and tool registration enhancement New feature or request labels Nov 22, 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 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Help agents recover from common argument-name mistakes in procedure and search tools

2 participants