Skip to main content
Glama
rupeedev

image-reader MCP Server

by rupeedev

scan_directory

Scan a directory to find images and extract their metadata, supporting recursive subdirectory searches for comprehensive file analysis.

Instructions

Scan a directory for images and return metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directoryYesDirectory path to scan for images
recursiveNoWhether to scan subdirectories recursively

Implementation Reference

  • The execution logic for the scan_directory tool. It validates input, scans the directory (recursively if specified), filters for supported image formats, retrieves metadata for each image using getImageMetadata, and returns a text content block with a JSON summary of found images.
    case "scan_directory": {
      const { directory, recursive = false } = 
        request.params.arguments as { directory: string, recursive?: boolean };
      
      if (!directory) {
        throw new McpError(ErrorCode.InvalidParams, "Directory path is required");
      }
      
      if (!fs.existsSync(directory)) {
        throw new McpError(ErrorCode.InvalidRequest, `Directory not found: ${directory}`);
      }
      
      try {
        // Function to scan directory recursively
        async function scanDir(dir: string, results: ImageMetadata[] = []): Promise<ImageMetadata[]> {
          // Use fs instead of fsExtra for readdir
          const entries = await fs.promises.readdir(dir, { withFileTypes: true });
          
          for (const entry of entries) {
            const fullPath = path.join(dir, entry.name);
            
            if (entry.isDirectory() && recursive) {
              await scanDir(fullPath, results);
            } else if (entry.isFile()) {
              const ext = path.extname(entry.name).toLowerCase();
              if (SUPPORTED_FORMATS.includes(ext)) {
                try {
                  const metadata = await getImageMetadata(fullPath);
                  results.push(metadata);
                } catch (error) {
                  console.error(`Error processing ${fullPath}:`, error);
                }
              }
            }
          }
          
          return results;
        }
        
        const images = await scanDir(directory);
        
        return {
          content: [
            {
              type: "text",
              text: `Found ${images.length} images in ${directory}${recursive ? ' (including subdirectories)' : ''}:\n\n` +
                JSON.stringify(images.map(img => ({
                  filename: img.filename,
                  path: img.path,
                  format: img.format,
                  dimensions: `${img.width}x${img.height}`,
                  size: `${(img.size / 1024).toFixed(2)} KB`
                })), null, 2)
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error scanning directory: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • src/index.ts:309-326 (registration)
    Registration of the scan_directory tool in the ListToolsRequestSchema handler, including its name, description, and input schema.
    {
      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"]
      }
    }
  • Input schema definition for the scan_directory tool, specifying directory (required) and optional recursive flag.
    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"]
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. It states the action ('scan') and output ('return metadata'), but lacks details on permissions needed, error handling, rate limits, or what metadata includes (e.g., file sizes, formats). This is inadequate for a tool that interacts with the file system.

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 action and output. It avoids unnecessary words and gets straight to the point, making it easy for an agent 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 of file system operations and the lack of annotations and output schema, the description is insufficient. It doesn't explain what 'metadata' entails, potential errors, or security considerations. For a tool with no structured output, more context is needed to guide the agent effectively.

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 input schema has 100% description coverage, clearly documenting both parameters. The description adds no additional meaning beyond the schema, such as examples or constraints on the 'directory' path. Since the schema does the heavy lifting, the baseline score of 3 is appropriate.

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 tool's purpose with a specific verb ('scan') and resource ('directory for images'), and it mentions the output ('return metadata'). However, it doesn't explicitly differentiate from sibling tools like 'analyze_image' or 'convert_format', which might also involve image processing but with different operations.

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 scenarios where scanning for images is preferred over other operations or prerequisites like file system access. This leaves the agent without context for tool selection among siblings.

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