Skip to main content
Glama

read-metadata

Extract and analyze metadata from images including EXIF, GPS, XMP, ICC, IPTC, JFIF, and IHDR segments for offline image analysis and data extraction.

Instructions

Read all or specified metadata segments from an image

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageYes
segmentsNo

Implementation Reference

  • The core handler function for the 'read-metadata' tool. Loads image buffer using loadImage, builds exifr options from segments using buildOptions, parses metadata with exifr.parse, returns success response with metadata JSON or error.
    async (args, extra) => {
      try {
        const { image, segments } = args;
        const buf = await loadImage(image);
        const opts = buildOptions(segments as any);
        const meta = await exifr.parse(buf, opts);
        
        if (!meta || Object.keys(meta).length === 0) {
          return createErrorResponse('No metadata found in image');
        }
        
        return createSuccessResponse(meta);
      } catch (error) {
        return createErrorResponse(`Error reading metadata: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Input schema definition: ImageSourceSchema (zod object for image source kinds) and segments (optional array of specific metadata segments enum). Used in server.tool call.
    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()
    });
    
    // Tool 1: read-metadata - reads all or specified metadata segments from an image
    const readMetadataTool = server.tool('read-metadata', 
      "Read all or specified metadata segments from an image",
      {
        image: ImageSourceSchema,
        segments: z.array(z.enum(['EXIF', 'GPS', 'XMP', 'ICC', 'IPTC', 'JFIF', 'IHDR'])).optional()
      },
  • Registration of the 'read-metadata' tool via server.tool() with name, description, input schema, and handler function. Reference stored in tools object.
    const readMetadataTool = server.tool('read-metadata', 
      "Read all or specified metadata segments from an image",
      {
        image: ImageSourceSchema,
        segments: z.array(z.enum(['EXIF', 'GPS', 'XMP', 'ICC', 'IPTC', 'JFIF', 'IHDR'])).optional()
      },
      async (args, extra) => {
        try {
          const { image, segments } = args;
          const buf = await loadImage(image);
          const opts = buildOptions(segments as any);
          const meta = await exifr.parse(buf, opts);
          
          if (!meta || Object.keys(meta).length === 0) {
            return createErrorResponse('No metadata found in image');
          }
          
          return createSuccessResponse(meta);
        } catch (error) {
          return createErrorResponse(`Error reading metadata: ${error instanceof Error ? error.message : String(error)}`);
        }
      }
    );
    tools['read-metadata'] = readMetadataTool;
  • loadImage helper: asynchronously loads image data from path, URL (http/file), base64 data URI or raw, or base64 buffer into Buffer/Uint8Array. Handles errors and size limits.
    export async function loadImage(src: ImageSourceType): Promise<Buffer | Uint8Array> {
      try {
        switch (src.kind) {
          case 'path':
            if (!src.path) {
              throw new Error('Path is required for kind="path"');
            }
            return await fs.promises.readFile(src.path);
          
          case 'url':
            if (!src.url) {
              throw new Error('URL is required for kind="url"');
            }
            
            if (src.url.startsWith('file://')) {
              // Handle file:// URLs by converting to filesystem path
              const filePath = fileURLToPath(src.url);
              return await fs.promises.readFile(filePath);
            } else {
              // Handle HTTP/HTTPS URLs
              const response = await fetch(src.url);
              if (!response.ok) {
                throw new Error(`Failed to fetch URL: ${response.status} ${response.statusText}`);
              }
              return new Uint8Array(await response.arrayBuffer());
            }
          
          case 'base64':
            if (!src.data) {
              throw new Error('Data is required for kind="base64"');
            }
            
            // Check for potential oversized base64 string (>30MB)
            if (src.data.length > 40000000) { // ~30MB in base64
              throw new Error('PayloadTooLarge: Base64 data exceeds 30MB limit');
            }
            
            // Handle data URIs or raw base64
            if (src.data.startsWith('data:')) {
              const base64Data = src.data.split(',')[1];
              return Buffer.from(base64Data, 'base64');
            } else {
              return Buffer.from(src.data, 'base64');
            }
          
          case 'buffer':
            if (!src.buffer) {
              throw new Error('Buffer is required for kind="buffer"');
            }
            return Buffer.from(src.buffer, 'base64');
          
          default:
            // This should never happen due to type constraints, but TypeScript needs it
            throw new Error(`Unsupported image source kind: ${(src as any).kind}`);
        }
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Failed to load image: ${error.message}`);
        }
        throw error;
      }
    }
  • buildOptions helper: creates exifr.parse options enabling all segments by default or only specified ones (EXIF/GPS via 'tiff', XMP, ICC, IPTC, JFIF, IHDR).
    export function buildOptions(segments?: SegmentType[]): ExifrOptions {
      // Default options - include everything if segments not specified
      if (!segments || segments.length === 0) {
        return {
          tiff: true,    // Includes EXIF and GPS
          xmp: true,
          icc: true,
          iptc: true,
          jfif: true,
          ihdr: true,
        };
      }
    
      // Start with all segments disabled
      const options: ExifrOptions = {
        tiff: false,
        xmp: false,
        icc: false,
        iptc: false,
        jfif: false,
        ihdr: false,
      };
    
      // Enable requested segments
      segments.forEach(segment => {
        switch (segment) {
          case 'EXIF':
          case 'GPS':
            options.tiff = true;
            break;
          case 'XMP':
            options.xmp = true;
            break;
          case 'ICC':
            options.icc = true;
            break;
          case 'IPTC':
            options.iptc = true;
            break;
          case 'JFIF':
            options.jfif = true;
            break;
          case 'IHDR':
            options.ihdr = true;
            break;
        }
      });
    
      return options;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states the tool reads metadata, implying a read-only operation, but doesn't disclose behavioral traits like error handling, performance, or output format. This is a significant gap for a tool with complex input schema and no output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. Every word earns its place, with no redundancy or unnecessary details, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (2 parameters, nested objects, no annotations, no output schema), the description is incomplete. It doesn't explain the return values, error cases, or how to interpret the 'image' object, leaving the agent with insufficient context for reliable use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It mentions 'all or specified metadata segments,' which hints at the 'segments' parameter, but doesn't explain the 'image' object or its properties. The description adds minimal value beyond the schema, failing to fully address the coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Read') and resource ('metadata segments from an image'), specifying it can read 'all or specified' segments. It distinguishes from siblings like 'read-exif' or 'read-icc' by being more general, though it doesn't explicitly contrast them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus the more specific sibling tools (e.g., read-exif, read-icc). The description implies it can read multiple segments, but doesn't advise on alternatives or prerequisites, leaving the agent to infer usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/stass/exif-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server