Skip to main content
Glama

list_emails

Retrieve all newsletter emails from Buttondown, with optional filtering by draft, scheduled, or sent status.

Instructions

List all emails, optionally filtered by status (draft, scheduled, sent)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
statusNoOptional status to filter emails by

Implementation Reference

  • The handler function that implements the logic for the 'list_emails' tool. It handles the optional status parameter, calls appropriate API methods, formats the email list, and returns a structured text response.
    async ({ status }) => { await this.ensureApiKey(); let response; switch (status) { case "draft": response = await this.api.listDrafts(); break; case "scheduled": response = await this.api.listScheduledEmails(); break; case "sent": response = await this.api.listSentEmails(); break; default: // If no status specified, list all drafts by default response = await this.api.listDrafts(); } // Format the response to be more readable const formattedEmails = response.results.map((email) => ({ id: email.id, subject: email.subject || "Untitled", status: email.status, created: email.creation_date, scheduled_for: email.scheduled_for || null, publish_date: email.publish_date || null, analytics: email.analytics ? { recipients: email.analytics.recipients, opens: email.analytics.opens, clicks: email.analytics.clicks, } : null, })); return { content: [ { type: "text", text: JSON.stringify( { total: response.count, emails: formattedEmails, }, null, 2 ), }, ], }; }
  • Zod schema defining the input parameters for the list_emails tool, specifically the optional 'status' field.
    { status: z .enum(["draft", "scheduled", "sent"]) .optional() .describe("Optional status to filter emails by"), },
  • Registration of the 'list_emails' tool on the MCP server, including name, description, schema, and handler reference.
    this.server.tool( "list_emails", "List all emails, optionally filtered by status (draft, scheduled, sent)", { status: z .enum(["draft", "scheduled", "sent"]) .optional() .describe("Optional status to filter emails by"), }, async ({ status }) => { await this.ensureApiKey(); let response; switch (status) { case "draft": response = await this.api.listDrafts(); break; case "scheduled": response = await this.api.listScheduledEmails(); break; case "sent": response = await this.api.listSentEmails(); break; default: // If no status specified, list all drafts by default response = await this.api.listDrafts(); } // Format the response to be more readable const formattedEmails = response.results.map((email) => ({ id: email.id, subject: email.subject || "Untitled", status: email.status, created: email.creation_date, scheduled_for: email.scheduled_for || null, publish_date: email.publish_date || null, analytics: email.analytics ? { recipients: email.analytics.recipients, opens: email.analytics.opens, clicks: email.analytics.clicks, } : null, })); return { content: [ { type: "text", text: JSON.stringify( { total: response.count, emails: formattedEmails, }, null, 2 ), }, ], }; } );
  • Helper method in ButtondownAPI to list draft emails, used when status is 'draft' or default.
    async listDrafts(): Promise<ButtondownEmailsResponse> { return this.request<ButtondownEmailsResponse>("/emails?status=draft"); }
  • Helper method to list scheduled emails, used when status is 'scheduled'.
    async listScheduledEmails(): Promise<ButtondownEmailsResponse> { return this.request<ButtondownEmailsResponse>("/emails?status=scheduled"); }
  • Helper method to list sent emails, used when status is 'sent'.
    async listSentEmails(): Promise<ButtondownEmailsResponse> { return this.request<ButtondownEmailsResponse>("/emails?status=sent"); }

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/The-Focus-AI/buttondown-mcp'

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