Skip to main content
Glama
devstacks-software-engineering

ID Generator MCP

generate-id

Generate unique identifiers using UUID, CUID2, Nanoid, or ULID algorithms for database records, API requests, or distributed systems.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
algorithmNocuid2
quantityNo

Implementation Reference

  • The handler function for the 'generate-id' tool. It generates the specified quantity of unique IDs using the chosen algorithm (cuid2, uuid, nanoid, or ulid) and returns them comma-separated 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);
      }
    }
  • Zod schema defining the input parameters for the tool: 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 using server.tool(name, schema, handler).
    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 handler to format responses as CallToolResult objects, with optional error flag.
    function respond(text: string, isError: boolean = false): CallToolResult {
      return {
        content: [
          {
            type: 'text' as const,
            text
          }
        ],
        isError
      };
    }
Install Server

Other 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