Skip to main content
Glama

create-qr-code

Generate QR codes for URLs, text, or data. Get a shareable image URL or save the QR code file directly with customizable size, colors, and formatting options.

Instructions

Create QR codes using QuickChart - get QR code image URL or save QR code image to file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesWhether to get QR code URL or save as file
outputPathNoPath where to save the file (only used with action=save_file)
textYesContent of the QR code (URL, text, etc.)
formatNoOutput format (default: png)
sizeNoImage dimensions in pixels (default: 150)
marginNoWhitespace around QR image (default: 4)
darkNoHex color for QR grid cells (default: black)
lightNoHex color for background (default: white, use '0000' for transparent)
ecLevelNoError correction level (default: M)
centerImageUrlNoURL of center image (must be URL-encoded)
centerImageSizeRatioNoCenter image size ratio (0.0-1.0, default: 0.3)
captionNoText below QR code
captionFontFamilyNoCaption font family (default: 'sans-serif')
captionFontSizeNoCaption font size (default: 10)
captionFontColorNoCaption text color (default: black)

Implementation Reference

  • Main handler function that validates inputs, builds QuickChart API parameters, fetches QR code image data, embeds PNG base64, provides URL, and optionally saves file to disk.
    export async function handleQRCodeTool(args: any): Promise<any> { const text = args.text as string; const action = args.action as string; validateText(text); validateAction(action); validateOutputPath(args.outputPath, action); validateFormat(args.format); validateSize(args.size); validateMargin(args.margin); validateEcLevel(args.ecLevel); validateCenterImageSizeRatio(args.centerImageSizeRatio); validateFontSize(args.captionFontSize); const params = buildQRCodeParams(text, { format: args.format as string, size: args.size as number, margin: args.margin as number, dark: args.dark as string, light: args.light as string, ecLevel: args.ecLevel as string, centerImageUrl: args.centerImageUrl as string, centerImageSizeRatio: args.centerImageSizeRatio as number, caption: args.caption as string, captionFontFamily: args.captionFontFamily as string, captionFontSize: args.captionFontSize as number, captionFontColor: args.captionFontColor as string, }); const chartUrl = buildQRCodeUrl(text); const result: any = { content: [ { type: "text", text: "Below is the QR code URL:", }, { type: "text", text: chartUrl, }, ], metadata: { chartType: "qrcode", generatedAt: new Date().toISOString(), chartUrl: chartUrl, }, }; try { const pngData = await fetchQRCodeContent(params, "png"); const pngBase64 = Buffer.from(pngData).toString("base64"); result.content.push( { type: "text", text: "Below is the PNG image:", }, { type: "image", data: pngBase64, mimeType: "image/png", } ); result.metadata.pngBase64 = pngBase64; } catch (error) { result.content.unshift({ type: "text", text: "⚠️ Failed to fetch QR code image", }); result.content.push({ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}`, }); result.metadata.error = error instanceof Error ? error.message : String(error); } if (action === "get_url") { return result; } const format = (args.format as string) || "png"; const outputPath = getDownloadPath( args.outputPath as string | undefined, format ); try { const dir = path.dirname(outputPath); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } const data = await fetchQRCodeContent(params, format); if (format === "svg") { fs.writeFileSync(outputPath, data, "utf8"); } else { fs.writeFileSync(outputPath, data); } result.metadata.savedPath = outputPath; result.content.push({ type: "text", text: "Below is the saved file path:", }); result.content.push({ type: "text", text: outputPath, }); return result; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to save QR code: ${ error instanceof Error ? error.message : String(error) }` ); } }
  • Tool schema defining name, description, and detailed inputSchema with parameters for QR code customization including action, text, format, size, colors, error correction, center image, and caption options.
    export const CREATE_QR_CODE_TOOL: Tool = { name: "create-qr-code", description: "Create QR codes using QuickChart - get QR code image URL or save QR code image to file", inputSchema: { type: "object", properties: { action: { type: "string", enum: ["get_url", "save_file"], description: "Whether to get QR code URL or save as file", }, outputPath: { type: "string", description: "Path where to save the file (only used with action=save_file)", }, text: { type: "string", description: "Content of the QR code (URL, text, etc.)", }, format: { type: "string", enum: ["png", "svg", "base64"], description: "Output format (default: png)", }, size: { type: "integer", description: "Image dimensions in pixels (default: 150)", }, margin: { type: "integer", description: "Whitespace around QR image (default: 4)", }, dark: { type: "string", description: "Hex color for QR grid cells (default: black)", }, light: { type: "string", description: "Hex color for background (default: white, use '0000' for transparent)", }, ecLevel: { type: "string", enum: ["L", "M", "Q", "H"], description: "Error correction level (default: M)", }, centerImageUrl: { type: "string", description: "URL of center image (must be URL-encoded)", }, centerImageSizeRatio: { type: "number", minimum: 0, maximum: 1, description: "Center image size ratio (0.0-1.0, default: 0.3)", }, caption: { type: "string", description: "Text below QR code", }, captionFontFamily: { type: "string", description: "Caption font family (default: 'sans-serif')", }, captionFontSize: { type: "integer", description: "Caption font size (default: 10)", }, captionFontColor: { type: "string", description: "Caption text color (default: black)", }, }, required: ["action", "text"], }, };
  • Registers the handler function for the 'create-qr-code' tool in the central tool handlers mapping.
    "create-qr-code": { handler: handleQRCodeTool, toolName: ToolNames.QRCODE },
  • Registers the tool schema in the ALL_TOOLS array, which is filtered for enabled tools to create the exported TOOLS array.
    { tool: CREATE_QR_CODE_TOOL, name: ToolNames.QRCODE },
  • Documentation and usage examples for the create-qr-code tool, served by the help tool.
    "create-qr-code": { name: "create-qr-code", description: "Create QR codes with extensive customization options - get QR code image URL or save QR code image to file", documentation: "https://quickchart.io/documentation/qr-codes/", additionalResources: { apiReference: "https://quickchart.io/documentation/qr-codes/", qrCodeBestPractices: "https://blog.qr4.nl/post/qr-code-best-practices/", }, whatYouCanCreate: [ "Website Links: Direct links to websites, landing pages, and online content", "Contact Information: vCard data for easy contact sharing", "WiFi Access: Network credentials for guest access", "Event Details: Calendar events, meeting information, and RSVP links", "App Downloads: Direct links to app stores and download pages", "Payment Information: Payment links and cryptocurrency addresses", "Location Sharing: GPS coordinates and map links", "Social Media: Profile links and social media connections", "Product Information: Item details, specifications, and reviews", "Marketing Campaigns: Promotional links and special offers", "Business Cards: Digital business card information", "Menu Access: Restaurant menus and ordering systems", "Document Sharing: Links to PDFs, forms, and downloads", "Survey Links: Research questionnaires and feedback forms", ], promptExamples: [ 'Marketing Campaigns: "Create QR codes linking to product pages"', 'Event Management: "Generate QR codes for ticket verification"', 'Contact Sharing: "Create QR codes containing business card information"', 'WiFi Access: "Generate QR codes for guest network access"', ], usageExample: { action: "save_file", text: "https://example.com", size: 300, centerImageUrl: "https://example.com/logo.png", centerImageSizeRatio: 0.2, caption: "Visit our website", }, },

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/TakanariShimbo/quickchart-mcp-server'

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