Skip to main content
Glama

qrcode

Create customizable QR codes by inputting text, adjusting size, colors, error correction, and margin settings for versatile and tailored use cases.

Instructions

Generate a QR code image

Input Schema

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

Implementation Reference

  • The handler function for the 'qrcode' tool. It receives input parameters, calls generateQRCode with appropriate options, extracts the base64 data from the data URL, and returns it as image content in the MCP format.
    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(), including 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" }], }); } );
  • Supporting function that generates the QR code data URL using the 'qrcode' library, merges default and provided options, handles errors.
    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 the generateQRCode helper function.
    interface QRCodeOptions { width?: number; // 二维码宽度 margin?: number; // 二维码边距 color?: { dark?: string; // 二维码颜色 light?: string; // 背景颜色 }; errorCorrectionLevel?: "L" | "M" | "Q" | "H"; // 错误纠正级别 }

Other Tools

Related 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