Skip to main content
Glama

generateQRCode

Convert input data into QR codes in terminal, SVG, or base64 formats with customizable error correction levels using a dedicated MCP server tool.

Instructions

Generate a QR code from input data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYesData to encode in QR code
errorCorrectionLevelNoError correction levelM
typeNoOutput type (terminal, svg, or base64)terminal

Implementation Reference

  • The handler function that executes the generateQRCode tool logic, supporting terminal, SVG, or base64 output formats using qrcode and qrcode-terminal libraries.
    handler: async ({
      data,
      type = 'terminal',
      errorCorrectionLevel = 'M'
    }: {
      data: string;
      type?: 'terminal' | 'svg' | 'base64';
      errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H'
    }) => {
      try {
        let result: string;
        const options = {
          errorCorrectionLevel,
          margin: 1,
          width: type === 'svg' ? 200 : undefined
        };
    
        switch (type) {
          case 'terminal':
            // Use qrcode-terminal for better terminal output
            result = await generateTerminalQR(data, { small: true });
            break;
          case 'svg':
            result = await QRCode.toString(data, { ...options, type: 'svg' });
            break;
          case 'base64':
            const buffer = await QRCode.toBuffer(data, { ...options, type: 'png' });
            result = `data:image/png;base64,${buffer.toString('base64')}`;
            break;
          default:
            throw new Error(`Unsupported output type: ${type}`);
        }
    
        return {
          content: [{
            type: 'text',
            text: result
          }]
        };
      } catch (error) {
        throw new Error(`QR code generation failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • Input schema for the generateQRCode tool defining required 'data' and optional 'type' and 'errorCorrectionLevel' parameters.
    inputSchema: {
      type: 'object',
      properties: {
        data: {
          type: 'string',
          description: 'Data to encode in QR code'
        },
        type: {
          type: 'string',
          description: 'Output type (terminal, svg, or base64)',
          enum: ['terminal', 'svg', 'base64'],
          default: 'terminal'
        },
        errorCorrectionLevel: {
          type: 'string',
          description: 'Error correction level',
          enum: ['L', 'M', 'Q', 'H'],
          default: 'M'
        }
      },
      required: ['data']
    },
  • src/index.ts:27-33 (registration)
    Registration of generatorTools (including generateQRCode) into the allTools object, which is used by the MCP server to list and call tools.
    const allTools: ToolKit = {
      ...encodingTools,
      ...geoTools,
      ...generatorTools,
      ...dateTimeTools,
      ...securityTools
    };
  • src/index.ts:6-6 (registration)
    Import of generatorTools containing the generateQRCode tool definition.
    import { generatorTools } from './tools/generator.js';
  • Helper function to promisify qrcode-terminal.generate for use in the terminal QR code generation.
    const generateTerminalQR = promisify((text: string, opts: any, cb: (error: Error | null, result: string) => void) => {
      qrcodeTerminal.generate(text, opts, (result: string) => cb(null, result));
    });
Install Server

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/MissionSquad/mcp-helper-tools'

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