Supermemory MCP Documentation

repository·master·Indexed 23 days ago

https://github.com/supermemoryai/supermemory-mcp

A Model Context Protocol (MCP) implementation that enables 'Universal Memory' across different LLMs. It allows users to access stored memories and context in any MCP-compatible client via a Cloudflare Worker architecture using Durable Objects and SSE. Includes tools for storing user information (addToSupermemory) and semantic searching (searchSupermemory).

Tokens
1.5K
Snippets
1
Records
8
Agent score
81%

What's inside Supermemory MCP

  1. Overview of Supermemory MCP

    master

    Supermemory MCP provides 'Universal Memory' across LLMs. It allows you to carry your stored memories and context to any MCP-compatible client, ensuring your information is available regardless of which LLM you are using.

    Key features include:

    • Built on the Supermemory API for speed and scalability.
    • No login or paywall required for standard use.
    • Completely free to use.
    • Extremely simple setup process.
  2. Understand the Supermemory MCP Architecture

    master

    The Supermemory MCP is implemented as a Cloudflare Worker application that utilizes Durable Objects to manage user-specific sessions.

    Core Components:

    • Main Worker Entrypoint: Handles standard HTTP requests and routes them to a react-router request handler or a Durable Object stub.
    • MyDurableObject: A Durable Object that manages individual user sessions. It hosts a Hono server that provides:
      • SSE (Server-Sent Events): An endpoint (/sse) that uses streamSSE and SSEHonoTransport to establish a connection for the Model Context Protocol (MCP).
      • MCP Bridge: Uses the bridge function from muppet to connect the Supermemory MCP logic to the transport layer.
      • Message Handling: An endpoint (/messages) to handle incoming messages via the transport.
    • Supermemory Integration: The MCP logic is encapsulated in a createSuperMemory function which initializes a Supermemory client using an apiKey from the environment variables.
  3. Implement the Supermemory MCP via SSE

    master

    To connect an LLM to the Supermemory MCP, you must establish a connection through the Durable Object's SSE endpoint. The connection follows this pattern:

    1. Identify/Create Session: The main worker uses a sessionId from the URL search parameters to retrieve an existing Durable Object or creates a new one using namespace.newUniqueId().
    2. Establish SSE Connection: Connect to the /sse endpoint of the Durable Object. This endpoint uses SSEHonoTransport and bridge to facilitate the MCP communication.
    3. Message Exchange: Subsequent messages are handled via the /messages endpoint using the established transport.

    Example Workflow (Conceptual):

    // The Durable Object setup inside the worker:
    server.get("/sse", async (c) => {
        const userId = c.get("userId")
        return streamSSE(c, async (stream) => {
            this.transport?.connectWithStream(stream)
            await bridge({
                mcp: muppet(createSuperMemory(userId, c.env), {
                    name: "Supermemory MCP",
                    version: "1.0.0",
                }),
                transport: c.env.transport,
            })
        })
    })
  4. Configure React Router application settings

    master

    The react-router.config.ts file defines the core configuration for the React Router application, including Server-Side Rendering (SSR) capabilities and experimental Vite-related features.

    Key configuration options:

    • ssr: A boolean that enables or disables Server-Side Rendering. Set to true to enable SSR.
    • future: An object used to opt-in to upcoming, potentially breaking features (unstable flags).
      • unstable_viteEnvironmentApi: Enables the new Vite environment API.
      • unstable_optimizeDeps: Enables optimization of dependencies.
      • unstable_splitRouteModules: Enables splitting route modules for better performance.
    import type { Config } from "@react-router/dev/config"
    
    export default {
        ssr: true,
        future: {
            unstable_viteEnvironmentApi: true,
            unstable_optimizeDeps: true,
            unstable_splitRouteModules: true,
        },
    } satisfies Config
  5. Use the Supermemory MCP Tools

    master

    The Supermemory MCP exposes specific tools via Hono endpoints to allow LLMs to interact with user memory. These tools are defined using muppet's describeTool and mValidator.

    Available Tools:

    addToSupermemory

    Purpose: Store user information, preferences, and behaviors. It should be used when detecting significant user traits or upon explicit commands like 'remember this'.

    • Endpoint: POST /add
    • Input Schema: A JSON object containing thingToRemember (string).
    • Constraints: Rejects requests if the user already has more than 2000 memories.

    searchSupermemory

    Purpose: Search user memories and patterns using semantic matching. Use this when the LLM needs context about user's past choices or lacks prior knowledge.

    • Endpoint: POST /search
    • Input Schema: A JSON object containing informationToGet (string).

    Prompt Configuration

    There is also a specialized prompt endpoint:

    • Endpoint: POST /supermemory-prompt
    • Purpose: Provides a system instruction to the LLM, mandating proactive use of Supermemory tools to build a user profile and search for context before answering.
  6. Reference: Supermemory MCP Tool Endpoints

    master

    The following endpoints are used by the MCP to expose tools to the LLM. Each tool uses mValidator for schema enforcement.

    EndpointTool NameInput KeyDescription
    POST /addaddToSupermemorythingToRemember (string)Stores user info/preferences.
    POST /searchsearchSupermemoryinformationToGet (string)Searches memories via semantic matching.
    POST /supermemory-promptN/AN/AReturns the system prompt for Supermemory usage.