知识图谱存储服务

Universal Memory MCP Server是一个远程MCP服务器,为AI助手提供持久化知识图谱作为长期记忆,支持与多种MCP兼容客户端(如Claude、ChatGPT、Gemini等)协作。

  • by JasonMakes801
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 JasonMakes801/universal-memory-mcp

使用说明

Universal Memory MCP Server

A remote MCP (Model Context Protocol) server that provides a persistent knowledge graph as long-term memory for AI assistants. Works with any MCP-compatible client: Claude, ChatGPT, Gemini, Cursor, VS Code Copilot, Windsurf, JetBrains, and more.

Built on Cloudflare Workers with D1 (SQLite), Vectorize (vector search), and Workers AI (embeddings).

What it does

Stores a knowledge graph of entities (people, companies, projects), observations (facts about entities), and relations (connections between entities). Any MCP-compatible AI assistant can use this as persistent memory across conversations, devices, and platforms.

Compatible clients

Platform Remote MCP Support
Claude (claude.ai, iOS, Desktop, Code) Custom connectors
ChatGPT (Business/Enterprise/Edu) Apps / connectors
Gemini (Enterprise / CLI) Custom MCP servers
VS Code + GitHub Copilot MCP servers config
Cursor Streamable HTTP
Windsurf Streamable HTTP
JetBrains IDEs AI Assistant MCP
Xcode 26.3+ Native MCP support
  • Hybrid search: semantic similarity via Vectorize + keyword matching via FTS5
  • OAuth protected: password-gated so only you can access your memory
  • Visualization: force-directed graph at /viz with obfuscate mode for screenshots
  • Gmail ingestion pipeline: automated extraction of entities and facts from email threads

Architecture

Cloudflare Workers (TypeScript)
├── MCP Server (Streamable HTTP transport)
│   ├── 12 tools: CRUD for entities, observations, relations + search
│   └── OAuth via @cloudflare/workers-oauth-provider
├── D1 (SQLite)
│   ├── entities, observations, relations tables
│   ├── FTS5 full-text search with sync triggers
│   └── processed_threads tracking for Gmail pipeline
├── Vectorize
│   └── 768-dim embeddings for semantic search
├── Workers AI
│   └── @cf/baai/bge-base-en-v1.5 for embedding generation
└── Visualization
    └── D3.js force-directed graph at /viz

MCP Tools

Tool Description
create_entity Create a person, company, project, etc. (idempotent)
add_observation Attach a fact to an entity
update_observation Replace an observation's content
remove_observation Delete an observation
create_relation Create a directed edge between entities
remove_relation Remove a relation
get_entity Get entity with all observations and relations
search Hybrid semantic + keyword search
list_entities List all entities, optionally by type
delete_entity Delete entity and cascade
filter_unprocessed_threads Check which Gmail thread IDs haven't been ingested
mark_threads_processed Mark thread IDs as ingested

Setup

Prerequisites

  • Cloudflare account on the Workers Paid plan ($5/month)
  • Node.js 18+

1. Install dependencies

npm install

2. Create Cloudflare resources

npx wrangler login
npx wrangler d1 create universal-memory
npx wrangler vectorize create universal-memory-vectors --dimensions=768 --metric=cosine
npx wrangler kv namespace create OAUTH_KV

3. Configure wrangler.jsonc

Update wrangler.jsonc with the D1 database ID and KV namespace ID from step 2.

4. Set the auth password

npx wrangler secret put AUTH_PASSWORD

5. Run schema migrations

npx wrangler d1 execute universal-memory --remote --file=schema.sql
npx wrangler d1 execute universal-memory --remote --file=schema-v2.sql

6. Deploy

npx wrangler deploy

7. Register as Claude connector

Go to claude.ai > Settings > Connectors > Add Custom Connector and paste your Worker URL with /mcp appended:

https://<your-worker>.workers.dev/mcp

Gmail Ingestion Pipeline

The server includes a cron-triggered pipeline that automatically ingests Gmail threads into the knowledge graph. It runs every 6 hours and:

  1. Fetches recent threads via the Gmail API
  2. Skips already-processed threads
  3. Sends each thread to the Claude API for structured entity extraction
  4. Writes entities, observations, and relations to D1
  5. Embeds observations in Vectorize

To enable, set these secrets:

npx wrangler secret put GMAIL_CLIENT_ID
npx wrangler secret put GMAIL_CLIENT_SECRET
npx wrangler secret put GMAIL_REFRESH_TOKEN
npx wrangler secret put ANTHROPIC_API_KEY

Alternatively, use Claude Code's /loop command to ingest via the Gmail MCP connector without needing direct API credentials.

Visualization

Visit https://<your-worker>.workers.dev/viz to see an interactive force-directed graph of your knowledge graph. Features:

  • Nodes colored by entity type, sized by observation count
  • Click nodes to see observations and relations in a sidebar
  • Zoom and pan, drag nodes to rearrange
  • Obfuscate button scrambles all text for safe screenshots

Project Structure

src/
├── index.ts          # Worker entry, McpAgent, OAuth provider, cron handler
├── tools.ts          # MCP tool definitions and handlers
├── db.ts             # D1 query layer
├── embeddings.ts     # Workers AI + Vectorize operations
├── types.ts          # TypeScript interfaces
├── auth-handler.ts   # OAuth login, viz routes, API endpoints
├── gmail.ts          # Gmail API client (refresh token auth)
├── extractor.ts      # Claude API entity extraction
└── pipeline.ts       # Gmail ingestion orchestration

License

MIT