Skip to main content
Glama
ajaystream

HubSpot MCP Server

by ajaystream

hubspot-batch-create-associations

Idempotent

Create multiple relationships between HubSpot CRM objects in a single batch operation, linking records across different object types with consistent association types.

Instructions

🛡️ Guardrails:
  1.  Data Modification Warning: This tool modifies HubSpot data. Only use when the user has explicitly requested to update their CRM.

🎯 Purpose:
  1. Establishes relationships between HubSpot objects, linking records across different object types, by creating associations between objects in batch.
  2. Uses a single set of association types for all associations in the batch.

📋 Prerequisites:
  1. Use the hubspot-get-user-details tool to get the OwnerId and UserId if you don't have that already.
  2. Use the hubspot-get-association-definitions tool to identify valid association types before creating associations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromObjectTypeYesThe type of HubSpot object to create association from. 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.
toObjectTypeYesThe type of HubSpot object to create association to. 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.
typesYesThe types of associations to create
inputsYesList of association inputs defining the relationships to create. (max 100 associations per batch)

Implementation Reference

  • Implements the tool logic: maps types to each input, calls HubSpot CRM v4 associations batch create API endpoint, returns formatted response or error.
    async process(args) {
        try {
            // Add types to each input
            const inputs = args.inputs.map(input => ({
                ...input,
                types: args.types,
            }));
            const response = await this.client.post(`/crm/v4/associations/${args.fromObjectType}/${args.toObjectType}/batch/create`, {
                body: { inputs },
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response, null, 2),
                    },
                ],
            };
        }
        catch (error) {
            return {
                content: [
                    {
                        type: 'text',
                        text: `Error creating HubSpot associations: ${error instanceof Error ? error.message : String(error)}`,
                    },
                ],
                isError: true,
            };
        }
    }
  • Zod schemas for association types, inputs, and the main ObjectAssociationSchema defining the tool's input structure including object types, association types, and batch inputs.
    const AssociationTypeSchema = z.object({
        associationCategory: z.enum(['HUBSPOT_DEFINED', 'USER_DEFINED', 'INTEGRATOR_DEFINED']),
        associationTypeId: z.number().int().positive(),
    });
    const AssociationInputSchema = z.object({
        from: z.object({
            id: z.string().describe('The ID of the object to create association from'),
        }),
        to: z.object({
            id: z.string().describe('The ID of the object to create association to'),
        }),
    });
    const ObjectAssociationSchema = z.object({
        fromObjectType: z
            .string()
            .describe(`The type of HubSpot object to create association from. Valid values include: ${HUBSPOT_OBJECT_TYPES.join(', ')}. For custom objects, use the hubspot-get-schemas tool to get the objectType.`),
        toObjectType: z
            .string()
            .describe(`The type of HubSpot object to create association to. Valid values include: ${HUBSPOT_OBJECT_TYPES.join(', ')}. For custom objects, use the hubspot-get-schemas tool to get the objectType.`),
        types: z.array(AssociationTypeSchema).min(1).describe('The types of associations to create'),
        inputs: z
            .array(AssociationInputSchema)
            .min(1)
            .describe('List of association inputs defining the relationships to create. (max 100 associations per batch)'),
  • ToolDefinition object containing the tool name 'hubspot-batch-create-associations', detailed description, JSON schema from Zod, and annotations; passed to BaseTool constructor.
    const ToolDefinition = {
        name: 'hubspot-batch-create-associations',
        description: `
        🛡️ Guardrails:
          1.  Data Modification Warning: This tool modifies HubSpot data. Only use when the user has explicitly requested to update their CRM.
    
        🎯 Purpose:
          1. Establishes relationships between HubSpot objects, linking records across different object types, by creating associations between objects in batch.
          2. Uses a single set of association types for all associations in the batch.
    
        📋 Prerequisites:
          1. Use the hubspot-get-user-details tool to get the OwnerId and UserId if you don't have that already.
          2. Use the hubspot-get-association-definitions tool to identify valid association types before creating associations.
      `,
        inputSchema: zodToJsonSchema(ObjectAssociationSchema),
        annotations: {
            title: 'Create CRM Object Associations in Batch',
            readOnlyHint: false,
            destructiveHint: false,
            idempotentHint: true,
            openWorldHint: true,
        },
    };
  • Instantiates the BatchCreateAssociationsTool and registers it with the central tools registry.
    registerTool(new BatchCreateAssociationsTool());
Behavior4/5

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

The description adds valuable behavioral context beyond what annotations provide. While annotations indicate this is a non-destructive, idempotent write operation (readOnlyHint: false, destructiveHint: false, idempotentHint: true), the description warns about data modification and specifies a batch limit ('max 100 associations per batch') in the schema. However, it doesn't mention authentication requirements or rate limits, which would be helpful for a batch operation.

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 is well-structured with clear sections (Guardrails, Purpose, Prerequisites) and uses emojis for visual organization. Each sentence adds value, though the 'Purpose' section could be more concise by combining its two points into one sentence. Overall, it's appropriately sized for a batch operation tool with important prerequisites.

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?

Given the tool's complexity (batch association creation with 4 required parameters) and the absence of an output schema, the description provides good contextual coverage. It explains the tool's purpose, includes important warnings and prerequisites, and references sibling tools for obtaining necessary data. However, it doesn't describe what the tool returns or potential error conditions, which would be helpful since there's no output schema.

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 input schema already thoroughly documents all 4 parameters. The description doesn't add significant parameter semantics beyond what's in the schema, though it does mention 'Uses a single set of association types for all associations in the batch' which helps explain the 'types' parameter's purpose. This meets the baseline for high schema coverage.

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 explicitly states the tool 'Establishes relationships between HubSpot objects, linking records across different object types, by creating associations between objects in batch.' This provides a specific verb ('creates associations'), resource ('HubSpot objects'), and scope ('in batch'), clearly distinguishing it from sibling tools like hubspot-list-associations or hubspot-get-association-definitions.

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 description provides explicit guidance on when to use this tool versus alternatives. It includes a 'Data Modification Warning' stating to 'Only use when the user has explicitly requested to update their CRM,' and lists prerequisites that reference sibling tools (hubspot-get-user-details, hubspot-get-association-definitions) for obtaining necessary information before creating associations.

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