MCP memory_prompt: support session-only and long_term_search modes#268
MCP memory_prompt: support session-only and long_term_search modes#268
Conversation
Update all documentation and READMEs to consistently describe search as supporting semantic, keyword, and hybrid modes instead of only semantic. Changes: - Expand feature descriptions to include keyword and hybrid search - Add SDK usage examples (Python, TypeScript/JS, Java) for keyword and hybrid search modes - Add full-text indexing table to long-term memory docs - Fix deprecated function reference in agent examples - Fix tuple unpacking order in error handling example - Update search capability descriptions across all guides Context: The server already supports keyword (BM25) and hybrid (RRF) search modes via the search_mode parameter, but documentation only referenced semantic search. This brings docs in line with actual capabilities. Refs: #251, #253
Forward search_mode, offset, and optimize_query through resolve_tool_call, MCP tools, and hydrate_memory_prompt. Remove hybrid_alpha and text_scorer from LLM-facing interfaces (MCP, tool schemas, LangChain) since these are server-level hyperparameters that LLMs cannot reliably tune. Changes: - Forward search_mode, offset, optimize_query in _resolve_search_memory - Add search_mode to MCP memory_prompt and search_long_term_memory - Remove hybrid_alpha and text_scorer from MCP tools and client tool schemas (kept in developer-facing hydrate_memory_prompt) - Align max_results default from 5 to 10 in _resolve_search_memory - Add distance_threshold validation for non-semantic search modes - Fix deprecated function references in tool descriptions and docstrings (search_memory -> search_memory_tool, get_working_memory -> get_or_create_working_memory) - Correct optimize_query docstrings in API and MCP - Make error message name-agnostic in client - Update MCP docs for search mode support Tests: - Add test for search_mode forwarding through resolve_function_call - Add test for search_mode forwarding through LangChain tool - Both tests verify hybrid_alpha/text_scorer are NOT in tool schemas - Update MCP parameter passing tests Design context (from #251 discussion): - @nkanu17: Hyperparameters like alpha, recency, and scorer config should be set at the server/session level, not by the LLM - @abrookins: MCP interface is intentionally smaller than REST API. LLMs can reason about search mode selection (semantic vs keyword vs hybrid) but struggle with arbitrary numeric tuning values - @tylerhutcherson: Questioned whether LLMs should toggle these params, leading to the decision to expose only search_mode - @vishal-bala: Cataloged full MCP/REST gaps in #253, confirmed remaining items are out of scope for this PR Refs: #251, #253
Move search_mode, hybrid_alpha, and text_scorer after limit, offset, and optimize_query to avoid breaking existing callers that pass those params positionally.
…d client - Forward event_date, recency_boost, recency_*_weight, recency_half_life_*, and server_side_recency through MCP search_long_term_memory and memory_prompt - Add same params to Python client hydrate_memory_prompt (at end of signature to preserve positional argument order) - Fix namespace injection: target 'memory_prompt' instead of 'hydrate_memory_prompt' - Import EventDate filter in mcp.py
… modes Add include_long_term_search param to memory_prompt so it can express: - Session + long-term search (default, existing behavior) - Session-only (include_long_term_search=False) - Long-term search only (no session_id) This addresses the memory_prompt mode gap from #253 while keeping the MCP interface intentionally smaller than REST per the design discussion on #251. Deliberately omits admin/operational tools (forget, sessions, summary views, tasks) that are better suited to the REST API and developer tooling rather than LLM-facing interfaces.
agent_memory_server/mcp.py
Outdated
| if distance_threshold is not None and search_mode != SearchModeEnum.SEMANTIC: | ||
| raise ValueError( | ||
| "distance_threshold is only supported for semantic search mode" | ||
| ) |
There was a problem hiding this comment.
Bug: Validation runs unconditionally before checking include_long_term_search
The validation for distance_threshold compatibility with search_mode occurs at lines 779-782, but this happens before checking whether include_long_term_search=True (line 808). This means if a user calls memory_prompt with:
memory_prompt(
query="test",
session_id={"eq": "session123"},
include_long_term_search=False,
distance_threshold=0.8,
search_mode="keyword"
)They will get an error "distance_threshold is only supported for semantic search mode" even though distance_threshold won't be used since long-term search is disabled.
Suggested fix:
Move the validation inside the if include_long_term_search: block (after line 808) so it only validates when the parameters will actually be used:
if include_long_term_search:
# Validate distance_threshold only when doing long-term search
if distance_threshold is not None and search_mode != SearchModeEnum.SEMANTIC:
raise ValueError(
"distance_threshold is only supported for semantic search mode"
)
# Build search payload...
search_payload = SearchRequest(
text=query,
# ...
)This matches the pattern used in search_long_term_memory at lines 603-606, where the validation happens right before the parameters are used.
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 16884348a9
ℹ️ 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".
There was a problem hiding this comment.
Pull request overview
This PR updates the MCP memory_prompt tool to support session-only hydration (no long-term search) and improves parity with the server’s existing search modes, while also updating client/tooling and docs to consistently describe semantic/keyword/hybrid search.
Changes:
- Add
include_long_term_searchto MCPmemory_promptto allow session-only vs session+long-term vs long-term-only modes. - Forward
search_mode(and additional search controls) through MCP and client tool-resolution paths; remove LLM exposure tohybrid_alpha/text_scorerwhere intended. - Update SDK/docs/examples and add/adjust tests to reflect semantic/keyword/hybrid search support.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
agent_memory_server/mcp.py |
Adds include_long_term_search mode selection to memory_prompt, updates namespace injection target, and expands/adjusts MCP search parameter handling. |
agent_memory_server/api.py |
Docstring clarification for optimize_query semantics across search modes. |
agent-memory-client/agent_memory_client/client.py |
Forwards additional tool-call args (search_mode, offset, optimize_query), aligns defaults, and expands hydrate_memory_prompt filter forwarding. |
agent-memory-client/agent_memory_client/integrations/langchain.py |
Adds search_mode to the LangChain search_memory tool wrapper and updates tool description. |
tests/test_mcp.py |
Extends MCP parameter-passing assertions to verify search_mode forwarding. |
tests/test_client_tool_calls.py |
Adds regression test ensuring search_mode is forwarded via resolve_function_call and hyperparams are not. |
agent-memory-client/tests/test_langchain_integration.py |
Adds test ensuring LangChain tool forwards search_mode and omits hyperparams. |
README.md |
Updates feature/architecture wording to include semantic/keyword/hybrid search. |
examples/README.md |
Updates example descriptions to mention semantic/keyword/hybrid search. |
docs/README.md |
Updates feature matrix wording to include semantic/keyword/hybrid search. |
docs/mcp.md |
Updates MCP docs to describe semantic/keyword/hybrid search modes. |
docs/quick-start.md |
Updates quick-start narrative to mention keyword and hybrid search. |
docs/long-term-memory.md |
Expands long-term memory docs to describe semantic/keyword/hybrid search and indexing. |
docs/typescript-sdk.md |
Adds keyword/hybrid search examples to TS SDK docs. |
docs/java-sdk.md |
Adds keyword/hybrid search examples to Java SDK docs. |
agent-memory-client/README.md |
Updates client README examples for get_or_create_working_memory and adds keyword/hybrid search examples. |
agent-memory-client/agent-memory-client-js/README.md |
Adds keyword/hybrid search examples and clarifies default semantic mode. |
docs/index.md |
Updates marketing text to mention semantic/keyword/hybrid search. |
docs/use-cases.md |
Updates guidance text to include keyword/hybrid search alongside semantic. |
docs/agent-examples.md |
Updates example bullets and corrects working-memory method usage in code sample. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ch guard The distance_threshold vs search_mode check was running unconditionally, causing session-only calls (include_long_term_search=False) to fail if incompatible search params were present but unused. Now the validation only triggers when long-term search is active, matching the pattern in search_long_term_memory.
- Session-only mode omits long_term_search from params - Session-only mode does not validate unused search params (distance_threshold) - Error when neither session_id nor include_long_term_search is active
ba4e46e to
60cd714
Compare

Summary
Adds
include_long_term_searchparameter to the MCPmemory_prompttool so it can express the three modes that the REST API already supports. This addresses the memory_prompt mode gap from #253.Also fixes a validation bug where
distance_thresholdwas checked unconditionally, causing session-only calls to fail with spurious errors.Context
The discussion on #251 established that the MCP interface should be intentionally smaller than the REST API. Specifically:
This PR follows that philosophy. It only adds one parameter that LLMs can meaningfully reason about: whether to include long-term search or just use session context.
Admin/operational tools (forget, list sessions, delete working memory, SummaryView CRUD, task polling) are intentionally left as REST-only. These are developer/operator concerns, not decisions an LLM should make.
Problem
The MCP
memory_prompttool always constructed a long-term search payload. It could not express:long_term_search=Trueshortcut vs explicit search payloadChanges
memory_prompttoolAdded
include_long_term_search: bool = Trueparameter. The tool now supports three modes:session_id, leaveinclude_long_term_search=Truesession_id, setinclude_long_term_search=Falsesession_id, leaveinclude_long_term_search=TrueValidation ensures at least one of
session_idorinclude_long_term_search=Trueis active.Session ID is intentionally excluded from the long-term search to avoid scoping long-term results to a single session (matching REST behavior).
Validation fix
Moved
distance_thresholdvssearch_modevalidation inside theif include_long_term_search:block so it only triggers when the search is actually performed. Previously, session-only calls with unused search params would raise a spuriousValueError.MCP tool surface changes (from parent PR #265)
This branch builds on #265, which added the following to both
search_long_term_memoryandmemory_prompt:event_date,recency_boost,recency_semantic_weight,recency_recency_weight,recency_freshness_weight,recency_novelty_weight,recency_half_life_last_access_days,recency_half_life_created_days,server_side_recencyhybrid_alpha,text_scorer(server-level hyperparameters that LLMs cannot reason about)These are intentional:
search_mode(semantic/keyword/hybrid) has established meanings an LLM can reason about, whilehybrid_alphaandtext_scorerare tuning knobs best configured at the server level.What this PR does NOT do
Per the MCP design philosophy discussed in #251:
get_working_memorywith model/token paramsTesting
New tests added
test_memory_prompt_session_only_mode: Verifies session-only mode omits long_term_searchtest_memory_prompt_session_only_ignores_search_params: Verifies session-only mode does not validate unused search paramstest_memory_prompt_no_session_no_search_raises: Verifies error when neither session nor search is activeRelated
Note
Medium Risk
Changes MCP tool behavior for
memory_promptand long-term search parameter handling, which can affect agent retrieval results and prompt construction. Risk is moderated by added/updated tests and mostly additive, backwards-compatible parameters.Overview
MCP
memory_promptnow supports session-only vs long-term-search modes. Addsinclude_long_term_search(defaultTrue) to allow session+LTM (default), session-only, or LTM-only hydration, and fixes validation so search-only constraints (e.g.,distance_threshold) are enforced only when long-term search runs.Search/tooling updates to reflect multi-mode retrieval. Client tool resolution now forwards
search_mode/pagination/optimize_queryforsearch_memory, updates defaults (e.g.,max_results), and documentation/SDK examples are refreshed to highlight semantic/keyword/hybrid search andget_or_create_working_memory, with tests added to verify parameter forwarding and new MCP modes.Written by Cursor Bugbot for commit 60cd714. This will update automatically on new commits. Configure here.