generate_nanoid
Create compact, URL-friendly unique identifiers for applications requiring reliable ID generation with customizable length and quantity.
Instructions
Generate a NanoID — a compact, URL-friendly unique ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| length | No | Length of the NanoID (1-128, default: 21) | |
| count | No | Number of IDs to generate (1-100, default: 1) |
Implementation Reference
- src/tools/generators.ts:48-53 (handler)Handler function for generating NanoID, utilizing the nanoid library.
async ({ length, count }) => { const ids = Array.from({ length: count }, () => nanoid(length)); return { content: [{ type: "text" as const, text: ids.join("\n") }], }; } - src/tools/generators.ts:32-47 (schema)Input validation schema using Zod for length and count parameters of the NanoID tool.
{ length: z .number() .int() .min(1) .max(128) .default(21) .describe("Length of the NanoID (1-128, default: 21)"), count: z .number() .int() .min(1) .max(100) .default(1) .describe("Number of IDs to generate (1-100, default: 1)"), }, - src/tools/generators.ts:29-54 (registration)Registration of the 'generate_nanoid' tool within the McpServer instance.
server.tool( "generate_nanoid", "Generate a NanoID — a compact, URL-friendly unique ID.", { length: z .number() .int() .min(1) .max(128) .default(21) .describe("Length of the NanoID (1-128, default: 21)"), count: z .number() .int() .min(1) .max(100) .default(1) .describe("Number of IDs to generate (1-100, default: 1)"), }, async ({ length, count }) => { const ids = Array.from({ length: count }, () => nanoid(length)); return { content: [{ type: "text" as const, text: ids.join("\n") }], }; } );