thumbnail
Extract embedded thumbnails from images as base64 data or URLs using the exif-mcp server. Supports input as paths, URLs, base64, or buffers for efficient metadata retrieval.
Instructions
Extract embedded thumbnail from image as base64 data or URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image | Yes | ||
| url | No |
Implementation Reference
- src/tools/index.ts:250-275 (handler)The handler function that executes the thumbnail tool logic: loads image buffer, extracts thumbnail with exifr.thumbnail, converts to base64 data URL or base64.async (args, extra) => { try { const { image, url } = args; const buf = await loadImage(image); const thumbnail = await exifr.thumbnail(buf); if (!thumbnail) { return createErrorResponse('No thumbnail found in image'); } // Convert to base64 data URL by default if (!url) { const base64 = Buffer.from(thumbnail).toString('base64'); const mimeType = 'image/jpeg'; // Thumbnails are typically JPEG const dataUrl = `data:${mimeType};base64,${base64}`; return createSuccessResponse({ dataUrl }); } // For browsers, object URLs would be created, but we can't do that in Node // So we'll just return the base64 data const base64 = Buffer.from(thumbnail).toString('base64'); return createSuccessResponse({ base64 }); } catch (error) { return createErrorResponse(`Error extracting thumbnail: ${error instanceof Error ? error.message : String(error)}`); } }
- src/tools/index.ts:243-277 (registration)Registers the 'thumbnail' tool with the MCP server via server.tool and stores reference in tools object.// Tool 11: thumbnail - extracts embedded thumbnail const thumbnailTool = server.tool('thumbnail', "Extract embedded thumbnail from image as base64 data or URL", { image: ImageSourceSchema, url: z.boolean().optional() }, async (args, extra) => { try { const { image, url } = args; const buf = await loadImage(image); const thumbnail = await exifr.thumbnail(buf); if (!thumbnail) { return createErrorResponse('No thumbnail found in image'); } // Convert to base64 data URL by default if (!url) { const base64 = Buffer.from(thumbnail).toString('base64'); const mimeType = 'image/jpeg'; // Thumbnails are typically JPEG const dataUrl = `data:${mimeType};base64,${base64}`; return createSuccessResponse({ dataUrl }); } // For browsers, object URLs would be created, but we can't do that in Node // So we'll just return the base64 data const base64 = Buffer.from(thumbnail).toString('base64'); return createSuccessResponse({ base64 }); } catch (error) { return createErrorResponse(`Error extracting thumbnail: ${error instanceof Error ? error.message : String(error)}`); } } ); tools['thumbnail'] = thumbnailTool;
- src/tools/index.ts:54-60 (schema)ImageSourceSchema defining the 'image' input parameter used by the thumbnail tool (and others).const ImageSourceSchema = z.object({ kind: z.enum(['path', 'url', 'base64', 'buffer']), path: z.string().optional(), url: z.string().optional(), data: z.string().optional(), buffer: z.string().optional() });
- src/server.ts:19-20 (registration)Top-level call to registerTools which includes the thumbnail tool registration.// Register all tools registerTools(server);
- src/types/image.ts:56-65 (schema)ThumbnailSchema matching the thumbnail tool's input schema (defined but not directly used in tool registration).export const ThumbnailSchema = z.object({ image: z.object({ kind: z.enum(['path', 'url', 'base64', 'buffer']), path: z.string().optional(), url: z.string().optional(), data: z.string().optional(), buffer: z.string().optional() }), url: z.boolean().optional() });