Skip to main content
Glama
itrimble

Image Viewer MCP

by itrimble

list-images

Locate and generate a list of image files within a specified directory, with options to include subdirectories, using the searchPath input to define the target location.

Instructions

Find and list image files in a directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
recursiveNoWhether to search subdirectories recursively
searchPathYesDirectory path to search for images (supports ~ for home directory)

Implementation Reference

  • Handler function that executes the 'list-images' tool logic by calling the helper findImages and returning a JSON-formatted text response.
    async ({ searchPath, recursive }) => {
        try {
            const imagePaths = await imageViewer.findImages(searchPath, recursive);
            
            return {
                content: [
                    {
                        type: "text",
                        text: JSON.stringify({
                            searchPath,
                            recursive,
                            count: imagePaths.length,
                            images: imagePaths
                        }, null, 2),
                    },
                ],
            };
        } catch (error) {
            return {
                content: [
                    {
                        type: "text",
                        text: `Error listing images: ${error instanceof Error ? error.message : 'Unknown error'}`,
                    },
                ],
            };
        }
    }
  • Zod input schema defining parameters for the list-images tool: searchPath and optional recursive.
    {
        searchPath: z.string().describe("Directory path to search for images (supports ~ for home directory)"),
        recursive: z.boolean().optional().default(false).describe("Whether to search subdirectories recursively"),
    },
  • src/mcp.ts:46-52 (registration)
    Registration of the 'list-images' tool on the MCP server, including name, description, and schema.
    server.tool(
        "list-images",
        "Find and list image files in a directory",
        {
            searchPath: z.string().describe("Directory path to search for images (supports ~ for home directory)"),
            recursive: z.boolean().optional().default(false).describe("Whether to search subdirectories recursively"),
        },
  • Helper function that implements the core logic for finding image files in a directory, recursively if specified, using isImageFile check.
    export async function findImages(searchPath: string, recursive: boolean = false): Promise<string[]> {
        const resolvedPath = path.resolve(searchPath.replace(/^~/, process.env.HOME || ''));
        
        if (!fs.existsSync(resolvedPath)) {
            throw new Error(`Directory not found: ${resolvedPath}`);
        }
    
        const results: string[] = [];
        
        function scanDirectory(dirPath: string) {
            const items = fs.readdirSync(dirPath);
            
            for (const item of items) {
                const itemPath = path.join(dirPath, item);
                const stats = fs.statSync(itemPath);
                
                if (stats.isFile() && isImageFile(itemPath)) {
                    results.push(itemPath);
                } else if (stats.isDirectory() && recursive) {
                    scanDirectory(itemPath);
                }
            }
        }
        
        const stats = fs.statSync(resolvedPath);
        if (stats.isFile()) {
            if (isImageFile(resolvedPath)) {
                results.push(resolvedPath);
            }
        } else if (stats.isDirectory()) {
            scanDirectory(resolvedPath);
        }
        
        return results.sort();
    }
  • Utility function to check if a file is a supported image type based on extension.
    export function isImageFile(filePath: string): boolean {
        const ext = path.extname(filePath).toLowerCase();
        return SUPPORTED_EXTENSIONS.includes(ext);
    }
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 mentions 'find and list' but doesn't specify what constitutes an 'image file' (e.g., file extensions), how results are returned (e.g., format, pagination), or any limitations (e.g., permissions, rate limits). This leaves significant gaps for an agent to understand the tool's behavior.

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 is front-loaded and appropriately sized, 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 lack of annotations and output schema, the description is incomplete. It doesn't explain what 'image files' include, how results are structured, or any behavioral traits like error handling. For a tool with two parameters and no structured output guidance, more context is needed for effective 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?

The schema description coverage is 100%, with clear descriptions for both parameters ('searchPath' and 'recursive') in the input schema. The description adds no additional parameter semantics beyond what the schema already provides, so it meets the baseline score of 3.

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 ('find and list') and resource ('image files in a directory'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'display-image' or 'image-info', which might handle individual images differently.

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 like 'display-image' or 'image-info', nor does it mention any prerequisites or exclusions. It simply states what the tool does without contextual usage advice.

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

Related 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/itrimble/image-viewer-mcp'

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