Skip to content

feat: add context lines to memories MCP search#20997

Merged
jif-oai merged 5 commits into
mainfrom
jif/context-lines
May 4, 2026
Merged

feat: add context lines to memories MCP search#20997
jif-oai merged 5 commits into
mainfrom
jif/context-lines

Conversation

@jif-oai

@jif-oai jif-oai commented May 4, 2026

Copy link
Copy Markdown
Collaborator

Why

The paginated memories MCP search tool 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 separate read call. Adding a small amount of surrounding context makes individual hits much more usable while keeping the search response deterministic and line-addressable.

What changed

  • add an optional context_lines search argument and thread it through the MCP server into the local memories backend
  • change search matches to return the matched line_number plus a start_line_number and multi-line content block for the requested context window
  • update the search tool schema and description to document the new request/response shape
  • extend the local backend tests to cover zero-context matches, contextual results, pagination, and invalid cursors that point past the end of the result set

Testing

  • Added targeted unit coverage in memories/mcp/src/local_tests.rs
  • GitHub Actions are running for the branch

@jif-oai jif-oai changed the title feat: search add context lines feat: add context lines to memories MCP search May 4, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Base automatically changed from jif/s-pagination to main May 4, 2026 13:23
Co-authored-by: Codex <noreply@openai.com>
@jif-oai jif-oai merged commit 0269a46 into main May 4, 2026
26 checks passed
@jif-oai jif-oai deleted the jif/context-lines branch May 4, 2026 13:33
@github-actions github-actions Bot locked and limited conversation to collaborators May 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant