File size: 7,600 Bytes
71b378e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# D&D Campaign Manager MCP Server

A Model Context Protocol (MCP) server providing D&D 5e tools for AI agents and LLMs.

## 🎲 What This MCP Server Provides

This MCP server extends LLM capabilities with specialized D&D 5e tools for:
- Character validation and rules compliance
- Encounter difficulty calculation
- XP award computation
- Multiclass requirement checking
- NPC stat block generation
- Ability modifier calculations

## πŸš€ Quick Start

### Installation

```bash
# Install FastMCP
pip install fastmcp

# Run the MCP server
python3 mcp_server/dnd_mcp_server.py
```

### Usage with Claude Desktop

Add to your Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json`):

```json
{
  "mcpServers": {
    "dnd-campaign-manager": {
      "command": "python3",
      "args": [
        "/path/to/dungeon-smasher-pro/mcp_server/dnd_mcp_server.py"
      ]
    }
  }
}
```

## πŸ“š Available Tools

### `validate_character`
Validates D&D 5e character builds for rules compliance.

**Parameters:**
- `character_class` (string): Character class (e.g., "fighter")
- `level` (int): Character level (1-20)
- `ability_scores` (dict): Ability scores (e.g., `{"strength": 16, "dexterity": 14, ...}`)
- `multiclass` (list, optional): List of multiclass names

**Example:**
```python
validate_character(
    character_class="fighter",
    level=5,
    ability_scores={"strength": 16, "dexterity": 14, "constitution": 15, "intelligence": 10, "wisdom": 12, "charisma": 8}
)
```

**Returns:**
```json
{
  "valid": true,
  "errors": [],
  "warnings": ["Low charisma (8) for fighter - recommend 13+"],
  "hp_estimate": 49,
  "hit_die": "d10",
  "constitution_modifier": 2
}
```

### `calculate_encounter_cr`
Calculates encounter difficulty using D&D 5e rules.

**Parameters:**
- `party_levels` (list): Party member levels (e.g., `[5, 5, 4, 6]`)
- `monster_crs` (list): Monster challenge ratings (e.g., `[2, 2, 0.5]`)
- `difficulty_target` (string): Target difficulty ("easy", "medium", "hard", "deadly")

**Example:**
```python
calculate_encounter_cr(
    party_levels=[5, 5, 4, 6],
    monster_crs=[2, 2, 0.5],
    difficulty_target="medium"
)
```

**Returns:**
```json
{
  "difficulty": "hard",
  "adjusted_xp": 2100,
  "raw_xp": 1050,
  "multiplier": 2.0,
  "thresholds": {"easy": 1000, "medium": 2000, "hard": 3000, "deadly": 4400},
  "target_met": false,
  "recommendations": [],
  "party_size": 4,
  "monster_count": 3
}
```

### `calculate_xp_award`
Calculates XP rewards for defeated monsters.

**Parameters:**
- `party_size` (int): Number of players
- `monster_crs` (list): CRs of defeated monsters

**Example:**
```python
calculate_xp_award(party_size=4, monster_crs=[2, 2, 0.5])
```

**Returns:**
```json
{
  "total_xp": 1150,
  "xp_per_player": 287,
  "party_size": 4,
  "monsters_defeated": 3
}
```

### `validate_multiclass`
Checks multiclass requirements.

**Parameters:**
- `current_class` (string): Current primary class
- `target_class` (string): Class to multiclass into
- `ability_scores` (dict): Character ability scores

**Example:**
```python
validate_multiclass(
    current_class="fighter",
    target_class="wizard",
    ability_scores={"intelligence": 14, "strength": 16, ...}
)
```

**Returns:**
```json
{
  "valid": true,
  "requirements_met": true,
  "required": {"intelligence": 13},
  "missing": [],
  "can_multiclass": true
}
```

### `generate_npc_stats`
Generates balanced NPC stat blocks.

**Parameters:**
- `npc_name` (string): NPC name
- `character_class` (string): NPC class
- `level` (int): NPC level
- `role` (string): Combat role ("tank", "damage", "support", "standard")

**Example:**
```python
generate_npc_stats(
    npc_name="Guard Captain",
    character_class="fighter",
    level=5,
    role="tank"
)
```

**Returns:**
```json
{
  "name": "Guard Captain",
  "class": "fighter",
  "level": 5,
  "role": "tank",
  "hp": 49,
  "hp_formula": "5d10 + 10",
  "ac": 18,
  "ability_scores": {"strength": 16, "dexterity": 12, "constitution": 16, ...},
  "proficiency_bonus": 3,
  "primary_ability": "strength",
  "hit_die": "d10"
}
```

### `get_ability_modifier`
Calculates ability modifier from ability score.

**Parameters:**
- `ability_score` (int): Ability score (1-30)

**Example:**
```python
get_ability_modifier(16)
```

**Returns:** `3`

### `get_cr_for_solo_monster`
Recommends CR for solo monster encounters.

**Parameters:**
- `party_level` (int): Average party level
- `party_size` (int): Number of party members
- `difficulty` (string): Desired difficulty

**Example:**
```python
get_cr_for_solo_monster(party_level=5, party_size=4, difficulty="hard")
```

**Returns:**
```json
{
  "recommended_cr": 7.0,
  "target_xp": 3000,
  "actual_xp": 2900,
  "party_level": 5,
  "party_size": 4,
  "difficulty": "hard"
}
```

## πŸ—οΈ Architecture

```
mcp_server/
β”œβ”€β”€ __init__.py              # Package initialization
β”œβ”€β”€ dnd_mcp_server.py       # Main MCP server with tools
β”œβ”€β”€ mcp_config.json         # MCP configuration
└── README.md               # Documentation
```

## 🎯 Use Cases

### For DMs
- Validate player character builds during session 0
- Balance encounters on-the-fly
- Generate quick NPC stats for improvised encounters
- Calculate XP rewards accurately

### For AI Agents
- Autonomous character creation with rules compliance
- Intelligent encounter design
- Campaign balance analysis
- NPC generation for story development

### For Developers
- Integrate D&D rules into LLM applications
- Build D&D assistants and tools
- Create automated campaign managers
- Develop character builders with validation

## πŸ“Š Example Integration

```python
# Example: AI agent using MCP tools to balance an encounter

# 1. Validate party
for character in party:
    validation = validate_character(
        character_class=character.class,
        level=character.level,
        ability_scores=character.abilities
    )
    if not validation["valid"]:
        print(f"Error: {validation['errors']}")

# 2. Design encounter
party_levels = [char.level for char in party]
encounter = calculate_encounter_cr(
    party_levels=party_levels,
    monster_crs=[2, 2, 1, 0.5],
    difficulty_target="medium"
)

# 3. Adjust if needed
if encounter["difficulty"] != "medium":
    print(f"Encounter is {encounter['difficulty']}, adjusting...")
    # AI can now reason about how to adjust

# 4. Calculate rewards
xp = calculate_xp_award(
    party_size=len(party),
    monster_crs=[2, 2, 1, 0.5]
)
print(f"Party earns {xp['xp_per_player']} XP each")
```

## πŸ”§ Development

### Adding New Tools

1. Add tool function with `@mcp.tool()` decorator
2. Document parameters and return values
3. Add to tool list in `__main__`
4. Update this README

### Testing

```bash
# Test individual tools
python3 -c "from mcp_server.dnd_mcp_server import *; print(validate_character('fighter', 5, {'strength': 16, 'dexterity': 14, 'constitution': 15, 'intelligence': 10, 'wisdom': 12, 'charisma': 8}))"
```

## πŸ“ License

MIT License - See main project LICENSE

## 🀝 Contributing

Contributions welcome! Please:
1. Follow D&D 5e SRD rules
2. Add tests for new tools
3. Update documentation
4. Ensure backward compatibility

## 🎲 D&D 5e SRD Compliance

This MCP server implements rules from the D&D 5e System Reference Document (SRD).
All content is from open game content under the OGL 1.0a.

## πŸ”— Links

- [FastMCP Documentation](https://github.com/anthropics/anthropic-tools)
- [Model Context Protocol](https://modelcontextprotocol.io)
- [D&D 5e SRD](https://dnd.wizards.com/resources/systems-reference-document)