Skip to main content
Glama
README.md
# Game Design & 2D Top-Down RPG Practitioner RAG + MCP Knowledge Base

Offline Hybrid RAG (**SQLite FTS5 BM25 + ChromaDB `ONNXMiniLM_L6_V2` dense vectors + Reciprocal Rank Fusion**) and stdio JSON-RPC 2.0 MCP documentation server synthesizing **proven game design, level/world design, combat feel, mathematical balancing, progression/economy, quest state-machine, and 2D Top-Down RPG engineering wisdom** from veteran practitioners, free courses, online books, GDC talks, and open-source repositories.

## Why This Exists

AI agents building games without design discipline often invent bloated mechanics, ship cramped corridors, trap players in key soft-locks, pick arbitrary `HP/ATK/DEF` numbers that collapse under subtractive armor cliffs, neglect hitstop and attack telegraphs, or create mudflated economies and fragile boolean quests. This repository gives AI agents an offline, bilingual (**English + Vietnamese**) RAG MCP server to consult proven game-design rules before creating or editing game specs, levels, combat code, or balance tables.

## Repository Layout

- `docs/` — **19 curated practitioner guides** (`00_` through `18_`), covering Core Loops/MDA, Mechanics, Level/World Design, **Tileset/Autotile/7-Layer Map Assembly**, **Modular Asset Manifests**, **Procedural & Cyclic Dungeon Generation**, **Puzzles & Enemy/Companion AI**, **Camera/Lighting/Adaptive Audio**, **Ready-to-Use Blueprints/Schemas**, an **82-item Pitfall & 16-Point QA Gate Catalog** (`10_`), and a **Free Courses, Books, YouTube & GitHub Compendium** (`11_`).
- `AGENTS.md` — System working rules directing AI agents to query `game-design-lessons` before guessing mechanics, metrics, formulas, tilesets, asset manifests, or dungeon layouts.
- `fetch_sources.py` — Reproducible downloader pulling *The Level Design Book* chapters (including modular kits, env art, landscape, lighting), *Tiled* & *LDtk* docs, *Red Blob Games* (grids, A*, visibility, noise procgen), *Boris the Brave* (WFC, *Binding of Isaac*), *Ron Gilbert* Puzzle Dependency Charts, *Itay Keren* 2D Cameras, *Slynyrd* Top-Down Tiles, *David Sirlin*, *The Game Design Forum* Reverse Design RPG studies, *MIT OCW CMS.608*, Robert Nystrom's *Game Programming Patterns*, awesome-design repos, and curated GDC/GMTK/Sakurai/Tim Cain/Design Doc/Adam Millard/Extra Credits/jess::codes/Joris Dormans YouTube transcripts into `raw_sources/` (gitignored).
- `ingest.py` — Builds `data/lessons.sqlite3` (FTS5 + structured `pitfalls` table) and `data/chroma/` (`game_design_lessons`) from `docs/` and `raw_sources/`.
- `game_design_rag.py` — Standalone CLI + bilingual (Vietnamese/English) Hybrid RAG + stdio JSON-RPC 2.0 MCP server (`4` read-only tools).
- `smoke_test.py` — End-to-end verification suite (CLI search, pitfalls, section reads, and strict stdio MCP handshake/tool validation).

## Quick Setup

```bash
# 1. Install dependencies (Python >= 3.10)
pip install -e .

# 2. Fetch upstream free books, web courses, GitHub repos & YouTube transcripts
python fetch_sources.py all

# 3. Build local SQLite FTS5 + Chroma vector index
python ingest.py

# 4. Query via CLI (English or Vietnamese)
python game_design_rag.py search "spatial metrics corridor width dungeon boss keys"
python game_design_rag.py search "cach can bang sat thuong giap hyperbolic trong game rpg top-down"
python game_design_rag.py pitfalls "subtractive armor"
python game_design_rag.py read game-balancing-math-combat-formulas-and-spreadsheets --section "Damage"
python game_design_rag.py stats

# 5. Verify RAG + MCP protocol health
python smoke_test.py
```

## Register as an MCP Server

Add this server block to your MCP client config (e.g. `C:\Users\<user>\.gemini\config\mcp_config.json`):

```json
{
  "mcpServers": {
    "game-design-lessons": {
      "command": "python",
      "args": ["-B", "H:/TestAI/GameDocs/game_design_rag.py", "mcp"],
      "env": {
        "PYTHONUTF8": "1",
        "ANONYMIZED_TELEMETRY": "False"
      }
    }
  }
}
```

### Exposed MCP Tools

- `search_game_design_lessons(query, topic=None, tier="all", limit=6)`
- `read_game_design_lesson(doc_id, section=None, offset=0, limit=16000)`
- `get_game_design_pitfalls(symptom_or_topic, limit=8)`
- `list_game_design_topics_and_courses(tier="curated")`

## Security & Attribution

- Runs **100% offline** at query time with read-only SQLite access and telemetry disabled (see [SECURITY.md](SECURITY.md)).
- Third-party transcripts, web guides, and repositories (*The Level Design Book*, *Game Balance Concepts*, *David Sirlin*, *Red Blob Games*, *The Game Design Forum*, *MIT OCW CMS.608*, *Game Programming Patterns*, *GDC*, *Game Maker's Toolkit*, *Masahiro Sakurai*, *Timothy Cain*, *Adam Millard*, *Design Doc*, *Extra Credits*) are stored locally in `raw_sources/` (gitignored) and attributed in `docs/11_free_courses_youtube_books_and_resources_compendium.md`.