@wix/mcp 1.0.5 → 1.0.7
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/bin.js +1 -1
- package/build/bin.js +665 -82
- package/build/bin.js.map +7 -0
- package/build/chunk-QGIZNLF4.js +8179 -0
- package/build/chunk-QGIZNLF4.js.map +7 -0
- package/build/index.js +201 -6
- package/build/index.js.map +7 -0
- package/build/panorama.d.ts +2 -0
- package/build/wix-mcp-server.d.ts +4 -1
- package/package.json +8 -5
- package/build/api-call/index.js +0 -124
- package/build/cli-tools/cli.js +0 -338
- package/build/cli-tools/utils.js +0 -25
- package/build/docs/docs.js +0 -448
- package/build/docs/long-content.js +0 -1
- package/build/docs/semanticSearch.js +0 -108
- package/build/docs/semanticSearch.test.js +0 -459
- package/build/interactive-command-tools/eventually.js +0 -15
- package/build/interactive-command-tools/handleStdout.js +0 -75
- package/build/interactive-command-tools/interactive-command-utils.js +0 -75
- package/build/logger.js +0 -61
- package/build/resources/docs.js +0 -45
- package/build/sentry.js +0 -10
- package/build/support/index.js +0 -32
- package/build/tool-utils.js +0 -29
- package/build/tool-utils.spec.js +0 -119
- package/build/wix-mcp-server.js +0 -51
package/build/bin.js
CHANGED
|
@@ -1,98 +1,681 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { logger, attachStdErrLogger, attachMcpServerLogger, attachFileLogger } from './logger.js';
|
|
7
|
-
import { WixMcpServer } from './wix-mcp-server.js';
|
|
8
|
-
import { addDocsResources } from './resources/docs.js';
|
|
9
|
-
const PUBLIC_TOOLS = [...VALID_DOCS_TOOLS];
|
|
10
|
-
const EXPERIMENTAL_TOOLS = ['WIX_API', 'CLI_COMMAND'];
|
|
11
|
-
export const DEFAULT_TOOLS = [...VALID_DOCS_TOOLS];
|
|
12
|
-
const parsedArgs = minimist(process.argv.slice(2));
|
|
13
|
-
function parseExperimentalArg() {
|
|
14
|
-
const experimentalArg = parsedArgs['experimental'];
|
|
15
|
-
if (!experimentalArg)
|
|
16
|
-
return [];
|
|
17
|
-
return experimentalArg
|
|
18
|
-
.split(',')
|
|
19
|
-
.map((t) => t.trim())
|
|
20
|
-
.filter((tool) => EXPERIMENTAL_TOOLS.includes(tool));
|
|
1
|
+
|
|
2
|
+
// Shim require if needed.
|
|
3
|
+
import module from 'module';
|
|
4
|
+
if (typeof globalThis.require === "undefined") {
|
|
5
|
+
globalThis.require = module.createRequire(import.meta.url);
|
|
21
6
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
VALID_DOCS_TOOLS,
|
|
10
|
+
WixMcpServer,
|
|
11
|
+
addDocsResources,
|
|
12
|
+
addDocsTools,
|
|
13
|
+
attachFileLogger,
|
|
14
|
+
attachMcpServerLogger,
|
|
15
|
+
attachStdErrLogger,
|
|
16
|
+
handleWixAPIResponse,
|
|
17
|
+
logger
|
|
18
|
+
} from "./chunk-QGIZNLF4.js";
|
|
19
|
+
|
|
20
|
+
// src/sentry.ts
|
|
21
|
+
import * as Sentry from "@sentry/node";
|
|
22
|
+
Sentry.init({
|
|
23
|
+
dsn: "https://583c5af58c664fd1977d638a693b0ada@sentry-next.wixpress.com/20924",
|
|
24
|
+
tracesSampleRate: 1,
|
|
25
|
+
initialScope: {
|
|
26
|
+
tags: {
|
|
27
|
+
fullArtifactId: "com.wixpress.spartans.wix-mcp"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// src/bin.ts
|
|
33
|
+
import minimist from "minimist";
|
|
34
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
35
|
+
|
|
36
|
+
// src/cli-tools/cli.ts
|
|
37
|
+
import { z } from "zod";
|
|
38
|
+
|
|
39
|
+
// src/cli-tools/utils.ts
|
|
40
|
+
import { existsSync, readFileSync } from "fs";
|
|
41
|
+
import { homedir } from "os";
|
|
42
|
+
import path from "path";
|
|
43
|
+
function getCliAuthTokenForSiteId(siteIdOrAccountsFileName) {
|
|
44
|
+
const apiKeyFileName = path.join(homedir(), `.wix/auth/api-key.json`);
|
|
45
|
+
const apiKeyFileExists = existsSync(apiKeyFileName);
|
|
46
|
+
if (apiKeyFileExists) {
|
|
47
|
+
const apiKeyData = JSON.parse(readFileSync(apiKeyFileName, "utf8"));
|
|
48
|
+
return apiKeyData.token || apiKeyData.accessToken;
|
|
49
|
+
}
|
|
50
|
+
const siteTokenFileName = path.join(
|
|
51
|
+
homedir(),
|
|
52
|
+
`.wix/auth/${siteIdOrAccountsFileName}.json`
|
|
53
|
+
);
|
|
54
|
+
const siteTokenFileExists = existsSync(siteTokenFileName);
|
|
55
|
+
if (siteTokenFileExists) {
|
|
56
|
+
const authData = JSON.parse(readFileSync(siteTokenFileName, "utf8"));
|
|
57
|
+
return authData.accessToken || authData.token;
|
|
58
|
+
}
|
|
59
|
+
throw new Error(
|
|
60
|
+
"No site token or api key found. You need to authenticate with Wix CLI first."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function getSiteIdFromCliAppConfig(appPath) {
|
|
64
|
+
const appConfig = JSON.parse(
|
|
65
|
+
readFileSync(path.join(appPath, ".wix/app.config.json"), "utf8")
|
|
66
|
+
);
|
|
67
|
+
return appConfig.siteId;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/cli-tools/cli.ts
|
|
71
|
+
import { execa } from "execa";
|
|
72
|
+
|
|
73
|
+
// src/interactive-command-tools/handleStdout.ts
|
|
74
|
+
import stripAnsi from "strip-ansi";
|
|
75
|
+
|
|
76
|
+
// src/interactive-command-tools/eventually.ts
|
|
77
|
+
import waitForExpect from "wait-for-expect";
|
|
78
|
+
var defaultOptions = {
|
|
79
|
+
timeout: 1e4,
|
|
80
|
+
interval: 200
|
|
81
|
+
};
|
|
82
|
+
async function eventually(expectation, options) {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
waitForExpect.default(
|
|
85
|
+
async () => {
|
|
86
|
+
const ret = await expectation();
|
|
87
|
+
resolve(ret);
|
|
88
|
+
},
|
|
89
|
+
options?.timeout ?? defaultOptions.timeout,
|
|
90
|
+
options?.interval ?? defaultOptions.interval
|
|
91
|
+
).catch((error) => reject(error));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/interactive-command-tools/handleStdout.ts
|
|
96
|
+
function handleStdout(stdout) {
|
|
97
|
+
let checkStartIndex = 0;
|
|
98
|
+
const lines = [];
|
|
99
|
+
logger.log(`handleStdout: stdout: ${stdout}`);
|
|
100
|
+
stdout.on("data", (chunk) => {
|
|
101
|
+
logger.log(`handleStdout: chunk: ${chunk}`);
|
|
102
|
+
lines.push(...stripAnsi(chunk.toString()).split("\n"));
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
async waitForText(match, { timeout = 2 * 60 * 1e3 } = {}) {
|
|
106
|
+
return eventually(
|
|
107
|
+
() => {
|
|
108
|
+
const matchedIndex = lines.findIndex((line, index) => {
|
|
109
|
+
if (index < checkStartIndex) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
if (typeof match === "string") {
|
|
113
|
+
return line.includes(match);
|
|
114
|
+
}
|
|
115
|
+
return line.match(match);
|
|
116
|
+
});
|
|
117
|
+
checkStartIndex = matchedIndex >= 0 ? matchedIndex + 1 : lines.length;
|
|
118
|
+
if (matchedIndex !== -1) {
|
|
119
|
+
return lines[matchedIndex];
|
|
120
|
+
}
|
|
121
|
+
const message = `Could not match text in output: ${match}`;
|
|
122
|
+
throw new Error(message);
|
|
123
|
+
},
|
|
124
|
+
{ timeout }
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
async waitForAndCallback(matchesAndCallbacks, { timeout = 2 * 60 * 1e3 } = {}) {
|
|
128
|
+
let stopResolve;
|
|
129
|
+
const stopPromise = new Promise((resolve) => {
|
|
130
|
+
stopResolve = resolve;
|
|
131
|
+
});
|
|
132
|
+
const processedMatches = /* @__PURE__ */ new Set();
|
|
133
|
+
const waitPromise = eventually(
|
|
134
|
+
() => {
|
|
135
|
+
for (const { match, callback } of matchesAndCallbacks) {
|
|
136
|
+
if (processedMatches.has(match)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (lines.some((line) => line.includes(match))) {
|
|
140
|
+
logger.log(`create-cli: found match ${match}`);
|
|
141
|
+
processedMatches.add(match);
|
|
142
|
+
callback(() => {
|
|
143
|
+
logger.log(`create-cli: stopping match loop`);
|
|
144
|
+
stopResolve();
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (processedMatches.size === matchesAndCallbacks.length) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
throw new Error(
|
|
153
|
+
`Could not find any of the remaining matches: ${matchesAndCallbacks.filter((m) => !processedMatches.has(m.match)).map((m) => m.match).join(", ")}`
|
|
154
|
+
);
|
|
155
|
+
},
|
|
156
|
+
{ timeout }
|
|
157
|
+
);
|
|
158
|
+
return Promise.race([waitPromise, stopPromise]);
|
|
159
|
+
},
|
|
160
|
+
async getOutput() {
|
|
161
|
+
return lines.join("\n");
|
|
28
162
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/interactive-command-tools/interactive-command-utils.ts
|
|
167
|
+
var ENTER = "\r";
|
|
168
|
+
var DOWN = "\x1B[B";
|
|
169
|
+
var mockInteractiveGenerateCommandTool = async ({
|
|
170
|
+
extensionType,
|
|
171
|
+
stdin,
|
|
172
|
+
stdout
|
|
173
|
+
}) => {
|
|
174
|
+
try {
|
|
175
|
+
logger.log("RunWixCliCommand: handle stdout");
|
|
176
|
+
const stdoutHandler = handleStdout(stdout);
|
|
177
|
+
logger.log("RunWixCliCommand: waiting for text");
|
|
178
|
+
await stdoutHandler.waitForText(
|
|
179
|
+
"What kind of extension would you like to generate?"
|
|
180
|
+
);
|
|
181
|
+
if (extensionType === "DASHBOARD_PAGE") {
|
|
182
|
+
} else if (extensionType === "BACKEND_EVENT") {
|
|
183
|
+
logger.log("RunWixCliCommand: writing DOWN 9 times");
|
|
184
|
+
for (let i = 0; i < 9; i++) {
|
|
185
|
+
stdin.write(DOWN);
|
|
186
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
logger.log("RunWixCliCommand: writing ENTER 1");
|
|
190
|
+
stdin.write(ENTER);
|
|
191
|
+
if (extensionType === "DASHBOARD_PAGE") {
|
|
192
|
+
await stdoutHandler.waitForText("Page title");
|
|
193
|
+
logger.log("RunWixCliCommand: writing ENTER 2");
|
|
194
|
+
stdin.write(ENTER);
|
|
195
|
+
await stdoutHandler.waitForText("Enter the route for the new page");
|
|
196
|
+
logger.log("RunWixCliCommand: writing ENTER 3");
|
|
197
|
+
stdin.write(ENTER);
|
|
198
|
+
} else if (extensionType === "BACKEND_EVENT") {
|
|
199
|
+
await stdoutHandler.waitForText("Event folder");
|
|
200
|
+
logger.log("RunWixCliCommand: writing ENTER 2");
|
|
201
|
+
stdin.write(ENTER);
|
|
202
|
+
logger.log("RunWixCliCommand: waiting for text");
|
|
203
|
+
try {
|
|
204
|
+
await stdoutHandler.waitForText(
|
|
205
|
+
"Would you like to install dependencies now?",
|
|
206
|
+
{ timeout: 1e3 }
|
|
207
|
+
);
|
|
208
|
+
logger.log("RunWixCliCommand: writing ENTER 3");
|
|
209
|
+
stdin.write(ENTER);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
if (error instanceof Error && error.message.includes("Could not match text in output")) {
|
|
212
|
+
logger.log(
|
|
213
|
+
"RunWixCliCommand: dependencies are already installed, skipping install"
|
|
214
|
+
);
|
|
215
|
+
logger.log(await stdoutHandler.getOutput());
|
|
216
|
+
} else {
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
logger.log("RunWixCliCommand: waiting for success message");
|
|
222
|
+
try {
|
|
223
|
+
await stdoutHandler.waitForText("Successfully", { timeout: 1e3 });
|
|
224
|
+
logger.log("RunWixCliCommand: success message found");
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (error instanceof Error && error.message.includes("Could not match text in output")) {
|
|
227
|
+
logger.log("RunWixCliCommand: success message not found, skipping");
|
|
228
|
+
} else {
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return stdoutHandler.getOutput();
|
|
233
|
+
} catch (error) {
|
|
234
|
+
logger.error("RunWixCliCommand: error", error);
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// src/cli-tools/cli.ts
|
|
240
|
+
var VALID_CLI_TOOLS = [
|
|
241
|
+
"WIX_API",
|
|
242
|
+
"CLI_COMMAND",
|
|
243
|
+
"CLI_COMMAND_INTERACTIVE_MODE"
|
|
244
|
+
];
|
|
245
|
+
function addCliTools(server2, allowedTools = [
|
|
246
|
+
"WIX_API",
|
|
247
|
+
"CLI_COMMAND",
|
|
248
|
+
"CLI_COMMAND_INTERACTIVE_MODE"
|
|
249
|
+
], isWixOne2 = false) {
|
|
250
|
+
if (allowedTools.includes("WIX_API")) {
|
|
251
|
+
server2.tool(
|
|
252
|
+
"CallWixAPI",
|
|
253
|
+
"Call Wix apis on an app. Use this to create, read, update, and delete data and other Wix entities in your Wix app.",
|
|
254
|
+
{
|
|
255
|
+
appPath: z.string().describe(
|
|
256
|
+
"The dir path to the wix backoffice cli app to call the api on behalf of. should have {appPath}/.wix/app.config.json file with a siteId field. if passed, siteId is not required"
|
|
257
|
+
).optional(),
|
|
258
|
+
// should we have appPath or siteId here? (appPath encapsulates this more since we can get the siteId from the appPath then perform the call)
|
|
259
|
+
siteId: z.string().describe(
|
|
260
|
+
"The siteId of the wix backoffice cli app to call the api on behalf of. You can find the siteId in the {appPath}/.wix/app.config.json file. You can pass any other siteId if you want to call the api on behalf of a different site. If passed, appPath is not required. if not passed, the appPath must be provided."
|
|
261
|
+
).optional(),
|
|
262
|
+
url: z.string().describe(
|
|
263
|
+
"The url of the api to call - usually you get this from the Wix REST docs or from the conversation context"
|
|
264
|
+
),
|
|
265
|
+
method: z.string().describe(
|
|
266
|
+
"The HTTP method to use for the API call (e.g. GET, POST, PUT, DELETE)"
|
|
267
|
+
),
|
|
268
|
+
body: z.string().optional().describe(
|
|
269
|
+
"A string representing of a valid JSON object to describe the body of the request"
|
|
270
|
+
)
|
|
271
|
+
},
|
|
272
|
+
async ({ method, url, body, appPath, siteId }) => {
|
|
273
|
+
logger.log(
|
|
274
|
+
`Calling Wix API: ${appPath} ${siteId} ${method} ${url}, body: ${JSON.stringify(
|
|
275
|
+
body
|
|
276
|
+
)}`
|
|
277
|
+
);
|
|
278
|
+
if (!siteId && !appPath) {
|
|
279
|
+
return {
|
|
280
|
+
content: [
|
|
281
|
+
{
|
|
282
|
+
type: "text",
|
|
283
|
+
text: "Either appPath or siteId must be provided"
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
let siteIdToUse = siteId;
|
|
289
|
+
if (!siteIdToUse && appPath) {
|
|
290
|
+
siteIdToUse = getSiteIdFromCliAppConfig(appPath);
|
|
291
|
+
}
|
|
292
|
+
if (!siteIdToUse) {
|
|
293
|
+
return {
|
|
294
|
+
content: [
|
|
295
|
+
{
|
|
296
|
+
type: "text",
|
|
297
|
+
text: "Either appPath or siteId must be provided"
|
|
298
|
+
}
|
|
299
|
+
]
|
|
300
|
+
};
|
|
40
301
|
}
|
|
41
|
-
|
|
42
|
-
|
|
302
|
+
logger.log(`Site ID for Wix API call: ${siteIdToUse}`);
|
|
303
|
+
const authorization = getCliAuthTokenForSiteId(siteIdToUse);
|
|
304
|
+
if (!authorization) {
|
|
305
|
+
return {
|
|
306
|
+
content: [
|
|
307
|
+
{
|
|
308
|
+
type: "text",
|
|
309
|
+
text: "Failed to get authorization token. Please check your siteId and appPath"
|
|
310
|
+
}
|
|
311
|
+
]
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
const response = await fetch(url, {
|
|
316
|
+
method,
|
|
317
|
+
headers: {
|
|
318
|
+
Authorization: authorization,
|
|
319
|
+
"wix-site-id": siteIdToUse,
|
|
320
|
+
...body ? { "Content-Type": "application/json" } : {}
|
|
321
|
+
},
|
|
322
|
+
body
|
|
323
|
+
});
|
|
324
|
+
const responseData = await handleWixAPIResponse(response);
|
|
325
|
+
return {
|
|
326
|
+
content: [
|
|
327
|
+
{
|
|
328
|
+
type: "text",
|
|
329
|
+
text: `Wix API call successful: ${JSON.stringify(responseData)}`
|
|
330
|
+
}
|
|
331
|
+
]
|
|
332
|
+
};
|
|
333
|
+
} catch (error) {
|
|
334
|
+
logger.error(`Failed to call Wix API: ${error}`);
|
|
335
|
+
throw new Error(`Failed to call Wix API: ${error}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
if (allowedTools.includes("CLI_COMMAND_INTERACTIVE_MODE")) {
|
|
341
|
+
server2.tool(
|
|
342
|
+
"RunWixCliCommandInteractiveMode",
|
|
343
|
+
`Executes Wix CLI commands for Wix app development and management.
|
|
344
|
+
Use this tool to run commands like 'wix app generate' (adds new extensions), 'wix app build' (builds your app), 'wix app preview' (creates shareable preview), 'wix app release' (releases a new version of your app), and more.
|
|
345
|
+
|
|
346
|
+
IMPORTANT: Before using this tool, check if the command is mapped in package.json scripts:
|
|
347
|
+
* Use this tool for npm/yarn scripts that map to Wix CLI commands as well.
|
|
348
|
+
* Do not use this tool for starting the local development server.
|
|
349
|
+
|
|
350
|
+
Before using this tool, you MUST search the Wix documentation for the command you want to run.
|
|
351
|
+
|
|
352
|
+
DO NOT USE THIS TOOL FOR ANY OTHER PURPOSE. IT IS ONLY FOR WIX CLI COMMANDS.`,
|
|
353
|
+
{
|
|
354
|
+
appPath: z.string().describe("The full path to the Wix CLI app to run the command on"),
|
|
355
|
+
extensionType: z.enum(["DASHBOARD_PAGE", "BACKEND_EVENT"]).optional().describe(
|
|
356
|
+
"The type of extension to generate. You MUST provide this for commands that generate extensions."
|
|
357
|
+
),
|
|
358
|
+
searchedDocs: z.boolean().describe(
|
|
359
|
+
"Whether you have already searched the Wix documentation for the command you want to run."
|
|
360
|
+
),
|
|
361
|
+
command: z.string().min(1, "Command cannot be empty").max(1e3, "Command is too long").describe(
|
|
362
|
+
"The Wix CLI command to execute (e.g. 'wix app generate', 'wix app build', 'wix app preview', 'wix app release', etc.), or a npm/yarn script that maps to a Wix CLI command (e.g. 'npm run generate', 'yarn build', etc.)."
|
|
363
|
+
)
|
|
364
|
+
},
|
|
365
|
+
async ({ command, appPath, extensionType }) => {
|
|
366
|
+
command = command.replace("wix app generate", "npm run generate");
|
|
367
|
+
if (command.includes("generate") && !extensionType) {
|
|
368
|
+
return {
|
|
369
|
+
content: [
|
|
370
|
+
{
|
|
371
|
+
type: "text",
|
|
372
|
+
text: "Error: You must provide an extension type for the 'generate' command."
|
|
373
|
+
}
|
|
374
|
+
],
|
|
375
|
+
isError: true
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
logger.log(
|
|
379
|
+
`RunWixCliCommand: command: ${command}, appPath: ${appPath}, extensionType: ${extensionType}`
|
|
380
|
+
);
|
|
381
|
+
try {
|
|
382
|
+
logger.log(`Executing Wix CLI command: ${command}`);
|
|
383
|
+
const commandParts = command.split(" ");
|
|
384
|
+
const commandName = commandParts[0];
|
|
385
|
+
const commandArgs = commandParts.slice(1);
|
|
386
|
+
const subprocess = execa(commandName, commandArgs, {
|
|
387
|
+
cwd: appPath,
|
|
388
|
+
extendEnv: true,
|
|
389
|
+
env: {
|
|
390
|
+
...process.env,
|
|
391
|
+
PATH: process.env.PATH,
|
|
392
|
+
WIX_CLI_TEST_OVERRIDES: JSON.stringify({
|
|
393
|
+
inkDebug: true
|
|
394
|
+
})
|
|
395
|
+
},
|
|
396
|
+
timeout: 5 * 60 * 1e3,
|
|
397
|
+
// 5 minute timeout
|
|
398
|
+
maxBuffer: 10 * 1024 * 1024
|
|
399
|
+
// 10MB output limit
|
|
400
|
+
});
|
|
401
|
+
logger.log(`RunWixCliCommand: pid: ${subprocess.pid}`);
|
|
402
|
+
if (!subprocess.pid) {
|
|
403
|
+
let spawnError;
|
|
404
|
+
if (!spawnError) {
|
|
405
|
+
await new Promise((resolve) => {
|
|
406
|
+
subprocess.on("error", (err) => {
|
|
407
|
+
spawnError = err;
|
|
408
|
+
resolve({ spawnError });
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
content: [
|
|
414
|
+
{
|
|
415
|
+
type: "text",
|
|
416
|
+
text: `Failed to start the Wix CLI command process. This usually indicates a problem with the command or the environment. Are you sure Wix CLI is installed globally?
|
|
417
|
+
|
|
418
|
+
Command: ${command}
|
|
419
|
+
|
|
420
|
+
${spawnError}`
|
|
421
|
+
}
|
|
422
|
+
]
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
const { stdin, stdout, stderr } = subprocess;
|
|
426
|
+
if (extensionType) {
|
|
427
|
+
const output = await mockInteractiveGenerateCommandTool({
|
|
428
|
+
extensionType,
|
|
429
|
+
stdin,
|
|
430
|
+
stdout
|
|
431
|
+
});
|
|
432
|
+
logger.log(`RunWixCliCommand: output: ${output}`);
|
|
433
|
+
return {
|
|
434
|
+
content: [{ type: "text", text: output }]
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
const stringifyStdout = JSON.stringify(stdout);
|
|
438
|
+
const stringifyStderr = JSON.stringify(stderr);
|
|
439
|
+
return {
|
|
440
|
+
content: [
|
|
441
|
+
{ type: "text", text: stringifyStdout },
|
|
442
|
+
...stringifyStderr ? [{ type: "text", text: `Error: ${stringifyStderr}` }] : []
|
|
443
|
+
]
|
|
444
|
+
};
|
|
445
|
+
} catch (error) {
|
|
446
|
+
logger.error(`Error executing Wix CLI command: ${error}`);
|
|
447
|
+
return {
|
|
448
|
+
content: [{ type: "text", text: `Error: ${error}` }],
|
|
449
|
+
isError: true
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
if (allowedTools.includes("CLI_COMMAND")) {
|
|
456
|
+
server2.tool(
|
|
457
|
+
"RunWixCliCommand",
|
|
458
|
+
`Executes Wix CLI commands for Wix app development and management.
|
|
459
|
+
Use this tool to run commands like 'wix app generate' (adds new extensions), 'wix app build' (builds your app), 'wix app preview' (creates shareable preview), 'wix app release' (releases a new version of your app), and more.
|
|
460
|
+
|
|
461
|
+
IMPORTANT: Before using this tool, check if the command is mapped in package.json scripts:
|
|
462
|
+
* Use this tool for npm/yarn scripts that map to Wix CLI commands as well.
|
|
463
|
+
* Do not use this tool for starting the local development server.
|
|
464
|
+
|
|
465
|
+
Before using this tool, you MUST search the Wix documentation for the command you want to run.
|
|
466
|
+
|
|
467
|
+
DO NOT USE THIS TOOL FOR ANY OTHER PURPOSE. IT IS ONLY FOR WIX CLI COMMANDS.`,
|
|
468
|
+
{
|
|
469
|
+
appPath: z.string().describe("The full path to the Wix CLI app to run the command on."),
|
|
470
|
+
extensionType: z.enum([
|
|
471
|
+
"dashboard-page",
|
|
472
|
+
"dashboard-plugin",
|
|
473
|
+
"dashboard-menu-plugin",
|
|
474
|
+
"dashboard-modal",
|
|
475
|
+
"web-method",
|
|
476
|
+
"api-route",
|
|
477
|
+
"event",
|
|
478
|
+
"service-plugin"
|
|
479
|
+
]).optional().describe(
|
|
480
|
+
"The type of extension to generate. You MUST provide this for commands that generate extensions."
|
|
481
|
+
),
|
|
482
|
+
extensionName: z.string().optional().describe(
|
|
483
|
+
"The name of the extension to generate, e.g. My Dashboard Page. You MUST provide this for commands that generate extensions."
|
|
484
|
+
),
|
|
485
|
+
searchedDocs: z.boolean().describe(
|
|
486
|
+
"Whether you have already searched the Wix documentation for the command you want to run."
|
|
487
|
+
),
|
|
488
|
+
command: z.string().min(1, "Command cannot be empty").max(1e3, "Command is too long").describe(
|
|
489
|
+
"The Wix CLI command to execute (e.g. 'wix app generate', 'wix app build', 'wix app preview', 'wix app release', etc.), or a script that maps to a Wix CLI command (e.g. 'npm run generate', 'yarn generate', etc.)."
|
|
490
|
+
)
|
|
491
|
+
},
|
|
492
|
+
async ({ command, appPath, extensionType, extensionName }) => {
|
|
493
|
+
logger.log(
|
|
494
|
+
`RunWixCliCommand: command: ${command}, appPath: ${appPath}, extensionType: ${extensionType}, extensionName: ${extensionName}`
|
|
495
|
+
);
|
|
496
|
+
let commandName = "";
|
|
497
|
+
let commandArgs = [];
|
|
498
|
+
if (command.includes("generate")) {
|
|
499
|
+
if (!extensionType) {
|
|
500
|
+
return {
|
|
501
|
+
content: [
|
|
502
|
+
{
|
|
503
|
+
type: "text",
|
|
504
|
+
text: "Error: You must provide an extension type for the 'generate' command."
|
|
505
|
+
}
|
|
506
|
+
],
|
|
507
|
+
isError: true
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
if (!extensionName) {
|
|
511
|
+
return {
|
|
512
|
+
content: [
|
|
513
|
+
{
|
|
514
|
+
type: "text",
|
|
515
|
+
text: "Error: You must provide an extension name for the 'generate' command."
|
|
516
|
+
}
|
|
517
|
+
],
|
|
518
|
+
isError: true
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
commandName = "npx";
|
|
522
|
+
commandArgs = [
|
|
523
|
+
isWixOne2 ? "wix-one" : "wix",
|
|
524
|
+
"app",
|
|
525
|
+
"generate",
|
|
526
|
+
"-t",
|
|
527
|
+
extensionType,
|
|
528
|
+
"-n",
|
|
529
|
+
extensionName,
|
|
530
|
+
"--json"
|
|
531
|
+
];
|
|
532
|
+
} else {
|
|
533
|
+
const commandParts = command.split(" ");
|
|
534
|
+
commandName = commandParts[0];
|
|
535
|
+
commandArgs = commandParts.slice(1);
|
|
536
|
+
}
|
|
537
|
+
if (isWixOne2 && commandName === "wix") {
|
|
538
|
+
commandName = "wix-one";
|
|
539
|
+
}
|
|
540
|
+
try {
|
|
541
|
+
logger.log(
|
|
542
|
+
`Executing Wix CLI command: ${commandName} ${commandArgs.join(" ")}`
|
|
543
|
+
);
|
|
544
|
+
const { stdout, stderr, exitCode } = await execa(
|
|
545
|
+
commandName,
|
|
546
|
+
commandArgs,
|
|
547
|
+
{
|
|
548
|
+
cwd: appPath,
|
|
549
|
+
extendEnv: true,
|
|
550
|
+
env: {
|
|
551
|
+
...process.env
|
|
552
|
+
},
|
|
553
|
+
timeout: 5 * 60 * 1e3,
|
|
554
|
+
// 5 minute timeout
|
|
555
|
+
maxBuffer: 10 * 1024 * 1024
|
|
556
|
+
// 10MB output limit
|
|
557
|
+
}
|
|
558
|
+
);
|
|
559
|
+
if (exitCode !== 0) {
|
|
560
|
+
return {
|
|
561
|
+
content: [{ type: "text", text: `Error: ${stderr}` }],
|
|
562
|
+
isError: true
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
logger.log(`RunWixCliCommand: stdout: ${stdout}`);
|
|
566
|
+
logger.log(`RunWixCliCommand: stderr: ${stderr}`);
|
|
567
|
+
return {
|
|
568
|
+
content: [
|
|
569
|
+
{ type: "text", text: stdout },
|
|
570
|
+
...stderr ? [{ type: "text", text: `Error: ${stderr}` }] : []
|
|
571
|
+
]
|
|
572
|
+
};
|
|
573
|
+
} catch (error) {
|
|
574
|
+
logger.error(`Error executing Wix CLI command: ${error}`);
|
|
575
|
+
return {
|
|
576
|
+
content: [{ type: "text", text: `Error: ${error}` }],
|
|
577
|
+
isError: true
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
);
|
|
582
|
+
}
|
|
43
583
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
584
|
+
|
|
585
|
+
// src/bin.ts
|
|
586
|
+
var PUBLIC_TOOLS = [...VALID_DOCS_TOOLS];
|
|
587
|
+
var EXPERIMENTAL_TOOLS = ["WIX_API", "CLI_COMMAND"];
|
|
588
|
+
var DEFAULT_TOOLS = [...VALID_DOCS_TOOLS];
|
|
589
|
+
var parsedArgs = minimist(process.argv.slice(2));
|
|
590
|
+
function parseExperimentalArg() {
|
|
591
|
+
const experimentalArg = parsedArgs["experimental"];
|
|
592
|
+
if (!experimentalArg) return [];
|
|
593
|
+
return experimentalArg.split(",").map((t) => t.trim()).filter(
|
|
594
|
+
(tool) => EXPERIMENTAL_TOOLS.includes(tool)
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
function parseToolsArg() {
|
|
598
|
+
const toolsArg = parsedArgs["tools"];
|
|
599
|
+
const experimentalTools = parseExperimentalArg();
|
|
600
|
+
if (!toolsArg) {
|
|
601
|
+
return [...DEFAULT_TOOLS, ...experimentalTools];
|
|
602
|
+
}
|
|
603
|
+
const requestedTools = toolsArg.split(",").map((t) => t.trim());
|
|
604
|
+
const tools = [
|
|
605
|
+
// Include valid non-experimental tools
|
|
606
|
+
...requestedTools.filter(
|
|
607
|
+
(tool) => PUBLIC_TOOLS.includes(tool)
|
|
608
|
+
),
|
|
609
|
+
// Include enabled experimental tools
|
|
610
|
+
...experimentalTools
|
|
611
|
+
];
|
|
612
|
+
tools.forEach((tool) => {
|
|
613
|
+
if (EXPERIMENTAL_TOOLS.includes(tool)) {
|
|
614
|
+
logger.log(
|
|
615
|
+
`Warning: ${tool} is an experimental tool and may have limited functionality or breaking changes`
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
return tools;
|
|
47
620
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
621
|
+
var loggerType = parsedArgs["logger"] || "mcp";
|
|
622
|
+
if (loggerType === "file") {
|
|
623
|
+
attachFileLogger();
|
|
624
|
+
} else {
|
|
625
|
+
attachStdErrLogger();
|
|
52
626
|
}
|
|
53
|
-
logger.log(
|
|
54
|
-
logger.log(
|
|
55
|
-
logger.log(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
627
|
+
logger.log("--------------------------------");
|
|
628
|
+
logger.log("starting WIX MCP server");
|
|
629
|
+
logger.log("--------------------------------");
|
|
630
|
+
var server = new WixMcpServer(
|
|
631
|
+
{
|
|
632
|
+
name: "wix-mcp-server",
|
|
633
|
+
version: "1.0.0"
|
|
634
|
+
},
|
|
635
|
+
{
|
|
60
636
|
capabilities: {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
637
|
+
tools: {},
|
|
638
|
+
prompts: {},
|
|
639
|
+
logging: {},
|
|
640
|
+
resources: {}
|
|
65
641
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
642
|
+
}
|
|
643
|
+
);
|
|
644
|
+
var activeTools = parseToolsArg();
|
|
645
|
+
logger.log("Active tools:", activeTools);
|
|
646
|
+
var docsTools = activeTools.filter(
|
|
647
|
+
(tool) => VALID_DOCS_TOOLS.includes(tool)
|
|
648
|
+
);
|
|
70
649
|
if (docsTools.length > 0) {
|
|
71
|
-
|
|
72
|
-
|
|
650
|
+
logger.log("Adding docs tools:", docsTools);
|
|
651
|
+
addDocsTools(server, docsTools);
|
|
73
652
|
}
|
|
74
|
-
|
|
75
|
-
|
|
653
|
+
var isWixOne = parsedArgs["cli"] === "wix-one";
|
|
654
|
+
var cliTools = activeTools.filter(
|
|
655
|
+
(tool) => VALID_CLI_TOOLS.includes(tool)
|
|
656
|
+
);
|
|
76
657
|
if (cliTools.length > 0) {
|
|
77
|
-
|
|
78
|
-
|
|
658
|
+
logger.log("Adding cli tools:", cliTools, "isWixOne:", isWixOne);
|
|
659
|
+
addCliTools(server, cliTools, isWixOne);
|
|
79
660
|
}
|
|
80
661
|
try {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
logger.error('Error adding docs resources:', error);
|
|
662
|
+
const portals = parsedArgs["portals"]?.split(",") || [];
|
|
663
|
+
if (portals.length > 0) {
|
|
664
|
+
logger.log("Adding docs resources for portals:", portals);
|
|
665
|
+
await addDocsResources(server, portals);
|
|
666
|
+
}
|
|
667
|
+
} catch (error) {
|
|
668
|
+
logger.error("Error adding docs resources:", error);
|
|
89
669
|
}
|
|
90
|
-
logger.log(
|
|
91
|
-
|
|
92
|
-
logger.log(
|
|
670
|
+
logger.log("Starting server");
|
|
671
|
+
var transport = new StdioServerTransport();
|
|
672
|
+
logger.log("Connecting to transport");
|
|
93
673
|
await server.connect(transport);
|
|
94
|
-
logger.log(
|
|
95
|
-
if (loggerType ===
|
|
96
|
-
|
|
97
|
-
attachMcpServerLogger(server);
|
|
674
|
+
logger.log("Transport connected");
|
|
675
|
+
if (loggerType === "mcp") {
|
|
676
|
+
attachMcpServerLogger(server);
|
|
98
677
|
}
|
|
678
|
+
export {
|
|
679
|
+
DEFAULT_TOOLS
|
|
680
|
+
};
|
|
681
|
+
//# sourceMappingURL=bin.js.map
|