STS2 Agent 标志

STS2 Agent

社区
CharTyr

杀戮尖塔2的MOD,将杀戮尖塔2的游戏状态与操作暴露为本地 HTTP API 包装成 MCP Server,供支持 MCP 的AI客户端直接调用

发布者CharTyr
代码仓库STS2-Agent
语言C#
复刻数
45
星标数
324
可用工具
0
传输类型stdio
链接
  • 将工具接入 AI 工作流

    STS2 Agent 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 324 个 Star 和 45 个 Fork。

STS2 AI Agent

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


🌟 Key Highlights

  • 🎮 In-Game Overlay UI: Press F8 at any time to open the configuration and control window directly inside the game—no external browser required.
  • 🤖 OpenAI-Compatible Endpoints: Configure a compatible chat-completions endpoint, with per-model thinking settings. Tool calling, vision, streaming, and usage reporting depend on the provider and model; test chat and play separately.
  • 🃏 Autonomous Auto-Play: Uses text state for combat, card drafting, shops, events, pathing, and capstones, with optional screenshot context. Run completion and strategy quality depend on the model and game conditions; see the current status for validation limits.
  • 👥 Local Co-op AI Teammate: One-click launch from the main menu spins up an isolated second game instance. You play your character; the AI teammate plays its own character in co-op mode.
  • 💬 Live Team Conversation: Talk to your AI teammate in natural language from the human window (e.g., "focus the right cultist", "let's take the shop path"). The AI replies and uses recent context in subsequent decisions.
  • 🛡️ Session Budget Guards & Fault Recovery: Tracks reported token usage and request counts, stops new calls when session limits are reached, and bounds retries. Missing usage is shown as unknown; these guards are not a billing guarantee.
  • 🔌 Developer-Ready: Built-in local HTTP API (:8080). The overlay Connect tab can expose MCP at /mcp on the same port for Cursor, Claude, and Codex.

🚀 3-Minute Quick Start (Players)

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.

Step 1: Install The Mod

Option A: Steam Workshop (recommended)

  1. Subscribe on the Workshop page and wait for the download.
  2. Start the game from Steam with Play with Mods. You do not copy any files.
  3. If the game warns that the code is untrusted: accept, quit fully, enable STS2 AI Agent in Mods, then restart.

Option B: GitHub zip

  1. Download sts2-ai-agent-v*-windows.zip from GitHub Releases and unzip it.
  2. Copy only these three files from the zip mod/ folder into the game mods/ folder (create it if needed):
    text
    STS2AIAgent.dll
    STS2AIAgent.pck
    mod_id.json
  3. Final layout example:
    text
    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.

Step 2: Launch The Game & Open The Overlay

  1. Start Slay the Spire 2 from Steam with Play with Mods.
  2. Press F8 (configurable) or click the grey AI tab on the right edge of the screen to open the Agent window.

Step 3: Configure Your LLM Endpoint

  1. The overlay opens automatically on first launch. Later, press F8 or click AI. A default URL plus model name is not treated as ready.
  2. Open Settings:
    1. Add Endpoint (name, Base URL; API Key may be empty for Ollama / LM Studio)
    2. Add Model and bind it to that endpoint
    3. Choose Chat Model and Play Model (empty play model uses chat)
    4. Click Test Connection (sends a request to your configured service). Chat success is not play success.
    5. Click Save Settings. Unsaved edits are saved when you leave the tab so they are not dropped silently.
  3. Thinking intensity, vision, and session budgets are under Show advanced options.
  4. Invite a teammate only after the play model shows connectivity success. That requirement belongs to the auto-play route: a teammate invited without a verified play model still launches, it just waits to be taken over from outside. See Option C below.

Step 4: Play!

Option A: Auto-Play

  • Start a standard single-player run.
  • Switch to the Play tab and click Start Auto-Play (or Step Once).
  • The model evaluates live state and dispatches cards, rewards, and route decisions autonomously.

Option B: Co-op With An AI Teammate (Recommended!)

  • Go to the game's Main Menu.
  • Switch to the AI Teammate tab and click Invite AI Teammate.
  • A second game window will launch automatically and join the co-op lobby. You play your character; the AI controls its character!
  • The main window shows whether the teammate is connected, waiting on you/the game/the model, or why it stopped and what to click next. Pause teammate gives immediate feedback; already submitted actions still finish.
  • Use team chat to coordinate in plain English or Chinese.
  • By default the teammate takes the preselected character and readies up by itself. To pick its character yourself (in the teammate window, or through the companion API with 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.
  • To pick up a saved co-op run, use Continue the saved co-op run, the button under the invite; it is enabled on the main menu while a co-op save exists. It hosts the saved run over the local connection and brings the teammate back. Do not use the game's own Load button for that save: it opens the run over Steam networking, rejects the local-connection player ids, and renames the save as corrupt.

Option C: Hand The Teammate Window To An External Agent

  • You do not need to configure or verify any model to invite a teammate on this route: it never calls a model, so a missing or broken model cannot make it fail. The teammate still launches, joins the lobby, and readies up on its own.
  • When the run starts, the teammate stops where it is and plays nothing by itself: its /health reports play_phase: "paused" with session_requests: 0, because this route never calls a model.
  • Drive that character from outside with the teammate instance's own 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.
  • Start and pause it with 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.


🎮 Core Features

1. Autonomous Gameplay (Auto-Play)

  • Compact State Engine: Actionable text state covering cards, energy, intents, relics, HP, and potion slots. Vision is optional; offline state and action tests do not prove full-run completion.
  • Optional Vision Augmentation: When using a vision-capable model, screenshots are captured on demand to provide rich visual context.
  • Real-Time Counters: The overlay displays prompt, completion, total tokens, and request counts live.

2. Dual-Instance Local Co-op

  • Two Co-op Routes: With a verified play model the teammate auto-plays as before; with no model it still launches and joins, but stops and waits to be taken over from outside (see Option C).
  • Zero-Collision Isolation: Propagates --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.
  • Team Conversation:
    • Chat directly with the AI teammate during multiplayer runs.
    • Teammate replies using its play model, and recent discussions inform subsequent play decisions.
    • Read-only safety: The chat interface never plays cards for the human or unpauses a paused companion.
    • Conversation is player-initiated by default. An optional, off-by-default proactive chat lets the teammate speak one short line when a fight starts and ends, with a selectable tone (轻松搭档 / 沉稳参谋 / 简短简报). It never plays for you and stays under the session budget.

3. Interactive In-Game Advisor

  • Use the Chat tab to ask strategic advice.
  • Enable "Attach State" to pass full live game context (deck, relics, route) to the model for tactical guidance.

🛡️ Reliability & Safety Guards

MechanismDescriptionPlayer Benefit
Session Budget Guard (SessionBudgetGuard)Tracks provider-reported JSON/SSE usage and requests; checks configured caps before new callsStops 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 backoffPrevents spin loops on unrecognized game dialogs or invalid choices
Immediate Config Error ExitHalts immediately upon receiving HTTP 401, 403, or 404 responsesStops wasted token calls when API keys expire or are mistyped
Run Boundary Protection (CurrentRunBoundary)Scoped strictly to the active run's unique runIdExiting a run, surrendering, or returning to lobby immediately stops autoplay
Process & Settings Isolation (CoopLaunchPolicy)Dedicated companion settings file and safe clientId steppingComplete segregation between main and companion instances

🛠️ Advanced Users & Developers Guide

System Architecture

text
┌───────────────────────────────────────────────────────────┐
│                    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)

Local HTTP API

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.

Which MCP entry to use

If you want to…UseNeedsHow to confirm
Play with an AI teammateIn-game overlay, MCP offMod onlyF8 / AI tab opens AI Teammate
Drive the game from Cursor / Claude / CodexNative MCP on the Connect tabMod onlyCopy the actual URL shown (port may not be 8080)
stdio, layered/full, or compatibilityOptional Python mcp_server/Python + uvFrom 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):

json
{
  "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.


🧪 Building From Source & Automated Testing

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.

Build Mod

⚠️ Close the game first so the DLL file is not locked by the OS.

powershell
# Windows
powershell -ExecutionPolicy Bypass -File ".\scripts\build-mod.ps1" -Configuration Release

# Linux / macOS
./scripts/build-mod.sh --configuration Release

Run Tests

  • C# Core Unit Tests:
    powershell
    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.
  • Python MCP Contract Tests:
    powershell
    cd mcp_server
    uv run python -m unittest discover -s tests -v
  • Full Release Preflight Check:
    powershell
    powershell -ExecutionPolicy Bypass -File ".\scripts\preflight-release.ps1"

❓ FAQ

Q1: Pressing F8 does not open the overlay.

  1. Workshop: start with Play with Mods. GitHub: copy the three files from the zip mod/ folder into the game mods/ folder. Do not keep both Workshop and a manual copy.
  2. Confirm files were copied into the Steam game installation directory, not the repository directory.
  3. Look for the grey AI tab on the right screen edge and click it directly.

Q2: Autoplay stopped unexpectedly. How do I resume?

  1. Read the AI Teammate status line and the suggested next click. Config errors do not retry forever; fix settings, test, then Resume play without restarting the whole game.
  2. If tokens show unknown, the provider omitted usage; that is not a zero spend. Request caps still work.
  3. Use Export diagnostics. The copy excludes API keys, Authorization headers, and session tokens, and does not include chat bodies by default.

Q3: Dual-instance companion window fails to start.

  1. Local co-op runs through the internal multiplayer test lobby.
  2. The launcher sets --force-steam off and steps clientId automatically. Check if third-party antivirus software blocked launching the child process.
  3. If ports are in use, the mod automatically selects an available fallback port.

📁 Repository Layout

text
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

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).

将 STS2 Agent MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 STS2 Agent 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 STS2 Agent 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 STS2 Agent MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "sts2-agent": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 STS2 Agent MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 STS2 Agent MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 STS2 Agent 帮我完成这项任务吗?
STS2 Agent
当然。我已阅读。
以下是我使用 STS2 Agent 得到的结果。

常见问题

STS2 Agent MCP 服务器有什么用途?

STS2 Agent 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 STS2 Agent MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 STS2 Agent,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 STS2 Agent MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 STS2 Agent 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 STS2 Agent MCP 连接到 TypingMind?

STS2 Agent 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

STS2 Agent MCP 在 TypingMind 中提供哪些工具?

STS2 Agent 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 STS2 Agent MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 STS2 Agent 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇