Skip to main content
Glama
Garoth

SendGrid MCP Server

by Garoth

get_contacts_by_list

Retrieve all contacts from a specific SendGrid email list using the list ID to manage and organize your email marketing recipients.

Instructions

Get all contacts in a SendGrid list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
list_idYesID of the contact list

Implementation Reference

  • The handler logic within handleToolCall that executes the 'get_contacts_by_list' tool. It calls the SendGrid service method with the provided list_id and returns a formatted JSON string of the contacts (email, first_name, last_name).
    case 'get_contacts_by_list':
      const contacts = await service.getContactsByList(args.list_id);
      return {
        content: [{
          type: 'text',
          text: JSON.stringify(contacts.map(c => ({
            email: c.email,
            first_name: c.first_name,
            last_name: c.last_name
          })), null, 2)
        }]
      };
  • Input schema and tool definition (registration) for 'get_contacts_by_list', requiring a 'list_id' string parameter.
    {
      name: 'get_contacts_by_list',
      description: 'Get all contacts in a SendGrid list',
      inputSchema: {
        type: 'object',
        properties: {
          list_id: {
            type: 'string',
            description: 'ID of the contact list'
          }
        },
        required: ['list_id']
      }
    },
  • Core helper method in SendGridService that queries the SendGrid Marketing Contacts Search API to retrieve all contacts belonging to the specified list using a CONTAINS query on list_ids.
    async getContactsByList(listId: string): Promise<SendGridContact[]> {
      const [response] = await this.client.request({
        method: 'POST',
        url: '/v3/marketing/contacts/search',
        body: {
          query: `CONTAINS(list_ids, '${listId}')`
        }
      });
      return (response.body as { result: SendGridContact[] }).result || [];
    }
  • src/index.ts:42-46 (registration)
    MCP server registration for listing tools, which includes 'get_contacts_by_list' via getToolDefinitions.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: getToolDefinitions(sendGridService)
      };
    });
  • src/index.ts:52-55 (registration)
    MCP server handler for tool calls, delegating to handleToolCall which processes 'get_contacts_by_list'.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      try {
        return await handleToolCall(sendGridService, request.params.name, request.params.arguments);
      } catch (error: any) {

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