Skip to main content
Glama

generate-qrcode-batch

Generate multiple QR codes from texts or URLs in batch, supporting various output formats like DataURL, SVG, or terminal display with customizable size, colors, and error correction.

Instructions

Generate multiple QR codes from an array of texts or URLs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoOutput format for QR codesdataurl
optionsNoQR code generation options
textsYesArray of texts or URLs to encode (max 10)

Implementation Reference

  • The main handler function for the 'generate-qrcode-batch' tool. It processes an array of texts, generates QR codes in specified format (dataurl, svg, or terminal), handles errors per item, and returns structured content with images or text representations.
    async ({ texts, format = 'dataurl', options = {} }) => { try { const results = []; for (let i = 0; i < texts.length; i++) { const text = texts[i]; try { let qrResult; if (format === 'dataurl') { const qrOptions = { errorCorrectionLevel: options.errorCorrectionLevel || 'M', width: options.width, margin: options.margin || defaultMargin, color: { dark: options.color?.dark || getDefaultDarkColor(), light: options.color?.light || getDefaultLightColor() } }; qrResult = await QRCode.toDataURL(text, qrOptions); } else if (format === 'svg') { qrResult = await QRCode.toString(text, { type: 'svg' }); } else if (format === 'terminal') { qrResult = await QRCode.toString(text, { type: 'terminal' }); } results.push({ text, success: true, result: qrResult || '' }); } catch (error) { results.push({ text, success: false, error: error instanceof Error ? error.message : 'Unknown error' }); } } const successCount = results.filter(r => r.success).length; const content: Array<{ type: "text"; text: string; } | { type: "image"; data: string; mimeType: string; }> = [ { type: "text", text: `Batch QR code generation completed: ${successCount}/${texts.length} successful\n\n` } ]; // Add results for (let i = 0; i < results.length; i++) { const result = results[i]; if (result.success && result.result) { content.push({ type: "text", text: `${i + 1}. QR code for "${result.text}":` }); if (format === 'dataurl') { content.push({ type: "image", data: result.result, mimeType: options.type || "image/png" }); } else { content.push({ type: "text", text: result.result }); } } else { content.push({ type: "text", text: `${i + 1}. Error for "${result.text}": ${result.error || 'Unknown error'}` }); } content.push({ type: "text", text: "\n" }); } return { content }; } catch (error) { return { content: [ { type: "text", text: `Error in batch QR code generation: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } }
  • Input schema defining parameters for batch QR code generation: texts array (1-10), format (dataurl/svg/terminal), and options.
    inputSchema: { texts: z.array(z.string().min(1)).min(1).max(10).describe("Array of texts or URLs to encode (max 10)"), format: z.enum(['dataurl', 'svg', 'terminal']).optional().default('dataurl').describe("Output format for QR codes"), options: QRCodeOptionsSchema.optional().describe("QR code generation options") }
  • Shared schema for QR code generation options, used in the batch tool's options field.
    const QRCodeOptionsSchema = z.object({ errorCorrectionLevel: z.enum(['L', 'M', 'Q', 'H']).optional().default('M'), width: z.number().min(50).max(2000).optional(), margin: z.number().min(0).max(10).optional().default(defaultMargin), color: z.object({ dark: z.string().optional().default(getDefaultDarkColor()), light: z.string().optional().default(getDefaultLightColor()) }).optional(), type: z.enum(['image/png', 'image/jpeg', 'image/webp']).optional().default('image/png') });
  • src/index.ts:181-291 (registration)
    Registration of the 'generate-qrcode-batch' tool using server.registerTool, including title, description, input schema, and handler reference.
    server.registerTool( "generate-qrcode-batch", { title: "Generate Multiple QR Codes", description: "Generate multiple QR codes from an array of texts or URLs", inputSchema: { texts: z.array(z.string().min(1)).min(1).max(10).describe("Array of texts or URLs to encode (max 10)"), format: z.enum(['dataurl', 'svg', 'terminal']).optional().default('dataurl').describe("Output format for QR codes"), options: QRCodeOptionsSchema.optional().describe("QR code generation options") } }, async ({ texts, format = 'dataurl', options = {} }) => { try { const results = []; for (let i = 0; i < texts.length; i++) { const text = texts[i]; try { let qrResult; if (format === 'dataurl') { const qrOptions = { errorCorrectionLevel: options.errorCorrectionLevel || 'M', width: options.width, margin: options.margin || defaultMargin, color: { dark: options.color?.dark || getDefaultDarkColor(), light: options.color?.light || getDefaultLightColor() } }; qrResult = await QRCode.toDataURL(text, qrOptions); } else if (format === 'svg') { qrResult = await QRCode.toString(text, { type: 'svg' }); } else if (format === 'terminal') { qrResult = await QRCode.toString(text, { type: 'terminal' }); } results.push({ text, success: true, result: qrResult || '' }); } catch (error) { results.push({ text, success: false, error: error instanceof Error ? error.message : 'Unknown error' }); } } const successCount = results.filter(r => r.success).length; const content: Array<{ type: "text"; text: string; } | { type: "image"; data: string; mimeType: string; }> = [ { type: "text", text: `Batch QR code generation completed: ${successCount}/${texts.length} successful\n\n` } ]; // Add results for (let i = 0; i < results.length; i++) { const result = results[i]; if (result.success && result.result) { content.push({ type: "text", text: `${i + 1}. QR code for "${result.text}":` }); if (format === 'dataurl') { content.push({ type: "image", data: result.result, mimeType: options.type || "image/png" }); } else { content.push({ type: "text", text: result.result }); } } else { content.push({ type: "text", text: `${i + 1}. Error for "${result.text}": ${result.error || 'Unknown error'}` }); } content.push({ type: "text", text: "\n" }); } return { content }; } catch (error) { return { content: [ { type: "text", text: `Error in batch QR code generation: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } );
  • Helper functions providing default colors for QR code generation, used in options processing.
    function getDefaultLightColor(): string { return '#FFFFFF'; } function getDefaultDarkColor(): string { return '#000000'; }

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/antoBrugnot/qrcode-mcp'

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