Skip to main content
Glama
ajaystream

HubSpot MCP Server

by ajaystream

hubspot-refresh-token

Idempotent

Refresh HubSpot OAuth access tokens when API requests fail due to expiration, automatically updating the active token for continued API access.

Instructions

🔄 Refreshes the HubSpot OAuth access token using the refresh token from environment variables.

🎯 Purpose:
- Use only when HubSpot API requests fail due to expired tokens.
- Automatically refreshes and sets the active access token in process.env.PRIVATE_APP_ACCESS_TOKEN.
- Not required for long-lived Private App tokens.

🛡️ Guardrails:
- Only use if using OAuth (i.e. REFRESH_TOKEN is present in environment).
- Do not invoke more than once per session unless a 401 Unauthorized response is received from HubSpot API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Executes the token refresh logic: validates environment variables, makes POST request to HubSpot OAuth endpoint, updates process.env.PRIVATE_APP_ACCESS_TOKEN on success, returns structured response.
    async process() {
      const { CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN } = process.env;
    
      if (!CLIENT_ID || !CLIENT_SECRET || !REFRESH_TOKEN) {
        return {
          content: [
            {
              type: 'text',
              text: '❌ Missing CLIENT_ID, CLIENT_SECRET, or REFRESH_TOKEN in environment.',
            },
          ],
          isError: true,
        };
      }
    
      try {
        const res = await fetch('https://api.hubapi.com/oauth/v1/token', {
          method: 'POST',
          headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
          body: new URLSearchParams({
            grant_type: 'refresh_token',
            client_id: CLIENT_ID,
            client_secret: CLIENT_SECRET,
            refresh_token: REFRESH_TOKEN,
          }),
        });
    
        const json = await res.json();
    
        if (!res.ok) {
          throw new Error(json.message || 'Token refresh failed');
        }
    
        process.env.PRIVATE_APP_ACCESS_TOKEN = json.access_token;
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                access_token: json.access_token,
                expires_in: json.expires_in,
                refresh_token: json.refresh_token,
              }, null, 2),
            },
          ],
        };
      } catch (err) {
        return {
          content: [
            {
              type: 'text',
              text: `❌ Token refresh failed: ${err instanceof Error ? err.message : String(err)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Registers an instance of the RefreshTokenTool with the central tool registry.
    registerTool(new RefreshTokenTool());
  • Defines the Zod input schema (empty object, relies on env vars) and ToolDefinition object with name, description, JSON schema for inputs, and annotations passed to BaseTool constructor.
    const RefreshTokenSchema = z.object({}); // No inputs — uses environment variables
    
    const ToolDefinition = {
      name: 'hubspot-refresh-token',
      description: `
        🔄 Refreshes the HubSpot OAuth access token using the refresh token from environment variables.
    
        🎯 Purpose:
        - Use only when HubSpot API requests fail due to expired tokens.
        - Automatically refreshes and sets the active access token in process.env.PRIVATE_APP_ACCESS_TOKEN.
        - Not required for long-lived Private App tokens.
    
        🛡️ Guardrails:
        - Only use if using OAuth (i.e. REFRESH_TOKEN is present in environment).
        - Do not invoke more than once per session unless a 401 Unauthorized response is received from HubSpot API.
      `,
      inputSchema: zodToJsonSchema(RefreshTokenSchema),
      annotations: {
        title: 'Refresh HubSpot OAuth Token',
        readOnlyHint: false,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: false,
      },
    };
Behavior4/5

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

The description adds valuable behavioral context beyond annotations: it explains the tool automatically sets the refreshed token in process.env.PRIVATE_APP_ACCESS_TOKEN (an important side effect), specifies rate limiting guidance ('do not invoke more than once per session'), and clarifies authentication requirements. Annotations already indicate idempotent and non-destructive, but the description provides practical usage constraints that aren't captured in structured fields.

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

Conciseness5/5

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

The description is efficiently structured with emoji-labeled sections (🔄, 🎯, 🛡️) that make it scannable. Each sentence adds value: the first states the core action, the Purpose section provides usage context, and the Guardrails section adds important constraints. There's no wasted text or redundancy.

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

Completeness5/5

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

For a parameterless token refresh tool with comprehensive annotations (idempotent, non-destructive) and no output schema, the description provides complete context. It covers when to use, prerequisites, behavioral effects (sets environment variable), and usage constraints. The combination of structured annotations and descriptive text gives the agent everything needed to use this tool correctly.

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

Parameters4/5

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

The tool has zero parameters with 100% schema description coverage, so the baseline would be 4. The description appropriately doesn't discuss parameters since none exist, and instead focuses on the tool's operational context and effects, which is the right approach for a parameterless tool.

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 specific action ('refreshes the HubSpot OAuth access token') and resource ('using the refresh token from environment variables'). It distinguishes this tool from all sibling tools, which perform CRUD operations on HubSpot data objects rather than token management.

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 ('when HubSpot API requests fail due to expired tokens'), when not to use ('not required for long-lived Private App tokens'), and prerequisites ('only use if using OAuth with REFRESH_TOKEN present'). It also specifies an alternative scenario ('do not invoke more than once per session unless a 401 Unauthorized response is received').

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