D&D MCP Server
A comprehensive Model Context Protocol server for managing Dungeons & Dragons campaigns with tools for characters, NPCs, locations, quests, combat encounters, and session tracking.
README
D&D MCP Server - FastMCP 2.8.0+ Compliant
A comprehensive Model Context Protocol (MCP) server for managing Dungeons & Dragons campaigns, built with FastMCP 2.8.0+ for modern compatibility and enhanced performance.
🎯 FastMCP 2.8.0+ Compliance
This server is fully compliant with FastMCP 2.8.0+ and includes:
✅ Modern Decorator-Based Architecture - Uses @mcp.tool decorators
✅ Automatic Schema Generation - From Python type annotations
✅ Pydantic Field Validation - Rich parameter validation and descriptions
✅ FastMCP CLI Support - Easy installation and development
✅ Type Safety - Full type hints with mypy compatibility
Features
Campaign Management
- Create and manage multiple campaigns
- Switch between campaigns seamlessly
- Track campaign metadata (name, description, DM, setting)
Character Management
- Complete character sheets with D&D 5e stats
- Ability scores with automatic modifier calculation
- Hit points, armor class, and combat stats
- Inventory and equipment management
- Spellcasting support
NPC Management
- Create and track non-player characters
- Manage relationships and locations
- Store descriptions and notes
Location/World Building
- Create detailed locations (cities, dungeons, etc.)
- Track populations, governments, and notable features
- Connect locations and manage geography
Quest Management
- Create quests with objectives and rewards
- Track quest status and completion
- Link quests to NPCs and locations
Combat Management
- Initiative tracking
- Turn-based combat flow
- Combat encounter planning
Session Management
- Session notes and summaries
- Experience and treasure tracking
- Character attendance
Adventure Log
- Comprehensive event logging
- Categorized by event type (combat, roleplay, exploration, etc.)
- Searchable and filterable
- Importance ratings
Game State Tracking
- Current location and session
- Party level and funds
- Combat status
- In-game date tracking
Utility Tools
- Dice rolling with advantage/disadvantage
- Experience point calculations
- D&D 5e mechanics support
Installation
Prerequisites
- Python 3.10+
- FastMCP 2.8.0+
Install with FastMCP CLI (Recommended)
# Install FastMCP
pip install fastmcp>=2.8.0
# Install this server
fastmcp install src/gamemaster_mcp/main.py:mcp -n "D&D Campaign Manager"
Manual Installation
# Clone repository
git clone <repository-url>
cd dnd-mcp
# Install dependencies
pip install -e .
# Or install with uv
uv pip install -e .
Usage
Running with FastMCP CLI (Recommended)
# Development mode with inspector
fastmcp dev src/gamemaster_mcp/main.py:mcp
# Run demo to test functionality
python demo.py
Traditional Python
# Run server directly
python -m gamemaster_mcp
# Or using the main script
python src/main.py
Claude Desktop Configuration
Add to your Claude Desktop MCP configuration:
{
"mcpServers": {
"dnd-campaign-manager": {
"command": "fastmcp",
"args": ["run", "/path/to/dnd-mcp/src/gamemaster_mcp/main.py:mcp"]
}
}
}
Or with dependencies:
{
"mcpServers": {
"dnd-campaign-manager": {
"command": "uv",
"args": [
"run",
"--with", "fastmcp>=2.8.0",
"--with", "pydantic>=2.0.0",
"python",
"/path/to/dnd-mcp/src/gamemaster_mcp/main.py"
]
}
}
}
Available Tools (25+ FastMCP Tools)
Campaign Management
create_campaign- Create a new campaignget_campaign_info- Get current campaign informationlist_campaigns- List all available campaignsload_campaign- Switch to a different campaign
Character Management
create_character- Create a new player characterget_character- Get character sheet detailsupdate_character_hp- Update character hit pointsadd_item_to_character- Add items to inventorylist_characters- List all characters
NPC Management
create_npc- Create a new NPCget_npc- Get NPC detailslist_npcs- List all NPCs
Location Management
create_location- Create a new locationget_location- Get location detailslist_locations- List all locations
Quest Management
create_quest- Create a new questupdate_quest- Update quest status or objectiveslist_quests- List quests (optionally filtered by status)
Game State Management
update_game_state- Update current game stateget_game_state- Get current game state
Combat Management
start_combat- Initialize combat with initiative orderend_combat- End combat encounternext_turn- Advance to next participant's turn
Session Management
add_session_note- Add session notes and summaryget_sessions- Get all session notes
Adventure Log
add_event- Add event to adventure logget_events- Get events (with filtering and search)
Utility Tools
roll_dice- Roll dice with D&D notation (e.g., "1d20", "3d6+2")calculate_experience- Calculate XP distribution for encounters
FastMCP 2.8.0+ Features
Type-Safe Tool Definitions
@mcp.tool
def create_character(
name: Annotated[str, Field(description="Character name")],
character_class: Annotated[str, Field(description="Character class")],
class_level: Annotated[int, Field(description="Class level", ge=1, le=20)],
race: Annotated[str, Field(description="Character race")],
# ... more parameters with rich validation
) -> str:
"""Create a new player character."""
# Implementation automatically handled by FastMCP
Automatic Schema Generation
FastMCP automatically generates JSON schemas from your Python type annotations, providing:
- Parameter validation
- Rich descriptions for LLMs
- Constraint enforcement (ge, le, pattern, etc.)
- Optional vs required parameter detection
Rich Parameter Validation
strength: Annotated[int, Field(description="Strength score", ge=1, le=30)] = 10
attitude: Annotated[Optional[Literal["friendly", "neutral", "hostile"]], Field(...)] = None
Data Storage
The server stores all data in JSON files in a dnd_data directory:
dnd_data/
├── campaigns/
│ ├── My_Campaign.json
│ └── Another_Campaign.json
└── events/
└── adventure_log.json
Example Usage
Creating a Campaign with FastMCP
# FastMCP automatically handles this as a tool
result = await mcp_client.call_tool("create_campaign", {
"name": "Curse of Strahd",
"description": "A gothic horror adventure in Barovia",
"dm_name": "John Smith",
"setting": "Ravenloft"
})
Creating a Character
result = await mcp_client.call_tool("create_character", {
"name": "Gandalf the Grey",
"character_class": "Wizard",
"class_level": 5,
"race": "Human",
"strength": 10,
"intelligence": 18,
"wisdom": 16
})
Rolling Dice
result = await mcp_client.call_tool("roll_dice", {
"dice_notation": "1d20+5",
"advantage": True
})
Development
FastMCP Development Workflow
# Install development dependencies
pip install -e .[dev]
# Run with FastMCP inspector
fastmcp dev src/gamemaster_mcp/main.py:mcp
# Run tests
pytest
# Type checking
mypy src/
# Code formatting
black src/
ruff check src/
Adding New Tools
With FastMCP 2.8.0+, adding tools is simple:
@mcp.tool
def new_tool(
param: Annotated[str, Field(description="Parameter description")]
) -> str:
"""Tool description for the LLM."""
# Your implementation
return "Result"
FastMCP automatically:
- Registers the tool
- Generates JSON schema
- Handles parameter validation
- Routes requests to your function
Compliance Features
FastMCP 2.8.0+ Specific
- ✅ Modern import syntax:
from fastmcp import FastMCP - ✅ Decorator-based tools:
@mcp.tool - ✅ Automatic schema generation from type hints
- ✅ Rich parameter validation with Pydantic
- ✅ FastMCP CLI integration
- ✅ Built-in development server
Type Safety
- ✅ Full type annotations
- ✅ Pydantic model validation
- ✅ MyPy compatibility
- ✅ Runtime type checking
Modern Python
- ✅ Python 3.10+ features
- ✅
Annotatedtype hints - ✅
Literaltypes for constraints - ✅ Modern async/await patterns
Migration from Raw MCP SDK
This server has been migrated from the raw MCP SDK to FastMCP 2.8.0+ for:
- Simplified Development - Decorator-based instead of manual tool registration
- Better Type Safety - Automatic schema generation from type hints
- Enhanced DX - Built-in development tools and CLI
- Modern Standards - Compliance with latest MCP best practices
License
MIT License
FastMCP 2.8.0+ Compliant ✅ | D&D 5e Compatible 🐉 | Production Ready 🚀
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。