hubspot_get_active_contacts
Retrieve recently active contacts from HubSpot CRM to monitor engagement and manage customer relationships.
Instructions
Get most recently active contacts from HubSpot
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "hubspot_get_active_contacts"
}
}Input 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 function that performs a search on HubSpot CRM contacts API, sorted by lastmodifieddate descending to get active contacts, applies datetime conversion, handles 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:295-302 (handler)MCP tool call handler (switch case) that extracts arguments, calls HubSpotClient.getRecentContacts, and formats response as MCP content.
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/index.ts:172-185 (registration)Tool registration in ListToolsRequestSchema handler, defining name, description, and input schema.
{ 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:175-184 (schema)Input schema definition for the tool.
inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Maximum number of contacts to return (default: 10)', default: 10 } } } - src/hubspot-client.ts:7-29 (helper)Recursive utility function to convert any Date objects to ISO strings in the response data.
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; }