view_media
Read image files (PNG, JPEG, GIF, WebP, BMP, SVG) from allowed directories, returning base64-encoded data and MIME type for analysis, display, or processing.
Instructions
Read an image file. Returns the base64 encoded data and MIME type. Only works within allowed directories.
SUPPORTED FORMATS: Images: PNG, JPEG, GIF, WebP, BMP, SVG
USAGE: Use this tool to read and encode image files for analysis, display, or processing. The tool streams files efficiently and returns base64-encoded data with proper MIME type detection.
Args: path: Absolute or relative path to the image file within allowed directories
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- index.ts:389-412 (handler)Executes the view_media tool: parses arguments, validates path, determines MIME type from file extension, reads file content as base64 using helper, and returns structured content block.case "view_media": { const parsed = ReadImageFileArgsSchema.safeParse(args); if (!parsed.success) { throw new Error(`Invalid arguments for view_media: ${parsed.error}`); } const validPath = await validatePath(parsed.data.path); const extension = path.extname(validPath).toLowerCase(); const mimeTypes: Record<string, string> = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp", ".bmp": "image/bmp", ".svg": "image/svg+xml", }; const mimeType = mimeTypes[extension] || "application/octet-stream"; const data = await readFileAsBase64Stream(validPath); const type = mimeType.startsWith("image/") ? "image" : "blob"; return { content: [{ type, data, mimeType }], }; }
- index.ts:94-96 (schema)Zod schema defining the input for view_media tool: requires a path string.const ReadImageFileArgsSchema = z.object({ path: z.string() });
- index.ts:276-289 (registration)Registers the view_media tool in the list of available tools, providing name, detailed description, and input schema reference.{ name: "view_media", description: "Read an image file. Returns the base64 encoded data and MIME type. " + "Only works within allowed directories.\n\n" + "SUPPORTED FORMATS:\n" + "Images: PNG, JPEG, GIF, WebP, BMP, SVG\n\n" + "USAGE:\n" + "Use this tool to read and encode image files for analysis, display, or processing. " + "The tool streams files efficiently and returns base64-encoded data with proper MIME type detection.\n\n" + "Args:\n" + " path: Absolute or relative path to the image file within allowed directories", inputSchema: zodToJsonSchema(ReadImageFileArgsSchema) as ToolInput, },
- index.ts:239-252 (helper)Utility function to efficiently read any file via stream, concatenate buffers, and return base64-encoded string. Used by the view_media handler.async function readFileAsBase64Stream(filePath: string): Promise<string> { return new Promise((resolve, reject) => { const stream = createReadStream(filePath); const chunks: Buffer[] = []; stream.on('data', (chunk) => { chunks.push(chunk as Buffer); }); stream.on('end', () => { const finalBuffer = Buffer.concat(chunks); resolve(finalBuffer.toString('base64')); }); stream.on('error', (err) => reject(err)); }); }