Skip to main content
Glama

read-ihdr

Extract IHDR metadata from images to analyze dimensions, color depth, and compression details for image processing workflows.

Instructions

Read IHDR metadata from an image

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageYes

Implementation Reference

  • Shared handler function that implements the core logic for the 'read-ihdr' tool. Loads image buffer, configures exifr options for IHDR via buildSegmentOptions('IHDR'), parses metadata, extracts 'ihdr' field, and returns it or an error response.
    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)}`);
      }
    }
  • Zod schema for ImageSource input parameter used by the 'read-ihdr' tool to validate image source (path, url, base64, or buffer).
    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()
    });
  • Registration of the 'read-ihdr' tool via the segmentTools array and forEach loop using server.tool, including name, description, schema, and handler.
    const segmentTools = [
      { name: 'read-icc', segment: 'ICC' },
      { name: 'read-iptc', segment: 'IPTC' },
      { name: 'read-jfif', segment: 'JFIF' },
      { name: 'read-ihdr', segment: 'IHDR' }
    ] as const;
    
    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;
    });
  • Helper function buildSegmentOptions that creates exifr options specifically for IHDR by setting options.ihdr = true when segment='IHDR', used in the read-ihdr handler.
    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;
    }
  • Helper function to standardize successful MCP tool responses, used by read-ihdr handler.
    function createSuccessResponse(data: any) {
      return {
        content: [
          {
            type: "text" as const,
            text: typeof data === 'string' ? data : JSON.stringify(data, null, 2)
          }
        ]
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool reads metadata, implying a read-only operation, but doesn't disclose any behavioral traits such as error handling, performance characteristics, or what IHDR metadata entails (e.g., image dimensions, color type). This is a significant gap for a tool with zero annotation coverage.

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 directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 (1 parameter with nested objects, 0% schema coverage, no output schema, and no annotations), the description is incomplete. It doesn't explain the parameter, what IHDR metadata includes, or the return format, leaving critical gaps for effective tool use.

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

Parameters2/5

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

The schema description coverage is 0%, and the description provides no information about the 'image' parameter or its nested properties (kind, path, url, data, buffer). It doesn't explain what IHDR metadata is or how the image input should be provided, failing to compensate for the lack of schema documentation.

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 the resource 'IHDR metadata from an image', making the purpose specific and understandable. However, it doesn't explicitly distinguish this tool from sibling tools like 'read-exif' or 'read-metadata', which likely read different types of image metadata, so it misses full sibling differentiation.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'read-exif' or 'read-metadata', nor does it specify contexts or exclusions for reading IHDR metadata specifically, leaving usage unclear.

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