Skip to main content
Glama
UpendraNath

Tavily Web Search MCP Server

by UpendraNath

roll_dice

Simulate dice rolls using standard dice notation to generate random numbers for games, probability calculations, or decision-making scenarios.

Instructions

Roll the dice with the given notation

Input Schema

NameRequiredDescriptionDefault
notationYes
num_rollsNo

Input Schema (JSON Schema)

{ "properties": { "notation": { "title": "Notation", "type": "string" }, "num_rolls": { "default": 1, "title": "Num Rolls", "type": "integer" } }, "required": [ "notation" ], "type": "object" }

Implementation Reference

  • server.py:21-26 (handler)
    MCP tool handler for 'roll_dice'. Decorated with @mcp.tool(), it creates a DiceRoller instance and returns its string representation, which executes the dice rolling logic.
    @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 method in DiceRoller class that parses dice notation (e.g., '2d20k1'), generates random rolls, sorts them descending, keeps the highest specified number, and returns all rolls and kept rolls.
    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
  • __str__ method of DiceRoller that formats the roll results into a readable string, handling single or multiple rolls by calling roll_dice or roll_multiple.
    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:21-21 (registration)
    The @mcp.tool() decorator registers the roll_dice function as an MCP tool.
    @mcp.tool()

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/UpendraNath/MCP'

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