Skip to main content
Glama
Garoth

SendGrid MCP Server

by Garoth

remove_contacts_from_list

Remove email addresses from a SendGrid contact list while preserving the contacts in your database. Specify list ID and emails to manage your email marketing audience.

Instructions

Remove contacts from a SendGrid list without deleting them

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
list_idYesID of the contact list
emailsYesArray of email addresses to remove from the list

Implementation Reference

  • Handler for the 'remove_contacts_from_list' tool call. It invokes the service method with list_id and emails, then returns a success message.
    case 'remove_contacts_from_list':
      await service.removeContactsFromList(args.list_id, args.emails);
      return { content: [{ type: 'text', text: `Removed ${args.emails.length} contacts from list ${args.list_id}` }] };
  • Schema definition for the 'remove_contacts_from_list' tool, including name, description, and inputSchema with required properties list_id and emails.
    {
      name: 'remove_contacts_from_list',
      description: 'Remove contacts from a SendGrid list without deleting them',
      inputSchema: {
        type: 'object',
        properties: {
          list_id: {
            type: 'string',
            description: 'ID of the contact list'
          },
          emails: {
            type: 'array',
            items: {
              type: 'string'
            },
            description: 'Array of email addresses to remove from the list'
          }
        },
        required: ['list_id', 'emails']
      }
    }
  • Helper method in SendGridService that implements the core logic: searches for contacts by email within the specified list, retrieves their IDs, and deletes the associations from the list via SendGrid API.
    async removeContactsFromList(listId: string, contactEmails: string[]) {
      // 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 (${contactEmails.map(email => `'${email}'`).join(',')}) AND CONTAINS(list_ids, '${listId}')`
        }
      });
      
      const contacts = (searchResponse.body as { result: SendGridContact[] }).result || [];
      const contactIds = contacts.map(contact => contact.id).filter(id => id) as string[];
    
      if (contactIds.length > 0) {
        // Remove the contacts from the list
        await this.client.request({
          method: 'DELETE',
          url: `/v3/marketing/lists/${listId}/contacts`,
          qs: {
            contact_ids: contactIds.join(',')
          }
        });
      }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Garoth/sendgrid-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server