Skip to main content
Glama

Generate QR Code as SVG

generate-qrcode-svg

Generate QR codes in SVG format from text or URLs with customizable options including error correction, colors, size, and margins for versatile integration needs.

Instructions

Generate a QR code from text or URL and return it as SVG format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
optionsNoQR code generation options
textYesThe text or URL to encode in the QR code

Implementation Reference

  • src/index.ts:81-136 (registration)
    Full registration of the 'generate-qrcode-svg' tool using server.registerTool, including title, description, inputSchema, and the handler function.
    server.registerTool(
      "generate-qrcode-svg",
      {
        title: "Generate QR Code as SVG",
        description: "Generate a QR code from text or URL and return it as SVG format",
        inputSchema: {
          text: z.string().min(1).describe("The text or URL to encode in the QR code"),
          options: 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()
          }).optional().describe("QR code generation options")
        }
      },
      async ({ text, options = {} }) => {
        try {
          const qrOptions = {
            errorCorrectionLevel: options.errorCorrectionLevel || 'M',
            width: options.width,
            margin: options.margin || defaultMargin,
            color: {
              dark: options.color?.dark || getDefaultDarkColor(),
              light: options.color?.light || getDefaultLightColor()
            }
          };
    
          const svgString = await QRCode.toString(text, { 
            ...qrOptions,
            type: 'svg' 
          });
          
          return {
            content: [
              {
                type: "text",
                text: `QR code SVG generated successfully for: "${text}"\n\n${svgString}`
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error generating QR code SVG: ${error instanceof Error ? error.message : 'Unknown error'}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Handler function that takes text and options, constructs QR code options, generates SVG using QRCode.toString, and returns the SVG as text content or error.
    async ({ text, options = {} }) => {
      try {
        const qrOptions = {
          errorCorrectionLevel: options.errorCorrectionLevel || 'M',
          width: options.width,
          margin: options.margin || defaultMargin,
          color: {
            dark: options.color?.dark || getDefaultDarkColor(),
            light: options.color?.light || getDefaultLightColor()
          }
        };
    
        const svgString = await QRCode.toString(text, { 
          ...qrOptions,
          type: 'svg' 
        });
        
        return {
          content: [
            {
              type: "text",
              text: `QR code SVG generated successfully for: "${text}"\n\n${svgString}`
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error generating QR code SVG: ${error instanceof Error ? error.message : 'Unknown error'}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod input schema for the tool: required 'text' string and optional 'options' object with errorCorrectionLevel, width, margin, and color settings.
    inputSchema: {
      text: z.string().min(1).describe("The text or URL to encode in the QR code"),
      options: 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()
      }).optional().describe("QR code generation options")
    }
  • Helper functions providing default colors for QR code (light: white, dark: black), used in options.
    function getDefaultLightColor(): string {
      return '#FFFFFF';
    }
  • Default margin value used for QR code generation.
    const defaultMargin = 4;
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the output format (SVG) but doesn't describe other behavioral traits like whether this is a read-only operation, potential rate limits, error handling, or what happens with invalid input. For a generation tool with zero annotation coverage, this leaves significant gaps.

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 states the core functionality without unnecessary words. It's appropriately sized and front-loaded with the essential information.

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

Completeness3/5

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

Given the tool's moderate complexity (2 parameters, nested objects) and 100% schema coverage but no annotations or output schema, the description is minimally adequate. It covers the basic purpose but lacks behavioral context and sibling differentiation that would make it more complete for agent use.

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 the schema already documents both parameters (text and options) thoroughly. The description adds minimal value beyond the schema - it mentions 'text or URL' which aligns with the schema's description, but doesn't provide additional context about parameter usage or constraints. Baseline 3 is appropriate when schema does the heavy lifting.

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 tool's purpose: 'Generate a QR code from text or URL and return it as SVG format.' It specifies the verb (generate), resource (QR code), and output format (SVG). However, it doesn't explicitly differentiate from its siblings (batch, dataurl, terminal variants), which would require a 5.

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 (generate-qrcode-batch, generate-qrcode-dataurl, generate-qrcode-terminal). It doesn't mention alternatives, exclusions, or specific contexts for choosing SVG output over other formats.

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