Mem0 MCP Server

repository·main·Indexed 20 days ago

https://github.com/mem0ai/mem0-mcp

A Model Context Protocol (MCP) server that exposes the Mem0 long-term memory API as tools for LLMs. It enables agents to manage long-term memories—including adding, searching, updating, and deleting data—through a standardized interface. The server supports semantic search, graph memories, and scoped memory management via user, agent, app, or run IDs. It can be deployed locally, via Docker, or as a Smithery remote server.

Tokens
4.3K
Snippets
20
Records
25
Agent score
70%

What's inside mem0-mcp

  1. Connect to a Smithery Remote Server

    main

    To use the Mem0 MCP server via a Smithery remote server, configure the agent by setting MEM0_MCP_CONFIG_PATH to the Smithery configuration file and MEM0_MCP_CONFIG_SERVER to the remote server identifier.

    export MEM0_MCP_CONFIG_PATH=example/config-smithery.json
    export MEM0_MCP_CONFIG_SERVER=mem0-memory-mcp
    python example/pydantic_ai_repl.py
  2. Install the Mem0 MCP Server

    main

    You can install the mem0-mcp-server package using pip or uv to run it locally with any MCP-compatible client.

    Note: This project has been archived. For the official cloud-hosted version, use the Mem0 documentation.

    # Using uv
    uv pip install mem0-mcp-server
    
    # Using pip
    pip install mem0-mcp-server
  3. Deploy Mem0 MCP Server with Docker

    main

    To run the server in a containerized environment, build the image and run it with your API key. This creates an /mcp HTTP endpoint.

    1. Build the image:
    docker build -t mem0-mcp-server .
    1. Run the container:
    docker run --rm -d \
      --name mem0-mcp \
      -e MEM0_API_KEY=m0-... \
      -p 8080:8081 \
      mem0-mcp-server
    1. Monitor logs:
    docker logs -f mem0-mcp
    docker build -t mem0-mcp-server .
    
    docker run --rm -d \
      --name mem0-mcp \
      -e MEM0_API_KEY=m0-... \
      -p 8080:8081 \
      mem0-mcp-server
  4. Quick Start with Mem0 MCP Server and Pydantic AI

    main

    To interactively test the Mem0 MCP server using the provided Pydantic AI demo agent, install the package, set your required API keys, and run the REPL script. This setup allows you to test memory operations like remembering, searching, updating, and deleting memories through an interactive prompt.

    # Install the package
    pip install mem0-mcp-server
    # Or with uv
    uv pip install mem0-mcp-server
    
    # Set your API keys
    export MEM0_API_KEY="m0-..."
    export OPENAI_API_KEY="sk-openai_..."
    
    # Run the REPL
    python example/pydantic_ai_repl.py
  5. Run Mem0 MCP Server in a Docker Container

    main

    You can run the Mem0 MCP server as a standalone Docker container. When running the Pydantic AI agent against a Docker container, you must point the agent to the specific Docker configuration file and server name using environment variables.

    # Start Docker container
    docker run --rm -d \
      --name mem0-mcp \
      -e MEM0_API_KEY="m0-..." \
      -p 8080:8081 \
      mem0-mcp-server
    
    # Run agent pointing to Docker
    export MEM0_MCP_CONFIG_PATH=example/docker-config.json
    export MEM0_MCP_CONFIG_SERVER=mem0-docker
    python example/pydantic_ai_repl.py
  6. Configure Mem0 MCP Server connection modes

    main

    The Pydantic AI demo agent uses environment variables to determine which server configuration to load. Use these variables to switch between local, Docker, or remote (Smithery) environments:

    • MEM0_MCP_CONFIG_PATH: Path to the JSON configuration file.
    • MEM0_MCP_CONFIG_SERVER: The identifier/name of the server defined in the config.

    Available configuration files in the example directory:

    • config.json: Used for the default Local Server.
    • docker-config.json: Used to connect to a Docker container on port 8080.
    • config-smithery.json: Used to connect to a Smithery remote server.
  7. Configure an MCP client for Mem0

    main

    To use the Mem0 MCP server in a client like Claude Desktop, add the following configuration. You must provide your MEM0_API_KEY and can optionally set a MEM0_DEFAULT_USER_ID to scope memories to a specific user or handle.

    {
      "mcpServers": {
        "mem0": {
          "command": "uvx",
          "args": ["mem0-mcp-server"],
          "env": {
            "MEM0_API_KEY": "m0-...",
            "MEM0_DEFAULT_USER_ID": "your-handle"
          }
        }
      }
    }
  8. Test the server with the Pydantic AI agent

    main

    You can test the server immediately using the included Pydantic AI REPL. This requires setting both your MEM0_API_KEY and an OPENAI_API_KEY.

    # Install
    pip install mem0-mcp-server
    
    # Set keys
    export MEM0_API_KEY="m0-..."
    export OPENAI_API_KEY="sk-openai-..."
    
    # Run REPL
    cd mem0-mcp-server
    python example/pydantic_ai_repl.py

    To test different server configurations (like Docker or Smithery), set the MEM0_MCP_CONFIG_PATH and MEM0_MCP_CONFIG_SERVER environment variables before running the script.

    pip install mem0-mcp-server
    export MEM0_API_KEY="m0-..."
    export OPENAI_API_KEY="sk-openai-..."
    
    cd mem0-mcp-server
    python example/pydantic_ai_repl.py
  9. Configure the Mem0 MCP Server via Environment Variables

    main

    When running the Mem0 MCP Server in production environments (such as Smithery or other container hosts), you can override the default host and port using environment variables. This ensures the server respects the networking configuration injected by the host.

    Use the following environment variables:

    • HOST: Sets the network interface the server binds to.
    • PORT: Sets the port number the server listens on (must be an integer).
    # Example: Running the server on a specific host and port
    export HOST=0.0.0.0
    export PORT=8080
    python -m mem0_mcp_server.http_entry
  10. Configure the Mem0 MCP Server

    main

    The Mem0 MCP server requires an API key to function. You can provide configuration via environment variables or through the MCP client's session configuration (e.g., via Smithery).

    Environment Variables:

    • MEM0_API_KEY: Your Mem0 API key (Required).
    • MEM0_DEFAULT_USER_ID: The fallback user_id used when none is provided in tool calls. Defaults to mem0-mcp.
    • MEM0_ENABLE_GRAPH_DEFAULT: Whether to enable graph memory by default. Defaults to false.
    • HOST: The server host. Defaults to 0.0.0.0.
    • PORT: The server port. Defaults to 8081.
    export MEM0_API_KEY='your_api_key_here'
    export MEM0_DEFAULT_USER_ID='my_user'
  11. Configure the Mem0 MCP Server via ConfigSchema

    main

    When hosting the Mem0 MCP server (e.g., via Smithery or HTTP), use the ConfigSchema to define session-level overrides. This allows you to set a global API key and default identifiers that will be automatically applied to tool calls.

    # Configuration keys available in ConfigSchema:
    mem0_api_key: str  # Required Mem0 API key
    default_user_id: Optional[str]  # Injected into filters when unspecified
    enable_graph_default: Optional[bool]  # Default toggle when clients omit the flag
  12. Configure Mem0 MCP environment variables

    main

    The following environment variables control the behavior of the Mem0 MCP server:

    • MEM0_API_KEY (required): Your Mem0 platform API key.
    • MEM0_DEFAULT_USER_ID (optional): The default user_id injected into filters and write requests. Defaults to mem0-mcp.
    • MEM0_ENABLE_GRAPH_DEFAULT (optional): Enables graph memories by default. Defaults to false.
    • MEM0_MCP_AGENT_MODEL (optional): The default LLM used for the bundled Pydantic AI agent example. Defaults to openai:gpt-4o-mini.