@diviops/mcp-server 1.5.38 → 1.5.40
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/README.md +54 -10
- package/dist/canonical-tool-registry.d.ts +21 -0
- package/dist/canonical-tool-registry.js +33 -0
- package/dist/compatibility.d.ts +7 -0
- package/dist/cross-env-source-hints.d.ts +7 -0
- package/dist/cross-env-source-hints.js +22 -0
- package/dist/health-tools.d.ts +53 -0
- package/dist/health-tools.js +83 -0
- package/dist/index.d.ts +26 -1
- package/dist/index.js +72 -49
- package/dist/target-evidence.d.ts +40 -0
- package/dist/target-evidence.js +152 -0
- package/dist/wp-client.d.ts +6 -2
- package/dist/wp-client.js +14 -7
- package/package.json +16 -4
package/README.md
CHANGED
|
@@ -21,7 +21,8 @@ DiviOps fits multiple WordPress workflows where AI-driven authoring + management
|
|
|
21
21
|
|
|
22
22
|
## Quick start
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
The first three steps prove connectivity. Native Divi authoring additionally
|
|
25
|
+
requires the client-side skill and first-run verification in steps 4 and 5.
|
|
25
26
|
|
|
26
27
|
### 1. Install the WordPress plugin
|
|
27
28
|
|
|
@@ -38,6 +39,19 @@ In **WP Admin → Users → Your Profile → Application Passwords**:
|
|
|
38
39
|
|
|
39
40
|
### 3. Register the MCP server
|
|
40
41
|
|
|
42
|
+
The successor server line requires Node.js 22 or newer. Upgrade Node before
|
|
43
|
+
selecting `@diviops/mcp-server@1.5.40` or a later release. Operators who must
|
|
44
|
+
remain on Node 18 can pin the previously shipped compatible server explicitly:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npx -y --package=@diviops/mcp-server@1.5.39 diviops-mcp
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
That pin affects only the MCP server. Free and Pro WordPress plugin versions
|
|
51
|
+
use independent version series and remain compatible through the advertised
|
|
52
|
+
per-capability handshake. Direct npm/stdio and MCP v1 remain supported on the
|
|
53
|
+
Node 22 successor; MCP v2 fixtures and the launcher sidecar are not published.
|
|
54
|
+
|
|
41
55
|
Claude Code:
|
|
42
56
|
|
|
43
57
|
```bash
|
|
@@ -61,12 +75,39 @@ WP_USER = "your-wp-username"
|
|
|
61
75
|
WP_APP_PASSWORD = "xxxxXXXXxxxxXXXXxxxxXXXX"
|
|
62
76
|
```
|
|
63
77
|
|
|
64
|
-
Then ask your AI client: **"List the pages on my site."** It calls
|
|
78
|
+
Then ask your AI client: **"List the pages on my site."** It calls
|
|
79
|
+
`diviops_page_list` and renders the result. This proves the plugin and MCP transport;
|
|
80
|
+
it does not prove that the client has loaded Divi authoring knowledge.
|
|
65
81
|
|
|
66
82
|
For Claude Desktop JSON, use `"command": "npx"` with args `["-y", "--package", "@diviops/mcp-server", "diviops-mcp"]`. The package also ships `diviops-preset`, so the explicit package/bin form is required; shorthand package invocation cannot reliably infer which bin to run.
|
|
67
83
|
|
|
84
|
+
The public npm package exposes exactly three supported CLIs:
|
|
85
|
+
`diviops-mcp`, `diviops-preset`, and `diviops-cross-env-preflight`. The
|
|
86
|
+
launcher-managed MCP sidecar is a separate future artifact identity; it is not
|
|
87
|
+
a public npm bin or part of the npm tarball. Repository launcher development
|
|
88
|
+
builds and supplies that private entrypoint explicitly. This boundary does not
|
|
89
|
+
change direct npm/stdio support.
|
|
90
|
+
|
|
68
91
|
For a deeper walkthrough (containerized environments, WP-CLI configuration, troubleshooting installation), see [setup-guide.md](../docs/setup-guide.md).
|
|
69
92
|
|
|
93
|
+
### 4. Load the `divi-5-builder` skill
|
|
94
|
+
|
|
95
|
+
Install it for Claude Code by running
|
|
96
|
+
`claude plugin marketplace add oaris-dev/diviops` and then
|
|
97
|
+
`claude plugin install divi-5-builder@diviops`, or copy the distribution's
|
|
98
|
+
`skills/*` into the supported skill directory for Codex/manual setups. WordPress
|
|
99
|
+
and npm updates do not update manual skill copies. Avoid simultaneous
|
|
100
|
+
plugin-managed and stale manual copies, then restart the client and confirm
|
|
101
|
+
`divi-5-builder` is visible.
|
|
102
|
+
|
|
103
|
+
### 5. Prove native module authoring
|
|
104
|
+
|
|
105
|
+
Run the disposable, fail-closed
|
|
106
|
+
[native Divi verification](../docs/setup-guide.md#first-run-native-divi-verification).
|
|
107
|
+
Stop if the skill or required tools are unavailable. Do not accept page-sized HTML,
|
|
108
|
+
Code modules, iframe layouts, or structural HTML in text/container fields as a
|
|
109
|
+
fallback for editable native Divi modules.
|
|
110
|
+
|
|
70
111
|
## Example workflow
|
|
71
112
|
|
|
72
113
|
> **You:** Create a hero section on a new page called "Spring Launch" with a heading, subheading, and a CTA button. Use my brand colors.
|
|
@@ -75,9 +116,10 @@ Claude orchestrates a few tool calls in sequence:
|
|
|
75
116
|
|
|
76
117
|
1. `diviops_global_color_list` — discovers your brand palette.
|
|
77
118
|
2. `diviops_template_list` / `diviops_template_get` — pulls a verified hero template that matches the request.
|
|
78
|
-
3. `
|
|
79
|
-
4. `
|
|
80
|
-
5. `
|
|
119
|
+
3. `diviops_validate_blocks` with inline `content` — confirms the constructed hero markup is well-formed before any write.
|
|
120
|
+
4. `diviops_page_create` — creates `Spring Launch` as a draft using those exact validated bytes.
|
|
121
|
+
5. `diviops_validate_blocks` with the saved `page_id` — verifies persisted readback.
|
|
122
|
+
6. `diviops_render_preview` — returns the rendered HTML so you can verify before publishing. Accepts inline `content` or a `page_id` to preview an existing page.
|
|
81
123
|
|
|
82
124
|
The skill enforces the Divi block format, the design system, and the response contract throughout — you stay at the prompt level.
|
|
83
125
|
|
|
@@ -219,10 +261,12 @@ plus checksum, not an arbitrary filesystem path.
|
|
|
219
261
|
To collect the target JSON from the target WordPress site, call the Free/core
|
|
220
262
|
read-only MCP tool `diviops_cross_env_target_context_get` against the target
|
|
221
263
|
server and save the returned `data` object as `target.json`. Optional
|
|
222
|
-
`source_asset_hints` and `source_attachment_ids` let the
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
264
|
+
`source_asset_hints`, `source_upload_paths`, and `source_attachment_ids` let the
|
|
265
|
+
target site search for media-library candidates. `source_upload_paths` preserves
|
|
266
|
+
exact path provenance, including for root-level filenames; basename-only hints
|
|
267
|
+
remain ambiguous when multiple target paths share a filename. No media is
|
|
268
|
+
uploaded and no global colors or layouts are created. The export includes a
|
|
269
|
+
SHA-256 checksum of the current target layout
|
|
226
270
|
`post_content` as `destination_checksum` so preflight can bind the reviewed plan
|
|
227
271
|
to the target state without exposing the raw target content. It also includes
|
|
228
272
|
`global_color_value_evidence`, a deterministic SHA-256 digest map for resolved
|
|
@@ -373,7 +417,7 @@ Common quick fixes — full reference in [troubleshooting.md](../docs/troublesho
|
|
|
373
417
|
|
|
374
418
|
## Requirements
|
|
375
419
|
|
|
376
|
-
- Node.js >=
|
|
420
|
+
- Node.js >= 22.0.0
|
|
377
421
|
- PHP >= 7.4
|
|
378
422
|
- WordPress >= 6.5
|
|
379
423
|
- Divi 5 theme active
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport-neutral ownership of DiviOps MCP registrations.
|
|
3
|
+
*
|
|
4
|
+
* The shipped server still materializes this registry into the v1 SDK. The
|
|
5
|
+
* non-publishing v2 compatibility spike materializes the same definitions
|
|
6
|
+
* into the split v2 server package. Keeping the registry ignorant of either
|
|
7
|
+
* SDK is the guard against a second tool catalog or a wire-shape translator.
|
|
8
|
+
*/
|
|
9
|
+
export type ToolRegistrar = {
|
|
10
|
+
registerTool(name: string, config: any, handler: any): unknown;
|
|
11
|
+
};
|
|
12
|
+
export type ResourceRegistrar = {
|
|
13
|
+
registerResource(name: string, uri: string, config: any, handler: any): unknown;
|
|
14
|
+
};
|
|
15
|
+
export type RegistryTarget = ToolRegistrar & ResourceRegistrar;
|
|
16
|
+
export declare class CanonicalToolRegistry implements RegistryTarget {
|
|
17
|
+
#private;
|
|
18
|
+
registerTool(name: string, config: any, handler: any): void;
|
|
19
|
+
registerResource(name: string, uri: string, config: any, handler: any): void;
|
|
20
|
+
install(target: RegistryTarget): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport-neutral ownership of DiviOps MCP registrations.
|
|
3
|
+
*
|
|
4
|
+
* The shipped server still materializes this registry into the v1 SDK. The
|
|
5
|
+
* non-publishing v2 compatibility spike materializes the same definitions
|
|
6
|
+
* into the split v2 server package. Keeping the registry ignorant of either
|
|
7
|
+
* SDK is the guard against a second tool catalog or a wire-shape translator.
|
|
8
|
+
*/
|
|
9
|
+
export class CanonicalToolRegistry {
|
|
10
|
+
#tools = new Map();
|
|
11
|
+
#resources = new Map();
|
|
12
|
+
registerTool(name, config, handler) {
|
|
13
|
+
if (this.#tools.has(name)) {
|
|
14
|
+
throw new Error(`Duplicate canonical MCP tool registration: ${name}`);
|
|
15
|
+
}
|
|
16
|
+
this.#tools.set(name, { name, config, handler });
|
|
17
|
+
}
|
|
18
|
+
registerResource(name, uri, config, handler) {
|
|
19
|
+
if (this.#resources.has(name)) {
|
|
20
|
+
throw new Error(`Duplicate canonical MCP resource registration: ${name}`);
|
|
21
|
+
}
|
|
22
|
+
this.#resources.set(name, { name, uri, config, handler });
|
|
23
|
+
}
|
|
24
|
+
install(target) {
|
|
25
|
+
for (const registration of this.#tools.values()) {
|
|
26
|
+
target.registerTool(registration.name, registration.config, registration.handler);
|
|
27
|
+
}
|
|
28
|
+
for (const registration of this.#resources.values()) {
|
|
29
|
+
target.registerResource(registration.name, registration.uri, registration.config, registration.handler);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
package/dist/compatibility.d.ts
CHANGED
|
@@ -80,6 +80,13 @@ export interface HandshakeResult {
|
|
|
80
80
|
active_modules?: Record<string, boolean>;
|
|
81
81
|
/** Advisory installed-plugin versions for S0 preflight reports. */
|
|
82
82
|
plugins?: Record<string, HandshakePluginInfo>;
|
|
83
|
+
/** Permission-gated non-secret identity of the authenticated App Password owner. */
|
|
84
|
+
authenticated_user?: {
|
|
85
|
+
id: number;
|
|
86
|
+
login: string;
|
|
87
|
+
};
|
|
88
|
+
/** Observed WordPress site URL; normalized and pinned by launcher mode. */
|
|
89
|
+
site_url?: string;
|
|
83
90
|
}
|
|
84
91
|
export declare function proToolGatesSatisfied(state: {
|
|
85
92
|
proActive: boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SourceLayoutPayload } from "./cross-env-preflight/header-preflight.js";
|
|
2
|
+
export interface CrossEnvSourceHints {
|
|
3
|
+
source_asset_hints?: string[];
|
|
4
|
+
source_upload_paths?: string[];
|
|
5
|
+
source_attachment_ids?: number[];
|
|
6
|
+
}
|
|
7
|
+
export declare function sourceHintsFromPayload(source: SourceLayoutPayload): CrossEnvSourceHints;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function sourceHintsFromPayload(source) {
|
|
2
|
+
const hints = new Set();
|
|
3
|
+
const uploadPaths = new Set();
|
|
4
|
+
const ids = new Set();
|
|
5
|
+
for (const attachment of source.attachments ?? []) {
|
|
6
|
+
if (typeof attachment.id === "number" && Number.isInteger(attachment.id) && attachment.id > 0) {
|
|
7
|
+
ids.add(attachment.id);
|
|
8
|
+
}
|
|
9
|
+
for (const value of [attachment.path, attachment.url, attachment.filename]) {
|
|
10
|
+
if (typeof value === "string" && value.trim())
|
|
11
|
+
hints.add(value.trim());
|
|
12
|
+
}
|
|
13
|
+
if (typeof attachment.path === "string" && attachment.path.trim()) {
|
|
14
|
+
uploadPaths.add(attachment.path.trim());
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
...(hints.size > 0 ? { source_asset_hints: [...hints].sort((a, b) => a.localeCompare(b)) } : {}),
|
|
19
|
+
...(uploadPaths.size > 0 ? { source_upload_paths: [...uploadPaths].sort((a, b) => a.localeCompare(b)) } : {}),
|
|
20
|
+
...(ids.size > 0 ? { source_attachment_ids: [...ids].sort((a, b) => a - b) } : {}),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ToolRegistrar } from "./canonical-tool-registry.js";
|
|
2
|
+
import type { WPClient } from "./wp-client.js";
|
|
3
|
+
import type { TargetEvidence } from "./target-evidence.js";
|
|
4
|
+
export declare const LAUNCHER_HEALTH_TOOL_NAMES: readonly ["diviops_meta_ping", "diviops_meta_info"];
|
|
5
|
+
export declare const META_PING_CONFIG: {
|
|
6
|
+
readonly description: "Test the connection to the WordPress site and verify the Divi MCP plugin is active. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; success payload is { connected: true, message: \"Connected to Divi <version>\" } and connection failure surfaces as { ok: false, error: { code: 'wp_error', message } } with the underlying transport message preserved.";
|
|
7
|
+
readonly annotations: {
|
|
8
|
+
readonly readOnlyHint: true;
|
|
9
|
+
readonly idempotentHint: true;
|
|
10
|
+
};
|
|
11
|
+
readonly _meta: {
|
|
12
|
+
readonly idempotent: "true";
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare const META_INFO_CONFIG: {
|
|
16
|
+
readonly description: "Returns DiviOps MCP server identity, server_version, license type, numeric tool_count, registered tool catalog summary, active plugin version summary, WP-CLI allowlist, and plugin handshake/slice state including Pro and FluentCart target readiness. Use as the S0 preflight before dogfooding or product work. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.";
|
|
17
|
+
readonly annotations: {
|
|
18
|
+
readonly readOnlyHint: true;
|
|
19
|
+
readonly idempotentHint: true;
|
|
20
|
+
};
|
|
21
|
+
readonly _meta: {
|
|
22
|
+
readonly idempotent: "true";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare function modelVisibleHealthResult(response: unknown, target: TargetEvidence, toolName: string): {
|
|
26
|
+
content: {
|
|
27
|
+
type: "text";
|
|
28
|
+
text: string;
|
|
29
|
+
}[];
|
|
30
|
+
structuredContent: {
|
|
31
|
+
result: unknown;
|
|
32
|
+
diviops_target: TargetEvidence;
|
|
33
|
+
};
|
|
34
|
+
_meta: {
|
|
35
|
+
diviops_target: TargetEvidence;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
type ToolCancellationContext = {
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
mcpReq?: {
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export declare function requestAbortSignal(args: unknown, context?: ToolCancellationContext): AbortSignal | undefined;
|
|
45
|
+
export declare function registerLauncherHealthTools(options: {
|
|
46
|
+
server: ToolRegistrar;
|
|
47
|
+
wp: {
|
|
48
|
+
testConnection(signal?: AbortSignal): ReturnType<WPClient["testConnection"]>;
|
|
49
|
+
};
|
|
50
|
+
observe: (signal?: AbortSignal) => Promise<TargetEvidence>;
|
|
51
|
+
serverVersion: string;
|
|
52
|
+
}): void;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ErrorCodes, recordIdempotent, serializeEnvelope, withCode, wrapResponse, } from "./envelope.js";
|
|
2
|
+
export const LAUNCHER_HEALTH_TOOL_NAMES = [
|
|
3
|
+
"diviops_meta_ping",
|
|
4
|
+
"diviops_meta_info",
|
|
5
|
+
];
|
|
6
|
+
export const META_PING_CONFIG = {
|
|
7
|
+
description: "Test the connection to the WordPress site and verify the Divi MCP plugin is active. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; success payload is { connected: true, message: \"Connected to Divi <version>\" } and connection failure surfaces as { ok: false, error: { code: 'wp_error', message } } with the underlying transport message preserved.",
|
|
8
|
+
annotations: { readOnlyHint: true, idempotentHint: true },
|
|
9
|
+
_meta: { idempotent: "true" },
|
|
10
|
+
};
|
|
11
|
+
export const META_INFO_CONFIG = {
|
|
12
|
+
description: "Returns DiviOps MCP server identity, server_version, license type, numeric tool_count, registered tool catalog summary, active plugin version summary, WP-CLI allowlist, and plugin handshake/slice state including Pro and FluentCart target readiness. Use as the S0 preflight before dogfooding or product work. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
|
|
13
|
+
annotations: { readOnlyHint: true, idempotentHint: true },
|
|
14
|
+
_meta: { idempotent: "true" },
|
|
15
|
+
};
|
|
16
|
+
export function modelVisibleHealthResult(response, target, toolName) {
|
|
17
|
+
const visible = {
|
|
18
|
+
...response,
|
|
19
|
+
diviops_target: target,
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
content: [
|
|
23
|
+
{
|
|
24
|
+
type: "text",
|
|
25
|
+
text: serializeEnvelope(visible, toolName),
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
structuredContent: {
|
|
29
|
+
result: response,
|
|
30
|
+
diviops_target: target,
|
|
31
|
+
},
|
|
32
|
+
_meta: { diviops_target: target },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function requestAbortSignal(args, context) {
|
|
36
|
+
const fallback = args;
|
|
37
|
+
return (context?.mcpReq?.signal ??
|
|
38
|
+
context?.signal ??
|
|
39
|
+
fallback?.mcpReq?.signal ??
|
|
40
|
+
fallback?.signal);
|
|
41
|
+
}
|
|
42
|
+
export function registerLauncherHealthTools(options) {
|
|
43
|
+
const { server, wp, observe, serverVersion } = options;
|
|
44
|
+
recordIdempotent("diviops_meta_ping", META_PING_CONFIG._meta);
|
|
45
|
+
recordIdempotent("diviops_meta_info", META_INFO_CONFIG._meta);
|
|
46
|
+
server.registerTool("diviops_meta_ping", META_PING_CONFIG, async (_args, context) => {
|
|
47
|
+
const signal = requestAbortSignal(_args, context);
|
|
48
|
+
const target = await observe(signal);
|
|
49
|
+
const response = await wrapResponse(async () => {
|
|
50
|
+
const ping = await wp.testConnection(signal);
|
|
51
|
+
if (!ping.ok)
|
|
52
|
+
withCode(ErrorCodes.WP_ERROR, ping.message);
|
|
53
|
+
return { connected: true, message: ping.message };
|
|
54
|
+
});
|
|
55
|
+
return modelVisibleHealthResult(response, target, "diviops_meta_ping");
|
|
56
|
+
});
|
|
57
|
+
server.registerTool("diviops_meta_info", META_INFO_CONFIG, async (_args, context) => {
|
|
58
|
+
const target = await observe(requestAbortSignal(_args, context));
|
|
59
|
+
const response = await wrapResponse(async () => ({
|
|
60
|
+
brand: "DiviOps",
|
|
61
|
+
server: "diviops-mcp",
|
|
62
|
+
server_version: serverVersion,
|
|
63
|
+
version: serverVersion,
|
|
64
|
+
license: "MIT",
|
|
65
|
+
launcher_mode: true,
|
|
66
|
+
tool_count: LAUNCHER_HEALTH_TOOL_NAMES.length,
|
|
67
|
+
tools: {
|
|
68
|
+
registered_total: LAUNCHER_HEALTH_TOOL_NAMES.length,
|
|
69
|
+
registered_tool_names: [...LAUNCHER_HEALTH_TOOL_NAMES],
|
|
70
|
+
},
|
|
71
|
+
plugins: {
|
|
72
|
+
diviops_agent: { active: true, version: target.plugin_version },
|
|
73
|
+
},
|
|
74
|
+
handshake: {
|
|
75
|
+
state: "ok",
|
|
76
|
+
plugin_version: target.plugin_version,
|
|
77
|
+
capability_count: Object.values(target.capabilities).filter(Boolean).length,
|
|
78
|
+
},
|
|
79
|
+
wp_cli: false,
|
|
80
|
+
}));
|
|
81
|
+
return modelVisibleHealthResult(response, target, "diviops_meta_info");
|
|
82
|
+
});
|
|
83
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,4 +8,29 @@
|
|
|
8
8
|
* Auth: WordPress Application Passwords (Basic Auth).
|
|
9
9
|
* Config: Environment variables WP_URL, WP_USER, WP_APP_PASSWORD.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
import { type HandshakePluginInfo } from "./compatibility.js";
|
|
12
|
+
import { CanonicalToolRegistry } from "./canonical-tool-registry.js";
|
|
13
|
+
export type HandshakeState = {
|
|
14
|
+
kind: "ok";
|
|
15
|
+
capabilities: Record<string, boolean>;
|
|
16
|
+
pluginVersion: string | null;
|
|
17
|
+
proVersion?: string;
|
|
18
|
+
proActive: boolean;
|
|
19
|
+
availableTargets: Record<string, {
|
|
20
|
+
present: boolean;
|
|
21
|
+
version?: string | null;
|
|
22
|
+
}>;
|
|
23
|
+
activeModules: Record<string, boolean>;
|
|
24
|
+
plugins: Record<string, HandshakePluginInfo>;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "failed";
|
|
27
|
+
} | {
|
|
28
|
+
kind: "pending";
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Complete the canonical registry after the connected site's handshake has
|
|
32
|
+
* settled. Production startup and the credential-free dual-era compatibility
|
|
33
|
+
* fixture deliberately share this seam so the v2 proof materializes the real
|
|
34
|
+
* Free/Pro-gated catalog instead of maintaining a second set of definitions.
|
|
35
|
+
*/
|
|
36
|
+
export declare function finalizeProductionRegistryForHandshake(state: HandshakeState): CanonicalToolRegistry;
|
package/dist/index.js
CHANGED
|
@@ -18,12 +18,15 @@ import { ErrorCodes, envelopeMap, recordIdempotent, serializeEnvelope, withCode,
|
|
|
18
18
|
import { preflightCrossEnvHeaderSync, } from "./cross-env-preflight/header-preflight.js";
|
|
19
19
|
import { preflightCrossEnvThemeBuilderLayoutSync, } from "./cross-env-preflight/layout-preflight.js";
|
|
20
20
|
import { crossEnvEvidenceLayoutKinds } from "./cross-env-preflight/layout-capability.js";
|
|
21
|
+
import { sourceHintsFromPayload } from "./cross-env-source-hints.js";
|
|
21
22
|
import { createSourcePayloadRef, loadSourcePayloadRef, } from "./cross-env-preflight/source-payload-ref.js";
|
|
22
23
|
import { optimizeSchema } from "./schema-optimizer.js";
|
|
23
24
|
import { schemaModuleRoute } from "./schema-route.js";
|
|
24
25
|
import { createWpCli } from "./wp-cli.js";
|
|
26
|
+
import { META_INFO_CONFIG, META_PING_CONFIG, requestAbortSignal, } from "./health-tools.js";
|
|
27
|
+
import { CanonicalToolRegistry } from "./canonical-tool-registry.js";
|
|
25
28
|
import { isolationFailure, scanValueForForeignVarRefs, writerIsolationErrorResult, } from "./validate-attrs.js";
|
|
26
|
-
import { readFileSync, readdirSync } from "fs";
|
|
29
|
+
import { readFileSync, readdirSync, realpathSync } from "fs";
|
|
27
30
|
import { join, dirname } from "path";
|
|
28
31
|
import { fileURLToPath } from "url";
|
|
29
32
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -31,7 +34,9 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
31
34
|
const WP_URL = process.env.WP_URL ?? "";
|
|
32
35
|
const WP_USER = process.env.WP_USER ?? "";
|
|
33
36
|
const WP_APP_PASSWORD = process.env.WP_APP_PASSWORD ?? "";
|
|
34
|
-
|
|
37
|
+
function requireCredentials() {
|
|
38
|
+
if (WP_URL && WP_USER && WP_APP_PASSWORD)
|
|
39
|
+
return;
|
|
35
40
|
const missing = [
|
|
36
41
|
!WP_URL && "WP_URL",
|
|
37
42
|
!WP_USER && "WP_USER",
|
|
@@ -86,10 +91,7 @@ const SERVER_VERSION = (() => {
|
|
|
86
91
|
}
|
|
87
92
|
})();
|
|
88
93
|
// ── MCP Server ───────────────────────────────────────────────────────
|
|
89
|
-
const
|
|
90
|
-
name: "diviops-mcp",
|
|
91
|
-
version: SERVER_VERSION,
|
|
92
|
-
});
|
|
94
|
+
const registry = new CanonicalToolRegistry();
|
|
93
95
|
let handshakeState = { kind: "pending" };
|
|
94
96
|
const toolCatalog = [];
|
|
95
97
|
function recordToolCatalog(entry) {
|
|
@@ -351,7 +353,7 @@ function registerPluginTool(name, config, handler) {
|
|
|
351
353
|
return handler(args);
|
|
352
354
|
});
|
|
353
355
|
recordIdempotent(name, config?._meta);
|
|
354
|
-
|
|
356
|
+
registry.registerTool(name, config, wrapped);
|
|
355
357
|
}
|
|
356
358
|
/**
|
|
357
359
|
* Server-local tools (no plugin dependency) register via this thin shim
|
|
@@ -363,7 +365,7 @@ function registerPluginTool(name, config, handler) {
|
|
|
363
365
|
function registerLocalTool(name, config, handler) {
|
|
364
366
|
recordToolCatalog({ name, kind: "server_local", registered: true });
|
|
365
367
|
recordIdempotent(name, config?._meta);
|
|
366
|
-
|
|
368
|
+
registry.registerTool(name, config, handler);
|
|
367
369
|
}
|
|
368
370
|
/**
|
|
369
371
|
* Register a Pro-coverage-slice tool (ADR-003 / ADR-007).
|
|
@@ -416,7 +418,7 @@ function registerProTool(name, config, handler, gates) {
|
|
|
416
418
|
return;
|
|
417
419
|
catalogEntry.registered = true;
|
|
418
420
|
recordIdempotent(name, config?._meta);
|
|
419
|
-
|
|
421
|
+
registry.registerTool(name, config, handler);
|
|
420
422
|
}
|
|
421
423
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
422
424
|
// ── dry_run convention ──────────────────────────────────────────────
|
|
@@ -2529,6 +2531,10 @@ function registerCrossEnvEvidenceTools() {
|
|
|
2529
2531
|
.array(z.string())
|
|
2530
2532
|
.optional()
|
|
2531
2533
|
.describe("Optional source upload paths, asset URLs, or basenames used to search target media candidates. Query strings, fragments, and credentials are stripped from output."),
|
|
2534
|
+
source_upload_paths: z
|
|
2535
|
+
.array(z.string())
|
|
2536
|
+
.optional()
|
|
2537
|
+
.describe("Optional source-export attachment paths with exact-path provenance, including root-level filenames."),
|
|
2532
2538
|
source_attachment_ids: z
|
|
2533
2539
|
.array(z.number())
|
|
2534
2540
|
.optional()
|
|
@@ -2541,7 +2547,7 @@ function registerCrossEnvEvidenceTools() {
|
|
|
2541
2547
|
},
|
|
2542
2548
|
annotations: { idempotentHint: true },
|
|
2543
2549
|
_meta: { idempotent: "true" },
|
|
2544
|
-
}, async ({ destination_id, destination_kind, source_asset_hints, source_attachment_ids, }) => {
|
|
2550
|
+
}, async ({ destination_id, destination_kind, source_asset_hints, source_upload_paths, source_attachment_ids, }) => {
|
|
2545
2551
|
const body = {
|
|
2546
2552
|
destination_id,
|
|
2547
2553
|
destination_kind: destination_kind ?? "tb_header_layout",
|
|
@@ -2549,6 +2555,9 @@ function registerCrossEnvEvidenceTools() {
|
|
|
2549
2555
|
if (source_asset_hints && source_asset_hints.length > 0) {
|
|
2550
2556
|
body.source_asset_hints = source_asset_hints;
|
|
2551
2557
|
}
|
|
2558
|
+
if (source_upload_paths && source_upload_paths.length > 0) {
|
|
2559
|
+
body.source_upload_paths = source_upload_paths;
|
|
2560
|
+
}
|
|
2552
2561
|
if (source_attachment_ids && source_attachment_ids.length > 0) {
|
|
2553
2562
|
body.source_attachment_ids = source_attachment_ids;
|
|
2554
2563
|
}
|
|
@@ -3490,12 +3499,12 @@ registerLocalTool("diviops_scf_field_group_get", {
|
|
|
3490
3499
|
});
|
|
3491
3500
|
// ── Connection ──────────────────────────────────────────────────────
|
|
3492
3501
|
registerLocalTool("diviops_meta_ping", {
|
|
3493
|
-
|
|
3494
|
-
annotations: { idempotentHint: true },
|
|
3502
|
+
...META_PING_CONFIG,
|
|
3495
3503
|
_meta: { idempotent: "true" },
|
|
3496
|
-
}, async () => {
|
|
3504
|
+
}, async (_args, context) => {
|
|
3505
|
+
const signal = requestAbortSignal(_args, context);
|
|
3497
3506
|
const response = await wrapResponse(async () => {
|
|
3498
|
-
const ping = await wp.testConnection();
|
|
3507
|
+
const ping = await wp.testConnection(signal);
|
|
3499
3508
|
if (!ping.ok) {
|
|
3500
3509
|
withCode(ErrorCodes.WP_ERROR, ping.message);
|
|
3501
3510
|
}
|
|
@@ -3508,8 +3517,7 @@ registerLocalTool("diviops_meta_ping", {
|
|
|
3508
3517
|
};
|
|
3509
3518
|
});
|
|
3510
3519
|
registerLocalTool("diviops_meta_info", {
|
|
3511
|
-
|
|
3512
|
-
annotations: { idempotentHint: true },
|
|
3520
|
+
...META_INFO_CONFIG,
|
|
3513
3521
|
_meta: { idempotent: "true" },
|
|
3514
3522
|
}, async () => {
|
|
3515
3523
|
const response = await wrapResponse(async () => buildMetaInfo());
|
|
@@ -3520,7 +3528,7 @@ registerLocalTool("diviops_meta_info", {
|
|
|
3520
3528
|
};
|
|
3521
3529
|
});
|
|
3522
3530
|
// ── Resources ────────────────────────────────────────────────────────
|
|
3523
|
-
|
|
3531
|
+
registry.registerResource("divi-block-format-guide", "divi://block-format-guide", {}, async () => ({
|
|
3524
3532
|
contents: [
|
|
3525
3533
|
{
|
|
3526
3534
|
uri: "divi://block-format-guide",
|
|
@@ -4133,23 +4141,6 @@ const CrossEnvSourcePayloadRefSchema = z
|
|
|
4133
4141
|
function normalizeReviewedFingerprint(value) {
|
|
4134
4142
|
return value.trim().replace(/^sha256:/i, "").toLowerCase();
|
|
4135
4143
|
}
|
|
4136
|
-
function sourceHintsFromPayload(source) {
|
|
4137
|
-
const hints = new Set();
|
|
4138
|
-
const ids = new Set();
|
|
4139
|
-
for (const attachment of source.attachments ?? []) {
|
|
4140
|
-
if (typeof attachment.id === "number" && Number.isInteger(attachment.id) && attachment.id > 0) {
|
|
4141
|
-
ids.add(attachment.id);
|
|
4142
|
-
}
|
|
4143
|
-
for (const value of [attachment.path, attachment.url, attachment.filename]) {
|
|
4144
|
-
if (typeof value === "string" && value.trim())
|
|
4145
|
-
hints.add(value.trim());
|
|
4146
|
-
}
|
|
4147
|
-
}
|
|
4148
|
-
return {
|
|
4149
|
-
...(hints.size > 0 ? { source_asset_hints: [...hints].sort((a, b) => a.localeCompare(b)) } : {}),
|
|
4150
|
-
...(ids.size > 0 ? { source_attachment_ids: [...ids].sort((a, b) => a - b) } : {}),
|
|
4151
|
-
};
|
|
4152
|
-
}
|
|
4153
4144
|
const ManagedRecoveryPolicySchema = z
|
|
4154
4145
|
.object({
|
|
4155
4146
|
version: z.literal(1),
|
|
@@ -5151,9 +5142,9 @@ function registerProTools() {
|
|
|
5151
5142
|
// ── V3.1 — order/license/activation read + guarded mark-paid ───────
|
|
5152
5143
|
//
|
|
5153
5144
|
// FluentCart commerce-artifact readback surface plus a single
|
|
5154
|
-
// mutating tool: a guarded offline mark-paid that
|
|
5155
|
-
//
|
|
5156
|
-
// smoke off of eval-file PHP probes.
|
|
5145
|
+
// mutating tool: a guarded offline mark-paid that uses FluentCart 1.6's
|
|
5146
|
+
// canonical charge + StatusHelper synchronization contract. Lifts the local
|
|
5147
|
+
// checkout/license smoke off of eval-file PHP probes.
|
|
5157
5148
|
// diviops_fc_order_list — POST /diviops/v1/pro/fluentcart/orders
|
|
5158
5149
|
registerProTool("diviops_fc_order_list", {
|
|
5159
5150
|
description: "List FluentCart orders for commerce dogfooding / smoke baselines (Pro tier; V3.1; requires FluentCart installed + activated). Returns a paginated summary with order identity (id, status, payment_status), gateway info (payment_method + payment_method_title, mode), totals (currency, total_amount, total_paid), fulfillment_type, type (payment/subscription), customer (customer_id + customer_email), item_count, license_count, and timestamps (created_at, updated_at, completed_at). Filterable by status, payment_status, payment_method, product_id, customer_email, and mode (test/live). Read-only. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; the success payload is { orders: OrderSummary[], pagination: { page, per_page, total, total_pages }, filters: { ... } }. Error codes: invalid_input (HTTP 400) when status/payment_status/mode is out of range; fluentcart.module_inactive (HTTP 412); fluentcart.query_failed (HTTP 500). Use this alongside diviops_fc_order_get / diviops_fc_license_list to verify a smoke run without raw SQL probes.",
|
|
@@ -5273,7 +5264,7 @@ function registerProTools() {
|
|
|
5273
5264
|
}, { target: "fluentcart", capabilityKey: "fluentcart_order_get" });
|
|
5274
5265
|
// diviops_fc_order_mark_paid — POST /diviops/v1/pro/fluentcart/orders/{id}/mark-paid
|
|
5275
5266
|
registerProTool("diviops_fc_order_mark_paid", {
|
|
5276
|
-
description: "Guarded local/offline mark-paid for a FluentCart order (Pro tier; V3.1;
|
|
5267
|
+
description: "Guarded local/offline mark-paid for a FluentCart order (Pro tier; V3.1; exact audited FluentCart 1.6.0 contract). DiviOps serializes apply on the FluentCart order row, creates or updates one canonical succeeded `transaction_type=charge` transaction, then delegates the atomic paid transition and every derived cart/event/subscription/license/fulfillment effect to `FluentCart\\App\\Helpers\\StatusHelper::syncOrderStatuses`; it never dispatches vendor events or mutates subscriptions/licenses directly. Initial payment/subscription orders use FluentCart's `order_paid` and initial-activation family; renewal invoices use `renewal_paid` and store-managed subscription advancement without replaying new-order effects. Exact Free/installed-Pro version, transaction-lock, and StatusHelper shapes are checked before querying or mutation; older, newer, mixed, and unsupported shapes fail closed with component evidence. Refuses real gateways, canceled orders, missing subscription context, non-manual/system subscription collection, and conflicting legacy/duplicate transaction candidates. Already-paid and concurrent retries are no-ops after locked readback, while interrupted retries reuse the single matching succeeded charge before synchronization. **dry_run defaults to TRUE**; apply requires `dry_run:false` plus matching `confirm_order_id`, `confirm_payment_method`, and `confirm_due_amount`. Dry-run returns the transaction action plus canonical sync effect scope. Apply returns exact order/charge readback, initial-vs-renewal transition evidence, redacted license readback, and subscription before/after summaries. Exceptions after transaction mutation starts return `fluentcart.mutation_uncertain` with best-effort readback and explicitly require manual inspection instead of a blind retry. Error codes include invalid_input (400), not_found (404), fluentcart.unsupported_version (412), fluentcart.order_canceled / fluentcart.unsupported_payment_method / fluentcart.unsupported_order_shape / fluentcart.missing_subscription_context / fluentcart.unsupported_subscription_shape (422), fluentcart.transaction_conflict / fluentcart.concurrent_state_changed (409), fluentcart.readback_failed / fluentcart.mutation_uncertain (500), fluentcart.module_inactive (412), and fluentcart.command_failed (500). Idempotency is conditional and retry-safe only when the response says so." +
|
|
5277
5268
|
" Pass dry_run: false plus the confirm_* fields to apply.",
|
|
5278
5269
|
inputSchema: {
|
|
5279
5270
|
id: z
|
|
@@ -5554,8 +5545,26 @@ function registerProTools() {
|
|
|
5554
5545
|
};
|
|
5555
5546
|
}, { target: "fluentcart", capabilityKey: "fluentcart_gateway_get" });
|
|
5556
5547
|
}
|
|
5548
|
+
let productionRegistryFinalized = false;
|
|
5549
|
+
/**
|
|
5550
|
+
* Complete the canonical registry after the connected site's handshake has
|
|
5551
|
+
* settled. Production startup and the credential-free dual-era compatibility
|
|
5552
|
+
* fixture deliberately share this seam so the v2 proof materializes the real
|
|
5553
|
+
* Free/Pro-gated catalog instead of maintaining a second set of definitions.
|
|
5554
|
+
*/
|
|
5555
|
+
export function finalizeProductionRegistryForHandshake(state) {
|
|
5556
|
+
if (productionRegistryFinalized) {
|
|
5557
|
+
throw new Error("Production MCP registry has already been finalized");
|
|
5558
|
+
}
|
|
5559
|
+
handshakeState = state;
|
|
5560
|
+
registerCrossEnvEvidenceTools();
|
|
5561
|
+
registerProTools();
|
|
5562
|
+
productionRegistryFinalized = true;
|
|
5563
|
+
return registry;
|
|
5564
|
+
}
|
|
5557
5565
|
// ── Start ────────────────────────────────────────────────────────────
|
|
5558
5566
|
async function main() {
|
|
5567
|
+
requireCredentials();
|
|
5559
5568
|
// Capability handshake — populate the per-tool gate map (#486)
|
|
5560
5569
|
// and the ADR-003 / ADR-007 Pro-extension surface (target presence,
|
|
5561
5570
|
// module activation). On Free-only sites the Pro fields are
|
|
@@ -5603,18 +5612,32 @@ async function main() {
|
|
|
5603
5612
|
// The cross-env evidence schema is additive-capability aware: older Free
|
|
5604
5613
|
// plugins retain the existing header-only enum, while current plugins prove
|
|
5605
5614
|
// footer support through cross_env_footer_layout_evidence.
|
|
5606
|
-
|
|
5607
|
-
//
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5615
|
+
// Cross-env evidence and Pro coverage-slice registration must run AFTER
|
|
5616
|
+
// the handshake so capability and tier gates reflect the connected site.
|
|
5617
|
+
const finalizedRegistry = finalizeProductionRegistryForHandshake(handshakeState);
|
|
5618
|
+
const server = new McpServer({
|
|
5619
|
+
name: "diviops-mcp",
|
|
5620
|
+
version: SERVER_VERSION,
|
|
5621
|
+
});
|
|
5622
|
+
finalizedRegistry.install(server);
|
|
5613
5623
|
const transport = new StdioServerTransport();
|
|
5614
5624
|
await server.connect(transport);
|
|
5615
5625
|
console.error("Divi MCP Server running on stdio");
|
|
5616
5626
|
}
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5627
|
+
function isDirectEntryPoint() {
|
|
5628
|
+
const entryPoint = process.argv[1];
|
|
5629
|
+
if (!entryPoint)
|
|
5630
|
+
return false;
|
|
5631
|
+
try {
|
|
5632
|
+
return realpathSync(entryPoint) === fileURLToPath(import.meta.url);
|
|
5633
|
+
}
|
|
5634
|
+
catch {
|
|
5635
|
+
return false;
|
|
5636
|
+
}
|
|
5637
|
+
}
|
|
5638
|
+
if (isDirectEntryPoint()) {
|
|
5639
|
+
main().catch((error) => {
|
|
5640
|
+
console.error("Fatal error:", error);
|
|
5641
|
+
process.exit(1);
|
|
5642
|
+
});
|
|
5643
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { HandshakeResult } from "./compatibility.js";
|
|
2
|
+
export declare const TARGET_EVIDENCE_SCHEMA_VERSION = 1;
|
|
3
|
+
export type LauncherProfileIdentity = {
|
|
4
|
+
profile_id: string;
|
|
5
|
+
profile_revision: number;
|
|
6
|
+
profile_label: string;
|
|
7
|
+
endpoint: string;
|
|
8
|
+
credential_ref: string;
|
|
9
|
+
};
|
|
10
|
+
export type TargetEvidence = {
|
|
11
|
+
schema_version: 1;
|
|
12
|
+
profile_id: string;
|
|
13
|
+
profile_revision: number;
|
|
14
|
+
profile_label: string;
|
|
15
|
+
endpoint: string;
|
|
16
|
+
credential_ref: string;
|
|
17
|
+
authenticated_user: {
|
|
18
|
+
id: number;
|
|
19
|
+
login: string;
|
|
20
|
+
};
|
|
21
|
+
observed_site_url: string;
|
|
22
|
+
plugin_version: string | null;
|
|
23
|
+
divi: {
|
|
24
|
+
active: boolean;
|
|
25
|
+
version: string | null;
|
|
26
|
+
};
|
|
27
|
+
capabilities: Record<string, boolean>;
|
|
28
|
+
capability_digest: string;
|
|
29
|
+
target_evidence_hash: string;
|
|
30
|
+
observed_at: string;
|
|
31
|
+
drift_state: "healthy";
|
|
32
|
+
};
|
|
33
|
+
export type TargetIdentityForHash = Omit<TargetEvidence, "profile_label" | "target_evidence_hash" | "observed_at" | "drift_state">;
|
|
34
|
+
export declare function canonicalJson(value: unknown): string;
|
|
35
|
+
export declare function normalizeWordPressEndpoint(raw: string): string;
|
|
36
|
+
export declare function canonicalCapabilities(value: unknown): Record<string, boolean>;
|
|
37
|
+
export declare function targetIdentityForHash(evidence: TargetEvidence): TargetIdentityForHash;
|
|
38
|
+
export declare function targetEvidenceHash(evidence: TargetEvidence): string;
|
|
39
|
+
export declare function createTargetEvidence(profile: LauncherProfileIdentity, handshake: HandshakeResult, observedAt?: Date): TargetEvidence;
|
|
40
|
+
export declare function targetDriftAxes(approved: TargetEvidence, current: TargetEvidence): string[];
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
export const TARGET_EVIDENCE_SCHEMA_VERSION = 1;
|
|
3
|
+
function sha256(value) {
|
|
4
|
+
return `sha256:${createHash("sha256").update(value, "utf8").digest("hex")}`;
|
|
5
|
+
}
|
|
6
|
+
function assertPlainRecord(value, name) {
|
|
7
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
8
|
+
throw new Error(`launcher.target_evidence_invalid: ${name} must be an object`);
|
|
9
|
+
}
|
|
10
|
+
if (Object.getPrototypeOf(value) !== Object.prototype) {
|
|
11
|
+
throw new Error(`launcher.target_evidence_invalid: ${name} must be a plain object`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function canonicalJson(value) {
|
|
15
|
+
const visit = (input) => {
|
|
16
|
+
if (input === null || typeof input === "string" || typeof input === "boolean")
|
|
17
|
+
return input;
|
|
18
|
+
if (typeof input === "number") {
|
|
19
|
+
if (!Number.isFinite(input) || !Number.isSafeInteger(input)) {
|
|
20
|
+
throw new Error("launcher.target_evidence_invalid: canonical numbers must be safe integers");
|
|
21
|
+
}
|
|
22
|
+
return input;
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(input))
|
|
25
|
+
return input.map(visit);
|
|
26
|
+
assertPlainRecord(input, "canonical value");
|
|
27
|
+
const out = {};
|
|
28
|
+
for (const key of Object.keys(input).sort()) {
|
|
29
|
+
if (input[key] === undefined) {
|
|
30
|
+
throw new Error("launcher.target_evidence_invalid: undefined values are forbidden");
|
|
31
|
+
}
|
|
32
|
+
out[key] = visit(input[key]);
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
};
|
|
36
|
+
return JSON.stringify(visit(value));
|
|
37
|
+
}
|
|
38
|
+
export function normalizeWordPressEndpoint(raw) {
|
|
39
|
+
if (raw.trim() !== raw || raw.length === 0) {
|
|
40
|
+
throw new Error("launcher.endpoint_invalid: endpoint must be non-empty without surrounding whitespace");
|
|
41
|
+
}
|
|
42
|
+
let url;
|
|
43
|
+
try {
|
|
44
|
+
url = new URL(raw);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new Error("launcher.endpoint_invalid: endpoint must be an absolute URL");
|
|
48
|
+
}
|
|
49
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
50
|
+
throw new Error("launcher.endpoint_invalid: endpoint scheme must be http or https");
|
|
51
|
+
}
|
|
52
|
+
if (url.username || url.password || url.search || url.hash) {
|
|
53
|
+
throw new Error("launcher.endpoint_invalid: userinfo, query, and fragment are forbidden");
|
|
54
|
+
}
|
|
55
|
+
if (!url.hostname || url.hostname.includes("%")) {
|
|
56
|
+
throw new Error("launcher.endpoint_invalid: endpoint host is invalid");
|
|
57
|
+
}
|
|
58
|
+
url.hostname = url.hostname.toLowerCase();
|
|
59
|
+
url.pathname = url.pathname.replace(/\/+$/, "") || "/";
|
|
60
|
+
return url.toString().replace(/\/$/, "");
|
|
61
|
+
}
|
|
62
|
+
export function canonicalCapabilities(value) {
|
|
63
|
+
assertPlainRecord(value, "capabilities");
|
|
64
|
+
const sorted = {};
|
|
65
|
+
for (const key of Object.keys(value).sort()) {
|
|
66
|
+
if (!/^[a-z0-9_]+$/.test(key) || typeof value[key] !== "boolean") {
|
|
67
|
+
throw new Error("launcher.target_evidence_invalid: capabilities must be boolean slug entries");
|
|
68
|
+
}
|
|
69
|
+
sorted[key] = value[key];
|
|
70
|
+
}
|
|
71
|
+
return sorted;
|
|
72
|
+
}
|
|
73
|
+
export function targetIdentityForHash(evidence) {
|
|
74
|
+
return {
|
|
75
|
+
schema_version: evidence.schema_version,
|
|
76
|
+
profile_id: evidence.profile_id,
|
|
77
|
+
profile_revision: evidence.profile_revision,
|
|
78
|
+
endpoint: evidence.endpoint,
|
|
79
|
+
credential_ref: evidence.credential_ref,
|
|
80
|
+
authenticated_user: evidence.authenticated_user,
|
|
81
|
+
observed_site_url: evidence.observed_site_url,
|
|
82
|
+
plugin_version: evidence.plugin_version,
|
|
83
|
+
divi: evidence.divi,
|
|
84
|
+
capabilities: evidence.capabilities,
|
|
85
|
+
capability_digest: evidence.capability_digest,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export function targetEvidenceHash(evidence) {
|
|
89
|
+
return sha256(canonicalJson(targetIdentityForHash(evidence)));
|
|
90
|
+
}
|
|
91
|
+
export function createTargetEvidence(profile, handshake, observedAt = new Date()) {
|
|
92
|
+
const endpoint = normalizeWordPressEndpoint(profile.endpoint);
|
|
93
|
+
const observedSiteUrl = normalizeWordPressEndpoint(handshake.site_url ?? "");
|
|
94
|
+
const user = handshake.authenticated_user;
|
|
95
|
+
if (!user ||
|
|
96
|
+
!Number.isSafeInteger(user.id) ||
|
|
97
|
+
user.id < 1 ||
|
|
98
|
+
typeof user.login !== "string" ||
|
|
99
|
+
user.login.length === 0) {
|
|
100
|
+
throw new Error("launcher.target_evidence_invalid: handshake owner evidence is missing or malformed");
|
|
101
|
+
}
|
|
102
|
+
const capabilities = canonicalCapabilities(handshake.capabilities);
|
|
103
|
+
const capabilityDigest = sha256(canonicalJson(capabilities));
|
|
104
|
+
const evidence = {
|
|
105
|
+
schema_version: TARGET_EVIDENCE_SCHEMA_VERSION,
|
|
106
|
+
profile_id: profile.profile_id,
|
|
107
|
+
profile_revision: profile.profile_revision,
|
|
108
|
+
profile_label: profile.profile_label,
|
|
109
|
+
endpoint,
|
|
110
|
+
credential_ref: profile.credential_ref,
|
|
111
|
+
authenticated_user: { id: user.id, login: user.login },
|
|
112
|
+
observed_site_url: observedSiteUrl,
|
|
113
|
+
plugin_version: typeof handshake.plugin_version === "string" && handshake.plugin_version.length > 0
|
|
114
|
+
? handshake.plugin_version
|
|
115
|
+
: null,
|
|
116
|
+
divi: {
|
|
117
|
+
active: handshake.divi.active === true,
|
|
118
|
+
version: typeof handshake.divi.version === "string" && handshake.divi.version.length > 0
|
|
119
|
+
? handshake.divi.version
|
|
120
|
+
: null,
|
|
121
|
+
},
|
|
122
|
+
capabilities,
|
|
123
|
+
capability_digest: capabilityDigest,
|
|
124
|
+
target_evidence_hash: "",
|
|
125
|
+
observed_at: observedAt.toISOString(),
|
|
126
|
+
drift_state: "healthy",
|
|
127
|
+
};
|
|
128
|
+
evidence.target_evidence_hash = targetEvidenceHash(evidence);
|
|
129
|
+
return evidence;
|
|
130
|
+
}
|
|
131
|
+
export function targetDriftAxes(approved, current) {
|
|
132
|
+
const axes = [];
|
|
133
|
+
const pairs = [
|
|
134
|
+
["profile_id", approved.profile_id, current.profile_id],
|
|
135
|
+
["profile_revision", approved.profile_revision, current.profile_revision],
|
|
136
|
+
["endpoint", approved.endpoint, current.endpoint],
|
|
137
|
+
["credential_ref", approved.credential_ref, current.credential_ref],
|
|
138
|
+
["authenticated_user.id", approved.authenticated_user.id, current.authenticated_user.id],
|
|
139
|
+
["authenticated_user.login", approved.authenticated_user.login, current.authenticated_user.login],
|
|
140
|
+
["observed_site_url", approved.observed_site_url, current.observed_site_url],
|
|
141
|
+
["plugin_version", approved.plugin_version, current.plugin_version],
|
|
142
|
+
["divi.active", approved.divi.active, current.divi.active],
|
|
143
|
+
["divi.version", approved.divi.version, current.divi.version],
|
|
144
|
+
["capability_digest", approved.capability_digest, current.capability_digest],
|
|
145
|
+
["target_evidence_hash", approved.target_evidence_hash, current.target_evidence_hash],
|
|
146
|
+
];
|
|
147
|
+
for (const [axis, before, after] of pairs) {
|
|
148
|
+
if (before !== after)
|
|
149
|
+
axes.push(axis);
|
|
150
|
+
}
|
|
151
|
+
return axes;
|
|
152
|
+
}
|
package/dist/wp-client.d.ts
CHANGED
|
@@ -10,10 +10,12 @@ export interface WPClientConfig {
|
|
|
10
10
|
siteUrl: string;
|
|
11
11
|
username: string;
|
|
12
12
|
applicationPassword: string;
|
|
13
|
+
fetch?: typeof globalThis.fetch;
|
|
13
14
|
}
|
|
14
15
|
export declare class WPClient {
|
|
15
16
|
private baseUrl;
|
|
16
17
|
private authHeader;
|
|
18
|
+
private fetchImpl;
|
|
17
19
|
constructor(config: WPClientConfig);
|
|
18
20
|
/**
|
|
19
21
|
* Make a request to the diviops/v1 REST namespace.
|
|
@@ -22,6 +24,7 @@ export declare class WPClient {
|
|
|
22
24
|
method?: string;
|
|
23
25
|
body?: Record<string, unknown>;
|
|
24
26
|
params?: Record<string, string>;
|
|
27
|
+
signal?: AbortSignal;
|
|
25
28
|
}): Promise<T>;
|
|
26
29
|
/**
|
|
27
30
|
* Envelope-aware sibling of `request()`.
|
|
@@ -52,6 +55,7 @@ export declare class WPClient {
|
|
|
52
55
|
method?: string;
|
|
53
56
|
body?: Record<string, unknown>;
|
|
54
57
|
params?: Record<string, string>;
|
|
58
|
+
signal?: AbortSignal;
|
|
55
59
|
}): Promise<DiviopsResponse<T>>;
|
|
56
60
|
/**
|
|
57
61
|
* Test the connection to WordPress.
|
|
@@ -63,7 +67,7 @@ export declare class WPClient {
|
|
|
63
67
|
* silently regresses meta_ping to "Connected to Divi unknown" on
|
|
64
68
|
* healthy sites.
|
|
65
69
|
*/
|
|
66
|
-
testConnection(): Promise<{
|
|
70
|
+
testConnection(signal?: AbortSignal): Promise<{
|
|
67
71
|
ok: boolean;
|
|
68
72
|
message: string;
|
|
69
73
|
}>;
|
|
@@ -80,5 +84,5 @@ export declare class WPClient {
|
|
|
80
84
|
* The plugin still rejects servers below its own MIN_SERVER_VERSION
|
|
81
85
|
* with HTTP 426 — that error surfaces here as a regular request error.
|
|
82
86
|
*/
|
|
83
|
-
handshake(serverVersion: string): Promise<HandshakeResult>;
|
|
87
|
+
handshake(serverVersion: string, signal?: AbortSignal): Promise<HandshakeResult>;
|
|
84
88
|
}
|
package/dist/wp-client.js
CHANGED
|
@@ -121,9 +121,11 @@ function normalizeBody(value, withinBlockTree = false) {
|
|
|
121
121
|
export class WPClient {
|
|
122
122
|
baseUrl;
|
|
123
123
|
authHeader;
|
|
124
|
+
fetchImpl;
|
|
124
125
|
constructor(config) {
|
|
125
126
|
// Strip trailing slash.
|
|
126
127
|
this.baseUrl = config.siteUrl.replace(/\/+$/, '');
|
|
128
|
+
this.fetchImpl = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
127
129
|
// WP Application Passwords use Basic Auth.
|
|
128
130
|
const credentials = Buffer.from(`${config.username}:${config.applicationPassword}`).toString('base64');
|
|
129
131
|
this.authHeader = `Basic ${credentials}`;
|
|
@@ -132,7 +134,7 @@ export class WPClient {
|
|
|
132
134
|
* Make a request to the diviops/v1 REST namespace.
|
|
133
135
|
*/
|
|
134
136
|
async request(endpoint, options = {}) {
|
|
135
|
-
const { method = 'GET', body, params } = options;
|
|
137
|
+
const { method = 'GET', body, params, signal } = options;
|
|
136
138
|
let url = `${this.baseUrl}/wp-json/diviops/v1${endpoint}`;
|
|
137
139
|
if (params) {
|
|
138
140
|
const searchParams = new URLSearchParams(params);
|
|
@@ -145,12 +147,13 @@ export class WPClient {
|
|
|
145
147
|
'Content-Type': 'application/json',
|
|
146
148
|
Accept: 'application/json',
|
|
147
149
|
},
|
|
150
|
+
signal,
|
|
148
151
|
};
|
|
149
152
|
if (body && method !== 'GET') {
|
|
150
153
|
const normalized = endpointSkipsNormalization(endpoint) ? body : normalizeBody(body);
|
|
151
154
|
fetchOptions.body = JSON.stringify(normalized);
|
|
152
155
|
}
|
|
153
|
-
const response = await
|
|
156
|
+
const response = await this.fetchImpl(url, fetchOptions);
|
|
154
157
|
if (!response.ok) {
|
|
155
158
|
const errorBody = await response.text();
|
|
156
159
|
let errorMessage;
|
|
@@ -195,7 +198,7 @@ export class WPClient {
|
|
|
195
198
|
* `request()` becomes orphan and is removed.
|
|
196
199
|
*/
|
|
197
200
|
async requestEnveloped(endpoint, options = {}) {
|
|
198
|
-
const { method = 'GET', body, params } = options;
|
|
201
|
+
const { method = 'GET', body, params, signal } = options;
|
|
199
202
|
let url = `${this.baseUrl}/wp-json/diviops/v1${endpoint}`;
|
|
200
203
|
if (params) {
|
|
201
204
|
const searchParams = new URLSearchParams(params);
|
|
@@ -208,12 +211,13 @@ export class WPClient {
|
|
|
208
211
|
'Content-Type': 'application/json',
|
|
209
212
|
Accept: 'application/json',
|
|
210
213
|
},
|
|
214
|
+
signal,
|
|
211
215
|
};
|
|
212
216
|
if (body && method !== 'GET') {
|
|
213
217
|
const normalized = endpointSkipsNormalization(endpoint) ? body : normalizeBody(body);
|
|
214
218
|
fetchOptions.body = JSON.stringify(normalized);
|
|
215
219
|
}
|
|
216
|
-
const response = await
|
|
220
|
+
const response = await this.fetchImpl(url, fetchOptions);
|
|
217
221
|
const rawBody = await response.text();
|
|
218
222
|
// Try to parse the body as JSON. Failure is recoverable for non-2xx
|
|
219
223
|
// responses (HTML/plain-text error pages from a misconfigured host or
|
|
@@ -311,9 +315,9 @@ export class WPClient {
|
|
|
311
315
|
* silently regresses meta_ping to "Connected to Divi unknown" on
|
|
312
316
|
* healthy sites.
|
|
313
317
|
*/
|
|
314
|
-
async testConnection() {
|
|
318
|
+
async testConnection(signal) {
|
|
315
319
|
try {
|
|
316
|
-
const response = await this.requestEnveloped('/schema/settings');
|
|
320
|
+
const response = await this.requestEnveloped('/schema/settings', { signal });
|
|
317
321
|
if (!response.ok) {
|
|
318
322
|
return {
|
|
319
323
|
ok: false,
|
|
@@ -326,6 +330,8 @@ export class WPClient {
|
|
|
326
330
|
};
|
|
327
331
|
}
|
|
328
332
|
catch (error) {
|
|
333
|
+
if (signal?.aborted)
|
|
334
|
+
throw signal.reason ?? error;
|
|
329
335
|
return {
|
|
330
336
|
ok: false,
|
|
331
337
|
message: `Connection failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -345,10 +351,11 @@ export class WPClient {
|
|
|
345
351
|
* The plugin still rejects servers below its own MIN_SERVER_VERSION
|
|
346
352
|
* with HTTP 426 — that error surfaces here as a regular request error.
|
|
347
353
|
*/
|
|
348
|
-
async handshake(serverVersion) {
|
|
354
|
+
async handshake(serverVersion, signal) {
|
|
349
355
|
const result = await this.request('/handshake', {
|
|
350
356
|
method: 'POST',
|
|
351
357
|
body: { mcp_server_version: serverVersion },
|
|
358
|
+
signal,
|
|
352
359
|
});
|
|
353
360
|
// Pre-1.2.0 plugins emit `capabilities` as a string[] of coarse
|
|
354
361
|
// namespace tags. Coerce to an empty map so per-tool gates fail fast
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diviops/mcp-server",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.40",
|
|
4
4
|
"description": "MCP server exposing Divi 5 Visual Builder as tools for Claude",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"dist/**/*",
|
|
14
14
|
"!dist/**/__tests__/**",
|
|
15
|
+
"!dist/launcher-bootstrap.js",
|
|
16
|
+
"!dist/launcher-bootstrap.d.ts",
|
|
17
|
+
"!dist/launcher-sidecar.js",
|
|
18
|
+
"!dist/launcher-sidecar.d.ts",
|
|
15
19
|
"templates",
|
|
16
20
|
"data/verified-attrs.json",
|
|
17
21
|
"data/verified-attrs-backlog.json",
|
|
@@ -21,7 +25,7 @@
|
|
|
21
25
|
"build": "tsc",
|
|
22
26
|
"start": "node dist/index.js",
|
|
23
27
|
"dev": "tsc --watch",
|
|
24
|
-
"test": "npm run build && node --test dist/__tests__/*.test.js dist/preset-cli/__tests__/*.test.js dist/cross-env-preflight/__tests__/*.test.js",
|
|
28
|
+
"test": "npm run build && node --test dist/__tests__/*.test.js dist/preset-cli/__tests__/*.test.js dist/cross-env-preflight/__tests__/*.test.js && node scripts/check-release-boundary.mjs",
|
|
25
29
|
"prepublishOnly": "npm run build",
|
|
26
30
|
"regen:skill": "node scripts/regen-module-formats.mjs"
|
|
27
31
|
},
|
|
@@ -44,13 +48,21 @@
|
|
|
44
48
|
},
|
|
45
49
|
"homepage": "https://github.com/oaris-dev/diviops/tree/main/diviops-server#readme",
|
|
46
50
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
51
|
+
"node": ">=22.0.0"
|
|
48
52
|
},
|
|
49
53
|
"dependencies": {
|
|
50
|
-
"@
|
|
54
|
+
"@hono/node-server": "2.1.0",
|
|
55
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
56
|
+
"body-parser": "2.3.0",
|
|
57
|
+
"fast-uri": "3.1.5",
|
|
58
|
+
"hono": "4.13.1",
|
|
59
|
+
"ip-address": "10.5.0",
|
|
51
60
|
"zod": "^4.3.6"
|
|
52
61
|
},
|
|
53
62
|
"devDependencies": {
|
|
63
|
+
"@modelcontextprotocol/client": "2.0.0",
|
|
64
|
+
"@modelcontextprotocol/core": "2.0.0",
|
|
65
|
+
"@modelcontextprotocol/server": "2.0.0",
|
|
54
66
|
"@types/node": "^22.0.0",
|
|
55
67
|
"typescript": "^5.7.0"
|
|
56
68
|
}
|