read-xmp
Extract XMP metadata from images to access embedded information, with support for extended XMP segments when needed.
Instructions
Read XMP metadata from an image with option for extended XMP segments
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image | Yes | ||
| extended | No |
Implementation Reference
- src/tools/index.ts:121-136 (handler)The core handler function that implements the logic for the 'read-xmp' tool. It destructures the input arguments, loads the image into a buffer, builds XMP-specific parsing options, extracts metadata using the exifr library, checks for XMP presence, and returns a standardized success or error response.async (args, extra) => { try { const { image, extended } = args; const buf = await loadImage(image); const opts = buildXmpOptions(extended); const meta = await exifr.parse(buf, opts); if (!meta || !meta.xmp) { return createErrorResponse('No XMP metadata found in image'); } return createSuccessResponse(meta); } catch (error) { return createErrorResponse(`Error reading XMP data: ${error instanceof Error ? error.message : String(error)}`); } }
- src/tools/index.ts:114-138 (registration)Registers the 'read-xmp' tool with the MCP server instance using server.tool(), providing the tool name, description, input schema, and handler function. Also stores a reference in the tools object for testing purposes.// Tool 3: read-xmp - reads XMP data const readXmpTool = server.tool('read-xmp', "Read XMP metadata from an image with option for extended XMP segments", { image: ImageSourceSchema, extended: z.boolean().optional() }, async (args, extra) => { try { const { image, extended } = args; const buf = await loadImage(image); const opts = buildXmpOptions(extended); const meta = await exifr.parse(buf, opts); if (!meta || !meta.xmp) { return createErrorResponse('No XMP metadata found in image'); } return createSuccessResponse(meta); } catch (error) { return createErrorResponse(`Error reading XMP data: ${error instanceof Error ? error.message : String(error)}`); } } ); tools['read-xmp'] = readXmpTool;
- src/tools/index.ts:54-60 (schema)Zod schema defining the standardized ImageSource input parameter used by the 'read-xmp' tool (and other image tools). Supports path, URL, base64, or buffer inputs.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/segments.ts:92-107 (helper)Helper function that creates exifr parsing options specifically tailored for XMP metadata extraction, enabling only XMP parsing and optionally multi-segment support for extended XMP./** * Creates options object for the read-xmp tool * @param extended Whether to read extended XMP segments * @returns Options object configured for XMP reading */ export function buildXmpOptions(extended?: boolean): ExifrOptions { return { tiff: false, xmp: true, icc: false, iptc: false, jfif: false, ihdr: false, multiSegment: extended ?? false }; }