Skip to content

fix(mcp): complement #444 — limit upper-bound, filter asymmetry, prefix-match safety #476

Closed

Description

@Sinity

Problem

Complements the auth/validation/error-sanitization work in #444 with additional MCP surface fixes:

No upper bound on limit

mcp/server_support.py:81-94 — _clamp_limit enforces max(1, limit) but no upper bound. limit=10000000 → gigabyte JSON response, potential server crash.

search and list_conversations asymmetric filter surfaces

mcp/server_tools.py:31-122 — search can't filter by tag/title. list_conversations can't do FTS. Users needing "conversations with tag X about Y" are stuck.

resolve_id prefix matching dangerous on destructive ops

storage/backends/queries/conversations_identity.py:15-31 — delete_conversation(id="abc") deletes "abc123" if it's the only prefix match. Adding "abc456" later changes behavior from delete to ambiguity error. Destructive operations should require exact ID match.

get_stats_by passes user-controlled string through fragile whitelist

storage/backends/queries/stats.py:222-251 — validated by if/elif branches with safe fallback, not by type-level Literal["provider", "month", "year"]. Fragile if a branch is added that interpolates the value.

bulk_tag_conversations O(N×M) in separate transactions

mcp/server_mutation_tools.py:48-71 — nested for-loops, each add_tag has its own transaction + round-trip. No item-count limit.

Fix direction

  • Add min(limit, 1000) upper bound to _clamp_limit
  • Add tag/title/sort params to search, or merge into one unified tool
  • Add strict=True flag to resolve_id for destructive operations
  • Use Literal["provider", "month", "year"] for group_by
  • Batch tag operations in a single transaction with a size limit

Ref: #444
Discovered during adversarial audit 2026-04-26.


Severity note (2026-04-26): The security.py bare except is sloppy but low-risk in practice (is_symlink() only raises OSError). The benchmark/devtools issues are developer-facing only with no user impact. The assert statements in production code are real but python -O is vanishingly rare. Focus remediation on the search degradation and diagnostics findings, which have real user impact.

Activity

  1. Sinity commented on Apr 26, 2026

    @Sinity
    OwnerAuthor

    Partially addressed by #489. Remaining items tracked in this issue.

  2. added a commit that references this issue on Apr 27, 2026
    c691f4c
  3. added a commit that references this issue on May 7, 2026
    a8c6db1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions