Skip to main content
Glama
nilay320

Tavily Web Search MCP Server

by nilay320

roll_dice

Simulate dice rolls using standard notation to generate random numbers for games, decisions, or probability testing.

Instructions

Roll the dice with the given notation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
notationYes
num_rollsNo

Implementation Reference

  • server.py:23-27 (handler)
    The main handler function for the 'roll_dice' tool, decorated with @mcp.tool() for registration in the MCP server. It creates a DiceRoller instance and returns its string representation containing the roll results.
    @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)
  • The DiceRoller class implements the core dice rolling logic: parses notation like '2d20k1', rolls random dice, keeps highest N rolls, supports multiple rolls, and formats output string used by the tool 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:10-10 (registration)
    Import of the DiceRoller helper class used in the roll_dice tool implementation.
    from dice_roller import DiceRoller
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action without disclosing behavioral traits like output format, error handling, or constraints (e.g., notation syntax limits). It mentions 'notation' but doesn't explain what that entails, leaving gaps in transparency.

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 with zero waste, front-loading the core action. It's appropriately sized for a simple tool, making every word count without unnecessary elaboration.

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?

Given no annotations, 0% schema coverage, and no output schema, the description is incomplete. It doesn't explain what 'notation' means, how results are returned, or any error cases, making it inadequate for a tool with two parameters and unspecified behavior.

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

Parameters2/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 but only vaguely references 'notation' without explaining its meaning or format. It doesn't address the 'num_rolls' parameter at all, failing to add meaningful semantics beyond the bare schema.

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'), specifying it uses 'given notation' which distinguishes it from simple dice rolling. However, it doesn't explicitly differentiate from sibling tools like generate_qr_code or scientific_calculator, which prevents a perfect score.

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 or in what context. It lacks any mention of prerequisites, exclusions, or comparisons with sibling tools, leaving usage entirely implicit.

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/nilay320/MCP-Session-Code'

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