Skip to main content
Glama

CU-MCP-Bridge

BepInEx 模组 + Python MCP 服务器,让 AI 助手通过命名管道实时控制 Casualties Unknown 的游戏玩法。

环境要求

Related MCP server: Unity-MCP

快速开始

1. 安装模组

将 mod/ 中的两个 DLL 复制到游戏的 BepInEx/plugins/ 文件夹:

<game directory>/BepInEx/plugins/CU-MCP-Mod.dll
<game directory>/BepInEx/plugins/Newtonsoft.Json.dll

2. 安装 Python 依赖

pip install -r requirements.txt

3. 配置你的 AI 客户端

添加到你的 MCP 配置中(例如 opencode.json):

{
  "mcp": {
    "servers": {
      "cu-mcp-bridge": {
        "type": "stdio",
        "command": "python",
        "args": ["src/bridge_server/server.py"],
        "cwd": "/path/to/CU-MCP-Bridge"
      }
    }
  }
}

4. 开始游戏

  1. 启动游戏,进入一个关卡

  2. 启动 Python 服务器:python src/bridge_server/server.py

  3. 让 AI 助手控制玩家

顺序很重要:服务器必须在游戏运行之后启动。

从源码构建

# Build the C# mod
dotnet build BepInEx/CU-MCP-Mod.csproj -c Release

# Deploy to game (kills the game process, rebuilds, copies DLL)
.\deploy.ps1 -Action deploy

输出:BepInEx/bin/Release/net472/CU-MCP-Mod.dll

架构

AI Client (opencode)
        |
    stdio (JSON-RPC)
        |
Python FastMCP Server (src/bridge_server/)
        |
    Named Pipe (win32pipe, newline-delimited JSON)
        |
C# BepInEx Mod (BepInEx/, inside Unity game)
        |
    Unity Game (Casualties Unknown)

通信

  • AI -> 游戏:命令通过命名管道发送,并在 Unity 的主线程上执行

  • 游戏 -> AI:玩家状态和查询结果通过同一管道返回

  • 阻塞:每个命令都会阻塞,直到模组报告完成(成功/失败/超时)

项目结构

CU-MCP-Bridge/
├── BepInEx/                # C# mod source (BepInEx plugin)
│   ├── Executor/           # Order execution, pathfinding, movement
│   ├── Collector/          # Game state collection (player, environment)
│   ├── Contingency/        # Local condition-action rules
│   ├── Pipe/               # Named pipe client + protocol
│   ├── AIPlayerManager.cs  # AI companion creation/destruction
│   ├── BridgePlugin.cs     # Entry point, tick loop
│   └── DebugGUI.cs         # F6 debug panel
├── src/bridge_server/      # Python MCP server
│   ├── server.py           # MCP tool definitions
│   ├── state_manager.py    # Pipe reader, state cache
│   ├── order_manager.py    # Order queue
│   ├── pipe_server.py      # Named pipe server (win32pipe)
│   └── contingency.py      # Contingency rule manager
├── tests/                  # Unit & integration tests
├── deploy.ps1              # Build + deploy script
└── requirements.txt        # Python dependencies

MCP 工具

工具

描述

get_game_state

玩家状态(位置、生命值、物品栏)+ 环境快照

get_map_info

玩家周围的地形和实体信息

get_nearby_items

列出玩家附近掉落物品

query_position

查询特定世界坐标处的实体/地形

search_blocks

按材质名称搜索地形(例如 "sand"、"rock")

move_to

将当前活跃玩家移动到世界坐标

move_to_player

将 AI 同伴移动到人类玩家身边

follow

让 AI 同伴跟随人类玩家

jump

跳跃(支持水平方向)

use_item

使用物品栏中的物品

pick_up_item

拾取附近物品(按名称或最近物品)

drop_item

丢弃物品栏中的物品

sleep

休息以恢复体力

heal_ai

治疗 AI 同伴的特定肢体

create_ai_player

在人类玩家旁边克隆一个 AI 同伴

destroy_ai_player

移除 AI 同伴

set_contingency

设置条件-动作规则(例如 "HP < 30% 时治疗")

update_contingency

在运行时更新应变规则

user_interact

最高优先级的人类干预

已知问题

  • 皮肤模组兼容性:安装第三方皮肤模组(例如 "Skin Sync")可能会导致 AI 同伴显示一条与人类玩家尾巴镜像的重复尾巴。这是皮肤模组兼容性问题,在原版游戏中不会出现。

许可证

MIT

Related MCP Connectors

Related MCP Servers