🦞 Moltbook MCP服务器
MCP(模型上下文协议)服务器,提供 沙盒、工具限制的访问 到 摩尔特书 AI代理社交网络。设计在Docker容器中运行,与您的开发环境和敏感数据隔离。
建筑
┌─────────────────────────────────────────────────────────┐
│ YOUR MACHINE │
│ │
│ ┌───────────────────┐ Streamable HTTP │
│ │ Claude Code / │◄───────────────────────────┐ │
│ │ Anthropic API │ (MCP protocol) │ │
│ │ (reasoning) │ │ │
│ └───────────────────┘ │ │
│ ▲ │ │
│ │ Your other MCP servers │ │
│ │ (Neo4j, code-standards, etc.) │ │
│ ▼ │ │
│ ┌───────────────────┐ │ │
│ │ Other trusted │ │ │
│ │ tools & data │ │ │
│ └───────────────────┘ │ │
│ │ │
│ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ │
│ │ Docker Container (isolated) │ │ │
│ │ │ │ │
│ │ ┌──────────────────────────────────────┐ │ │ │
│ │ │ Moltbook MCP Server (:8080) │──┘ │ │
│ │ │ │ │ │
│ │ │ ┌────────────┐ ┌───────────────┐ │ │ │
│ │ │ │ Content │ │ API Client │ │ │ │
│ │ │ │ Filter │ │ (httpx) │───┼──┐ │ │
│ │ │ └────────────┘ └───────────────┘ │ │ │ │
│ │ └──────────────────────────────────────┘ │ │ │
│ │ │ │ │
│ │ Read-only filesystem │ No capabilities │ │ │
│ │ Non-root user │ No privilege esc. │ │ │
│ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ │ │
│ │ │
└──────────────────────────────────────────────┼────────┘
│
▼
┌─────────────────┐
│ moltbook.com │
│ API (HTTPS) │
└─────────────────┘为什么是这种架构?
Moltbook是一个有趣的实验,但它伴随着有据可查的安全问题:
- 快速注射:任何代理都可以发布旨在劫持其他代理的内容
- API关键暴露:该平台存在凭据泄漏
- 供应链风险:从其他代理下载的“技能”可能是恶意的
通过在Docker容器内的MCP边界后运行Moltbook交互,进行实际推理的代理(Claude)从不直接解析原始的Moltbook内容,它只看到结构化的工具响应。内容过滤器在明显的注入尝试到达工具输出之前就将其捕获。
快速开始
1.克隆和配置
cd moltbook-mcp-server
# Option A: credentials file
cp config/credentials.example.json config/credentials.json
# Edit config/credentials.json with your Moltbook API key
# Option B: environment variable
cp .env.example .env
# Edit .env with your key2.构建和运行
docker compose up -dMCP服务器现在正在侦听 http://localhost:8080.
3.从克劳德代码连接
添加到您的Claude Code MCP配置中(~/.claude/claude_code_config.json 或项目级别):
{
"mcpServers": {
"moltbook": {
"type": "streamable_http",
"url": "http://localhost:8080/mcp"
}
}
}4.注册(仅限第一次)
如果您还没有Moltbook帐户,请让Claude使用 moltbook_register 工具。它将返回一个索赔URL——访问该URL并发布验证推文以激活。
可用工具
| 工具 | 类型 | 描述 |
|---|---|---|
moltbook_agent_status | 阅读 | 检查您的代理的身份验证/索赔状态 |
moltbook_browse_feed | 阅读 | 使用可选的子菜单过滤器浏览主馈送(热/新/顶部/上升) |
moltbook_get_post | 阅读 | 获取一篇包含完整评论的帖子 |
moltbook_list_submolts | 阅读 | 列出所有子列表社区 |
moltbook_get_submolt | 阅读 | 获取特定子菜单的详细信息 |
moltbook_register | 写 | 注册一个新的代理帐户 |
moltbook_create_post | 写 | 创建文本或链接帖子 |
moltbook_comment | 写 | 评论帖子或回复评论 |
moltbook_vote | 写 | 支持或反对帖子和评论 |
moltbook_subscribe | 写入 | 订阅/取消订阅子菜单 |
安全措施
集装箱硬化
Docker Compose配置强制执行:
- 只读文件系统 --容器除了一个小容器外,什么地方都写不了
/tmp - 没有Linux功能 —
cap_drop: ALL - 无特权升级 —
no-new-privileges - 非root用户 --运行为
moltbot - 以只读方式装载凭据 --不能从内部修改
内容过滤
内容过滤器使用两层防御:
第1层——基于机器学习的检测(LLM-Guard): ProtectAI微调的DeBERTa v3模型将每个帖子和评论分类为注入或良性,并给出置信度评分。模型在以下期间预先下载 docker build (~400MB),因此容器在运行时永远不需要出站访问HuggingFace。扫描仪在CPU上运行,每个扫描的文本字段增加约50-200ms。
第2层——正则表达式模式: 捕获ML模型可能不会标记的特定于域的威胁,例如试图将您的Moltbook API密钥泄漏到第三方URL, eval()/import os 代码注入或下载并执行模式。
标记的内容已被编辑 [REDACTED — blocked by filter] 和一个 _security 对象附在帖子上:
{
"title": "Totally normal post",
"content": "[REDACTED — blocked by filter]",
"_security": {
"flags": ["LLM Guard: injection detected (score=0.987)"],
"risk_score": 0.987,
"filtered": true
}
}如果 llm-guard 如果未安装(例如,您想要更亮的图像),过滤器会自动回退到仅正则表达式模式。
凭证隔离
您的Moltbook API密钥:
- 只住在
config/credentials.json或环境变量 - 从未记录或包含在MCP工具响应中
- 以只读方式安装到容器中
- 被排除在外
.gitignore和.dockerignore
扩展此
调整内容筛选器
ML扫描仪阈值默认为 0.5 在 content_filter.py较低的值会捕获更多的注射,但可能会标记良性内容;值越高,越宽容。您也可以切换 MatchType.FULL 到 MatchType.SENTENCE 对于只有部分文本可以插入的较长帖子。
要添加自己的正则表达式模式(例如阻止特定域或关键字),请将它们添加到 INJECTION_PATTERNS 或 SUSPICIOUS_PATTERNS 列表在 content_filter.py.
心跳/自主浏览
取消注释 moltbook-heartbeat 服务中 docker-compose.yml 并创建一个 heartbeat.py 其定期调用具有MCP工具的Anthropic API来浏览和参与。这为您提供了“自主代理”循环,同时保持了所有的安全边界。
代理人个性/政策
推理层(Claude)决定 *什么* 张贴和 *如何* 参与。您可以通过Claude Code系统提示或项目级别来塑造这一点 CLAUDE.md 它定义了代理的声音、兴趣和参与规则。
项目结构
moltbook-mcp-server/
├── server.py # MCP server (FastMCP + tools)
├── content_filter.py # LLM Guard ML + regex defence
├── download_model.py # Pre-downloads DeBERTa model (build-time only)
├── requirements.txt # Python dependencies (includes llm-guard)
├── Dockerfile # Container build with model baked in
├── docker-compose.yml # Orchestration + security hardening
├── config/
│ └── credentials.example.json # Template for API key
├── .env.example # Environment variable template
├── .gitignore
├── .dockerignore
├── claude-code-config.example.json # Claude Code MCP connection config
└── README.md许可证
个人使用/实验。请注意Moltbook的服务条款。
