shared-memory

shared-memory

Provides a shared long-term memory across multiple AI clients, enabling persistent storage and retrieval of facts, preferences, decisions, and snippets with semantic search.

Category
访问服务器

README

shared-memory — MCP Server for Cross-Client Long-Term Memory

One shared long-term memory for all your AI clients.

Connect a single MCP server to Cursor, Cherry Studio, Odysseus AI, NextChat — they all read and write to the same database. A fact saved in Cursor is available in Cherry Studio and vice versa.


How it works

Cursor ─┐
Cherry Studio ─┤  HTTPS + Bearer token   ┌──── Raspberry Pi ────────────────┐
Odysseus AI ─┼─────────────────────────►  │  FastMCP (Streamable HTTP)       │
NextChat ─┘   (mcp-remote if stdio)       │  → MongoDB Atlas (Vector Search) │
                                           └──────────────────────────────────┘
  • Server: Python (FastMCP 3.x), runs on Raspberry Pi 4 inside Docker.
  • Transport: Streamable HTTP (single POST endpoint /mcp, SSE for streaming).
  • Storage: MongoDB Atlas (M0 free tier) with Atlas Vector Search + Automated Embedding (Voyage AI).
  • Security: Per-client Bearer tokens, rate limited at 60 req/min.
  • Publication: Tailscale Funnel — HTTPS out of the box, no open ports.

Tools (MCP)

The server exposes 5 tools. Below is the description written for the AI agent that will call them.

1. memory_write

memory_write(content: string, type: "fact" | "preference" | "decision" | "snippet",
             scope?: string, tags?: string[], pinned?: boolean) -> { id, created, scope }

Saves a fact to long-term memory. Idempotent: if the exact same fact (normalized: lowercase, collapsed whitespace) already exists in this scope, it does not create a duplicate but updates updated_at.

Parameters:

  • content — one self-contained statement, 1-4000 characters.
  • type — category: fact, preference, decision, snippet.
  • scope — namespace (global / project-name). Defaults to the client's scope from the token.
  • tags — labels for filtering.
  • pinned — if true, surfaces in every bootstrap call.

When to call: user stated a preference, made a decision, corrected you, or shared configuration.

2. memory_search

memory_search(query: string, scope?: string, tags?: string[],
              limit?: number) -> { count, limit, results: [...] }

Semantic search over memory. Uses Atlas Vector Search (Voyage AI embeddings) when available, falls back to case-insensitive regex.

Parameters:

  • query — phrase this as the question you are trying to answer, not keywords.
  • scope, tags — filters.
  • limit — 1..25 (default 5).

Each result:

{
  "id": "ObjectId",
  "content": "fact text",
  "scope": "global",
  "type": "fact",
  "tags": [],
  "pinned": false,
  "created_at": "2026-08-01T07:48:48+00:00",
  "source_client": "cursor",
  "score": 0.92        // only present with vector search
}

When to call: before answering a question about preferences, projects, or past user decisions.

3. memory_bootstrap

memory_bootstrap(scope?: string, limit?: number) -> { count, results: [...] }

Returns pinned facts (always first) + most recent. Cheap call to load context at the start of a dialogue.

When to call: exactly once at the beginning of a new conversation.

4. memory_forget

memory_forget(id: string) -> { forgotten: boolean }

Soft-delete: marks the record as deleted: true. Does not physically erase it.

When to call: the user said a fact is no longer accurate. After forget, write the corrected version.

5. ping

ping() -> "pong"

Health check.


Authentication

Every request to /mcp must include:

Authorization: Bearer <token>

Tokens are configured in .env:

MCP_TOKENS=tok_cursor:cursor:global,tok_cherry:cherry:global,tok_nextchat:nextchat:global,tok_odysseus:odysseus:global

Format: token:client_name:default_scope. Different clients get different tokens (auditing + revoking one doesn't break the others).

Rate limit: 60 requests/minute per token. On exceeding: 429 + Retry-After: 60.


Endpoints

Path Method Auth Description
/healthz GET none Server health check
/mcp POST Bearer MCP requests (tools/list, tools/call, etc.)

Data model

Collection shared_memory.memories:

{
  "_id": ObjectId,
  "content": "user prefers dark mode in all editors",
  "content_hash": "sha256(normalize(content))",
  "scope": "global",
  "type": "preference",
  "source_client": "cursor",
  "tags": ["editor", "theme"],
  "pinned": false,
  "deleted": false,
  "created_at": ISODate,
  "updated_at": ISODate
}

Unique index: (scope, content_hash) — guarantees no exact duplicates within a scope.

Collection shared_memory.audit_log (TTL 30 days):

{
  "_id": ObjectId,
  "ts": ISODate,
  "client": "cursor",
  "tool": "memory_write",
  "args": "type=preference scope=global",
  "result_count": 1
}

Client setup

Cursor (direct connection)

~/.cursor/mcp.json:

{
  "mcpServers": {
    "shared-memory": {
      "url": "https://mcp-pi.<tailnet>.ts.net/mcp",
      "headers": { "Authorization": "Bearer tok_cursor" }
    }
  }
}

Cherry Studio (direct connection)

Settings → MCP Servers → Add:

  • Type: Streamable HTTP
  • URL: https://mcp-pi.<tailnet>.ts.net/mcp
  • Headers: { "Authorization": "Bearer tok_cherry" }

NextChat / Odysseus AI (via mcp-remote bridge)

{
  "mcpServers": {
    "shared-memory": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://mcp-pi.<tailnet>.ts.net/mcp",
               "--header", "Authorization: Bearer tok_client"]
    }
  }
}

System prompt (paste into each client's custom instructions)

You have access to the user's shared long-term memory via the `shared-memory` MCP server.

- At the start of a new conversation, call `memory_bootstrap` once.
- Before answering a question that depends on the user's preferences, projects,
  or past decisions — call `memory_search` with the question you are trying to answer.
- When the user states a stable preference, makes a decision, or corrects you —
  call `memory_write` (one self-contained statement).
- When the user corrects a previously stored fact — `memory_forget` by the id
  from search results, then `memory_write` with the corrected version.
- Do NOT save temporary task state, drafts, or anything easily re-derived.

Infrastructure

  • Server: Raspberry Pi 4 (4GB), Docker + docker-compose.
  • Publication: Tailscale Funnel → https://mcp-pi.<tailnet>.ts.net.
  • Database: MongoDB Atlas M0 (free), automated Voyage AI embeddings for vector search.
  • Auto-start: systemd unit (deploy/mcp-memory.service).
  • Backup: nightly mongodump via deploy/backup.sh (30-day retention).

Tests

pytest -v    # 48 tests, mongomock (no Docker needed)

For integration with a real Atlas cluster: TEST_MONGODB_URI="mongodb+srv://..." pytest -v.


Key source files

File Purpose
src/mcp_memory/server.py FastMCP server, 5 tool registrations
src/mcp_memory/tools/memory.py Pure tool logic (memory_write_impl etc.)
src/mcp_memory/repository.py MongoDB CRUD + vector search + audit
src/mcp_memory/auth.py Bearer authentication + rate limiting
src/mcp_memory/ratelimit.py Token bucket rate limiter
src/mcp_memory/models.py Pydantic MemoryRecord + content_hash
src/mcp_memory/config.py Settings from env
src/mcp_memory/context.py ContextVar for per-request client identity
src/mcp_memory/app.py ASGI composition: healthz + auth + MCP
Dockerfile ARM64 Docker image for Pi
deploy/docker-compose.yml Production compose config
docs/setup-tailscale.md Tailscale Funnel setup guide

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选