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));
    });
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('Generate') but doesn't describe what the tool returns (e.g., image data, file, or display), any side effects, error handling, or performance considerations. This is a significant gap for a tool with no annotation coverage.

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 front-loaded with the core purpose and appropriately sized for the tool's complexity, making it easy to parse quickly.

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?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., QR code as text, SVG, or base64 string), which is critical for a generation tool. The schema covers inputs well, but the overall context for the agent to use the tool effectively is lacking.

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?

The input schema has 100% description coverage, with clear documentation for all three parameters (data, errorCorrectionLevel, type). The description adds no additional parameter semantics beyond what the schema provides, such as examples or usage tips. 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 'Generate a QR code from input data' clearly states the verb ('Generate') and resource ('QR code'), making the purpose immediately understandable. It distinguishes from siblings like encodeBase64 or hashData by specifying QR code generation, though it doesn't explicitly differentiate from potential similar tools not present in the sibling list.

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. It doesn't mention prerequisites, use cases, or comparisons with sibling tools like encodeBase64 for other encoding needs. The agent must infer usage solely from the tool name and description.

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

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