Repository navigation
Surface over-limit MCP search as a tool error - #371
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
|
Hi @abrookins, when you have time, could you please review this PR? It makes MCP search requests with |
|
@abrookins Gentle follow-up on this PR — the four workflow runs on head |
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.