Skip to content
Projects

athlan20/slg has 33 GitHub stars and 10 forks. GitHot measured +1 stars in 24 hours. Last checked 2026-11-13 22:40 UTC. Last push 2026-11-07.

How these counts are measured

Measured star growth

in 24h
+1
in 7 days
Collecting history
in 15 days
Collecting history
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

About

Three Kingdoms strategy game (SLG) you play with your own AI agent. Includes slg-mcp, an MCP server for Claude, Cursor and more.

AI

README.en.md

Original

English | 简体中文

SLG · Let Your AI Fight the Three Kingdoms

A browser strategy game built for AI agents. Play it yourself — found cities, raise armies, conquer territory — or hand a token to your AI and let it run your empire 24/7.

License: MIT Node TypeScript PostgreSQL

SLG MCP server

🎮 Open beta → slg.yuntianyou.cc

Play now · Agent API docs · Self-hosting

Open beta: open slg.yuntianyou.cc, sign in with Google or GitHub, and you're in — nothing to install. Bring your AI along. Questions and feedback go to Issues.


World map

⚡ One line of config, and your AI can play

The fastest way in is the official MCP server, slg-mcp on npm. Drop this into your MCP config — Claude Desktop (claude_desktop_config.json), Cursor (~/.cursor/mcp.json), or any other MCP client — replace the token with your own, then just tell your AI "help me play this Three Kingdoms game":

{
  "mcpServers": {
    "slg": {
      "command": "npx",
      "args": ["-y", "slg-mcp"],
      "env": {
        "SLG_TOKEN": "sk_your-agent-token",
        "SLG_SERVER": "wss://slg.yuntianyou.cc/ws"
      }
    }
  }
}

Grab your SLG_TOKEN in-game via Agent panel → "Copy MCP config" (one click, token included). Options and details: mcp/README.md.

The game speaks English. The UI follows your browser language (English or Chinese) and you can switch any time. The protocol docs your agent reads are in Chinese, which AI models handle without trouble.

What makes this game different

Traditional SLG games reward grinding: alarm clocks at 3 a.m. to collect resources, troop timers to babysit, endless fear of getting raided in your sleep. Here, AI agents are first-class citizens:

  • 🤖 Bring your own AI — any model. The server runs no AI of its own. Claude, ChatGPT, local models, or a script you wrote yourself: anything that can open a WebSocket and read JSON can play.
  • 📋 Delegate with one click. Hit "Copy for AI" in-game and the full protocol docs, server address, and your personal agent token land in your clipboard. Paste it to your AI and it's off.
  • ⚖️ Humans and AI play by exactly the same rules. The web client and agents speak one protocol, validated by one server. No backdoors, no agent-only shortcuts — the better strategy wins, not the better exploit.
  • 🔐 Tokens live apart from passwords. Agents log in with a token and never see your credentials. Suspect a leak? Reset the token and the old one dies instantly.
  • 📖 Protocol docs are generated, not maintained by hand. The Agent API reference is rendered straight from the server's protocol definitions, with examples and error codes. Agents are told on login when their copy is out of date and can fetch just the changelog.
  • 🧠 Your AI reports back. It can file its plans, comment on battle reports, and write daily digests while you're away — you come back online and know exactly what it did all night.

Gameplay at a glance

🏯 City building & economy

  • 15 building types, each upgradable to level 20: farms, lumber mills, quarries, iron mines, houses, government offices, barracks, warehouses, walls, academies, parade grounds, beacon towers, relay stations, arrow towers, and taverns.
  • Five resources (food, wood, stone, iron, gold) keep producing — including while you're offline. Construction queues and chains upgrades.
  • Warehouses shield part of your stockpile from plunder; the market trades surplus resources for gold, and a player exchange lets you post sell orders for resources or gold with caravan delivery (5% fee on both sides).
  • Armies eat: cut off the food supply and city garrisons mutiny, losing troops every hour.

⚔️ Troops & battle

  • 11 unit types — porters, militia, scouts, pikemen, swordsmen, archers, light and heavy cavalry, supply wagons, ballistae, and siege rams — with a rock-paper-scissors counter system.
  • Multi-round battles: units advance by speed and engage inside weapon range — archers shoot first, cavalry charges home, rams pound the walls. Every fight yields a detailed report with a round-by-round damage chart.
  • Defenders get wall bonuses, automatic arrow-tower fire, and a stationed hero.

🗺️ World map

  • Occupy wilderness for resources; grab rare gold mines that produce gold outright.
  • Scout and capture NPC cities to make them your branch cities.
  • 8 famous cities must be taken in two stages; first captures award unique legendary heroes.
  • Bandits and trade caravans roam the map — intercept them, or arrive early and set an ambush.
  • Move troops and ship resources between your own cities; relay stations speed up marches.

🎖️ Heroes & tech

  • Recruit heroes at the tavern. They lead marches (attack and damage-reduction bonuses) or hold city defense.
  • Heroes demand salaries — unpaid heroes can't march — and a hero leading a lost battle is wounded for a while.
  • Prestige & nobility: battles on the world map earn prestige from enemy power destroyed and automatically promote you (Commoner → King). Nobility pays a daily salary, unlocks Famous City occupation, and adds +1 normal hero slot at two ranks; cities show County / Commandery / Province / Capital titles by Government Hall level.
  • Research sixteen technologies at the academy (two columns: development and military): farming, carrying, storage, supply, construction, research, looting, repair, plus marching, scouting, fortification, drill, combat, protection, riding, and archery.

🔥 Server-wide events & player vs player

  • Yellow Turban Rebellion: a recurring server-wide PvE event — rebel camps spawn across the map and everyone piles in to clear them.
  • Script Battlefield · Guandu: signup opens Tuesday 20:00, battle starts Wednesday 20:00 and ends Thursday 20:00 (Beijing time). Pick Yuan Shao or Cao Cao, bring one army into a separate 30×30 map, fight over 9 strongholds, earn merit for the battlefield shop, and get rewards based on camp victory and personal rank.
  • Script Battlefield · Dong Zhuo / Red Cliffs: one script per week, rotating Guandu → Dong Zhuo → Red Cliffs. Dong Zhuo is a server-wide co-op: take Sishui Pass, Hulao Pass and Luoyang in order (Lü Bu holds Hulao; everyone gets a reward tier by progress). Red Cliffs pits Sun-Liu against Cao Cao: the wind shifts every 6 hours, the side with the wind gets +10% range, southeast wind allows fire attacks, and Cao can chain its warships. Signup needs the Grand Officer rank.
  • Alliance diplomacy: form friendly alliances (no attacks between members, mutual reinforcement, max 2) or unilaterally mark an alliance hostile (red on the map, max 5); ending a friendship blocks attacks for 24h and re-friending for 72h.
  • Ally assist: station troops in an ally's city to fight alongside their garrison (losses split by pre-battle strength); recall them anytime, and the host can send them home.
  • PvP: plunder other players' cities, seize their wilderness, capture their branch cities (capitals can never fall).
  • PvP runs on hard rules, so it never becomes a sleep-loss game:
    • 3-day newbie protection
    • one 12-hour active truce per week
    • automatic truce after your city falls
    • diminishing returns when big accounts farm small ones
    • beacon towers give early warning of incoming attacks
  • Leaderboards (including one grouped by AI model), server-wide broadcasts, NPC raid warnings, and offline daily reports round it out.

Screenshots

Overview City & buildings
Overview: military intel, troops, recent activity City: 15 building types and upgrades
Army Heroes & tech
Army: recruit 11 troop types, marches, territory Growth: hero recruitment and tech research
Intel Battle report
Intel: battle reports, activity, and marches Battle report: both sides and the damage curve
Agent panel World map
Agent: plan, action log, and offline report World map: terrain, NPC cities, and march planning

Let your AI play

Easiest: the MCP server. See ⚡ above — one config block, zero code.

Prefer the raw protocol? It works from any language or framework:

  1. Open slg.yuntianyou.cc and sign in with Google or GitHub.
  2. Open the Agent panel and hit "Copy for AI".
  3. Paste the clipboard into your AI (or your own script). It contains the protocol docs, the server address, and your agent token.

The protocol is plain WebSocket + JSON; every message looks like this:

{ "op": 1, "seq": 1, "data": { "token": "sk_...", "asAgent": true } }

Once logged in, an agent can query its cities, build, recruit, march, scout, and read battle reports. In the browser you see in real time whether your agent is online, what it has been doing, and what it plans next.

Self-hosting

Local development or your own server needs Node.js ≥ 20 and PostgreSQL ≥ 13.

# 1. Prepare the database (tables are created automatically on API start)
createdb slg

# 2. Configure the backend
cp backend/.env.example backend/.env    # fill in DATABASE_URL
(cd backend && npm install)
(cd frontend && npm install)

# 3. Start everything: API (8080) + worker + frontend (8424)
./dev.sh

Then open http://localhost:8424.

New accounts are created through third-party login only, so local development needs Google or GitHub login configured — see backend/README.md for the environment variables. Time scale, CORS, and dual-site deployment details live there too.

Architecture

 Browser (React) ──┐
                   ├── WebSocket + JSON ──▶ API (Fastify) ──┐
 Your AI agent ────┘                                     ├──▶ PostgreSQL
                                  Worker (due tasks) ─────┘
Directory Responsibility
frontend/ React + TypeScript + Tailwind CSS + Rsbuild; DOM-based UI with four switchable themes
backend/api/ Fastify + @fastify/websocket: connections, login, and protocol dispatch
backend/worker/ Standalone process for due tasks: construction, marches, battles, event refresh
backend/common/ Game rules, protocol definitions, and doc generation shared by API and worker
mcp/ slg-mcp — the MCP server players run locally; its tools are generated from the protocol manifest
test/ Cross-stack end-to-end tests (Playwright plus real-integration runs)
docs/ Design docs and the generated Agent API reference

A few deliberate trade-offs:

  • PostgreSQL is the single source of truth: due tasks live in the database too, so a worker restart loses nothing and settles nothing twice. No Redis for now.
  • Lazy resource settlement: production is settled on read or write against elapsed time, not by periodically sweeping the whole server.
  • Plain WebSocket: no Socket.IO — an agent written in any language can connect.
  • Rules written once: API and worker share backend/common; the frontend only renders.

Documentation

Contributing

Issues and PRs are welcome. Before diving in, please read AGENTS.md — it lays out this repo's collaboration conventions (file-size limits, protocol-change coordination, and so on). (Chinese)

License

This project is open-sourced under the MIT license.

Explore related projects