Skip to main content
Glama
d20-mcp

d20-mcp

by saidsurucu

๐ŸŽฒ d20-mcp

๐Ÿ‡น๐Ÿ‡ท Tรผrkรงe README iรงin tฤฑklayฤฑn / Click here for Turkish README

A powerful MCP (Model Context Protocol) server for dice rolling in RPG games. Built with FastMCP and the d20 library, this server brings comprehensive dice mechanics to Claude and other MCP clients.

Perfect for D&D, Pathfinder, and any tabletop RPG that uses standard dice notation!

โœจ Features

  • ๐ŸŽฏ Simple Rolls: Quick 1d20+5 expressions with instant results

  • ๐Ÿ“Š Detailed Analysis: See every die roll with AST breakdown

  • โšก Batch Rolling: Roll multiple expressions efficiently

  • โœ… Syntax Validation: Check expressions before rolling

  • ๐ŸŽฎ Advanced Mechanics: Keep/drop, reroll, exploding dice, and more

  • ๐Ÿค– LLM-Optimized: Comprehensive tool descriptions for AI understanding

Related MCP server: Dice Roller MCP Server

๐Ÿš€ Quick Start

Easy Setup (Remote MCP)

The quickest way to use d20-mcp - no installation needed!

  1. Open Claude Desktop

  2. Go to Settings โ†’ Connectors

  3. Click Add Custom Connector

  4. Enter the URL: https://d20-mcp.fastmcp.app/mcp

Note: Remote MCP support is currently in beta and available for Claude Pro, Max, Team, and Enterprise users.

Local Installation (Alternative)

For local installation with uvx:

uvx --from git+https://github.com/saidsurucu/d20-mcp d20-mcp

Claude Desktop Configuration (Local)

Add this to your claude_desktop_config.json:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "d20-mcp": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/saidsurucu/d20-mcp",
        "d20-mcp"
      ]
    }
  }
}

Restart Claude Desktop completely (Quit and reopen), then look for the ๐Ÿ”จ hammer icon!

๐Ÿ“ธ Screenshot

d20-mcp in action

๐ŸŽฎ Usage Examples

Once installed, try these prompts with Claude:

Basic Rolling

Roll 1d20+5 for my attack

Character Creation

Roll 6 sets of 4d6kh3 for ability scores

Combat

Roll attack (1d20+7) and damage (2d8+4) for my greatsword

With Advantage

Roll 2d20kh1+5 for my Perception check with advantage

Complex Expressions

Roll (1d4+1)*2 for Magic Missile damage

๐Ÿ› ๏ธ Available Tools

roll

Quick dice rolls returning total and formatted result. Perfect for standard gameplay.

Use for: Attack rolls, ability checks, damage, saving throws

roll_detailed

Comprehensive breakdown with AST structure showing individual die values and operations.

Use for: Character creation, debugging complex rolls, transparency

roll_batch

Roll multiple different expressions in one operation.

Use for: Combat rounds, rolling all ability scores, party checks

validate_syntax

Validate expressions without rolling (no randomness).

Use for: Testing complex expressions, user input validation

๐Ÿ“ Supported Dice Notation

Basic

  • 1d20 - Roll one 20-sided die

  • 3d6 - Roll three 6-sided dice

  • d20 - Equivalent to 1d20

Keep/Drop

  • 4d6kh3 - Keep highest 3

  • 4d6kl1 - Keep lowest 1

  • 4d6p1 - Drop lowest 1

Reroll

  • 1d20rr<10 - Reroll until โ‰ฅ10

  • 1d20ro1 - Reroll 1s once

Exploding Dice

  • 1d6e - Explode on max

  • 1d6e6 - Explode on 6

Min/Max

  • 1d20mi10 - Minimum 10

  • 1d20ma20 - Maximum 20

Arithmetic

  • 1d20+5 - Addition

  • 2d6-1 - Subtraction

  • 3d6*2 - Multiplication

  • (1d4+1)*2 - Parentheses

Advanced

  • 2d20kh1+5 - Advantage in D&D

  • 2d20kl1+2 - Disadvantage

  • 8d6 [fire] - Annotated damage (with allow_comments)

๐ŸŽฏ Common RPG Use Cases

D&D 5e Character Creation

Roll me 6 ability scores using 4d6 keep highest 3

Attack with Advantage

I have advantage on this attack. Roll 2d20kh1+8

Critical Hit

I crit! Roll 4d6+2d6+5 for my sneak attack damage

Multiple Saves

Roll saves for 4 party members: 1d20+5, 1d20+2, 1d20+7, 1d20+3

๐Ÿ”ง Development

Local Testing

# Clone the repository
git clone https://github.com/saidsurucu/d20-mcp.git
cd d20-mcp

# Run with uv
uv run server.py

# Or with Python directly (after installing dependencies)
python server.py

Project Structure

d20-mcp/
โ”œโ”€โ”€ server.py          # Main MCP server with 4 tools
โ”œโ”€โ”€ pyproject.toml     # Project configuration
โ”œโ”€โ”€ README.md          # English documentation
โ”œโ”€โ”€ README.tr.md       # Turkish documentation
โ””โ”€โ”€ LICENSE            # MIT License

๐Ÿค Contributing

Contributions are welcome! Feel free to:

  • Report bugs

  • Suggest new features

  • Submit pull requests

  • Improve documentation

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ™ Credits

Built with:

  • d20 - Powerful dice rolling engine

  • FastMCP - FastMCP framework

  • MCP - Model Context Protocol

๐Ÿ“š Learn More


Made with โค๏ธ for the TTRPG community

Available Tools

4 tools
rollA

Roll dice using standard RPG notation and return the total result.

PURPOSE: Use this tool when you need a quick dice roll with just the total numeric result and a formatted output string. This is the most common tool for standard RPG scenarios like attack rolls, ability checks, saving throws, and damage calculations.

WHEN TO USE:

  • Making attack rolls (1d20+5)

  • Rolling damage (2d6+3, 8d6)

  • Ability checks and saves (1d20+modifier)

  • Any roll where you just need the total

  • Quick single rolls without needing detailed breakdown

WHEN NOT TO USE:

  • If you need to see individual die results, use roll_detailed instead

  • If you need to make multiple different rolls, use roll_batch instead

  • If you just want to validate syntax without rolling, use validate_syntax instead

SUPPORTED NOTATION:

  • Basic: 1d20, 3d6, d20 (equivalent to 1d20)

  • Arithmetic: 1d20+5, 2d6-1, 3d6*2, 1d20/2

  • Keep highest/lowest: 4d6kh3 (keep highest 3), 4d6kl1 (keep lowest 1)

  • Drop: 4d6p1 (drop lowest 1, equivalent to kh3)

  • Reroll: 1d20rr<10 (reroll until โ‰ฅ10), 1d20ro1 (reroll 1s once)

  • Exploding: 1d6e (explode on max), 1d6e6 (explode on 6)

  • Min/Max: 1d20mi10 (minimum 10), 1d20ma20 (maximum 20)

  • Complex: (1d4+1)*2, (1d6, 3, 2d4)

COMMON EXAMPLES:

  • D&D Attack Roll: "1d20+5" โ†’ Check if hits AC

  • Ability Score: "4d6kh3" โ†’ Roll 4d6, keep highest 3

  • Fireball Damage: "8d6" โ†’ Total fire damage

  • Sneak Attack: "1d20+7" for attack, then "1d6+3d6" for damage

  • Critical Hit: "2d8+6" (doubled dice)

  • With Advantage: "2d20kh1" (roll 2d20, keep highest)

Inputs: expression (required), allow_comments.

roll_batchA

Roll multiple different dice expressions in a single efficient operation.

PURPOSE: Use this tool when you need to make several different dice rolls at once. Instead of calling the roll tool multiple times, batch them together for efficiency and to receive all results in a single structured response. Perfect for combat rounds, character creation, or any scenario requiring multiple distinct rolls.

WHEN TO USE:

  • Combat rounds: Roll attack, damage, and saving throws together

  • Character creation: Roll all 6 ability scores at once (6x "4d6kh3")

  • Multiple checks: Roll several different ability checks simultaneously

  • Efficiency: When you need 3+ different rolls, batching is more efficient

  • Organized results: Get all rolls back in a structured array

  • Mixed roll types: Different expressions with different modifiers/mechanics

WHEN NOT TO USE:

  • Single roll (use roll instead)

  • Need detailed AST for each roll (call roll_detailed multiple times)

  • Rolls are dependent on each other (roll one, check result, then decide next roll)

ERROR HANDLING: Each roll in the batch is evaluated independently. If one expression fails, it returns an error entry, but other rolls continue. Check the "success" field for each result:

  • success: true โ†’ Roll succeeded, has "total" and "result"

  • success: false โ†’ Roll failed, has "error" message

COMMON EXAMPLES:

Combat Round: ["1d20+5", "2d6+3", "1d20+2"] โ†’ Attack roll, damage roll, saving throw

Character Creation (6 ability scores): ["4d6kh3", "4d6kh3", "4d6kh3", "4d6kh3", "4d6kh3", "4d6kh3"] โ†’ Roll all six ability scores at once

Party Ability Checks: ["1d20+3", "1d20+1", "1d20+5", "1d20+0"] โ†’ Perception checks for 4 party members

Mixed Damage Types: ["2d6", "1d8", "3d4+2"] โ†’ Sword damage, fire damage, poison damage

With Advantage/Disadvantage: ["2d20kh1+5", "2d20kl1+2"] โ†’ Attack with advantage, save with disadvantage

Inputs: expressions (required), allow_comments.

roll_detailedA

Roll dice with comprehensive breakdown including AST structure and individual die values.

PURPOSE: Use this tool when you need to see exactly what happened during a dice roll, including which specific values each die showed, which dice were kept or dropped, and the complete Abstract Syntax Tree (AST) structure of the roll. Perfect for debugging, transparency, and understanding complex roll mechanics.

WHEN TO USE:

  • Character creation: See which specific values you rolled for ability scores (4d6kh3)

  • Debugging: Understand why a complex roll gave a particular result

  • Transparency: Show players exactly what each die rolled

  • Learning: Understand how keep/drop/reroll mechanics work

  • Complex rolls: Analyze multi-step expressions with nested operations

  • Statistical analysis: See individual die distributions

WHEN NOT TO USE:

  • Simple rolls where you only need the total (use roll instead)

  • Multiple different rolls (use roll_batch instead)

  • You don't need the AST complexity for basic gameplay

AST STRUCTURE EXPLANATION: The "ast" field contains a tree structure representing the roll:

  • "type": Type of node (Expression, Dice, Number, etc.)

  • "total": Numeric value of this node

  • "number": Number of dice rolled (for Dice nodes)

  • "size": Dice size, e.g., 6 for d6 (for Dice nodes)

  • "values": Array of individual die results with "value" and "kept" (true/false)

  • "children": Nested operations (for complex expressions)

INDIVIDUAL DIE RESULTS: The "values" array shows each die roll:

  • {"value": 4, "kept": true} โ†’ This die was kept in the final result

  • {"value": 2, "kept": false} โ†’ This die was dropped (e.g., in 4d6kh3)

COMMON EXAMPLES:

  • Character Stats: "4d6kh3" โ†’ See which 3 of 4 dice were kept

  • Advantage: "2d20kh1" โ†’ See both d20 results, know which was kept

  • Reroll Analysis: "4d6rr1" โ†’ See which dice were rerolled

  • Exploding Dice: "3d6e" โ†’ See which dice exploded and their chain

  • Complex Expression: "(1d4+1)*2d6kh1" โ†’ Full breakdown of nested operations

Inputs: expression (required), allow_comments.

validate_syntaxA

Validate a dice expression's syntax without actually rolling any dice.

PURPOSE: Use this tool to check if a dice expression is syntactically correct and can be evaluated before actually rolling it. Perfect for validating user input, testing complex expressions, or checking syntax in application development. This is a read-only operation that doesn't generate random results.

WHEN TO USE:

  • User input validation: Check if user-provided expression is valid

  • Testing complex expressions: Verify syntax before committing to a roll

  • Application development: Validate dice notation in forms/configs

  • Error prevention: Catch syntax errors before attempting a roll

  • Teaching: Show users why an expression is invalid

  • API integration: Validate before passing to game systems

WHEN NOT TO USE:

  • If you want to actually roll dice (use roll, roll_detailed, or roll_batch)

  • If the expression is simple and you're confident in its syntax

  • When immediate rolling is acceptable even if it fails

VALIDATION SCOPE: This tool checks: โœ“ Basic dice notation (NdN format) โœ“ Arithmetic operators and precedence โœ“ Keep/drop/reroll/explode operations โœ“ Parentheses matching and nesting โœ“ Valid operator combinations โœ“ Number format and ranges

This tool does NOT check: โœ— Logical sense (e.g., "1d0" may pass but isn't useful) โœ— Performance implications (e.g., "99999d99999" is valid but slow) โœ— Statistical properties of the roll

COMMON EXAMPLES:

Valid Expressions:

  • "1d20+5" โ†’ โœ“ Valid

  • "4d6kh3" โ†’ โœ“ Valid

  • "2d20kh1+5" โ†’ โœ“ Valid (advantage)

  • "(1d4+1)*2" โ†’ โœ“ Valid (parentheses)

  • "3d6e6" โ†’ โœ“ Valid (exploding)

Invalid Expressions:

  • "1d" โ†’ โœ— Invalid (missing die size)

  • "d20+" โ†’ โœ— Invalid (incomplete expression)

  • "1d20kh" โ†’ โœ— Invalid (missing keep count)

  • "roll 1d20" โ†’ โœ— Invalid (text instead of pure notation)

  • "1d20 +" โ†’ โœ— Invalid (trailing operator)

USE CASES:

Form Validation: Before saving a custom dice formula in a character sheet, validate it first.

Complex Expression Testing: Testing: "(2d6+3)*1d4kh1" before using in game Validate โ†’ If valid, then roll

User Input: User types: "3d8+5" Validate โ†’ Show โœ“ or explain error โ†’ Then allow roll

Inputs: expression (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelogโ€ฆ

    TDQS

    A4.8/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool serves a distinct purpose: roll provides totals, roll_detailed provides per-die breakdowns, roll_batch handles multiple expressions, and validate_syntax checks syntax without rolling. Descriptions clearly delineate when to use each.

    Naming Consistency5/5

    All tool names follow a consistent snake_case verb_noun pattern. roll, roll_detailed, roll_batch, and validate_syntax are clearly related to the domain and consistently formatted.

    Tool Count5/5

    Four tools is well-scoped for a dice rolling server. Each tool covers a necessary capability without redundancy, fitting comfortably within the recommended 3-15 range.

    Completeness5/5

    The tool set covers the full lifecycle of dice rolling: validating syntax, rolling for totals, inspecting detailed outcomes, and batching multiple rolls. No obvious gaps for the stated domain.

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables dice rolling mechanics for tabletop RPGs including standard dice notation, coin flips, advantage/disadvantage rolls, exploding dice, and maintains a history of recent rolls. Supports D\&D 5e mechanics and various gaming dice types (d4, d6, d8, d10, d12, d20, d100).
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides comprehensive dice rolling functionality for tabletop games and RPGs, supporting standard dice notation, D\&D ability score generation, advantage/disadvantage rolls, and skill checks against difficulty classes.
      -
    • A
      license
      A
      quality
      D
      maintenance
      Provides comprehensive TRPG dice rolling functionality including standard notation, advantage/disadvantage mechanics, and success-counting dice pools. It enables users to perform complex dice logic and track roll history through an MCP-compliant interface.
      2
      MIT