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
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Whether to get QR code URL or save as file | |
| outputPath | No | Path where to save the file (only used with action=save_file) | |
| text | Yes | Content of the QR code (URL, text, etc.) | |
| format | No | Output format (default: png) | |
| size | No | Image dimensions in pixels (default: 150) | |
| margin | No | Whitespace around QR image (default: 4) | |
| dark | No | Hex color for QR grid cells (default: black) | |
| light | No | Hex color for background (default: white, use '0000' for transparent) | |
| ecLevel | No | Error correction level (default: M) | |
| centerImageUrl | No | URL of center image (must be URL-encoded) | |
| centerImageSizeRatio | No | Center image size ratio (0.0-1.0, default: 0.3) | |
| caption | No | Text below QR code | |
| captionFontFamily | No | Caption font family (default: 'sans-serif') | |
| captionFontSize | No | Caption font size (default: 10) | |
| captionFontColor | No | Caption text color (default: black) |
Implementation Reference
- src/tools/qrcode.ts:292-410 (handler)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) }` ); } }
- src/tools/qrcode.ts:11-88 (schema)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"], }, };
- src/tools/index.ts:89-89 (registration)Registers the handler function for the 'create-qr-code' tool in the central tool handlers mapping."create-qr-code": { handler: handleQRCodeTool, toolName: ToolNames.QRCODE },
- src/tools/index.ts:44-44 (registration)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 },
- src/tools/help.ts:358-397 (helper)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", }, },