@diviops/mcp-server 1.5.37 → 1.5.39
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 +19 -4
- package/dist/canonical-tool-registry.d.ts +21 -0
- package/dist/canonical-tool-registry.js +33 -0
- package/dist/capability-envelope.d.ts +6 -1
- package/dist/capability-envelope.js +19 -8
- package/dist/compatibility.d.ts +19 -9
- package/dist/compatibility.js +38 -9
- package/dist/envelope.d.ts +1 -1
- package/dist/envelope.js +1 -1
- 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 +184 -42
- package/dist/preset-cli/write-path.d.ts +6 -4
- package/dist/preset-cli/write-path.js +22 -7
- 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 +9 -2
|
@@ -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.39",
|
|
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
|
},
|
|
@@ -51,6 +55,9 @@
|
|
|
51
55
|
"zod": "^4.3.6"
|
|
52
56
|
},
|
|
53
57
|
"devDependencies": {
|
|
58
|
+
"@modelcontextprotocol/client": "2.0.0",
|
|
59
|
+
"@modelcontextprotocol/core": "2.0.0",
|
|
60
|
+
"@modelcontextprotocol/server": "2.0.0",
|
|
54
61
|
"@types/node": "^22.0.0",
|
|
55
62
|
"typescript": "^5.7.0"
|
|
56
63
|
}
|