Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • 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 }],
      };
    }
  • 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,
    },
  • 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));
      });
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other 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/4regab/tasksync-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server