Skip to main content
Glama
turlockmike

MCP Rand

by turlockmike

roll_dice

Simulate dice rolls using standard notation (e.g., "2d6", "3d6+5") for tabletop games, RPGs, or probability testing. Input an array of dice codes to generate random outcomes.

Instructions

Roll a set of dice using standard dice notation (e.g., "2d6" for two six-sided dice, "3d6+5" for three six-sided dice plus 5)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
diceYesArray of dice to roll

Implementation Reference

  • The main handler function that executes the roll_dice tool, parsing arguments, rolling dice, and returning results as JSON.
    export const rollDiceHandler = async (
      request: CallToolRequest
    ): Promise<CallToolResult> => {
      const args = request.params.arguments as { dice: string[] };
      
      if (!args.dice || args.dice.length === 0) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Must specify at least one die to roll'
        );
      }
    
      const results = args.dice.map(dice => rollDiceSet(dice));
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(results, null, 2)
          }
        ]
      };
    };
  • Tool specification including name, description, and input schema for validating roll_dice parameters.
    export const toolSpec = {
      name: 'roll_dice',
      description: 'Roll a set of dice using standard dice notation (e.g., "2d6" for two six-sided dice, "3d6+5" for three six-sided dice plus 5)',
      inputSchema: {
        type: 'object' as const,
        properties: {
          dice: {
            type: 'array',
            items: {
              type: 'string',
              description: 'Dice notation (e.g., "2d6", "1d20", "4d4")'
            },
            description: 'Array of dice to roll'
          }
        },
        required: ['dice']
      }
    };
  • src/index.ts:24-24 (registration)
    Registers the roll_dice tool handler in the main server registry.
    registry.register('tools/call', 'roll_dice', rollDiceHandler as Handler);
  • Helper function that rolls a single set of dice, computes rolls and total.
    function rollDiceSet(notation: string): DiceRoll {
      const { count, sides, modifier } = parseDiceNotation(notation);
      const rolls = Array.from({ length: count }, () => rollDie(sides));
      const rollTotal = rolls.reduce((a, b) => a + b, 0);
      const total = rollTotal + modifier;
    
      return {
        dice: notation,
        rolls,
        modifier,
        total
      };
    }
  • Helper function to parse dice notation like '2d6+5' into count, sides, and modifier.
    function parseDiceNotation(notation: string): { count: number; sides: number; modifier: number } {
      const match = notation.toLowerCase().match(/^(\d+)d(\d+)([+-]\d+)?$/);
      if (!match) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid dice notation'
        );
      }
    
      const count = parseInt(match[1]);
      const sides = parseInt(match[2]);
      const modifier = match[3] ? parseInt(match[3]) : 0; // If no modifier, default to 0
    
      if (count <= 0) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Number of dice must be positive'
        );
      }
    
      if (sides <= 0) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Die size must be positive'
        );
      }
    
      return { count, sides, modifier };
    }
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. It explains the input format but does not describe output behavior (e.g., return format, whether results are summed or listed, error handling for invalid notation). This leaves gaps in understanding how the tool behaves beyond basic input.

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 front-loads the purpose and provides essential examples without unnecessary details. Every part earns its place by clarifying the tool's function and input format concisely.

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 the complexity of a dice-rolling tool with no annotations and no output schema, the description is incomplete. It adequately covers the input but fails to explain the output (e.g., what is returned, format of results), which is critical for an agent to use the tool correctly. More context on behavior is needed.

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?

Schema description coverage is 100%, so the schema already documents the 'dice' parameter with examples. The description adds marginal value by reinforcing the notation with examples like '2d6' and '3d6+5', but does not provide additional semantics beyond what the schema specifies, such as constraints or advanced usage.

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 a set of dice') and the resource ('using standard dice notation'), with explicit examples that distinguish it from sibling tools like generate_random_number or generate_gaussian. It precisely defines what the tool does without ambiguity.

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 for dice-rolling scenarios by providing notation examples, but it does not explicitly state when to use this tool versus alternatives like generate_random_number for non-dice random numbers or other sibling tools. No guidance on exclusions or prerequisites is provided.

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

Related 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/turlockmike/mcp-rand'

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