Skip to main content
Glama

通过 MCP 玩 DOOM

MCP Registry npm version npm downloads License: MIT

它能运行 DOOM 吗?能——你的 AI 编程助手可以运行 DOOM。

在 Claude Code、Cursor 或任何兼容 MCP 的客户端中玩 DOOM。AI 能看到游戏画面、与恶魔战斗、探索关卡,并报告正在发生的事情——或者你逐步指挥它。

> Let's play DOOM!

  Starting E1M1 on medium difficulty...

  HP:100 Armor:0 | Pistol (key:2) | Ammo: 50b 0s 0r 0c | Kills:0 | E1M1
  No enemies in sight. Exploring the corridor ahead.

> Go forward and find some enemies

  Sprinting down the hallway... I can see an opening ahead.

  HP:100 Armor:0 | Pistol (key:2) | Ammo: 50b 0s 0r 0c | Kills:0 | E1M1
  ENEMIES IN SIGHT (aim for angle~0 then fire): Imp (HP:60) to your left (turn_left ~9) nearby

  There's an Imp to the left! Turning to face it...

> Shoot it!

  Aimed and firing!

  HP:100 Armor:0 | Pistol (key:2) | Ammo: 47b 0s 0r 0c | Kills:0 | E1M1
  ENEMIES IN SIGHT (aim for angle~0 then fire): Imp (HP:15) AHEAD close

  Hit! The Imp is wounded (HP:15). One more burst should finish it.

  HP:95 Armor:0 | Pistol (key:2) | Ammo: 44b 0s 0r 0c | Kills:1 | E1M1
  ITEMS: Stimpack (+10 HP) slightly to your right (turn_right ~4) point-blank (~3 ticks fwd+run to reach)
  1 kill! Want to see a screenshot?

阅读博客文章了解完整故事。


目录


Related MCP server: local-agent-context

工作原理

一个 Rust MCP 服务器通过 FFI 直接嵌入真正的 DOOM 引擎(doomgeneric)。没有模拟,没有子进程。每次工具调用都会将游戏推进若干 tick,并返回:

  1. 游戏状态 - 生命值、护甲、弹药、击杀数、位置、当前武器

  2. 敌人情报 - 可见敌人及其可读的方向、距离和生命值

  3. 附近物品 - 拾取范围内的生命、弹药、护甲、武器

  4. 门和开关 - 检测到范围内的可交互 linedefs

  5. 帧图像 - 供 AI 视觉使用的小型 PNG 缩略图

AI 利用这些信息进行导航、战斗和探索。你可以指挥它,也可以让它自主游玩。

graph LR
    A[MCP Client] -->|doom_start| B[doom-mcp binary]
    A -->|doom_action| B
    A -->|doom_screenshot| B
    B -->|FFI| C[doomgeneric C engine]
    C -->|frame buffer| B
    B -->|game state + PNG| A

快速开始

1. 向你的 MCP 客户端注册

Claude Code:

claude mcp add doom --scope user -- npx -y doom-mcp

Cursor、Windsurf 或任何 MCP 客户端 - 添加到 .mcp.json:

{
  "mcpServers": {
    "doom": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "doom-mcp"]
    }
  }
}

2. 开始游戏

打开一个新会话并说:

“我们来玩 DOOM 吧”

AI 会询问你想要哪种模式,在 E1M1 上开始游戏,然后开始游玩。


游戏模式

模式

工作原理

最适合

你指挥

你发出命令(“前进”、“打开那扇门”、“射击小鬼”)。AI 一次执行一个动作并描述发生了什么。

沉浸式引导游玩

AI 自主

AI 做出所有决策——移动、战斗、探索。你观看并在需要时干预。

观看 AI 游玩


工具参考

doom_start

启动或重启 DOOM。可随时安全调用——如果游戏已在运行,它会干净地重启,无需新会话。

参数

类型

默认值

描述

skill

int (1-5)

3

难度:1=婴儿,2=简单,3=中等,4=困难,5=噩梦

episode

int (1-4)

1

章节编号

map

int (1-9)

1

地图编号

doom_action

推进游戏。所有列出的动作在 tick 持续时间内同时保持。

参数

类型

必填

描述

actions

string

是

逗号分隔:forward、backward、turn_left、turn_right、strafe_left、strafe_right、fire、use、run、1-7

ticks

int (1-105)

否

要推进的游戏 tick 数。默认 7。以 35 tick/秒计算:7 ~ 0.2 秒,35 ~ 1 秒

游戏玩法说明:

  • fire 在整个持续时间内按住扳机。手枪每 ~10 tick 自动开火。

  • 转身和开火应该是分开的动作(边转身边开火会浪费弹药)。

  • use 打开门并激活开关。

  • 武器键:1=拳头,2=手枪,3=霰弹枪,4=链枪,5=火箭发射器,6=等离子枪,7=BFG。

doom_screenshot

将全分辨率 320x200 截图保存到系统临时目录,并在默认图像查看器中打开。不会推进游戏(除了短暂暂停让画面稳定)。


配置

环境变量

描述

DOOM_WAD_PATH

自定义 IWAD 文件的路径(例如你自己的 DOOM.WAD 或 DOOM2.WAD)

DOOM_MCP_DEBUG

设置为 1 以启用调试日志,输出到系统临时目录中的 doom-mcp.log

捆绑的 Freedoom WAD 开箱即用,但原始 DOOM 共享版 WAD 有更好的关卡和精灵。要使用它:

  1. 从 doomworld.com/classicdoom/info/shareware.php 下载 DOOM1.WAD(合法、免费)

  2. 在你的 MCP 配置中设置 DOOM_WAD_PATH:

{
  "mcpServers": {
    "doom": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "doom-mcp"],
      "env": {
        "DOOM_WAD_PATH": "/path/to/DOOM1.WAD"
      }
    }
  }
}

如果你拥有 DOOM 或 DOOM 2,你可以用同样的方式使用这些 WAD。要使用任何自定义 WAD:

{
  "mcpServers": {
    "doom": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "doom-mcp"],
      "env": {
        "DOOM_WAD_PATH": "/path/to/DOOM.WAD"
      }
    }
  }
}

常见问题

这在 Windows 上能用吗? 能。npm 包包含 Windows x64 二进制文件。注册方式与 macOS/Linux 相同。

我可以使用自己的 DOOM WAD(DOOM.WAD、DOOM2.WAD)吗? 可以。在你的 MCP 配置中设置 DOOM_WAD_PATH。共享版 DOOM1.WAD 可从 doomworld.com 免费下载,其关卡比捆绑的 Freedoom 好得多。详见配置部分。

这会消耗多少 API token? 每次 doom_action 调用返回约 1-2KB 文本(游戏状态 + 敌人信息)以及约 6KB 的 PNG 缩略图。每次动作大约消耗 1,500-2,500 个 token。一个典型的 50 次动作的游戏会话大约使用 75,000-125,000 个 token。

AI 真的能玩好 DOOM 吗? 它能导航关卡、找到敌人、瞄准和战斗。在中等难度下,它在 E1M1 上每场会话大约能击杀 5-10 个敌人。它在对付部分掩体后的敌人和穿越复杂门序列时会遇到困难。当你指挥它时,它会表现得更好。

我可以玩特定关卡吗? 可以。向 doom_start 传递 episode 和 map 参数。例如,第 1 章第 3 关就是 episode:1, map:3。

我死了会怎样? 引擎会报告 HP:0 并提供死亡画面的截图。目前会话内没有重启功能——要重新玩,请开始新对话。

这支持多人游戏吗? 还没有。DOOM 的多人协议理论上可以支持多智能体游玩,但尚未实现。

AI 会作弊吗?它能看穿墙壁吗? 不会。敌人检测使用 DOOM 原生的视线检查(P_CheckSight)。AI 只能看到屏幕上可见的敌人。物品通过接近检测,但 AI 仍然需要走过去才能拾取。


架构

src/main.rs         MCP JSON-RPC server over stdio
src/doom.rs         Engine FFI wrapper: init, tick, frame capture, state extraction
src/renderer.rs     PNG rendering (216-color palette thumbnails for MCP, full RGB for screenshots)
src/paths.rs        WAD file discovery across platforms
src/log.rs          Debug logging to file
build.rs            Compiles doomgeneric C sources via cc crate (whitelist approach)
csrc/platform.c     DG_ callbacks, virtual time, key injection, enemy/item/door detection

该二进制在编译时链接 doomgeneric C 引擎。运行时它是单个进程,不产生子进程。帧从共享屏幕缓冲区读取,按键输入通过 FFI 注入。

虚拟时间 - 引擎的时钟与墙钟时间解耦。每次 doomgeneric_Tick() 精确推进一个游戏 tick(1/35 秒),无论实际经过多少时间。这使游戏玩法具有确定性,并防止 tick 被跳过。

敌人和物品检测 - 服务器遍历引擎的内部对象列表(thinker_t 链)以查找附近的敌人和可拾取物品。视线检查使用 Doom 原生的 P_CheckSight()。只报告可见的敌人,以防止“透视”作弊。


开发

要求:Rust 工具链、GCC、Make、Git、curl、unzip。

git clone https://github.com/gunnargrosch/doom-mcp.git
cd doom-mcp
bash scripts/setup.sh      # clones engines, downloads Freedoom WAD
cargo build --release       # compiles everything into a single binary
cargo test                  # runs unit + integration tests

注册本地构建以进行测试:

claude mcp add doom --scope user -- ./target/release/doom-mcp

启用调试日志:

claude mcp add doom --scope user -e DOOM_MCP_DEBUG=1 -- ./target/release/doom-mcp
tail -f /tmp/doom-mcp.log   # Linux/macOS (Windows: %TEMP%\doom-mcp.log)

npm 包

在本地构建 npm 包:

bash scripts/build-npm.sh   # copies binary + WAD into npm/
cd npm && npm pack           # creates doom-mcp-0.1.2.tgz

发布(需要 npm 账户 + NPM_TOKEN 用于 CI):

cd npm && npm publish

致谢


更新日志

参见 CHANGELOG.md 获取详细的更改列表。

许可证

本仓库中的 MCP 服务器代码采用 MIT 许可证。

doomgeneric 采用 GPL-2.0 许可证,并在构建时克隆(非内置)。Freedoom WAD 根据 BSD 风格许可证分发。

Related MCP Connectors

Related MCP Servers