Skip to main content
Glama

qrcode

Generate customizable QR code images from text input with adjustable size, colors, error correction, and margin settings.

Instructions

Generate a QR code image

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe input string to generate qrcode
sizeNoThe size of qrcode, default is 256
darkColorNoThe dark color of qrcode, default is #000000#000000
lightColorNoThe light color of qrcode, default is #ffffff#ffffff
errorCorrectionLevelNoThe error correction level of qrcode, default is MM
marginNoThe margin of qrcode, default is 4

Implementation Reference

  • The handler function for the 'qrcode' MCP tool. It receives input parameters, calls generateQRCode to produce a data URL, extracts the base64 part, and returns it as image content.
    async ({
      text,
      size,
      darkColor,
      lightColor,
      errorCorrectionLevel,
      margin,
    }) => {
      const qrcode = await generateQRCode(text, {
        width: size,
        color: {
          dark: darkColor,
          light: lightColor,
        },
        errorCorrectionLevel,
        margin,
      });
    
      const base64Image = qrcode.split(",")[1];
    
      return Promise.resolve({
        content: [{ type: "image", data: base64Image, mimeType: "image/png" }],
      });
    }
  • Zod schema defining the input parameters for the 'qrcode' tool, including text, size, colors, error correction level, and margin with defaults.
    {
      text: z.string().describe("The input string to generate qrcode"),
      size: z
        .number()
        .describe("The size of qrcode, default is 256")
        .default(256),
      darkColor: z
        .string()
        .describe("The dark color of qrcode, default is #000000")
        .default("#000000"),
      lightColor: z
        .string()
        .describe("The light color of qrcode, default is #ffffff")
        .default("#ffffff"),
      errorCorrectionLevel: z
        .enum(["L", "M", "Q", "H"])
        .describe("The error correction level of qrcode, default is M")
        .default("M"),
      margin: z
        .number()
        .describe("The margin of qrcode, default is 4")
        .default(4),
    },
  • src/index.ts:29-79 (registration)
    Registration of the 'qrcode' tool on the MCP server using server.tool(), specifying name, description, input schema, and handler function.
    server.tool(
      "qrcode",
      "Generate a QR code image",
      {
        text: z.string().describe("The input string to generate qrcode"),
        size: z
          .number()
          .describe("The size of qrcode, default is 256")
          .default(256),
        darkColor: z
          .string()
          .describe("The dark color of qrcode, default is #000000")
          .default("#000000"),
        lightColor: z
          .string()
          .describe("The light color of qrcode, default is #ffffff")
          .default("#ffffff"),
        errorCorrectionLevel: z
          .enum(["L", "M", "Q", "H"])
          .describe("The error correction level of qrcode, default is M")
          .default("M"),
        margin: z
          .number()
          .describe("The margin of qrcode, default is 4")
          .default(4),
      },
      async ({
        text,
        size,
        darkColor,
        lightColor,
        errorCorrectionLevel,
        margin,
      }) => {
        const qrcode = await generateQRCode(text, {
          width: size,
          color: {
            dark: darkColor,
            light: lightColor,
          },
          errorCorrectionLevel,
          margin,
        });
    
        const base64Image = qrcode.split(",")[1];
    
        return Promise.resolve({
          content: [{ type: "image", data: base64Image, mimeType: "image/png" }],
        });
      }
    );
  • Core helper function that generates QR code data URL using the 'qrcode' library, merging default and provided options.
    async function generateQRCode(
      text: string,
      options: QRCodeOptions = {}
    ): Promise<string> {
      try {
        const defaultOptions: QRCodeOptions = {
          width: 256,
          margin: 4,
          color: {
            dark: "#000000",
            light: "#ffffff",
          },
          errorCorrectionLevel: "M",
        };
    
        // 合并默认选项和用户选项
        const qrOptions = { ...defaultOptions, ...options };
    
        // 生成二维码(返回 base64 格式)
        const qrCodeImage = await QRCode.toDataURL(text, qrOptions);
        return qrCodeImage;
      } catch (error) {
        console.error("generateQRCode error:", error);
        throw error;
      }
    }
  • TypeScript interface defining options for QR code generation, used internally by generateQRCode.
    interface QRCodeOptions {
      width?: number; // 二维码宽度
      margin?: number; // 二维码边距
      color?: {
        dark?: string; // 二维码颜色
        light?: string; // 背景颜色
      };
      errorCorrectionLevel?: "L" | "M" | "Q" | "H"; // 错误纠正级别
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. 'Generate a QR code image' implies a creation operation but doesn't disclose behavioral traits like whether this is a read-only generation, if it requires external resources, what happens with invalid inputs, or the format of the returned image. For a tool with 6 parameters and no annotation coverage, this is inadequate.

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 a single, efficient sentence with zero waste. It's appropriately sized for a straightforward tool and front-loads the core purpose without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (6 parameters, no output schema, no annotations), the description is minimally adequate but incomplete. It states what the tool does but lacks context about the generated output (e.g., image format, return type), error handling, or performance considerations, leaving gaps for the agent.

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%, with all parameters well-documented in the schema itself. The description adds no additional parameter information beyond implying 'text' is needed for generation. This meets the baseline of 3 since the schema does the heavy lifting, but doesn't provide extra context like typical text lengths or color format expectations.

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 'Generate a QR code image' clearly states the verb 'Generate' and resource 'QR code image', making the purpose immediately understandable. However, it lacks specific differentiation from potential siblings (though none exist in this context), and doesn't specify output format or medium, keeping it from a perfect score.

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, prerequisites, or typical use cases. With no sibling tools, this is less critical, but still leaves the agent without context about appropriate scenarios for QR code generation.

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/1595901624/qrcode-mcp'

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