Skip to main content
Glama
lkm1developer

HubSpot MCP Server

hubspot_create_contact

Add new contacts to HubSpot CRM by providing essential details like name and email, enabling organized customer relationship management.

Instructions

Create a new contact in HubSpot

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
firstnameYesContact's first name
lastnameYesContact's last name
emailNoContact's email address
propertiesNoAdditional contact properties

Implementation Reference

  • MCP CallToolRequestSchema handler switch case that extracts arguments and delegates to HubSpotClient.createContact, returning the result as JSON text content.
    case 'hubspot_create_contact': {
      const result = await this.hubspot.createContact(
        args.firstname as string,
        args.lastname as string,
        args.email as string | undefined,
        args.properties as Record<string, any> | undefined
      );
      return {
        content: [{
          type: 'text',
          text: JSON.stringify(result, null, 2)
        }]
      };
    }
  • src/index.ts:79-105 (registration)
    Tool registration definition returned by ListToolsRequestSchema handler, including name, description, and input schema.
    {
      name: 'hubspot_create_contact',
      description: 'Create a new contact in HubSpot',
      inputSchema: {
        type: 'object',
        properties: {
          firstname: { 
            type: 'string', 
            description: "Contact's first name" 
          },
          lastname: { 
            type: 'string', 
            description: "Contact's last name" 
          },
          email: { 
            type: 'string', 
            description: "Contact's email address" 
          },
          properties: { 
            type: 'object', 
            description: 'Additional contact properties',
            additionalProperties: true
          }
        },
        required: ['firstname', 'lastname']
      }
    },
  • HubSpotClient.createContact method: searches for existing contact by firstname/lastname (and optional company), creates new contact if not exists, adds email and custom properties, uses HubSpot CRM API.
    async createContact(
      firstname: string, 
      lastname: string, 
      email?: string, 
      properties?: Record<string, any>
    ): Promise<any> {
      try {
        // Search for existing contacts with same name and company
        const company = properties?.company;
        
        // Use type assertion to satisfy the HubSpot API client types
        const searchRequest = {
          filterGroups: [{
            filters: [
              {
                propertyName: 'firstname',
                operator: 'EQ',
                value: firstname
              } as any,
              {
                propertyName: 'lastname',
                operator: 'EQ',
                value: lastname
              } as any
            ]
          }]
        } as any;
        
        // Add company filter if provided
        if (company) {
          searchRequest.filterGroups[0].filters.push({
            propertyName: 'company',
            operator: 'EQ',
            value: company
          } as any);
        }
        
        const searchResponse = await this.client.crm.contacts.searchApi.doSearch(searchRequest);
        
        if (searchResponse.total > 0) {
          // Contact already exists
          return { 
            message: 'Contact already exists', 
            contact: searchResponse.results[0] 
          };
        }
        
        // If no existing contact found, proceed with creation
        const contactProperties: Record<string, any> = {
          firstname,
          lastname
        };
        
        // Add email if provided
        if (email) {
          contactProperties.email = email;
        }
        
        // Add any additional properties
        if (properties) {
          Object.assign(contactProperties, properties);
        }
        
        // Create contact
        const apiResponse = await this.client.crm.contacts.basicApi.create({
          properties: contactProperties
        });
        
        return apiResponse;
      } catch (error: any) {
        console.error('Error creating contact:', error);
        throw new Error(`HubSpot API error: ${error.message}`);
      }
    }

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/lkm1developer/hubspot-mcp-server'

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