RPG-MCP is a comprehensive, rules-enforced D&D 5e-compatible RPG backend that turns any LLM into a game master with deterministic physics and persistent state management. The server provides anti-hallucination validation where LLMs propose intentions but cannot directly mutate world state—all actions are validated against rules.
Core Systems:
World Management: Generate procedural worlds with 28+ biomes, terrain-aware POI placement, dynamic environmental systems (time, weather, seasons, moon phases), and multi-world setups with forkable timelines for parallel simulations
D&D 5e Combat: Full tactical combat with initiative tracking, 3D spatial positioning, obstacles/difficult terrain, opportunity attacks, death saving throws, legendary creature lair actions, area-of-effect calculations, and ASCII map visualization
Magic System: 15+ SRD spells with slot tracking, class-based progression, Warlock pact magic, concentration mechanics, rest recovery, and anti-hallucination validation preventing unknown spell casting
Character & Party Management: Create characters with full D&D stat blocks, class/race support, level progression, equipment systems, and organize into parties with roles (leader, member, companion, hireling, prisoner, mount) and world map travel
Inventory & Economy: Complete system with equipment slots, weight tracking, item templates, currency with auto-conversion, and theft mechanics featuring heat levels, witness recording, and fence NPCs
Quest System: Create quests with typed objectives (kill, collect, deliver, explore, interact), track progress, define prerequisites for quest chains, and grant rewards (gold, items, XP)
NPC & Social: Relationship tracking, conversation history with importance levels, context injection for LLM prompts, corpse mechanics with decay states, loot tables with guaranteed/random drops, and harvestable resources
Narrative Memory: Persistent story layer tracking plot threads, canonical moments, NPC voices, foreshadowing, and session logs with visibility controls
Improvisation Engine: Rule of Cool stunts, custom effects (boons, curses, transformations), and arcane synthesis for dynamic spell creation
Grand Strategy: Nation simulation with leaders, ideologies, resources, personality traits, diplomacy, territorial claims, turn-based resolution, and fog of war
Math & Physics: D&D dice notation (advantage/disadvantage, exploding dice), probability calculations, algebra solver, and projectile trajectory computation
Spatial Navigation: Room-based dungeon networks, terrain-aware movement, and environmental observation tools
Technical Features:
Multi-tenant Architecture: Isolated projects with SQLite persistence and full audit trails
Real-time Eventing: Subscribe to world and combat events via JSON-RPC notifications
Tool Discovery: Search and load schemas for 135-145+ MCP tools by category or keyword
Token Efficiency: Composite tools and shorthand notation reduce LLM context overhead by 80-95%
Deterministic Execution: Seed-based randomness ensures reproducible results with 800+ tests ensuring system integrity
Runs as a Node.js application with support for standalone binary distribution, providing the runtime environment for the MCP server.
Uses SQLite as the persistence layer for storing world state, entities, inventories, combat encounters, quests, and all simulation data with full transaction support and migration system.
Implemented in TypeScript with full type safety across the codebase, providing strongly-typed schemas and APIs for all simulation systems.
Employs Zod for runtime schema validation of all entities, actions, world state, and constraints, ensuring type safety at API boundaries and preventing invalid data mutations.
RPG-MCP: Agentic Embodied Simulation Kernel
A rules-enforced RPG backend that turns any LLM into a game master who can't cheat.
What Is This? (Start Here)
You are the player. The AI is the dungeon master.
You talk to an AI (Claude, GPT, etc.) in natural language. You say things like "I attack the goblin" or "I search the room for traps." The AI narrates what happens and describes the world.
The difference from pure AI storytelling: This engine enforces the rules. When you attack, it actually rolls dice, checks armor class, calculates damage, and updates HP in a real database. The AI can't just decide you hit or miss—the math happens, and both you and the AI see the result.
What can you actually do?
Explore procedurally generated worlds with 28+ biome types
Fight enemies using D&D 5e-style combat (initiative, AC, damage rolls, death saves)
Cast spells with real slot tracking—if you're out of slots, you can't cast
Manage inventory with equipment slots, weight, and item properties
Complete quests with tracked objectives and rewards
Interact with NPCs who remember your conversations across sessions
Everything persists—close the game, come back tomorrow, your character is exactly where you left them
Who is this for?
Solo RPG players who want AI-driven adventures with mechanical integrity
People frustrated with AI RPGs that fall apart when you ask "wait, how much HP do I have?"
Developers building AI game integrations who need a reference implementation
How do I play?
Install the MCP server (see Installation below)
Connect it to Claude Desktop (or any MCP-compatible client)
Tell the AI: "Let's start a new game. Create a character for me."
Play naturally—the AI handles narration, the engine handles mechanics
For Developers
RPG-MCP is a world kernel—the physics, constraints, persistence, and deterministic execution layer that allows LLM agents to inhabit a simulated reality with real bodies, real limits, and real consequences.
What's New (December 2025)
Latest Release
145+ MCP Tools - Complete RPG mechanics coverage with new composite tools
800+ Passing Tests - Comprehensive test coverage across all systems
Composite Tools (TIER 1) - Reduce token overhead by 80-95% for common workflows
Preset Systems - 1100+ creature presets, 50+ encounter presets, 30+ location presets
Schema Shorthand (TIER 2) - Token-efficient position/stats parsing
Batch Repository Methods - Optimized for world generation workflows
Location Presets - Tavern, dungeon, temple, market presets with full population
Encounter Presets - Level-scaled encounters (goblin ambush, undead crypt, dragon's lair)
Core Systems
Full Spellcasting System - 15+ SRD spells, class progression, slot tracking
Theft & Fence System - Heat decay, witness tracking, black market economy
Corpse & Loot System - Decay states, harvestable resources, loot tables
NPC Memory System - Relationship tracking, conversation history, context injection
Improvisation Engine - Rule of Cool stunts, custom effects, arcane synthesis
Legendary Creatures - Lair actions, legendary resistances, boss mechanics
Death Saving Throws - Full D&D 5e rules with stabilization
Spatial Navigation - Room networks, terrain-aware POI placement
Narrative Memory Layer - Session notes, plot threads, NPC voices, foreshadowing
Currency System - Gold/silver/copper with auto-conversion
Architecture Philosophy
This engine implements the Event-Driven Agentic AI Architecture:
The Embodiment Model
Biological System | RPG-MCP Component | Role |
Brain | LLM Agent (external) | Strategic reasoning, planning, interpretation |
Nervous System | Engine + Orchestrator | Validates intent, enforces constraints, routes actions |
Reflex Arc | Constraint Validator | Blocks impossible actions before execution |
Sensory Organs | Observation Tools |
|
Muscles | Action Tools |
|
Environment | World State + Physics | SQLite-persisted, deterministic, forkable reality |
Key invariant: LLMs propose intentions. The engine validates and executes. LLMs never directly mutate world state.
Features
Core Systems
Multi-tenant & Multi-world
Isolated projects (
projectId) and parallel worlds (worldId)Fork worlds for branching timelines or "what-if" simulations
Embodied Entities
Position, velocity, orientation in 3D space
Stats, inventories, status effects, controller links
Sensory radius, line-of-sight, perception limits
Intent-Based Actions
Agents submit intentions:
MOVE_TO,ATTACK,CAST_SPELL,INTERACTEngine validates against physics, rules, and constraints
Invalid actions rejected with structured feedback
Deterministic Physics
Collision detection, projectile trajectories, movement costs
Reproducible world steps—same inputs always yield same outputs
Full audit trail: snapshots, event logs, action history
Combat & Encounters
Initiative tracking with advantage/disadvantage
Spatial combat with grid positioning and collision
Opportunity attacks with reaction economy
Death saving throws (D&D 5e rules)
Damage resistance/vulnerability/immunity
Legendary creatures with lair actions and legendary resistances
Encounter presets - Pre-balanced encounters by party level
Magic System
15+ SRD spells (Magic Missile, Fireball, Cure Wounds, etc.)
Spell slot tracking with class-based progression
Warlock pact magic with short rest recovery
Concentration tracking
Anti-hallucination validation - LLMs cannot cast spells they don't know
Rest mechanics restore spell slots and HP
Theft & Economy
Stolen item tracking with heat levels (burning → cold)
Witness recording for theft detection
Fence NPCs with buy rates and heat capacity
Item recognition - original owners detect their stolen goods
Heat decay over time
Corpse & Loot
Corpse creation on creature death
Loot tables with guaranteed and random drops
Harvestable resources (pelts, fangs, etc.)
Decay system (fresh → decaying → skeletal → gone)
NPC Memory
Relationship tracking (familiarity + disposition)
Conversation memory with importance levels
Context injection for LLM prompts
Interaction history across sessions
Improvisation Engine
Rule of Cool stunts - "I kick the brazier into the zombies"
Custom effects - Divine boons, curses, transformations
Arcane synthesis - Dynamic spell creation with wild surge risk
Project Structure
Installation
Option 1: Standalone Binaries (Recommended)
Download the pre-built binary for your platform from the Releases page:
Windows:
macOS (Intel):
macOS (Apple Silicon - M1/M2/M3/M4):
Linux:
The binaries are self-contained and include all dependencies. No Node.js installation needed.
Option 2: From Source
To build binaries yourself:
MCP Client Configuration
To use with an MCP-compatible client (Claude Desktop, etc.), add to your client's configuration:
Using Binary:
Using Source:
MCP Tools Reference (135 Tools)
World Management (12 tools)
Tool | Description |
| Create a new world |
| Retrieve world by ID |
| List all worlds |
| Delete world (cascades) |
| Procedural generation with Perlin noise |
| Full world state dump |
| Summary stats & biome distribution |
| Full tile grid |
| Single region details |
| DSL for map modifications |
| Dry-run of patch |
| Time, weather, season |
POI Location Tools (2 tools)
Tool | Description |
| Terrain-aware placement for points of interest |
| Suggest multiple valid POI locations |
Character Management (5 tools)
Tool | Description |
| Full D&D stat block support |
| Retrieve by ID |
| Update any field |
| List all characters |
| Remove from DB |
Inventory & Items (15 tools)
Tool | Description |
| Define item types |
| Get template by ID |
| All templates |
| Query by name/type/value |
| Modify template |
| Remove template |
| Add to character inventory |
| Take from inventory |
| Move between characters |
| Consume items |
| Assign to equipment slot |
| Return to inventory |
| Basic inventory list |
| Full item info, sorted |
| Transfer gold/silver/copper with auto-conversion |
Combat & Encounters (7 tools)
Tool | Description |
| Initialize combat with participants |
| Current combat status |
| Resume saved encounter |
| End combat, sync HP |
| Attack/heal/move/cast spell |
| Move to next in initiative |
| D&D 5e death saving throws |
| Legendary creature lair actions |
Spellcasting (integrated with combat)
Action | Description |
| Cast known spell with slot consumption |
Rest System (2 tools)
Tool | Description |
| Restore all HP and spell slots |
| Hit dice healing, Warlock pact slots |
Theft & Fence System (10 tools)
Tool | Description |
| Record theft with heat tracking |
| Check if item is stolen |
| List all stolen items held |
| NPC recognition check |
| Sell stolen goods |
| Register NPC as fence |
| Report to guards (adds bounty) |
| Process heat decay |
| Get fence details |
| List all fences |
Corpse & Loot System (14 tools)
Tool | Description |
| Create corpse from dead character |
| Get corpse by ID |
| Get by original character |
| Items on corpse |
| Corpses in combat |
| Corpses near position |
| Loot single item |
| Harvest resources |
| Generate from loot table |
| Custom loot tables |
| Get table by ID |
| List all tables |
| Process decay |
| Remove decayed corpses |
NPC Memory System (7 tools)
Tool | Description |
| Get relationship status |
| Create/update relationship |
| Store conversation summary |
| Get memories with NPC |
| Recent memories across NPCs |
| Full context for LLM injection |
| PHASE-2: Spatial-aware conversations |
Improvisation System (8 tools)
Tool | Description |
| Rule of Cool resolution |
| Apply boons/curses/transformations |
| Get active effects |
| Remove effect |
| Fire effect triggers |
| Tick effect durations |
| Dynamic spell creation |
| Get mastered spells |
Quest System (8 tools)
Tool | Description |
| Define quest with objectives |
| Single quest details |
| All quests |
| Give quest to character |
| Increment progress |
| Mark objective done |
| Complete entire quest |
| Full quest objects |
Secrets System (9 tools)
Tool | Description |
| Hidden info with reveal conditions |
| DM-only view |
| All secrets for world |
| Modify properties |
| Remove secret |
| Show to player |
| Test if conditions met |
| Format for LLM injection |
| Scan text for accidental reveals |
Party System (17 tools)
Tool | Description |
| Create adventuring party |
| Get party details |
| All parties |
| Modify party properties |
| Remove party |
| Add character to party |
| Remove from party |
| Modify party member role |
| Change leadership |
| Set active PC |
| Get members with details |
| Party summary for LLM |
| Characters not in a party |
| Move entire party on world map |
| Party location |
| Parties in specific region |
Spatial Navigation (4 tools)
Tool | Description |
| Observe current location details |
| Create room in dungeon network |
| List exits from current room |
| Move character between rooms |
Math & Dice (5 tools)
Tool | Description |
| Full D&D notation (2d6+3, 4d6dl1, adv/dis) |
| Calculate odds |
| Solve equations |
| Simplify expressions |
| Trajectory calculations |
Grand Strategy (11 tools)
Tool | Description |
| Create nation with resources |
| Private nation state |
| World with fog of war |
| Diplomatic action |
| Territorial claims |
| Initialize turn management |
| Check nation readiness |
| Batch action submission |
| Signal turn complete |
| Process all actions |
| Get resolution results |
Use Cases
Tabletop RPG Backend Run D&D, Pathfinder, or custom systems with AI dungeon masters and NPCs that have real bodies and spatial reasoning.
Multi-Agent Simulation Test agent coordination, emergent behavior, or adversarial scenarios in a controlled, reproducible environment.
Embodied AI Research Study how LLMs behave when constrained by physics, resources, and perception limits—not just text.
Game Development Use as a headless game server with deterministic state, replay capability, and clean API boundaries.
Training Data Generation Fork worlds, run thousands of parallel scenarios, collect structured action/outcome pairs.
Design Principles
LLMs propose, never execute The brain suggests; the nervous system validates.
All action is tool-mediated No direct world mutation. Every change flows through MCP tools.
Validation precedes observation Act → Validate → Observe. The reflex arc pattern.
Events trigger tasks JIT execution. No polling, no stale state.
Deterministic outcomes Same inputs → same outputs. Always reproducible.
Schema-driven everything Zod validates all data at boundaries. Type safety end-to-end.
Anti-hallucination by design LLMs cannot cast spells they don't know or claim damage they didn't roll.
Token efficiency Composite tools and schema shorthand reduce LLM context overhead.
Test Coverage
Key test areas:
Combat encounters and HP persistence
Spellcasting validation (anti-hallucination)
Inventory integrity and exploit prevention
Theft/fence mechanics with heat decay
Corpse/loot system with decay states
NPC memory and relationship tracking
Improvisation system (stunts, effects, synthesis)
Composite tool workflows
Preset system expansion and validation
Contributing
Contributions welcome! Please:
Fork the repo
Create a feature branch (
git checkout -b feature/your-feature)Write tests for new functionality
Follow existing code style (TypeScript + Zod + tests)
Submit a pull request
See CONTRIBUTING.md for detailed guidelines.
Roadmap
Full spellcasting system with validation
Theft and fence economy
Corpse and loot mechanics
NPC memory and relationships
Improvisation engine
Composite tools (TIER 1)
Preset systems (creatures, encounters, locations)
Narrative memory layer
WebSocket real-time subscriptions
Dialogue tree system
Cover mechanics in combat
Quest chains with prerequisites
Visual debugger / world inspector UI
License
ISC — Use freely, attribution appreciated.
Related
Quest Keeper AI — Desktop AI dungeon master using this engine
Documentation
CLAUDE.md - Development instructions
docs/WHITE_PAPER.md - Design philosophy and architecture
docs/LLMSpatialGuide.md - LLM spatial navigation guide