Skip to main content
Glama

Image Viewer MCP

by itrimble
mcp.ts3.9 kB
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { z } from "zod"; import * as imageViewer from "./imageViewer.js"; const server = new McpServer({ name: "Image Viewer", version: "1.0.0", }); 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'}`, }, ], }; } } ); 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"), }, 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'}`, }, ], }; } } ); server.tool( "image-info", "Get detailed information about an image file without loading the full image data", { 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: "text", text: JSON.stringify({ name: imageInfo.name, path: imageInfo.path, size: imageInfo.size, sizeKB: Math.round(imageInfo.size / 1024), mimeType: imageInfo.mimeType }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error getting image info: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], }; } } ); export { server };

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