Skip to main content
Glama
products-tools.tsβ€’26.2 kB
/** * GoHighLevel Products API Tools for MCP Server * Provides comprehensive tools for managing products, prices, inventory, collections, and reviews */ import { // MCP Product Types MCPCreateProductParams, MCPUpdateProductParams, MCPListProductsParams, MCPGetProductParams, MCPDeleteProductParams, MCPCreatePriceParams, MCPUpdatePriceParams, MCPListPricesParams, MCPGetPriceParams, MCPDeletePriceParams, MCPBulkUpdateProductsParams, MCPListInventoryParams, MCPUpdateInventoryParams, MCPGetProductStoreStatsParams, MCPUpdateProductStoreParams, MCPCreateProductCollectionParams, MCPUpdateProductCollectionParams, MCPListProductCollectionsParams, MCPGetProductCollectionParams, MCPDeleteProductCollectionParams, MCPListProductReviewsParams, MCPGetReviewsCountParams, MCPUpdateProductReviewParams, MCPDeleteProductReviewParams, MCPBulkUpdateProductReviewsParams, // API Client Types GHLCreateProductRequest, GHLUpdateProductRequest, GHLListProductsRequest, GHLGetProductRequest, GHLDeleteProductRequest, GHLCreatePriceRequest, GHLUpdatePriceRequest, GHLListPricesRequest, GHLGetPriceRequest, GHLDeletePriceRequest, GHLBulkUpdateRequest, GHLListInventoryRequest, GHLUpdateInventoryRequest, GHLGetProductStoreStatsRequest, GHLUpdateProductStoreRequest, GHLCreateProductCollectionRequest, GHLUpdateProductCollectionRequest, GHLListProductCollectionsRequest, GHLGetProductCollectionRequest, GHLDeleteProductCollectionRequest, GHLListProductReviewsRequest, GHLGetReviewsCountRequest, GHLUpdateProductReviewRequest, GHLDeleteProductReviewRequest, GHLBulkUpdateProductReviewsRequest } from '../types/ghl-types.js'; import { GHLApiClient } from '../clients/ghl-api-client.js'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; export interface ProductsToolResult { content: { type: 'text'; text: string; }[]; } export class ProductsTools { constructor(private apiClient: GHLApiClient) {} // Product Operations async createProduct(params: MCPCreateProductParams): Promise<ProductsToolResult> { try { const request: GHLCreateProductRequest = { ...params, locationId: params.locationId || this.apiClient.getConfig().locationId }; const response = await this.apiClient.createProduct(request); if (!response.data) { throw new Error('No data returned from API'); } return { content: [{ type: 'text', text: `πŸ›οΈ **Product Created Successfully!** πŸ“¦ **Product Details:** β€’ **ID:** ${response.data._id} β€’ **Name:** ${response.data.name} β€’ **Type:** ${response.data.productType} β€’ **Location:** ${response.data.locationId} β€’ **Available in Store:** ${response.data.availableInStore ? 'βœ… Yes' : '❌ No'} β€’ **Created:** ${new Date(response.data.createdAt).toLocaleString()} ${response.data.description ? `πŸ“ **Description:** ${response.data.description}` : ''} ${response.data.image ? `πŸ–ΌοΈ **Image:** ${response.data.image}` : ''} ${response.data.collectionIds?.length ? `πŸ“‚ **Collections:** ${response.data.collectionIds.length} assigned` : ''} ${response.data.variants?.length ? `πŸ”§ **Variants:** ${response.data.variants.length} configured` : ''} ${response.data.medias?.length ? `πŸ“Έ **Media Files:** ${response.data.medias.length} attached` : ''} ✨ **Status:** Product successfully created and ready for configuration!` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ **Error Creating Product**\n\n${error instanceof Error ? error.message : 'Unknown error occurred'}` }] }; } } async listProducts(params: MCPListProductsParams): Promise<ProductsToolResult> { try { const request: GHLListProductsRequest = { ...params, locationId: params.locationId || this.apiClient.getConfig().locationId }; const response = await this.apiClient.listProducts(request); if (!response.data) { throw new Error('No data returned from API'); } const products = response.data.products; const total = response.data.total[0]?.total || 0; return { content: [{ type: 'text', text: `πŸ›οΈ **Products List** (${products.length} of ${total} total) ${products.length === 0 ? 'πŸ“­ **No products found**' : products.map((product, index) => ` **${index + 1}. ${product.name}** (${product.productType}) β€’ **ID:** ${product._id} β€’ **Store Status:** ${product.availableInStore ? 'βœ… Available' : '❌ Not Available'} β€’ **Created:** ${new Date(product.createdAt).toLocaleString()} ${product.description ? `β€’ **Description:** ${product.description.substring(0, 100)}${product.description.length > 100 ? '...' : ''}` : ''} ${product.collectionIds?.length ? `β€’ **Collections:** ${product.collectionIds.length}` : ''} `).join('\n')} πŸ“Š **Summary:** β€’ **Total Products:** ${total} β€’ **Displayed:** ${products.length} ${params.search ? `β€’ **Search:** "${params.search}"` : ''} ${params.storeId ? `β€’ **Store Filter:** ${params.storeId}` : ''} ${params.includedInStore !== undefined ? `β€’ **Store Status:** ${params.includedInStore ? 'Included only' : 'Excluded only'}` : ''}` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ **Error Listing Products**\n\n${error instanceof Error ? error.message : 'Unknown error occurred'}` }] }; } } getTools(): Tool[] { return [ // Product Management Tools { name: 'ghl_create_product', description: 'Create a new product in GoHighLevel', inputSchema: { type: 'object', properties: { locationId: { type: 'string', description: 'GHL Location ID (optional, uses default if not provided)' }, name: { type: 'string', description: 'Product name' }, productType: { type: 'string', enum: ['DIGITAL', 'PHYSICAL', 'SERVICE', 'PHYSICAL/DIGITAL'], description: 'Type of product' }, description: { type: 'string', description: 'Product description' }, image: { type: 'string', description: 'Product image URL' }, availableInStore: { type: 'boolean', description: 'Whether product is available in store' }, slug: { type: 'string', description: 'Product URL slug' } }, required: ['name', 'productType'] } }, { name: 'ghl_list_products', description: 'List products with optional filtering', inputSchema: { type: 'object', properties: { locationId: { type: 'string', description: 'GHL Location ID (optional, uses default if not provided)' }, limit: { type: 'number', description: 'Maximum number of products to return' }, offset: { type: 'number', description: 'Number of products to skip' }, search: { type: 'string', description: 'Search term for product names' }, storeId: { type: 'string', description: 'Filter by store ID' }, includedInStore: { type: 'boolean', description: 'Filter by store inclusion status' }, availableInStore: { type: 'boolean', description: 'Filter by store availability' } }, required: [] } }, { name: 'ghl_get_product', description: 'Get a specific product by ID', inputSchema: { type: 'object', properties: { productId: { type: 'string', description: 'Product ID to retrieve' }, locationId: { type: 'string', description: 'GHL Location ID (optional, uses default if not provided)' } }, required: ['productId'] } }, { name: 'ghl_update_product', description: 'Update an existing product', inputSchema: { type: 'object', properties: { productId: { type: 'string', description: 'Product ID to update' }, locationId: { type: 'string', description: 'GHL Location ID (optional, uses default if not provided)' }, name: { type: 'string', description: 'Product name' }, productType: { type: 'string', enum: ['DIGITAL', 'PHYSICAL', 'SERVICE', 'PHYSICAL/DIGITAL'], description: 'Type of product' }, description: { type: 'string', description: 'Product description' }, image: { type: 'string', description: 'Product image URL' }, availableInStore: { type: 'boolean', description: 'Whether product is available in store' } }, required: ['productId'] } }, { name: 'ghl_delete_product', description: 'Delete a product by ID', inputSchema: { type: 'object', properties: { productId: { type: 'string', description: 'Product ID to delete' }, locationId: { type: 'string', description: 'GHL Location ID (optional, uses default if not provided)' } }, required: ['productId'] } }, // Price Management Tools { name: 'ghl_create_price', description: 'Create a price for a product', inputSchema: { type: 'object', properties: { productId: { type: 'string', description: 'Product ID to create price for' }, name: { type: 'string', description: 'Price name/variant name' }, type: { type: 'string', enum: ['one_time', 'recurring'], description: 'Price type' }, currency: { type: 'string', description: 'Currency code (e.g., USD)' }, amount: { type: 'number', description: 'Price amount in cents' }, locationId: { type: 'string', description: 'GHL Location ID (optional, uses default if not provided)' }, compareAtPrice: { type: 'number', description: 'Compare at price (for discounts)' } }, required: ['productId', 'name', 'type', 'currency', 'amount'] } }, { name: 'ghl_list_prices', description: 'List prices for a product', inputSchema: { type: 'object', properties: { productId: { type: 'string', description: 'Product ID to list prices for' }, locationId: { type: 'string', description: 'GHL Location ID (optional, uses default if not provided)' }, limit: { type: 'number', description: 'Maximum number of prices to return' }, offset: { type: 'number', description: 'Number of prices to skip' } }, required: ['productId'] } }, // Inventory Tools { name: 'ghl_list_inventory', description: 'List inventory items with stock levels', inputSchema: { type: 'object', properties: { locationId: { type: 'string', description: 'GHL Location ID (optional, uses default if not provided)' }, limit: { type: 'number', description: 'Maximum number of items to return' }, offset: { type: 'number', description: 'Number of items to skip' }, search: { type: 'string', description: 'Search term for inventory items' } }, required: [] } }, // Collection Tools { name: 'ghl_create_product_collection', description: 'Create a new product collection', inputSchema: { type: 'object', properties: { locationId: { type: 'string', description: 'GHL Location ID (optional, uses default if not provided)' }, name: { type: 'string', description: 'Collection name' }, slug: { type: 'string', description: 'Collection URL slug' }, image: { type: 'string', description: 'Collection image URL' }, seo: { type: 'object', properties: { title: { type: 'string', description: 'SEO title' }, description: { type: 'string', description: 'SEO description' } } } }, required: ['name', 'slug'] } }, { name: 'ghl_list_product_collections', description: 'List product collections', inputSchema: { type: 'object', properties: { locationId: { type: 'string', description: 'GHL Location ID (optional, uses default if not provided)' }, limit: { type: 'number', description: 'Maximum number of collections to return' }, offset: { type: 'number', description: 'Number of collections to skip' }, name: { type: 'string', description: 'Search by collection name' } }, required: [] } } ]; } async executeProductsTool(toolName: string, params: any): Promise<ProductsToolResult> { switch (toolName) { case 'ghl_create_product': return this.createProduct(params as MCPCreateProductParams); case 'ghl_list_products': return this.listProducts(params as MCPListProductsParams); case 'ghl_get_product': return this.getProduct(params as MCPGetProductParams); case 'ghl_update_product': return this.updateProduct(params as MCPUpdateProductParams); case 'ghl_delete_product': return this.deleteProduct(params as MCPDeleteProductParams); case 'ghl_create_price': return this.createPrice(params as MCPCreatePriceParams); case 'ghl_list_prices': return this.listPrices(params as MCPListPricesParams); case 'ghl_list_inventory': return this.listInventory(params as MCPListInventoryParams); case 'ghl_create_product_collection': return this.createProductCollection(params as MCPCreateProductCollectionParams); case 'ghl_list_product_collections': return this.listProductCollections(params as MCPListProductCollectionsParams); default: return { content: [{ type: 'text', text: `❌ **Unknown Products Tool**: ${toolName}` }] }; } } // Additional Product Operations async getProduct(params: MCPGetProductParams): Promise<ProductsToolResult> { try { const response = await this.apiClient.getProduct( params.productId, params.locationId || this.apiClient.getConfig().locationId ); if (!response.data) { throw new Error('No data returned from API'); } return { content: [{ type: 'text', text: `πŸ›οΈ **Product Details** πŸ“¦ **${response.data.name}** (${response.data.productType}) β€’ **ID:** ${response.data._id} β€’ **Location:** ${response.data.locationId} β€’ **Available in Store:** ${response.data.availableInStore ? 'βœ… Yes' : '❌ No'} β€’ **Created:** ${new Date(response.data.createdAt).toLocaleString()} β€’ **Updated:** ${new Date(response.data.updatedAt).toLocaleString()} ${response.data.description ? `πŸ“ **Description:** ${response.data.description}` : ''} ${response.data.image ? `πŸ–ΌοΈ **Image:** ${response.data.image}` : ''} ${response.data.slug ? `πŸ”— **Slug:** ${response.data.slug}` : ''} ${response.data.collectionIds?.length ? `πŸ“‚ **Collections:** ${response.data.collectionIds.length} assigned` : ''} ${response.data.variants?.length ? `πŸ”§ **Variants:** ${response.data.variants.length} configured` : ''} ${response.data.medias?.length ? `πŸ“Έ **Media Files:** ${response.data.medias.length} attached` : ''} ${response.data.isTaxesEnabled ? `πŸ’° **Taxes:** Enabled` : ''} ${response.data.isLabelEnabled ? `🏷️ **Labels:** Enabled` : ''}` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ **Error Getting Product**\n\n${error instanceof Error ? error.message : 'Unknown error occurred'}` }] }; } } async updateProduct(params: MCPUpdateProductParams): Promise<ProductsToolResult> { try { const request: GHLUpdateProductRequest = { ...params, locationId: params.locationId || this.apiClient.getConfig().locationId }; const response = await this.apiClient.updateProduct(params.productId, request); if (!response.data) { throw new Error('No data returned from API'); } return { content: [{ type: 'text', text: `βœ… **Product Updated Successfully!** πŸ“¦ **Updated Product:** β€’ **ID:** ${response.data._id} β€’ **Name:** ${response.data.name} β€’ **Type:** ${response.data.productType} β€’ **Available in Store:** ${response.data.availableInStore ? 'βœ… Yes' : '❌ No'} β€’ **Last Updated:** ${new Date(response.data.updatedAt).toLocaleString()} πŸ”„ **Product has been successfully updated with the new information!**` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ **Error Updating Product**\n\n${error instanceof Error ? error.message : 'Unknown error occurred'}` }] }; } } async deleteProduct(params: MCPDeleteProductParams): Promise<ProductsToolResult> { try { const response = await this.apiClient.deleteProduct( params.productId, params.locationId || this.apiClient.getConfig().locationId ); if (!response.data) { throw new Error('No data returned from API'); } return { content: [{ type: 'text', text: `πŸ—‘οΈ **Product Deleted Successfully!** βœ… **Status:** ${response.data.status ? 'Product successfully deleted' : 'Deletion failed'} πŸ—‚οΈ **Product ID:** ${params.productId} ⚠️ **Note:** This action cannot be undone. The product and all associated data have been permanently removed.` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ **Error Deleting Product**\n\n${error instanceof Error ? error.message : 'Unknown error occurred'}` }] }; } } async createPrice(params: MCPCreatePriceParams): Promise<ProductsToolResult> { try { const request: GHLCreatePriceRequest = { ...params, locationId: params.locationId || this.apiClient.getConfig().locationId }; const response = await this.apiClient.createPrice(params.productId, request); if (!response.data) { throw new Error('No data returned from API'); } return { content: [{ type: 'text', text: `πŸ’° **Price Created Successfully!** 🏷️ **Price Details:** β€’ **ID:** ${response.data._id} β€’ **Name:** ${response.data.name} β€’ **Type:** ${response.data.type} β€’ **Amount:** ${response.data.amount / 100} ${response.data.currency} β€’ **Product ID:** ${response.data.product} β€’ **Created:** ${new Date(response.data.createdAt).toLocaleString()} ${response.data.compareAtPrice ? `πŸ’Έ **Compare At:** ${response.data.compareAtPrice / 100} ${response.data.currency}` : ''} ${response.data.recurring ? `πŸ”„ **Recurring:** ${response.data.recurring.intervalCount} ${response.data.recurring.interval}(s)` : ''} ${response.data.sku ? `πŸ“¦ **SKU:** ${response.data.sku}` : ''} ✨ **Price is ready for use in your product catalog!**` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ **Error Creating Price**\n\n${error instanceof Error ? error.message : 'Unknown error occurred'}` }] }; } } async listPrices(params: MCPListPricesParams): Promise<ProductsToolResult> { try { const request: GHLListPricesRequest = { ...params, locationId: params.locationId || this.apiClient.getConfig().locationId }; const response = await this.apiClient.listPrices(params.productId, request); if (!response.data) { throw new Error('No data returned from API'); } const prices = response.data.prices; return { content: [{ type: 'text', text: `πŸ’° **Product Prices** (${prices.length} of ${response.data.total} total) ${prices.length === 0 ? 'πŸ“­ **No prices found**' : prices.map((price, index) => ` **${index + 1}. ${price.name}** (${price.type}) β€’ **ID:** ${price._id} β€’ **Amount:** ${price.amount / 100} ${price.currency} ${price.compareAtPrice ? `β€’ **Compare At:** ${price.compareAtPrice / 100} ${price.currency}` : ''} ${price.recurring ? `β€’ **Recurring:** ${price.recurring.intervalCount} ${price.recurring.interval}(s)` : ''} ${price.sku ? `β€’ **SKU:** ${price.sku}` : ''} β€’ **Created:** ${new Date(price.createdAt).toLocaleString()} `).join('\n')} πŸ“Š **Summary:** β€’ **Total Prices:** ${response.data.total} β€’ **Product ID:** ${params.productId}` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ **Error Listing Prices**\n\n${error instanceof Error ? error.message : 'Unknown error occurred'}` }] }; } } async listInventory(params: MCPListInventoryParams): Promise<ProductsToolResult> { try { const request: GHLListInventoryRequest = { altId: params.locationId || this.apiClient.getConfig().locationId, altType: 'location', ...params }; const response = await this.apiClient.listInventory(request); if (!response.data) { throw new Error('No data returned from API'); } const inventory = response.data.inventory; const total = response.data.total.total; return { content: [{ type: 'text', text: `πŸ“¦ **Inventory Items** (${inventory.length} of ${total} total) ${inventory.length === 0 ? 'πŸ“­ **No inventory items found**' : inventory.map((item, index) => ` **${index + 1}. ${item.name}** ${item.productName ? `(${item.productName})` : ''} β€’ **ID:** ${item._id} β€’ **Available Quantity:** ${item.availableQuantity} β€’ **SKU:** ${item.sku || 'N/A'} β€’ **Out of Stock Purchases:** ${item.allowOutOfStockPurchases ? 'βœ… Allowed' : '❌ Not Allowed'} β€’ **Product ID:** ${item.product} β€’ **Last Updated:** ${new Date(item.updatedAt).toLocaleString()} ${item.image ? `β€’ **Image:** ${item.image}` : ''} `).join('\n')} πŸ“Š **Summary:** β€’ **Total Items:** ${total} β€’ **Displayed:** ${inventory.length} ${params.search ? `β€’ **Search:** "${params.search}"` : ''}` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ **Error Listing Inventory**\n\n${error instanceof Error ? error.message : 'Unknown error occurred'}` }] }; } } async createProductCollection(params: MCPCreateProductCollectionParams): Promise<ProductsToolResult> { try { const request: GHLCreateProductCollectionRequest = { ...params, altId: params.locationId || this.apiClient.getConfig().locationId, altType: 'location' }; const response = await this.apiClient.createProductCollection(request); if (!response.data?.data) { throw new Error('No data returned from API'); } return { content: [{ type: 'text', text: `πŸ“‚ **Product Collection Created Successfully!** 🏷️ **Collection Details:** β€’ **ID:** ${response.data.data._id} β€’ **Name:** ${response.data.data.name} β€’ **Slug:** ${response.data.data.slug} β€’ **Location:** ${response.data.data.altId} β€’ **Created:** ${new Date(response.data.data.createdAt).toLocaleString()} ${response.data.data.image ? `πŸ–ΌοΈ **Image:** ${response.data.data.image}` : ''} ${response.data.data.seo?.title ? `πŸ” **SEO Title:** ${response.data.data.seo.title}` : ''} ${response.data.data.seo?.description ? `πŸ“ **SEO Description:** ${response.data.data.seo.description}` : ''} ✨ **Collection is ready to organize your products!**` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ **Error Creating Collection**\n\n${error instanceof Error ? error.message : 'Unknown error occurred'}` }] }; } } async listProductCollections(params: MCPListProductCollectionsParams): Promise<ProductsToolResult> { try { const request: GHLListProductCollectionsRequest = { ...params, altId: params.locationId || this.apiClient.getConfig().locationId, altType: 'location' }; const response = await this.apiClient.listProductCollections(request); if (!response.data?.data) { throw new Error('No data returned from API'); } const collections = response.data.data; return { content: [{ type: 'text', text: `πŸ“‚ **Product Collections** (${collections.length} of ${response.data.total} total) ${collections.length === 0 ? 'πŸ“­ **No collections found**' : collections.map((collection: any, index: number) => ` **${index + 1}. ${collection.name}** β€’ **ID:** ${collection._id} β€’ **Slug:** ${collection.slug} ${collection.image ? `β€’ **Image:** ${collection.image}` : ''} ${collection.seo?.title ? `β€’ **SEO Title:** ${collection.seo.title}` : ''} β€’ **Created:** ${new Date(collection.createdAt).toLocaleString()} `).join('\n')} πŸ“Š **Summary:** β€’ **Total Collections:** ${response.data.total} β€’ **Displayed:** ${collections.length} ${params.name ? `β€’ **Search:** "${params.name}"` : ''}` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ **Error Listing Collections**\n\n${error instanceof Error ? error.message : 'Unknown error occurred'}` }] }; } } }

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/cpretzinger/GoHighLevel-MCP'

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