Skip to main content
Glama
ericyangpan

Scan QRCode MCP Server

by ericyangpan

decode_qrcode_data_url

Extract text from QR codes encoded as base64 data URLs. This tool processes image data URLs to decode and retrieve the embedded information.

Instructions

Decode a QR code from a data URL (data:;base64,...)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageDataUrlYesImage data URL (base64) of the QR image.

Implementation Reference

  • Specific handler for decoding QR code from data URL: parses the base64 data and calls buffer decoder.
    export async function decodeQrFromDataUrl(dataUrl: string): Promise<DecodeResult> { const { buffer } = parseBase64DataUrl(dataUrl); return decodeQrFromBuffer(buffer); }
  • Core implementation: loads image buffer with Jimp, prepares data for jsQR, detects and extracts QR text.
    export async function decodeQrFromBuffer(buffer: Buffer): Promise<DecodeResult> { const image = await Jimp.read(buffer); const { data, width, height } = image.bitmap; // Jimp gives a Node Buffer; jsQR expects a Uint8ClampedArray in RGBA order (same layout as Canvas ImageData). const clamped = new Uint8ClampedArray(data.buffer, data.byteOffset, data.byteLength); const qr = ( jsQR as unknown as ( data: Uint8ClampedArray, width: number, height: number, ) => { data: string } | null )(clamped, width, height); if (!qr) { throw new Error('No QR code detected in image'); } return { text: qr.data }; }
  • Supporting utility to parse data URL and extract the base64 buffer.
    export function parseBase64DataUrl(dataUrl: string): { mime: string; buffer: Buffer } { const match = /^data:([^;]+);base64,(.+)$/i.exec(dataUrl); if (!match) { throw new Error('Invalid data URL. Expected format: data:<mime>;base64,<data>'); } const [, mime, data] = match; const buffer = Buffer.from(data, 'base64'); return { mime, buffer }; }
  • src/server.ts:29-43 (registration)
    Tool registration in ListToolsResult: defines name, description, and input schema.
    { name: 'decode_qrcode_data_url', description: 'Decode a QR code from a data URL (data:<mime>;base64,...)', inputSchema: { type: 'object', required: ['imageDataUrl'], properties: { imageDataUrl: { type: 'string', description: 'Image data URL (base64) of the QR image.', }, }, additionalProperties: false, }, },
  • MCP server CallToolRequest handler: input validation and invocation of service implementation.
    if (name === 'decode_qrcode_data_url') { if (!args.imageDataUrl || typeof args.imageDataUrl !== 'string') { throw new Error('Missing required argument: imageDataUrl'); } const result = await decodeQr({ imageDataUrl: args.imageDataUrl }); return { content: [{ type: 'text', text: result.text }] }; }

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

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