feat: add context lines to memories MCP search#20997
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1d8c6e67b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| query: args.query, | ||
| path: args.path, | ||
| cursor: args.cursor, | ||
| context_lines: args.context_lines.unwrap_or(0), |
There was a problem hiding this comment.
Clamp context_lines to prevent oversized search responses
context_lines is accepted without any upper bound and passed straight into search. With a very large value, each match can include almost an entire file (lines[start..end].join("\n")), so one request can produce huge allocations and JSON payloads, causing severe latency or OOM risk. Clamp this input similarly to max_results before executing the search.
Useful? React with 👍 / 👎.
Co-authored-by: Codex <noreply@openai.com>
Why
The paginated memories MCP
searchtool still returned only the matching line text, which made it harder for clients to present useful search results or decide whether they needed to follow up with a separatereadcall. Adding a small amount of surrounding context makes individual hits much more usable while keeping the search response deterministic and line-addressable.What changed
context_linessearch argument and thread it through the MCP server into the local memories backendline_numberplus astart_line_numberand multi-linecontentblock for the requested context windowTesting
memories/mcp/src/local_tests.rs