@wix/mcp 1.0.7 → 1.0.8

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.
Files changed (46) hide show
  1. package/build/api-call/index.d.ts +2 -1
  2. package/build/api-call/index.js +149 -0
  3. package/build/auth/index.d.ts +5 -0
  4. package/build/bin-standalone.js +16370 -0
  5. package/build/bin-standalone.js.map +7 -0
  6. package/build/bin.d.ts +1 -1
  7. package/build/bin.js +82 -665
  8. package/build/cli-tools/cli.d.ts +2 -2
  9. package/build/cli-tools/cli.js +339 -0
  10. package/build/cli-tools/utils.js +25 -0
  11. package/build/docs/docs.js +447 -0
  12. package/build/docs/long-content.js +1 -0
  13. package/build/docs/semanticSearch.js +108 -0
  14. package/build/docs/semanticSearch.test.js +459 -0
  15. package/build/index-standalone.js +18849 -0
  16. package/build/index-standalone.js.map +7 -0
  17. package/build/index.d.ts +1 -0
  18. package/build/index.js +6 -201
  19. package/build/infra/bi-logger.d.ts +2 -0
  20. package/build/infra/bi-logger.js +10 -0
  21. package/build/infra/environment.d.ts +9 -0
  22. package/build/infra/environment.js +27 -0
  23. package/build/infra/logger.js +61 -0
  24. package/build/infra/panorama.d.ts +7 -0
  25. package/build/infra/panorama.js +35 -0
  26. package/build/infra/sentry.d.ts +1 -0
  27. package/build/infra/sentry.js +10 -0
  28. package/build/interactive-command-tools/eventually.js +15 -0
  29. package/build/interactive-command-tools/handleStdout.js +75 -0
  30. package/build/interactive-command-tools/interactive-command-utils.js +75 -0
  31. package/build/resources/docs.js +45 -0
  32. package/build/support/index.js +32 -0
  33. package/build/tool-utils.d.ts +2 -1
  34. package/build/tool-utils.js +30 -0
  35. package/build/tool-utils.spec.js +99 -0
  36. package/build/wix-mcp-server.d.ts +12 -1
  37. package/build/wix-mcp-server.js +114 -0
  38. package/package.json +15 -10
  39. package/bin.js +0 -2
  40. package/build/bin.js.map +0 -7
  41. package/build/chunk-QGIZNLF4.js +0 -8179
  42. package/build/chunk-QGIZNLF4.js.map +0 -7
  43. package/build/index.js.map +0 -7
  44. package/build/panorama.d.ts +0 -2
  45. /package/build/{sentry.d.ts → auth/index.js} +0 -0
  46. /package/build/{logger.d.ts → infra/logger.d.ts} +0 -0
package/build/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export { addApiCallTool } from './api-call/index.js';
4
4
  export { handleWixAPIResponse } from './tool-utils.js';
5
5
  export { addDocsResources } from './resources/docs.js';
6
6
  export { addSupportTool } from './support/index.js';
7
+ export { McpAuthenticationStrategy, McpHeaders } from './auth/index.js';
package/build/index.js CHANGED
@@ -1,201 +1,6 @@
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);
6
- }
7
-
8
- import {
9
- VALID_DOCS_TOOLS,
10
- WixMcpServer,
11
- addDocsResources,
12
- addDocsTools,
13
- handleWixAPIResponse,
14
- logger
15
- } from "./chunk-QGIZNLF4.js";
16
-
17
- // src/api-call/index.ts
18
- import { z } from "zod";
19
- function addApiCallTool(server, getSiteAccessToken, getAccountAccessToken) {
20
- server.tool(
21
- "CallWixSiteAPI",
22
- [
23
- "Call Wix apis on a business or site. Use this to create, read, update, and delete data and other Wix entities in your Wix site,",
24
- `You should ALWAYS check the rest docs - "SearchWixRESTDocumentation" for the specific API you want to call, don't just call it without knowing what it does, CHECK THE DOCS`,
25
- "Error Handling:",
26
- 'If the error is related to missing installed app or "WDE0110: Wix Code not enabled", you should install the missing app by using ReadFullDocsArticle tool to fetch the article - https://dev.wix.com/docs/kb-only/MCP_REST_RECIPES_KB_ID/TRAIN_wix.devcenter.apps.installer.v1.AppsInstallerService.InstallApp',
27
- "**Note:** there is no need to check if an app is installed/ Wix Code enabled in advance, just call the API and handle the error if it occurs, the API error message will state it clearly.",
28
- "For any other error, use your default error handling mechanism"
29
- ].join("\n"),
30
- {
31
- siteId: z.string().describe("The id of the site selected using site selection tool"),
32
- url: z.string().describe(
33
- "The url of the api to call - ALWAYS get the information from the Wix REST docs or from the conversation context, the URL MUST BE ABSOLUTE URL"
34
- ),
35
- method: z.string().describe(
36
- "The HTTP method to use for the API call (e.g. GET, POST, PUT, DELETE)"
37
- ),
38
- body: z.string().optional().describe(
39
- "A string representing of a valid JSON object to describe the body of the request"
40
- )
41
- },
42
- async ({ url, body, method, siteId }) => {
43
- logger.log(
44
- `Calling Wix Site API: ${siteId} ${url}, body: ${JSON.stringify(body)}`
45
- );
46
- const authorization = await getSiteAccessToken(siteId);
47
- try {
48
- const response = await fetch(url, {
49
- method,
50
- headers: {
51
- Authorization: authorization,
52
- ...body ? { "Content-Type": "application/json" } : {}
53
- },
54
- body: method === "GET" ? void 0 : body
55
- });
56
- const responseData = await handleWixAPIResponse(response);
57
- return {
58
- content: [
59
- {
60
- type: "text",
61
- text: `Wix Site API call successful: ${JSON.stringify(responseData)}`
62
- }
63
- ]
64
- };
65
- } catch (error) {
66
- logger.error(`Failed to call Wix Site API: ${error}`);
67
- throw new Error(`Failed to call Wix Site API: ${error}`);
68
- }
69
- }
70
- );
71
- server.tool(
72
- "ListWixSites",
73
- "List Wix sites for the current user",
74
- async () => {
75
- const sitesRes = await fetch(
76
- "https://www.wixapis.com/site-list/v2/sites/query",
77
- {
78
- method: "POST",
79
- headers: {
80
- "Content-Type": "application/json",
81
- Accept: "application/json, text/plain, */*",
82
- Authorization: await getAccountAccessToken()
83
- },
84
- body: JSON.stringify({
85
- query: {
86
- cursorPaging: { limit: 50 }
87
- }
88
- })
89
- }
90
- );
91
- const result = await sitesRes.json().then(
92
- ({ sites }) => sites?.map(({ id, displayName }) => ({
93
- id,
94
- name: displayName
95
- })) ?? []
96
- );
97
- return {
98
- content: [
99
- {
100
- type: "text",
101
- text: JSON.stringify(result)
102
- },
103
- {
104
- type: "text",
105
- text: "if there is more than one site returned, the user should pick one from a list, list the sites (only name) for the user and ask them to pick one"
106
- }
107
- ]
108
- };
109
- }
110
- );
111
- server.tool(
112
- "ManageWixSite",
113
- `Use account level API in order to create a site, update a site and publish site.
114
- ALWAYS use "SearchWixRESTDocumentation" to search for the API you should invoke, NEVER GUESS THE SITE API URL
115
- You should ALWAYS check the rest docs - "SearchWixRESTDocumentation" for the specific API you want to call, don't just call it without knowing what it does, CHECK THE DOCS`,
116
- {
117
- url: z.string().describe(
118
- "The url of the api to call - ALWAYS get the information from the Wix REST docs DONT GUESS IT, the URL MUST BE ABSOLUTE URL"
119
- ),
120
- method: z.string().describe(
121
- "The HTTP method to use for the API call (e.g. GET, POST, PUT, DELETE)"
122
- ),
123
- body: z.string().optional().describe(
124
- "A string representing of a valid JSON object to describe the body of the request"
125
- )
126
- },
127
- async ({ url, body, method }) => {
128
- logger.log(
129
- `Calling Wix Account level API: ${url}, body: ${JSON.stringify(body)}`
130
- );
131
- const authorization = await getAccountAccessToken();
132
- try {
133
- const response = await fetch(url, {
134
- method,
135
- headers: {
136
- Authorization: authorization,
137
- ...body ? { "Content-Type": "application/json" } : {}
138
- },
139
- body: method === "GET" ? void 0 : body
140
- });
141
- const responseData = await handleWixAPIResponse(response);
142
- return {
143
- content: [
144
- {
145
- type: "text",
146
- text: `Wix Account API call successful: ${JSON.stringify(responseData)}`
147
- }
148
- ]
149
- };
150
- } catch (error) {
151
- logger.error(`Failed to call Wix Account API: ${error}`);
152
- throw new Error(`Failed to call Wix Account API: ${error}`);
153
- }
154
- }
155
- );
156
- }
157
-
158
- // src/support/index.ts
159
- import { z as z2 } from "zod";
160
- function addSupportTool(server) {
161
- server.tool(
162
- "SupportAndFeedback",
163
- [
164
- "If the user would like to provide Wix with some feedback (good or bad), about the tools in Wix MCP,",
165
- "for example they used the tools provided, and they reflected satisfaction or dissatisfaction with the tools.",
166
- "Also, if you encounter too many errors tyring to call the Wix API, you can also suggest the user to provide feedback to Wix using this tool.",
167
- "**IMPORTANT NOTE**",
168
- "This tool is not sending the message, but formats it in order to another tool to actually send it"
169
- ].join("\n"),
170
- {
171
- requestId: z2.string().optional().describe(
172
- "request id if returned from the server in a failed API call to Wix"
173
- ),
174
- message: z2.string().describe("The message to send to Wix")
175
- },
176
- async ({ requestId, message }) => {
177
- return {
178
- content: [
179
- {
180
- type: "text",
181
- text: `${message} ${requestId ? `request id: ${requestId}` : ""}`
182
- },
183
- {
184
- type: "text",
185
- text: "You should present the user with the formatted message above and ask if they would like to send it to Wix.If the user confirms, you can get the details about send feedback API from the article `https://dev.wix.com/docs/kb-only/MCP_REST_RECIPES_KB_ID/TRAIN_send_mcp_feedback_to_wix_from_user`.You can use the `ReadFullDocsArticle` tool to fetch the article and get the details about the API call.Once you have the details, you can use the `ManageWixSite` (if site id is in context) or `CallWixSiteAPI` (if site id is not in context) tool to call the API and send the feedback to Wix."
186
- }
187
- ]
188
- };
189
- }
190
- );
191
- }
192
- export {
193
- VALID_DOCS_TOOLS,
194
- WixMcpServer,
195
- addApiCallTool,
196
- addDocsResources,
197
- addDocsTools,
198
- addSupportTool,
199
- handleWixAPIResponse
200
- };
201
- //# sourceMappingURL=index.js.map
1
+ export { WixMcpServer } from './wix-mcp-server.js';
2
+ export { addDocsTools, VALID_DOCS_TOOLS } from './docs/docs.js';
3
+ export { addApiCallTool } from './api-call/index.js';
4
+ export { handleWixAPIResponse } from './tool-utils.js';
5
+ export { addDocsResources } from './resources/docs.js';
6
+ export { addSupportTool } from './support/index.js';
@@ -0,0 +1,2 @@
1
+ import type { BiEvent, BiLogger } from '@wix/wix-bi-logger-client';
2
+ export declare function createBiLogger(defaultFields?: BiEvent): BiLogger;
@@ -0,0 +1,10 @@
1
+ import { StandaloneNodeLogger } from '@wix/standalone-node-bi-logger';
2
+ export function createBiLogger(defaultFields) {
3
+ return new StandaloneNodeLogger()
4
+ .factory({})
5
+ .updateDefaults({
6
+ localTime: () => Date.now(),
7
+ ...defaultFields
8
+ })
9
+ .logger();
10
+ }
@@ -0,0 +1,9 @@
1
+ export declare enum ENV {
2
+ DEV = "DEV",
3
+ TEST = "TEST",
4
+ LOCAL = "LOCAL",
5
+ REMOTE = "REMOTE",
6
+ PICASSO = "PICASSO"
7
+ }
8
+ export declare const DEV_ENVIRONMENTS: ENV[];
9
+ export declare function getEnvironment(nodeEnv?: string): ENV;
@@ -0,0 +1,27 @@
1
+ export var ENV;
2
+ (function (ENV) {
3
+ ENV["DEV"] = "DEV";
4
+ ENV["TEST"] = "TEST";
5
+ ENV["LOCAL"] = "LOCAL";
6
+ ENV["REMOTE"] = "REMOTE";
7
+ ENV["PICASSO"] = "PICASSO";
8
+ })(ENV || (ENV = {}));
9
+ const DEFAULT_ENV = ENV.LOCAL;
10
+ export const DEV_ENVIRONMENTS = [ENV.DEV, ENV.TEST];
11
+ export function getEnvironment(nodeEnv) {
12
+ const env = nodeEnv || process.env.NODE_ENV;
13
+ switch (env?.toUpperCase()) {
14
+ case 'DEV':
15
+ return ENV.DEV;
16
+ case 'TEST':
17
+ return ENV.TEST;
18
+ case 'LOCAL':
19
+ return ENV.LOCAL;
20
+ case 'REMOTE':
21
+ return ENV.REMOTE;
22
+ case 'PICASSO':
23
+ return ENV.PICASSO;
24
+ default:
25
+ return DEFAULT_ENV;
26
+ }
27
+ }
@@ -0,0 +1,61 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import { homedir } from 'os';
4
+ const createNullLogger = () => {
5
+ return {
6
+ log: () => { },
7
+ error: () => { }
8
+ };
9
+ };
10
+ const createStdErrLogger = () => {
11
+ return {
12
+ log: (data) => {
13
+ console.error(data);
14
+ },
15
+ error: (data) => {
16
+ console.error(data);
17
+ }
18
+ };
19
+ };
20
+ const createMcpServerLogger = (server) => {
21
+ return {
22
+ log: (data) => {
23
+ server.server.sendLoggingMessage({ level: 'info', data });
24
+ },
25
+ error: (data) => {
26
+ server.server.sendLoggingMessage({ level: 'error', data });
27
+ }
28
+ };
29
+ };
30
+ const createFileLogger = () => {
31
+ const filePath = path.join(homedir(), 'wix-mcp-log.txt');
32
+ const date = new Date()
33
+ .toLocaleString('en-US', { timeZone: 'Asia/Jerusalem' })
34
+ .replace(/,/g, '');
35
+ return {
36
+ log: (...data) => {
37
+ const message = `[info] ${date} - ${data.join(' ')}`;
38
+ fs.appendFile(filePath, `${message}\n`);
39
+ },
40
+ error: (...data) => {
41
+ const message = `[error] ${date} - ${data.join(' ')}`;
42
+ fs.appendFile(filePath, `${message}\n`);
43
+ }
44
+ };
45
+ };
46
+ export const logger = createNullLogger();
47
+ export const attachMcpServerLogger = (server) => {
48
+ const mcpLogger = createMcpServerLogger(server);
49
+ logger.log = mcpLogger.log;
50
+ logger.error = mcpLogger.error;
51
+ };
52
+ export const attachStdErrLogger = () => {
53
+ const stdErrLogger = createStdErrLogger();
54
+ logger.log = stdErrLogger.log;
55
+ logger.error = stdErrLogger.error;
56
+ };
57
+ export const attachFileLogger = () => {
58
+ const fileLogger = createFileLogger();
59
+ logger.log = fileLogger.log;
60
+ logger.error = fileLogger.error;
61
+ };
@@ -0,0 +1,7 @@
1
+ import type { ENV } from './environment.js';
2
+ export declare const createPanoramaClient: (opts: {
3
+ environment: ENV;
4
+ sessionId: string;
5
+ componentId: string;
6
+ uuid?: string;
7
+ }) => import("@wix/panorama-client-node").PanoramaClient;
@@ -0,0 +1,35 @@
1
+ // import { createRequire } from 'module';
2
+ import { createGlobalConfig, panoramaClientFactory, PanoramaPlatform } from '@wix/panorama-client-node';
3
+ // const require = createRequire(import.meta.url);
4
+ // const packageJson = require('../package.json');
5
+ // TODO: use real package.json
6
+ // I temporarily disabled this because it's not working in the remote server
7
+ const packageJson = {
8
+ version: '1.0.0'
9
+ };
10
+ export const createPanoramaClient = (opts) => {
11
+ const globalPanoramaConfig = createGlobalConfig();
12
+ globalPanoramaConfig.setSessionId(opts.sessionId);
13
+ const panoramaFactory = panoramaClientFactory({
14
+ reporterOptions: {
15
+ silent: true
16
+ },
17
+ baseParams: {
18
+ uuid: opts.uuid,
19
+ componentId: opts.componentId,
20
+ platform: PanoramaPlatform.Standalone,
21
+ fullArtifactId: 'com.wixpress.spartans.wix-mcp',
22
+ artifactVersion: packageJson.version
23
+ },
24
+ data: {
25
+ environment: opts.environment,
26
+ runtime: {
27
+ packageVersion: packageJson.version,
28
+ versions: process.versions,
29
+ platform: process.platform,
30
+ arch: process.arch
31
+ }
32
+ }
33
+ }).withGlobalConfig(globalPanoramaConfig);
34
+ return panoramaFactory.client();
35
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import * as Sentry from '@sentry/node';
2
+ Sentry.init({
3
+ dsn: 'https://583c5af58c664fd1977d638a693b0ada@sentry-next.wixpress.com/20924',
4
+ tracesSampleRate: 1.0,
5
+ initialScope: {
6
+ tags: {
7
+ fullArtifactId: 'com.wixpress.spartans.wix-mcp'
8
+ }
9
+ }
10
+ });
@@ -0,0 +1,15 @@
1
+ import waitForExpect from 'wait-for-expect';
2
+ const defaultOptions = {
3
+ timeout: 10000,
4
+ interval: 200
5
+ };
6
+ export default async function eventually(expectation, options) {
7
+ return new Promise((resolve, reject) => {
8
+ waitForExpect
9
+ .default(async () => {
10
+ const ret = await expectation();
11
+ resolve(ret);
12
+ }, options?.timeout ?? defaultOptions.timeout, options?.interval ?? defaultOptions.interval)
13
+ .catch((error) => reject(error));
14
+ });
15
+ }
@@ -0,0 +1,75 @@
1
+ import stripAnsi from 'strip-ansi';
2
+ import eventually from './eventually.js';
3
+ import { logger } from '../infra/logger.js';
4
+ export function handleStdout(stdout) {
5
+ let checkStartIndex = 0;
6
+ const lines = [];
7
+ logger.log(`handleStdout: stdout: ${stdout}`);
8
+ stdout.on('data', (chunk) => {
9
+ logger.log(`handleStdout: chunk: ${chunk}`);
10
+ // log(`create-cli: chunk: ${chunk}`);
11
+ lines.push(...stripAnsi(chunk.toString()).split('\n'));
12
+ });
13
+ return {
14
+ async waitForText(match, { timeout = 2 * 60 * 1000 } = {}) {
15
+ return eventually(() => {
16
+ const matchedIndex = lines.findIndex((line, index) => {
17
+ if (index < checkStartIndex) {
18
+ return false;
19
+ }
20
+ if (typeof match === 'string') {
21
+ return line.includes(match);
22
+ }
23
+ return line.match(match);
24
+ });
25
+ checkStartIndex = matchedIndex >= 0 ? matchedIndex + 1 : lines.length;
26
+ if (matchedIndex !== -1) {
27
+ return lines[matchedIndex];
28
+ }
29
+ const message = `Could not match text in output: ${match}`;
30
+ throw new Error(message);
31
+ }, { timeout });
32
+ },
33
+ async waitForAndCallback(matchesAndCallbacks, { timeout = 2 * 60 * 1000 } = {}) {
34
+ let stopResolve;
35
+ const stopPromise = new Promise((resolve) => {
36
+ stopResolve = resolve;
37
+ });
38
+ // Keep track of matches we've already processed
39
+ const processedMatches = new Set();
40
+ const waitPromise = eventually(() => {
41
+ //log(`create-cli: waiting for ${matchesAndCallbacks.length - processedMatches.size} matches`);
42
+ for (const { match, callback } of matchesAndCallbacks) {
43
+ // Skip if we've already processed this match
44
+ if (processedMatches.has(match)) {
45
+ continue;
46
+ }
47
+ if (lines.some((line) => line.includes(match))) {
48
+ logger.log(`create-cli: found match ${match}`);
49
+ // Add to processed matches so we don't match it again
50
+ processedMatches.add(match);
51
+ callback(() => {
52
+ logger.log(`create-cli: stopping match loop`);
53
+ stopResolve();
54
+ });
55
+ }
56
+ else {
57
+ // log(`create-cli: waiting for ${match}`);
58
+ }
59
+ }
60
+ // If we've processed all matches, we're done
61
+ if (processedMatches.size === matchesAndCallbacks.length) {
62
+ return true;
63
+ }
64
+ throw new Error(`Could not find any of the remaining matches: ${matchesAndCallbacks
65
+ .filter((m) => !processedMatches.has(m.match))
66
+ .map((m) => m.match)
67
+ .join(', ')}`);
68
+ }, { timeout });
69
+ return Promise.race([waitPromise, stopPromise]);
70
+ },
71
+ async getOutput() {
72
+ return lines.join('\n');
73
+ }
74
+ };
75
+ }
@@ -0,0 +1,75 @@
1
+ import { handleStdout } from './handleStdout.js';
2
+ import { logger } from '../infra/logger.js';
3
+ export const ENTER = '\r';
4
+ const DOWN = '\u001b[B';
5
+ export const mockInteractiveGenerateCommandTool = async ({ extensionType, stdin, stdout }) => {
6
+ try {
7
+ logger.log('RunWixCliCommand: handle stdout');
8
+ const stdoutHandler = handleStdout(stdout);
9
+ logger.log('RunWixCliCommand: waiting for text');
10
+ await stdoutHandler.waitForText('What kind of extension would you like to generate?');
11
+ // Enter the extension type
12
+ if (extensionType === 'DASHBOARD_PAGE') {
13
+ // No need to press enter
14
+ }
15
+ else if (extensionType === 'BACKEND_EVENT') {
16
+ logger.log('RunWixCliCommand: writing DOWN 9 times');
17
+ for (let i = 0; i < 9; i++) {
18
+ stdin.write(DOWN);
19
+ await new Promise((resolve) => setTimeout(resolve, 10));
20
+ }
21
+ }
22
+ logger.log('RunWixCliCommand: writing ENTER 1');
23
+ stdin.write(ENTER);
24
+ // Wait for next step
25
+ if (extensionType === 'DASHBOARD_PAGE') {
26
+ await stdoutHandler.waitForText('Page title');
27
+ logger.log('RunWixCliCommand: writing ENTER 2');
28
+ stdin.write(ENTER);
29
+ await stdoutHandler.waitForText('Enter the route for the new page');
30
+ logger.log('RunWixCliCommand: writing ENTER 3');
31
+ stdin.write(ENTER);
32
+ }
33
+ else if (extensionType === 'BACKEND_EVENT') {
34
+ await stdoutHandler.waitForText('Event folder');
35
+ logger.log('RunWixCliCommand: writing ENTER 2');
36
+ stdin.write(ENTER);
37
+ logger.log('RunWixCliCommand: waiting for text');
38
+ // Check if the text is "Would you like to install dependencies now?", if dependencies are already installed, it will not be printed
39
+ try {
40
+ await stdoutHandler.waitForText('Would you like to install dependencies now?', { timeout: 1000 });
41
+ logger.log('RunWixCliCommand: writing ENTER 3');
42
+ stdin.write(ENTER);
43
+ }
44
+ catch (error) {
45
+ if (error instanceof Error &&
46
+ error.message.includes('Could not match text in output')) {
47
+ logger.log('RunWixCliCommand: dependencies are already installed, skipping install');
48
+ logger.log(await stdoutHandler.getOutput());
49
+ }
50
+ else {
51
+ throw error;
52
+ }
53
+ }
54
+ }
55
+ logger.log('RunWixCliCommand: waiting for success message');
56
+ try {
57
+ await stdoutHandler.waitForText('Successfully', { timeout: 1000 });
58
+ logger.log('RunWixCliCommand: success message found');
59
+ }
60
+ catch (error) {
61
+ if (error instanceof Error &&
62
+ error.message.includes('Could not match text in output')) {
63
+ logger.log('RunWixCliCommand: success message not found, skipping'); // just skip and try to continue by returning the output
64
+ }
65
+ else {
66
+ throw error;
67
+ }
68
+ }
69
+ return stdoutHandler.getOutput();
70
+ }
71
+ catch (error) {
72
+ logger.error('RunWixCliCommand: error', error);
73
+ throw error;
74
+ }
75
+ };
@@ -0,0 +1,45 @@
1
+ import { logger } from '../infra/logger.js';
2
+ const getPortalIndex = async (portalName) => {
3
+ const response = await fetch(`https://dev.wix.com/digor/api/portal-index?portalName=${portalName}`);
4
+ const data = await response.json();
5
+ return data;
6
+ };
7
+ const addPortalResources = async (server, portalName) => {
8
+ // get portal index:
9
+ const portalIndexResponse = await getPortalIndex(portalName);
10
+ logger.log(`portalIndexResponse for ${portalName}`, JSON.stringify(portalIndexResponse, null, 2));
11
+ // for each portalIndex entry, add a resource to the server:
12
+ for (const entry of portalIndexResponse.portalIndex) {
13
+ logger.log(`entry ${JSON.stringify(entry, null, 2)}`);
14
+ const name = entry.url;
15
+ const uri = entry.url.replace('https://dev.wix.com/docs/', 'wix-docs://');
16
+ logger.log(`adding resource ${name} ${uri}`);
17
+ server.resource(name, uri, async (uri) => {
18
+ logger.log(`fetching resource ${uri}`);
19
+ const docsURL = uri
20
+ .toString()
21
+ .replace('wix-docs://', 'https://dev.wix.com/docs/');
22
+ const response = await fetch(`https://dev.wix.com/digor/api/get-article-content?articleUrl=${encodeURIComponent(docsURL)}`);
23
+ const data = await response.json();
24
+ return {
25
+ contents: [
26
+ {
27
+ uri: uri.href,
28
+ text: data.articleContent || 'No content found'
29
+ }
30
+ ]
31
+ };
32
+ });
33
+ }
34
+ };
35
+ export const addDocsResources = async (server, portals) => {
36
+ for (const portal of portals) {
37
+ try {
38
+ logger.log(`Processing portal: ${portal}`);
39
+ await addPortalResources(server, portal);
40
+ }
41
+ catch (error) {
42
+ logger.error(`Error processing portal ${portal}:`, error);
43
+ }
44
+ }
45
+ };
@@ -0,0 +1,32 @@
1
+ import { z } from 'zod';
2
+ export function addSupportTool(server) {
3
+ server.tool('SupportAndFeedback', [
4
+ 'If the user would like to provide Wix with some feedback (good or bad), about the tools in Wix MCP,',
5
+ 'for example they used the tools provided, and they reflected satisfaction or dissatisfaction with the tools.',
6
+ 'Also, if you encounter too many errors tyring to call the Wix API, you can also suggest the user to provide feedback to Wix using this tool.',
7
+ '**IMPORTANT NOTE**',
8
+ 'This tool is not sending the message, but formats it in order to another tool to actually send it'
9
+ ].join('\n'), {
10
+ requestId: z
11
+ .string()
12
+ .optional()
13
+ .describe('request id if returned from the server in a failed API call to Wix'),
14
+ message: z.string().describe('The message to send to Wix')
15
+ }, async ({ requestId, message }) => {
16
+ return {
17
+ content: [
18
+ {
19
+ type: 'text',
20
+ text: `${message} ${requestId ? `request id: ${requestId}` : ''}`
21
+ },
22
+ {
23
+ type: 'text',
24
+ text: 'You should present the user with the formatted message above and ask if they would like to send it to Wix.' +
25
+ 'If the user confirms, you can get the details about send feedback API from the article `https://dev.wix.com/docs/kb-only/MCP_REST_RECIPES_KB_ID/TRAIN_send_mcp_feedback_to_wix_from_user`.' +
26
+ 'You can use the `ReadFullDocsArticle` tool to fetch the article and get the details about the API call.' +
27
+ 'Once you have the details, you can use the `ManageWixSite` (if site id is in context) or `CallWixSiteAPI` (if site id is not in context) tool to call the API and send the feedback to Wix.'
28
+ }
29
+ ]
30
+ };
31
+ });
32
+ }
@@ -1 +1,2 @@
1
- export declare const handleWixAPIResponse: <T = any>(response: Response) => Promise<T>;
1
+ import type { HttpResponse } from '@wix/http-client';
2
+ export declare const handleWixAPIResponse: <T = any>(response: HttpResponse<any>) => Promise<T>;
@@ -0,0 +1,30 @@
1
+ const safeParseJSON = (text) => {
2
+ try {
3
+ return JSON.parse(text);
4
+ }
5
+ catch {
6
+ return text;
7
+ }
8
+ };
9
+ export const handleWixAPIResponse = async (response) => {
10
+ const responseData = typeof response.data === 'string'
11
+ ? safeParseJSON(response.data)
12
+ : response.data;
13
+ if (!response.status.toString().startsWith('2')) {
14
+ const requestId = response.headers.get('x-wix-request-id');
15
+ const errorDetails = typeof responseData === 'object'
16
+ ? JSON.stringify(responseData)
17
+ : responseData;
18
+ throw new Error([
19
+ `Failed to call Wix API: ${response.status} ${response.statusText}.`,
20
+ requestId ? `request id: ${requestId}` : '',
21
+ // Wix 404 for API does not exist is huge (generic 404 page) and loaded to the context
22
+ response.status === 404 && errorDetails.includes('<html')
23
+ ? 'Not found'
24
+ : errorDetails
25
+ ]
26
+ .filter((str) => !!str)
27
+ .join('\n'));
28
+ }
29
+ return responseData;
30
+ };