Skip to main content
Glama

roll_dice

Roll dice using standard notation (e.g., '2d6+4') to simulate random outcomes for games or probability tasks. Specify notation and number of rolls to generate results.

Instructions

Roll the dice with the given notation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
notationYes
num_rollsNo

Implementation Reference

  • server.py:19-23 (handler)
    MCP tool handler for 'roll_dice' - registers with @mcp.tool() decorator, creates a DiceRoller instance and returns the string representation of the roll result.
    @mcp.tool()
    def roll_dice(notation: str, num_rolls: int = 1) -> str:
        """Roll the dice with the given notation"""
        roller = DiceRoller(notation, num_rolls)
        return str(roller)
  • server.py:19-23 (registration)
    Tool registration via FastMCP's @mcp.tool() decorator, exposing the roll_dice function as an MCP tool with parameters 'notation' (required string) and 'num_rolls' (optional int, default 1).
    @mcp.tool()
    def roll_dice(notation: str, num_rolls: int = 1) -> str:
        """Roll the dice with the given notation"""
        roller = DiceRoller(notation, num_rolls)
        return str(roller)
  • Core helper that implements the dice rolling logic using Python's random module. Parses notation (e.g., '2d20k1'), generates random rolls, sorts them descending, and keeps the top N results.
    def roll_dice(self):
        match = self.dice_pattern.match(self.notation)
        if not match:
            raise ValueError("Invalid dice notation")
    
        num_dice = int(match.group(1))
        dice_sides = int(match.group(2))
        keep = int(match.group(4)) if match.group(4) else num_dice
    
        rolls = [random.randint(1, dice_sides) for _ in range(num_dice)]
        rolls.sort(reverse=True)
        kept_rolls = rolls[:keep]
    
        return rolls, kept_rolls
  • Alternative helper that implements dice rolling using numpy for random generation. Same logic but uses np.random.randint instead of random.randint.
    def roll_dice(self):
        match = self.dice_pattern.match(self.notation)
        if not match:
            raise ValueError("Invalid dice notation")
    
        num_dice = int(match.group(1))
        dice_sides = int(match.group(2))
        keep = int(match.group(4)) if match.group(4) else num_dice
    
        # Use numpy to generate random integers
        rolls = np.random.randint(1, dice_sides + 1, size=num_dice).tolist()
        rolls.sort(reverse=True)
        kept_rolls = rolls[:keep]
    
        return rolls, kept_rolls
Behavior1/5

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

No annotations are present, and the description does not disclose behavioral traits (e.g., randomness, side effects, idempotency). The tool's safety profile is completely unaddressed.

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

Conciseness4/5

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

The description is a single sentence with no wasted words. It is front-loaded with the action. However, it lacks necessary detail, so highest score is not warranted.

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?

The tool is simple, but the description fails to explain the notation format, default values, or return values. Without this, an AI agent cannot correctly invoke the tool.

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

Parameters1/5

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

Schema description coverage is 0%, and the description adds no meaning to the parameters. 'Notation' is not defined (e.g., expected format like '2d6'), and 'num_rolls' is not mentioned.

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) and resource (dice), and the tool name aligns. It distinguishes from siblings (weather, search). However, 'notation' is vague without further explanation.

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

Usage Guidelines1/5

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

No guidance is provided on when to use this tool versus alternatives. There is no mention of context, 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/keertanachandar/AIE8-MCP'

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