Skip to main content
Glama
turlockmike

MCP Rand

by turlockmike

generate_string

Create a random string of a specified length and character set, such as alphanumeric, numeric, lowercase, uppercase, or special characters.

Instructions

Generate a random string with specified length and character set

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
charsetNoCharacter set to use (alphanumeric, numeric, lowercase, uppercase, special). Defaults to alphanumeric.
lengthNoLength of the string to generate. Defaults to 10.

Implementation Reference

  • The generateStringHandler function that executes the tool: parses arguments, validates inputs, generates random string using helper, and returns as MCP tool result.
    export const generateStringHandler = async (
      request: CallToolRequest
    ): Promise<CallToolResult> => {
      const args = request.params.arguments as { length?: number; charset?: CharsetType };
      const length = args.length ?? 10;
      const charsetType = args.charset ?? 'alphanumeric';
    
      if (length <= 0) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Length must be a positive number'
        );
      }
    
      if (!Object.keys(charsets).includes(charsetType)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid charset specified'
        );
      }
    
      const randomString = generateRandomString(length, charsets[charsetType]);
      
      return {
        content: [
          {
            type: 'text',
            text: randomString
          }
        ]
      };
    };
  • The toolSpec defining the name, description, and input schema for 'generate_string' tool.
    export const toolSpec = {
      name: 'generate_string',
      description: 'Generate a random string with specified length and character set',
      inputSchema: {
        type: 'object' as const,
        properties: {
          length: {
            type: 'number',
            description: 'Length of the string to generate. Defaults to 10.',
          },
          charset: {
            type: 'string',
            description: 'Character set to use (alphanumeric, numeric, lowercase, uppercase, special). Defaults to alphanumeric.',
            enum: ['alphanumeric', 'numeric', 'lowercase', 'uppercase', 'special']
          }
        }
      }
    };
  • src/index.ts:22-22 (registration)
    Registration of the generateStringHandler under the 'generate_string' tool name in the MCP handler registry.
    registry.register('tools/call', 'generate_string', generateStringHandler as Handler);
  • Helper function to generate the random string by sampling characters from the specified charset.
    function generateRandomString(length: number, charset: string): string {
      let result = '';
      for (let i = 0; i < length; i++) {
        const randomIndex = Math.floor(Math.random() * charset.length);
        result += charset[randomIndex];
      }
      return result;
    }
  • Charset definitions used by the generate_string tool for different character sets.
    const charsets: Record<CharsetType, string> = {
      alphanumeric: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
      numeric: '0123456789',
      lowercase: 'abcdefghijklmnopqrstuvwxyz',
      uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
      special: '!@#$%^&*()_+-=[]{};\'"\\|,.<>/?'
    };
Behavior3/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 the tool generates random strings, which implies non-destructive behavior, but doesn't mention any rate limits, performance characteristics, randomness quality, or what happens with invalid inputs. The description adds basic context but lacks depth about operational behavior.

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 immediately states the tool's purpose and key parameters. Every word earns its place with zero waste or redundancy. It's appropriately sized for a simple generation tool.

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

Completeness4/5

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

For a simple random string generator with 2 well-documented parameters and no output schema, the description is reasonably complete. It covers the core purpose and parameters, though it could benefit from mentioning the randomness source or quality. Given the tool's low complexity and good schema coverage, the description is mostly adequate.

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 fully documents both parameters (charset with enum values and defaults, length with defaults). The description mentions 'specified length and character set' but adds no additional meaning beyond what's in the schema. Baseline 3 is appropriate when schema does the heavy lifting.

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 ('Generate a random string') and specifies the key resources ('with specified length and character set'). It distinguishes from siblings like generate_password, generate_uuid, and generate_random_number by focusing specifically on customizable string generation rather than passwords, UUIDs, or numbers.

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 generating random strings with customizable parameters, but doesn't explicitly state when to use this tool versus alternatives like generate_password (which might have different security characteristics) or generate_uuid (for unique identifiers). No explicit exclusions or comparisons to sibling tools are 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