create_contact_with_lists
Add new contacts to specific email marketing lists to organize subscribers and target communications effectively.
Instructions
Create new contacts and assign them to specific email lists
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contacts | Yes | Array of contact objects | |
| list_ids | Yes | Array of list IDs to add the contact to |
Implementation Reference
- src/tools/contacts.ts:146-157 (handler)The handler function that implements the tool logic: checks read-only mode, then makes a PUT request to SendGrid API to create contacts and assign them to the specified list_ids.handler: async ({ contacts, list_ids }: { contacts: any[]; list_ids: string[] }): 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, list_ids }), }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; },
- src/tools/contacts.ts:138-145 (schema)The tool configuration including input schema using Zod for validation of contacts array (referencing ContactSchema) and list_ids array.config: { title: "Create Contact with Lists", description: "Create new contacts and assign them to specific email lists", inputSchema: { contacts: z.array(ContactSchema).describe("Array of contact objects"), list_ids: z.array(z.string()).describe("Array of list IDs to add the contact to"), }, },
- src/shared/types.ts:6-11 (schema)Zod schema definition for individual contact objects used in the 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:9-17 (registration)Exports allTools object by spreading contactTools (containing create_contact_with_lists) along with other tool groups.export const allTools = { ...automationTools, ...campaignTools, ...contactTools, ...mailTools, ...miscTools, ...statsTools, ...templateTools, };
- src/index.ts:20-23 (registration)Registers all tools from allTools (including create_contact_with_lists) to the MCP server using registerTool in a loop.// Register all tools for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }