Skip to main content
Glama

Generate Multiple QR Codes

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';
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the basic function without disclosing behavioral traits. It doesn't mention output format (e.g., array of data URLs), performance implications of batch generation, error handling for invalid inputs, or any rate limits—critical gaps for a batch operation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded with the core action and input, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a batch operation with nested parameters, the description is incomplete. It doesn't explain what the tool returns (e.g., an array of QR codes in the specified format), error conditions, or how batch processing differs behaviorally from single generation, leaving significant gaps for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description adds minimal value by mentioning 'array of texts or URLs' which aligns with the 'texts' parameter, but doesn't provide additional context beyond what the schema already specifies, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('generate multiple QR codes') and the input source ('from an array of texts or URLs'), which is specific and actionable. However, it doesn't explicitly differentiate from its siblings (generate-qrcode-dataurl, generate-qrcode-svg, generate-qrcode-terminal) which appear to be single-output variants, missing full sibling distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus its siblings or alternatives. It doesn't mention scenarios like batch processing needs, performance considerations, or differences from the single-output tools, leaving usage context entirely implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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

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