Skip to main content
Glama
turlockmike

MCP Rand

by turlockmike

draw_cards

Draw a specified number of cards from a standard deck using a base64 encoded deck state for tracking. Ideal for card-based applications needing controlled randomization.

Instructions

Draw cards from a standard deck of playing cards

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countYesNumber of cards to draw
deckStateNoOptional base64 encoded string representing the current deck state

Implementation Reference

  • The main handler function that executes the draw_cards tool: parses arguments, manages deck state, shuffles and draws cards, returns JSON result.
    export const drawCardsHandler = async (
      request: CallToolRequest
    ): Promise<CallToolResult> => {
      const args = request.params.arguments as { count: number; deckState?: string };
      
      if (args.count <= 0) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Must draw at least one card'
        );
      }
    
      // Validate and process deck state if provided
      let availableCards: Card[];
      if (args.deckState) {
        // Validate base64 format
        if (!/^[A-Za-z0-9+/]+=*$/.test(args.deckState)) {
          throw new McpError(
            ErrorCode.InvalidParams,
            'Invalid deck state: must be base64 encoded'
          );
        }
        availableCards = getAvailableCardsFromState(args.deckState);
      } else {
        availableCards = createDeck();
      }
    
      if (args.count > availableCards.length) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Cannot draw ${args.count} cards from deck with ${availableCards.length} cards remaining`
        );
      }
    
      // Shuffle the available cards
      const shuffledCards = shuffleArray(availableCards);
      
      // Draw the requested number of cards
      const drawnCards = shuffledCards.slice(0, args.count);
      
      // Calculate remaining cards and get their state
      const remainingCards = shuffledCards.slice(args.count);
      const newDeckState = getDeckStateFromCards(remainingCards);
    
      const result = {
        drawnCards,
        remainingCount: remainingCards.length,
        deckState: newDeckState
      };
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2)
          }
        ]
      };
    };
  • Tool specification defining name, description, and input schema for the draw_cards tool.
    export const toolSpec = {
      name: 'draw_cards',
      description: 'Draw cards from a standard deck of playing cards',
      inputSchema: {
        type: 'object' as const,
        properties: {
          count: {
            type: 'number',
            description: 'Number of cards to draw',
          },
          deckState: {
            type: 'string',
            description: 'Optional base64 encoded string representing the current deck state',
          }
        },
        required: ['count']
      }
    };
  • src/index.ts:17-26 (registration)
    Registers all tool handlers including draw_cards with the HandlerRegistry in the main server setup.
    async function registerHandlers(registry: HandlerRegistry): Promise<void> {
      registry.register('tools/list', 'list', ListToolsHandler as Handler);
      registry.register('tools/call', 'generate_uuid', generateUuidHandler as Handler);
      registry.register('tools/call', 'generate_random_number', generateRandomNumberHandler as Handler);
      registry.register('tools/call', 'generate_gaussian', generateGaussianHandler as Handler);
      registry.register('tools/call', 'generate_string', generateStringHandler as Handler);
      registry.register('tools/call', 'generate_password', generatePasswordHandler as Handler);
      registry.register('tools/call', 'roll_dice', rollDiceHandler as Handler);
      registry.register('tools/call', 'draw_cards', drawCardsHandler as Handler);
    }
  • Helper function to create a full standard deck of 52 cards.
    function createDeck(): Card[] {
      const deck: Card[] = [];
      for (const suit of SUITS) {
        for (const value of VALUES) {
          deck.push({ suit, value });
        }
      }
      return deck;
    }
  • Fisher-Yates shuffle implementation for randomizing the deck.
    function shuffleArray<T>(array: T[]): T[] {
      const shuffled = [...array];
      for (let i = shuffled.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
      }
      return shuffled;
    }
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 states what the tool does but doesn't describe how it behaves: whether it draws with or without replacement, how the deck state parameter affects behavior, what happens when the deck is exhausted, or what the output format looks like. For a tool with mutation implications (drawing changes deck state), this is a significant gap.

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 directly states the tool's function with zero wasted words. It's appropriately sized and front-loaded, making it immediately clear what the tool does 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 the complexity of a card-drawing tool with deck state management, no annotations, and no output schema, the description is incomplete. It doesn't explain the return format (e.g., card values, suits), how deck state is used or updated, or error conditions (e.g., drawing more cards than available). For a tool that likely involves state mutation and random selection, more context 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 both parameters thoroughly. The description doesn't add any meaning beyond what the schema provides about count or deckState. It implies drawing from a deck but doesn't elaborate on parameter interactions or constraints beyond the schema's baseline documentation.

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 ('draw') and resource ('cards from a standard deck of playing cards'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools, but since the siblings are all different generation functions (Gaussian, password, random number, string, UUID, dice), the distinction is inherent rather than explicitly stated.

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 prerequisites like needing a deck state for sequential draws or clarify that it's for card games versus other random generation tools. There's no explicit when/when-not or alternative tool references.

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