Skip to main content
Glama
jicoing

MCP Image Metadata Server

by jicoing

extract_image_metadata

Extract EXIF, GPS, IPTC, and XMP metadata from an image by providing its URL. Returns structured data for further processing.

Instructions

Extract metadata from image (EXIF, GPS, IPTC, XMP). Price: $0.002 USDC via x402

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageUrlYesURL or file path to the image
includeOptionsNo
paymentHeaderNox402 payment header (if paying for access)
payerNoCaller wallet address (for freemium tracking)

Implementation Reference

  • The handler function `handleExtract` that executes the extract_image_metadata tool logic. It validates payment/freemium, then calls `extractMetadata` from exif.ts to extract EXIF, GPS, IPTC, XMP, color, thumbnail, OCR, and deep hash data.
    export async function handleExtract(
      input: ExtractInput,
      paymentHeader?: string,
      payer?: string
    ): Promise<{
      success: boolean;
      data?: ImageMetadata;
      price?: number;
      paymentStatus?: string;
      freemiumRemaining?: number;
      error?: string;
    }> {
      try {
        const { imageUrl, includeOptions } = input;
        const options = includeOptions || {};
        const tier = getTierFromOptions(options);
        const price = calculatePrice(tier);
    
        if (paymentHeader || !checkFreemium(payer).allowed) {
          const payment = await verifyPayment(paymentHeader, tier, payer);
          if (!payment.valid) {
            return {
              success: false,
              price,
              paymentStatus: 'failed',
              freemiumRemaining: 0,
              error: payment.error || 'Payment verification failed',
            };
          }
        }
    
        const freemium = checkFreemium(payer);
        const data = await extractMetadata(imageUrl, options);
    
        return {
          success: true,
          data,
          price,
          paymentStatus: freemium.allowed ? 'free' : 'paid',
          freemiumRemaining: freemium.allowed ? freemium.remaining : 0,
        };
      } catch (error) {
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Unknown error',
        };
      }
    }
  • Zod schemas `ExtractOptionsSchema` and `ExtractInputSchema` defining the input validation for the extract_image_metadata tool, including optional booleans for includeGps, includeColor, includeThumbnail, includeOcr, includeDeepHash.
    import { z } from 'zod';
    
    export const ExtractOptionsSchema = z.object({
      includeGps: z.boolean().default(true),
      includeColor: z.boolean().default(true),
      includeThumbnail: z.boolean().default(false),
      includeOcr: z.boolean().default(false),
      includeDeepHash: z.boolean().default(false),
    });
    
    export type ExtractOptions = z.infer<typeof ExtractOptionsSchema>;
    
    export const ExtractInputSchema = z.object({
      imageUrl: z.string(),
      includeOptions: ExtractOptionsSchema.optional(),
    });
    
    export type ExtractInput = z.infer<typeof ExtractInputSchema>;
  • src/index.ts:31-64 (registration)
    Registration of the extract_image_metadata tool in the MCP ListToolsRequestSchema handler, defining its name, description, and inputSchema.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: 'extract_image_metadata',
            description: `Extract metadata from image (EXIF, GPS, IPTC, XMP). Price: $${PRICING.standard.price} USDC via x402`,
            inputSchema: {
              type: 'object',
              properties: {
                imageUrl: {
                  type: 'string',
                  description: 'URL or file path to the image',
                },
                includeOptions: {
                  type: 'object',
                  properties: {
                    includeGps: { type: 'boolean', default: true },
                    includeColor: { type: 'boolean', default: true },
                    includeThumbnail: { type: 'boolean', default: false },
                    includeOcr: { type: 'boolean', default: false },
                    includeDeepHash: { type: 'boolean', default: false },
                  },
                },
                paymentHeader: {
                  type: 'string',
                  description: 'x402 payment header (if paying for access)',
                },
                payer: {
                  type: 'string',
                  description: 'Caller wallet address (for freemium tracking)',
                },
              },
              required: ['imageUrl'],
            },
  • The CallToolRequestSchema switch-case that routes the 'extract_image_metadata' name to the handleExtract function via ExtractInputSchema parsing.
    case 'extract_image_metadata': {
      const { paymentHeader: _, payer: __, ...rest } = args as Record<string, unknown>;
      const input = ExtractInputSchema.parse(rest);
      const result = await handleExtract(input, paymentHeader, payer);
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
    }
  • The core `extractMetadata` function that reads image EXIF/IPTC/XMP data using ExifReader and sharp, extracts GPS, color, thumbnail, deep hash, and animation info as requested.
    export async function extractMetadata(
      imagePath: string,
      options: {
        includeGps?: boolean;
        includeColor?: boolean;
        includeThumbnail?: boolean;
        includeOcr?: boolean;
        includeDeepHash?: boolean;
      } = {}
    ): Promise<ImageMetadata> {
      const buffer = await sharp(imagePath).toBuffer();
      const tags = ExifReader.load(buffer);
    
      const fileInfo = await sharp(imagePath).metadata();
    
      const metadata: ImageMetadata = {
        file: {
          width: fileInfo.width || 0,
          height: fileInfo.height || 0,
          format: fileInfo.format || 'unknown',
          colorDepth: fileInfo.channels,
          dpi: fileInfo.density,
          fileSize: buffer.length,
          mimeType: `image/${fileInfo.format}`,
        },
      };
    
      if (tags.exif) {
        metadata.exif = extractExif(tags.exif as unknown as Record<string, unknown>);
      }
    
      if (options.includeGps && tags.gps) {
        metadata.gps = extractGps(tags.gps as unknown as Record<string, unknown>);
      }
    
      if (options.includeColor) {
        const hasIccProfile = !!fileInfo.icc;
        metadata.color = {
          colorProfile: fileInfo.icc ? 'Embedded' : undefined,
          hasIccProfile,
        };
      }
    
      if (tags.iptc) {
        metadata.iptc = extractIptc(tags.iptc as unknown as Record<string, unknown>);
      }
    
      if (tags.xmp) {
        metadata.xmp = extractXmp(tags.xmp as unknown as Record<string, unknown>);
      }
    
      if (fileInfo.pages) {
        metadata.animation = {
          frameCount: fileInfo.pages,
        };
      }
    
      if (options.includeThumbnail) {
        const thumbnailBuffer = await sharp(imagePath)
          .resize(200, 200, { fit: 'inside' })
          .toBuffer();
        metadata.thumbnail = `data:image/jpeg;base64,${thumbnailBuffer.toString('base64')}`;
      }
    
      if (options.includeDeepHash) {
        const crypto = await import('crypto');
        const hash = crypto.createHash('sha256').update(buffer).digest('hex');
        metadata.deepHash = hash;
      }
    
      return metadata;
    }
Behavior3/5

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

The description mentions a cost ($0.002 USDC via x402), which is a behavioral trait not in annotations (none provided). However, it does not clarify if payment is mandatory, what happens without paymentHeader, or any side effects. No annotations exist, so description carries burden but adds limited transparency beyond cost.

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

Conciseness4/5

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

Two sentences, front-loaded with purpose ('Extract metadata from image (EXIF, GPS, IPTC, XMP).'), then pricing. No redundancy. Could be slightly more informative about payment flow, but overall efficient 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?

The tool has nested input schema (includeOptions), optional payment parameters, and no output schema. The description does not explain the return format, the meaning of includeOptions, or how payment works (x402). Given the complexity and missing output schema, the description is incomplete.

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 75% (all parameters have descriptions, nested options have defaults). The tool description adds no additional parameter-level information beyond what the schema provides. At high coverage, baseline of 3 is appropriate.

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

Purpose5/5

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

The description clearly states the verb 'Extract' and resource 'metadata from image', and lists specific metadata types (EXIF, GPS, IPTC, XMP). It distinguishes from siblings like detect_image_manipulation (manipulation detection) and extract_batch_metadata (batch operation) by implying single image focus.

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

Usage Guidelines3/5

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

No explicit guidance on when to use vs alternatives like batch extraction or pricing tool. The description implies single image use but does not address when to choose this over extract_batch_metadata or detect_image_manipulation. The pricing info is a usage hint but not a guideline.

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/jicoing/mcp-image-metadata'

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