Skip to main content
Glama

generate_random_bytes

Create cryptographically secure random bytes for encryption or data security. Specify length and encoding (hex, base64, binary) for tailored output. Ideal for secure key generation or sensitive data handling.

Instructions

Generate cryptographically secure random bytes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
encodingNoOutput encoding formathex
lengthNoNumber of random bytes to generate

Implementation Reference

  • The core handler function that generates cryptographically secure random bytes using Node.js crypto.randomBytes. Supports length (1-1024 bytes, default 32) and encoding (hex, base64, binary). Returns JSON with the result.
    private async generateRandomBytes(args: any) { const length = args.length ?? 32; const encoding = args.encoding ?? "hex"; if (length < 1 || length > 1024) { throw new Error("Length must be between 1 and 1024"); } const bytes = randomBytes(length); let result: string; switch (encoding) { case "hex": result = bytes.toString("hex"); break; case "base64": result = bytes.toString("base64"); break; case "binary": result = bytes.toString("binary"); break; default: throw new Error("Invalid encoding. Must be 'hex', 'base64', or 'binary'"); } return { content: [ { type: "text", text: JSON.stringify({ type: "random_bytes", value: result, parameters: { length, encoding }, timestamp: new Date().toISOString(), }, null, 2), }, ], }; }
  • Input schema for the generate_random_bytes tool, defining parameters: length (integer, 1-1024, default 32) and encoding (string enum: hex/base64/binary, default hex).
    inputSchema: { type: "object", properties: { length: { type: "integer", description: "Number of random bytes to generate", default: 32, minimum: 1, maximum: 1024, }, encoding: { type: "string", description: "Output encoding format", enum: ["hex", "base64", "binary"], default: "hex", }, }, required: [], },
  • src/index.ts:110-132 (registration)
    Tool registration in the ListTools response, including name, description, and reference to inputSchema.
    { name: "generate_random_bytes", description: "Generate cryptographically secure random bytes", inputSchema: { type: "object", properties: { length: { type: "integer", description: "Number of random bytes to generate", default: 32, minimum: 1, maximum: 1024, }, encoding: { type: "string", description: "Output encoding format", enum: ["hex", "base64", "binary"], default: "hex", }, }, required: [], }, },
  • src/index.ts:253-254 (registration)
    Dispatch case in the CallToolRequestSchema handler that routes calls to the generateRandomBytes method.
    case "generate_random_bytes": return await this.generateRandomBytes(args);

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