Skip to main content
Glama

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of contacts to return (default: 10)

Implementation Reference

  • 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 }; } }
  • 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 } } } },
  • Input schema definition for the tool.
    inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Maximum number of contacts to return (default: 10)', default: 10 } } }
  • 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; }

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