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
| Name | Required | Description | Default |
|---|---|---|---|
| imageDataUrl | Yes | Image data URL (base64) of the QR image. |
Implementation Reference
- src/services/qrcode-service.ts:38-41 (handler)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); }
- src/services/qrcode-service.ts:16-33 (handler)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 }; }
- src/utils/data-url.ts:6-14 (helper)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, }, },
- src/server.ts:64-70 (handler)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 }] }; }