Memory PostgreSQL MCP server

Provides long-term memory capabilities using PostgreSQL with pgvector for efficient semantic search across stored memories, enabling tagging, confidence scoring, and filtering for maintaining context across conversations.
Back to servers
Setup instructions
Provider
Svetlin Dimitrov
Release date
Mar 16, 2025
Language
TypeScript
Stats
38 stars

The MCP Memory Server implements long-term memory capabilities for AI assistants following mem0 principles. It leverages PostgreSQL with pgvector for efficient vector similarity search, allowing assistants to store, retrieve, and search memories semantically.

Prerequisites

Before installation, ensure you have:

  1. PostgreSQL 14+ with pgvector extension:

    CREATE EXTENSION vector;
    
  2. Node.js 16+

Installation

  1. Install dependencies:

    npm install
    
  2. Configure environment variables:

    cp .env.sample .env
    

    Configure your .env file with appropriate settings:

    # With username/password
    DATABASE_URL="postgresql://username:password@localhost:5432/mcp_memory"
    PORT=3333
    
    # Local development with peer authentication
    DATABASE_URL="postgresql:///mcp_memory"
    PORT=3333
    
  3. Initialize the database:

    npm run prisma:migrate
    
  4. Start the server:

    npm start
    

    For development with auto-reload:

    npm run dev
    

Integration with Cursor

Setting Up the MCP Server in Cursor

Add the memory server to your Cursor configuration by modifying ~/.cursor/mcp.json:

{
  "mcpServers": {
    "memory": {
      "command": "node",
      "args": [
        "/path/to/your/memory/src/server.js"
      ]
    }
  }
}

Replace /path/to/your/memory with the actual path to your memory server installation. For example:

{
  "mcpServers": {
    "memory": {
      "command": "node",
      "args": [
        "/Users/username/workspace/memory/src/server.js"
      ]
    }
  }
}

The server will start automatically when Cursor launches. Verify it's working by visiting http://localhost:3333/mcp/v1/health.

Using the API

SSE Connection

Connect to the server's event stream:

GET /mcp/v1/sse

Query parameters:

  • subscribe: Comma-separated list of events to subscribe to (optional)

Available events:

  • connected: Sent on initial connection
  • memory.created: Sent when new memories are created
  • memory.updated: Sent when existing memories are updated

Memory Operations

Create Memory

POST /mcp/v1/memory
Content-Type: application/json

{
  "type": "learning",
  "content": {
    "topic": "Express.js",
    "details": "Express.js is a web application framework for Node.js"
  },
  "source": "documentation",
  "tags": ["nodejs", "web-framework"],
  "confidence": 0.95
}

Search Memories

GET /mcp/v1/memory/search?query=web+frameworks&type=learning&tags=nodejs

List Memories

GET /mcp/v1/memory?type=learning&tags=nodejs,web-framework

Health Check

GET /mcp/v1/health

Response Format

All API responses follow the standard MCP format:

Success response:

{
  "status": "success",
  "data": {
    // Response data
  }
}

Error response:

{
  "status": "error",
  "error": "Error message"
}

Memory Schema

Each memory entry contains:

  • id: Unique identifier
  • type: Type of memory (learning, experience, etc.)
  • content: Actual memory content (JSON)
  • source: Origin of the memory
  • embedding: Vector representation (384 dimensions)
  • tags: Array of relevant tags
  • confidence: Confidence score (0-1)
  • createdAt: Creation timestamp
  • updatedAt: Last update timestamp

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "memory" '{"command":"node","args":["/path/to/your/memory/src/server.js"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "memory": {
            "command": "node",
            "args": [
                "/path/to/your/memory/src/server.js"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "memory": {
            "command": "node",
            "args": [
                "/path/to/your/memory/src/server.js"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later