Skip to content

Tool handler parameter validation skips bounds check on optional integer arrays #1994

Description

@Widthdom

Summary

Several tools accept optional integer array parameters (e.g., names in symbols, queries in batch_query) but only validate non-empty at the collection level. At /Users/widthdom/Projects/mine/cdidx/CodeIndex/src/CodeIndex/Mcp/McpToolHandlers.cs:143-150, ReadStringList silently drops null, whitespace, and non-string elements without reporting truncation. A client sending ["", null, 123, "validName"] will silently reduce to ["validName"] with no indication that 3 invalid entries were dropped. For batch_query (line 1129-1135), a malformed queries array with invalid tool objects will add errors to resultsArray but never report how many entries were skipped before processing.

Where

  • McpToolHandlers.cs:143-150 ReadStringList silent filtering
  • McpToolHandlers.cs:187-202 ReadPathList silent filtering
  • McpToolHandlers.cs:323-340 symbols names validation with silent drops
  • McpToolHandlers.cs:1129-1155 batch_query queries array processing

Suggested approach

  1. Add a tryReadStringList overload that returns (values, invalidCount, invalidSamples).
  2. Track invalid entries during filtering and report count in error if invalidCount > 0.
  3. In batch_query, validate each queries[i] has required "tool" and "arguments" fields before processing.
  4. Return a summary object: ["valid_count", "invalid_count", "skipped_reasons"] to help clients debug input issues.
  5. Add tool description notes: "Empty or null entries in this list are silently dropped."
  6. Write integration tests sending mixed-valid-invalid arrays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions