Repository navigation
Surface over-limit MCP search as a tool error - #371
Open
PoisonGodv wants to merge 1 commit into
Open
PoisonGodv wants to merge 1 commit into
PoisonGodv wants to merge 1 commit into
Conversation
The MCP search_long_term_memory tool built its SearchRequest inside the broad try/except that turns failures into an empty MemoryRecordResults. A limit above 100 therefore came back as "no results" with isError=false instead of a validation error. Build the request before the try block so parameter validation errors reach the caller, matching memory_prompt and the REST endpoint (which already returns 422). Also document the 1-100 range on SearchRequest.limit, the REST API docs, and the Python client's search_long_term_memory docstring. Fixes redis#308
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SearchRequest.limitis capped at 100 (le=100). The REST endpoint already rejectslimit > 100with a 422 response, and the Python client raisesMemoryServerError. The MCPsearch_long_term_memorytool is different: it buildsSearchRequestinside a broadtry/except Exceptionthat returnsMemoryRecordResults(total=0, memories=[]). Solimit=101comes back as a successful, empty result (isError=false), which looks exactly like "no matching memories" (#308).Reproduced on
main:Fix
mcp.py: buildSearchRequestbefore thetryblock, so validation errors reach the caller as a tool error. This matchesmemory_promptand the REST endpoint. Errors raised during the search itself still use the existing fallback.SearchRequest.limit(which feeds the OpenAPI schema), indocs/api.md, in the MCP tool docstring, and in the client'ssearch_long_term_memorydocstring.Tests
tests/test_mcp.py::TestMCP::test_search_long_term_memory_rejects_limit_above_maximum. It fails onmain(isError=False) and passes with the fix.tests/test_api.py::TestSearchEndpoint::test_search_rejects_limit_above_maximum, which locks in the REST 422 behavior.uv run pytest: 864 passed, 109 skipped.uv run pytest tests/test_api.py -k TestSearchEndpoint --run-api-tests: 8 passed. All search calls are mocked; a dummyOPENAI_API_KEYwas set.agent-memory-client:uv run pytest tests: 88 passed, 9 skipped.Fixes #308
Notes
SearchRequestconstruction out of thetryalso turns otherSearchRequestvalidation failures (e.g. negativeoffset,hybrid_alphaoutside 0-1) into tool errors instead of empty results.--run-api-tests, so default CI skips it.docs/api.mdwas edited by hand; theSearchRequest.limitfield description inmodels.pyis the source of truth.max_resultsmaximum 20, andvalidate_memory_search_filtersonly checks the lower bound.Note
Low Risk
Targeted validation-order fix and documentation; search execution error handling is unchanged. Low risk aside from callers that relied on silent empty results for invalid limits.
Overview
Fixes #308: MCP
search_long_term_memoryno longer returns a successful empty result whenlimitexceeds the server cap.MCP behavior:
SearchRequestis built before the broadtry/exceptinmcp.py, so Pydantic validation (e.g.limit> 100) fails as a tool error instead of being caught and turned into{total: 0, memories: []}. Runtime search failures still use the existing empty-result fallback.Docs: Clarifies that search
limitis 1–100 inSearchRequest(models.py),docs/api.md, the MCP tool docstring, and the Python clientsearch_long_term_memorydocstring (422 /MemoryServerErroron REST).Tests: Adds MCP test asserting
limit=101is an error with no search call, and REST test asserting 422 onlimit=101.Reviewed by Cursor Bugbot for commit e4c3d4b. Bugbot is set up for automated code reviews on this repo. Configure here.