hubspot_get_active_companies
Retrieve recently active companies from HubSpot CRM to monitor business engagement and manage customer relationships.
Instructions
Get most recently active companies from HubSpot
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of companies to return (default: 10) |
Implementation Reference
- src/index.ts:285-293 (handler)MCP tool handler for 'hubspot_get_active_companies': delegates to HubSpotClient.getRecentCompanies with optional limit and returns JSON-formatted result.case 'hubspot_get_active_companies': { const result = await this.hubspot.getRecentCompanies(args.limit as number | undefined); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }
- src/index.ts:158-171 (registration)Registration of the 'hubspot_get_active_companies' tool in the MCP server, including name, description, and input schema.{ name: 'hubspot_get_active_companies', description: 'Get most recently active companies from HubSpot', inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Maximum number of companies to return (default: 10)', default: 10 } } } },
- src/index.ts:161-170 (schema)Input schema for 'hubspot_get_active_companies' tool: accepts optional 'limit' parameter (number, default 10).inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Maximum number of companies to return (default: 10)', default: 10 } } }
- src/hubspot-client.ts:44-63 (helper)Helper method implementing the core logic: searches HubSpot CRM companies sorted by 'lastmodifieddate' descending, retrieves specified properties, converts datetime fields, handles errors.async getRecentCompanies(limit: number = 10): Promise<any> { try { // Create search request with sort by lastmodifieddate const searchRequest = { sorts: ['lastmodifieddate:desc'], limit, properties: ['name', 'domain', 'website', 'phone', 'industry', 'hs_lastmodifieddate'] }; // Execute the search const searchResponse = await this.client.crm.companies.searchApi.doSearch(searchRequest); // Convert the response to a dictionary const companiesDict = searchResponse.results; return convertDatetimeFields(companiesDict); } catch (error: any) { console.error('Error getting recent companies:', error); return { error: error.message }; } }
- src/hubspot-client.ts:7-29 (helper)Utility helper to recursively convert Date objects to ISO strings in response objects, used by getRecentCompanies.export function convertDatetimeFields(obj: any): any { if (obj === null || obj === undefined) { return obj; } if (typeof obj === 'object') { if (obj instanceof Date) { return obj.toISOString(); } if (Array.isArray(obj)) { return obj.map(item => convertDatetimeFields(item)); } const result: Record<string, any> = {}; for (const [key, value] of Object.entries(obj)) { result[key] = convertDatetimeFields(value); } return result; } return obj; }