ygopro-mcp
This MCP server lets an LLM/agent inspect and control a YGOPro client to play duels and manage rooms via semantic actions.
Read full duel state: turn, phase, LP, hand/field/grave/deck, card details, prompt counters.
Long-poll for the next decision prompt with
control_wait_prompt.List available semantic actions with
control_actions, then execute one by id withcontrol_act_id.Submit raw/int32 responses directly with
control_actwhen needed.Manage a room/lobby: join a server, preload a deck, ready up, start the duel as host.
Surrender the current duel and read recent chat/system messages.
Check control-layer health and inspect the last raw server message for debugging.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ygopro-mcp wait for my next duel prompt and show the available actions"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
ygopro-mcp
把 YGOPro 客户端接到 MCP(Model Context Protocol):LLM / agent 通过 20 个 MCP 工具, 用「语义动作」打牌——不用拼 CTOS/STOC 二进制帧,也不需要用像素点屏幕。
LLM / agent(MCP 宿主)
│ MCP over stdio (JSON-RPC)
▼
bridge/mcp-server.mjs 薄桥:20 个工具 → HTTP
│ HTTP 127.0.0.1:7788(房主)/ 7789(客机)
▼
带控制层的 YGOPro 客户端 进程内 HTTP server + 动作编码 + UI 注入
│ CTOS_RESPONSE / STOC_*
▼
ygopro 内核(ocgcore)+ 真实客户端窗口控制层负责:协议编解码、线程安全、把「召唤/盖放/发动/攻击/选卡」编码成内核能接受的响应, 并尽量走真实 UI 注入(点不中时自动回退为直连响应,保证绝不死锁)。
bridge 只做两件事:把 MCP 工具映射成 HTTP 调用;提供一个参考策略(
policy-semantic.mjs) 和运维工具(doctor / supervisor / netfault / net-probe)。
1. 前置条件
需要 | 说明 |
带控制层的 YGOPro 客户端 | 本仓库不包含客户端二进制。控制层是客户端源码里的扩展( |
Node.js ≥ 18 | 只用内置模块( |
(可选)卡组 | 客户端自己的 |
控制端口:房主默认 7788,客机默认 7789(客户端用
YGO_CONTROL_PORT指定)。
Related MCP server: lemonade-bench
2. 快速开始(3 步)
# ① 先启动带控制层的客户端(房主 / 客机各一个进程)
# 房主示例(控制端口 7788,监听 7911)
$env:YGO_CONTROL_PORT='7788'
.\mycard-client\bin\release\x64\YGOPro.exe -c -h 127.0.0.1 -p 7911 -n HostA -d Blackwing -k
# ② 启动 MCP server(stdio;本身不占网络端口)
cd bridge
npm start # 等价于 node mcp-server.mjs
# 客机位(7789)时:
# $env:CONTROL_URL='http://127.0.0.1:7789'; npm start
# ③ 在你的 MCP 宿主里配置(示例见 examples/)
# command = node
# args = ["<绝对路径>/bridge/mcp-server.mjs"]
# env = { CONTROL_URL: "http://127.0.0.1:7788" }宿主配置片段:examples/claude_desktop_config.json(Claude Desktop)、examples/cursor.mcp.json
(Cursor)、examples/dsh.mcp.json(DeepSeek Harness)。路径换成你自己的即可。
最小调用循环(agent 侧):
control_wait_prompt({since: lastSeq}) // 长轮询,等一个需要你回答的 prompt
control_actions() // 本 prompt 的候选:{id, kind, label}
control_act_id({id}) // 提交你选中的候选
lastSeq = prompt.seq三条铁律:① 动作必须匹配当前 seq(旧 seq 会被拒:stale seq);② /state.started ≠
/health.started(前者是"决斗已开始",后者是"控制服务在监听");③ 看到 UI fallback 是正常兜底,不是故障。
3. 自检
cd bridge
npm run doctor # = node doctor.mjs(默认探测 127.0.0.1:7788)
node doctor.mjs --port 7789 # 客机位
node doctor.mjs --client "C:\path\to\YGOPro.exe" # 顺带核对 exe 指纹(size)
node doctor.mjs --client "C:\path\to\YGOPro.exe" --strict-build # 发布自检:size + sha256 都比输出 [GREEN]/[YELLOW]/[RED]/[INFO] 每项检查 + HINTS + JSON;退出码 0 = 全绿,1 = 有问题。
没有客户端时会输出 RED 并提示「先启动带控制层的 YGOPro 客户端(房主 7788 / 客机 7789)」。
--client默认只比 size(跨机/跨时区/复制场景都可移植);加--strict-build时才比 sha256。 这两个必须区分:真实出现过"两个不同 build 的 exe 大小完全一样(都是 6,295,040 B)"的情况,只看 size 分辨不出。
4. 目录说明
路径 | 类别 | 作用 |
| runtime | MCP stdio server,20 个工具 → HTTP |
| runtime | 参考策略(语义决策循环;可当 LLM 的替身) |
| runtime | 常驻监护:读 |
| ops | 自检(本文件) |
| ops | 故障注入 TCP 代理( |
| ops | 轮询 |
| ops | 本地 LAN 一键起房/客机跑局 |
| ops | 掉线检测实验(host + 客机走 netfault + 注入故障 + 汇总) |
| doc | 对应工具的用法 |
| doc | 权威接口规范与设计文档(见下) |
| doc | MCP 宿主配置片段 |
| dev-only | 维护者的开发/排障脚本(一次性探针、旧实验脚本),不属于运行时分发内容,分发时可整目录删掉 |
维护者的开发/排障脚本(一次性探针、旧实验脚本)不属于运行时分发内容。
5. 已知限制
LAN 不支持续局:本地 LAN 服务端不能"掉线后回到原对局";
supervisor --profile lan只检测+记账。 真正的续局验证只能在线上(--profile ranked,需要客户端 journal//net支持)。ranked(线上排位) 需要较新的客户端构建(
/net、isWin/isLoss/isDraw、deckError、prompt 快照一致性修复); 旧构建会缺字段(doctor 会提示,policy 会记isWin=unknown而不是猜)。自动化有账号风险:排位自动对战可能违反服务条款/被判异常,请自行评估;本仓库不含任何账号凭据。
不含卡图/卡表/卡组:只做控制层桥接,卡牌数据由客户端自己管理。
UI 注入不是 100%:部分语义词(
select/sum/sort/counter/announce/auto)仍走直连响应(刻意保留的兜底), 详见docs/direct-actions.md。动作被内核拒绝时看
/state.retryCount/retryStreak;prompt 卡住时看/state.pipeline与pipeline.recentMsgs(需要新构建)。Bo3 新局(Game2/3)会重置结果状态:客户端在
STOC_DUEL_START时把winPlayer/winPlayerLocal/winReason重置为-1、awaiting=false、tpPending/sidePending=false(日志DUEL_START reset result state (match game N))。 旧客户端可能让新局沿用上一局的winPlayer,导致 policy 一开局就误判"对局已结束"并退出——遇到请升级客户端。
更新记录(近期)
2026-11-27 客户端
17:22:16 / 6,338,048 B:position 掩码 +ignorekeep-own 定稿版——MSG_SELECT_POSITION捕获合法掩码 →/prompt.selectablePositions/selectablePositionsHex;/actions.position按掩码动态生成(表攻/里攻/表守/里守),旧版写死defense=0x02(=里侧攻击,非法响应seq连发)已修;编码校验掩码,单 bit 自动应答。当前构建/actions项只有id/kind/label(无index字段)——按label选、act_id自动发正确 POS 值(日志i=1/2/4/8);index字段自下个 build(>17:22:16)起提供。ignore不再吞我方诱发:activatable_cards有我方候选时保留窗口(YGO_CHAIN_IGNORE_KEEP_OWN默认 1,0=旧行为;日志ownCand=.. ignoreDecline=.. keepOwn=..)。验证position-mask-ignore-validation.md:mask 0x5 选 defense 发i=4推进/无 RETRY、mask 0x9 里守i=8、ignore 下我方诱发正常弹出、env=0 对照旧行为、四态回归 PASS。2026-11-27 客户端
17:09:18 / 6,336,000 B(历史):side_ok label 三态 +changed版——/actions(sidePending)side_oklabel 三态(no changes / confirm side deck (changed) / counts mismatch),顶格changed:true|false;counts相等 ≠ 没换牌。现已被17:22:16版取代。2026-11-27 客户端
15:03:45 / 6,335,488 B(历史):SelfSeat 修复版(lastChainEvent阵营反)——SelfSeat()在对局/换备期间以dInfo.isFirst为准(isFirst==true ⟺ 服务端座位 0);修 MC 不发STOC_TYPE_CHANGE、launcher-d/-k使-c/-jfallback 失效时 guest 被错判 seat 0;SEAT resolved seat=.. isFirst=..可核对;验证lastchain-side-validation.md(guest「我方发动 [黑洞]」/ host「对手发动 [黑洞]」)。现已被17:09:18版取代。2026-11-27 客户端
11:04:58 / 6,334,976 B(历史):时点四态normal定稿版——0=all(全部时点) / 1=avail(全部可用时点) / 2=ignore(无视所有时点) / 3=normal(常用时点),进入对局默认normal;YGO_CHAIN_MODE4 值默认 normal;行为语义见MCP-INTERFACE.md/PLAYBOOK-FULL.md(all=任何时候都给窗口;avail=有合法动作就问;ignore=自动放弃但强制/必发仍处理;normal=在 avail 基础上过滤非常用询问)。现已被15:03:45版取代。2026-11-26 客户端
10:26:12 / 6,335,488 B(历史):座位坐标/isMine统一修复版——ToServerSeat(localCtrl,mySeat)全路径统一(ctrl=服务端座位、isMine==(ctrl==mySeat)、name回填)、places含ctrlRaw、chain label 修正;验证seat-isMine-validation.md。现已被11:04:58版取代。2026-11-23 客户端
14:53:57 / 6,334,464 B(历史):MCP 实战反馈修复版——wait_prompt阻塞语义修正(seq>since && awaiting)、候选卡ctrl/isMine修正 +selectableCards[].resp(响应用resp/seqNo不是下标i)、BUG-1 归类外部断线。现已被10:26:12版取代。2026-11-20 客户端
15:34:59 / 6,329,856 B(历史):stall 诊断版(判死逻辑不变)——/net新增stallMs/oppTimeLeft/oppClockFresh、NET STALL(YGO_STALL_WARN_MS默认 120000/30s);stallMs>120s && oppClockFresh=false= 对方卡住 →control_leave离桌重排。现已被14:53:57版取代。2026-11-19 客户端
17:33:31 / 6,330,368 B(历史):看门狗回归修复版(修g_timeLeft不清零导致clockRunning永久 true)——g_timeLeftTick+clockFresh(<3s)+clockRunning=ourTurn&&clockFresh;/net新增ourTurn/oppTurn/timeLeft/clockFresh;heartbeat 空闲时 15s;验证net-watchdog-validation.md4/4 PASS;不再建议 600000(默认 60000)。现已被15:34:59版取代。2026-11-17 客户端
15:18:21 / 6,329,344 B(历史):逐卡选择修复版(修"有对象的攻击不结算")——/actions对MSG_SELECT_CARD/TRIBUTE/UNSELECT_CARD(单目标)每个候选一条kind:"select_card"(label 带 atk/def/loc/seq),select_auto只作多选兜底;/prompt.selectableCards[]新增position、战斗目标窗isAttackTarget:true;单目标id=0仍等价旧行为;验证attack-target-choice-validation.mdA–E PASS。现已被17:33:31版取代。2026-11-16 客户端
11:31:00 / 6,328,320 B(历史):probe-fails 误判修复版——/tip探活超时不再单独判死(旧版 2 次失败即confirmed_dead+断线,对手长展开 7.5s 静默会被误踢);probe 失败只置probe_failed并打NET probe failed fails=.. (defer to passive silence guard);新增YGO_NET_PROBE_FAIL_MAX(默认 5,仅降级/日志);判死统一由被动静默YGO_NET_DEAD_SILENCE_MS(默认 60s)+ 我方回合/倒计时/awaiting/busy 守卫决定;现已被15:18:21版取代。2026-11-16 客户端
10:25:14 / 6,327,808 B(历史):EOF guard 版(防"LLM 静默 → 服务端 AFK ~90s eof")——YGO_PROMPT_AUTO_DEFAULT_MS(默认 60000,0=关)60s 自动发保守默认、YGO_PROMPT_IDLE_WARN_MS(45000)告警、/prompt.awaitingSinceMs;现已被11:31:00版取代。2026-11-15 客户端
20:11:00 / 6,323,712 B(历史):SORT 已实机验证(realMsg=25 len=3 hex=000102,裸位序无前缀、直连字节UI skip sort -> direct bytes)+ announce 140–143 修复(kPromptMsgs/announceNumberValues/announce_number/race/attrib/card;number=数值、race/attrib=掩码、card=卡号)+ 攻击目标/TP 自动/判死 60s;现已被10:25:14版取代。2026-11-15 客户端
19:05:42 / 6,321,152 B(历史):真实 LLM 使用反馈修复版——① 战斗攻击目标(curMsg 15↔10循环、攻击不结算)修复(selectMin==0→[0]、select 直连字节、stale seq/snapshot 防护),LAN 实机 PASS(send15=2 retry15=0、hex=0100、LP 8000→3900→1850、loops=0);② TP 默认 2s 自动答(YGO_TP_AUTO/YGO_TP_AUTO_RES,默认res=2=后攻,可配YGO_TP_AUTO_RES=1先攻;实测TP auto-answered res=2);③ 判死误杀修复(默认阈值 60s + 我方回合/倒计时在走不判死,NET ALIVE reason=our-turn-idle;实测 40s 思考无 NET DEAD;旧 exe 仍需YGO_NET_DEAD_SILENCE_MS=600000);④MSG_SORT_CARD裸位序字节无前缀(hex=0001)已实现,待 LAN 实机触发验证;现已被20:11:00版取代。2026-11-13 客户端
14:51:46 / 6,319,104 B(历史):LAN 全流程验收(VERDICT: over=True won=2 games=2)——/state.match整场结果(game/over/games[]/gamesWonLocal/gamesWonOpp/lastWinnerLocal/lastReasonName)、/startlatch 修复、YGO_TP/YGO_SIDE_AUTO、控制驱动STOC_REPLAY直接跳过(replay: dialog skipped,LAN 实测 双方各 2 次、replay-save=0、stoc=23 stall=0);MCP 侧新增control_match一句话报结果;现已被19:05:42版取代。2026-11-13 客户端
01:11:32 / 6,316,032 B(历史):控制驱动下STOC_REPLAY跳过 + 3/3 Bo3 实机验收;现已被14:51:46版取代。2026-11-10 客户端
00:07:02 / 6,295,040 B:Bo3 Game2/3 结果状态重置(DUEL_START reset result state); bridge 侧同步 fingerprint + sha256,doctor 新增--strict-build(size+sha256)。2026-11-09 客户端:Bo3 换备牌
side_ok(STOC_CHANGE_SIDE)+ 回放保存框自动跳过(限流 1s)。2026-11-08 客户端:先/后攻交给 LLM(
/actions kind:"tp");policy 支持TP_PREF。2026-11-07 客户端:排位全链路(拿房→选卡组→准备→对局→自然结算)、
isWin/isLoss/isDraw、deckError、/net探活。
6. 权威文档
文档 | 内容 |
全流程权威操作手册(给 AI/LLM,零歧义):系统架构、20 个工具逐个说明(参数/返回/适用/失败)、排队→进房→卡组→准备→开始→TP→决策→局末→换备→下一局→整场结束的每一步判定、状态字段字典、计时节奏、完整实战脚本 + 真实时间线、排错表、已知限制 | |
精简版操作手册(给 AI):一页速查;详细版见 | |
接口规范(权威):20 个工具、所有 HTTP 端点、 | |
掉线/重连设计: | |
supervisor 用法、状态机、JSONL 字段 | |
哪些动作走 UI、哪些走直连、对 LLM 的影响、改进路线 | |
掉线检测量化工具 / 故障注入代理用法 |
环境变量清单见 .env.example(与代码里 process.env.* 一一对应)。
7. FAQ / 排障
Q: doctor.mjs 报 RED "连不上 127.0.0.1:7788"?
A: 客户端没起、或没用带控制层的构建、或端口不是 7788。检查客户端启动日志是否有
control: started port=7788;用 netstat -ano | findstr :7788 看端口。
Q: 两个客户端同时跑,端口冲突?
A: 每个客户端要不同的 YGO_CONTROL_PORT:房主 7788、客机 7789(lan-run.ps1 就是这么分的)。
对应 MCP server 的 CONTROL_URL 也要指向你要控制的那一端。
Q: 客机想走代理/故障注入,但流量没过去?
A: 客户端的 -j 参数会用 system.conf 的 lasthost/lastport 自动加入并忽略 -p;
要经代理必须不带 -j、起来后用控制层 GET /join?ip=127.0.0.1&port=7912&pass= 显式进房,
并断言代理 totalConnections >= 1(reconnect-lab-run.ps1 已内置该断言)。
Q: 动作被拒 (ok:false / stale seq)?
A: prompt 已经前进了。丢弃这次决策,重新 control_wait_prompt + control_actions;
/state.retryStreak 持续上涨说明响应编码有问题(看 /state.lastRetryAfterMsg)。
Q: 卡组非法 / 开局不动?
A: 新构建在 /state.deckError 给出原因;用合法的 .ydk(例如 Blackwing.ydk)。
旧构建会弹"卡组非法"模态框阻塞,需要新构建(会自动 suppress)。
Q: 怎么确认"我们赢了还是输了"?
A: 用 /state.isWin(本地视角)。不要用 winPlayer(那是 raw 座位号,本机是 raw seat 1,
winPlayer=0 表示对手赢);旧构建没有 isWin 时用 winPlayerLocal===0,再没有就记 unknown,不要猜。
Available Tools
14 toolscontrol_actB
Submit a response for the prompt with the given seq. Use either i (int32 encoded response, e.g. idle (index<<16)|cmd, -1 for chain decline) or hex (raw response bytes, e.g. card selection "0100" = select 1 card at index 0).
Inputs: seq (required), i, hex.
control_act_idB
Execute one of the actions returned by control_actions, by id.
Inputs: id (required).
control_actionsA
List the semantic actions available for the current prompt (id + kind + human label, e.g. summon/special summon/attack/chain/zone). The caller only picks an id; the client encodes the kernel response itself.
Inputs: no named parameters.
control_chatB
Recent server chat / system messages (useful to see why a room was rejected or a duel was kicked).
Inputs: no named parameters.
control_deckA
Preload a deck by name (file under deck/*.ydk). Call before control_ready so the deck update is valid.
Inputs: name.
control_healthC
Health check of the control layer.
Inputs: no named parameters.
control_joinB
Connect to a game server (LAN or a matchmade room).
Inputs: ip, pass, port.
control_lobbyA
Room/prep-screen state: our seat (0=host,1=guest), whether we are host, readiness of both seats, deck loaded, raw HS status bytes. Use this before ready/start.
Inputs: no named parameters.
control_msgA
Last raw server message (id, length, hex) - debug only.
Inputs: no named parameters.
control_readyA
Send CTOS_HS_READY (click the Ready button) for the current room.
Inputs: no named parameters.
control_startA
Click "Start" (CTOS_HS_START). Only valid when we are the host (seat 0) and both players are ready.
Inputs: no named parameters.
control_stateB
Get the full duel state: turn, phase, LP, hand/field/grave/deck counts with card details, pending prompt counters.
Inputs: no named parameters.
control_surrenderB
Surrender the current duel (CTOS_SURRENDER).
Inputs: no named parameters.
control_wait_promptB
Long-poll until it is this client's turn to respond. Returns the prompt: seq (pass it back to control_act), curMsg (what kind of decision), and candidate counters. This is the main agent loop primitive.
Inputs: since, timeout_ms.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 14 tools
Most tools map to distinct duel-control lifecycle stages (lobby, deck, ready, start, prompt, act, surrender), so selection is usually clear. The main overlap is the prompt-response group: control_act and control_act_id both submit a decision and differ mainly by encoding, though the raw-vs-semantic descriptions help.
All names share a consistent control_ namespace and snake_case formatting, making the set easy to scan. However, suffixes mix nouns (state, lobby, chat) and verbs (act, start, join) rather than following a pure verb_noun pattern.
Fourteen tools are well within a reasonable range for controlling a duel client, and each covers a distinct concern: session setup, prompt loop, action submission, state inspection, surrender, chat, and health. The debug/health/msg tools are minor extras but do not feel like bloat.
The surface covers join, deck preload, ready, start, prompt handling, action execution, state inspection, surrender, and chat, which is most of the duel session lifecycle. Minor gaps remain around explicit disconnect/leave and room creation or listing, with some room state visible only through chat or raw messages.
Related MCP Connectors
Stateless agentic tools over MCP: concept extraction, long-context, knowledge graph, planning.
214 tools for AI agents over one MCP endpoint: image, video, audio, 3D, data, storage, mail, GPUs.
Hosted MCP server to manage a restaurant menu from AI agents - 39 tools over the DuckHub API.
Make games with AI: one MCP server that connects your agent to Unity, Unreal and Godot editors.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to autonomously create characters, join matchmaking, and battle other LLMs in a turn-based game using 7 tools for status, abilities, and actions.ISC
- AlicenseAqualityDmaintenanceEnables tool-using language models to play Lemonade Tycoon Deluxe as a text-only business benchmark, exposing game UI state and actions as semantic MCP tools without vision or shell access.23MIT
- FlicenseNot gradedqualityCmaintenanceEnables LLMs to control a Minecraft bot and interact with the game through MCP tools, including observing state, moving, mining, crafting, building, farming, managing inventory, enchanting, and chatting in-game.1-
- AlicenseNot gradedqualityDmaintenanceProvides Yu-Gi-Oh! card data, banlist, deck management, OCG rules engine, duel simulation, replay analysis, and YGOPro2 bridge for AI agents via MCP.7BSD Zero Clause