Skip to main content
Glama
ajaystream

HubSpot MCP Server

by ajaystream

hubspot-search-objects

Read-only

Search HubSpot CRM objects using advanced filters and criteria to retrieve targeted data with pagination support.

Instructions

🎯 Purpose:
  1. Performs advanced filtered searches across HubSpot object types using complex criteria.

📋 Prerequisites:
  1. Use the hubspot-list-objects tool to sample existing objects for the object type.
  2. If hubspot-list-objects tool's response isn't helpful, use hubspot-list-properties tool.

📦 Returns:
  1. Filtered collection matching specific criteria with pagination information.

🧭 Usage Guidance:
  1. Preferred for targeted data retrieval when exact filtering criteria are known. Supports complex boolean logic through filter groups.
  2. Use hubspot-list-objects when filter criteria is not specified or clear or when a search fails.
  3. Use hubspot-batch-read-objects to retrieve specific objects by their IDs.
  4. Use hubspot-list-associations to get the associations between objects.

🔍 Filtering Capabilities:
  1. Think of "filterGroups" as separate search conditions that you want to combine with OR logic (meaning ANY of them can match).
  2. If you want to find things that match ALL of several conditions (AND logic), put those conditions together in the same filters list.
  3. If you want to find things that match AT LEAST ONE of several conditions (OR logic), put each condition in a separate filterGroup.
  4. You can include a maximum of five filterGroups with up to 6 filters in each group, with a maximum of 18 filters in total.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
objectTypeYesThe type of HubSpot object to search. Valid values include: appointments, companies, contacts, courses, deals, leads, line_items, listings, marketing_events, meetings, orders, postal_mail, products, quotes, services, subscriptions, tickets, users. For custom objects, use the hubspot-get-schemas tool to get the objectType.
queryNoText to search across default searchable properties of the specified object type. Each object type has different searchable properties. For example: contacts (firstname, lastname, email, phone, company), companies (name, website, domain, phone), deals (dealname, pipeline, dealstage, description, dealtype), etc
limitNoThe maximum number of results to display per page (max: 100).
afterNoThe paging cursor token of the last successfully read resource.
propertiesNoA list of the properties to be returned in the response.
sortsNoA list of sort criteria to apply to the results.
filterGroupsNoGroups of filters to apply (combined with OR).

Implementation Reference

  • Executes the HubSpot CRM object search by constructing a request body from input parameters, calling the HubSpot API search endpoint, and formatting the response with results and pagination.
    async process(args) {
        try {
            const { query, limit, after, properties, sorts, filterGroups } = args;
            const requestBody = {
                query,
                limit,
                after,
                properties: properties && properties.length > 0 ? properties : undefined,
                sorts: sorts && sorts.length > 0 ? sorts : undefined,
                filterGroups: filterGroups && filterGroups.length > 0 ? filterGroups : undefined,
            };
            const cleanRequestBody = Object.fromEntries(Object.entries(requestBody).filter(([_, value]) => value !== undefined));
            const response = await this.client.post(`/crm/v3/objects/${args.objectType}/search`, {
                body: cleanRequestBody,
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({
                            results: response.results.map(item => ({
                                id: item.id,
                                properties: item.properties,
                                createdAt: item.createdAt,
                                updatedAt: item.updatedAt,
                                archived: item.archived,
                                archivedAt: item.archivedAt,
                            })),
                            paging: response.paging,
                        }, null, 2),
                    },
                ],
            };
        }
        catch (error) {
            return {
                content: [
                    {
                        type: 'text',
                        text: `Error searching HubSpot ${args.objectType}: ${error instanceof Error ? error.message : String(error)}`,
                    },
                ],
                isError: true,
            };
        }
    }
  • Zod schema defining the input parameters for the tool, including objectType, query, limit, pagination, properties, sorts, and complex filterGroups.
    const ObjectSearchSchema = z.object({
        objectType: z
            .string()
            .describe(`The type of HubSpot object to search. Valid values include: ${HUBSPOT_OBJECT_TYPES.join(', ')}. For custom objects, use the hubspot-get-schemas tool to get the objectType.`),
        query: z
            .string()
            .optional()
            .describe('Text to search across default searchable properties of the specified object type. Each object type has different searchable properties. For example: contacts (firstname, lastname, email, phone, company), companies (name, website, domain, phone), deals (dealname, pipeline, dealstage, description, dealtype), etc'),
        limit: z
            .number()
            .int()
            .min(1)
            .max(100)
            .default(10)
            .describe('The maximum number of results to display per page (max: 100).'),
        after: z
            .string()
            .optional()
            .describe('The paging cursor token of the last successfully read resource.'),
        properties: z
            .array(z.string())
            .optional()
            .describe('A list of the properties to be returned in the response.'),
        sorts: z
            .array(SortSchema)
            .optional()
            .describe('A list of sort criteria to apply to the results.'),
        filterGroups: z
            .array(FilterGroupSchema)
            .optional()
            .describe('Groups of filters to apply (combined with OR).'),
    });
  • Registers an instance of the ObjectSearchTool (which implements hubspot-search-objects) with the central tools registry.
    registerTool(new ObjectSearchTool());
  • Tool definition object containing the name 'hubspot-search-objects', detailed description, JSON schema from Zod, and annotations passed to BaseTool constructor.
    const ToolDefinition = {
        name: 'hubspot-search-objects',
        description: `
        🎯 Purpose:
          1. Performs advanced filtered searches across HubSpot object types using complex criteria.
    
        📋 Prerequisites:
          1. Use the hubspot-list-objects tool to sample existing objects for the object type.
          2. If hubspot-list-objects tool's response isn't helpful, use hubspot-list-properties tool.
    
        📦 Returns:
          1. Filtered collection matching specific criteria with pagination information.
    
        🧭 Usage Guidance:
          1. Preferred for targeted data retrieval when exact filtering criteria are known. Supports complex boolean logic through filter groups.
          2. Use hubspot-list-objects when filter criteria is not specified or clear or when a search fails.
          3. Use hubspot-batch-read-objects to retrieve specific objects by their IDs.
          4. Use hubspot-list-associations to get the associations between objects.
    
        🔍 Filtering Capabilities:
          1. Think of "filterGroups" as separate search conditions that you want to combine with OR logic (meaning ANY of them can match).
          2. If you want to find things that match ALL of several conditions (AND logic), put those conditions together in the same filters list.
          3. If you want to find things that match AT LEAST ONE of several conditions (OR logic), put each condition in a separate filterGroup.
          4. You can include a maximum of five filterGroups with up to 6 filters in each group, with a maximum of 18 filters in total.
      `,
        inputSchema: zodToJsonSchema(ObjectSearchSchema),
        annotations: {
            title: 'Search CRM Objects',
            readOnlyHint: true,
            destructiveHint: false,
            idempotentHint: false,
            openWorldHint: true,
        },
    };
  • Imports the ObjectSearchTool class required for registration.
    import { ObjectSearchTool } from './objects/searchObjectsTool.js';
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already provide readOnlyHint=true and destructiveHint=false, indicating safe read operations. The description adds valuable behavioral context beyond annotations: pagination information in returns, complex boolean logic capabilities, and specific limits (max 5 filterGroups, 6 filters per group, 18 total filters). It doesn't mention rate limits or authentication needs, but provides substantial operational guidance.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description uses clear section headers (🎯 Purpose, 📋 Prerequisites, etc.) and is appropriately front-loaded with purpose. While comprehensive, some sections could be more concise - the filtering capabilities explanation is detailed but could be streamlined. Overall structure is logical with minimal wasted text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex search tool with 7 parameters, 100% schema coverage, and no output schema, the description provides excellent contextual completeness. It covers purpose, prerequisites, returns, usage guidance, and filtering capabilities. The main gap is lack of output format details, but given the annotations and comprehensive parameter documentation, this is a minor omission.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the baseline is 3. The description adds some semantic context for filterGroups (explaining OR/AND logic relationships) and mentions the 'query' parameter searches 'default searchable properties,' but doesn't significantly enhance understanding of individual parameters beyond what's already well-documented in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool performs 'advanced filtered searches across HubSpot object types using complex criteria.' This specifies both the verb ('searches') and resource ('HubSpot object types') while distinguishing it from simpler list tools through the 'advanced filtered' and 'complex criteria' qualifiers.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The 'Usage Guidance' section explicitly states when to use this tool ('targeted data retrieval when exact filtering criteria are known') and provides three specific alternatives: hubspot-list-objects (when filter criteria unclear), hubspot-batch-read-objects (for retrieval by IDs), and hubspot-list-associations (for associations). It also includes prerequisites for sampling objects.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/ajaystream/hubspot-mcp-custom'

If you have feedback or need assistance with the MCP directory API, please join our Discord server