Memory MCP Worker

Memory MCP Worker

Provides cross-device access to a persistent knowledge graph via Cloudflare Workers, enabling memory storage and retrieval through both MCP protocol and REST API with full-text search capabilities.

Category
访问服务器

README

Memory MCP Worker

Cloudflare Worker implementing MCP protocol for cross-device memory/knowledge graph access.

Features

  • MCP Protocol Support: Works with Claude Code via HTTP transport
  • REST API: Access from mobile apps, desktop apps, n8n workflows
  • D1 Database: SQLite-based persistent storage
  • Full-text Search: Search across all observations

Quick Start

1. Install Dependencies

npm install

2. Create D1 Database

# Create the database
wrangler d1 create memory-graph

# Copy the database_id from output to wrangler.toml

3. Run Migrations

# Local development
npm run db:migrate:local

# Production
npm run db:migrate

4. Deploy

npm run deploy

5. Set API Key Secret

# Generate an API key
openssl rand -base64 32 | tr -d '/+=' | head -c 32

# Add as secret
echo "YOUR_API_KEY" | npx wrangler secret put API_KEY

6. Configure Claude Code

Add to your ~/.claude/settings.json or .mcp.json:

{
  "mcpServers": {
    "memory-remote": {
      "type": "http",
      "url": "https://memory-mcp.45black-limited.workers.dev/mcp",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Migrating from Local Memory

  1. Export your local memory:

    claude -p "Use mcp__memory__read_graph and output the raw JSON result" > scripts/local-memory.json
    
  2. Run migration:

    npx ts-node scripts/migrate-local-memory.ts
    

API Endpoints

REST API (for apps)

Endpoint Method Description
/api/entities GET List all entities
/api/entities/:name GET Get entity with observations
/api/entities POST Create entity
/api/entities/:name/observations POST Add observations
/api/relations GET List all relations
/api/relations POST Create relation
/api/search?q= GET Search entities and observations
/api/graph GET Get full graph
/api/import POST Bulk import

MCP Protocol

Endpoint Method Description
/mcp POST MCP JSON-RPC requests
/mcp/sse GET SSE connection for MCP

MCP Tools Available

  • create_entities - Create new entities
  • create_relations - Create relations between entities
  • add_observations - Add observations to entities
  • read_graph - Read entire knowledge graph
  • search_nodes - Search by query
  • open_nodes - Get specific nodes by name
  • delete_entities - Delete entities
  • delete_relations - Delete relations

Authentication

All /api/* and /mcp/* endpoints require authentication via API key.

Headers supported:

  • X-API-Key: YOUR_API_KEY
  • Authorization: Bearer YOUR_API_KEY

The health check endpoint (/) is public.

Mobile App Integration

Example fetch from a mobile app:

const API_KEY = 'YOUR_API_KEY';
const BASE_URL = 'https://memory-mcp.45black-limited.workers.dev';

const headers = {
  'Content-Type': 'application/json',
  'X-API-Key': API_KEY,
};

// Search for a project
const response = await fetch(`${BASE_URL}/api/search?q=Household%20Planner`, { headers });
const data = await response.json();

// Add an observation
await fetch(`${BASE_URL}/api/entities/Household%20Planner/observations`, {
  method: 'POST',
  headers,
  body: JSON.stringify({
    contents: ['Added new budget category feature']
  })
});

n8n Integration

An n8n workflow is included for querying the Memory API via webhooks.

Setup

  1. Import n8n-workflow-memory-api.json into n8n
  2. Create a "Header Auth" credential:
    • Name: Memory MCP API Key
    • Header Name: X-API-Key
    • Header Value: YOUR_API_KEY
  3. Assign the credential to all three HTTP Request nodes
  4. Activate the workflow

Endpoints

Search - POST to /webhook/memory-search:

curl -X POST https://your-n8n-instance/webhook/memory-search \
  -H "Content-Type: application/json" \
  -d '{"query": "Household Planner"}'

Get Entity - POST to /webhook/memory-entity:

curl -X POST https://your-n8n-instance/webhook/memory-entity \
  -H "Content-Type: application/json" \
  -d '{"name": "Household Planner"}'

Get Full Graph - POST to /webhook/memory-graph:

curl -X POST https://your-n8n-instance/webhook/memory-graph \
  -H "Content-Type: application/json" \
  -d '{}'

Create Entity - POST to /webhook/memory-create:

curl -X POST https://your-n8n-instance/webhook/memory-create \
  -H "Content-Type: application/json" \
  -d '{"name": "My Project", "entityType": "Project", "observations": ["First observation"]}'

Add Observations - POST to /webhook/memory-observations:

curl -X POST https://your-n8n-instance/webhook/memory-observations \
  -H "Content-Type: application/json" \
  -d '{"name": "My Project", "contents": ["New observation 1", "New observation 2"]}'

Create Relation - POST to /webhook/memory-relations:

curl -X POST https://your-n8n-instance/webhook/memory-relations \
  -H "Content-Type: application/json" \
  -d '{"from": "Project A", "to": "Project B", "relationType": "depends_on"}'

Delete Entity - POST to /webhook/memory-delete:

curl -X POST https://your-n8n-instance/webhook/memory-delete \
  -H "Content-Type: application/json" \
  -d '{"name": "Entity Name"}'

Delete Relation - POST to /webhook/memory-delete-relation:

curl -X POST https://your-n8n-instance/webhook/memory-delete-relation \
  -H "Content-Type: application/json" \
  -d '{"from": "Entity A", "to": "Entity B", "relationType": "relation_type"}'

Development

# Start local dev server
npm run dev

# Typecheck
npm run typecheck

Architecture

┌─────────────────────────────────────────┐
│         Cloudflare Worker               │
│      memory-mcp.45black.workers.dev     │
├─────────────────────────────────────────┤
│  Hono Framework                         │
│  ├── /api/* → REST API                  │
│  └── /mcp   → MCP Protocol              │
├─────────────────────────────────────────┤
│  Cloudflare D1 (SQLite)                 │
│  ├── entities                           │
│  ├── observations                       │
│  ├── relations                          │
│  └── observations_fts (full-text)       │
└─────────────────────────────────────────┘

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选