Skip to main content
Glama
pmhw

MCP Lottery Demo

by pmhw

roll_dice

Roll dice with customizable sides and quantities for random number generation in games, simulations, or decision-making scenarios.

Instructions

投掷骰子,支持自定义面数和数量

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNo骰子数量,默认为1
sidesNo骰子面数,默认为6

Implementation Reference

  • Handler for roll_dice tool: validates sides and count parameters, generates random dice rolls from 1 to sides for specified count, computes total if multiple, formats and returns text content.
    case 'roll_dice': {
      // 投骰子工具:模拟投掷骰子
      const { sides = 6, count = 1 } = args;
      
      // 参数验证
      if (sides < 2) {
        throw new Error('骰子面数至少为2');
      }
      
      if (count < 1) {
        throw new Error('骰子数量至少为1');
      }
    
      // 执行投骰子逻辑
      const results = [];
      let total = 0;
      
      for (let i = 0; i < count; i++) {
        // 生成 1 到 sides 之间的随机数
        const roll = Math.floor(Math.random() * sides) + 1;
        results.push(roll);
        total += roll;
      }
    
      // 根据骰子数量格式化输出
      const resultText = count === 1 
        ? `🎲 投掷结果:${results[0]}`
        : `🎲 投掷结果:${results.join(', ')}\n📊 总计:${total}`;
    
      return {
        content: [
          {
            type: 'text',
            text: resultText,
          },
        ],
      };
    }
  • Input schema for roll_dice tool defining properties sides (number, default 6) and count (number, default 1).
    {
      name: 'roll_dice',
      description: '投掷骰子,支持自定义面数和数量',
      inputSchema: {
        type: 'object',
        properties: {
          sides: {
            type: 'number',
            description: '骰子面数,默认为6',
            default: 6,
          },
          count: {
            type: 'number',
            description: '骰子数量,默认为1',
            default: 1,
          },
        },
      },
    },
  • Handler for roll_dice tool in HTTP server: identical logic to stdio version, validates parameters, rolls dice, formats result.
    case 'roll_dice': {
      const { sides = 6, count = 1 } = args;
      
      if (sides < 2) {
        throw new Error('骰子面数至少为2');
      }
      
      if (count < 1) {
        throw new Error('骰子数量至少为1');
      }
    
      const results = [];
      let total = 0;
      
      for (let i = 0; i < count; i++) {
        const roll = Math.floor(Math.random() * sides) + 1;
        results.push(roll);
        total += roll;
      }
    
      const resultText = count === 1 
        ? `🎲 投掷结果:${results[0]}`
        : `🎲 投掷结果:${results.join(', ')}\n📊 总计:${total}`;
    
      return {
        content: [
          {
            type: 'text',
            text: resultText,
          },
        ],
      };
    }
  • Input schema for roll_dice tool in HTTP server: properties sides (number, default 6) and count (number, default 1).
    name: 'roll_dice',
    description: '投掷骰子,支持自定义面数和数量',
    inputSchema: {
      type: 'object',
      properties: {
        sides: {
          type: 'number',
          description: '骰子面数,默认为6',
          default: 6,
        },
        count: {
          type: 'number',
          description: '骰子数量,默认为1',
          default: 1,
        },
      },
    },
  • src/server.js:118-122 (registration)
    Registration of tools list handler which includes roll_dice in the tools array.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools,  // 返回工具列表
      };
    });
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool rolls dice with customizable parameters but doesn't describe output format, randomness characteristics, error conditions, or any side effects. For a tool with no annotation coverage, this leaves significant behavioral gaps.

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 extremely concise - a single sentence that efficiently communicates the core functionality. Every word earns its place with no redundant information or 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 and no output schema, the description is incomplete. It doesn't explain what the tool returns (individual rolls, sum, distribution), error handling, or practical usage context. For a randomization tool with two parameters, more behavioral context would be helpful.

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?

The schema has 100% description coverage with clear parameter documentation, so the baseline is 3. The description adds minimal value beyond the schema by mentioning customizability of sides and count, but doesn't provide additional semantic context about parameter usage or constraints.

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 dice) and specifies key capabilities ('支持自定义面数和数量' - supports custom number of sides and quantity). It distinguishes from siblings by focusing on dice rather than lottery or coin operations, though it doesn't explicitly contrast with them.

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 the sibling tools (draw_lottery, flip_coin). It mentions what the tool does but offers no context about appropriate use cases, alternatives, 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/pmhw/McpDemo'

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