delete_contacts
Remove email addresses from your SendGrid contact database to maintain clean mailing lists and comply with data privacy requirements.
Instructions
Delete contacts from your SendGrid account
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emails | Yes | Array of email addresses to delete |
Implementation Reference
- src/services/sendgrid.ts:28-51 (handler)Core handler function that implements deleting SendGrid contacts by first searching for them by email addresses and then deleting them using the SendGrid Marketing Contacts API.
async deleteContactsByEmails(emails: string[]): Promise<void> { // First get the contact IDs for the emails const [searchResponse] = await this.client.request({ method: 'POST', url: '/v3/marketing/contacts/search', body: { query: `email IN (${emails.map(email => `'${email}'`).join(',')})` } }); const contacts = (searchResponse.body as { result: SendGridContact[] }).result || []; const contactIds = contacts.map(contact => contact.id).filter(id => id) as string[]; if (contactIds.length > 0) { // Then delete the contacts by their IDs await this.client.request({ method: 'DELETE', url: '/v3/marketing/contacts', qs: { ids: contactIds.join(',') } }); } } - src/tools/index.ts:5-21 (registration)Tool registration within getToolDefinitions array, defining name, description, and input schema for the delete_contacts tool.
{ name: 'delete_contacts', description: 'Delete contacts from your SendGrid account', inputSchema: { type: 'object', properties: { emails: { type: 'array', items: { type: 'string' }, description: 'Array of email addresses to delete' } }, required: ['emails'] } }, - src/tools/index.ts:8-20 (schema)Input schema definition specifying that delete_contacts requires an array of email strings.
inputSchema: { type: 'object', properties: { emails: { type: 'array', items: { type: 'string' }, description: 'Array of email addresses to delete' } }, required: ['emails'] } - src/tools/index.ts:378-380 (handler)Dispatcher in handleToolCall that invokes the deleteContactsByEmails service method and formats the tool response.
case 'delete_contacts': await service.deleteContactsByEmails(args.emails); return { content: [{ type: 'text', text: `Successfully deleted ${args.emails.length} contacts` }] };