Skip to main content
Glama
itrimble

Image Viewer MCP

by itrimble

display-image

Render an image from the local filesystem by providing its path. The tool converts the image to base64 data, enabling it to be displayed directly in conversations for visual interaction and analysis.

Instructions

Display an image from the filesystem. Returns the image as base64 data that Claude can render.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imagePathYesPath to the image file (supports ~ for home directory)

Implementation Reference

  • Handler function for the display-image tool. It calls the loadImage helper, constructs a response with base64-encoded image data and accompanying text metadata, or an error message if loading fails.
    async ({ imagePath }) => {
        try {
            const imageInfo = await imageViewer.loadImage(imagePath);
            
            return {
                content: [
                    {
                        type: "image",
                        data: imageInfo.base64Data,
                        mimeType: imageInfo.mimeType,
                    },
                    {
                        type: "text",
                        text: `Image: ${imageInfo.name}\nPath: ${imageInfo.path}\nSize: ${Math.round(imageInfo.size / 1024)} KB\nType: ${imageInfo.mimeType}`,
                    },
                ],
            };
        } catch (error) {
            return {
                content: [
                    {
                        type: "text",
                        text: `Error loading image: ${error instanceof Error ? error.message : 'Unknown error'}`,
                    },
                ],
            };
        }
    }
  • Zod input schema for the display-image tool, defining the imagePath parameter as a string.
    {
        imagePath: z.string().describe("Path to the image file (supports ~ for home directory)"),
    },
  • src/mcp.ts:10-44 (registration)
    Full registration of the display-image tool using server.tool(), including name, description, schema, and inline handler.
    server.tool(
        "display-image",
        "Display an image from the filesystem. Returns the image as base64 data that Claude can render.",
        {
            imagePath: z.string().describe("Path to the image file (supports ~ for home directory)"),
        },
        async ({ imagePath }) => {
            try {
                const imageInfo = await imageViewer.loadImage(imagePath);
                
                return {
                    content: [
                        {
                            type: "image",
                            data: imageInfo.base64Data,
                            mimeType: imageInfo.mimeType,
                        },
                        {
                            type: "text",
                            text: `Image: ${imageInfo.name}\nPath: ${imageInfo.path}\nSize: ${Math.round(imageInfo.size / 1024)} KB\nType: ${imageInfo.mimeType}`,
                        },
                    ],
                };
            } catch (error) {
                return {
                    content: [
                        {
                            type: "text",
                            text: `Error loading image: ${error instanceof Error ? error.message : 'Unknown error'}`,
                        },
                    ],
                };
            }
        }
    );
  • Core helper function loadImage that resolves the file path (handling ~), validates it's an image, reads the file, encodes to base64, determines MIME type, and returns ImageInfo object used by the tool handler.
    export async function loadImage(imagePath: string): Promise<ImageInfo> {
        // Resolve the path to handle ~ and relative paths
        const resolvedPath = path.resolve(imagePath.replace(/^~/, process.env.HOME || ''));
        
        if (!fs.existsSync(resolvedPath)) {
            throw new Error(`Image file not found: ${resolvedPath}`);
        }
    
        if (!isImageFile(resolvedPath)) {
            throw new Error(`File is not a supported image type: ${resolvedPath}`);
        }
    
        const stats = fs.statSync(resolvedPath);
        const imageData = fs.readFileSync(resolvedPath);
        const base64Data = imageData.toString('base64');
        
        return {
            path: resolvedPath,
            name: path.basename(resolvedPath),
            size: stats.size,
            mimeType: getMimeType(resolvedPath),
            base64Data: base64Data
        };
    }
  • TypeScript interface defining the structure of image information returned by loadImage, used in the tool's response.
    export interface ImageInfo {
        path: string;
        name: string;
        size: number;
        mimeType: string;
        base64Data: string;
    }
Behavior3/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 tool reads and returns image data as base64, implying a read-only operation, but doesn't specify error handling (e.g., for invalid paths), performance considerations, or file format support. It adds some context about the return format being renderable by Claude, which is useful beyond basic functionality.

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 two sentences, front-loaded with the core purpose and followed by return value information. Every sentence earns its place by adding value: the first defines the action, and the second clarifies the output format. There is zero waste or redundancy, making it highly efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (one parameter, no annotations, no output schema), the description is minimally adequate. It covers the basic purpose and return format, but lacks details on error conditions, supported image types, or how it interacts with siblings. Without an output schema, it helpfully explains the return value, but more context could improve agent decision-making.

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, with 'imagePath' clearly documented in the schema itself. The description doesn't add any parameter-specific details beyond what's in the schema (e.g., no examples or edge cases). Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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 ('Display') and resource ('an image from the filesystem'), making the purpose immediately understandable. It distinguishes from 'image-info' (which likely provides metadata) and 'list-images' (which enumerates files), though it doesn't explicitly name these siblings. The action is specific but could be more precise about how 'display' differs from just reading the file.

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 'image-info' or 'list-images'. It mentions the return format (base64 data for Claude rendering), which hints at usage for visualization, but lacks explicit when/when-not instructions or prerequisites. This leaves the agent to infer usage context from tool names alone.

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