Skip to content

Make MCP scalar and batch argument parsing type-safe #3791

@Widthdom

Description

@Widthdom

Found while dogfooding the locally built cdidx on branch codex/search-audit-issues-20260619.

Duplicate check: no open issue found for MCP scalar arguments GetValue type mismatch batch queries AsArray invalid argument.

Evidence:

  • src/CodeIndex/Mcp/McpToolHandlers.cs:382, :391, and :510 use GetValue<int>() for numeric arguments.
  • src/CodeIndex/Mcp/McpToolHandlers.cs:3816 uses args?["queries"]?.AsArray() for batch query input.

Problem:
Malformed MCP argument shapes should consistently return structured invalid-argument errors. Direct GetValue<T>() / AsArray() calls can throw for wrong JSON shapes unless every caller is protected by a wrapper.

Acceptance criteria:

  • Replace direct scalar/array extraction in MCP argument paths with TryGetValue or shared validators.
  • Return categorized MCP invalid-argument errors for wrong numeric or array types.
  • Add tests for string/object/array values supplied to numeric arguments and non-array batch_query.queries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcodex

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions