MCP
Last updated:
- Published on
Overview
概述
Connect any Model Context Protocol client (Claude Desktop, IDE MCP plugins, etc.) to a running STS2 session with KitLib loaded (KitLib.Dev satellite). KitLib starts an in-game HTTP bridge on port 9877; the stdio proxy in tools/KitLib.Mcp (built with the official MCP C# SDK) forwards MCP messages to http://127.0.0.1:9877/messages.
Requires: Slay the Spire 2 running with KitLib (Dev module) loaded for tool execution (start the game before or keep it running while the client connects). Tool listing works without the game.
任意支持 Model Context Protocol 的客户端(Claude Desktop、IDE MCP 插件等)可连接到正在运行的 STS2 会话(需加载 KitLib,含 KitLib.Dev 卫星模块)。KitLib 在游戏内启动 9877 端口的 HTTP 桥;tools/KitLib.Mcp 里的 stdio 代理(基于官方 MCP C# SDK)把 MCP 消息转发到 http://127.0.0.1:9877/messages。
前提: 杀戮尖塔 2 已运行且加载 KitLib(Dev 模块),工具才会真正执行(可先开游戏再连客户端,或保持游戏运行)。仅列出工具不需要游戏在跑。
Tools
工具列表
get_game_state— Current run snapshot (HP, gold, deck, combat, enemies, …). In combat:playerPowers[](id,modelId,amount),phase/isPlayPhaseActive,enemies[].index+powers[]get_combat_stats— Combat event log withsince_sequencefor incremental checks (combatEvents:kind,sourceKey,amount, …)combat_action— Play a card, end turn, or use a potion.play_cardsuccess returnsafterState(player powers + enemy HP) unless pseudo-coop queued. When a pile/hand picker opens, may returnpendingSelection+selectionState; useselection_actionor passselection_card_idonplay_cardget_selection_state— Active combat card selection UI and indexed options (id, name, cost)selection_action— Pick cards on the active selection screen (card_index,card_indices, orcard_id)map_action— Map node, rewards, events, shop, restdev_get_session— Run active, game phase, dev-run flag, blocking startup promptsdev_list_save_slots— Save slots with metadata anddebugNotesfor AI selectiondev_tag_save_slot— SetdebugNoteson a slot (e.g.combat:ironclad-act1-boss)dev_load_save_slot— Load a DevMode save (async; polldev_get_session)dev_start_test_run— New test run from main menu (opens character select; optional seed)dev_list_cards— List cards in deck / hand / draw / discard / exhaust (or all piles)dev_add_card— Add a card to a pile (card_id,target,duration,upgrade_levels)dev_remove_card— Remove a card bycard_idorpile_indexfrom a piledev_add_relic— Grant a relic by model id (relic_id), or passsearchto list ids and raritiesdev_list_monsters— List monster model IDs (fordev_add_monster)dev_list_enemies— List enemies currently in combat (index, HP, monsterId)dev_add_monster— Add a monster mid-combat (DevMode enemy panel)dev_set_cheat— Toggle cheats or set multipliers (freeze_enemies,damage_multiplier, …)dev_set_stat— Set gold/energy/HP values or enable stat locksdev_hover— Focus a UI element so hover-only behaviour fires.targettakes an alias (map_node,reward_alternative,rest_option,relic,boss_icon,event_option,potion,card,creature,treasure_relic) or any node type name;target: "list"reports what is hoverable on screen,"none"unhovers,clickpresses after focusing
Health check: GET http://127.0.0.1:9877/health
get_game_state— 当前局快照(生命、金币、牌组、战斗、敌人等)。战斗中含playerPowers[](id、modelId、amount)、phase/isPlayPhaseActive、enemies[].index+powers[]get_combat_stats— 战斗事件日志;since_sequence可只取增量(combatEvents:kind、sourceKey、amount等)combat_action— 出牌、结束回合或使用药水。play_card成功会返回afterState(玩家能力 + 敌人生命),伪联机排队时除外。若弹出堆/手牌选择,可能返回pendingSelection+selectionState;可调用selection_action或在play_card上传selection_card_idget_selection_state— 当前战斗内卡牌选择界面及带 index 的选项(id、名称、费用)selection_action— 在打开的选择界面上点选(card_index、card_indices或card_id)map_action— 地图节点、奖励、事件、商店、休息dev_get_session— 是否在局、游戏阶段、是否 dev 局、阻塞的启动提示dev_list_save_slots— 存档槽及元数据、debugNotes(供 AI 选档)dev_tag_save_slot— 给槽位写debugNotes(如combat:ironclad-act1-boss)dev_load_save_slot— 加载 DevMode 存档(异步;轮询dev_get_session)dev_start_test_run— 主菜单开新测试局(会打开选角色;可选种子)dev_list_cards— 列出牌组 / 手牌 / 抽牌堆 / 弃牌堆 / 消耗堆(或全部堆)dev_add_card— 往某堆加牌(card_id、target、duration、upgrade_levels)dev_remove_card— 按card_id或pile_index从某堆移除dev_add_relic— 按 model id 授予遗物(relic_id);传search则列出 id 与稀有度dev_list_monsters— 怪物 model ID 列表(供dev_add_monster)dev_list_enemies— 当前战斗中的敌人(index、HP、monsterId)dev_add_monster— 战斗中加怪(Dev 敌人面板)dev_set_cheat— 开关作弊或设倍率(freeze_enemies、damage_multiplier等)dev_set_stat— 设金币/能量/生命或开启数值锁定dev_hover— 聚焦(悬停)UI 元素以触发只在悬停时发生的行为。target可用别名(map_node、reward_alternative、rest_option、relic、boss_icon、event_option、potion、card、creature、treasure_relic)或任意节点类型名;target: "list"列出当前屏幕上可悬停的类型,"none"取消悬停,click在聚焦后按下
健康检查:GET http://127.0.0.1:9877/health
Agent debug loop
Agent 调试循环
Bootstrap a session (deploy mod, launch game, wait for bridge):
make dev-sessionTypical MCP agent flow after the bridge is ready:
dev_list_save_slots— Pick a slot bydebugNotes,name, floor, or character.dev_load_save_slot— Load the chosen slot, ordev_start_test_runwhen no suitable save exists (character select is manual in this MVP).- Poll
dev_get_sessionevery 1–2s untilrunActiveistrue(load is async; allow up to ~30s). get_game_state+combat_action/map_actionto drive the run.
Before a debugging session, tag saves with dev_tag_save_slot so agents can pick the right snapshot later. Suggested debugNotes format: combat:ironclad-act1-boss, map:shop-test.
Known blockers
- Startup progress loss prompts must be dismissed manually (
blockingPromptsindev_get_session). GET /healthcan respond while the Godot main thread is stuck; if MCP tool calls time out, stop and investigate.- After changing mod code, run
make syncand restart the game.
Not in this MVP: auto character select, hang watchdog (kill/restart/reload), or autonomous code fixes.
启动会话(部署 mod、开游戏、等桥就绪):
make dev-session桥就绪后典型的 MCP agent 流程:
dev_list_save_slots— 按debugNotes、name、层数或角色选槽。dev_load_save_slot— 加载所选槽,或 没有合适存档时用dev_start_test_run(本 MVP 选角色仍需手动)。- 每 1–2 秒轮询
dev_get_session,直到runActive为true(加载异步,最多约 30 秒)。 get_game_state+combat_action/map_action驱动对局。
调试前可用 dev_tag_save_slot 给存档打标签,方便 agent 以后选对快照。建议 debugNotes 格式:combat:ironclad-act1-boss、map:shop-test。
已知阻塞
- 启动时的 进度丢失 提示需手动关掉(看
dev_get_session的blockingPrompts)。 GET /health可能在 Godot 主线程卡死时仍返回;MCP 工具超时则应停手排查。- 改 mod 代码后执行
make sync并重启游戏。
本 MVP 尚未包含: 自动选角色、挂死看门狗(杀进程/重启/重载)、或自主改代码。
Build proxy
构建代理
Local dev (DLL; used by dotnet exec config below):
dotnet build tools/KitLib.Mcp/KitLib.Mcp.csproj -c ReleaseSelf-contained executable (repo Makefile; default RID is your host OS):
make build-toolsOutput: build/tools/KitLib.Mcp/<rid>/publish/KitLib.Mcp.exe (Windows) or KitLib.Mcp (macOS/Linux).
Cross-compile manually, for example:
dotnet publish tools/KitLib.Mcp/KitLib.Mcp.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true
dotnet publish tools/KitLib.Mcp/KitLib.Mcp.csproj -c Release -r osx-arm64 --self-contained true -p:PublishSingleFile=true本地开发(DLL;下面 dotnet exec 配置会用到):
dotnet build tools/KitLib.Mcp/KitLib.Mcp.csproj -c Release自包含可执行文件(仓库 Makefile;默认 RID 为当前系统):
make build-tools输出:build/tools/KitLib.Mcp/<rid>/publish/KitLib.Mcp.exe(Windows)或 KitLib.Mcp(macOS/Linux)。
手动交叉编译示例:
dotnet publish tools/KitLib.Mcp/KitLib.Mcp.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true
dotnet publish tools/KitLib.Mcp/KitLib.Mcp.csproj -c Release -r osx-arm64 --self-contained true -p:PublishSingleFile=trueClient configuration
客户端配置
Add a devmode entry under mcpServers in your MCP client config (stdio transport). This is one server among many — keep your existing entries and only add or update the devmode block. Exact config file path depends on the client; see its MCP documentation.
Paste one of the blocks below into your existing MCP client config (merge with your other mcpServers entries). Default port is 9877 (must match McpConfig.Port in the mod). Override with --port on the proxy only if you also change the mod source and rebuild KitLib.
Cross-platform development (dotnet exec; paths are relative to the repo / workspace root):
{
"mcpServers": {
"devmode": {
"command": "dotnet",
"args": [
"exec",
"tools/KitLib.Mcp/bin/Release/net8.0/KitLib.Mcp.dll",
"--",
"--port",
"9877"
]
},
"your-other-mcp-server": {
"command": "...",
"args": ["..."]
}
}
}Requires .NET 8 runtime (dotnet --list-runtimes should include Microsoft.NETCore.App 8.x).
Published proxy (after make build-tools or dotnet publish; adjust the path):
Windows:
{
"mcpServers": {
"devmode": {
"command": "C:/path/to/KitLib.Mcp.exe",
"args": ["--port", "9877"]
}
}
}macOS / Linux:
{
"mcpServers": {
"devmode": {
"command": "/path/to/KitLib.Mcp",
"args": ["--port", "9877"]
}
}
}在 MCP 客户端配置的 mcpServers 下添加 devmode 条目(stdio 传输)。这是众多服务器之一——保留现有条目,只新增或更新 devmode 块。配置文件路径因客户端而异,见其 MCP 文档。
把下面某一块粘贴进现有配置(与其他 mcpServers 合并)。默认端口 9877(须与 mod 里 McpConfig.Port 一致)。只有同时改 mod 源码并重编 KitLib 时,才在代理上用 --port 覆盖。
跨平台开发(dotnet exec;路径相对仓库根目录):
{
"mcpServers": {
"devmode": {
"command": "dotnet",
"args": [
"exec",
"tools/KitLib.Mcp/bin/Release/net8.0/KitLib.Mcp.dll",
"--",
"--port",
"9877"
]
},
"your-other-mcp-server": {
"command": "...",
"args": ["..."]
}
}
}需要 .NET 8 运行时(dotnet --list-runtimes 应包含 Microsoft.NETCore.App 8.x)。
已发布代理(make build-tools 或 dotnet publish 之后;按实际路径改):
Windows:
{
"mcpServers": {
"devmode": {
"command": "C:/path/to/KitLib.Mcp.exe",
"args": ["--port", "9877"]
}
}
}macOS / Linux:
{
"mcpServers": {
"devmode": {
"command": "/path/to/KitLib.Mcp",
"args": ["--port", "9877"]
}
}
}HTTP bridge (manual test)
HTTP 桥(手动测试)
With the game running and KitLib loaded:
curl -s http://127.0.0.1:9877/healthcurl -s -X POST http://127.0.0.1:9877/messages \
-H "Content-Type: application/json" \
-d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"dev_get_session\",\"arguments\":{}}}"游戏运行且 KitLib 已加载时:
curl -s http://127.0.0.1:9877/healthcurl -s -X POST http://127.0.0.1:9877/messages \
-H "Content-Type: application/json" \
-d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"dev_get_session\",\"arguments\":{}}}"