@elitedcs/ghl-mcp 3.38.0 → 3.39.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.
Files changed (2) hide show
  1. package/dist/index.js +265 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var require_package = __commonJS({
31
31
  "package.json"(exports2, module2) {
32
32
  module2.exports = {
33
33
  name: "@elitedcs/ghl-mcp",
34
- version: "3.38.0",
34
+ version: "3.39.0",
35
35
  mcpName: "io.github.drjerryrelth/ghl-command",
36
36
  description: "GoHighLevel MCP Server for Claude. 218 tools \u2014 full CRM, automation, marketing control, account-wide workflow audit, and the only programmatic GHL workflow builder, now multi-tenant across client accounts.",
37
37
  main: "dist/index.js",
@@ -9625,8 +9625,8 @@ var import_zod53 = require("zod");
9625
9625
  var QUESTION_SET_VERSION = "0.1";
9626
9626
  var INTAKE_FIELD_NAME_PREFIX = "Intake: ";
9627
9627
  function deriveFieldKey(fieldName) {
9628
- const slug2 = fieldName.toLowerCase().replace(/[^a-z0-9 ]+/g, "").replace(/ /g, "_");
9629
- return `contact.${slug2}`;
9628
+ const slug3 = fieldName.toLowerCase().replace(/[^a-z0-9 ]+/g, "").replace(/ /g, "_");
9629
+ return `contact.${slug3}`;
9630
9630
  }
9631
9631
  function intakeFieldName(label) {
9632
9632
  return `${INTAKE_FIELD_NAME_PREFIX}${label}`;
@@ -10225,6 +10225,101 @@ function buildIntakeFormData(opts) {
10225
10225
  };
10226
10226
  }
10227
10227
 
10228
+ // src/intake-to-build/plan-form.ts
10229
+ function slug2(s) {
10230
+ return s.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).join("_");
10231
+ }
10232
+ function humanizeKey(key) {
10233
+ return key.split(/[^a-z0-9]+/i).filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
10234
+ }
10235
+ function buildPlanStandardField(key, required) {
10236
+ const isEmail = key === "email";
10237
+ const isPhone = key === "phone";
10238
+ const label = humanizeKey(key);
10239
+ const base = {
10240
+ fieldWidthPercentage: 100,
10241
+ hiddenFieldQueryKey: key,
10242
+ label,
10243
+ placeholder: label,
10244
+ required,
10245
+ standard: true,
10246
+ tag: key,
10247
+ type: isEmail ? "email" : "text",
10248
+ typeLabel: isEmail ? "Email" : isPhone ? "Phone" : "Text"
10249
+ };
10250
+ if (isPhone) base.enableCountryPicker = false;
10251
+ return base;
10252
+ }
10253
+ function buildPlanCustomField(record, required, locationId2, position) {
10254
+ const type = formFieldType(record.dataType);
10255
+ const field = {
10256
+ Id: record.id,
10257
+ id: record.id,
10258
+ tag: record.id,
10259
+ active: false,
10260
+ allowCustomOption: false,
10261
+ customFieldLabel: record.name,
10262
+ dataType: record.dataType,
10263
+ dateAdded: record.dateAdded ?? "",
10264
+ description: "",
10265
+ documentType: "field",
10266
+ edit: false,
10267
+ fieldKey: record.fieldKey,
10268
+ fieldWidthPercentage: 100,
10269
+ fieldsCount: 0,
10270
+ hiddenFieldQueryKey: slug2(record.name),
10271
+ label: record.name,
10272
+ locationId: locationId2,
10273
+ model: record.model ?? "contact",
10274
+ name: record.name,
10275
+ parentId: record.parentId ?? "",
10276
+ placeholder: "",
10277
+ position,
10278
+ required,
10279
+ showInForms: true,
10280
+ standard: false,
10281
+ type
10282
+ };
10283
+ const options = record.picklistOptions ?? void 0;
10284
+ if (type === "single_options" || type === "multiple_options" || type === "checkbox") {
10285
+ field.picklistOptions = options ? [...options] : [];
10286
+ }
10287
+ if (type === "multiple_options") {
10288
+ field.calculatedOptions = (options ?? []).map((label) => ({ calculatedValue: "", label }));
10289
+ field.category = "choiceElements";
10290
+ field.typeLabel = "Multi Dropdown";
10291
+ }
10292
+ if (type === "phone") field.enableCountryPicker = false;
10293
+ return field;
10294
+ }
10295
+ function buildPlanFormData(fields, locationId2) {
10296
+ const out = [];
10297
+ let position = 0;
10298
+ for (const f of fields) {
10299
+ if (f.kind === "standard") {
10300
+ out.push(buildPlanStandardField(f.key, f.required));
10301
+ } else {
10302
+ out.push(buildPlanCustomField(f.record, f.required, locationId2, position += 50));
10303
+ }
10304
+ }
10305
+ out.push(buildSubmitButton("Submit"));
10306
+ return {
10307
+ autoResponder: false,
10308
+ emailNotifications: false,
10309
+ form: {
10310
+ fields: out,
10311
+ formLabelVisible: true,
10312
+ formAction: {
10313
+ actionType: "2",
10314
+ headerImageSrc: "",
10315
+ mobileHeaderImageSrc: "",
10316
+ redirectUrl: "",
10317
+ thankyouText: "<p style='text-align:center;margin:0;'>Thanks! We received your submission.</p>"
10318
+ }
10319
+ }
10320
+ };
10321
+ }
10322
+
10228
10323
  // src/intake-to-build/brief.ts
10229
10324
  var import_zod51 = require("zod");
10230
10325
  var BRIEF_SCHEMA_VERSION = "0.1";
@@ -10777,6 +10872,26 @@ function checkRefIntegrity(plan, defined) {
10777
10872
  for (const b of plan.buildOrder ?? []) checkMaybeWildcard(b, "buildOrder");
10778
10873
  return { errors, scanned };
10779
10874
  }
10875
+ var KNOWN_STANDARD_FORM_KEYS = /* @__PURE__ */ new Set([
10876
+ "first_name",
10877
+ "last_name",
10878
+ "name",
10879
+ "full_name",
10880
+ "email",
10881
+ "phone",
10882
+ "address1",
10883
+ "address",
10884
+ "city",
10885
+ "state",
10886
+ "postal_code",
10887
+ "country",
10888
+ "website",
10889
+ "organization",
10890
+ "company_name",
10891
+ "date_of_birth",
10892
+ "contact_source",
10893
+ "source"
10894
+ ]);
10780
10895
  function validateBuildPlan(input) {
10781
10896
  const parsed = buildPlanSchema.safeParse(input);
10782
10897
  if (!parsed.success) {
@@ -10806,7 +10921,39 @@ function validateBuildPlan(input) {
10806
10921
  seen.add(key);
10807
10922
  }
10808
10923
  }
10924
+ const nameGroups = [
10925
+ ["pipelines", (plan.pipelines ?? []).map((x) => ({ ref: x.ref, name: x.name }))],
10926
+ ["customFields", (plan.customFields ?? []).map((x) => ({ ref: x.ref, name: x.name }))],
10927
+ ["tags", (plan.tags ?? []).map((x) => ({ ref: x.ref, name: x.name }))],
10928
+ ["customValues", (plan.customValues ?? []).map((x) => ({ ref: x.ref, name: x.name }))],
10929
+ ["calendars", (plan.calendars ?? []).map((x) => ({ ref: x.ref, name: x.name }))],
10930
+ ["forms", (plan.forms ?? []).map((x) => ({ ref: x.ref, name: x.name }))],
10931
+ ["funnels", (plan.funnels ?? []).map((x) => ({ ref: x.ref, name: x.name }))]
10932
+ ];
10933
+ for (const [type, objs] of nameGroups) {
10934
+ const seen = /* @__PURE__ */ new Map();
10935
+ for (const o of objs) {
10936
+ const key = o.name.trim().toLowerCase();
10937
+ const prev = seen.get(key);
10938
+ if (prev) {
10939
+ allErrors.push(
10940
+ `${type} "${o.ref}" and "${prev}" share the name "${o.name}" \u2014 names must be unique within a type (the executor binds same-named objects by name, so duplicates would collapse onto one real id)`
10941
+ );
10942
+ } else {
10943
+ seen.set(key, o.ref);
10944
+ }
10945
+ }
10946
+ }
10809
10947
  const warnings = [];
10948
+ for (const fm of plan.forms ?? []) {
10949
+ for (const fl of fm.fields) {
10950
+ if (fl.type === "standard" && !KNOWN_STANDARD_FORM_KEYS.has(fl.key.trim().toLowerCase())) {
10951
+ warnings.push(
10952
+ `forms "${fm.ref}" standard field key "${fl.key}" is not a recognized GHL standard contact field \u2014 GHL may not save it; if this is custom data, define a custom field and reference it with a custom fieldRef`
10953
+ );
10954
+ }
10955
+ }
10956
+ }
10810
10957
  for (const p of plan.pipelines ?? []) {
10811
10958
  const positions = p.stages.map((s) => s.position).sort((a, b) => a - b);
10812
10959
  const expected = positions.every((pos, idx) => pos === idx);
@@ -11465,6 +11612,61 @@ async function executeBackbone(plan, deps, opts = {}) {
11465
11612
  idMap[cal.ref] = verified.id;
11466
11613
  built.push({ ref: cal.ref, type: "calendar", name: cal.name, status: "created", realId: verified.id });
11467
11614
  }
11615
+ let cfRecords;
11616
+ for (const form of plan.forms ?? []) {
11617
+ let forms;
11618
+ try {
11619
+ forms = await deps.listForms();
11620
+ } catch (e) {
11621
+ return halt(form.ref, "form", `could not read existing forms: ${msg(e)}`);
11622
+ }
11623
+ const matches = forms.filter((f) => norm2(f.name) === norm2(form.name));
11624
+ if (matches.length > 1) {
11625
+ return halt(form.ref, "form", `${matches.length} existing forms are named "${form.name}" \u2014 ambiguous, cannot safely bind ${form.ref}. Resolve the duplicate in GHL, then re-run.`);
11626
+ }
11627
+ if (matches.length === 1) {
11628
+ idMap[form.ref] = matches[0].id;
11629
+ built.push({ ref: form.ref, type: "form", name: form.name, status: "existing", realId: matches[0].id });
11630
+ continue;
11631
+ }
11632
+ if (!cfRecords) {
11633
+ try {
11634
+ cfRecords = await deps.listCustomFieldRecords();
11635
+ } catch (e) {
11636
+ return halt(form.ref, "form", `could not read custom fields to resolve form refs: ${msg(e)}`);
11637
+ }
11638
+ }
11639
+ const byId = new Map(cfRecords.map((r) => [r.id, r]));
11640
+ const resolved = [];
11641
+ let fieldHalt2;
11642
+ for (const ff of form.fields) {
11643
+ if (ff.type === "standard") {
11644
+ resolved.push({ kind: "standard", key: ff.key, required: ff.required ?? false });
11645
+ continue;
11646
+ }
11647
+ const realId = idMap[ff.fieldRef];
11648
+ if (!realId) {
11649
+ fieldHalt2 = halt(form.ref, "form", `form "${form.name}" references ${ff.fieldRef} but that custom field was not built/resolved \u2014 cannot build the form`);
11650
+ break;
11651
+ }
11652
+ const rec = byId.get(realId);
11653
+ if (!rec) {
11654
+ fieldHalt2 = halt(form.ref, "form", `custom field ${ff.fieldRef} (id ${realId}) not found in this account when building form "${form.name}"`);
11655
+ break;
11656
+ }
11657
+ resolved.push({ kind: "custom", record: rec, required: ff.required ?? false });
11658
+ }
11659
+ if (fieldHalt2) return fieldHalt2;
11660
+ let formId;
11661
+ try {
11662
+ formId = await deps.createForm(form.name, resolved);
11663
+ } catch (e) {
11664
+ return halt(form.ref, "form", `create failed: ${msg(e)}`);
11665
+ }
11666
+ if (!formId) return halt(form.ref, "form", "form create returned no id");
11667
+ idMap[form.ref] = formId;
11668
+ built.push({ ref: form.ref, type: "form", name: form.name, status: "created", realId: formId });
11669
+ }
11468
11670
  return { ok: true, idMap, built, manual, deferred: deferredSections(plan) };
11469
11671
  }
11470
11672
  async function buildSimple(objects, type, list, create, nameOf, pollForNew, idMap, built) {
@@ -11501,7 +11703,6 @@ async function buildSimple(objects, type, list, create, nameOf, pollForNew, idMa
11501
11703
  }
11502
11704
  function deferredSections(plan) {
11503
11705
  const out = [];
11504
- if (plan.forms?.length) out.push({ section: "forms", count: plan.forms.length });
11505
11706
  if (plan.funnels?.length) out.push({ section: "funnels", count: plan.funnels.length });
11506
11707
  if (plan.workflows?.length) out.push({ section: "workflows", count: plan.workflows.length });
11507
11708
  return out;
@@ -11700,6 +11901,64 @@ ${text2.slice(0, 300)}`);
11700
11901
  locationId2
11701
11902
  );
11702
11903
  await client.post("/calendars/", { body, noRetry: true });
11904
+ },
11905
+ // Paginate the form list: a single limit:100 page would miss the target (or
11906
+ // an orphan) form on accounts with many forms, breaking NEVER-CLOBBER (the
11907
+ // executor would create a duplicate). Mirrors the update_form name-lookup scan.
11908
+ listForms: async () => {
11909
+ const out = [];
11910
+ const pageSize = 100;
11911
+ const maxForms = 5e3;
11912
+ for (let skip = 0; skip < maxForms; skip += pageSize) {
11913
+ const page = pickObjects(await client.get("/forms/", { params: { locationId: locationId2, limit: pageSize, skip } }), ["forms"]);
11914
+ out.push(...page);
11915
+ if (page.length < pageSize) break;
11916
+ }
11917
+ return out;
11918
+ },
11919
+ listCustomFieldRecords: async () => parseCustomFields(await client.get(`/locations/${locationId2}/customFields`)),
11920
+ createForm: async (name, fields) => {
11921
+ const formData = buildPlanFormData(fields, locationId2);
11922
+ const createResult = await formApiRequest(builderClient, "POST", `/?locationId=${locationId2}`, {
11923
+ name,
11924
+ locationId: locationId2,
11925
+ formData: { form: { fields: [], formLabelVisible: true } }
11926
+ });
11927
+ const formId = extractFormId(createResult);
11928
+ if (!formId) {
11929
+ throw new Error(`create_form returned no id: ${JSON.stringify(createResult).slice(0, 200)}`);
11930
+ }
11931
+ try {
11932
+ for (let attempt = 1; ; attempt++) {
11933
+ try {
11934
+ await formApiRequest(builderClient, "POST", `/${formId}?locationId=${locationId2}`, { name, formData });
11935
+ break;
11936
+ } catch (saveErr) {
11937
+ if (isFormNotYetPropagated(saveErr) && attempt < 6) {
11938
+ await sleep2(700 * attempt);
11939
+ continue;
11940
+ }
11941
+ throw saveErr;
11942
+ }
11943
+ }
11944
+ let persisted = 0;
11945
+ for (let attempt = 1; attempt <= 6; attempt++) {
11946
+ const verify = await formApiRequest(builderClient, "GET", `/${formId}?locationId=${locationId2}`);
11947
+ persisted = countFormFields(verify);
11948
+ if (persisted > 0) break;
11949
+ if (attempt < 6) await sleep2(700 * attempt);
11950
+ }
11951
+ if (persisted === 0) {
11952
+ throw new Error(`form "${name}" was created (${formId}) but no fields persisted after save (read-after-write); not binding`);
11953
+ }
11954
+ return formId;
11955
+ } catch (err) {
11956
+ try {
11957
+ await formApiRequest(builderClient, "DELETE", `/${formId}?locationId=${locationId2}`);
11958
+ } catch {
11959
+ }
11960
+ throw err;
11961
+ }
11703
11962
  }
11704
11963
  };
11705
11964
  }
@@ -11758,7 +12017,7 @@ function registerIntakeToBuildTools(server2, client, builderClient) {
11758
12017
  );
11759
12018
  server2.tool(
11760
12019
  "apply_build_plan",
11761
- `Take an APPROVED Blueprint \xA75 build plan + the CURRENT confirmed sub-account and build it. mode:"dry_run" (default) writes NOTHING \u2014 it resolves refs, expands each workflow's logical actions to native GHL JSON, runs the NEVER-CLOBBER existing-asset scan, and returns a two-part report. Run it FIRST. mode:"execute" performs LIVE writes for the CRM backbone (pipelines+stages, custom fields, tags, custom values) AND calendars: never clobbers (same-named objects are bound to their existing id, never modified), verifies each create by read-back before resolving its ref, halts on the first failure returning the partial idMap, and is idempotent (re-run = no-op). Staff-requiring calendars (round_robin etc.) auto-build only when you are the sole account user (auto-assigns you as the team member); with 0 or 2+ users they're surfaced as a manual step, not auto-staffed to a guess. Forms/funnels/workflows are surfaced as manual next steps, not auto-built yet. Always confirms the active location and validates the plan before any write.`,
12020
+ `Take an APPROVED Blueprint \xA75 build plan + the CURRENT confirmed sub-account and build it. mode:"dry_run" (default) writes NOTHING \u2014 it resolves refs, expands each workflow's logical actions to native GHL JSON, runs the NEVER-CLOBBER existing-asset scan, and returns a two-part report. Run it FIRST. mode:"execute" performs LIVE writes for the CRM backbone (pipelines+stages, custom fields, tags, custom values), calendars, AND forms: never clobbers (same-named objects are bound to their existing id, never modified), verifies each create by read-back before resolving its ref, halts on the first failure returning the partial idMap, and is idempotent (re-run = no-op). Staff-requiring calendars (round_robin etc.) auto-build only when you are the sole account user (auto-assigns you as the team member); with 0 or 2+ users they're surfaced as a manual step, not auto-staffed to a guess. Forms build with their standard + custom fields (custom fieldRefs resolve to the real fields created earlier in the run). Funnels/workflows are surfaced as manual next steps, not auto-built yet. Always confirms the active location and validates the plan before any write.`,
11762
12021
  {
11763
12022
  plan: import_zod53.z.record(import_zod53.z.unknown()).describe("The approved \xA75 Build Plan object."),
11764
12023
  mode: import_zod53.z.enum(["dry_run", "execute"]).optional().describe("dry_run (default) = resolve/expand/scan/report, no writes. execute = live writes (not yet enabled)."),
@@ -11851,7 +12110,7 @@ function registerIntakeToBuildTools(server2, client, builderClient) {
11851
12110
  manual: exec.manual,
11852
12111
  idMap: exec.idMap,
11853
12112
  deferred: exec.deferred,
11854
- deferredNote: "execute builds the CRM backbone (pipelines, custom fields, tags, custom values) and calendars live. Staff-requiring calendars (round_robin etc.) auto-build only when you are the sole user; otherwise they're listed under manual steps. Forms/funnels/workflows are planned but NOT auto-built yet \u2014 create them via the GHL UI or the dedicated tools, in this order: forms \u2192 funnels \u2192 workflows.",
12113
+ deferredNote: "execute builds the CRM backbone (pipelines, custom fields, tags, custom values), calendars, and forms live. Staff-requiring calendars (round_robin etc.) auto-build only when you are the sole user; otherwise they're listed under manual steps. Funnels/workflows are planned but NOT auto-built yet \u2014 create them via the GHL UI or the dedicated tools, in this order: funnels \u2192 workflows.",
11855
12114
  nextManualSteps: [...calendarManualLines, ...manualLines, ...handoffLines],
11856
12115
  summary: exec.ok ? `Built ${exec.built.filter((b) => b.status === "created").length} new object(s), bound ${exec.built.filter((b) => b.status === "existing").length} existing.${exec.manual.length ? ` ${exec.manual.length} calendar(s) need manual staff assignment.` : ""}${exec.deferred.length ? " Deferred: " + exec.deferred.map((d) => `${d.count} ${d.section}`).join(", ") + " (manual)." : ""}` : `HALTED at ${exec.halted?.atRef} (${exec.halted?.reason}). ${exec.built.length} object(s) were created before the halt \u2014 see idMap to resume or clean up. NEVER-CLOBBER means a re-run will bind those, not duplicate them.`
11857
12116
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elitedcs/ghl-mcp",
3
- "version": "3.38.0",
3
+ "version": "3.39.0",
4
4
  "mcpName": "io.github.drjerryrelth/ghl-command",
5
5
  "description": "GoHighLevel MCP Server for Claude. 218 tools — full CRM, automation, marketing control, account-wide workflow audit, and the only programmatic GHL workflow builder, now multi-tenant across client accounts.",
6
6
  "main": "dist/index.js",