read-exif
Extract and filter EXIF metadata from images using various input formats, enabling precise analysis of image details without external dependencies.
Instructions
Read EXIF data from an image with optional tag filtering
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image | Yes | ||
| pick | No |
Implementation Reference
- src/tools/index.ts:95-110 (handler)The core handler function for the 'read-exif' tool. It loads the image into a buffer using loadImage, builds EXIF-specific parsing options using buildExifOptions based on the optional 'pick' tags, parses the EXIF metadata with exifr.parse, checks if metadata was found, and returns a standardized success response with the EXIF data or an error response.async (args, extra) => { try { const { image, pick } = args; const buf = await loadImage(image); const opts = buildExifOptions(pick); const meta = await exifr.parse(buf, opts); if (!meta || Object.keys(meta).length === 0) { return createErrorResponse('No EXIF metadata found in image'); } return createSuccessResponse(meta); } catch (error) { return createErrorResponse(`Error reading EXIF data: ${error instanceof Error ? error.message : String(error)}`); } }
- src/tools/index.ts:54-60 (schema)Zod schema definition for ImageSource used as the 'image' input parameter in the read-exif tool schema.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/tools/index.ts:91-94 (schema)Input schema for the read-exif tool, including 'image' (ImageSourceSchema) and optional 'pick' array of EXIF tags to filter.{ image: ImageSourceSchema, pick: z.array(z.string()).optional() },
- src/tools/index.ts:89-112 (registration)Registration of the 'read-exif' tool using server.tool(), defining its name, description, input schema, and handler function. Also assigns to tools object for reference.const readExifTool = server.tool('read-exif', "Read EXIF data from an image with optional tag filtering", { image: ImageSourceSchema, pick: z.array(z.string()).optional() }, async (args, extra) => { try { const { image, pick } = args; const buf = await loadImage(image); const opts = buildExifOptions(pick); const meta = await exifr.parse(buf, opts); if (!meta || Object.keys(meta).length === 0) { return createErrorResponse('No EXIF metadata found in image'); } return createSuccessResponse(meta); } catch (error) { return createErrorResponse(`Error reading EXIF data: ${error instanceof Error ? error.message : String(error)}`); } } ); tools['read-exif'] = readExifTool;
- src/tools/segments.ts:75-90 (helper)buildExifOptions helper function specifically for the read-exif tool, creates exifr options object enabling TIFF (for EXIF) and optionally filtering specific tags with 'pick'./** * Creates options object for the read-exif tool * @param pick Optional array of specific EXIF tags to pick * @returns Options object configured for EXIF reading */ export function buildExifOptions(pick?: string[]): ExifrOptions { return { tiff: true, xmp: false, icc: false, iptc: false, jfif: false, ihdr: false, ...(pick ? { pick } : {}) }; }