Skip to main content
Glama
pmhw

MCP Lottery Demo

by pmhw

flip_coin

Simulate coin flips to generate random heads or tails outcomes for decision-making or probability testing. Specify the number of flips needed.

Instructions

抛硬币,返回正面或反面

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNo抛硬币次数,默认为1

Implementation Reference

  • Handler for flip_coin tool in stdio MCP server switch statement: validates input count, performs multiple coin flips using Math.random() < 0.5 for '正面'(heads) or '反面'(tails), tallies results, formats output text.
    case 'flip_coin': {
      // 抛硬币工具:模拟抛硬币
      const { count = 1 } = args;
      
      // 参数验证
      if (count < 1) {
        throw new Error('抛硬币次数至少为1');
      }
    
      // 执行抛硬币逻辑
      const results = [];
      let heads = 0;  // 正面次数
      let tails = 0;  // 反面次数
      
      for (let i = 0; i < count; i++) {
        // 50% 概率生成正面或反面
        const result = Math.random() < 0.5 ? '正面' : '反面';
        results.push(result);
        if (result === '正面') heads++;
        else tails++;
      }
    
      // 根据抛硬币次数格式化输出
      const resultText = count === 1 
        ? `🪙 抛硬币结果:${results[0]}`
        : `🪙 抛硬币结果:${results.join(', ')}\n📊 统计:正面 ${heads} 次,反面 ${tails} 次`;
    
      return {
        content: [
          {
            type: 'text',
            text: resultText,
          },
        ],
      };
    }
  • Handler for flip_coin tool in HTTP server's handleToolCall function: identical implementation to stdio server version.
    case 'flip_coin': {
      const { count = 1 } = args;
      
      if (count < 1) {
        throw new Error('抛硬币次数至少为1');
      }
    
      const results = [];
      let heads = 0;
      let tails = 0;
      
      for (let i = 0; i < count; i++) {
        const result = Math.random() < 0.5 ? '正面' : '反面';
        results.push(result);
        if (result === '正面') heads++;
        else tails++;
      }
    
      const resultText = count === 1 
        ? `🪙 抛硬币结果:${results[0]}`
        : `🪙 抛硬币结果:${results.join(', ')}\n📊 统计:正面 ${heads} 次,反面 ${tails} 次`;
    
      return {
        content: [
          {
            type: 'text',
            text: resultText,
          },
        ],
      };
    }
  • src/server.js:98-110 (registration)
    Registration of flip_coin tool in tools array for ListToolsRequestHandler, including name, description, and input schema.
      name: 'flip_coin',
      description: '抛硬币,返回正面或反面',
      inputSchema: {
        type: 'object',
        properties: {
          count: {
            type: 'number',
            description: '抛硬币次数,默认为1',
            default: 1,
          },
        },
      },
    },
  • Registration of flip_coin tool in tools array for HTTP /tools endpoint, including name, description, and input schema.
      name: 'flip_coin',
      description: '抛硬币,返回正面或反面',
      inputSchema: {
        type: 'object',
        properties: {
          count: {
            type: 'number',
            description: '抛硬币次数,默认为1',
            default: 1,
          },
        },
      },
    },
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the basic behavior (flip coin, return heads/tails) but lacks details like whether it's deterministic, if there are rate limits, error conditions, or how multiple flips (with count parameter) are handled. For a tool with no annotations, this is minimal disclosure.

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 and front-loaded: '抛硬币,返回正面或反面' (flip a coin, return heads or tails). It uses minimal words to convey the core purpose without any wasted sentences, making it efficient and easy to understand.

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

Completeness3/5

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

Given the tool's low complexity (simple random generation), no annotations, no output schema, and a single parameter with full schema coverage, the description is adequate but basic. It covers the main action and outcome, but lacks details on behavior for multiple flips or error handling, which could be useful for completeness in this context.

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 input schema has 100% description coverage, with the 'count' parameter documented as '抛硬币次数,默认为1' (number of coin flips, default is 1). The description doesn't add any parameter semantics beyond this, as it doesn't mention parameters at all. With high schema coverage, the baseline score of 3 is appropriate.

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 tool's purpose: '抛硬币,返回正面或反面' (flip a coin, return heads or tails). It specifies the action (flip coin) and the outcome (return heads/tails), which is straightforward. However, it doesn't explicitly differentiate from sibling tools like 'draw_lottery' or 'roll_dice', though the action is distinct enough to imply difference.

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. It doesn't mention sibling tools or any context for choosing flip_coin over draw_lottery or roll_dice, such as for binary outcomes or simple random selection. This lack of comparative guidance limits its utility in a multi-tool environment.

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