@diviops/mcp-server 1.5.28 → 1.5.30

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/dist/index.js CHANGED
@@ -12,8 +12,9 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
12
12
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
13
13
  import { z } from "zod";
14
14
  import { WPClient } from "./wp-client.js";
15
- import { MissingCapabilityError } from "./compatibility.js";
15
+ import { MissingCapabilityError, proToolGatesSatisfied } from "./compatibility.js";
16
16
  import { ErrorCodes, envelopeMap, recordIdempotent, serializeEnvelope, withCode, wrapResponse, } from "./envelope.js";
17
+ import { preflightCrossEnvHeaderSync, } from "./cross-env-preflight/header-preflight.js";
17
18
  import { optimizeSchema } from "./schema-optimizer.js";
18
19
  import { schemaModuleRoute } from "./schema-route.js";
19
20
  import { createWpCli } from "./wp-cli.js";
@@ -86,6 +87,95 @@ const server = new McpServer({
86
87
  version: SERVER_VERSION,
87
88
  });
88
89
  let handshakeState = { kind: "pending" };
90
+ const BASE_META_CAPABILITIES = [
91
+ "pages",
92
+ "modules",
93
+ "presets",
94
+ "library",
95
+ "theme_builder",
96
+ "canvas",
97
+ "variables",
98
+ "templates",
99
+ "icons",
100
+ "validation",
101
+ "preview",
102
+ ];
103
+ function enabledCapabilityKeys(prefix) {
104
+ if (handshakeState.kind !== "ok")
105
+ return [];
106
+ const state = handshakeState;
107
+ return Object.keys(state.capabilities)
108
+ .filter((key) => state.capabilities[key])
109
+ .filter((key) => (prefix ? key.startsWith(prefix) : true))
110
+ .sort();
111
+ }
112
+ function buildMetaInfo() {
113
+ const fluentCartCapabilityKeys = enabledCapabilityKeys("fluentcart_");
114
+ const crossEnvCapabilityKeys = enabledCapabilityKeys("cross_env_");
115
+ const fluentCartTarget = handshakeState.kind === "ok"
116
+ ? handshakeState.availableTargets.fluentcart ?? null
117
+ : null;
118
+ const crossEnvTarget = handshakeState.kind === "ok"
119
+ ? handshakeState.availableTargets.cross_env ?? null
120
+ : null;
121
+ const fluentCartActive = handshakeState.kind === "ok" &&
122
+ handshakeState.proActive === true &&
123
+ fluentCartTarget?.present === true &&
124
+ handshakeState.activeModules.fluentcart === true &&
125
+ fluentCartCapabilityKeys.length > 0;
126
+ const crossEnvActive = handshakeState.kind === "ok" &&
127
+ handshakeState.proActive === true &&
128
+ crossEnvTarget?.present === true &&
129
+ handshakeState.activeModules.cross_env === true &&
130
+ crossEnvCapabilityKeys.length > 0;
131
+ const capabilities = fluentCartActive
132
+ ? [...BASE_META_CAPABILITIES, "fluentcart"]
133
+ : [...BASE_META_CAPABILITIES];
134
+ if (crossEnvActive)
135
+ capabilities.push("cross_env");
136
+ return {
137
+ brand: "DiviOps",
138
+ server: "diviops-mcp",
139
+ version: SERVER_VERSION,
140
+ license: "MIT",
141
+ capabilities,
142
+ handshake: handshakeState.kind === "ok"
143
+ ? {
144
+ state: "ok",
145
+ plugin_version: handshakeState.pluginVersion,
146
+ capability_count: enabledCapabilityKeys().length,
147
+ }
148
+ : { state: handshakeState.kind },
149
+ pro: handshakeState.kind === "ok"
150
+ ? {
151
+ active: handshakeState.proActive,
152
+ version: handshakeState.proVersion ?? null,
153
+ }
154
+ : {
155
+ active: false,
156
+ version: null,
157
+ },
158
+ slices: {
159
+ fluentcart: {
160
+ target: fluentCartTarget,
161
+ active: fluentCartActive,
162
+ module_active: handshakeState.kind === "ok"
163
+ ? handshakeState.activeModules.fluentcart === true
164
+ : false,
165
+ tool_capabilities: fluentCartCapabilityKeys,
166
+ },
167
+ cross_env: {
168
+ target: crossEnvTarget,
169
+ active: crossEnvActive,
170
+ module_active: handshakeState.kind === "ok"
171
+ ? handshakeState.activeModules.cross_env === true
172
+ : false,
173
+ tool_capabilities: crossEnvCapabilityKeys,
174
+ },
175
+ },
176
+ wp_cli: wpCli ? wpCli.getAllowedCommands() : false,
177
+ };
178
+ }
89
179
  function requireCapability(key) {
90
180
  // Only gate when we have a real capability map. On handshake failure,
91
181
  // bypass the gate so the underlying request surfaces the actual cause
@@ -177,14 +267,7 @@ function registerLocalTool(name, config, handler) {
177
267
  function registerProTool(name, config, handler, gates) {
178
268
  if (handshakeState.kind !== "ok")
179
269
  return;
180
- if (!handshakeState.proActive)
181
- return;
182
- const target = handshakeState.availableTargets[gates.target];
183
- if (!target || target.present !== true)
184
- return;
185
- if (handshakeState.activeModules[gates.target] !== true)
186
- return;
187
- if (!handshakeState.capabilities[gates.capabilityKey])
270
+ if (!proToolGatesSatisfied(handshakeState, gates))
188
271
  return;
189
272
  recordIdempotent(name, config?._meta);
190
273
  server.registerTool(name, config, handler);
@@ -278,6 +361,61 @@ registerPluginTool("diviops_page_get_layout", {
278
361
  ],
279
362
  };
280
363
  });
364
+ registerPluginTool("diviops_module_get", {
365
+ description: 'Get one targeted Divi module/block from a page, post, or Theme Builder layout by auto_index (e.g. "text:5"), admin label, or text content. Uses the same selector validation as diviops_module_update: pass exactly one of auto_index, label, or match_text; use occurrence with duplicate labels. Default mode returns identity, block name, admin label, auto_index, text preview, source bounds, and a compact attr summary. Use full: true to include decoded attrs and raw serialized block markup for the matched module only. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; missing module returns code "not_found" with error.data = { target_kind: "module", target_mode, target_value, page_id }.',
366
+ inputSchema: {
367
+ page_id: z
368
+ .number()
369
+ .int()
370
+ .describe("WordPress post/layout ID whose Divi block content should be searched"),
371
+ label: z
372
+ .string()
373
+ .optional()
374
+ .describe("Admin label of the module (exact match)"),
375
+ match_text: z
376
+ .string()
377
+ .optional()
378
+ .describe("Text to find in module attrs/innerContent (case-insensitive substring, first match)"),
379
+ auto_index: z
380
+ .string()
381
+ .optional()
382
+ .describe('Auto-index target in "type:N" format (e.g. "text:5", "icon:3"). Get from diviops_page_get_layout.'),
383
+ occurrence: z
384
+ .number()
385
+ .int()
386
+ .min(1)
387
+ .optional()
388
+ .default(1)
389
+ .describe("Which occurrence to target when multiple modules share the same label (1-based)"),
390
+ full: z
391
+ .boolean()
392
+ .optional()
393
+ .default(false)
394
+ .describe("Include decoded attrs and raw serialized block markup for the matched module only"),
395
+ },
396
+ annotations: { idempotentHint: true },
397
+ _meta: { idempotent: "true" },
398
+ }, async ({ page_id, label, match_text, auto_index, occurrence, full }) => {
399
+ const params = {};
400
+ if (auto_index)
401
+ params.auto_index = auto_index;
402
+ if (label)
403
+ params.label = label;
404
+ if (match_text)
405
+ params.match_text = match_text;
406
+ if (occurrence > 1)
407
+ params.occurrence = String(occurrence);
408
+ if (full)
409
+ params.full = "true";
410
+ const qs = new URLSearchParams(params).toString();
411
+ const suffix = qs ? `?${qs}` : "";
412
+ const result = await wp.requestEnveloped(`/module/get/${page_id}${suffix}`);
413
+ return {
414
+ content: [
415
+ { type: "text", text: serializeEnvelope(result, "diviops_module_get") },
416
+ ],
417
+ };
418
+ });
281
419
  registerPluginTool("diviops_schema_list_modules", {
282
420
  description: "List all available Divi modules (block types) with their names, titles, and categories. Use this to discover what modules can be used in layouts. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
283
421
  annotations: { idempotentHint: true },
@@ -1750,6 +1888,98 @@ registerPluginTool("diviops_tb_layout_get", {
1750
1888
  ],
1751
1889
  };
1752
1890
  });
1891
+ registerPluginTool("diviops_cross_env_target_context_get", {
1892
+ description: "Export read-only, secret-free target-site context for the offline cross-environment Theme Builder header preflight. Produces JSON suitable for `diviops-cross-env-preflight --target`: target origin derived from WordPress, destination header layout metadata, a sha256 checksum of current target layout post_content without exposing raw content, target global colors, built-in customizer color IDs, sha256 value evidence for user/customizer global colors, defensible attachment candidates/remaps from optional source asset hints, and cache_scope. This Free/core tool does not write layouts, upload media, create global colors, or expose cookies, nonces, app passwords, signed URLs, query strings, fragments, or local filesystem paths. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; unsupported destination_kind returns invalid_input, and missing/non-header layouts return not_found.",
1893
+ inputSchema: {
1894
+ destination_id: z
1895
+ .number()
1896
+ .int()
1897
+ .positive()
1898
+ .describe("Existing target Theme Builder header layout post ID."),
1899
+ destination_kind: z
1900
+ .enum(["tb_header_layout"])
1901
+ .optional()
1902
+ .default("tb_header_layout")
1903
+ .describe("Destination kind. Only tb_header_layout is supported in this read-only slice."),
1904
+ source_asset_hints: z
1905
+ .array(z.string())
1906
+ .optional()
1907
+ .describe("Optional source upload paths, asset URLs, or basenames used to search target media candidates. Query strings, fragments, and credentials are stripped from output."),
1908
+ source_attachment_ids: z
1909
+ .array(z.number())
1910
+ .optional()
1911
+ .describe("Optional numeric source attachment IDs found in source markup. A remap is emitted only when exactly one source ID and one exact target candidate are present."),
1912
+ dry_run: z
1913
+ .boolean()
1914
+ .optional()
1915
+ .default(true)
1916
+ .describe("Accepted for workflow symmetry; the tool is always read-only and never mutates state."),
1917
+ },
1918
+ annotations: { idempotentHint: true },
1919
+ _meta: { idempotent: "true" },
1920
+ }, async ({ destination_id, destination_kind, source_asset_hints, source_attachment_ids, }) => {
1921
+ const body = {
1922
+ destination_id,
1923
+ destination_kind: destination_kind ?? "tb_header_layout",
1924
+ };
1925
+ if (source_asset_hints && source_asset_hints.length > 0) {
1926
+ body.source_asset_hints = source_asset_hints;
1927
+ }
1928
+ if (source_attachment_ids && source_attachment_ids.length > 0) {
1929
+ body.source_attachment_ids = source_attachment_ids;
1930
+ }
1931
+ const result = await wp.requestEnveloped("/cross-env/target-context", {
1932
+ method: "POST",
1933
+ body,
1934
+ });
1935
+ return {
1936
+ content: [
1937
+ {
1938
+ type: "text",
1939
+ text: serializeEnvelope(result, "diviops_cross_env_target_context_get"),
1940
+ },
1941
+ ],
1942
+ };
1943
+ });
1944
+ registerPluginTool("diviops_cross_env_source_export_get", {
1945
+ description: "Export read-only, secret-free source-site payload for the offline cross-environment Theme Builder header preflight. Produces JSON suitable for `diviops-cross-env-preflight --source`: source origin, `tb_header_layout` metadata, sanitized markup, bare sha256 checksum of that exported markup, export timestamp, DiviOps plugin version, and best-effort attachment inventory from markup media URLs and attachment IDs. This Free/core tool does not write layouts, upload media, create global colors, reconcile references, expose cookies, nonces, app passwords, signed URLs, query strings, fragments, admin URLs, or local filesystem paths. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; unsupported source_kind returns invalid_input, and missing/non-header source layouts return not_found.",
1946
+ inputSchema: {
1947
+ source_id: z
1948
+ .number()
1949
+ .int()
1950
+ .positive()
1951
+ .describe("Existing source Theme Builder header layout post ID."),
1952
+ source_kind: z
1953
+ .enum(["tb_header_layout"])
1954
+ .optional()
1955
+ .default("tb_header_layout")
1956
+ .describe("Source kind. Only tb_header_layout is supported in this read-only slice."),
1957
+ dry_run: z
1958
+ .boolean()
1959
+ .optional()
1960
+ .default(true)
1961
+ .describe("Accepted for workflow symmetry; the tool is always read-only and never mutates state."),
1962
+ },
1963
+ annotations: { idempotentHint: true },
1964
+ _meta: { idempotent: "true" },
1965
+ }, async ({ source_id, source_kind }) => {
1966
+ const body = {
1967
+ source_id,
1968
+ source_kind: source_kind ?? "tb_header_layout",
1969
+ };
1970
+ const result = await wp.requestEnveloped("/cross-env/source-export", {
1971
+ method: "POST",
1972
+ body,
1973
+ });
1974
+ return {
1975
+ content: [
1976
+ {
1977
+ type: "text",
1978
+ text: serializeEnvelope(result, "diviops_cross_env_source_export_get"),
1979
+ },
1980
+ ],
1981
+ };
1982
+ });
1753
1983
  registerPluginTool("diviops_tb_layout_update", {
1754
1984
  description: "Update a Theme Builder layout's block markup (header, body, or footer). Replaces the full content. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; missing layout_id returns ok:false with code 'not_found'." +
1755
1985
  DRY_RUN_DESC_SUFFIX,
@@ -2553,30 +2783,11 @@ registerLocalTool("diviops_meta_ping", {
2553
2783
  };
2554
2784
  });
2555
2785
  registerLocalTool("diviops_meta_info", {
2556
- description: "Returns DiviOps MCP server identity, version, license type, and available capabilities. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
2786
+ description: "Returns DiviOps MCP server identity, version, license type, available capability groups, WP-CLI allowlist, and plugin handshake/slice state including Pro and FluentCart target readiness. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
2557
2787
  annotations: { idempotentHint: true },
2558
2788
  _meta: { idempotent: "true" },
2559
2789
  }, async () => {
2560
- const response = await wrapResponse(async () => ({
2561
- brand: "DiviOps",
2562
- server: "diviops-mcp",
2563
- version: SERVER_VERSION,
2564
- license: "MIT",
2565
- capabilities: [
2566
- "pages",
2567
- "modules",
2568
- "presets",
2569
- "library",
2570
- "theme_builder",
2571
- "canvas",
2572
- "variables",
2573
- "templates",
2574
- "icons",
2575
- "validation",
2576
- "preview",
2577
- ],
2578
- wp_cli: wpCli ? wpCli.getAllowedCommands() : false,
2579
- }));
2790
+ const response = await wrapResponse(async () => buildMetaInfo());
2580
2791
  return {
2581
2792
  content: [
2582
2793
  { type: "text", text: serializeEnvelope(response, "diviops_meta_info") },
@@ -3077,7 +3288,7 @@ registerPluginTool("diviops_variable_used_on_page", {
3077
3288
  };
3078
3289
  });
3079
3290
  registerPluginTool("diviops_meta_flush_cache", {
3080
- description: "Flush Divi's compiled static CSS cache under wp-content/et-cache/. wp cache flush does NOT touch these files — the frontend can keep serving stale CSS after a preset/variable/module mutation until the cache is cleared. Delegates to Divi's native ET_Core_PageResource::remove_static_resources when available (response backend: \"divi_native\"), which additionally clears Theme Builder CSS scattered across other post dirs, archive/taxonomy/home/notfound CSS, the object cache, module features cache, post features cache, Google Fonts cache, dynamic assets cache, and post meta caches. Falls back to a targeted filesystem walk of numeric-named et-cache subdirs when the Divi class is absent (backend: \"fs_fallback\"). Provide exactly one selector — no site-wide default to prevent accidental full flush. Idempotent: missing cache root returns 200 with empty list. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; namespace-specific error codes: meta_flush_cache.unwritable (filesystem refused), meta_flush_cache.fs_init_failed (WP_Filesystem could not authenticate)." +
3291
+ description: "Flush Divi's compiled static CSS cache under wp-content/et-cache/. wp cache flush does NOT touch these files — the frontend can keep serving stale CSS after a preset/variable/module mutation until the cache is cleared. Delegates to Divi's native ET_Core_PageResource::remove_static_resources when available (response backend: \"divi_native\"), which additionally clears Theme Builder CSS scattered across other post dirs, archive/taxonomy/home/notfound CSS, the object cache, module features cache, post features cache, Google Fonts cache, dynamic assets cache, and post meta caches. Falls back to a targeted filesystem walk of numeric-named et-cache subdirs when the Divi class is absent (backend: \"fs_fallback\"). Provide exactly one selector — no site-wide default to prevent accidental full flush. Optional cleanup_dynamic_assets=true explicitly deletes and reports _divi_dynamic_assets_cached_feature_used postmeta for the selected target IDs; cleanup_canvas_refs=true also deletes _divi_dynamic_assets_canvases_used and is only appropriate when canvas/off-canvas references are affected. Dynamic-assets postmeta cleanup is supported with post_id or all (bounded to posts that already carry the selected meta keys), not after. Idempotent: missing cache root returns 200 with empty list and repeat postmeta cleanup reports absent keys. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; namespace-specific error codes: meta_flush_cache.unwritable (filesystem refused), meta_flush_cache.fs_init_failed (WP_Filesystem could not authenticate)." +
3081
3292
  DRY_RUN_DESC_SUFFIX +
3082
3293
  " Note: in `after` mode the dry-run plan reports the cutoff only — accurate file count requires the live mtime walk.",
3083
3294
  inputSchema: {
@@ -3099,10 +3310,20 @@ registerPluginTool("diviops_meta_flush_cache", {
3099
3310
  .optional()
3100
3311
  .describe("Unix timestamp — flush Divi CSS files (et-*.css) with mtime strictly greater than this value. Useful for flushing entries touched since a known deployment or mutation batch. Native backend does a single-pass filesystem sweep covering numeric post dirs AND archive/taxonomy/home/notfound/global subtrees in one walk (Visual Builder -vb-* runtime CSS preserved); fs_fallback iterates numeric post dirs whose latest file mtime > after. `flushed` lists numeric post_ids whose files were actually deleted; `skipped` lists numeric post_ids that exist but had no files pass the filter."),
3101
3312
  dry_run: DRY_RUN_FIELD,
3313
+ cleanup_dynamic_assets: z
3314
+ .boolean()
3315
+ .optional()
3316
+ .default(false)
3317
+ .describe("Explicitly delete and report Divi's _divi_dynamic_assets_cached_feature_used postmeta for the selected post_id, or for all posts that already carry selected dynamic-assets postmeta when all=true. Supported with post_id or all only."),
3318
+ cleanup_canvas_refs: z
3319
+ .boolean()
3320
+ .optional()
3321
+ .default(false)
3322
+ .describe("Opt-in canvas/off-canvas cleanup. Requires cleanup_dynamic_assets=true and also deletes _divi_dynamic_assets_canvases_used. Use only when canvas/off-canvas references are affected."),
3102
3323
  },
3103
3324
  annotations: { idempotentHint: true },
3104
3325
  _meta: { idempotent: "true" },
3105
- }, async ({ post_id, all, after, dry_run }) => {
3326
+ }, async ({ post_id, all, after, dry_run, cleanup_dynamic_assets, cleanup_canvas_refs }) => {
3106
3327
  const body = {};
3107
3328
  if (post_id !== undefined)
3108
3329
  body.post_id = post_id;
@@ -3112,6 +3333,10 @@ registerPluginTool("diviops_meta_flush_cache", {
3112
3333
  body.after = after;
3113
3334
  if (dry_run)
3114
3335
  body.dry_run = true;
3336
+ if (cleanup_dynamic_assets)
3337
+ body.cleanup_dynamic_assets = true;
3338
+ if (cleanup_canvas_refs)
3339
+ body.cleanup_canvas_refs = true;
3115
3340
  const result = await wp.requestEnveloped("/meta/flush-cache", {
3116
3341
  method: "POST",
3117
3342
  body,
@@ -3132,7 +3357,132 @@ registerPluginTool("diviops_meta_flush_cache", {
3132
3357
  //
3133
3358
  // Run inside `registerProTools()` rather than at module load because the
3134
3359
  // gates read handshakeState which is `pending` until `main()` runs.
3360
+ const CrossEnvSourceAttachmentSchema = z
3361
+ .object({
3362
+ id: z.number().int().positive().optional(),
3363
+ url: z.string().optional(),
3364
+ path: z.string().optional(),
3365
+ filename: z.string().optional(),
3366
+ mime: z.string().optional(),
3367
+ })
3368
+ .passthrough();
3369
+ const CrossEnvSourcePayloadSchema = z
3370
+ .object({
3371
+ origin: z.string().describe("Source site origin, e.g. https://source.example."),
3372
+ object_kind: z
3373
+ .enum(["tb_header_layout"])
3374
+ .describe("Source object kind. MVP supports tb_header_layout only."),
3375
+ object_id: z.union([z.number(), z.string()]).optional(),
3376
+ object_title: z.string().optional(),
3377
+ markup: z.string().describe("Sanitized source header layout block markup."),
3378
+ checksum: z
3379
+ .string()
3380
+ .regex(/^(sha256:)?[a-fA-F0-9]{64}$/)
3381
+ .describe("sha256 checksum of source_payload.markup from source export."),
3382
+ attachments: z.array(CrossEnvSourceAttachmentSchema).optional(),
3383
+ })
3384
+ .passthrough();
3385
+ function normalizeReviewedFingerprint(value) {
3386
+ return value.trim().replace(/^sha256:/i, "").toLowerCase();
3387
+ }
3388
+ function sourceHintsFromPayload(source) {
3389
+ const hints = new Set();
3390
+ const ids = new Set();
3391
+ for (const attachment of source.attachments ?? []) {
3392
+ if (typeof attachment.id === "number" && Number.isInteger(attachment.id) && attachment.id > 0) {
3393
+ ids.add(attachment.id);
3394
+ }
3395
+ for (const value of [attachment.path, attachment.url, attachment.filename]) {
3396
+ if (typeof value === "string" && value.trim())
3397
+ hints.add(value.trim());
3398
+ }
3399
+ }
3400
+ return {
3401
+ ...(hints.size > 0 ? { source_asset_hints: [...hints].sort((a, b) => a.localeCompare(b)) } : {}),
3402
+ ...(ids.size > 0 ? { source_attachment_ids: [...ids].sort((a, b) => a - b) } : {}),
3403
+ };
3404
+ }
3135
3405
  function registerProTools() {
3406
+ // diviops_cross_env_header_apply — guarded Pro apply for reviewed header preflight
3407
+ registerProTool("diviops_cross_env_header_apply", {
3408
+ description: "Apply a reviewed cross-environment Theme Builder header payload into an existing target header layout (Pro tier; requires the cross_env Pro module). This first MVP is intentionally narrow: it requires `confirm_apply: true`, a source export payload with checksum, an existing target `destination_id`, and the reviewed `confirmation_binding.fingerprint` from `diviops-cross-env-preflight`. The server re-exports current target context, reruns the TypeScript preflight engine, refuses fingerprint mismatch, unsafe verdicts, destination checksum drift, missing/ambiguous attachment remaps, missing global-color value evidence, and off-canvas/canvas references, then calls the Pro route with the verified plan. The Pro route re-loads the destination post, verifies the current checksum again, builds content only from source-origin upload URL rewrites and proven attachment-ID remaps, writes with readback/rollback evidence, and runs Divi static-resource cleanup plus explicit _divi_dynamic_assets_cached_feature_used cleanup. No media upload/import, global-color creation/import, new layout creation, off-canvas reconcile, public/store/license change, or live-site smoke is performed by this tool. Returns the standardized envelope { ok, data?, error: { code, message, hint?, data? } }. Error codes include cross_env.confirmation_required, cross_env.fingerprint_mismatch, cross_env.preflight_not_safe, cross_env.destination_checksum_drift, cross_env.source_checksum_mismatch, cross_env.content_write_corruption, invalid_input, not_found, forbidden, and wp_error.",
3409
+ inputSchema: {
3410
+ source_payload: CrossEnvSourcePayloadSchema.describe("The `data` object returned by diviops_cross_env_source_export_get on the source site."),
3411
+ destination_id: z
3412
+ .number()
3413
+ .int()
3414
+ .positive()
3415
+ .describe("Existing target Theme Builder header layout post ID."),
3416
+ destination_kind: z
3417
+ .enum(["tb_header_layout"])
3418
+ .optional()
3419
+ .default("tb_header_layout")
3420
+ .describe("Destination kind. MVP supports tb_header_layout only."),
3421
+ reviewed_fingerprint: z
3422
+ .string()
3423
+ .regex(/^(sha256:)?[a-fA-F0-9]{64}$/)
3424
+ .describe("Reviewed confirmation_binding.fingerprint from the safe preflight report."),
3425
+ confirm_apply: z
3426
+ .boolean()
3427
+ .describe("Must be true. Missing/false refuses before any target mutation."),
3428
+ },
3429
+ annotations: { idempotentHint: false },
3430
+ _meta: { idempotent: "conditional" },
3431
+ }, async ({ source_payload, destination_id, destination_kind, reviewed_fingerprint, confirm_apply, }) => {
3432
+ const result = await wrapResponse(async () => {
3433
+ if (confirm_apply !== true) {
3434
+ withCode("cross_env.confirmation_required", "confirm_apply: true is required before a cross-env header apply can mutate content.", "Review the preflight report, then retry with confirm_apply: true.");
3435
+ }
3436
+ const targetBody = {
3437
+ destination_id,
3438
+ destination_kind: destination_kind ?? "tb_header_layout",
3439
+ ...sourceHintsFromPayload(source_payload),
3440
+ };
3441
+ const targetEnvelope = await wp.requestEnveloped("/cross-env/target-context", { method: "POST", body: targetBody });
3442
+ if (!targetEnvelope.ok)
3443
+ return targetEnvelope;
3444
+ const report = preflightCrossEnvHeaderSync({
3445
+ source: source_payload,
3446
+ target: targetEnvelope.data,
3447
+ });
3448
+ const reviewed = normalizeReviewedFingerprint(reviewed_fingerprint);
3449
+ if (report.confirmation_binding.fingerprint !== reviewed) {
3450
+ withCode("cross_env.fingerprint_mismatch", "Reviewed confirmation fingerprint does not match the recomputed current preflight report.", "Re-run diviops-cross-env-preflight against the latest target context and confirm the new fingerprint.", {
3451
+ reviewed_fingerprint: reviewed,
3452
+ recomputed_fingerprint: report.confirmation_binding.fingerprint,
3453
+ current_destination_checksum: report.target.destination_checksum ?? null,
3454
+ });
3455
+ }
3456
+ if (report.verdict !== "safe_dry_run") {
3457
+ withCode("cross_env.preflight_not_safe", "Recomputed preflight verdict is not safe for this MVP apply path.", "Resolve blockers/operator actions, then re-run and re-confirm preflight.", {
3458
+ verdict: report.verdict,
3459
+ blockers: report.blockers,
3460
+ operator_actions: report.operator_actions,
3461
+ });
3462
+ }
3463
+ return wp.requestEnveloped("/pro/cross-env/header-layout/apply", {
3464
+ method: "POST",
3465
+ body: {
3466
+ confirm_apply: true,
3467
+ destination_id,
3468
+ destination_kind: destination_kind ?? "tb_header_layout",
3469
+ source_payload,
3470
+ source_checksum: source_payload.checksum,
3471
+ destination_checksum: report.target.destination_checksum,
3472
+ reviewed_fingerprint: reviewed,
3473
+ preflight_report: report,
3474
+ },
3475
+ });
3476
+ });
3477
+ return {
3478
+ content: [
3479
+ {
3480
+ type: "text",
3481
+ text: serializeEnvelope(result, "diviops_cross_env_header_apply"),
3482
+ },
3483
+ ],
3484
+ };
3485
+ }, { target: "cross_env", capabilityKey: "cross_env_header_apply" });
3136
3486
  // diviops_fc_product_list — bridges /diviops/v1/pro/fluentcart/products
3137
3487
  registerProTool("diviops_fc_product_list", {
3138
3488
  description: "List FluentCart Pro products (Pro tier; requires FluentCart Pro installed + activated). Returns a paginated summary list with product identity (id, title, slug, status), variation_type, variants_count, and min/max price. Filterable by `search` (LIKE post_title), `type` (one of physical/digital/subscription/onetime/simple/variations), and `status` (one of publish/draft/pending/private/trash; default returns publish+draft+pending+private). Read-only. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; the success payload is { products: ProductSummary[], pagination: { page, per_page, total, total_pages }, filters: { search, type, status } }. Error codes: invalid_input (HTTP 400) when type/status filter is out of range; fluentcart.module_inactive (HTTP 412) when FluentCart is uninstalled or the diviops-agent-pro module toggle is off; fluentcart.query_failed (HTTP 500) when the underlying FluentCart model query raises an exception (message field carries the upstream exception). Use this before authoring a Divi commerce page to identify which product IDs / types to render.",
@@ -3665,6 +4015,169 @@ function registerProTools() {
3665
4015
  target: "fluentcart",
3666
4016
  capabilityKey: "fluentcart_license_settings_update",
3667
4017
  });
4018
+ // ── V3.4 — downloadable artifact metadata + license changelog ──────
4019
+ //
4020
+ // Store-deployment helper surface. This intentionally complements
4021
+ // FluentCart's native MCP by focusing on DiviOps-specific launch
4022
+ // readiness: metadata-only download rows, attaching an already-present
4023
+ // server-side ZIP, and the FCP Pro updater changelog field. No binary
4024
+ // upload and no signed buyer URLs.
4025
+ // diviops_fc_download_list — POST /diviops/v1/pro/fluentcart/products/{id}/downloads
4026
+ registerProTool("diviops_fc_download_list", {
4027
+ description: "List FluentCart downloadable-file rows for a product (Pro tier; V3.4; requires FluentCart Pro installed + activated). Read-only metadata surface for store artifact deployment. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; success payload is { product_id, downloads: DownloadRow[] }. DownloadRow is { id, title, file_name, driver, file_size, type, variation_ids, is_update_file } — metadata only, never file_path, file_url, download_identifier, signed URLs, or buyer URLs. `is_update_file` is derived from the product's license_settings.global_update_file pointer when present. Use this before `diviops_fc_license_settings_update` so the updater pointer can be set to the plugin ZIP row, not the suite ZIP row. Error codes: invalid_input (400), not_found (404), fluentcart.module_inactive (412), fluentcart.query_failed (500). Idempotency: read-only.",
4028
+ inputSchema: {
4029
+ product_id: z
4030
+ .number()
4031
+ .int()
4032
+ .positive()
4033
+ .describe("FluentCart product ID (the post ID of the fluent_products CPT entry)."),
4034
+ },
4035
+ annotations: { idempotentHint: true },
4036
+ _meta: { idempotent: "true" },
4037
+ }, async ({ product_id }) => {
4038
+ const result = await wp.requestEnveloped(`/pro/fluentcart/products/${product_id}/downloads`, { method: "POST" });
4039
+ return {
4040
+ content: [
4041
+ {
4042
+ type: "text",
4043
+ text: serializeEnvelope(result, "diviops_fc_download_list"),
4044
+ },
4045
+ ],
4046
+ };
4047
+ }, { target: "fluentcart", capabilityKey: "fluentcart_download_list" });
4048
+ // diviops_fc_download_attach — POST /diviops/v1/pro/fluentcart/products/{id}/downloads/attach
4049
+ registerProTool("diviops_fc_download_attach", {
4050
+ description: "Attach an already-present server-side ZIP as a FluentCart downloadable-file row (Pro tier; V3.4; requires FluentCart Pro installed + activated). This is NOT a binary upload tool: `file_path` must resolve to a readable .zip on the WordPress server under ABSPATH or the uploads directory. The response never exposes file paths, file URLs, download identifiers, signed URLs, or buyer URLs. Required: product_id, file_path. Optional: file_name (defaults to basename(file_path), must end in .zip), title (defaults to filename without .zip), variation_ids (must belong to this product; empty means all variants), expected_sha1, expected_size, allow_duplicate (default false), dry_run. Duplicate detection rejects an existing row with the same file_name or title unless allow_duplicate:true is passed. Expected hash/size let operators verify the server-side file matches the locally built artifact before creating the row. Apply-mode success payload is { product_id, created: DownloadRow, downloads: DownloadRow[] } with DownloadRow metadata only. This tool only creates the download row and enables manage_downloadable; it does NOT set license_settings.global_update_file — follow with diviops_fc_license_settings_update using the created row ID. Error codes: invalid_input (400), not_found (404), fluentcart.download_duplicate (409), fluentcart.module_inactive (412), fluentcart.command_failed (500). Idempotency: false; repeat calls are rejected by duplicate detection unless allow_duplicate:true." +
4051
+ DRY_RUN_DESC_SUFFIX,
4052
+ inputSchema: {
4053
+ product_id: z
4054
+ .number()
4055
+ .int()
4056
+ .positive()
4057
+ .describe("FluentCart product ID (the post ID of the fluent_products CPT entry)."),
4058
+ file_path: z
4059
+ .string()
4060
+ .min(1)
4061
+ .describe("Server-side .zip path under ABSPATH or wp_upload_dir().basedir. Relative paths resolve under ABSPATH. No local-client upload occurs."),
4062
+ file_name: z
4063
+ .string()
4064
+ .min(1)
4065
+ .optional()
4066
+ .describe("Download filename shown to buyers/admins. Defaults to basename(file_path). Must end in .zip."),
4067
+ title: z
4068
+ .string()
4069
+ .min(1)
4070
+ .optional()
4071
+ .describe("FluentCart download title. Defaults to file_name without the .zip suffix."),
4072
+ variation_ids: z
4073
+ .array(z.number().int().positive())
4074
+ .optional()
4075
+ .describe("Optional product variation IDs this download applies to. Omit or pass [] for all variants."),
4076
+ expected_sha1: z
4077
+ .string()
4078
+ .regex(/^[a-fA-F0-9]{40}$/)
4079
+ .optional()
4080
+ .describe("Optional SHA1 of the expected server-side file. Mismatch aborts before mutation."),
4081
+ expected_size: z
4082
+ .number()
4083
+ .int()
4084
+ .min(0)
4085
+ .optional()
4086
+ .describe("Optional byte size of the expected server-side file. Mismatch aborts before mutation."),
4087
+ allow_duplicate: z
4088
+ .boolean()
4089
+ .optional()
4090
+ .describe("Default false. When false, an existing row with the same file_name or title returns fluentcart.download_duplicate."),
4091
+ dry_run: DRY_RUN_FIELD,
4092
+ },
4093
+ annotations: { idempotentHint: false },
4094
+ _meta: { idempotent: "false" },
4095
+ }, async ({ product_id, file_path, file_name, title, variation_ids, expected_sha1, expected_size, allow_duplicate, dry_run, }) => {
4096
+ const body = { file_path };
4097
+ if (file_name !== undefined)
4098
+ body.file_name = file_name;
4099
+ if (title !== undefined)
4100
+ body.title = title;
4101
+ if (variation_ids !== undefined)
4102
+ body.variation_ids = variation_ids;
4103
+ if (expected_sha1 !== undefined)
4104
+ body.expected_sha1 = expected_sha1;
4105
+ if (expected_size !== undefined)
4106
+ body.expected_size = expected_size;
4107
+ if (allow_duplicate !== undefined)
4108
+ body.allow_duplicate = allow_duplicate;
4109
+ if (dry_run !== undefined)
4110
+ body.dry_run = dry_run;
4111
+ const result = await wp.requestEnveloped(`/pro/fluentcart/products/${product_id}/downloads/attach`, { method: "POST", body });
4112
+ return {
4113
+ content: [
4114
+ {
4115
+ type: "text",
4116
+ text: serializeEnvelope(result, "diviops_fc_download_attach"),
4117
+ },
4118
+ ],
4119
+ };
4120
+ }, { target: "fluentcart", capabilityKey: "fluentcart_download_attach" });
4121
+ // diviops_fc_license_changelog_get — POST /diviops/v1/pro/fluentcart/products/{id}/license-changelog
4122
+ registerProTool("diviops_fc_license_changelog_get", {
4123
+ description: "Read the FluentCart Pro software-license changelog HTML for a product (Pro tier; V3.4; requires FluentCart Pro installed + activated). This reads ProductMeta meta_key='_fluent_sl_changelog', the field FluentCart Pro shows in Product → License Settings → Changelog Description. Read-only. Returns the standardized envelope { ok, data?, error }; success payload is { product_id, changelog_html, is_empty, storage_meta_key }. Error codes: invalid_input (400), not_found (404), fluentcart.module_inactive (412), fluentcart.query_failed (500). Idempotency: read-only.",
4124
+ inputSchema: {
4125
+ product_id: z
4126
+ .number()
4127
+ .int()
4128
+ .positive()
4129
+ .describe("FluentCart product ID (the post ID of the fluent_products CPT entry)."),
4130
+ },
4131
+ annotations: { idempotentHint: true },
4132
+ _meta: { idempotent: "true" },
4133
+ }, async ({ product_id }) => {
4134
+ const result = await wp.requestEnveloped(`/pro/fluentcart/products/${product_id}/license-changelog`, { method: "POST" });
4135
+ return {
4136
+ content: [
4137
+ {
4138
+ type: "text",
4139
+ text: serializeEnvelope(result, "diviops_fc_license_changelog_get"),
4140
+ },
4141
+ ],
4142
+ };
4143
+ }, {
4144
+ target: "fluentcart",
4145
+ capabilityKey: "fluentcart_license_changelog_get",
4146
+ });
4147
+ // diviops_fc_license_changelog_update — POST /diviops/v1/pro/fluentcart/products/{id}/license-changelog/update
4148
+ registerProTool("diviops_fc_license_changelog_update", {
4149
+ description: "Write the FluentCart Pro software-license changelog HTML for a product (Pro tier; V3.4; requires FluentCart Pro installed + activated). This writes ProductMeta meta_key='_fluent_sl_changelog', the field FluentCart Pro shows in Product → License Settings → Changelog Description. Input is sanitized by WordPress wp_kses_post on the plugin side. Supports dry_run and no-op detection. Success payload is { product_id, changed, changelog_html } or { noop:true, dry_run, product_id, changelog_html }. Error codes: invalid_input (400), not_found (404), fluentcart.module_inactive (412), fluentcart.command_failed (500). Idempotency: conditional — identical repeat is a no-op." +
4150
+ DRY_RUN_DESC_SUFFIX,
4151
+ inputSchema: {
4152
+ product_id: z
4153
+ .number()
4154
+ .int()
4155
+ .positive()
4156
+ .describe("FluentCart product ID (the post ID of the fluent_products CPT entry)."),
4157
+ changelog_html: z
4158
+ .string()
4159
+ .describe("Buyer/update-facing changelog HTML. Sanitized with wp_kses_post before storage."),
4160
+ dry_run: DRY_RUN_FIELD,
4161
+ },
4162
+ annotations: { idempotentHint: false },
4163
+ _meta: { idempotent: "conditional" },
4164
+ }, async ({ product_id, changelog_html, dry_run, }) => {
4165
+ const body = { changelog_html };
4166
+ if (dry_run !== undefined)
4167
+ body.dry_run = dry_run;
4168
+ const result = await wp.requestEnveloped(`/pro/fluentcart/products/${product_id}/license-changelog/update`, { method: "POST", body });
4169
+ return {
4170
+ content: [
4171
+ {
4172
+ type: "text",
4173
+ text: serializeEnvelope(result, "diviops_fc_license_changelog_update"),
4174
+ },
4175
+ ],
4176
+ };
4177
+ }, {
4178
+ target: "fluentcart",
4179
+ capabilityKey: "fluentcart_license_changelog_update",
4180
+ });
3668
4181
  // ── V3.1 — order/license/activation read + guarded mark-paid ───────
3669
4182
  //
3670
4183
  // FluentCart commerce-artifact readback surface plus a single
@@ -4083,6 +4596,7 @@ async function main() {
4083
4596
  kind: "ok",
4084
4597
  capabilities: hs.capabilities,
4085
4598
  pluginVersion: hs.plugin_version,
4599
+ proVersion: hs.pro_version,
4086
4600
  proActive: hs.pro_active === true,
4087
4601
  availableTargets: hs.available_targets ?? {},
4088
4602
  activeModules: hs.active_modules ?? {},