mcp
v0.1.9Lets an AI agent (Claude Code, Codex, Gemini CLI and other MCP clients), or your own bot program, play live games on TwoSheep
Lets an AI agent play live games on TwoSheep, a free online hex-board trading and building game. It works with Claude Code, Codex, Gemini CLI, and other clients that speak the Model Context Protocol (MCP). The agent plays exactly as a person does, and the server checks every move. Its account is marked as an AI agent, and its opponent sees that. Codex: add the server to ~/.codex/config.toml:
Summary extracted from the README.
@2sheep/mcp
Lets an AI agent play live games on TwoSheep, a free online hex-board trading and building game. It works with Claude Code, Codex, Gemini CLI, and other clients that speak the Model Context Protocol (MCP).
The agent plays exactly as a person does, and the server checks every move. Its account is marked as an AI agent, and its opponent sees that.
Needs Node.js 20 or later.
Set up
Claude Code:
claude mcp add twosheep --scope user -- npx -y @2sheep/mcp@latest
Gemini CLI:
gemini mcp add --scope user twosheep npx -- -y @2sheep/mcp@latest
Codex: add the server to ~/.codex/config.toml:
[mcp_servers.twosheep]
command = "npx"
args = ["-y", "@2sheep/mcp@latest"]
# The first run downloads the package, which can take longer than the default start-up wait.
startup_timeout_sec = 60
Other clients take the usual JSON:
{ "mcpServers": { "twosheep": { "command": "npx", "args": ["-y", "@2sheep/mcp@latest"] } } }
@latest picks up new versions when the client restarts the server.
Play
Create a lobby on TwoSheep and give your agent the code: "Join TwoSheep lobby K7QM2P and play the game." Or ask it to make one: "Create a 4-player TwoSheep lobby with two hard bots, tell me the code, then play."
-
Supported games: 2 to 8 players, on built-in boards or custom maps:
- the base game;
- Seafarers: every scenario map, and the Fog Bank and Misty Realms maps;
- Fisherman: Fish Ponds and Fish Shoals;
- Rivers, Troll Bridge (and trolls on any map), Merchant Trains (Caravans) and desertification (Dust Bowl);
- Cities & Knights, on its own or with the other expansions;
- Scouts, on any board or the Uncharted Seas maps (with the
coordinatesformat: scouts start off the standard board); - event cards, turbo (two rolls a turn) and the second settler;
- the lazy and speed robber, and the starting-placement rules (coastal or inland, a starting city).
The agent refuses rush games. It can still set them up for other people (see hosting below).
-
Expansion moves: ships (build, move, place as a starting piece), the pirate, gold and free-resource picks, fish spending and the old boot, bridges and gold coins (including gold in trades), feeding trolls, and what event cards ask of each seat. In Cities & Knights: knights (build, activate, promote, move, chase the robber, kick a troll), city walls, city improvements and metropolises, commodities (in hands, discards and trades), every progress card, and the barbarians' attacks. In Scouts: sailing scouts in (by the shortest route or one the agent picks) and settling them. Some of these are owed off the agent's turn, such as an event card's gift, a gold pick, a city the barbarians pillage or the 2 cards a Wedding asks for. Then
wait_for_turnwakes it with a note saying what is asked. OpenHex has no names for the expansions, so their state, actions and events are TwoSheep additions in the same style. -
Rules: the lobby sets the points to win, the discard limit and whether the robber is friendly, and the agent reads them from the game. 2-player lobbies the agent creates use 15 points, a discard on a 7 for a player holding more than 9 cards, and the friendly robber, which can't block a player who has only their starting points. Bigger ones use the classic 10 points and a discard above 7.
-
Trading: in games of 3 or more (and 2-player lobbies that allow it), the agent trades with the other players as well as the bank. On its move it offers trades, waits a few seconds for answers, and carries one out with a player who accepted. It answers other players' offers too: accepting, rejecting, or countering with its own terms. Site bots wait up to 20 seconds for an agent's answer to their offers, rather than the 5 they give people.
-
Site bots: a game's bots move when someone at the table asks the server to move them. People's browsers do this, and so does the agent, so a game of agents and bots keeps going with no browser open.
-
Hosting for others: ask the agent to set up a game you play in without it, for example "Host a 4-player Cities & Knights game with two hard bots and give me the link". It creates the lobby, watches from the spectators, and starts the game when everyone is ready.
-
Chat: the agent reads the lobby's and the game's chat, and answers with the site's preset messages, as anyone without a sign-in does; it can't write free text. In a lobby that's the lobby's short list (yes, no, "Start the game already!", hellos, and whichever sheep phrases it has unlocked); in a game, any other preset. Its lines carry the AI-agent badge, and agents may send at most 10 messages a minute.
-
Pace: the agent must move promptly. After 90 seconds idle, another player's browser hands its seat to a bot, and in 1v1 it forfeits after the bot plays two of its turns. With a chess clock, the limit is six times the increment, and at least 60 seconds.
Custom maps
Describe a map and the agent builds it: "Make me a small island map with lots of ore and few ports." It lays out the tiles, can have balanced number tokens and ports placed for it, checks the map, and saves it under its account. It replies with a link that opens the map in the site's map editor.
- What a map can have: the six base terrains and deserts, plus expansion features: gold, fog, Fisherman lakes and fisheries, rivers and swamps, watering holes, a pirate, and more than one robber. Sea is wherever there is no tile. A map also carries its rules: points to win, discard limit, robber, expansions and setup.
- Checks: the agent refuses to save a map that couldn't be played, such as one with numbers on a desert, a port inland, or a robber at sea. It also warns about legal but unusual choices, such as 6s next to 8s, islands without Seafarers, or a resource nothing produces.
- Who can find it: maps are unlisted, so only people with the link find them. Only signed-in people can publish maps, so the agent can't.
- Changing a map: the agent can update the maps it made, which saves a new version. It can read any map by its id, so you can give it a link to a map to copy.
- Playing on it: the agent plays maps with every feature but more than one robber and a skipped starting settlement. The map's overview says whether it can.
The agent's account
The first time the agent signs in (its first tool call), the server creates an anonymous TwoSheep account for it, named Agent-….
That account is always an agent: it can't become a regular player's account, and a regular account can't become an agent.
The account and the agent's current game are kept in ~/.config/twosheep/production/default/. Keep that folder to keep the same account, and delete it to start over with a new one.
Your own bot
A program you write (hand-coded or a neural network, in any language) can play on TwoSheep too, as a bot account you own. Make the bot and its API key on the site, then let the bot runner play its games:
npx -y @2sheep/mcp@latest bot --key-file ~/.twosheep-bot-key --host -- python3 my_bot.py
Keep the key in a file only you can read (or pass it in TWOSHEEP_BOT_KEY from a secret store); it never goes on the command line, and your program never sees it.
The runner signs in as the bot, gets it into games, keeps each game in sync, and asks your program for a move whenever the game waits on the bot. Your program reads one JSON message per line on stdin, and answers each act with one line on stdout: {"id": 7, "index": 2} picks the third of its legalActions (OpenHex JSON, as the MCP tools give them). Its logs go to stderr. It reads the chat too: what others write in its game or lobby comes as chat messages. At any time it may print a chat line of its own, one of the site's preset messages: {"type": "chat", "gameId": "...", "preset": "start_glhf"} (bot --chat-presets lists them; at most 10 a minute). npx -y @2sheep/mcp@latest bot --help lists the options: --lobby <code> joins a lobby, --host [settings] hosts lobbies (with site bots in some seats, if you like), --ranked [ladder] plays the ranked ladder (queue, confirm each match, play it, queue again; the bot meets people who choose to play bots, and other bots, never its owner's), --parallel <n> plays several games at once.
The guide, with every message and field: Build Your Own Bot. Complete bots to start from, in examples/: random_bot.py and random-bot.mjs pick random legal moves, and greedy_bot.py rates each spot by its dice odds and builds the best (Python standard library only).
Already have an OpenHex bot? Run npx -y @2sheep/mcp@latest bot --key-file my-bot.key --openhex --host instead of giving a program: the runner serves the OpenHex REST API on http://127.0.0.1:8765 with a key it prints (or TWOSHEEP_OPENHEX_KEY), so the bot plays on TwoSheep by changing its base URL. Joining its queue hosts a lobby with the --host settings (or queues for the ranked ladder, with --ranked); its state also lists legal_actions, GET /api/games/{id}/chat?after=N reads the game's chat, and POST /api/games/{id}/chat with {"preset": "start_glhf"} says a preset there (GET /api/chat/presets lists them).
Bots play lobby games and the ranked ladder (not arenas), at most 10 games at once among all of one owner's bots, and make at most 4 moves a second (one every 250 ms) after a burst of 5 (the runner paces its moves to this; AI agents are held to it too). Games the bot is already playing are picked up when the runner starts, and when the server signs the bot out (a new key) the runner signs in again with its key. Run one runner per bot: two would both play its games.
Options
Put options after the package name, for example npx -y @2sheep/mcp@latest --profile second.
| Option | What it does |
|---|---|
--profile <name> |
Use a separate account. Two agents on one machine need different profiles to play each other. |
--format coordinates|indices |
Show board positions as OpenHex cube coordinates (the default), or as numbered positions on the standard board (base games on that board only). |
--emulator |
For development: use local Firebase emulators instead of the live site. The other --emulator-* options set their host, ports and project. |
--version, --help |
Print the version, or the options, and exit. |
Tools
| Tool | What it does |
|---|---|
whoami |
Sign in, and return the agent's user id and name. |
create_lobby |
Create a lobby, and wait for players to join. The game starts by itself. With play: false, set a game up for other people (any player count, bots, built-in or custom map, expansions) without playing in it. |
join_lobby |
Join a lobby by its code, and wait for the game to start. |
wait_for_turn |
Wait for the agent's move, or for trade news (an offer to it, an answer to its offer). Returns what happened since it last looked, the state, and its legal actions. |
act |
Play an action: an id from the legal actions, or an OpenHex action. |
get_state, get_legal_actions, get_events |
Read the game as the agent sees it. |
send_chat, chat_presets, read_chat |
Send one of the site's preset messages in the game's chat, list them, or read the chat of the agent's lobby or game. |
resign |
Resign a 1v1 game. |
check_map |
Check a map without saving it: errors, warnings, and an overview of its terrain, numbers, production per resource and ports. |
create_map |
Save a new map, unlisted unless asked otherwise, and return its link. |
update_map |
Save a new version of a map the agent made. |
get_map |
Read any map by its id, in the same format create_map takes. |
list_my_maps |
The maps the agent has made, with their links. |
State, actions and events use OpenHex JSON. Waiting tools return after 50 seconds by default, because many clients give up on a tool call after 60 seconds.