image-info
Extract and view detailed metadata from image files without processing the full image data, enabling quick access to essential information for analysis or verification.
Instructions
Get detailed information about an image file without loading the full image data
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| imagePath | Yes | Path to the image file (supports ~ for home directory) |
Implementation Reference
- src/mcp.ts:83-118 (handler)Registration and inline handler for the 'image-info' MCP tool. Handles input validation with Zod schema, calls loadImage helper, and formats response as JSON text content.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'}`, }, ], }; } } );
- src/imageViewer.ts:4-10 (schema)TypeScript interface defining the ImageInfo structure used by the loadImage function and returned in image-info tool responses.export interface ImageInfo { path: string; name: string; size: number; mimeType: string; base64Data: string; }
- src/imageViewer.ts:40-63 (helper)Core helper function that resolves image path, validates file type, reads file stats and content, encodes to base64, and returns ImageInfo object. Called by image-info 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 }; }
- src/imageViewer.ts:35-38 (helper)Helper function to check if a file has a supported image extension, used in loadImage.export function isImageFile(filePath: string): boolean { const ext = path.extname(filePath).toLowerCase(); return SUPPORTED_EXTENSIONS.includes(ext); }
- src/imageViewer.ts:14-33 (helper)Helper function to determine MIME type from file extension, used in loadImage.export function getMimeType(filePath: string): string { const ext = path.extname(filePath).toLowerCase(); switch (ext) { case '.jpg': case '.jpeg': return 'image/jpeg'; case '.png': return 'image/png'; case '.gif': return 'image/gif'; case '.bmp': return 'image/bmp'; case '.webp': return 'image/webp'; case '.svg': return 'image/svg+xml'; default: return 'application/octet-stream'; } }