Skip to main content
Glama
arjunkmrm

Mem0 MCP Server

search_memories

Search stored memories using natural language queries and filters to find relevant information across users, agents, or time periods.

Instructions

Run a semantic search over existing memories.

    Use filters to narrow results. Common filter patterns:
    - Single user: {"AND": [{"user_id": "john"}]}
    - Agent memories: {"AND": [{"agent_id": "agent_name"}]}
    - Recent memories: {"AND": [{"user_id": "john"}, {"created_at": {"gte": "2024-01-01"}}]}
    - Multiple users: {"AND": [{"user_id": {"in": ["john", "jane"]}}]}
    - Cross-entity: {"OR": [{"user_id": "john"}, {"agent_id": "agent_name"}]}

    user_id is automatically added to filters if not provided.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesNatural language description of what to find.
filtersNoAdditional filter clauses (user_id injected automatically).
limitNoMaximum number of results to return.
enable_graphNoSet true only when the user explicitly wants graph-derived memories.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'search_memories' tool. It processes the input query and filters, injects the default user_id into filters, constructs the payload, and calls the Mem0 client's search method.
    def search_memories(
        query: Annotated[str, Field(description="Natural language description of what to find.")],
        filters: Annotated[
            Optional[Dict[str, Any]],
            Field(default=None, description="Additional filter clauses (user_id injected automatically)."),
        ] = None,
        limit: Annotated[
            Optional[int], Field(default=None, description="Maximum number of results to return.")
        ] = None,
        enable_graph: Annotated[
            Optional[bool],
            Field(
                default=None,
                description="Set true only when the user explicitly wants graph-derived memories.",
            ),
        ] = None,
        ctx: Context | None = None,
    ) -> str:
        """Semantic search against existing memories."""
    
        api_key, default_user, graph_default = _resolve_settings(ctx)
        args = SearchMemoriesArgs(
            query=query,
            filters=filters,
            limit=limit,
            enable_graph=_default_enable_graph(enable_graph, graph_default),
        )
        payload = args.model_dump(exclude_none=True)
        payload["filters"] = _with_default_filters(default_user, payload.get("filters"))
        payload.setdefault("enable_graph", graph_default)
        client = _mem0_client(api_key)
        return _mem0_call(client.search, **payload)
  • Pydantic schema defining the input parameters for the search_memories tool, including query, filters, limit, and enable_graph.
    class SearchMemoriesArgs(BaseModel):
        query: str = Field(..., description="Describe what you want to find.")
        filters: Optional[Dict[str, Any]] = Field(
            None, description="Additional filter clauses; user_id is injected automatically."
        )
        limit: Optional[int] = Field(None, description="Optional maximum number of matches.")
        enable_graph: Optional[bool] = Field(
            None, description="Set True only when the user asks for graph knowledge."
        )
  • Registers the search_memories tool with the FastMCP server, providing a detailed description and usage examples for filters.
    @server.tool(
        description="""Run a semantic search over existing memories.
    
        Use filters to narrow results. Common filter patterns:
        - Single user: {"AND": [{"user_id": "john"}]}
        - Agent memories: {"AND": [{"agent_id": "agent_name"}]}
        - Recent memories: {"AND": [{"user_id": "john"}, {"created_at": {"gte": "2024-01-01"}}]}
        - Multiple users: {"AND": [{"user_id": {"in": ["john", "jane"]}}]}
        - Cross-entity: {"OR": [{"user_id": "john"}, {"agent_id": "agent_name"}]}
    
        user_id is automatically added to filters if not provided.
        """
    )
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: the semantic search nature, automatic user_id injection into filters, and the enable_graph parameter's specific usage condition. It doesn't cover rate limits, authentication needs, or pagination, but provides substantial operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded with the core purpose. The filter examples are valuable but slightly lengthy; every sentence earns its place by providing practical guidance, though it could be slightly more streamlined.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (semantic search with filters), no annotations, and the presence of an output schema, the description is complete enough. It covers purpose, usage, key behaviors, and parameter semantics thoroughly, making it self-sufficient for an agent to understand and invoke the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds significant value beyond the schema by explaining filter patterns with concrete examples, clarifying that user_id is automatically added, and providing context for enable_graph usage. This elevates the score above baseline.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Run a semantic search') and resource ('over existing memories'), distinguishing it from siblings like get_memories (likely a simpler retrieval) and add_memory/update_memory/delete_memory (write operations). It establishes this as a search-focused tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool (semantic search with filters) and includes practical filter examples for common scenarios. However, it doesn't explicitly state when NOT to use it or name specific alternatives among siblings (e.g., get_memories for unfiltered retrieval), which prevents a perfect score.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/arjunkmrm/mem0-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server