Repository navigation
feat(mcp): guide agents from argument-name mistakes in procedure and search tools (#2146) - #8649
Conversation
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. |
3695168 to
cb6d7fc
Compare
There was a problem hiding this comment.
💡 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".
[Medium impact] The PR appears safe to merge; no new actionable issue was found. SummaryAdds fixed recovery hints for known argument-name mistakes without accepting alternate argument names.
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"]
Reviews (5) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile |
…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.
… 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.
…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.
|
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. |
…-name-guidance-2146
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Hi @morluto, The Codex review thread ("Suppress replacement guidance for already-present fields") was already addressed in commit The branch has also been synced with |
Summary
Fixes #2146.
Helps LLM agents recover in a single turn when they leak argument names from neighboring MCP tools (
addressinstead ofprocedureon procedure tools,queryinstead ofpatternon 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:procedure_pseudo_code,procedure_assembly, andread_function_instructionswithaddressinstead ofprocedure(primed by preceding calls toresolve_containing_procedure,xrefs, orread_bytes).search_stringsandsearch_procedureswithqueryinstead ofpattern.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 forsearch_strings).Expected behavior:
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'.").count,unexpected) remain rejected as plainunknown_argumentissues without false suggestions.additionalProperties: false) and Zod/JSON Schema parity are strictly maintained.Change and scope
Closed Domain Argument Guidance (
src/domain/inputArgumentGuidance.ts):address↔procedure,query↔pattern).Bounded Issue Projection (
src/domain/inputIssueProjection.ts):expectedandmessageto matching rootunknown_argumentissues whenoperationis supplied.chargeProjectionbefore allocating guided issue objects to enforce conservative memory budget bounds.Remediation Action Presentation (
src/domain/analysisErrorPresentation.ts):AnalysisInputError.remediationActionwhen known mistaken argument names are present in rejected issues.Single-Owner Normalization in IDA (
src/ida/IdaInput.ts):parseIdaInputto delegate schema failure construction toanalysisInputErrorFromIssuesinstead of duplicating manualAnalysisInputErrorandprojectInputIssuesinstantiation.MCP SDK Validation Error Partitioning (
src/server/EvidenceMcpServerCore.ts):tooltoprojectInputIssueGroupsWithinBudget.partitionSdkDiagnostic, omitted the raw SDKUnrecognized key: ...slice fromremainingwhen 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 }).Documentation (
docs/mcp-contracts.md):Contract and boundary impact
src/domain/inputArgumentGuidance.tsowns the guidance definitions;src/domain/inputIssueProjection.tsandsrc/server/EvidenceMcpServerCore.tsproject and format them at the application/MCP boundaries.Not applicable (ordinary enhancement within existing error-projection boundaries).
Advertised JSON Schemas remain unchanged and strict (
additionalProperties: false). MCPinvalid_requesterror payloads carry targetedexpectedandmessagefields on guidedunknown_argumentissues and prepended remediation text.Provider-neutral. Applies across all MCP and CLI invocations.
None. Successful tool operations and recorded Evidence parameters strictly retain their canonical keys.
Not applicable.
None.
Expected effects:
Evidence and regression coverage
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 forprocedure_pseudo_code,search_strings, andread_function_instructions.Verified with unit tests that prior behavior returned plain
Unrecognized key: ...without guidance.Calling
procedure_pseudo_codewith{ 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'?" } ] } } }None.
For evidence-bearing changes:
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 skippednpm run docs:check— 6 turbo tasks passed, 9 readme conformance tests passednpm run check:fast— typecheck and lint passed (0 errors)Compatibility, safety, and release
None. Fully backward compatible.
Tested on Windows x64 with Node.js 26.
None.
Guidance uses static, secret-safe strings without reflecting raw caller values or leaking private data.
Author readiness
Human owner: @HarsH-1877
Before merge
type(scope): outcome.