mailosaur_files_get_preview
Download an email preview screenshot as base64 content. Provide the preview ID to retrieve the image.
Instructions
Download a generated email preview screenshot. Returns base64 content.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| previewId | Yes |
Implementation Reference
- src/index.ts:370-384 (registration)Registration of the 'mailosaur_files_get_preview' tool via server.tool() with the MCP server, including its description, schema (expects previewId string), and handler logic.
server.tool( "mailosaur_files_get_preview", "Download a generated email preview screenshot. Returns base64 content.", { previewId: z.string() }, async ({ previewId }) => { const file = await mailosaur.files.getPreview(previewId); return response({ previewId, encoding: "base64", content: await toBase64(file) }); } ); - src/index.ts:376-383 (handler)Handler function for the tool: calls mailosaur.files.getPreview(previewId), converts the result to base64 via toBase64(), and returns a response with previewId, encoding, and content.
async ({ previewId }) => { const file = await mailosaur.files.getPreview(previewId); return response({ previewId, encoding: "base64", content: await toBase64(file) }); } - src/index.ts:373-375 (schema)Input schema for the tool: requires a single 'previewId' string parameter validated by zod.
{ previewId: z.string() }, - src/index.ts:100-118 (helper)Helper function 'toBase64' used by the handler to convert the file/stream response into a base64-encoded string.
async function toBase64(file: unknown) { if (file instanceof Readable) { const chunks: Buffer[] = []; for await (const chunk of file) { chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)); } return Buffer.concat(chunks).toString("base64"); } if (Buffer.isBuffer(file)) return file.toString("base64"); if (file instanceof Uint8Array) return Buffer.from(file).toString("base64"); if (typeof file === "string") return Buffer.from(file).toString("base64"); if (file && typeof file === "object" && "content" in file) { const content = (file as { content: unknown }).content; if (Buffer.isBuffer(content)) return content.toString("base64"); if (content instanceof Uint8Array) return Buffer.from(content).toString("base64"); if (typeof content === "string") return Buffer.from(content).toString("base64"); } return Buffer.from(JSON.stringify(file)).toString("base64"); } - src/index.ts:79-88 (helper)Helper function 'response' that wraps a value into the MCP content response format (text content type with JSON stringified value).
function response(value: unknown) { return { content: [ { type: "text" as const, text: JSON.stringify(value, null, 2) } ] }; }