Skip to main content
Full Code
This tutorial explains how to integrate Memobase with the Model Context Protocol (MCP) to provide your AI agents with persistent, long-term memory. By using the Memobase MCP server, your agents can store, retrieve, and search memories, making them stateful and context-aware across conversations.

What is MCP?

The Model Context Protocol is an open standard that allows AI assistants to securely connect to external data sources and tools. This enables them to access real-time information, execute functions, and maintain a persistent state, breaking free from the limitations of their training data.

Why Memobase + MCP?

Traditional AI conversations are stateless. The Memobase MCP server changes this by providing:
  1. Persistent Memory: Store conversation history and user preferences across sessions.
  2. Semantic Search: Find relevant context using natural language queries.
  3. User Profiles: Build a comprehensive understanding of users over time.
  4. Cross-Platform Compatibility: Works with any MCP-compatible client, such as Claude Desktop, Cursor, or Windsurf.

Setup

Prerequisites

  • Python 3.11+
  • A Memobase backend (either local or cloud)

Installation

We recommend using uv for installation:

Environment Configuration

Configure your .env file:

Running the MCP Server

Start the server using uv:
The server will be available at http://localhost:8050 with an SSE endpoint at /sse.

Client Integration

Configure your MCP client to connect to the Memobase server. For example, in Cursor, add this to your .cursor/mcp.json:

Available Tools

The Memobase MCP server exposes three powerful tools to your AI agent.

1. save_memory

Stores information in long-term memory with semantic indexing.

2. search_memories

Finds relevant context using natural language queries.

3. get_user_profiles

Retrieves a comprehensive, structured user profile.

Real-World Example

Without Memory:
User: “I prefer Python for backend development.” AI: “That’s great! Python is excellent for backend work.” Later… User: “What’s the best language for my new API?” AI: “There are many options, like Python, Node.js, or Go…”
With Memobase MCP:
User: “I prefer Python for backend development.” AI: “Got it. I’ll remember your preference for Python.” (Memory saved: “User prefers Python for backend development”) Later… User: “What’s the best language for my new API?” AI: (Searches memories) “Based on your preference for Python, I’d recommend using FastAPI or Django.”

Conclusion

The Memobase MCP server transforms stateless AI interactions into intelligent, context-aware conversations. By providing persistent memory through a standardized protocol, you can build AI applications that learn, remember, and deliver truly personalized experiences.