@elitedcs/ghl-mcp 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,320 @@
1
+ # Changelog
2
+
3
+ ## 2.7.0 — Complete Type Safety (Boris Cherny A+)
4
+
5
+ **171 tools across 35 modules. Bundle: 214KB.**
6
+
7
+ Closes every remaining type safety issue from the Boris Cherny audit. Zero escape hatches, runtime-validated API responses on critical paths, type-safe tool registration, and defensive property access everywhere.
8
+
9
+ ### account-export.ts — no more unsafe casts
10
+ - Replaced `contacts as Record<string, unknown> & { meta?: ... }` with defensive runtime checks (`typeof`, `Array.isArray`) before property access.
11
+ - `count()` helper uses `Object.values()` instead of indexing a cast object.
12
+ - Switched to `jsonResponse`/`errorResponse` helpers.
13
+
14
+ ### Type-safe tool registration
15
+ - `src/tools/index.ts` now uses a typed `ReadonlyArray<[ToolRegistrar, string]>` registry. The compiler verifies every function reference exists — adding an import without a registry entry or vice versa is a compile error.
16
+ - Builder tools (Firebase auth) registered separately with explicit `WorkflowBuilderClient` parameter.
17
+
18
+ ### WorkflowFull — no more escape hatch
19
+ - Removed `[key: string]: unknown` index signature from `WorkflowFull` interface. Replaced with explicit optional fields (`stopOnResponse`, `allowMultiple`, etc.) for all properties accessed in the codebase.
20
+
21
+ ### API response validation on critical paths
22
+ - New `src/api-schemas.ts` — Zod schemas with `.passthrough()` for contacts, pipelines, and calendars.
23
+ - `search_contacts` validates response against `ContactSearchResponseSchema`.
24
+ - `get_contact` validates against `ContactResponseSchema`.
25
+ - `get_pipelines` validates against `PipelinesResponseSchema`.
26
+ - `get_calendars` validates against `CalendarsResponseSchema`.
27
+ - Schema violations throw at the tool level with clear error messages instead of silently passing malformed data.
28
+
29
+ ### Startup update check
30
+ - Server runs a non-blocking `git fetch` on startup and warns via stderr if a newer version is available on the remote.
31
+ - Version is now read from `package.json` at build time instead of hardcoded — startup shows `v2.7.0 connected`.
32
+
33
+ ### Files changed
34
+ - `src/index.ts` — dynamic version from package.json, background update check
35
+ - `src/tools/account-export.ts` — defensive type access, response helpers
36
+ - `src/tools/index.ts` — typed registry array
37
+ - `src/workflow-builder-client.ts` — removed `[key: string]: unknown`
38
+ - `src/api-schemas.ts` — NEW: Zod response schemas
39
+ - `src/tools/contacts.ts` — output validation on search + get
40
+ - `src/tools/opportunities.ts` — output validation on get_pipelines
41
+ - `src/tools/calendars.ts` — output validation on get_calendars
42
+
43
+ ## 2.6.0 — A+ Type Safety
44
+
45
+ **171 tools across 35 modules. Bundle: 210KB.**
46
+
47
+ Eliminated all generic `as T` type casts from both HTTP clients, added Zod runtime validation on API responses and template files, added pre-flight workflow action validation, and documented pagination strategies across all tools.
48
+
49
+ ### Honest types — no more `as T` casts
50
+
51
+ - `GHLClient.request()` and all HTTP methods (`get`, `post`, `put`, `patch`, `delete`) now return `Promise<unknown>` instead of `Promise<T>`. No more `JSON.parse(text) as T` — the type system no longer lies about response shapes.
52
+ - `WorkflowBuilderClient.request()` — same treatment. Returns `Promise<unknown>`.
53
+ - `getWorkflow()` and `createWorkflow()` now validate responses against a `WorkflowFullSchema` (Zod) before returning typed `WorkflowFull`. Runtime-validated, not compile-time-assumed.
54
+ - `location-switcher.ts` — replaced `client.get<LocationResponse>(...)` with honest `Record<string, unknown>` + defensive property access.
55
+
56
+ ### Template Zod validation
57
+
58
+ - `template-deployer.ts` now validates template JSON against `TemplateSchema` on load — catches malformed templates with clear error messages instead of crashing mid-deploy.
59
+ - `resolveObj()` is now generic `<T>(obj: T): T` — preserves input types through string replacement, eliminating 5 downstream `as Record<string, unknown>` casts.
60
+ - Template structure (tags, customFields, pipelines, workflows, calendars) is now a single Zod source of truth.
61
+
62
+ ### Workflow action validation
63
+
64
+ - `validateActionChain()` — pre-flight validation before sending actions to GHL. Checks: SMS needs `body` + `attachments`, email needs `subject` + `html` + `trackingOptions`, tags need `tags[]`, wait needs `startAfter`, create_opportunity needs `pipelineId` + `stageId`, remove_from_workflow needs both `workflowId` and `workflow_id[]`.
65
+ - `hasId()` type guard — replaces `as string` casts on action ID filtering with proper TypeScript narrowing.
66
+ - Removed `!` non-null assertion on `action.next` assignment — replaced with explicit null check.
67
+
68
+ ### Pagination documentation
69
+
70
+ - 11 tools now include pagination strategy in their descriptions (offset-based, page-based, or cursor-based).
71
+ - Updated: get_funnels, get_funnel_pages, get_orders, get_subscriptions, get_transactions, list_invoices, get_blog_posts, get_form_submissions, get_survey_submissions, get_form_submissions_full, list_available_locations.
72
+
73
+ ### Files changed
74
+
75
+ - `src/ghl-client.ts` — removed all generic `<T>`, returns `Promise<unknown>`
76
+ - `src/workflow-builder-client.ts` — removed generics, added `WorkflowFullSchema`, `hasId()`, `validateActionChain()`
77
+ - `src/tools/location-switcher.ts` — removed `<LocationResponse>` generic, honest casts
78
+ - `src/tools/template-deployer.ts` — added `TemplateSchema`, generic `resolveObj<T>`, removed 6 unsafe casts
79
+ - 8 tool files — pagination documentation updates
80
+
81
+ ## 2.5.0 — Type Safety & Boilerplate Overhaul
82
+
83
+ **171 tools across 35 modules. Bundle: 206KB (down from 246KB).**
84
+
85
+ Boris Cherny-style type safety audit and overhaul. Eliminated ~40KB of duplicated boilerplate, added runtime validation, guarded destructive operations, and introduced typed workflow action schemas.
86
+
87
+ ### `safeTool()` wrapper — eliminates boilerplate (Phase A)
88
+
89
+ - New `safeTool()` higher-order function in `tool-helpers.ts` — wraps tool handlers with automatic try/catch and JSON response formatting
90
+ - Converted 25 tool modules (~120 tools) from manual try/catch/JSON.stringify to `safeTool()` — handlers now just return data
91
+ - Net reduction: ~1000 lines of duplicated error handling eliminated
92
+ - Files skipped (complex handlers): bulk-operations, template-deployer, location-switcher, account-export, workflow-cloner, builder modules
93
+
94
+ ### Zod-validated token registry (Phase B)
95
+
96
+ - `token-registry.ts` now validates `.ghl-tokens.json` against a Zod schema on load
97
+ - Types derived from schemas (`z.infer<>`) instead of manual interfaces — single source of truth
98
+ - Malformed registry files fail with a clear validation error instead of silent type-assertion cast
99
+
100
+ ### Delete confirmation guards (Phase C)
101
+
102
+ - 10 destructive delete operations now require `confirm: "DELETE"` parameter, matching existing `bulk_delete_contacts` pattern
103
+ - Guarded: `delete_contact`, `delete_opportunity`, `delete_calendar`, `delete_appointment`, `delete_business`, `delete_workflow_full`, `delete_pipeline`, `delete_form`, `delete_funnel`, `delete_funnel_page`
104
+ - Low-risk deletes (media, webhooks, social posts, coupons, tags, etc.) left unguarded
105
+
106
+ ### Discriminated union for WorkflowAction (Phase D)
107
+
108
+ - New `src/workflow-action-types.ts` — typed attribute interfaces for all 11 documented action types (sms, email, wait, add_contact_tag, remove_contact_tag, internal_notification, update_contact_field, add_notes, task_notification, remove_from_workflow, create_opportunity)
109
+ - `WorkflowAction` is now a discriminated union on `type` with a `string` fallback for unknown types
110
+ - Compile-time enforcement that SMS actions have `body` + `attachments`, emails have `subject` + `html` + `trackingOptions`, etc.
111
+
112
+ ### Files Changed
113
+
114
+ - `src/tool-helpers.ts` — Added `safeTool()` wrapper with MCP SDK type imports
115
+ - `src/token-registry.ts` — Zod schema validation, types derived from schemas
116
+ - `src/workflow-action-types.ts` — NEW: discriminated union type definitions
117
+ - `src/workflow-builder-client.ts` — Imports WorkflowAction from new types file
118
+ - 25 tool modules converted to `safeTool()` pattern
119
+ - 8 tool files updated with delete confirmation guards
120
+
121
+ ## 2.4.0 — Reliability & Consistency Audit
122
+
123
+ **171 tools across 35 modules.**
124
+
125
+ Full audit and hardening pass — every tool reviewed for reliability, error handling, and LLM usability.
126
+
127
+ ### Reliability Fixes
128
+
129
+ - **Retry with exponential backoff** — Both `ghl-client.ts` and `workflow-builder-client.ts` now retry on 429 rate limits, 5xx server errors, and transient network errors (ECONNRESET, ETIMEDOUT). 3 retries with 500ms base delay. Respects `Retry-After` header.
130
+ - **Clear timeout errors** — Request timeouts now throw `"Request timeout (30s): GET /path"` instead of cryptic `AbortError`.
131
+ - **Firebase token refresh lock** — Concurrent requests now share a single token refresh instead of racing. Eliminates duplicate Firebase calls and potential token corruption.
132
+ - **Firebase cache clear on failure** — If token refresh fails, the stale cache is cleared immediately instead of persisting for 55 minutes of cascading failures.
133
+ - **Startup API key validation** — Server validates the API key at startup (non-blocking) and logs a clear warning if it returns 401.
134
+ - **Token registry corruption backup** — If `.ghl-tokens.json` is corrupted, it's backed up as `.ghl-tokens.json.corrupted.<timestamp>` before falling back to empty.
135
+
136
+ ### Consistency Fixes (LLM Usability)
137
+
138
+ - **Standardized locationId handling** — All 13 affected tool files now use consistent `.optional()` locationId with `resolveLocationId()` fallback. Removed 25 instances of incorrect `await` on the synchronous `resolveLocationId()` method.
139
+ - **Fixed tools missing resolveLocationId()** — `users.ts`, `businesses.ts`, `courses.ts`, `social-planner.ts` now properly resolve locationId from env var fallback instead of passing raw (possibly undefined) values.
140
+ - **Hidden altId/altType from LLM** — `media.ts` tools now accept `locationId` and map to `altId`/`altType` internally, matching the pattern used by invoices, estimates, coupons, and payments.
141
+ - **Improved builder tool descriptions** — All `_full` builder tools now mention "Requires Firebase auth" and clarify when to use them vs public API versions. `update_workflow_actions` now says "Call get_workflow_full first". `create_workflow` shows the explicit 3-step flow.
142
+ - **Complete action/trigger type lists** — `update_workflow_actions` description now lists all supported action and trigger types instead of "etc."
143
+
144
+ ### Files Changed
145
+
146
+ - `src/ghl-client.ts` — Retry/backoff, timeout error handling
147
+ - `src/workflow-builder-client.ts` — Retry/backoff, timeout, token refresh lock + cache clear
148
+ - `src/token-registry.ts` — Corruption backup on load failure
149
+ - `src/index.ts` — Startup API key validation
150
+ - `src/tools/blogs.ts` — locationId optional + remove await
151
+ - `src/tools/campaigns.ts` — locationId optional + remove await
152
+ - `src/tools/emails.ts` — locationId optional + remove await
153
+ - `src/tools/forms.ts` — locationId optional + remove await
154
+ - `src/tools/funnels.ts` — locationId optional + remove await
155
+ - `src/tools/invoices.ts` — locationId optional + remove await
156
+ - `src/tools/payments.ts` — locationId optional + remove await
157
+ - `src/tools/surveys.ts` — locationId optional + remove await
158
+ - `src/tools/trigger-links.ts` — locationId optional + remove await
159
+ - `src/tools/users.ts` — locationId optional + add resolveLocationId
160
+ - `src/tools/businesses.ts` — locationId optional + add resolveLocationId
161
+ - `src/tools/courses.ts` — locationId optional + add resolveLocationId
162
+ - `src/tools/social-planner.ts` — locationId optional + add resolveLocationId
163
+ - `src/tools/media.ts` — Replace altId/altType with locationId
164
+ - `src/tools/workflow-builder.ts` — Improved tool descriptions
165
+
166
+ ## 2.3.0 — Multi-Sub-Account Token Registry
167
+
168
+ **171 tools across 35 modules.**
169
+
170
+ ### New: Token Registry
171
+
172
+ - **`src/token-registry.ts`** — Per-location API key storage for seamless multi-sub-account access
173
+ - Stores API keys in `.ghl-tokens.json` (gitignored) — no server restart needed to switch locations
174
+ - Also stores Firebase credentials and agency-level API key
175
+
176
+ ### New: Location Registry Tools (3 tools)
177
+
178
+ - `register_location` — Add a sub-account and its API key to the token registry
179
+ - `unregister_location` — Remove a sub-account from the token registry
180
+ - `list_registered_locations` — List all sub-accounts stored in the token registry
181
+
182
+ ### Improved: Location Switcher
183
+
184
+ - `switch_location` now automatically swaps the API key from the token registry when switching sub-accounts
185
+ - `get_current_location` now shows token registry status
186
+
187
+ ### Documentation
188
+
189
+ - Updated README tool count from 167 → 171 and version from 2.2.0 → 2.3.0
190
+ - Added **Known Limitations** section to README — documents what the MCP can't do (contact merge, templates, calls, analytics, etc.)
191
+ - Added **CONTRIBUTING.md** — dev setup, branching, PR guidelines, how to add tools
192
+ - Updated **Access & Collaboration** section with contributor (Write) role alongside customer (Read) role
193
+ - Updated project structure tree with `token-registry.ts`, `action-schemas.json`, `CONTRIBUTING.md`
194
+ - Updated CLAUDE.md architecture section and build notes for token registry
195
+ - Generated website update prompt at `templates/website-update-2026-04-01.md`
196
+
197
+ ## 2.2.0 — Builder Suite + Power Tools
198
+
199
+ **164 tools across 34 modules.**
200
+
201
+ ### New: Funnel/Page Builder (9 tools)
202
+ - `list_funnels_full`, `get_page_full`, `get_page_content` — read full page builder data (sections, elements, CSS, tracking codes)
203
+ - `create_funnel`, `update_funnel`, `delete_funnel` — funnel CRUD
204
+ - `create_funnel_page`, `update_page_content`, `delete_funnel_page` — page CRUD
205
+
206
+ ### New: Form Builder (5 tools)
207
+ - `get_form_full` — read all fields, conditional logic, auto-responder, email notifications
208
+ - `create_form`, `update_form`, `delete_form` — form CRUD
209
+ - `get_form_submissions_full` — full submission data via internal API
210
+
211
+ ### New: Pipeline Builder (5 tools)
212
+ - `list_pipelines_full`, `get_pipeline_full` — full stage details via internal API
213
+ - `create_pipeline`, `update_pipeline`, `delete_pipeline` — pipeline/stage CRUD
214
+
215
+ ### New: Bulk Operations (5 tools)
216
+ - `bulk_add_tags`, `bulk_remove_tags` — batch tag management
217
+ - `bulk_update_contacts` — batch field updates
218
+ - `bulk_add_to_workflow` — batch workflow enrollment
219
+ - `bulk_delete_contacts` — batch deletion with safety confirmation
220
+ - All operations rate-limited with success/failure reporting
221
+
222
+ ### New: Account Export & Comparison (2 tools)
223
+ - `export_account` — full sub-account backup to JSON
224
+ - `compare_locations` — side-by-side diff of two sub-accounts
225
+
226
+ ### New: Workflow Cloner (1 tool)
227
+ - `clone_workflow` — deep clone with UUID remapping for all actions, triggers, and references
228
+
229
+ ### New: Location Switcher (3 tools)
230
+ - `get_current_location`, `switch_location`, `list_available_locations`
231
+ - Switch between sub-accounts mid-session without restarting
232
+
233
+ ### Fixes
234
+ - Added `source: WEB_USER` header (required by funnel/form internal endpoints)
235
+ - Made `buildHeaders()` public on WorkflowBuilderClient for reuse by builder modules
236
+
237
+ ## 2.1.0 — Workflow Builder (Internal API)
238
+
239
+ **134 tools across 27 modules.**
240
+
241
+ ### New: Full Workflow CRUD
242
+
243
+ - **WorkflowBuilderClient** — authenticates via Firebase refresh token to access GHL's internal backend API (`backend.leadconnectorhq.com`)
244
+ - 6 new MCP tools for complete workflow management:
245
+ - `list_workflows_full` — list with full metadata and permissions
246
+ - `get_workflow_full` — read every action, trigger, condition, if/else branch, email template, SMS body
247
+ - `create_workflow` — create new workflows (start as draft)
248
+ - `update_workflow_actions` — add, edit, remove actions/triggers/branches
249
+ - `delete_workflow_full` — permanently delete workflows
250
+ - `publish_workflow` — publish drafts to make them active
251
+ - Supports all GHL action types: sms, email, add_contact_tag, wait, if_else, webhook, custom_code, and more
252
+ - Supports all GHL trigger types: contact_tag, form_submission, appointment, inbound_webhook, and more
253
+ - Automatic version tracking for safe concurrent editing
254
+ - Graceful degradation — if Firebase env vars not set, standard tools still work
255
+
256
+ ### New Environment Variables (Optional)
257
+
258
+ - `GHL_USER_ID` — required for workflow builder
259
+ - `GHL_FIREBASE_API_KEY` — Firebase API key from GHL auth
260
+ - `GHL_FIREBASE_REFRESH_TOKEN` — Firebase refresh token (may rotate)
261
+
262
+ ## 2.0.0 — CommonJS Rebuild
263
+
264
+ **128 tools across 26 modules.**
265
+
266
+ ### Breaking Changes
267
+
268
+ - Converted from ESM to CommonJS — removed `"type": "module"` from package.json
269
+ - Build system switched from `tsc` to `esbuild` — tsc OOMs on TS 5.9.3 with MCP SDK types
270
+ - MCP registration now uses `claude mcp add --scope user` (registers in `~/.claude.json`, NOT `~/.claude/mcp.json`)
271
+
272
+ ### New Modules (6)
273
+
274
+ - **Custom Objects** (7 tools) — List schemas, CRUD records
275
+ - **Associations** (3 tools) — Link custom object records to contacts/opportunities/other records
276
+ - **Estimates** (6 tools) — Create, update, delete, send quotes/estimates
277
+ - **Coupons** (5 tools) — Create and manage promo codes
278
+ - **Webhooks** (5 tools) — CRUD webhook subscriptions
279
+ - **Documents** (4 tools) — List, get, delete, send documents for signature
280
+
281
+ ### Improvements
282
+
283
+ - Added `dotenv` for `.env` fallback (wrapper script is primary env source)
284
+ - Improved error handling: `unhandledRejection` handler, stderr logging
285
+ - API key is now optional — server starts gracefully and reports auth errors per-tool
286
+ - Added `start-mcp.sh` wrapper script for reliable env var injection
287
+
288
+ ## 1.0.0 — Initial Release
289
+
290
+ **98 tools across 20 modules.**
291
+
292
+ ### Modules
293
+
294
+ - **Contacts** (15 tools) — Full CRM: search, create, update, delete, tags, notes, tasks, appointments, workflow management
295
+ - **Conversations** (8 tools) — Messaging: search threads, send SMS/email/WhatsApp, manage message status
296
+ - **Opportunities** (7 tools) — Pipeline: create/update/delete deals, move through stages, manage status
297
+ - **Calendars** (11 tools) — Scheduling: manage calendars, check availability, book/update/cancel appointments
298
+ - **Locations** (15 tools) — Admin: sub-account settings, custom fields, custom values, location tags
299
+ - **Invoices** (8 tools) — Billing: create, send, void, record payments
300
+ - **Social Planner** (5 tools) — Social media: create, list, delete posts, view connected accounts
301
+ - **Businesses** (5 tools) — Business entities: full CRUD
302
+ - **Blogs** (5 tools) — Blog management: posts, authors, categories, URL slugs
303
+ - **Payments** (4 tools) — Orders, subscriptions, transaction history
304
+ - **Funnels** (2 tools) — List funnels and pages
305
+ - **Forms** (2 tools) — List forms, view submissions
306
+ - **Surveys** (2 tools) — List surveys, view submissions
307
+ - **Users** (2 tools) — Team member management
308
+ - **Media** (2 tools) — Media file browsing and deletion
309
+ - **Campaigns** (1 tool) — Campaign listing
310
+ - **Workflows** (1 tool) — Workflow listing
311
+ - **Courses** (1 tool) — Course listing
312
+ - **Emails** (1 tool) — Email campaign listing
313
+ - **Trigger Links** (1 tool) — Trigger link listing
314
+
315
+ ### Infrastructure
316
+
317
+ - MCP server with stdio transport
318
+ - GHL API v2 HTTP client with auth, versioning, and error handling
319
+ - Zod schema validation on all tool inputs
320
+ - One-command setup script (`setup.sh`)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Elite DCs, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.