create_contact
Add new contacts to your SendGrid email marketing lists by providing email addresses, names, and custom field data for targeted communication.
Instructions
Create new contacts in your SendGrid account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contacts | Yes | Array of contact objects |
Implementation Reference
- src/tools/contacts.ts:123-134 (handler)The handler function that implements the core logic of the create_contact tool. It checks for read-only mode and performs a PUT request to the SendGrid API to create the provided 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) }] }; },
- src/tools/contacts.ts:116-122 (schema)Tool configuration including the input schema, which defines 'contacts' as an array of ContactSchema objects.config: { title: "Create Contact", description: "Create new contacts in your SendGrid account", inputSchema: { contacts: z.array(ContactSchema).describe("Array of contact objects"), }, },
- src/shared/types.ts:6-11 (schema)Zod schema defining the structure of a single contact object used in the create_contact tool's 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"), });
- src/tools/index.ts:3-17 (registration)Imports contactTools (containing create_contact) and spreads it into the allTools object, aggregating all tools for registration.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/index.ts:20-23 (registration)Main server registration loop that registers every tool in allTools, including create_contact, with the MCP server.// Register all tools for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }