@wix/mcp 1.0.6 → 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 (53) hide show
  1. package/build/api-call/index.d.ts +3 -0
  2. package/build/api-call/index.js +149 -0
  3. package/build/auth/index.d.ts +5 -0
  4. package/build/auth/index.js +1 -0
  5. package/build/bin-standalone.js +16370 -0
  6. package/build/bin-standalone.js.map +7 -0
  7. package/build/bin.d.ts +3 -3
  8. package/build/bin.js +82 -657
  9. package/build/cli-tools/cli.d.ts +4 -0
  10. package/build/cli-tools/cli.js +339 -0
  11. package/build/cli-tools/utils.d.ts +2 -0
  12. package/build/cli-tools/utils.js +25 -0
  13. package/build/docs/docs.d.ts +4 -0
  14. package/build/docs/docs.js +447 -0
  15. package/build/docs/long-content.d.ts +1 -0
  16. package/build/docs/long-content.js +1 -0
  17. package/build/docs/semanticSearch.d.ts +10 -0
  18. package/build/docs/semanticSearch.js +108 -0
  19. package/build/docs/semanticSearch.test.d.ts +1 -0
  20. package/build/docs/semanticSearch.test.js +459 -0
  21. package/build/index-standalone.js +18849 -0
  22. package/build/index-standalone.js.map +7 -0
  23. package/build/index.d.ts +7 -30
  24. package/build/index.js +6 -193
  25. package/build/infra/bi-logger.d.ts +2 -0
  26. package/build/infra/bi-logger.js +10 -0
  27. package/build/infra/environment.d.ts +9 -0
  28. package/build/infra/environment.js +27 -0
  29. package/build/infra/logger.d.ts +10 -0
  30. package/build/infra/logger.js +61 -0
  31. package/build/infra/panorama.d.ts +7 -0
  32. package/build/infra/panorama.js +35 -0
  33. package/build/infra/sentry.d.ts +1 -0
  34. package/build/infra/sentry.js +10 -0
  35. package/build/interactive-command-tools/eventually.d.ts +6 -0
  36. package/build/interactive-command-tools/eventually.js +15 -0
  37. package/build/interactive-command-tools/handleStdout.d.ts +13 -0
  38. package/build/interactive-command-tools/handleStdout.js +75 -0
  39. package/build/interactive-command-tools/interactive-command-utils.d.ts +7 -0
  40. package/build/interactive-command-tools/interactive-command-utils.js +75 -0
  41. package/build/resources/docs.d.ts +2 -0
  42. package/build/resources/docs.js +45 -0
  43. package/build/support/index.d.ts +2 -0
  44. package/build/support/index.js +32 -0
  45. package/build/tool-utils.d.ts +2 -0
  46. package/build/tool-utils.js +30 -0
  47. package/build/tool-utils.spec.d.ts +1 -0
  48. package/build/tool-utils.spec.js +99 -0
  49. package/build/wix-mcp-server.d.ts +27 -0
  50. package/build/wix-mcp-server.js +114 -0
  51. package/package.json +16 -11
  52. package/bin.js +0 -2
  53. package/build/chunk-YRLMZUQM.js +0 -1834
package/build/index.d.ts CHANGED
@@ -1,30 +1,7 @@
1
- import { ZodRawShape, z, ZodTypeAny } from 'zod';
2
- import { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
- import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
4
- import { PanoramaClientForComponent } from '@wix/panorama-client-node';
5
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
6
-
7
- type WixRequestHandlerExtra = RequestHandlerExtra & {
8
- panorama: PanoramaClientForComponent;
9
- };
10
- type WixToolCallback<Args extends undefined | ZodRawShape = undefined> = Args extends ZodRawShape ? (args: z.objectOutputType<Args, ZodTypeAny>, extra: WixRequestHandlerExtra) => CallToolResult | Promise<CallToolResult> : (extra: WixRequestHandlerExtra) => CallToolResult | Promise<CallToolResult>;
11
- declare class WixMcpServer extends McpServer {
12
- tool(name: string, cb: WixToolCallback): void;
13
- tool(name: string, description: string, cb: WixToolCallback): void;
14
- tool<Args extends ZodRawShape>(name: string, paramsSchema: Args, cb: WixToolCallback<Args>): void;
15
- tool<Args extends ZodRawShape>(name: string, description: string, paramsSchema: Args, cb: WixToolCallback<Args>): void;
16
- }
17
-
18
- declare const VALID_DOCS_TOOLS: readonly ["WDS", "REST", "SDK", "BUILD_APPS", "WIX_HEADLESS", "BUSINESS_SOLUTIONS"];
19
- type DocsTool = (typeof VALID_DOCS_TOOLS)[number];
20
- declare const addDocsTools: (server: WixMcpServer, allowedTools?: DocsTool[]) => void;
21
-
22
- declare function addApiCallTool(server: WixMcpServer, getSiteAccessToken: (siteId: string) => Promise<string>, getAccountAccessToken: () => Promise<string>): void;
23
-
24
- declare const handleWixAPIResponse: <T = any>(response: Response) => Promise<T>;
25
-
26
- declare const addDocsResources: (server: McpServer, portals: string[]) => Promise<void>;
27
-
28
- declare function addSupportTool(server: WixMcpServer): void;
29
-
30
- export { type DocsTool, VALID_DOCS_TOOLS, WixMcpServer, addApiCallTool, addDocsResources, addDocsTools, addSupportTool, handleWixAPIResponse };
1
+ export { WixMcpServer } from './wix-mcp-server.js';
2
+ export { addDocsTools, DocsTool, 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';
7
+ export { McpAuthenticationStrategy, McpHeaders } from './auth/index.js';
package/build/index.js CHANGED
@@ -1,193 +1,6 @@
1
- import {
2
- VALID_DOCS_TOOLS,
3
- WixMcpServer,
4
- addDocsResources,
5
- addDocsTools,
6
- handleWixAPIResponse,
7
- logger
8
- } from "./chunk-YRLMZUQM.js";
9
-
10
- // src/api-call/index.ts
11
- import { z } from "zod";
12
- function addApiCallTool(server, getSiteAccessToken, getAccountAccessToken) {
13
- server.tool(
14
- "CallWixSiteAPI",
15
- [
16
- "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,",
17
- `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`,
18
- "Error Handling:",
19
- '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',
20
- "**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.",
21
- "For any other error, use your default error handling mechanism"
22
- ].join("\n"),
23
- {
24
- siteId: z.string().describe("The id of the site selected using site selection tool"),
25
- url: z.string().describe(
26
- "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"
27
- ),
28
- method: z.string().describe(
29
- "The HTTP method to use for the API call (e.g. GET, POST, PUT, DELETE)"
30
- ),
31
- body: z.string().optional().describe(
32
- "A string representing of a valid JSON object to describe the body of the request"
33
- )
34
- },
35
- async ({ url, body, method, siteId }) => {
36
- logger.log(
37
- `Calling Wix Site API: ${siteId} ${url}, body: ${JSON.stringify(body)}`
38
- );
39
- const authorization = await getSiteAccessToken(siteId);
40
- try {
41
- const response = await fetch(url, {
42
- method,
43
- headers: {
44
- Authorization: authorization,
45
- ...body ? { "Content-Type": "application/json" } : {}
46
- },
47
- body: method === "GET" ? void 0 : body
48
- });
49
- const responseData = await handleWixAPIResponse(response);
50
- return {
51
- content: [
52
- {
53
- type: "text",
54
- text: `Wix Site API call successful: ${JSON.stringify(responseData)}`
55
- }
56
- ]
57
- };
58
- } catch (error) {
59
- logger.error(`Failed to call Wix Site API: ${error}`);
60
- throw new Error(`Failed to call Wix Site API: ${error}`);
61
- }
62
- }
63
- );
64
- server.tool(
65
- "ListWixSites",
66
- "List Wix sites for the current user",
67
- async () => {
68
- const sitesRes = await fetch(
69
- "https://www.wixapis.com/site-list/v2/sites/query",
70
- {
71
- method: "POST",
72
- headers: {
73
- "Content-Type": "application/json",
74
- Accept: "application/json, text/plain, */*",
75
- Authorization: await getAccountAccessToken()
76
- },
77
- body: JSON.stringify({
78
- query: {
79
- cursorPaging: { limit: 50 }
80
- }
81
- })
82
- }
83
- );
84
- const result = await sitesRes.json().then(
85
- ({ sites }) => sites?.map(({ id, displayName }) => ({
86
- id,
87
- name: displayName
88
- })) ?? []
89
- );
90
- return {
91
- content: [
92
- {
93
- type: "text",
94
- text: JSON.stringify(result)
95
- },
96
- {
97
- type: "text",
98
- 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"
99
- }
100
- ]
101
- };
102
- }
103
- );
104
- server.tool(
105
- "ManageWixSite",
106
- `Use account level API in order to create a site, update a site and publish site.
107
- ALWAYS use "SearchWixRESTDocumentation" to search for the API you should invoke, NEVER GUESS THE SITE API URL
108
- 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`,
109
- {
110
- url: z.string().describe(
111
- "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"
112
- ),
113
- method: z.string().describe(
114
- "The HTTP method to use for the API call (e.g. GET, POST, PUT, DELETE)"
115
- ),
116
- body: z.string().optional().describe(
117
- "A string representing of a valid JSON object to describe the body of the request"
118
- )
119
- },
120
- async ({ url, body, method }) => {
121
- logger.log(
122
- `Calling Wix Account level API: ${url}, body: ${JSON.stringify(body)}`
123
- );
124
- const authorization = await getAccountAccessToken();
125
- try {
126
- const response = await fetch(url, {
127
- method,
128
- headers: {
129
- Authorization: authorization,
130
- ...body ? { "Content-Type": "application/json" } : {}
131
- },
132
- body: method === "GET" ? void 0 : body
133
- });
134
- const responseData = await handleWixAPIResponse(response);
135
- return {
136
- content: [
137
- {
138
- type: "text",
139
- text: `Wix Account API call successful: ${JSON.stringify(responseData)}`
140
- }
141
- ]
142
- };
143
- } catch (error) {
144
- logger.error(`Failed to call Wix Account API: ${error}`);
145
- throw new Error(`Failed to call Wix Account API: ${error}`);
146
- }
147
- }
148
- );
149
- }
150
-
151
- // src/support/index.ts
152
- import { z as z2 } from "zod";
153
- function addSupportTool(server) {
154
- server.tool(
155
- "SupportAndFeedback",
156
- [
157
- "If the user would like to provide Wix with some feedback (good or bad), about the tools in Wix MCP,",
158
- "for example they used the tools provided, and they reflected satisfaction or dissatisfaction with the tools.",
159
- "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.",
160
- "**IMPORTANT NOTE**",
161
- "This tool is not sending the message, but formats it in order to another tool to actually send it"
162
- ].join("\n"),
163
- {
164
- requestId: z2.string().optional().describe(
165
- "request id if returned from the server in a failed API call to Wix"
166
- ),
167
- message: z2.string().describe("The message to send to Wix")
168
- },
169
- async ({ requestId, message }) => {
170
- return {
171
- content: [
172
- {
173
- type: "text",
174
- text: `${message} ${requestId ? `request id: ${requestId}` : ""}`
175
- },
176
- {
177
- type: "text",
178
- 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."
179
- }
180
- ]
181
- };
182
- }
183
- );
184
- }
185
- export {
186
- VALID_DOCS_TOOLS,
187
- WixMcpServer,
188
- addApiCallTool,
189
- addDocsResources,
190
- addDocsTools,
191
- addSupportTool,
192
- handleWixAPIResponse
193
- };
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,10 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ interface Logger {
3
+ log(...data: unknown[]): void;
4
+ error(...data: unknown[]): void;
5
+ }
6
+ export declare const logger: Logger;
7
+ export declare const attachMcpServerLogger: (server: McpServer) => void;
8
+ export declare const attachStdErrLogger: () => void;
9
+ export declare const attachFileLogger: () => void;
10
+ export {};
@@ -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,6 @@
1
+ interface Options {
2
+ timeout?: number;
3
+ interval?: number;
4
+ }
5
+ export default function eventually<ReturnType = void>(expectation: () => ReturnType | Promise<ReturnType>, options?: Options): Promise<ReturnType>;
6
+ export {};
@@ -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,13 @@
1
+ import Stream from 'node:stream';
2
+ export declare function handleStdout(stdout: Stream.Readable): {
3
+ waitForText(match: string | RegExp, { timeout }?: {
4
+ timeout?: number | undefined;
5
+ }): Promise<string | undefined>;
6
+ waitForAndCallback(matchesAndCallbacks: {
7
+ match: string;
8
+ callback: (stop: () => void) => void;
9
+ }[], { timeout }?: {
10
+ timeout?: number | undefined;
11
+ }): Promise<unknown>;
12
+ getOutput(): Promise<string>;
13
+ };
@@ -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,7 @@
1
+ import Stream from 'node:stream';
2
+ export declare const ENTER = "\r";
3
+ export declare const mockInteractiveGenerateCommandTool: ({ extensionType, stdin, stdout }: {
4
+ extensionType: string;
5
+ stdin: Stream.Writable;
6
+ stdout: Stream.Readable;
7
+ }) => Promise<string>;
@@ -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,2 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ export declare const addDocsResources: (server: McpServer, portals: string[]) => Promise<void>;