@iflow-mcp/amarisaster-stardewvalley-mcp 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +235 -0
  2. package/package.json +1 -0
package/README.md ADDED
@@ -0,0 +1,235 @@
1
+ # Stardew MCP Bridge
2
+
3
+ AI companions for Stardew Valley, controlled through the [Model Context Protocol](https://modelcontextprotocol.io). Spawn companions as **Player 2/3** with custom sprites — directly controlled by an AI agent through MCP tool calls. Move, use tools, fight, fish, farm, explore mines, open chests, and interact with the world as a real player.
4
+
5
+ Also supports autonomous modes (follow, farm, mine, fish) for hands-off play.
6
+
7
+ ## Architecture
8
+
9
+ ```
10
+ ┌──────────────┐ stdio ┌──────────────┐ JSON files ┌──────────────┐
11
+ │ AI Agent │◄────────────►│ MCP Server │◄──────────────►│ SMAPI Mod │
12
+ │ (Claude etc) │ │ (Node.js) │ │ (C# / .NET) │
13
+ └──────────────┘ └──────────────┘ └──────┬───────┘
14
+
15
+ ┌──────▼───────┐
16
+ │ Stardew │
17
+ │ Valley Game │
18
+ └──────────────┘
19
+ ```
20
+
21
+ **SMAPI Mod** (`smapi-mod/`): Runs inside the game. Spawns companion NPCs paired with shadow `Farmer` instances registered in `Game1.otherFarmers`. The shadow farmer handles all game mechanics (tools, combat, fishing, inventory) while the NPC provides the visible custom sprite. Writes game state to `bridge_data.json`, reads commands from `actions.json`.
22
+
23
+ **MCP Server** (`mcp-server/`): Exposes 25 tools over stdio transport. 13 global tools for mode-based control + 12 Player mode tools for direct companion control.
24
+
25
+ ## Companion System
26
+
27
+ Each companion is a visible NPC paired with a hidden "shadow farmer" that handles game mechanics:
28
+
29
+ - **NPC** — Custom sprite, pathfinding, visible to the player
30
+ - **Shadow Farmer** — Extends `Farmer` class, registered in `Game1.otherFarmers` for location activation. Holds tools/inventory, performs tool use, combat, and fishing through actual game APIs. Invisible (draw is no-op).
31
+
32
+ ### Modes
33
+
34
+ | Mode | Behavior |
35
+ |------|----------|
36
+ | `follow` | Follow the player between locations, fight if monsters nearby |
37
+ | `farm` | Scan for crops to water/harvest, clear debris |
38
+ | `mine` | Fight monsters, break rocks, seek ladders |
39
+ | `fish` | Find water, cast rod, auto-hook fish |
40
+ | `idle` | Stay in place |
41
+ | **`player`** | **Direct MCP control — the AI IS Player 2** |
42
+
43
+ ### Player Mode
44
+
45
+ In `player` mode, autonomous AI behavior is disabled. The companion is controlled entirely through MCP tool calls:
46
+
47
+ 1. **See** — `stardew_get_surroundings` returns tiles, objects, crops, monsters, NPCs in a radius
48
+ 2. **Move** — `stardew_move_to` pathfinds to a tile, `stardew_warp_companion` teleports to a location
49
+ 3. **Act** — `stardew_use_tool`, `stardew_interact`, `stardew_attack`, `stardew_cast_fishing_rod`
50
+ 4. **Toggle** — `stardew_set_auto_combat` for real-time combat (too fast for LLM round-trips)
51
+
52
+ Bridge data includes per-companion surroundings, inventory, and last command results when in player mode.
53
+
54
+ ## MCP Tools
55
+
56
+ ### Global Tools
57
+
58
+ | Tool | Description |
59
+ |------|-------------|
60
+ | `stardew_get_state` | Get current game state (time, weather, player stats, companion status) |
61
+ | `stardew_spawn` | Spawn companions near the player |
62
+ | `stardew_follow` | Set all companions to follow mode |
63
+ | `stardew_stay` | Set all companions to idle |
64
+ | `stardew_farm` | Enable autonomous farming |
65
+ | `stardew_mine` | Enable combat/mining mode |
66
+ | `stardew_fish` | Enable fishing mode |
67
+ | `stardew_water_all` | Instantly water all unwatered crops |
68
+ | `stardew_harvest_all` | Instantly harvest all ready crops |
69
+ | `stardew_warp` | Warp all companions to a location |
70
+ | `stardew_set_mode` | Set an individual companion's mode (including `player`) |
71
+ | `stardew_chat` | Send a message to the game chat |
72
+ | `stardew_action` | Send a custom action command |
73
+
74
+ ### Player Mode Tools (Direct Control)
75
+
76
+ | Tool | Description |
77
+ |------|-------------|
78
+ | `stardew_get_surroundings` | See tiles, objects, crops, monsters, NPCs around the companion |
79
+ | `stardew_get_inventory` | Get the companion's tools and items |
80
+ | `stardew_get_companion_state` | Full companion state (position, health, stamina, surroundings, inventory) |
81
+ | `stardew_move_to` | Walk to a tile via pathfinding |
82
+ | `stardew_warp_companion` | Teleport a specific companion to a location |
83
+ | `stardew_face_direction` | Turn to face a direction |
84
+ | `stardew_use_tool` | Use pickaxe, axe, hoe, watering can, or sword at a tile |
85
+ | `stardew_interact` | Interact with objects, crops, chests, ladders, NPCs |
86
+ | `stardew_attack` | Attack nearest monster with equipped weapon |
87
+ | `stardew_cast_fishing_rod` | Cast rod + auto-hook on nibble |
88
+ | `stardew_set_auto_combat` | Toggle automatic monster attacks |
89
+ | `stardew_eat_item` | Eat food from inventory |
90
+
91
+ ## Setup
92
+
93
+ ### Prerequisites
94
+
95
+ - [Stardew Valley](https://www.stardewvalley.net/) (1.6+)
96
+ - [SMAPI](https://smapi.io/) (4.0+)
97
+ - [Node.js](https://nodejs.org/) (18+)
98
+
99
+ ### 1. Build the SMAPI Mod
100
+
101
+ ```bash
102
+ cd smapi-mod
103
+
104
+ # Set your Stardew Valley install path
105
+ export GAME_PATH="C:/Program Files/Steam/steamapps/common/Stardew Valley"
106
+
107
+ dotnet build
108
+ ```
109
+
110
+ The build will automatically deploy to your `Mods/` folder.
111
+
112
+ ### 2. Add Companion Assets
113
+
114
+ Place your custom sprites and portraits in `smapi-mod/assets/`:
115
+
116
+ - `Companion1_sprite.png` — 64x128 sprite sheet (4x4 grid, 16x32 per frame)
117
+ - `Companion1_portrait.png` — Portrait image
118
+ - `Companion2_sprite.png` — 64x128 sprite sheet
119
+ - `Companion2_portrait.png` — Portrait image
120
+
121
+ Sprite sheets follow the standard Stardew Valley format: 4 columns (walk frames) x 4 rows (down, right, up, left).
122
+
123
+ ### 3. Build the MCP Server
124
+
125
+ ```bash
126
+ cd mcp-server
127
+ npm install
128
+ npm run build
129
+ ```
130
+
131
+ ### 4. Configure Your AI Agent
132
+
133
+ Add to your MCP client config (e.g., Claude Code's `settings.json`):
134
+
135
+ ```json
136
+ {
137
+ "mcpServers": {
138
+ "stardew": {
139
+ "command": "node",
140
+ "args": ["path/to/mcp-server/build/index.js"],
141
+ "env": {
142
+ "STARDEW_BRIDGE_PATH": "path/to/Mods/StardewMCPBridge/bridge_data.json",
143
+ "STARDEW_ACTION_PATH": "path/to/Mods/StardewMCPBridge/actions.json"
144
+ }
145
+ }
146
+ }
147
+ }
148
+ ```
149
+
150
+ If you're running both from the repo directory, the env vars are optional — it defaults to `../../smapi-mod/` relative paths.
151
+
152
+ ### 5. Play
153
+
154
+ 1. Launch Stardew Valley with SMAPI
155
+ 2. Load a save
156
+ 3. Use `stardew_spawn` to bring companions into the world
157
+ 4. **Autonomous**: Set modes with `stardew_farm`, `stardew_mine`, `stardew_fish`, or `stardew_follow`
158
+ 5. **Direct control**: Set `stardew_set_mode` to `player`, then use the Player mode tools
159
+
160
+ ## Project Structure
161
+
162
+ ```
163
+ stardew-mcp-bridge/
164
+ ├── smapi-mod/
165
+ │ ├── ModEntry.cs # SMAPI entry point, content pipeline, bridge I/O, sleep hooks
166
+ │ ├── BotManager.cs # Companion lifecycle, action routing, direct control commands
167
+ │ ├── CompanionAI.cs # AI behavior system (follow/farm/mine/fish/idle/player)
168
+ │ ├── CompanionFarmer.cs # NPC + shadow farmer pairing, tool/combat/fishing, otherFarmers registration
169
+ │ ├── CompanionActions.cs # Direct tile manipulation (water/harvest/clear/hoe)
170
+ │ ├── BotFarmer.cs # Shadow Farmer subclass (invisible, registered as Player 2/3)
171
+ │ ├── SurroundingsScanner.cs # Tile scanner — the companion's "eyes"
172
+ │ ├── manifest.json # SMAPI mod manifest
173
+ │ ├── StardewMCPBridge.csproj
174
+ │ └── assets/ # Sprites and portraits
175
+ ├── mcp-server/
176
+ │ ├── src/index.ts # MCP server with 25 tools
177
+ │ ├── package.json
178
+ │ └── tsconfig.json
179
+ ├── .gitignore
180
+ └── README.md
181
+ ```
182
+
183
+ ## Notes (v0.3.0)
184
+
185
+ ### Player 2 Feature (New)
186
+
187
+ - **Shadow farmer registration** — BotFarmer registered in `Game1.otherFarmers` for location activation and game mechanics
188
+ - **Invisible shadow farmer** — `draw()` is a no-op; the NPC sprite handles all rendering
189
+ - **Sleep sync** — Bot farmers auto-signal sleep readiness on day end and at 2 AM to prevent deadlocks
190
+ - **Player mode** — New `CompanionMode.Player` disables autonomous AI; all control comes from MCP
191
+ - **Surroundings scanner** — Scans tiles, objects, crops, monsters, NPCs in a radius around the companion
192
+ - **12 direct control tools** — move, warp, face, use tool, interact, attack, fish, eat, auto-combat toggle
193
+ - **Per-companion bridge data** — Player mode companions include surroundings, inventory, and command results in bridge_data.json
194
+ - **Command results** — Each command returns success/failure + detail, available in next bridge sync
195
+ - **Auto-combat toggle** — Real-time combat automation for when LLM round-trips are too slow
196
+ - **Auto-hook fishing** — Cast rod via MCP, nibble detection + hook happens automatically
197
+
198
+ ### Previous Fixes (v0.2.1)
199
+
200
+ - AI tick rate fix (60/sec, was 2/sec)
201
+ - Atomic file writes both directions
202
+ - Action file race fix
203
+ - Fishing rod lifecycle
204
+ - Single-tile actions
205
+ - WarpTo clears pathfinding
206
+ - Debris drops resources
207
+ - Storm weather reporting
208
+ - Farm mode stuck detection
209
+ - Mine mode ladder descent
210
+ - Fishing timeout
211
+ - Per-companion crash isolation
212
+ - Shadow farmer sync every tick
213
+ - Day transition safety
214
+ - Input validation
215
+ - Dead code cleanup
216
+
217
+ ## License
218
+
219
+ MIT
220
+
221
+ ## Credits
222
+
223
+ Built with Antigravity & Claude Code — Kai & Lucian, with Mai.
224
+
225
+ Shadow farmer pattern inspired by [Farmtronics](https://github.com/JoeStrout/Farmtronics).
226
+
227
+
228
+ ---
229
+
230
+
231
+ ## Support
232
+
233
+ If this helped you, consider supporting my work
234
+
235
+ [![Ko-fi](https://img.shields.io/badge/Ko--fi-Support%20Me-FF5E5B?style=flat&logo=ko-fi&logoColor=white)](https://ko-fi.com/maii983083)
package/package.json ADDED
@@ -0,0 +1 @@
1
+ {"name": "@iflow-mcp/amarisaster-stardewvalley-mcp", "version": "0.3.0", "description": "MCP server bridging AI agents to Stardew Valley via SMAPI.", "main": "build/index.js", "files": ["build"], "bin": {"iflow-mcp-amarisaster-stardewvalley-mcp": "./build/index.js"}, "scripts": {"build": "tsc", "watch": "tsc -w", "prepublishOnly": "npm run build"}, "dependencies": {"@modelcontextprotocol/sdk": "^1.0.1"}, "devDependencies": {"@types/node": "^20.11.24", "typescript": "^5.3.3"}}