Skip to main content
Glama
iKwesi

Tavily Web Search MCP Server

by iKwesi

roll_dice

Roll dice using D&D-style notation like 2d20k1 to generate random numbers for games, simulations, or decision-making.

Instructions

Roll dice with D&D-style notation (e.g., 2d20k1).

Args: notation: Dice notation (e.g., "2d20k1" = roll 2d20, keep highest 1) num_rolls: Number of times to roll (default 1)

Returns: Formatted dice roll results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
notationYes
num_rollsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • server.py:61-79 (handler)
    MCP tool handler for 'roll_dice': decorated with @mcp.tool(), instantiates DiceRoller and returns string result. This is the primary entrypoint for the tool.
    @mcp.tool()
    def roll_dice(notation: str, num_rolls: int = 1) -> str:
        """
        Roll dice with D&D-style notation (e.g., 2d20k1).
        
        Args:
            notation: Dice notation (e.g., "2d20k1" = roll 2d20, keep highest 1)
            num_rolls: Number of times to roll (default 1)
            
        Returns:
            Formatted dice roll results
        """
        try:
            roller = DiceRoller(notation, num_rolls)
            return str(roller)
        except ValueError as e:
            return f"Invalid dice notation: {str(e)}"
        except Exception as e:
            return f"Error rolling dice: {str(e)}"
  • DiceRoller class providing the core dice rolling logic: parses D&D notation, generates random rolls, handles keeping highest dice, and formats output strings used by the handler.
    class DiceRoller:
        def __init__(self, notation, num_rolls=1):
            self.notation = notation
            self.num_rolls = num_rolls
            self.dice_pattern = re.compile(r"(\d+)d(\d+)(k(\d+))?")
    
        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
    
        def roll_multiple(self):
            """Roll the dice multiple times according to num_rolls"""
            results = []
            for _ in range(self.num_rolls):
                rolls, kept_rolls = self.roll_dice()
                results.append({
                    "rolls": rolls,
                    "kept": kept_rolls,
                    "total": sum(kept_rolls)
                })
            return results
    
        def __str__(self):
            if self.num_rolls == 1:
                rolls, kept_rolls = self.roll_dice()
                return f"ROLLS: {', '.join(map(str, rolls))} -> RETURNS: {sum(kept_rolls)}"
            else:
                results = self.roll_multiple()
                result_strs = []
                for i, result in enumerate(results, 1):
                    result_strs.append(f"Roll {i}: ROLLS: {', '.join(map(str, result['rolls']))} -> RETURNS: {result['total']}")
                return "\n".join(result_strs)
  • server.py:93-93 (registration)
    Startup print confirming roll_dice tool registration.
    print("  ✅ roll_dice (D&D dice roller)")
  • Legacy version of the roll_dice handler in server_old.py.
    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)
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses the core behavior (rolling dice with specific notation) and mentions the return format ('Formatted dice roll results'), but lacks details about error handling, rate limits, or specific formatting of outputs. The description doesn't contradict any annotations since none exist.

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 efficiently structured with a clear purpose statement, parameter explanations in a labeled 'Args' section, and return information. Every sentence earns its place by providing essential information without redundancy. The information is front-loaded with the core functionality stated first.

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

Completeness4/5

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

Given the tool's moderate complexity (2 parameters, no annotations, but has output schema), the description is mostly complete. It explains parameters well and mentions return formatting. The output schema existence means it doesn't need to detail return values, but could benefit from more behavioral context about error cases or limitations.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate fully. It provides clear semantic explanations for both parameters: 'notation' is explained with examples and meaning ('2d20k1 = roll 2d20, keep highest 1'), and 'num_rolls' is explained with its default value and purpose. This adds significant value beyond the bare schema.

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

Purpose5/5

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

The description clearly states the specific action ('Roll dice') with precise resource specification ('with D&D-style notation') and provides a concrete example ('e.g., 2d20k1'). It distinguishes itself from sibling tools like 'ask_specialized_claude' and 'web_search' by focusing on dice rolling functionality.

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

Usage Guidelines3/5

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

The description implies usage through the example notation and default parameter, but doesn't explicitly state when to use this tool versus alternatives. No guidance is provided on when not to use it or what alternatives might exist for similar tasks.

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/iKwesi/AIE8-MCP-Session'

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