hubspot_get_active_contacts
Retrieve recently active contacts from HubSpot CRM to monitor engagement and manage customer relationships effectively.
Instructions
Get most recently active contacts from HubSpot
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of contacts to return (default: 10) |
Implementation Reference
- src/hubspot-client.ts:65-84 (handler)Core handler implementation: Searches HubSpot CRM contacts sorted by lastmodifieddate descending, returns top 'limit' (default 10) with key properties, handles datetime conversion and errors.async getRecentContacts(limit: number = 10): Promise<any> { try { // Create search request with sort by lastmodifieddate const searchRequest = { sorts: ['lastmodifieddate:desc'], limit, properties: ['firstname', 'lastname', 'email', 'phone', 'company', 'hs_lastmodifieddate', 'lastmodifieddate'] }; // Execute the search const searchResponse = await this.client.crm.contacts.searchApi.doSearch(searchRequest); // Convert the response to a dictionary const contactsDict = searchResponse.results; return convertDatetimeFields(contactsDict); } catch (error: any) { console.error('Error getting recent contacts:', error); return { error: error.message }; } }
- src/index.ts:172-185 (schema)MCP tool schema definition including name, description, and inputSchema with optional 'limit' parameter.{ name: 'hubspot_get_active_contacts', description: 'Get most recently active contacts from HubSpot', inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Maximum number of contacts to return (default: 10)', default: 10 } } } },
- src/index.ts:295-302 (registration)Tool handler registration in MCP CallToolRequestSchema: extracts 'limit' arg, calls HubSpotClient.getRecentContacts, returns JSON stringified result.case 'hubspot_get_active_contacts': { const result = await this.hubspot.getRecentContacts(args.limit as number | undefined); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
- src/hubspot-client.ts:7-29 (helper)Helper utility to recursively convert Date objects to ISO strings in API responses, used by getRecentContacts.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; }