UNPKG

ghl-mcp-server

Version:

GoHighLevel MCP Server for Claude Desktop and ChatGPT integration

617 lines (593 loc) • 27.1 kB
"use strict"; /** * GoHighLevel Products API Tools for MCP Server * Provides comprehensive tools for managing products, prices, inventory, collections, and reviews */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ProductsTools = void 0; class ProductsTools { apiClient; constructor(apiClient) { this.apiClient = apiClient; } // Product Operations async createProduct(params) { try { const request = { ...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) { try { const request = { ...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() { 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, params) { switch (toolName) { case 'ghl_create_product': return this.createProduct(params); case 'ghl_list_products': return this.listProducts(params); case 'ghl_get_product': return this.getProduct(params); case 'ghl_update_product': return this.updateProduct(params); case 'ghl_delete_product': return this.deleteProduct(params); case 'ghl_create_price': return this.createPrice(params); case 'ghl_list_prices': return this.listPrices(params); case 'ghl_list_inventory': return this.listInventory(params); case 'ghl_create_product_collection': return this.createProductCollection(params); case 'ghl_list_product_collections': return this.listProductCollections(params); default: return { content: [{ type: 'text', text: `āŒ **Unknown Products Tool**: ${toolName}` }] }; } } // Additional Product Operations async getProduct(params) { 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) { try { const request = { ...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) { 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) { try { const request = { ...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) { try { const request = { ...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) { try { const request = { 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) { try { const request = { ...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) { try { const request = { ...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, index) => ` **${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'}` }] }; } } } exports.ProductsTools = ProductsTools;