view_image
Open stored images in your default viewer to review generated artwork from the EverArt Forge MCP Server.
Instructions
Open a stored image in the default image viewer
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes | Name of the image file to view |
Implementation Reference
- src/index.ts:793-879 (handler)The handler for the 'view_image' tool. It takes a filename argument, constructs the full path using STORAGE_DIR, verifies the file exists, reads it for potential inline display, opens the image in the system's default viewer using the 'open' library, and returns a success message with the file path.case "view_image": { try { const args = request.params.arguments as any; // Validate filename if (!args.filename || typeof args.filename !== 'string') { return errorResponse({ type: EverArtErrorType.VALIDATION_ERROR, message: "filename is required and must be a string" }); } const filename = args.filename; const filepath = path.join(STORAGE_DIR, filename); try { // Check if file exists await fs.access(filepath); } catch (accessError) { // List available files to help the user const availableFiles = await listStoredImages(); let errorMsg = `Image not found: ${filename}`; if (availableFiles.length > 0) { const suggestions = availableFiles .filter(f => f.toLowerCase().includes(filename.toLowerCase()) || filename.toLowerCase().includes(f.toLowerCase().split('_').pop() || '')) .slice(0, 3); if (suggestions.length > 0) { errorMsg += `\n\nDid you mean one of these?\n` + suggestions.map(s => `• ${s}`).join('\n'); } errorMsg += `\n\nUse 'list_images' to see all available images.`; } return errorResponse({ type: EverArtErrorType.VALIDATION_ERROR, message: errorMsg }); } // Read the image for inline display let imageData: string | undefined; let mimeType: string = 'application/octet-stream'; try { const content = await fs.readFile(filepath); imageData = content.toString('base64'); const ext = path.extname(filename).slice(1).toLowerCase(); mimeType = getMimeType(ext); } catch (error) { console.warn("Unable to read image for inline display:", error); // Continue without inline display if reading fails } await open(filepath); // Skip opening in external viewer since we'll show in MCP try { // If we got here, cancel the auto-open to avoid duplicate windows // await open(filepath); } catch (openError) { // Ignore error } return { content: [ { type: "text", text: `✅ Viewing image: ${filename}` }, { type: "text", text: `Image opened in default viewer.\nFile path: file://${filepath}` } ], }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error"; return errorResponse({ type: EverArtErrorType.UNKNOWN_ERROR, message: `Error viewing image: ${errorMessage}` }); } }
- src/index.ts:427-440 (registration)Tool registration in the ListToolsRequestSchema handler, including the tool's name, description, and input schema definition.{ name: "view_image", description: "Open a stored image in the default image viewer", inputSchema: { type: "object", properties: { filename: { type: "string", description: "Name of the image file to view", }, }, required: ["filename"], }, },
- src/index.ts:430-439 (schema)Input schema for the 'view_image' tool, specifying a required 'filename' string parameter.inputSchema: { type: "object", properties: { filename: { type: "string", description: "Name of the image file to view", }, }, required: ["filename"], },