杀戮尖塔2的MOD,将杀戮尖塔2的游戏状态与操作暴露为本地 HTTP API 包装成 MCP Server,供支持 MCP 的AI客户端直接调用
C#
339
687 commits
updated Oct 7, 2026
https://github.com/user-attachments/assets/89353468-a299-4315-9516-e520bcbfbd4b
In-Game AI Companion & Autonomous Gameplay Mod for Slay the Spire 2
中文说明 (README.zh-CN) • Current Status • Historical Co-op Evidence • API Docs • MCP Tools Guide
:8080). The overlay Connect tab can expose MCP at /mcp on the same port for Cursor, Claude, and Codex.The easiest way to play is the Steam Workshop page. Subscribe, wait for the download, then Steam → Play with Mods. You do not copy any files. That page is a short player guide; this README has extra detail if you need it.
This mod is still in development. Some things may be unfinished or break. Please send suggestions and issues here: GitHub Issues.
Option A: Steam Workshop (recommended)
Option B: GitHub zip
sts2-ai-agent-v*-windows.zip from GitHub Releases and unzip it.mod/ folder into the game mods/ folder (create it if needed):
STS2AIAgent.dll
STS2AIAgent.pck
mod_id.json
C:\Program Files (x86)\Steam\steamapps\common\Slay the Spire 2\mods\STS2AIAgent.dll
C:\Program Files (x86)\Steam\steamapps\common\Slay the Spire 2\mods\STS2AIAgent.pck
C:\Program Files (x86)\Steam\steamapps\common\Slay the Spire 2\mods\mod_id.json
Do not copy the whole zip or mcp_server/ into mods/. mcp_server/ is optional for developers.Do not double-install: if you already subscribed on Workshop and also copied GitHub files, delete the manual copies from mods/ and keep the Workshop item. Two copies can load twice.
F8 (configurable) or click the grey AI tab on the right edge of the screen to open the Agent window.F8 or click AI. A default URL plus model name is not treated as ready.select_character then embark), tick Disable automatic character pick above the invite button (it sets companionAutoSelectCharacter to false in the mod's settings.json); the teammate then waits on the character screen, for the AI driving it or for you, without a timeout./health reports play_phase: "paused" with session_requests: 0, because this route never calls a model.GET /state and POST /action. Find its HTTP API through data.companion.api_port on the main window's GET /health (that port is usually not 8080). The teammate can only act for its own character; acting outside it returns 403 forbidden_actor. On this route data.companion.auto_play is false.POST /teammate/control on the main window, body {"running": true|false}. This is the supported entry point and it needs no session token (the main window holds the teammate session token itself). running: true still requires a verified play model, exactly like the in-game Continue Auto-Play button; running: false works at any time.Both routes enforce the same structural conditions (you are on the main menu, this is not the teammate instance, and the character has no auto-play already running); only the model gate differs. Full contract: docs/api.md.
--force-steam off and increments clientId in offline mode. Automatically derives and clones settings.companion.json so both instances never write over each other's configurations or save slots.| Mechanism | Description | Player Benefit |
|---|---|---|
Session Budget Guard (SessionBudgetGuard) | Tracks provider-reported JSON/SSE usage and requests; checks configured caps before new calls | Stops new calls at the limit and shows next steps; in-flight calls can add usage, and missing usage remains unknown |
Autoplay Circuit Breaker (AutoPlayRecovery) | Automatic halt after 3 consecutive failures with 2s/4s exponential backoff | Prevents spin loops on unrecognized game dialogs or invalid choices |
| Immediate Config Error Exit | Halts immediately upon receiving HTTP 401, 403, or 404 responses | Stops wasted token calls when API keys expire or are mistyped |
Run Boundary Protection (CurrentRunBoundary) | Scoped strictly to the active run's unique runId | Exiting a run, surrendering, or returning to lobby immediately stops autoplay |
Process & Settings Isolation (CoopLaunchPolicy) | Dedicated companion settings file and safe clientId stepping | Complete segregation between main and companion instances |
┌───────────────────────────────────────────────────────────┐
│ Slay the Spire 2 │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ STS2AIAgent (C# Mod) │ │
│ │ - Godot In-Game Overlay UI (F8) │ │
│ │ - OpenAI-compatible Client & Budget Guard │ │
│ │ - Autoplay Decision Loop & Recovery Controller │ │
│ │ - GameThread Action / State Synchronizer │ │
│ │ - Local Dual-Instance Process Launcher │ │
│ └───────────────────────┬─────────────────────────────┘ │
└──────────────────────────┼────────────────────────────────┘
│ Local HTTP API (:8080)
│ Optional MCP (:8080/mcp)
▼
External Agents (Cursor / Claude Desktop / Codex)
The mod runs an embedded HTTP server on http://127.0.0.1:8080 (with dynamic fallback on port contention):
GET /health: Health check, returns api_port, instance_role, mcp_enabled, and process PID. On the main window, once this co-op session has connected to a teammate, it also returns a companion block: the teammate's api_host, api_port, and process_id, plus this route's auto_play flag.GET /state: Full raw game state JSON.GET /actions/available: Currently available legal actions and schema.GET /events/stream: Real-time SSE stream for game events.POST /action: Dispatch an action (e.g., play_card, choose_map_node, proceed).GET /data/{collection}: Export a bundled game metadata collection (cards, relics, monsters, potions, events, powers, characters).POST /session/control: Start or pause autoplay for this instance ({"running": true|false}).POST /teammate/control: Start or pause the AI teammate from the main window ({"running": true|false}). Loopback only and main-window only; this is the supported entry point for an external agent (see Option C above).POST /companion/control / POST /companion/message: Control or message the AI teammate instance (local dual-instance only). These are the teammate instance's own controlled endpoints, called by the main process with this session's token; external callers should use POST /teammate/control instead.POST /mcp: Optional MCP (Streamable HTTP). Off by default; enable it on the overlay Connect tab.| If you want to… | Use | Needs | How to confirm |
|---|---|---|---|
| Play with an AI teammate | In-game overlay, MCP off | Mod only | F8 / AI tab opens AI Teammate |
| Drive the game from Cursor / Claude / Codex | Native MCP on the Connect tab | Mod only | Copy the actual URL shown (port may not be 8080) |
| stdio, layered/full, or compatibility | Optional Python mcp_server/ | Python + uv | From the release root, run scripts/test-mcp-tool-profile.ps1 |
External clients: F8 → Connect → enable Open MCP service → copy the URL or JSON. It shares the HTTP API port and listens on 127.0.0.1 only. Do not hard-code 8080 or 8765.
The Python sidecar is not required for players and is not the recommended entry.
Default shape (replace the port with the one on the Connect tab):
{
"mcpServers": {
"sts2-ai-agent": {
"type": "http",
"url": "http://127.0.0.1:8080/mcp"
}
}
}
Built-in MCP tools add health_check on top of the surface in-game Auto-Play uses: get_game_state, get_available_actions, act, get_game_data_*, wait_until_actionable. The default guided profile also exposes decide (state, available actions and scene guidance from one call), get_scene_guidance, get_raw_game_state, get_decision_log, get_run_summary and diff_state.
In-game Auto-Play already follows the bundled play contract. If you drive the game from an external agent over MCP (Cursor, Claude, Codex, or the optional Python sidecar), also load the companion skill sts2-mcp-player. Connecting tools without that skill can click legal actions; the skill is what matches in-game play quality.
Standalone core and MCP contract tests run without the game client. Godot UI, real-game actions, multiplayer, saves, and installation channels require separate live validation:
The GitHub zip includes only the optional sidecar launch and profile-check
scripts under scripts/. The build, preflight, and live-game commands below
require a source checkout.
⚠️ Close the game first so the DLL file is not locked by the OS.
# Windows
powershell -ExecutionPolicy Bypass -File ".\scripts\build-mod.ps1" -Configuration Release
# Linux / macOS
./scripts/build-mod.sh --configuration Release
dotnet run --project STS2AIAgent.Tests/STS2AIAgent.Tests.csproj
Covers the session budget guard, autoplay recovery backoff, run-boundary interception, offline dual-instance isolation, HTTP port fallback, and native save switching, among others.cd mcp_server
uv run python -m unittest discover -s tests -v
powershell -ExecutionPolicy Bypass -File ".\scripts\preflight-release.ps1"
mod/ folder into the game mods/ folder. Do not keep both Workshop and a manual copy.--force-steam off and steps clientId automatically. Check if third-party antivirus software blocked launching the child process.STS2-Agent/
├── STS2AIAgent/ # C# In-Game Mod (Overlay UI, LLM Client, Decision Loop, Budget Guard)
├── STS2AIAgent.Tests/ # Standalone C# tests (no game client required)
├── mcp_server/ # FastMCP Server implementation
├── scripts/ # Build, packaging, startup, and preflight scripts
├── skills/ # State-first gameplay skill specifications
├── docs/ # Developer reference and API documentation
├── PRODUCT_PLAN_CURRENT.md # Current product status and evidence boundary
└── COOP_DELIVERY.md # Historical co-op evidence index
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).
159 followers · starred Apr 2026
8 followers · starred Mar 2026
149 followers · starred Mar 2026
11 followers · starred Mar 2026
杀戮尖塔2的MOD,将杀戮尖塔2的游戏状态与操作暴露为本地 HTTP API 包装成 MCP Server,供支持 MCP 的AI客户端直接调用
C#
339
687 commits
updated Oct 7, 2026
https://github.com/user-attachments/assets/89353468-a299-4315-9516-e520bcbfbd4b
In-Game AI Companion & Autonomous Gameplay Mod for Slay the Spire 2
中文说明 (README.zh-CN) • Current Status • Historical Co-op Evidence • API Docs • MCP Tools Guide
:8080). The overlay Connect tab can expose MCP at /mcp on the same port for Cursor, Claude, and Codex.The easiest way to play is the Steam Workshop page. Subscribe, wait for the download, then Steam → Play with Mods. You do not copy any files. That page is a short player guide; this README has extra detail if you need it.
This mod is still in development. Some things may be unfinished or break. Please send suggestions and issues here: GitHub Issues.
Option A: Steam Workshop (recommended)
Option B: GitHub zip
sts2-ai-agent-v*-windows.zip from GitHub Releases and unzip it.mod/ folder into the game mods/ folder (create it if needed):
STS2AIAgent.dll
STS2AIAgent.pck
mod_id.json
C:\Program Files (x86)\Steam\steamapps\common\Slay the Spire 2\mods\STS2AIAgent.dll
C:\Program Files (x86)\Steam\steamapps\common\Slay the Spire 2\mods\STS2AIAgent.pck
C:\Program Files (x86)\Steam\steamapps\common\Slay the Spire 2\mods\mod_id.json
Do not copy the whole zip or mcp_server/ into mods/. mcp_server/ is optional for developers.Do not double-install: if you already subscribed on Workshop and also copied GitHub files, delete the manual copies from mods/ and keep the Workshop item. Two copies can load twice.
F8 (configurable) or click the grey AI tab on the right edge of the screen to open the Agent window.F8 or click AI. A default URL plus model name is not treated as ready.select_character then embark), tick Disable automatic character pick above the invite button (it sets companionAutoSelectCharacter to false in the mod's settings.json); the teammate then waits on the character screen, for the AI driving it or for you, without a timeout./health reports play_phase: "paused" with session_requests: 0, because this route never calls a model.GET /state and POST /action. Find its HTTP API through data.companion.api_port on the main window's GET /health (that port is usually not 8080). The teammate can only act for its own character; acting outside it returns 403 forbidden_actor. On this route data.companion.auto_play is false.POST /teammate/control on the main window, body {"running": true|false}. This is the supported entry point and it needs no session token (the main window holds the teammate session token itself). running: true still requires a verified play model, exactly like the in-game Continue Auto-Play button; running: false works at any time.Both routes enforce the same structural conditions (you are on the main menu, this is not the teammate instance, and the character has no auto-play already running); only the model gate differs. Full contract: docs/api.md.
--force-steam off and increments clientId in offline mode. Automatically derives and clones settings.companion.json so both instances never write over each other's configurations or save slots.| Mechanism | Description | Player Benefit |
|---|---|---|
Session Budget Guard (SessionBudgetGuard) | Tracks provider-reported JSON/SSE usage and requests; checks configured caps before new calls | Stops new calls at the limit and shows next steps; in-flight calls can add usage, and missing usage remains unknown |
Autoplay Circuit Breaker (AutoPlayRecovery) | Automatic halt after 3 consecutive failures with 2s/4s exponential backoff | Prevents spin loops on unrecognized game dialogs or invalid choices |
| Immediate Config Error Exit | Halts immediately upon receiving HTTP 401, 403, or 404 responses | Stops wasted token calls when API keys expire or are mistyped |
Run Boundary Protection (CurrentRunBoundary) | Scoped strictly to the active run's unique runId | Exiting a run, surrendering, or returning to lobby immediately stops autoplay |
Process & Settings Isolation (CoopLaunchPolicy) | Dedicated companion settings file and safe clientId stepping | Complete segregation between main and companion instances |
┌───────────────────────────────────────────────────────────┐
│ Slay the Spire 2 │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ STS2AIAgent (C# Mod) │ │
│ │ - Godot In-Game Overlay UI (F8) │ │
│ │ - OpenAI-compatible Client & Budget Guard │ │
│ │ - Autoplay Decision Loop & Recovery Controller │ │
│ │ - GameThread Action / State Synchronizer │ │
│ │ - Local Dual-Instance Process Launcher │ │
│ └───────────────────────┬─────────────────────────────┘ │
└──────────────────────────┼────────────────────────────────┘
│ Local HTTP API (:8080)
│ Optional MCP (:8080/mcp)
▼
External Agents (Cursor / Claude Desktop / Codex)
The mod runs an embedded HTTP server on http://127.0.0.1:8080 (with dynamic fallback on port contention):
GET /health: Health check, returns api_port, instance_role, mcp_enabled, and process PID. On the main window, once this co-op session has connected to a teammate, it also returns a companion block: the teammate's api_host, api_port, and process_id, plus this route's auto_play flag.GET /state: Full raw game state JSON.GET /actions/available: Currently available legal actions and schema.GET /events/stream: Real-time SSE stream for game events.POST /action: Dispatch an action (e.g., play_card, choose_map_node, proceed).GET /data/{collection}: Export a bundled game metadata collection (cards, relics, monsters, potions, events, powers, characters).POST /session/control: Start or pause autoplay for this instance ({"running": true|false}).POST /teammate/control: Start or pause the AI teammate from the main window ({"running": true|false}). Loopback only and main-window only; this is the supported entry point for an external agent (see Option C above).POST /companion/control / POST /companion/message: Control or message the AI teammate instance (local dual-instance only). These are the teammate instance's own controlled endpoints, called by the main process with this session's token; external callers should use POST /teammate/control instead.POST /mcp: Optional MCP (Streamable HTTP). Off by default; enable it on the overlay Connect tab.| If you want to… | Use | Needs | How to confirm |
|---|---|---|---|
| Play with an AI teammate | In-game overlay, MCP off | Mod only | F8 / AI tab opens AI Teammate |
| Drive the game from Cursor / Claude / Codex | Native MCP on the Connect tab | Mod only | Copy the actual URL shown (port may not be 8080) |
| stdio, layered/full, or compatibility | Optional Python mcp_server/ | Python + uv | From the release root, run scripts/test-mcp-tool-profile.ps1 |
External clients: F8 → Connect → enable Open MCP service → copy the URL or JSON. It shares the HTTP API port and listens on 127.0.0.1 only. Do not hard-code 8080 or 8765.
The Python sidecar is not required for players and is not the recommended entry.
Default shape (replace the port with the one on the Connect tab):
{
"mcpServers": {
"sts2-ai-agent": {
"type": "http",
"url": "http://127.0.0.1:8080/mcp"
}
}
}
Built-in MCP tools add health_check on top of the surface in-game Auto-Play uses: get_game_state, get_available_actions, act, get_game_data_*, wait_until_actionable. The default guided profile also exposes decide (state, available actions and scene guidance from one call), get_scene_guidance, get_raw_game_state, get_decision_log, get_run_summary and diff_state.
In-game Auto-Play already follows the bundled play contract. If you drive the game from an external agent over MCP (Cursor, Claude, Codex, or the optional Python sidecar), also load the companion skill sts2-mcp-player. Connecting tools without that skill can click legal actions; the skill is what matches in-game play quality.
Standalone core and MCP contract tests run without the game client. Godot UI, real-game actions, multiplayer, saves, and installation channels require separate live validation:
The GitHub zip includes only the optional sidecar launch and profile-check
scripts under scripts/. The build, preflight, and live-game commands below
require a source checkout.
⚠️ Close the game first so the DLL file is not locked by the OS.
# Windows
powershell -ExecutionPolicy Bypass -File ".\scripts\build-mod.ps1" -Configuration Release
# Linux / macOS
./scripts/build-mod.sh --configuration Release
dotnet run --project STS2AIAgent.Tests/STS2AIAgent.Tests.csproj
Covers the session budget guard, autoplay recovery backoff, run-boundary interception, offline dual-instance isolation, HTTP port fallback, and native save switching, among others.cd mcp_server
uv run python -m unittest discover -s tests -v
powershell -ExecutionPolicy Bypass -File ".\scripts\preflight-release.ps1"
mod/ folder into the game mods/ folder. Do not keep both Workshop and a manual copy.--force-steam off and steps clientId automatically. Check if third-party antivirus software blocked launching the child process.STS2-Agent/
├── STS2AIAgent/ # C# In-Game Mod (Overlay UI, LLM Client, Decision Loop, Budget Guard)
├── STS2AIAgent.Tests/ # Standalone C# tests (no game client required)
├── mcp_server/ # FastMCP Server implementation
├── scripts/ # Build, packaging, startup, and preflight scripts
├── skills/ # State-first gameplay skill specifications
├── docs/ # Developer reference and API documentation
├── PRODUCT_PLAN_CURRENT.md # Current product status and evidence boundary
└── COOP_DELIVERY.md # Historical co-op evidence index
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).
159 followers · starred Apr 2026
8 followers · starred Mar 2026
149 followers · starred Mar 2026
11 followers · starred Mar 2026