Update Contact
update_contactUpdate existing contact details in SendGrid by providing the contact ID and new field values.
Instructions
Update existing contact information
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contacts | Yes | Array of contact objects with updates |
Implementation Reference
- src/tools/contacts.ts:388-399 (handler)The handler function for update_contact tool. Accepts an array of contact objects with updates, checks read-only mode, then makes a PUT request to SendGrid's marketing contacts API endpoint.
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:369-386 (schema)Input schema for update_contact. Defines a Zod array of contact objects with required 'id' field and optional fields: email, first_name, last_name, phone_number, address fields, and custom_fields.
inputSchema: { contacts: z.array( z.object({ id: z.string().describe("Contact ID (required for updates)"), email: z.string().email().optional().describe("Email address"), first_name: z.string().optional().describe("First name"), last_name: z.string().optional().describe("Last name"), phone_number: z.string().optional().describe("Phone number"), address_line_1: z.string().optional().describe("Address line 1"), address_line_2: z.string().optional().describe("Address line 2"), city: z.string().optional().describe("City"), state_province_region: z.string().optional().describe("State/Province/Region"), postal_code: z.string().optional().describe("Postal code"), country: z.string().optional().describe("Country"), custom_fields: z.record(z.any()).optional().describe("Custom field values"), }) ).describe("Array of contact objects with updates"), }, - src/tools/contacts.ts:365-400 (registration)Tool registration within the contactTools object (exported from src/tools/contacts.ts). The tool is then spread into the allTools export in src/tools/index.ts.
update_contact: { config: { title: "Update Contact", description: "Update existing contact information", inputSchema: { contacts: z.array( z.object({ id: z.string().describe("Contact ID (required for updates)"), email: z.string().email().optional().describe("Email address"), first_name: z.string().optional().describe("First name"), last_name: z.string().optional().describe("Last name"), phone_number: z.string().optional().describe("Phone number"), address_line_1: z.string().optional().describe("Address line 1"), address_line_2: z.string().optional().describe("Address line 2"), city: z.string().optional().describe("City"), state_province_region: z.string().optional().describe("State/Province/Region"), postal_code: z.string().optional().describe("Postal code"), country: z.string().optional().describe("Country"), custom_fields: z.record(z.any()).optional().describe("Custom field values"), }) ).describe("Array of contact objects with updates"), }, }, 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/shared/env.ts:85-94 (helper)Helper function checkReadOnlyMode used by the update_contact handler to block write operations when READ_ONLY is enabled.
export function checkReadOnlyMode(): { blocked: boolean; message?: string } { const env = getEnv(); if (env.READ_ONLY) { return { blocked: true, message: "❌ Operation blocked: Server is running in READ_ONLY mode. Set READ_ONLY=false in your environment to enable write operations." }; } return { blocked: false }; } - src/shared/api.ts:3-18 (helper)Helper function makeRequest used by the update_contact handler to make the HTTP PUT request to the SendGrid API.
export async function makeRequest(url: string, options: RequestInit = {}): Promise<any> { const response = await fetch(url, { headers: { ...getAuthHeaders(), ...options.headers, }, ...options, }); if (!response.ok) { const errorText = await response.text(); throw new Error(`SendGrid API error (${response.status}): ${errorText}`); } return response.json(); }