Skip to main content
Glama

generate-id

Generate unique identifiers using algorithms like CUID2, UUID, NanoID, or ULID with customizable quantity. Designed for creating collision-resistant IDs in various applications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
algorithmNocuid2
quantityNo

Implementation Reference

  • The handler function for the 'generate-id' tool. It generates the specified quantity of IDs using the chosen algorithm (cuid2, uuid, nanoid, or ulid) and returns them as a comma-separated string or an error.
    async ({ algorithm, quantity }) => { try { let ids: string[] = []; for (let i = 0; i < quantity; i++) { switch (algorithm) { case 'cuid2': ids.push(createId()); break; case 'nanoid': ids.push(nanoid()); break; case 'ulid': ids.push(ulid()); break; case 'uuid': default: ids.push(uuidv4()); break; } } if (ids.length === 0) { return respond('Failed to generate IDs', true); } return respond(ids.join(',')); } catch (err: unknown) { const error = err as Error; return respond(`Error: ${error.message}`, true); } }
  • Input schema for the 'generate-id' tool using Zod, defining 'algorithm' (enum with default 'cuid2') and 'quantity' (number with default 1).
    { algorithm: z.enum(['cuid2', 'uuid', 'nanoid', 'ulid']).default('cuid2'), quantity: z.number().default(1), },
  • src/index.ts:19-57 (registration)
    Registration of the 'generate-id' tool on the MCP server, specifying the tool name, input schema, and handler function.
    server.tool( 'generate-id', { algorithm: z.enum(['cuid2', 'uuid', 'nanoid', 'ulid']).default('cuid2'), quantity: z.number().default(1), }, async ({ algorithm, quantity }) => { try { let ids: string[] = []; for (let i = 0; i < quantity; i++) { switch (algorithm) { case 'cuid2': ids.push(createId()); break; case 'nanoid': ids.push(nanoid()); break; case 'ulid': ids.push(ulid()); break; case 'uuid': default: ids.push(uuidv4()); break; } } if (ids.length === 0) { return respond('Failed to generate IDs', true); } return respond(ids.join(',')); } catch (err: unknown) { const error = err as Error; return respond(`Error: ${error.message}`, true); } } );
  • Helper function used by the tool handler to format successful or error responses as CallToolResult objects.
    function respond(text: string, isError: boolean = false): CallToolResult { return { content: [ { type: 'text' as const, text } ], isError }; }

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/devstacks-software-engineering/id-generator-mcp'

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