mcp-ad4m

mcp-ad4m

Enables Claude Code with persistent semantic memory, cross-session context, and memory hygiene via a local AD4M executor, offering 13 tools for managing semantic graphs and cross-terminal relay.

Category
访问服务器

README

mcp-ad4m

AD4M MCP server for Claude Code — 13-tool semantic memory and enforcement layer.

Gives Claude Code persistent memory, cross-session context, and memory hygiene via a locally hosted AD4M executor. All data stays on your machine.


The Problem

Getting AD4M working with Claude Code requires:

  • Figuring out the executor port (it reads from ~/.ad4m/executor-port, not a fixed value)
  • Writing a custom MCP server from scratch — none existed
  • Re-unlocking the agent on every reboot (no persistence)
  • No documented integration path for Claude Code specifically

This server solves all of it. One command sets everything up.


One-Command Install

git clone https://github.com/thefranceway/mcp-ad4m.git
cd mcp-ad4m
./setup-claude-code.sh --passphrase YOUR_AD4M_PASSPHRASE

The script:

  • Builds the TypeScript server
  • Stores your passphrase in macOS Keychain (not plaintext)
  • Installs a launchd job that auto-unlocks AD4M on every boot
  • Creates a ClaudeMemory Perspective and saves the UUID
  • Prints the settings.json snippet to paste into Claude Code

Requires: Node.js 18+, AD4M executor running locally, macOS


Tools (13)

Tool Description
ad4m_agent_status DID, initialization state, keystore lock state
ad4m_list_perspectives All local Perspectives
ad4m_create_perspective Create a new named semantic graph
ad4m_write_memory Write a LinkExpression (source → predicate → target)
ad4m_recall Query links with optional source/predicate/target filters
ad4m_delete_memory Remove links by filter — matched/removed/failed counts
ad4m_classify Classify content by layer before writing (env/local/relay/ad4m)
ad4m_config_check Detect MCP registration in the wrong config file
ad4m_optimize Deduplicate graph, flag stale entries, auto-runs every 10 writes
ad4m_stats Total links, duplicate count, breakdown by predicate
ad4m_get_neighbourhood Inspect a shared AD4M Neighbourhood
relay_write Write cross-terminal live state via AD4M
relay_read Read cross-terminal relay messages

Memory Architecture

AD4M stores information as signed links: source → predicate → target.

memory://project/zuafrique  →  ad4m://has-content  →  literal://Deployed CF Pages 2026-03-15
franc://session-log         →  franc://closed       →  literal://Session ended
franc://relay/terminal-a    →  franc://relay        →  literal://Build in progress

Layer Taxonomy (enforced by ad4m_classify)

Layer Where it belongs Examples
ad4m AD4M semantic graph Decisions, project facts, cross-session context
env ~/.zshrc API keys, tokens, credentials
local CLAUDE.md / settings.json Rules, hooks, permissions
relay AD4M relay predicate Live cross-terminal state

Run ad4m_classify before ad4m_write_memory if unsure which layer to use.


Self-Optimization

The graph self-prunes automatically. Every 10 writes from any terminal increments a shared counter stored in AD4M (franc://optimizer → franc://write-count). When it hits 10, ad4m_optimize runs and removes exact duplicates.

To run manually:

ad4m_optimize({ perspective_uuid: "...", dry_run: true })   // report only
ad4m_optimize({ perspective_uuid: "...", dry_run: false })  // remove duplicates

Cross-Terminal Relay

Two Claude Code terminals sharing the same AD4M executor can exchange live messages:

Terminal A:

relay_write({ perspective_uuid: "...", message: "build done", session_id: "terminal-a" })

Terminal B:

relay_read({ perspective_uuid: "...", since: "2026-05-16T00:00:00Z" })

Manual Setup (without the script)

1. Build

npm install && npm run build

2. Add to ~/.claude/settings.json

"ad4m": {
  "command": "/path/to/mcp-ad4m/bin/mcp-ad4m",
  "args": [],
  "env": {
    "AD4M_GQL_URL": "http://localhost:4000/graphql"
  }
}

3. Unlock the agent before each session

curl -s http://localhost:4000/graphql \
  -H "Content-Type: application/json" \
  -d '{"query":"mutation { agentUnlock(passphrase: \"YOUR_PASSPHRASE\") { isUnlocked } }"}'

Or install the launchd job from launchd/dev.ad4m.auto-unlock.plist to auto-unlock on boot.


Error Messages

The server returns actionable errors:

Situation What you see
Executor not running AD4M executor not reachable. Start it with: ad4m serve --port 4000
Agent locked Agent is locked. Unlock with: curl ... (exact command included)
Timeout fetch failed with port and URL

Tested On

  • macOS 13.3 ARM64 (Apple M1)
  • AD4M executor v0.12.x
  • Claude Code CLI (Sonnet 4.6)
  • Node.js v24

Project Structure

mcp-ad4m/
├── src/
│   └── index.ts          TypeScript source (13 tools)
├── dist/                 Compiled output (generated by npm run build)
├── launchd/
│   └── dev.ad4m.auto-unlock.plist
├── setup-claude-code.sh  One-command setup
├── package.json
└── tsconfig.json

License

MIT

推荐服务器

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

官方
精选