Skip to main content
Glama

create-barcode

Generate barcodes and QR codes by encoding data into customizable images, then retrieve URLs or save files for integration into documents and systems.

Instructions

Create barcodes using QuickChart - get barcode image URL or save barcode image to file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesWhether to get barcode URL or save as file
outputPathNoPath where to save the file (only used with action=save_file)
typeYesBarcode type (e.g., qr, code128, ean13, datamatrix, upca, etc.)
textYesData to encode in the barcode
widthNoBarcode width
heightNoBarcode height
scaleNoScale factor
includeTextNoInclude human-readable text below barcode
rotateNoRotation: N=Normal, R=Right 90°, L=Left 90°, I=Inverted 180°

Implementation Reference

  • Main tool handler that validates inputs, builds QuickChart URL, fetches barcode image as PNG, embeds base64 image in response, generates URL, and optionally saves to file using getDownloadPath.
    export async function handleBarcodeTool(args: any): Promise<any> {
      const type = args.type as string;
      const text = args.text as string;
      const action = args.action as string;
      
      validateBarcodeType(type);
      validateText(text);
      validateAction(action);
      validateOutputPath(args.outputPath, action);
      validateDimensions(args.width, args.height);
      validateScale(args.scale);
      validateRotation(args.rotate);
    
      const params = buildBarcodeParams(type, text, {
        width: args.width as number,
        height: args.height as number,
        scale: args.scale as number,
        includeText: args.includeText as boolean,
        rotate: args.rotate as string,
      });
      const chartUrl = buildBarcodeUrl(type, text);
    
      const result: any = {
        content: [
          {
            type: "text",
            text: "Below is the barcode URL:",
          },
          {
            type: "text",
            text: chartUrl,
          },
        ],
        metadata: {
          chartType: "barcode",
          generatedAt: new Date().toISOString(),
          chartUrl: chartUrl,
        },
      };
    
      try {
        const pngData = await fetchBarcodeContent(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 barcode 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 = "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 fetchBarcodeContent(params, format);
        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 barcode: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
      }
    }
  • Input schema and metadata definition for the create-barcode tool, including required parameters (action, type, text) and optional formatting options.
    export const CREATE_BARCODE_TOOL: Tool = {
      name: "create-barcode",
      description:
        "Create barcodes using QuickChart - get barcode image URL or save barcode image to file",
      inputSchema: {
        type: "object",
        properties: {
          action: {
            type: "string",
            enum: ["get_url", "save_file"],
            description: "Whether to get barcode URL or save as file",
          },
          outputPath: {
            type: "string",
            description:
              "Path where to save the file (only used with action=save_file)",
          },
          type: {
            type: "string",
            description:
              "Barcode type (e.g., qr, code128, ean13, datamatrix, upca, etc.)",
          },
          text: {
            type: "string",
            description: "Data to encode in the barcode",
          },
          width: {
            type: "integer",
            description: "Barcode width",
          },
          height: {
            type: "integer",
            description: "Barcode height",
          },
          scale: {
            type: "integer",
            description: "Scale factor",
          },
          includeText: {
            type: "boolean",
            description: "Include human-readable text below barcode",
          },
          rotate: {
            type: "string",
            enum: ["N", "R", "L", "I"],
            description:
              "Rotation: N=Normal, R=Right 90°, L=Left 90°, I=Inverted 180°",
          },
        },
        required: ["action", "type", "text"],
      },
    };
  • Maps the tool name 'create-barcode' to its handler function handleBarcodeTool and associates it with ToolNames.BARCODE in the ALL_TOOL_HANDLERS object.
    "create-barcode": { handler: handleBarcodeTool, toolName: ToolNames.BARCODE },
  • Registers the CREATE_BARCODE_TOOL schema in the ALL_TOOLS array with its ToolNames.BARCODE identifier.
    { tool: CREATE_BARCODE_TOOL, name: ToolNames.BARCODE },
  • Documentation and usage examples for the create-barcode tool provided in the help tool data.
    "create-barcode": {
      name: "create-barcode",
      description:
        "Generate barcodes and QR codes - get barcode image URL or save barcode image to file",
      documentation: "https://quickchart.io/documentation/barcode-api/",
      additionalResources: {
        apiReference: "https://quickchart.io/documentation/barcode-api/",
        supportedFormats: "https://github.com/bwipp/postscriptbarcode/wiki",
      },
      supportedBarcodeTypes: [
        "QR Code: High-density 2D barcode for URLs, text, and data",
        "Code 128: Versatile 1D barcode for alphanumeric content",
        "EAN-13/UPC-A: Standard retail product identification",
        "Data Matrix: Compact 2D barcode for small items",
        "PDF417: High-capacity 2D barcode for documents",
        "Aztec: Compact 2D barcode with built-in error correction",
      ],
      whatYouCanCreate: [
        "Product Management: UPC-A and EAN-13 codes for retail products",
        "Inventory Management: Code 128 barcodes for warehouse tracking",
        "Shipping Labels: Generate tracking codes for logistics",
        "Document Encoding: PDF417 codes for storing large amounts of data",
        "Asset Tracking: Data Matrix codes for equipment and tools",
        "Mobile Applications: QR codes for app downloads and links",
        "Contact Information: QR codes containing vCard data",
        "Event Tickets: Secure barcodes for entry validation",
        "Payment Processing: QR codes for mobile payments",
        "Location Sharing: QR codes with GPS coordinates",
        "WiFi Access: QR codes for network credentials",
        "Promotional Campaigns: QR codes linking to special offers",
      ],
      promptExamples: [
        'Inventory Management: "Generate product barcodes for warehouse system"',
        'Retail Operations: "Create UPC codes for new product lines"',
        'Asset Tracking: "Generate Code128 barcodes for equipment tracking"',
      ],
      usageExample: {
        action: "get_url",
        type: "code128",
        text: "ABC123456789",
        width: 300,
        height: 100,
      },
    },
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 two action outcomes (URL or file save) but doesn't describe what the URL format looks like, file format (likely PNG/JPEG), error conditions, rate limits, authentication needs, or whether the operation has side effects. For a tool with 9 parameters and no annotation coverage, this is insufficient behavioral context.

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 perfectly concise - a single sentence that front-loads the core purpose and immediately specifies the two action options. Every word earns its place with zero redundancy or unnecessary elaboration.

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 9 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (URL string? file path? success confirmation?), doesn't mention error handling, and provides no context about the QuickChart service (rate limits, supported formats, etc.). The description should do more given the complexity and lack of structured metadata.

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 9 parameters thoroughly. The description adds minimal value beyond the schema - it mentions the two action options but doesn't provide additional context about parameter interactions (e.g., that outputPath is only relevant for save_file). Baseline 3 is appropriate when the 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: 'Create barcodes using QuickChart' with two specific actions (get URL or save to file). It distinguishes itself from sibling tools like 'create-qr-code' by handling multiple barcode types, but doesn't explicitly contrast with all siblings. The verb 'create' is specific and the resource 'barcodes' 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-qr-code' (which appears to be a specialized sibling). It mentions the two action options but doesn't explain when to choose one over the other or when this tool is preferred over other visualization tools in the sibling list. No exclusions or prerequisites are mentioned.

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