Skip to main content
Glama
VeriTeknik

Pluggedin Random Number Generator

generate_random_string

Create cryptographically secure random strings with customizable length, character set, and count for enhanced data security and flexibility.

Instructions

Generate a cryptographically secure random string

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
charsetNoCharacter set to usealphanumeric
countNoNumber of random strings to generate
lengthNoLength of the random string

Implementation Reference

  • The core handler function implementing the generate_random_string tool logic, generating cryptographically secure random strings using Node.js crypto.randomInt from specified character sets.
    private async generateRandomString(args: any) {
      const length = args.length ?? 16;
      const charset = args.charset ?? "alphanumeric";
      const count = args.count ?? 1;
    
      if (length < 1 || length > 256) {
        throw new Error("Length must be between 1 and 256");
      }
    
      if (count < 1 || count > 100) {
        throw new Error("Count must be between 1 and 100");
      }
    
      const charsets = {
        alphanumeric: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
        alphabetic: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
        numeric: "0123456789",
        hex: "0123456789abcdef",
        base64: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
        ascii_printable: "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
      };
    
      const chars = charsets[charset as keyof typeof charsets];
      if (!chars) {
        throw new Error(`Invalid charset: ${charset}`);
      }
    
      const results: string[] = [];
      for (let i = 0; i < count; i++) {
        let result = "";
        for (let j = 0; j < length; j++) {
          const randomIndex = randomInt(0, chars.length);
          result += chars[randomIndex];
        }
        results.push(result);
      }
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({
              type: "random_strings",
              values: results,
              parameters: { length, charset, count },
              timestamp: new Date().toISOString(),
            }, null, 2),
          },
        ],
      };
    }
  • src/index.ts:156-185 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining the tool name, description, and input schema.
    {
      name: "generate_random_string",
      description: "Generate a cryptographically secure random string",
      inputSchema: {
        type: "object",
        properties: {
          length: {
            type: "integer",
            description: "Length of the random string",
            default: 16,
            minimum: 1,
            maximum: 256,
          },
          charset: {
            type: "string",
            description: "Character set to use",
            enum: ["alphanumeric", "alphabetic", "numeric", "hex", "base64", "ascii_printable"],
            default: "alphanumeric",
          },
          count: {
            type: "integer",
            description: "Number of random strings to generate",
            default: 1,
            minimum: 1,
            maximum: 100,
          },
        },
        required: [],
      },
    },
  • Input schema validation for the generate_random_string tool parameters.
    inputSchema: {
      type: "object",
      properties: {
        length: {
          type: "integer",
          description: "Length of the random string",
          default: 16,
          minimum: 1,
          maximum: 256,
        },
        charset: {
          type: "string",
          description: "Character set to use",
          enum: ["alphanumeric", "alphabetic", "numeric", "hex", "base64", "ascii_printable"],
          default: "alphanumeric",
        },
        count: {
          type: "integer",
          description: "Number of random strings to generate",
          default: 1,
          minimum: 1,
          maximum: 100,
        },
      },
      required: [],
  • Dispatch case in CallToolRequestSchema handler that routes to the generateRandomString implementation.
    case "generate_random_string":
      return await this.generateRandomString(args);
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/VeriTeknik/pluggedin-random-number-generator-mcp'

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