Skip to main content
Glama
deyikong

SendGrid MCP Server

by deyikong

create_contact

Add new contacts to your SendGrid account with email addresses, names, and custom fields for email marketing campaigns and contact management.

Instructions

Create new contacts in your SendGrid account

Input Schema

NameRequiredDescriptionDefault
contactsYesArray of contact objects

Input Schema (JSON Schema)

{ "properties": { "contacts": { "description": "Array of contact objects", "items": { "additionalProperties": false, "properties": { "custom_fields": { "additionalProperties": {}, "description": "Custom field values", "type": "object" }, "email": { "description": "Contact email address", "type": "string" }, "first_name": { "description": "First name", "type": "string" }, "last_name": { "description": "Last name", "type": "string" } }, "required": [ "email" ], "type": "object" }, "type": "array" } }, "required": [ "contacts" ], "type": "object" }

Implementation Reference

  • The handler function that performs the actual logic: checks read-only mode and sends a PUT request to SendGrid API to create the contacts.
    handler: async ({ contacts }: { contacts: 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/marketing/contacts", { method: "PUT", body: JSON.stringify({ contacts }), }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; },
  • Tool configuration including title, description, and input schema defining 'contacts' as array of ContactSchema.
    config: { title: "Create Contact", description: "Create new contacts in your SendGrid account", inputSchema: { contacts: z.array(ContactSchema).describe("Array of contact objects"), }, },
  • Zod schema defining the structure of a contact object used in create_contact input.
    export const ContactSchema = z.object({ email: z.string().describe("Contact email address"), first_name: z.string().optional().describe("First name"), last_name: z.string().optional().describe("Last name"), custom_fields: z.record(z.any()).optional().describe("Custom field values"), });
  • Full tool definition object for 'create_contact' exported as part of contactTools, which is then aggregated into allTools.
    create_contact: { config: { title: "Create Contact", description: "Create new contacts in your SendGrid account", inputSchema: { contacts: z.array(ContactSchema).describe("Array of contact objects"), }, }, handler: async ({ contacts }: { contacts: 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/marketing/contacts", { method: "PUT", body: JSON.stringify({ contacts }), }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }, },
  • src/index.ts:21-23 (registration)
    Generic registration loop that registers all tools from allTools, including create_contact, to the MCP server.
    for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }

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/deyikong/sendgrid-mcp'

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