Skip to main content
Glama
rupeedev

image-reader MCP Server

by rupeedev

analyze_image

Extract detailed metadata from image files to understand format, dimensions, and technical specifications for analysis and processing.

Instructions

Get detailed metadata about an image

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the image file

Implementation Reference

  • The main execution handler for the 'analyze_image' tool within the CallToolRequestSchema switch statement. It validates the image path, retrieves metadata and thumbnail, and returns structured JSON content or error.
    case "analyze_image": {
      const { path: imagePath } = request.params.arguments as { path: string };
      
      if (!imagePath) {
        throw new McpError(ErrorCode.InvalidParams, "Image path is required");
      }
      
      if (!fs.existsSync(imagePath)) {
        throw new McpError(ErrorCode.InvalidRequest, `Image not found: ${imagePath}`);
      }
      
      try {
        const metadata = await getImageMetadata(imagePath);
        const thumbnail = await generateThumbnail(imagePath);
        
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                filename: metadata.filename,
                format: metadata.format,
                dimensions: `${metadata.width}x${metadata.height}`,
                size: {
                  bytes: metadata.size,
                  kilobytes: (metadata.size / 1024).toFixed(2),
                  megabytes: (metadata.size / (1024 * 1024)).toFixed(2)
                },
                created: metadata.created.toISOString(),
                modified: metadata.modified.toISOString(),
                path: metadata.path,
                thumbnail
              }, null, 2)
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error analyzing image: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • The input schema definition for the 'analyze_image' tool, registered in the ListToolsRequestSchema response. Defines the required 'path' parameter.
    {
      name: "analyze_image",
      description: "Get detailed metadata about an image",
      inputSchema: {
        type: "object",
        properties: {
          path: {
            type: "string",
            description: "Path to the image file"
          }
        },
        required: ["path"]
      }
    },
  • src/index.ts:234-329 (registration)
    The ListToolsRequestSchema handler that registers and lists the 'analyze_image' tool among others.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "analyze_image",
            description: "Get detailed metadata about an image",
            inputSchema: {
              type: "object",
              properties: {
                path: {
                  type: "string",
                  description: "Path to the image file"
                }
              },
              required: ["path"]
            }
          },
          {
            name: "resize_image",
            description: "Resize an image and save to a new file",
            inputSchema: {
              type: "object",
              properties: {
                input: {
                  type: "string",
                  description: "Path to the input image file"
                },
                output: {
                  type: "string",
                  description: "Path to save the resized image"
                },
                width: {
                  type: "number",
                  description: "Target width in pixels"
                },
                height: {
                  type: "number",
                  description: "Target height in pixels (optional)"
                },
                fit: {
                  type: "string",
                  description: "Fit method: cover, contain, fill, inside, outside",
                  enum: ["cover", "contain", "fill", "inside", "outside"]
                }
              },
              required: ["input", "output", "width"]
            }
          },
          {
            name: "convert_format",
            description: "Convert an image to a different format",
            inputSchema: {
              type: "object",
              properties: {
                input: {
                  type: "string",
                  description: "Path to the input image file"
                },
                output: {
                  type: "string",
                  description: "Path to save the converted image"
                },
                format: {
                  type: "string",
                  description: "Target format: jpeg, png, webp, avif, tiff, etc.",
                  enum: ["jpeg", "png", "webp", "avif", "tiff", "gif"]
                },
                quality: {
                  type: "number",
                  description: "Quality level (1-100, for formats that support it)"
                }
              },
              required: ["input", "output", "format"]
            }
          },
          {
            name: "scan_directory",
            description: "Scan a directory for images and return metadata",
            inputSchema: {
              type: "object",
              properties: {
                directory: {
                  type: "string",
                  description: "Directory path to scan for images"
                },
                recursive: {
                  type: "boolean",
                  description: "Whether to scan subdirectories recursively"
                }
              },
              required: ["directory"]
            }
          }
        ]
      };
    });
  • Core helper function called by analyze_image handler to fetch and cache image metadata using sharp and fs.
    async function getImageMetadata(imagePath: string): Promise<ImageMetadata> {
      // Check cache first
      if (imageMetadataCache.has(imagePath)) {
        return imageMetadataCache.get(imagePath)!;
      }
    
      try {
        // Use fs.promises.stat instead of fsExtra.stat
        const stats = await fs.promises.stat(imagePath);
        const metadata = await sharp(imagePath).metadata();
        
        const imageMetadata: ImageMetadata = {
          path: imagePath,
          filename: path.basename(imagePath),
          format: metadata.format || path.extname(imagePath).replace('.', ''),
          width: metadata.width,
          height: metadata.height,
          size: stats.size,
          created: stats.birthtime,
          modified: stats.mtime
        };
    
        // Cache the metadata
        imageMetadataCache.set(imagePath, imageMetadata);
        
        return imageMetadata;
      } catch (error) {
        console.error(`Error getting metadata for ${imagePath}:`, error);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to process image: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Helper function to generate a base64-encoded thumbnail of the image, used in analyze_image response.
    async function generateThumbnail(imagePath: string, maxWidth = 300): Promise<string> {
      try {
        const buffer = await sharp(imagePath)
          .resize({ width: maxWidth, withoutEnlargement: true })
          .toBuffer();
        
        return `data:image/${path.extname(imagePath).replace('.', '')};base64,${buffer.toString('base64')}`;
      } catch (error) {
        console.error(`Error generating thumbnail for ${imagePath}:`, error);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to generate thumbnail: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'Get detailed metadata' implies a read-only operation, it doesn't specify what 'detailed metadata' includes, whether there are rate limits, authentication requirements, or any side effects. For a tool with zero annotation coverage, this leaves significant behavioral questions unanswered.

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 gets straight to the point with zero wasted words. It's appropriately sized for a simple tool with one parameter and is perfectly front-loaded with the core functionality.

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 lack of annotations and output schema, the description is incomplete for proper tool understanding. It doesn't explain what 'detailed metadata' includes (EXIF data, dimensions, format, etc.), nor does it address potential error conditions or return format. For a tool that presumably returns structured data about images, this leaves too much unspecified.

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?

The schema description coverage is 100%, with the single parameter 'path' clearly documented in the schema. The description doesn't add any parameter semantics beyond what the schema already provides - it doesn't clarify what format the path should take, what file systems are supported, or any constraints on the image file. Baseline 3 is appropriate when the schema does the heavy lifting.

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 action ('Get detailed metadata') and resource ('about an image'), making the purpose immediately understandable. However, it doesn't differentiate this from what sibling tools might do - for example, 'scan_directory' might also provide metadata about images. The description is specific but lacks 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 about when to use this tool versus alternatives like 'scan_directory' (which might provide metadata about multiple files) or 'convert_format'/'resize_image' (which modify images rather than analyze them). There's no mention of prerequisites, appropriate contexts, or exclusions for this tool.

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/rupeedev/mcp-image-reader'

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