Skip to main content
Glama
study-flamingo

D&D MCP Server

roll_dice

Roll dice using D&D notation like '1d20' or '3d6+2', with options for advantage or disadvantage to resolve game actions.

Instructions

Roll dice with D&D notation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dice_notationYesDice notation (e.g., '1d20', '3d6+2')
advantageNoRoll with advantage
disadvantageNoRoll with disadvantage

Implementation Reference

  • The complete implementation of the 'roll_dice' tool handler, including schema (input parameters with descriptions), registration via @mcp.tool decorator, and the full logic for parsing dice notation, rolling dice (with support for advantage/disadvantage), applying modifiers, and formatting the output.
    @mcp.tool
    def roll_dice(
        dice_notation: Annotated[str, Field(description="Dice notation (e.g., '1d20', '3d6+2')")],
        advantage: Annotated[bool, Field(description="Roll with advantage")] = False,
        disadvantage: Annotated[bool, Field(description="Roll with disadvantage")] = False,
    ) -> str:
        """Roll dice with D&D notation."""
        dice_notation = dice_notation.lower().strip()
    
        # Parse dice notation (e.g., "1d20", "3d6+2", "2d8-1")
        pattern = r'(\d+)d(\d+)([+-]\d+)?'
        match = re.match(pattern, dice_notation)
    
        if not match:
            return f"Invalid dice notation: {dice_notation}"
    
        num_dice = int(match.group(1))
        die_size = int(match.group(2))
        modifier = int(match.group(3)) if match.group(3) else 0
    
        # Roll dice
        if advantage or disadvantage:
            if num_dice != 1 or die_size != 20:
                return "Advantage/disadvantage only applies to single d20 rolls"
    
            roll1 = random.randint(1, 20)
            roll2 = random.randint(1, 20)
    
            if advantage:
                result = max(roll1, roll2)
                roll_text = f"Advantage: {roll1}, {roll2} (taking {result})"
            else:
                result = min(roll1, roll2)
                roll_text = f"Disadvantage: {roll1}, {roll2} (taking {result})"
    
            total = result + modifier
            modifier_text = f" {modifier:+d}" if modifier != 0 else ""
    
            return f"🎲 **{dice_notation}** {roll_text}{modifier_text} = **{total}**"
        else:
            rolls = [random.randint(1, die_size) for _ in range(num_dice)]
            roll_sum = sum(rolls)
            total = roll_sum + modifier
    
            rolls_text = ", ".join(map(str, rolls)) if num_dice > 1 else str(rolls[0])
            modifier_text = f" {modifier:+d}" if modifier != 0 else ""
    
            return f"🎲 **{dice_notation}** [{rolls_text}]{modifier_text} = **{total}**"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. 'Roll dice with D&D notation' implies a random generation operation but doesn't disclose important behavioral traits like whether results are deterministic, if there are rate limits, what the output format will be, or how advantage/disadvantage mechanics work. This leaves significant gaps for an agent to understand the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a simple dice rolling tool and front-loads the essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations, no output schema, and three parameters, the description is insufficiently complete. It doesn't explain what the tool returns, how advantage/disadvantage affects results, or provide examples of typical use cases. The agent would need to guess about the output format and behavioral details.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions 'D&D notation' which provides context for the dice_notation parameter, but doesn't add meaningful semantic information beyond what the schema already provides. With 100% schema description coverage, the baseline is 3, and the description doesn't significantly enhance understanding of the three parameters or their interactions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Roll dice') and specifies the notation system ('D&D notation'), making the purpose immediately understandable. However, it doesn't differentiate from potential sibling tools like 'calculate_experience' or 'next_turn' that might also involve dice mechanics in a D&D context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of when to choose roll_dice over other tools like 'calculate_experience' or 'next_turn' that might handle dice rolling in different contexts, nor does it specify prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/study-flamingo/gamemaster-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server