send_mail
Send transactional emails and marketing communications using SendGrid's API. Configure recipients, content, and delivery settings to manage email campaigns and automated messaging.
Instructions
Send an email using SendGrid Mail Send API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Email content | |
| from | Yes | ||
| personalizations | Yes | Personalization settings for recipients | |
| reply_to | No | ||
| subject | No | Default subject if not set in personalizations |
Implementation Reference
- src/tools/mail.ts:28-39 (handler)The handler function executes the send_mail tool: checks if in read-only mode, if not, makes a POST request to SendGrid's /v3/mail/send endpoint with the provided mailData, and returns a success response with the API result.handler: async (mailData: any): Promise<ToolResult> => { const readOnlyCheck = checkReadOnlyMode(); if (readOnlyCheck.blocked) { return { content: [{ type: "text", text: readOnlyCheck.message! }] }; } const result = await makeRequest("https://api.sendgrid.com/v3/mail/send", { method: "POST", body: JSON.stringify(mailData), }); return { content: [{ type: "text", text: `Email sent successfully. Response: ${JSON.stringify(result, null, 2)}` }] }; },
- src/tools/mail.ts:11-26 (schema)Zod schema defining the input parameters for the send_mail tool, including personalizations (to, cc, bcc, subject, substitutions), from, default subject, content (type and value), and optional reply_to.inputSchema: { personalizations: z.array(z.object({ to: z.array(EmailAddressSchema), cc: z.array(EmailAddressSchema).optional(), bcc: z.array(EmailAddressSchema).optional(), subject: z.string().optional(), substitutions: z.record(z.any()).optional(), })).describe("Personalization settings for recipients"), from: EmailAddressSchema, subject: z.string().optional().describe("Default subject if not set in personalizations"), content: z.array(z.object({ type: z.string().describe("Content type (text/plain, text/html)"), value: z.string().describe("Content body"), })).describe("Email content"), reply_to: EmailAddressSchema.optional(), },
- src/index.ts:21-23 (registration)Registers all tools from the allTools object (which includes send_mail from mailTools) with the MCP server using server.registerTool.for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }
- src/tools/index.ts:9-17 (registration)Aggregates and exports allTools by spreading mailTools (containing send_mail) along with other tool sets.export const allTools = { ...automationTools, ...campaignTools, ...contactTools, ...mailTools, ...miscTools, ...statsTools, ...templateTools, };