List Single Send Campaigns
list_single_sendsRetrieve all single send campaigns from your SendGrid account. Specify the number of results to return per page.
Instructions
List all single send campaigns
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_size | No | Number of results to return |
Implementation Reference
- src/tools/campaigns.ts:1-18 (handler)The main handler, config (schema), and definition for the 'list_single_sends' tool. It accepts an optional page_size parameter (default 50), calls the SendGrid API endpoint POST /v3/marketing/singlesends/search, and returns the JSON result.
import { z } from "zod"; import { makeRequest } from "../shared/api.js"; import { ToolResult } from "../shared/types.js"; export const campaignTools = { list_single_sends: { config: { title: "List Single Send Campaigns", description: "List all single send campaigns", inputSchema: { page_size: z.number().optional().default(50).describe("Number of results to return"), }, }, handler: async ({ page_size }: { page_size: number }): Promise<ToolResult> => { const result = await makeRequest(`https://api.sendgrid.com/v3/marketing/singlesends/search?page_size=${page_size}`); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }, }, - src/tools/index.ts:1-17 (registration)The tool is registered by spreading 'campaignTools' (which contains list_single_sends) into the 'allTools' export, making it available to the MCP server.
import { automationTools } from "./automations.js"; import { campaignTools } from "./campaigns.js"; import { contactTools } from "./contacts.js"; import { mailTools } from "./mail.js"; import { miscTools } from "./misc.js"; import { statsTools } from "./stats.js"; import { templateTools } from "./templates.js"; export const allTools = { ...automationTools, ...campaignTools, ...contactTools, ...mailTools, ...miscTools, ...statsTools, ...templateTools, }; - src/prompts/help.ts:68-70 (helper)Help text documentation referencing the 'list_single_sends' tool in the campaign help prompt, describing it as 'View all your single send campaigns'.
Available single send tools: - list_single_sends: View all your single send campaigns - open_single_send_creator: Open the SendGrid web interface to create a new campaign - src/shared/api.ts:1-17 (helper)The 'makeRequest' helper function used by the handler to execute the HTTP request to the SendGrid API.
import { getAuthHeaders } from "./auth.js"; export async function makeRequest(url: string, options: RequestInit = {}): Promise<any> { const response = await fetch(url, { headers: { ...getAuthHeaders(), ...options.headers, }, ...options, }); if (!response.ok) { const errorText = await response.text(); throw new Error(`SendGrid API error (${response.status}): ${errorText}`); } return response.json(); - src/shared/types.ts:24-29 (helper)The ToolResult interface definition used as the return type of the handler.
export interface ToolResult { content: Array<{ type: "text"; text: string; }>; }