Factorio AI伴侣
通过MCP协议在Factorio和Claude Code之间建立双向聊天桥。
状态:✅ 第一阶段完成-聊天桥工作!
Factorio和Claude Code之间通过RCON进行双向聊天。
快速入门指南
1.安装依赖项
bun install2.安装Factorio Mod
窗户:
xcopy /E /I factorio-mod "%APPDATA%\Factorio\mods\ai-companion"Linux/Mac: 看 factorio-mod/README.md
3.在Factoryo中配置RCON
编辑 %APPDATA%\Factorio\config\config.ini 并添加这些行(如果尚未存在):
local-rcon-socket=127.0.0.1:34198
local-rcon-password=factorio或者使用隐藏的设置GUI:
- 在Factorio主菜单中,按 Ctrl+Alt 然后单击 设置
- 首选 “其余的” 标签
- 集
local-rcon-socket到127.0.0.1:34198 - 集
local-rcon-password到factorio
4.启动Factorio多人游戏
重要提示: RCON仅在多人模式下工作(即使是单人游戏)。
- 发射因子
- 多人游戏 → 主持新游戏 (或 加载游戏)
- 选择您的保存并单击 播放
- RCON将自动启用
5.测试RCON连接(可选)
bun run src/rcon/test-connection.ts预期产量:
✅ RCON connected on attempt 1
✅ Connection successful!
✅ RCON is working!6.启动MCP服务器
bun run src/index.ts预期产量:
🚀 Starting Factorio MCP Server...
✅ RCON connected on attempt 1
📡 RCON connected to Factorio
✅ MCP server running on stdio
💡 Server is ready! Claude Code can now use:
- get_companion_messages
- send_companion_message7.连接克劳德代码
这 .mcp.json 此项目根目录中的文件配置Claude Code使用此服务器。
Claude Code将在需要时自动启动MCP服务器。
8.测试一下!
在Factorio聊天中:
/companion Hello Claude! Can you help me?在克劳德代码中:
Use the get_companion_messages tool克劳德将看到:
[
{
"player": "YourName",
"message": "Hello Claude! Can you help me?",
"tick": 12345
}
]克劳德可以回答:
Use send_companion_message with "Hello! I'm here to help!"在Factorio中,您将看到:
[AI Companion] Hello! I'm here to help!可用工具
get_companion_messages
从Factorio聊天中获取未读消息,开头为 /companion.
退货: 数组 {player, message, tick}
send_companion_message
以AI Companion的身份向Factorio聊天室发送消息。
输入: { message: string }
建筑
Factorio (Lua mod captures /companion chat)
↕ RCON (TCP port 27000)
Node.js MCP Server (Bun)
↕ MCP Protocol (stdio)
Claude Code (You!)建造了什么
- ✅ 具有重试逻辑的RCON客户端
- ✅ 聊天消息解析器
- ✅ 具有FLE模式的Factorio Lua模型
- ✅ 带2个工具的MCP服务器
- ✅ 通过.mcp.json集成Claude代码
第二阶段(未来)
- AI控制字符
- 游戏状态反思
- 自动化构建/制作
- 多智能体协调
故障排除
“连接失败”
- 确保Factorio正在运行
- 检查“以服务器身份启动”是否启用
- 验证RCON端口是否为27000
- 验证RCON密码是否为“factorio”
“无消息”
- 类型
/companion在Factorio聊天中(不仅仅是“伴侣”) - 检查Factorio中是否启用了mod→ Mods菜单
- 安装mod后重新启动Factorio
“找不到命令”
- 确保Bun已安装:https://bun.sh
- 跑
bun --version验证
发展
# Run tests
bun test
# Test RCON connection
bun run src/rcon/test-connection.ts
# Start MCP server
bun run src/index.ts学分
灵感来自 Factorio学习环境 模式和最佳实践。
