hubspot_create_company
Create a new company record in HubSpot CRM by specifying the company name and optional additional properties to organize business data.
Instructions
Create a new company in HubSpot
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Company name | |
| properties | No | Additional company properties |
Implementation Reference
- src/hubspot-client.ts:391-437 (handler)Core handler function that implements the logic to create a new HubSpot company after checking for duplicates.async createCompany(name: string, properties?: Record<string, any>): Promise<any> { try { // Search for existing companies with same name // Use type assertion to satisfy the HubSpot API client types const searchRequest = { filterGroups: [{ filters: [ { propertyName: 'name', operator: 'EQ', value: name } as any ] }] } as any; const searchResponse = await this.client.crm.companies.searchApi.doSearch(searchRequest); if (searchResponse.total > 0) { // Company already exists return { message: 'Company already exists', company: searchResponse.results[0] }; } // If no existing company found, proceed with creation const companyProperties: Record<string, any> = { name }; // Add any additional properties if (properties) { Object.assign(companyProperties, properties); } // Create company const apiResponse = await this.client.crm.companies.basicApi.create({ properties: companyProperties }); return apiResponse; } catch (error: any) { console.error('Error creating company:', error); throw new Error(`HubSpot API error: ${error.message}`); } }
- src/index.ts:107-124 (registration)Tool registration in the MCP server, defining name, description, and input schema.name: 'hubspot_create_company', description: 'Create a new company in HubSpot', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Company name' }, properties: { type: 'object', description: 'Additional company properties', additionalProperties: true } }, required: ['name'] } },
- src/index.ts:249-260 (handler)MCP tool call handler that dispatches to HubSpotClient.createCompany and formats the response.case 'hubspot_create_company': { const result = await this.hubspot.createCompany( args.name as string, args.properties as Record<string, any> | undefined ); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }