@wix/mcp 1.0.0

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 ADDED
@@ -0,0 +1,131 @@
1
+ # General Config:
2
+
3
+ ## From npm package:
4
+
5
+ ```
6
+ command: npx:
7
+ args: ["@wix/mcp"]
8
+ ```
9
+
10
+ ## Local:
11
+
12
+ First: clone + install + build
13
+
14
+ ```
15
+ command: npx
16
+ args: ["/Users/absolute/path/to/repo/dir/."]
17
+ ```
18
+
19
+ ```
20
+ command: node
21
+ args: ["/Users/absolute/path/to/build/index.js"]
22
+ ```
23
+
24
+ # Optional config arguments:
25
+
26
+ ### choose a tool:
27
+ `--tools=WDS,REST,SDK,WIX_HEADLESS,BUILD_APPS` - specify which standard tools to enable (if not specified, all standard tools are enabled)
28
+
29
+ ### enable experimental tools:
30
+ `--experimental=WIX_API,CLI_COMMAND` - enable specific experimental tools (disabled by default)
31
+
32
+ ### choose a logger:
33
+ `--logger=mcp` - log to MCP server (default)
34
+ `--logger=file` - log to file (in `~/wix-mcp-log.txt`)
35
+
36
+ Available tool options:
37
+
38
+ Standard tools (all enabled by default if no --tools specified):
39
+ - `WDS`: Wix Design System Documentation tools (MCP tool: `SearchWixWDSDocumentation`)
40
+ - `REST`: Wix REST API Documentation tools (MCP tool: `SearchWixRESTDocumentation`)
41
+ - `SDK`: Wix SDK Documentation tools (MCP tool: `SearchWixSDKDocumentation`)
42
+ - `BUILD_APPS`: Build Apps Documentation tools (MCP tool: `SearchBuildAppsDocumentation`)
43
+ - `WIX_HEADLESS`: Wix Headless Documentation tools (MCP tool: `SearchWixHeadlessDocumentation`)
44
+
45
+ Experimental tools (disabled by default):
46
+ - `WIX_API`: Wix API tools for calling APIs on a Wix app (MCP tool: `CallWixAPI`)
47
+ - `CLI_COMMAND`: CLI commands for working with Wix apps (MCP tool: `RunWixCliCommand`)
48
+
49
+ Note: Experimental tools are in early development and may have limited functionality or breaking changes. These tools are disabled by default and must be explicitly enabled via the --experimental argument, regardless of whether --tools is specified or not.
50
+
51
+ The tool enum value (e.g. `WDS`) is used in the `--tools` and `--experimental` arguments, while the MCP tool name (e.g. `SearchWixWDSDocumentation`) is what you'll see in the actual tool calls.
52
+
53
+ # Resource Feature
54
+
55
+ The resource feature provides access to Wix documentation through the MCP server. It:
56
+
57
+ 1. Fetches documentation indexes from specified Wix portals
58
+ 2. Makes documentation articles available as resources through the MCP server
59
+ 3. Allows fetching article content using the MCP protocol
60
+
61
+ Resources are accessible using the `wix-docs://` URI scheme, which maps to the corresponding Wix documentation URLs.
62
+ It's exactly parallel to the real docs url, for example:
63
+ Docs URL: https://dev.wix.com/docs/picasso/wix-ai-docs/best-practices/sdk-best-practices
64
+ Resource URI: wix-docs://picasso/wix-ai-docs/best-practices/sdk-best-practices
65
+
66
+ # Cursor
67
+
68
+ ## Cursor MCP docs:
69
+
70
+ https://docs.cursor.com/context/model-context-protocol
71
+
72
+ ## Config:
73
+
74
+ ## using `~/.cursor/mcp.json`
75
+
76
+ ### with npx:
77
+
78
+ ```
79
+ {
80
+ "mcpServers": {
81
+ "IGOR_TOOLS": {
82
+ "command": "npx",
83
+ "args": [
84
+ "@wix/mcp"
85
+ ]
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ ### With npx locally:
92
+ ```
93
+ {
94
+ "mcpServers": {
95
+ "IGOR_TOOLS": {
96
+ "command": "npx",
97
+ "args": [
98
+ "/Users/absolute/path/to/repo/dir/."
99
+ ]
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ ### with node:
106
+
107
+ 1. clone
108
+ 2. build
109
+
110
+ ```
111
+ {
112
+ "mcpServers": {
113
+ "IGOR_TOOLS": {
114
+ "command": "node",
115
+ "args": [
116
+ "/Users/absolute/path/to/build/index.js"
117
+ ]
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ ### You can try using bun + index.ts
124
+
125
+ # Troubleshooting
126
+
127
+ - try including full path to node
128
+ - try using bun and index.ts directly
129
+ - make sure build files have permissions for cursor to access
130
+ - log should be written to `~/wix-mcp-log.txt`
131
+ - add .env file with `WIX_COOKIE=` to avoid rate limits on SDK tool use
package/bin.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import './build/index.js';
@@ -0,0 +1,295 @@
1
+ import { z } from 'zod';
2
+ import { getCliAuthTokenForSiteId, getSiteIdFromCliAppConfig, handleWixAPIResponse } from './utils.js';
3
+ import { logger } from '../logger.js';
4
+ import { execa } from 'execa';
5
+ import { mockInteractiveGenerateCommandTool } from '../interactive-command-tools/interactive-command-utils.js';
6
+ export const VALID_CLI_TOOLS = [
7
+ 'WIX_API',
8
+ 'CLI_COMMAND',
9
+ 'CLI_COMMAND_INTERACTIVE_MODE'
10
+ ];
11
+ export function addCliTools(server, allowedTools = [
12
+ 'WIX_API',
13
+ 'CLI_COMMAND',
14
+ 'CLI_COMMAND_INTERACTIVE_MODE'
15
+ ]) {
16
+ if (allowedTools.includes('WIX_API')) {
17
+ server.tool('CallWixAPI', 'Call Wix apis on an app. Use this to create, read, update, and delete data and other Wix entities in your Wix app.', {
18
+ appPath: z
19
+ .string()
20
+ .describe('The dir path to the wix backoffice cli app to call the api on behalf of'), // should we have appPath or siteId here? (appPath encapsulates this more since we can get the siteId from the appPath then perform the call)
21
+ url: z
22
+ .string()
23
+ .describe('The url of the api to call - usually you get this from the Wix REST docs or from the conversation context'),
24
+ method: z
25
+ .string()
26
+ .describe('The HTTP method to use for the API call (e.g. GET, POST, PUT, DELETE)'),
27
+ body: z
28
+ .string()
29
+ .optional()
30
+ .describe('A string representing of a valid JSON object to describe the body of the request')
31
+ }, async ({ method, url, body, appPath }) => {
32
+ logger.log(`Calling Wix API: ${appPath} ${method} ${url}, body: ${JSON.stringify(body)}`);
33
+ const siteId = getSiteIdFromCliAppConfig(appPath);
34
+ logger.log(`Site ID for Wix API call: ${siteId}`);
35
+ const authorization = getCliAuthTokenForSiteId(siteId);
36
+ try {
37
+ const response = await fetch(url, {
38
+ method,
39
+ headers: {
40
+ Authorization: authorization,
41
+ ...(body ? { 'Content-Type': 'application/json' } : {})
42
+ },
43
+ body
44
+ });
45
+ const responseData = await handleWixAPIResponse(response);
46
+ return {
47
+ content: [
48
+ {
49
+ type: 'text',
50
+ text: `Wix API call successful: ${JSON.stringify(responseData)}`
51
+ }
52
+ ]
53
+ };
54
+ }
55
+ catch (error) {
56
+ logger.error(`Failed to call Wix API: ${error}`);
57
+ throw new Error(`Failed to call Wix API: ${error}`);
58
+ }
59
+ });
60
+ }
61
+ if (allowedTools.includes('CLI_COMMAND_INTERACTIVE_MODE')) {
62
+ server.tool('RunWixCliCommandInteractiveMode', `Executes Wix CLI commands for Wix app development and management.
63
+ 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.
64
+
65
+ IMPORTANT: Before using this tool, check if the command is mapped in package.json scripts:
66
+ * Use this tool for npm/yarn scripts that map to Wix CLI commands as well.
67
+ * Do not use this tool for starting the local development server.
68
+
69
+ Before using this tool, you MUST search the Wix documentation for the command you want to run.
70
+
71
+ DO NOT USE THIS TOOL FOR ANY OTHER PURPOSE. IT IS ONLY FOR WIX CLI COMMANDS.`, {
72
+ appPath: z
73
+ .string()
74
+ .describe('The full path to the Wix CLI app to run the command on'),
75
+ extensionType: z
76
+ .enum(['DASHBOARD_PAGE', 'BACKEND_EVENT'])
77
+ .optional()
78
+ .describe('The type of extension to generate. You MUST provide this for commands that generate extensions.'),
79
+ searchedDocs: z
80
+ .boolean()
81
+ .describe('Whether you have already searched the Wix documentation for the command you want to run.'),
82
+ command: z
83
+ .string()
84
+ .min(1, 'Command cannot be empty')
85
+ .max(1000, 'Command is too long')
86
+ .describe("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.).")
87
+ }, async ({ command, appPath, extensionType }) => {
88
+ command = command.replace('wix app generate', 'npm run generate');
89
+ if (command.includes('generate') && !extensionType) {
90
+ return {
91
+ content: [
92
+ {
93
+ type: 'text',
94
+ text: "Error: You must provide an extension type for the 'generate' command."
95
+ }
96
+ ],
97
+ isError: true
98
+ };
99
+ }
100
+ logger.log(`RunWixCliCommand: command: ${command}, appPath: ${appPath}, extensionType: ${extensionType}`);
101
+ try {
102
+ logger.log(`Executing Wix CLI command: ${command}`);
103
+ const commandParts = command.split(' ');
104
+ const commandName = commandParts[0];
105
+ const commandArgs = commandParts.slice(1);
106
+ // Execute with timeout
107
+ const subprocess = execa(commandName, commandArgs, {
108
+ cwd: appPath,
109
+ extendEnv: true,
110
+ env: {
111
+ ...process.env,
112
+ PATH: process.env.PATH,
113
+ WIX_CLI_TEST_OVERRIDES: JSON.stringify({
114
+ inkDebug: true
115
+ })
116
+ },
117
+ timeout: 5 * 60 * 1000, // 5 minute timeout
118
+ maxBuffer: 10 * 1024 * 1024 // 10MB output limit
119
+ });
120
+ logger.log(`RunWixCliCommand: pid: ${subprocess.pid}`);
121
+ if (!subprocess.pid) {
122
+ let spawnError;
123
+ // make sure spawnError is defined by waiting for the error event
124
+ if (!spawnError) {
125
+ await new Promise((resolve) => {
126
+ subprocess.on('error', (err) => {
127
+ spawnError = err;
128
+ resolve({ spawnError });
129
+ });
130
+ });
131
+ }
132
+ return {
133
+ content: [
134
+ {
135
+ type: 'text',
136
+ 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?\n\nCommand: ${command}\n\n${spawnError}`
137
+ }
138
+ ]
139
+ };
140
+ }
141
+ const { stdin, stdout, stderr } = subprocess;
142
+ if (extensionType) {
143
+ const output = await mockInteractiveGenerateCommandTool({
144
+ extensionType,
145
+ stdin,
146
+ stdout
147
+ });
148
+ logger.log(`RunWixCliCommand: output: ${output}`);
149
+ return {
150
+ content: [{ type: 'text', text: output }]
151
+ };
152
+ }
153
+ const stringifyStdout = JSON.stringify(stdout);
154
+ const stringifyStderr = JSON.stringify(stderr);
155
+ return {
156
+ content: [
157
+ { type: 'text', text: stringifyStdout },
158
+ ...(stringifyStderr
159
+ ? [{ type: 'text', text: `Error: ${stringifyStderr}` }]
160
+ : [])
161
+ ]
162
+ };
163
+ }
164
+ catch (error) {
165
+ logger.error(`Error executing Wix CLI command: ${error}`);
166
+ return {
167
+ content: [{ type: 'text', text: `Error: ${error}` }],
168
+ isError: true
169
+ };
170
+ }
171
+ });
172
+ }
173
+ if (allowedTools.includes('CLI_COMMAND')) {
174
+ server.tool('RunWixCliCommand', `Executes Wix CLI commands for Wix app development and management.
175
+ 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.
176
+
177
+ IMPORTANT: Before using this tool, check if the command is mapped in package.json scripts:
178
+ * Use this tool for npm/yarn scripts that map to Wix CLI commands as well.
179
+ * Do not use this tool for starting the local development server.
180
+
181
+ Before using this tool, you MUST search the Wix documentation for the command you want to run.
182
+
183
+ DO NOT USE THIS TOOL FOR ANY OTHER PURPOSE. IT IS ONLY FOR WIX CLI COMMANDS.`, {
184
+ appPath: z
185
+ .string()
186
+ .describe('The full path to the Wix CLI app to run the command on'),
187
+ extensionType: z
188
+ .enum([
189
+ 'dashboard-page',
190
+ 'dashboard-plugin',
191
+ 'dashboard-menu-plugin',
192
+ 'dashboard-modal',
193
+ 'web-method',
194
+ 'api-route',
195
+ 'event',
196
+ 'service-plugin'
197
+ ])
198
+ .optional()
199
+ .describe('The type of extension to generate. You MUST provide this for commands that generate extensions.'),
200
+ extensionName: z
201
+ .string()
202
+ .optional()
203
+ .describe('The name of the extension to generate, e.g. My Dashboard Page. You MUST provide this for commands that generate extensions.'),
204
+ searchedDocs: z
205
+ .boolean()
206
+ .describe('Whether you have already searched the Wix documentation for the command you want to run.'),
207
+ command: z
208
+ .string()
209
+ .min(1, 'Command cannot be empty')
210
+ .max(1000, 'Command is too long')
211
+ .describe("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.).")
212
+ }, async ({ command, appPath, extensionType, extensionName }) => {
213
+ logger.log(`RunWixCliCommand: command: ${command}, appPath: ${appPath}, extensionType: ${extensionType}, extensionName: ${extensionName}`);
214
+ let commandName = '';
215
+ let commandArgs = [];
216
+ if (command.includes('generate')) {
217
+ if (!extensionType) {
218
+ return {
219
+ content: [
220
+ {
221
+ type: 'text',
222
+ text: "Error: You must provide an extension type for the 'generate' command."
223
+ }
224
+ ],
225
+ isError: true
226
+ };
227
+ }
228
+ if (!extensionName) {
229
+ return {
230
+ content: [
231
+ {
232
+ type: 'text',
233
+ text: "Error: You must provide an extension name for the 'generate' command."
234
+ }
235
+ ],
236
+ isError: true
237
+ };
238
+ }
239
+ // Format generate command with proper arguments
240
+ commandName = 'npx';
241
+ commandArgs = [
242
+ 'wix',
243
+ 'app',
244
+ 'generate',
245
+ '-t',
246
+ extensionType,
247
+ '-n',
248
+ extensionName,
249
+ '--json'
250
+ ];
251
+ }
252
+ else {
253
+ const commandParts = command.split(' ');
254
+ commandName = commandParts[0];
255
+ commandArgs = commandParts.slice(1);
256
+ }
257
+ try {
258
+ logger.log(`Executing Wix CLI command: ${commandName} ${commandArgs.join(' ')}`);
259
+ // Execute with timeout
260
+ const { stdout, stderr, exitCode } = await execa(commandName, commandArgs, {
261
+ cwd: appPath,
262
+ extendEnv: true,
263
+ env: {
264
+ ...process.env
265
+ },
266
+ timeout: 5 * 60 * 1000, // 5 minute timeout
267
+ maxBuffer: 10 * 1024 * 1024 // 10MB output limit
268
+ });
269
+ if (exitCode !== 0) {
270
+ return {
271
+ content: [{ type: 'text', text: `Error: ${stderr}` }],
272
+ isError: true
273
+ };
274
+ }
275
+ logger.log(`RunWixCliCommand: stdout: ${stdout}`);
276
+ logger.log(`RunWixCliCommand: stderr: ${stderr}`);
277
+ return {
278
+ content: [
279
+ { type: 'text', text: stdout },
280
+ ...(stderr
281
+ ? [{ type: 'text', text: `Error: ${stderr}` }]
282
+ : [])
283
+ ]
284
+ };
285
+ }
286
+ catch (error) {
287
+ logger.error(`Error executing Wix CLI command: ${error}`);
288
+ return {
289
+ content: [{ type: 'text', text: `Error: ${error}` }],
290
+ isError: true
291
+ };
292
+ }
293
+ });
294
+ }
295
+ }
@@ -0,0 +1,31 @@
1
+ import { readFileSync } from 'fs';
2
+ import { homedir } from 'os';
3
+ import path from 'path';
4
+ export function getCliAuthTokenForSiteId(siteIdOrAccountsFileName) {
5
+ const authData = JSON.parse(readFileSync(path.join(homedir(), `.wix/auth/${siteIdOrAccountsFileName}.json`), 'utf8'));
6
+ return authData.accessToken;
7
+ }
8
+ // f"first get the site id - its in the `{backoffice_app_dir}/.wix/app.config.json` file, it has a json object with a siteId field",
9
+ export function getSiteIdFromCliAppConfig(appPath) {
10
+ const appConfig = JSON.parse(readFileSync(path.join(appPath, '.wix/app.config.json'), 'utf8'));
11
+ return appConfig.siteId;
12
+ }
13
+ const safeParseJSON = (text) => {
14
+ try {
15
+ return JSON.parse(text);
16
+ }
17
+ catch {
18
+ return text;
19
+ }
20
+ };
21
+ export const handleWixAPIResponse = async (response) => {
22
+ const responseText = await response.text();
23
+ const responseData = safeParseJSON(responseText);
24
+ if (!response.ok) {
25
+ const errorDetails = typeof responseData === 'object'
26
+ ? JSON.stringify(responseData)
27
+ : responseData;
28
+ throw new Error(`Failed to call Wix API: ${response.status} ${response.statusText}. ${errorDetails}`);
29
+ }
30
+ return responseData;
31
+ };