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",
      },
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the two possible actions but doesn't describe what happens during each action (e.g., what the URL format is, where files are saved, error conditions, or performance characteristics). For a tool with 15 parameters and no annotation coverage, this is a significant gap in behavioral transparency.

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 extremely concise - a single sentence that efficiently communicates the core functionality. It's front-loaded with the main purpose and immediately specifies the two action options. Every word earns its place with zero wasted text or redundancy.

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?

For a tool with 15 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what the tool returns (URL format, file location, error responses), doesn't mention any constraints or limitations, and provides no guidance on parameter interactions. The single sentence description fails to address the complexity of this multi-parameter visualization tool.

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 all 15 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema. It mentions the two action options but doesn't provide additional context about parameter interactions or usage patterns. The baseline of 3 is appropriate when the schema does all the parameter documentation work.

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: 'Create QR codes using QuickChart' with specific actions 'get QR code image URL or save QR code image to file'. It distinguishes from sibling tools by specifying QR codes rather than other visualizations like charts or barcodes, though it doesn't explicitly differentiate from create-barcode. The verb 'create' is specific and the resource 'QR codes' is well-defined.

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 alternatives like create-barcode or other visualization tools. It mentions the two action options (get_url vs save_file) but doesn't explain when to choose one over the other or any prerequisites. There's no context about when QR codes are appropriate compared to other formats or tools.

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

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