create_contact_with_lists
Add new email contacts to specific SendGrid mailing lists for targeted email marketing campaigns.
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 executes the tool: checks read-only mode, sends PUT request to SendGrid API to create contacts and assign to specified lists, returns the API response.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)Tool configuration including title, description, and input schema using Zod for validation.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 for individual contact objects referenced in the tool's input schema.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_with_lists) and spreads it into the allTools object for global tool 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, };