read-iptc
Extract IPTC metadata from images to access embedded information like captions, keywords, and copyright details for content management and analysis.
Instructions
Read IPTC metadata from an image
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image | Yes |
Implementation Reference
- src/tools/index.ts:142-146 (registration)segmentTools array that includes the configuration for the 'read-iptc' tool with segment 'IPTC', used in the subsequent registration loop.
{ name: 'read-icc', segment: 'ICC' }, { name: 'read-iptc', segment: 'IPTC' }, { name: 'read-jfif', segment: 'JFIF' }, { name: 'read-ihdr', segment: 'IHDR' } ] as const; - src/tools/index.ts:148-173 (registration)Dynamic registration loop that registers the 'read-iptc' tool using server.tool with description, schema, and shared handler function.
segmentTools.forEach(({ name, segment }) => { const segmentTool = server.tool(name, `Read ${segment} metadata from an image`, { image: ImageSourceSchema }, async (args, extra) => { try { const { image } = args; const buf = await loadImage(image); const opts = buildSegmentOptions(segment); const meta = await exifr.parse(buf, opts); const segmentKey = segment.toLowerCase(); if (!meta || !meta[segmentKey]) { return createErrorResponse(`No ${segment} metadata found in image`); } return createSuccessResponse(meta); } catch (error) { return createErrorResponse(`Error reading ${segment} data: ${error instanceof Error ? error.message : String(error)}`); } } ); tools[name] = segmentTool; }); - src/tools/index.ts:154-171 (handler)Handler function executed for read-iptc: loads image, builds IPTC-specific exifr options, parses and returns IPTC metadata or appropriate error.
async (args, extra) => { try { const { image } = args; const buf = await loadImage(image); const opts = buildSegmentOptions(segment); const meta = await exifr.parse(buf, opts); const segmentKey = segment.toLowerCase(); if (!meta || !meta[segmentKey]) { return createErrorResponse(`No ${segment} metadata found in image`); } return createSuccessResponse(meta); } catch (error) { return createErrorResponse(`Error reading ${segment} data: ${error instanceof Error ? error.message : String(error)}`); } } ); - src/tools/index.ts:54-60 (schema)Zod schema defining the input structure for the 'image' parameter required by the read-iptc tool.
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:114-128 (helper)Helper function buildSegmentOptions that configures exifr.parse options specifically for IPTC by setting iptc: true when segment='IPTC'.
export function buildSegmentOptions(segment: 'ICC' | 'IPTC' | 'JFIF' | 'IHDR'): ExifrOptions { const options: ExifrOptions = { tiff: false, xmp: false, icc: false, iptc: false, jfif: false, ihdr: false, }; const key = segment.toLowerCase() as 'icc' | 'iptc' | 'jfif' | 'ihdr'; options[key] = true; return options; }