Repository navigation
fix(mcp): SSE search_memories was leaking rejected/superseded memories - #7763
Conversation
The SSE MCP search_memories tool only filtered is_locked, while the REST MCP path (routers/mcp.py) also skips user_review=False (user-rejected) and invalid_at (superseded) memories. So agents hitting /v1/mcp/sse (e.g. external clients) could get stale or explicitly-rejected facts back from semantic search. Mirror the REST filter so both paths return only active, non-rejected memories. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Greptile SummaryThis PR fixes a data-leak in the SSE MCP
Confidence Score: 4/5The fix is correct and targeted — it closes the rejected/invalidated memory leak in the SSE path with minimal risk of regression. The two new filter conditions directly match the REST MCP path's logic and are safe to merge. Two non-blocking observations remain: the fetch size isn't inflated before filtering (so heavily-filtered queries return fewer results than requested), and locked memories are still included with truncated content via SSE while the REST path excludes them entirely. backend/routers/mcp_sse.py — specifically the Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[SSE search_memories request] --> B[vector_db.find_similar_memories]
B --> C[get_memories_by_ids]
C --> D{user_review is False?}
D -- Yes --> E[skip NEW]
D -- No --> F{invalid_at is not None?}
F -- Yes --> G[skip NEW]
F -- No --> H{is_locked?}
H -- Yes --> I[truncate content to 70 chars]
I --> J[append to results]
H -- No --> J
J --> K[sort by relevance_score]
K --> L[return memories]
|
| if mem.get('is_locked', False): | ||
| content = mem.get('content', '') | ||
| mem['content'] = (content[:70] + '...') if len(content) > 70 else content |
There was a problem hiding this comment.
is_locked treatment diverges from REST MCP path
In routers/mcp.py line 160, locked memories are excluded entirely from search_memories results (is_locked is in the same continue guard as user_review and invalid_at). The SSE path instead includes them with content truncated to 70 characters. This is a pre-existing SSE behavior left intentionally unchanged by this PR, but it means a locked fact is visible (in truncated form) via SSE while invisible via REST. Worth reconciling if both paths are meant to behave identically.
Problem
The SSE MCP
search_memoriestool (/v1/mcp/sse, used by external clients like personal agents) only filteredis_lockedwhen building results. The REST MCP path (routers/mcp.py) additionally skips:user_review is False— memories the user explicitly rejectedinvalid_at is not None— memories that were superseded by a newer factSo semantic search over SSE could return stale or user-rejected facts that the REST path correctly hides.
Fix
Mirror the REST filter in the SSE results loop — skip rejected/invalidated memories before returning. Locked-content truncation behavior is unchanged.
Verification
Reproduced on dev: created an active memory ("favorite language = Python") and a rejected one (
user_review=False, "= COBOL"), both vectorized. Vector search returns both; the old loop returned both (leaking COBOL), the fixed loop returns only Python.🤖 Generated with Claude Code