Skip to content

MCP paginated tools should cap offset before SQL queries #2895

Description

@Widthdom

Problem

MCP ReadOffset currently clamps only the lower bound with Math.Max(0, ...). Tools such as references, callers, callees, and symbols can pass very large offsets into SQL queries or follow-up count paths.

Large offsets can force SQLite to scan and discard many rows, and some graph paths also compute totals when offset > 0, making a single request far more expensive than the advertised limit suggests.

Suggested fix

Introduce a documented maximum offset for MCP pagination, reject or clamp values above it, and include the cap in the server limits metadata.

Evidence

  • src/CodeIndex/Mcp/McpToolHandlers.cs: ReadOffset
  • src/CodeIndex/Database/DbReader.References.cs: queries use LIMIT @limit OFFSET @offset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions