@wp-playground/mcp 3.1.60 → 3.1.62
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/client.cjs +1 -1
- package/client.cjs.map +1 -1
- package/client.js +211 -183
- package/client.js.map +1 -1
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/package.json +5 -5
- package/{tool-executors-BhDxY6BQ.cjs → tool-executors-CkOyDA_-.cjs} +11 -11
- package/tool-executors-CkOyDA_-.cjs.map +1 -0
- package/{tool-executors-jX-K5l3h.js → tool-executors-D1J1qKnB.js} +86 -74
- package/tool-executors-D1J1qKnB.js.map +1 -0
- package/tools/tool-definitions.d.ts +3 -0
- package/tools/tool-executors.d.ts +1 -1
- package/webmcp.d.ts +6 -2
- package/tool-executors-BhDxY6BQ.cjs.map +0 -1
- package/tool-executors-jX-K5l3h.js.map +0 -1
package/client.js
CHANGED
|
@@ -1,331 +1,359 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { logger as
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
let
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
f !==
|
|
1
|
+
import { c as C, t as P, a as T, s as p, b as h, f as v, g as $ } from "./tool-executors-D1J1qKnB.js";
|
|
2
|
+
import { logger as S } from "@php-wasm/logger";
|
|
3
|
+
const I = 5e3;
|
|
4
|
+
function L(n, c) {
|
|
5
|
+
const d = crypto.randomUUID();
|
|
6
|
+
let t = null, r = "", u = null, o = !1;
|
|
7
|
+
function a(l) {
|
|
8
|
+
const s = n.list(), f = JSON.stringify(s);
|
|
9
|
+
f !== r && (r = f, l.send(JSON.stringify({ type: "register", tabId: d, sites: s })));
|
|
10
10
|
}
|
|
11
|
-
async function
|
|
11
|
+
async function e() {
|
|
12
12
|
try {
|
|
13
|
-
const
|
|
14
|
-
`http://127.0.0.1:${
|
|
13
|
+
const l = await fetch(
|
|
14
|
+
`http://127.0.0.1:${c}/bridge-token`
|
|
15
15
|
);
|
|
16
|
-
if (!
|
|
17
|
-
|
|
16
|
+
if (!l.ok) {
|
|
17
|
+
i();
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
const { token:
|
|
21
|
-
|
|
20
|
+
const { token: s } = await l.json();
|
|
21
|
+
t = new WebSocket(`ws://127.0.0.1:${c}?token=${s}`);
|
|
22
22
|
} catch {
|
|
23
|
-
|
|
23
|
+
i();
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
}),
|
|
30
|
-
let
|
|
26
|
+
t.addEventListener("open", () => {
|
|
27
|
+
var l;
|
|
28
|
+
r = "", a(t), (l = n.onConnect) == null || l.call(n);
|
|
29
|
+
}), t.addEventListener("message", async (l) => {
|
|
30
|
+
let s;
|
|
31
31
|
try {
|
|
32
|
-
|
|
32
|
+
s = JSON.parse(l.data);
|
|
33
33
|
} catch {
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
if (
|
|
36
|
+
if (s.type !== "command")
|
|
37
37
|
return;
|
|
38
|
-
const { id: f, method:
|
|
38
|
+
const { id: f, method: b, args: y, siteSlug: _ } = s;
|
|
39
39
|
try {
|
|
40
|
-
const
|
|
40
|
+
const m = await N(
|
|
41
41
|
n,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
b,
|
|
43
|
+
y || [],
|
|
44
|
+
_,
|
|
45
|
+
c
|
|
46
46
|
);
|
|
47
|
-
(
|
|
48
|
-
} catch (
|
|
49
|
-
const
|
|
50
|
-
(
|
|
47
|
+
(t == null ? void 0 : t.readyState) === WebSocket.OPEN && t.send(JSON.stringify({ id: f, type: "response", value: m }));
|
|
48
|
+
} catch (m) {
|
|
49
|
+
const E = m instanceof Error ? m.message : String(m);
|
|
50
|
+
(t == null ? void 0 : t.readyState) === WebSocket.OPEN && t.send(
|
|
51
51
|
JSON.stringify({
|
|
52
52
|
id: f,
|
|
53
53
|
type: "response",
|
|
54
|
-
error:
|
|
54
|
+
error: E
|
|
55
55
|
})
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
|
-
}),
|
|
59
|
-
|
|
60
|
-
}),
|
|
58
|
+
}), t.addEventListener("close", () => {
|
|
59
|
+
t = null, i();
|
|
60
|
+
}), t.addEventListener("error", () => {
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
63
|
+
function i() {
|
|
64
|
+
o || (u = setTimeout(e, I));
|
|
65
65
|
}
|
|
66
|
-
return
|
|
66
|
+
return e(), {
|
|
67
67
|
notifySitesChanged: () => {
|
|
68
|
-
(
|
|
68
|
+
(t == null ? void 0 : t.readyState) === WebSocket.OPEN && a(t);
|
|
69
69
|
},
|
|
70
70
|
stop: () => {
|
|
71
|
-
|
|
71
|
+
o = !0, u !== null && (clearTimeout(u), u = null), t && (t.close(), t = null);
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
async function
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
75
|
+
async function N(n, c, d, t, r) {
|
|
76
|
+
if (c === "__open_site_in_new_tab") {
|
|
77
|
+
const e = new URL(window.location.href);
|
|
78
|
+
if (e.searchParams.set("mcp-port", String(r)), e.searchParams.set("site-slug", t), !window.open(e.toString(), "_blank"))
|
|
79
79
|
throw new Error(
|
|
80
80
|
"Pop-up blocked by browser. The user must allow pop-ups for this site."
|
|
81
81
|
);
|
|
82
82
|
return !0;
|
|
83
83
|
}
|
|
84
|
-
if (
|
|
85
|
-
const [
|
|
86
|
-
return await n.rename(
|
|
84
|
+
if (c === "__rename_site") {
|
|
85
|
+
const [e] = d;
|
|
86
|
+
return await n.rename(e), !0;
|
|
87
87
|
}
|
|
88
|
-
if (
|
|
88
|
+
if (c === "__save_site")
|
|
89
89
|
return await n.saveInBrowser();
|
|
90
|
-
const
|
|
91
|
-
if (!
|
|
92
|
-
throw new Error(`No active client for site: ${
|
|
93
|
-
const
|
|
94
|
-
if (typeof
|
|
95
|
-
throw new Error(`Unknown method: ${
|
|
96
|
-
return await
|
|
90
|
+
const u = n.getClient();
|
|
91
|
+
if (!u)
|
|
92
|
+
throw new Error(`No active client for site: ${t}`);
|
|
93
|
+
const a = C(u)[c];
|
|
94
|
+
if (typeof a != "function")
|
|
95
|
+
throw new Error(`Unknown method: ${c}`);
|
|
96
|
+
return await a(...d);
|
|
97
97
|
}
|
|
98
|
-
const g =
|
|
99
|
-
let
|
|
100
|
-
function
|
|
101
|
-
const
|
|
102
|
-
if (!
|
|
98
|
+
const g = $();
|
|
99
|
+
let w = null;
|
|
100
|
+
function W(n) {
|
|
101
|
+
const d = n.list().find((t) => t.isActive);
|
|
102
|
+
if (!d)
|
|
103
103
|
throw new Error("No active Playground site");
|
|
104
|
-
return
|
|
104
|
+
return d;
|
|
105
105
|
}
|
|
106
|
-
async function
|
|
107
|
-
const
|
|
108
|
-
if (!
|
|
106
|
+
async function J(n) {
|
|
107
|
+
const c = x();
|
|
108
|
+
if (!c)
|
|
109
109
|
return;
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
function
|
|
113
|
-
const
|
|
114
|
-
if (!
|
|
110
|
+
w == null || w.abort(), w = new AbortController();
|
|
111
|
+
const d = w, t = d.signal;
|
|
112
|
+
function r() {
|
|
113
|
+
const e = n.getClient();
|
|
114
|
+
if (!e)
|
|
115
115
|
throw new Error("No client for active site");
|
|
116
|
-
return
|
|
116
|
+
return e;
|
|
117
117
|
}
|
|
118
|
-
const
|
|
119
|
-
([
|
|
120
|
-
name:
|
|
121
|
-
description:
|
|
122
|
-
inputSchema:
|
|
123
|
-
annotations:
|
|
124
|
-
execute: async (
|
|
118
|
+
const u = Object.entries(P).map(
|
|
119
|
+
([e, i]) => ({
|
|
120
|
+
name: e,
|
|
121
|
+
description: i.description,
|
|
122
|
+
inputSchema: h(i.params),
|
|
123
|
+
annotations: i.annotations,
|
|
124
|
+
execute: async (l, s) => {
|
|
125
|
+
var f, b;
|
|
125
126
|
try {
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
(f = s == null ? void 0 : s.signal) == null || f.throwIfAborted();
|
|
128
|
+
const y = T[e];
|
|
129
|
+
if (!y)
|
|
128
130
|
return {
|
|
129
|
-
error: `No executor for "${
|
|
131
|
+
error: `No executor for "${e}"`
|
|
130
132
|
};
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
const _ = C(r()), m = await y(
|
|
134
|
+
_,
|
|
135
|
+
l,
|
|
136
|
+
s == null ? void 0 : s.signal
|
|
137
|
+
);
|
|
138
|
+
return (b = s == null ? void 0 : s.signal) == null || b.throwIfAborted(), m;
|
|
139
|
+
} catch (y) {
|
|
134
140
|
return {
|
|
135
|
-
error: `${
|
|
141
|
+
error: `${i.errorPrefix}: ${p(y)}`
|
|
136
142
|
};
|
|
137
143
|
}
|
|
138
144
|
}
|
|
139
145
|
})
|
|
140
146
|
);
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
await
|
|
147
|
+
u.push(...A(n));
|
|
148
|
+
const o = await Promise.allSettled(
|
|
149
|
+
u.map(async (e) => {
|
|
150
|
+
await c.registerTool(e, { signal: t });
|
|
145
151
|
})
|
|
146
|
-
),
|
|
147
|
-
for (const [
|
|
148
|
-
|
|
149
|
-
name:
|
|
150
|
-
reason:
|
|
152
|
+
), a = [];
|
|
153
|
+
for (const [e, i] of o.entries())
|
|
154
|
+
i.status === "rejected" && a.push({
|
|
155
|
+
name: u[e].name,
|
|
156
|
+
reason: i.reason
|
|
151
157
|
});
|
|
152
|
-
if (
|
|
153
|
-
throw
|
|
154
|
-
"Failed to register WebMCP tools: " +
|
|
155
|
-
({ name:
|
|
158
|
+
if (a.length > 0)
|
|
159
|
+
throw d.abort(), w === d && (w = null), new Error(
|
|
160
|
+
"Failed to register WebMCP tools: " + a.map(
|
|
161
|
+
({ name: e, reason: i }) => `${e} (${p(i)})`
|
|
156
162
|
).join(", ")
|
|
157
163
|
);
|
|
158
164
|
}
|
|
159
|
-
function
|
|
165
|
+
function x() {
|
|
160
166
|
if (typeof document > "u")
|
|
161
167
|
return;
|
|
162
168
|
const n = document.modelContext;
|
|
163
169
|
return typeof (n == null ? void 0 : n.registerTool) == "function" ? n : void 0;
|
|
164
170
|
}
|
|
165
|
-
function
|
|
166
|
-
const
|
|
171
|
+
function A(n) {
|
|
172
|
+
const c = g.playground_list_sites, d = g.playground_save_in_browser, t = g.playground_rename_site, r = g.playground_get_website_url;
|
|
167
173
|
return [
|
|
168
174
|
{
|
|
169
175
|
name: "playground_list_sites",
|
|
170
|
-
description:
|
|
171
|
-
|
|
172
|
-
|
|
176
|
+
description: c.description,
|
|
177
|
+
inputSchema: h(c.params),
|
|
178
|
+
annotations: c.annotations,
|
|
179
|
+
execute: async (u, o) => {
|
|
180
|
+
var a;
|
|
173
181
|
try {
|
|
174
|
-
return {
|
|
182
|
+
return (a = o == null ? void 0 : o.signal) == null || a.throwIfAborted(), {
|
|
175
183
|
connectedTabs: 1,
|
|
176
|
-
sites: n.list().map((
|
|
177
|
-
siteId:
|
|
178
|
-
name:
|
|
179
|
-
storage:
|
|
180
|
-
isActive:
|
|
184
|
+
sites: n.list().map((e) => ({
|
|
185
|
+
siteId: e.slug,
|
|
186
|
+
name: e.name,
|
|
187
|
+
storage: v(e.storage),
|
|
188
|
+
isActive: e.isActive
|
|
181
189
|
}))
|
|
182
190
|
};
|
|
183
|
-
} catch (
|
|
191
|
+
} catch (e) {
|
|
184
192
|
return {
|
|
185
|
-
error: `${
|
|
193
|
+
error: `${c.errorPrefix}: ${p(e)}`
|
|
186
194
|
};
|
|
187
195
|
}
|
|
188
196
|
}
|
|
189
197
|
},
|
|
190
198
|
{
|
|
191
199
|
name: "playground_save_in_browser",
|
|
192
|
-
description:
|
|
193
|
-
|
|
194
|
-
|
|
200
|
+
description: d.description,
|
|
201
|
+
inputSchema: h(d.params),
|
|
202
|
+
annotations: d.annotations,
|
|
203
|
+
execute: async (u, o) => {
|
|
204
|
+
var a, e;
|
|
195
205
|
try {
|
|
196
|
-
|
|
206
|
+
(a = o == null ? void 0 : o.signal) == null || a.throwIfAborted();
|
|
207
|
+
const i = W(n), l = v(i.storage);
|
|
197
208
|
if (l !== "temporary")
|
|
198
209
|
return {
|
|
199
210
|
success: !0,
|
|
200
211
|
alreadySaved: !0,
|
|
201
|
-
siteId:
|
|
202
|
-
name:
|
|
212
|
+
siteId: i.slug,
|
|
213
|
+
name: i.name,
|
|
203
214
|
storage: l
|
|
204
215
|
};
|
|
205
|
-
const
|
|
206
|
-
return {
|
|
216
|
+
const s = await n.saveInBrowser();
|
|
217
|
+
return (e = o == null ? void 0 : o.signal) == null || e.throwIfAborted(), {
|
|
207
218
|
success: !0,
|
|
208
219
|
alreadySaved: !1,
|
|
209
|
-
siteId:
|
|
210
|
-
name:
|
|
211
|
-
storage:
|
|
220
|
+
siteId: s.slug,
|
|
221
|
+
name: i.name ?? s.slug,
|
|
222
|
+
storage: v(s.storage)
|
|
212
223
|
};
|
|
213
|
-
} catch (
|
|
224
|
+
} catch (i) {
|
|
214
225
|
return {
|
|
215
|
-
error: `${
|
|
226
|
+
error: `${d.errorPrefix}: ${p(i)}`
|
|
216
227
|
};
|
|
217
228
|
}
|
|
218
229
|
}
|
|
219
230
|
},
|
|
220
231
|
{
|
|
221
232
|
name: "playground_rename_site",
|
|
222
|
-
description:
|
|
223
|
-
inputSchema:
|
|
224
|
-
annotations:
|
|
225
|
-
execute: async (
|
|
233
|
+
description: t.description,
|
|
234
|
+
inputSchema: h(t.params),
|
|
235
|
+
annotations: t.annotations,
|
|
236
|
+
execute: async (u, o) => {
|
|
237
|
+
var a, e;
|
|
226
238
|
try {
|
|
227
|
-
|
|
228
|
-
|
|
239
|
+
(a = o == null ? void 0 : o.signal) == null || a.throwIfAborted();
|
|
240
|
+
const i = u.newName, s = n.list().find((f) => f.isActive);
|
|
241
|
+
return await n.rename(i), (e = o == null ? void 0 : o.signal) == null || e.throwIfAborted(), {
|
|
229
242
|
success: !0,
|
|
230
|
-
siteId:
|
|
231
|
-
newName:
|
|
243
|
+
siteId: s == null ? void 0 : s.slug,
|
|
244
|
+
newName: i
|
|
232
245
|
};
|
|
233
|
-
} catch (
|
|
246
|
+
} catch (i) {
|
|
234
247
|
return {
|
|
235
|
-
error: `${
|
|
248
|
+
error: `${t.errorPrefix}: ${p(i)}`
|
|
236
249
|
};
|
|
237
250
|
}
|
|
238
251
|
}
|
|
239
252
|
},
|
|
240
253
|
{
|
|
241
254
|
name: "playground_get_website_url",
|
|
242
|
-
description:
|
|
243
|
-
|
|
244
|
-
|
|
255
|
+
description: r.description,
|
|
256
|
+
inputSchema: h(r.params),
|
|
257
|
+
annotations: r.annotations,
|
|
258
|
+
execute: async (u, o) => {
|
|
259
|
+
var a;
|
|
245
260
|
try {
|
|
246
|
-
return {
|
|
261
|
+
return (a = o == null ? void 0 : o.signal) == null || a.throwIfAborted(), {
|
|
247
262
|
url: window.location.href
|
|
248
263
|
};
|
|
249
|
-
} catch (
|
|
264
|
+
} catch (e) {
|
|
250
265
|
return {
|
|
251
|
-
error: `${
|
|
266
|
+
error: `${r.errorPrefix}: ${p(e)}`
|
|
252
267
|
};
|
|
253
268
|
}
|
|
254
269
|
}
|
|
255
270
|
}
|
|
256
271
|
];
|
|
257
272
|
}
|
|
258
|
-
function
|
|
259
|
-
const
|
|
260
|
-
if (!
|
|
273
|
+
function U(n) {
|
|
274
|
+
const c = x();
|
|
275
|
+
if (!c)
|
|
261
276
|
return { stop: () => {
|
|
262
277
|
} };
|
|
263
|
-
const
|
|
264
|
-
let
|
|
265
|
-
async function
|
|
266
|
-
if (
|
|
278
|
+
const d = c, t = M();
|
|
279
|
+
let r = null, u = !1, o = "";
|
|
280
|
+
async function a(e) {
|
|
281
|
+
if (u)
|
|
267
282
|
return;
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
283
|
+
const i = JSON.stringify(e);
|
|
284
|
+
if (i === o)
|
|
270
285
|
return;
|
|
271
|
-
|
|
272
|
-
const { signal:
|
|
273
|
-
for (const
|
|
274
|
-
if (
|
|
275
|
-
|
|
276
|
-
`Skipping the WebMCP tool "${
|
|
286
|
+
o = i, r == null || r.abort(), r = new AbortController();
|
|
287
|
+
const { signal: l } = r;
|
|
288
|
+
for (const s of e) {
|
|
289
|
+
if (t.has(s.name)) {
|
|
290
|
+
S.warn(
|
|
291
|
+
`Skipping the WebMCP tool "${s.name}" registered by the site: Playground already provides a tool under that name.`
|
|
277
292
|
);
|
|
278
293
|
continue;
|
|
279
294
|
}
|
|
280
295
|
try {
|
|
281
|
-
await
|
|
282
|
-
signal:
|
|
296
|
+
await d.registerTool(k(n, s), {
|
|
297
|
+
signal: l
|
|
283
298
|
});
|
|
284
299
|
} catch (f) {
|
|
285
|
-
|
|
286
|
-
`Failed to register the site's WebMCP tool "${
|
|
300
|
+
S.warn(
|
|
301
|
+
`Failed to register the site's WebMCP tool "${s.name}": ${p(f)}`
|
|
287
302
|
);
|
|
288
303
|
}
|
|
289
|
-
if (
|
|
304
|
+
if (l.aborted)
|
|
290
305
|
return;
|
|
291
306
|
}
|
|
292
307
|
}
|
|
293
|
-
return n.onWebMCPToolsChanged((
|
|
294
|
-
|
|
295
|
-
}).catch((
|
|
296
|
-
|
|
308
|
+
return n.onWebMCPToolsChanged((e) => {
|
|
309
|
+
a(e);
|
|
310
|
+
}).catch((e) => {
|
|
311
|
+
S.warn("Failed to observe the site's WebMCP tools:", e);
|
|
297
312
|
}), {
|
|
298
313
|
stop() {
|
|
299
|
-
|
|
314
|
+
u = !0, r == null || r.abort(), r = null, o = "";
|
|
300
315
|
}
|
|
301
316
|
};
|
|
302
317
|
}
|
|
303
|
-
function
|
|
318
|
+
function M() {
|
|
304
319
|
return /* @__PURE__ */ new Set([
|
|
305
|
-
...Object.keys(
|
|
306
|
-
...Object.keys(
|
|
320
|
+
...Object.keys(P),
|
|
321
|
+
...Object.keys($())
|
|
307
322
|
]);
|
|
308
323
|
}
|
|
309
|
-
function
|
|
324
|
+
function k(n, c) {
|
|
310
325
|
return {
|
|
311
|
-
name:
|
|
312
|
-
description:
|
|
313
|
-
inputSchema:
|
|
314
|
-
annotations:
|
|
315
|
-
execute: async (
|
|
326
|
+
name: c.name,
|
|
327
|
+
description: c.description,
|
|
328
|
+
inputSchema: c.inputSchema,
|
|
329
|
+
annotations: c.annotations,
|
|
330
|
+
execute: async (d, t) => {
|
|
331
|
+
const r = t == null ? void 0 : t.signal, u = crypto.randomUUID(), o = () => {
|
|
332
|
+
n.cancelWebMCPTool(u).catch((a) => {
|
|
333
|
+
S.warn("Failed to cancel the site tool:", a);
|
|
334
|
+
});
|
|
335
|
+
};
|
|
316
336
|
try {
|
|
317
|
-
|
|
318
|
-
|
|
337
|
+
r == null || r.throwIfAborted(), r == null || r.addEventListener("abort", o, { once: !0 });
|
|
338
|
+
const a = await n.callWebMCPTool(
|
|
339
|
+
c.name,
|
|
340
|
+
d ?? {},
|
|
341
|
+
u
|
|
342
|
+
);
|
|
343
|
+
return r == null || r.throwIfAborted(), a;
|
|
344
|
+
} catch (a) {
|
|
319
345
|
return {
|
|
320
|
-
error: `Error running the WordPress site's "${
|
|
346
|
+
error: `Error running the WordPress site's "${c.name}" tool: ${p(a)}`
|
|
321
347
|
};
|
|
348
|
+
} finally {
|
|
349
|
+
r == null || r.removeEventListener("abort", o);
|
|
322
350
|
}
|
|
323
351
|
}
|
|
324
352
|
};
|
|
325
353
|
}
|
|
326
354
|
export {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
355
|
+
J as registerWebMCPTools,
|
|
356
|
+
L as startMcpBridge,
|
|
357
|
+
U as startWebMCPSiteToolProxy
|
|
330
358
|
};
|
|
331
359
|
//# sourceMappingURL=client.js.map
|