Skip to main content
Glama

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;

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