ChatRPG
A lightweight ChatGPT app that converts your LLM into a Dungeon Master!
README
ChatRPG
D&D 5e MCP Server for AI Dungeon Masters
A Model Context Protocol (MCP) server providing 30+ D&D 5e tools for LLM-powered tabletop gaming. Features real-time combat tracking, character persistence, ASCII art rendering, and a web client interface.
Features
- 30+ D&D 5e Tools - Character creation, combat encounters, spell tracking, dice rolling
- ASCII Art Output - Retro-style box drawing for immersive terminal/chat display
- Dual Transport - stdio for Claude Desktop, SSE for web client
- Real-time Sync - WebSocket broadcasting for encounter updates
- Persistent Storage - Characters and encounters saved to AppData
- Web Client - Browser-based interface with typing indicators
Quick Start
1. Build & Run
npm install
npm run build
# Run with stdio (for Claude Desktop)
npm start
# Run with SSE (for web client, port 3001)
node dist/index.js --sse
2. Configure Claude Desktop
Add to your Claude Desktop config:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"chatrpg": {
"command": "node",
"args": ["C:\\path\\to\\ChatRPG\\dist\\index.js"]
}
}
}
3. Web Client
The web client connects to the SSE endpoint:
# Start server with SSE
node dist/index.js --sse
# Open web-client/index.html in browser
Available Tools
Character Management
| Tool | Description |
|---|---|
create_character |
Full D&D 5e character creation with auto-calculated stats |
get_character |
Retrieve by ID/name, supports listing and filtering |
update_character |
Modify stats with before/after comparison |
delete_character |
Remove with cascade cleanup, batch support |
level_up |
Level progression with HP rolls, spell slots |
take_rest |
Short/long rest with hit dice and recovery |
manage_spell_slots |
Full/half/third casters, warlock pact magic |
roll_check |
Skill checks, saves, attacks, initiative |
Combat System
| Tool | Description |
|---|---|
create_encounter |
Initialize combat with participants and terrain |
get_encounter |
Retrieve state with verbosity levels |
execute_action |
Attack, dash, dodge, disengage, grapple, shove, cast |
advance_turn |
Turn management with condition ticking |
end_encounter |
Close with outcome tracking |
roll_death_save |
D&D 5e death save mechanics |
manage_condition |
Apply/remove conditions with duration |
manage_encounter |
Composite operations with state sync |
render_battlefield |
ASCII tactical map |
modify_terrain |
Hazards, obstacles, difficult terrain |
Magic System
| Tool | Description |
|---|---|
manage_concentration |
Concentration checks and tracking |
manage_aura |
Spirit Guardians, Paladin auras, etc. |
use_scroll |
Spell scroll mechanics |
synthesize_spell |
Improvised magic with Arcana checks |
Spatial Mechanics
| Tool | Description |
|---|---|
measure_distance |
Grid-based distance (5e rules) |
calculate_aoe |
Sphere, cone, line, cube, cylinder |
check_line_of_sight |
Obstacle detection |
check_cover |
Half, three-quarters, full cover |
place_prop |
Interactive battlefield objects |
calculate_movement |
Pathfinding with terrain |
World & Session
| Tool | Description |
|---|---|
manage_location |
Location graph for navigation |
move_party |
Travel between locations |
manage_party |
Party composition and roles |
manage_inventory |
Item management and equipping |
manage_notes |
Session notes with tagging |
get_session_context |
Comprehensive state snapshot |
Dice
| Tool | Description |
|---|---|
roll_dice |
Standard notation, advantage/disadvantage, batch rolls |
Project Structure
ChatRPG/
├── src/
│ ├── index.ts # MCP server (stdio + SSE transports)
│ ├── registry.ts # Tool registration (30+ tools)
│ ├── types.ts # Shared Zod schemas
│ ├── fuzzy-enum.ts # Fuzzy enum matching
│ ├── websocket.ts # Real-time broadcasting
│ └── modules/
│ ├── ascii-art.ts # Box drawing, formatting
│ ├── characters.ts # Character CRUD, leveling
│ ├── combat.ts # Encounters, conditions, actions
│ ├── data.ts # Locations, party, inventory, notes
│ ├── dice.ts # Dice parsing and rolling
│ ├── magic.ts # Spells, concentration, auras
│ └── spatial.ts # Distance, AoE, movement
├── web-client/ # Browser-based interface
├── tests/ # Vitest test suites
├── dist/ # Compiled output
└── design docs/ # ADRs and documentation
Development
Commands
# Development with auto-rebuild
npm run dev
# Type check
npx tsc --noEmit
# Build
npm run build
# Run tests
npm test
# Run tests once
npm test -- --run
Adding a New Tool
- Define Zod schema in
src/modules/[module].ts - Write handler function
- Export schema from module
- Register in
src/registry.ts - Add tests in
tests/[module]/
Git Workflow
- main - Production-ready, auto-deploys to Railway
- development - Active development branch
Data Storage
Character and session data is stored in:
- Windows:
%APPDATA%\rpg-lite-mcp\ - macOS/Linux:
~/.config/rpg-lite-mcp/
rpg-lite-mcp/
├── characters/ # Character JSON files
├── encounters/ # Active encounter state
├── locations/ # Location graph
├── party/ # Party composition
└── notes/ # Session notes
Example Usage
Ask Claude:
"Create a level 5 halfling rogue named Finn with high dexterity"
Response:
╔═══════════════════════ CHARACTER SHEET ════════════════════════╗
║ Finn ║
║ PC - Halfling Rogue (Level 5) ║
║ ║
║ HP: [████████████████] 35/35 ║
║ ║
║ ────────────────────────────────────────────────────────────── ║
║ ║
║ AC │ Speed │ Initiative │ Prof Bonus ║
║ 15 │ 25 ft │ +4 │ +3 ║
╚════════════════════════════════════════════════════════════════╝
Other commands:
- "Roll 4d6 drop lowest for ability scores"
- "Start a combat encounter with 3 goblins"
- "Cast fireball centered at position 5,5"
- "Move the party to the tavern"
Deployment
The server is deployed on Railway and auto-deploys from the main branch.
SSE Endpoint: https://chatrpg-production.up.railway.app/
Troubleshooting
Server Won't Start
- Verify build:
npm run build - Check path in config is absolute
- Test manually:
node dist/index.js
Tool Calls Failing
- Rebuild:
npm run build - Run tests:
npm test -- --run - Check TypeScript:
npx tsc --noEmit
Encoding Issues
If ASCII art displays as garbled text (e.g., ââ€â‚¬ instead of ─), ensure:
- Source files are UTF-8 encoded
- Terminal/client supports Unicode
- No double-encoding in transport layer
Architecture
MCP Protocol
- Transports: stdio, SSE (Server-Sent Events)
- Format: JSON-RPC 2.0
- Capabilities: Tools (30+)
Design Principles
- ASCII Art First - All output uses box drawing for terminal aesthetics
- Zod Validation - Strict input schemas with fuzzy enum matching
- Stateful Persistence - JSON files in AppData
- D&D 5e Accurate - SRD-compliant mechanics
- Real-time Updates - WebSocket broadcasting for encounters
Contributing
This project follows TDD:
- Write failing tests
- Implement minimal code to pass
- Refactor
PRs must:
- Include tests
- Pass TypeScript strict mode
- Follow existing patterns
License
Proprietary - Personal, non-commercial use permitted. See LICENSE.
Credits
- @modelcontextprotocol/sdk - MCP TypeScript SDK
- Zod - Schema validation
- Vitest - Testing framework
- D&D 5e SRD (System Reference Document)
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。