@wix/mcp 1.0.4 → 1.0.6

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 (41) hide show
  1. package/bin.js +1 -1
  2. package/build/bin.d.ts +3 -3
  3. package/build/bin.js +657 -82
  4. package/build/chunk-YRLMZUQM.js +1834 -0
  5. package/build/index.d.ts +30 -6
  6. package/build/index.js +193 -6
  7. package/package.json +7 -4
  8. package/build/api-call/index.d.ts +0 -2
  9. package/build/api-call/index.js +0 -124
  10. package/build/cli-tools/cli.d.ts +0 -4
  11. package/build/cli-tools/cli.js +0 -337
  12. package/build/cli-tools/utils.d.ts +0 -2
  13. package/build/cli-tools/utils.js +0 -12
  14. package/build/docs/docs.d.ts +0 -4
  15. package/build/docs/docs.js +0 -448
  16. package/build/docs/long-content.d.ts +0 -1
  17. package/build/docs/long-content.js +0 -1
  18. package/build/docs/semanticSearch.d.ts +0 -10
  19. package/build/docs/semanticSearch.js +0 -108
  20. package/build/docs/semanticSearch.test.d.ts +0 -1
  21. package/build/docs/semanticSearch.test.js +0 -459
  22. package/build/interactive-command-tools/eventually.d.ts +0 -6
  23. package/build/interactive-command-tools/eventually.js +0 -15
  24. package/build/interactive-command-tools/handleStdout.d.ts +0 -13
  25. package/build/interactive-command-tools/handleStdout.js +0 -75
  26. package/build/interactive-command-tools/interactive-command-utils.d.ts +0 -7
  27. package/build/interactive-command-tools/interactive-command-utils.js +0 -75
  28. package/build/logger.d.ts +0 -10
  29. package/build/logger.js +0 -61
  30. package/build/resources/docs.d.ts +0 -2
  31. package/build/resources/docs.js +0 -45
  32. package/build/sentry.d.ts +0 -1
  33. package/build/sentry.js +0 -10
  34. package/build/support/index.d.ts +0 -2
  35. package/build/support/index.js +0 -32
  36. package/build/tool-utils.d.ts +0 -1
  37. package/build/tool-utils.js +0 -29
  38. package/build/tool-utils.spec.d.ts +0 -1
  39. package/build/tool-utils.spec.js +0 -119
  40. package/build/wix-mcp-server.d.ts +0 -13
  41. package/build/wix-mcp-server.js +0 -51
package/build/logger.js DELETED
@@ -1,61 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- export declare const addDocsResources: (server: McpServer, portals: string[]) => Promise<void>;
@@ -1,45 +0,0 @@
1
- import { logger } from '../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
- };
package/build/sentry.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/build/sentry.js DELETED
@@ -1,10 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- import { WixMcpServer } from '../wix-mcp-server.js';
2
- export declare function addSupportTool(server: WixMcpServer): void;
@@ -1,32 +0,0 @@
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 +0,0 @@
1
- export declare const handleWixAPIResponse: <T = any>(response: Response) => Promise<T>;
@@ -1,29 +0,0 @@
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 responseText = await response.text();
11
- const responseData = safeParseJSON(responseText);
12
- if (!response.ok) {
13
- const requestId = response.headers.get('x-wix-request-id');
14
- const errorDetails = typeof responseData === 'object'
15
- ? JSON.stringify(responseData)
16
- : responseData;
17
- throw new Error([
18
- `Failed to call Wix API: ${response.status} ${response.statusText}.`,
19
- requestId ? `request id: ${requestId}` : '',
20
- // Wix 404 for API does not exist is huge (generic 404 page) and loaded to the context
21
- response.status === 404 && errorDetails.includes('<html')
22
- ? 'Not found'
23
- : errorDetails
24
- ]
25
- .filter((str) => !!str)
26
- .join('\n'));
27
- }
28
- return responseData;
29
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,119 +0,0 @@
1
- import { handleWixAPIResponse } from './tool-utils.js';
2
- import { expect, test, vi, describe, beforeEach } from 'vitest';
3
- // Mock the global fetch function
4
- global.fetch = vi.fn();
5
- describe('handleWixAPIResponse', () => {
6
- beforeEach(() => {
7
- // Reset the mock before each test
8
- global.fetch.mockClear();
9
- });
10
- describe('safeParseJSON', () => {
11
- test('should parse valid JSON string', async () => {
12
- const jsonString = '{"key": "value", "number": 123}';
13
- global.fetch.mockResolvedValueOnce(new Response(jsonString, { status: 200 }));
14
- const result = await handleWixAPIResponse(new Response(jsonString, { status: 200 }));
15
- expect(result).toEqual({ key: 'value', number: 123 });
16
- });
17
- test('should return the original string if parsing fails', async () => {
18
- const invalidJSONString = 'this is not valid json';
19
- global.fetch.mockResolvedValueOnce(new Response(invalidJSONString, { status: 200 }));
20
- const result = await handleWixAPIResponse(new Response(invalidJSONString, { status: 200 }));
21
- expect(result).toBe(invalidJSONString);
22
- });
23
- test('should return an empty string if the response text is empty', async () => {
24
- global.fetch.mockResolvedValueOnce(new Response('', { status: 200 }));
25
- const result = await handleWixAPIResponse(new Response('', { status: 200 }));
26
- expect(result).toBe('');
27
- });
28
- });
29
- test('should return parsed JSON data for a successful response', async () => {
30
- const mockData = { message: 'Success!' };
31
- global.fetch.mockResolvedValueOnce(new Response(JSON.stringify(mockData), {
32
- status: 200,
33
- statusText: 'OK',
34
- headers: new Headers({ 'Content-Type': 'application/json' })
35
- }));
36
- const response = new Response(JSON.stringify(mockData), {
37
- status: 200,
38
- statusText: 'OK',
39
- headers: new Headers({ 'Content-Type': 'application/json' })
40
- });
41
- const result = await handleWixAPIResponse(response);
42
- expect(result).toEqual(mockData);
43
- });
44
- test('should return the original string if the successful response is not JSON', async () => {
45
- const mockData = 'This is plain text';
46
- global.fetch.mockResolvedValueOnce(new Response(mockData, { status: 200, statusText: 'OK' }));
47
- const response = new Response(mockData, { status: 200, statusText: 'OK' });
48
- const result = await handleWixAPIResponse(response);
49
- expect(result).toBe(mockData);
50
- });
51
- test('should throw an error for a failed response with JSON error details', async () => {
52
- const mockError = { error: 'Something went wrong', code: 500 };
53
- const mockRequestId = 'some-request-id';
54
- global.fetch.mockResolvedValueOnce(new Response(JSON.stringify(mockError), {
55
- status: 500,
56
- statusText: 'Internal Server Error',
57
- headers: new Headers({ 'x-wix-request-id': mockRequestId })
58
- }));
59
- const response = new Response(JSON.stringify(mockError), {
60
- status: 500,
61
- statusText: 'Internal Server Error',
62
- headers: new Headers({ 'x-wix-request-id': mockRequestId })
63
- });
64
- await expect(handleWixAPIResponse(response)).rejects.toThrowError([
65
- 'Failed to call Wix API: 500 Internal Server Error.',
66
- `request id: ${mockRequestId}`,
67
- '{"error":"Something went wrong","code":500}'
68
- ].join('\n'));
69
- });
70
- test('should throw an error for a failed response with non-JSON error details', async () => {
71
- const mockError = 'Internal server error occurred.';
72
- global.fetch.mockResolvedValueOnce(new Response(mockError, {
73
- status: 503,
74
- statusText: 'Service Unavailable'
75
- }));
76
- const response = new Response(mockError, {
77
- status: 503,
78
- statusText: 'Service Unavailable'
79
- });
80
- await expect(handleWixAPIResponse(response)).rejects.toThrowError(['Failed to call Wix API: 503 Service Unavailable.', mockError].join('\n'));
81
- });
82
- test('should include the request ID in the error message if present', async () => {
83
- const mockError = { message: 'Unauthorized' };
84
- const mockRequestId = 'another-id';
85
- global.fetch.mockResolvedValueOnce(new Response(JSON.stringify(mockError), {
86
- status: 401,
87
- statusText: 'Unauthorized',
88
- headers: new Headers({ 'x-wix-request-id': mockRequestId })
89
- }));
90
- const response = new Response(JSON.stringify(mockError), {
91
- status: 401,
92
- statusText: 'Unauthorized',
93
- headers: new Headers({ 'x-wix-request-id': mockRequestId })
94
- });
95
- await expect(handleWixAPIResponse(response)).rejects.toThrowError([
96
- 'Failed to call Wix API: 401 Unauthorized.',
97
- `request id: ${mockRequestId}`,
98
- '{"message":"Unauthorized"}'
99
- ].join('\n'));
100
- });
101
- test('should return "Not found" in the error message for a 404 with HTML content', async () => {
102
- const mockHtmlError = '<html><body><h1>404 Not Found</h1></body></html>';
103
- global.fetch.mockResolvedValueOnce(new Response(mockHtmlError, { status: 404, statusText: 'Not Found' }));
104
- const response = new Response(mockHtmlError, {
105
- status: 404,
106
- statusText: 'Not Found'
107
- });
108
- await expect(handleWixAPIResponse(response)).rejects.toThrowError(['Failed to call Wix API: 404 Not Found.', 'Not found'].join('\n'));
109
- });
110
- test('should include the HTML content in the error message for a 404 without typical HTML structure', async () => {
111
- const mockNonHtmlError = 'Resource not found on the server.';
112
- global.fetch.mockResolvedValueOnce(new Response(mockNonHtmlError, { status: 404, statusText: 'Not Found' }));
113
- const response = new Response(mockNonHtmlError, {
114
- status: 404,
115
- statusText: 'Not Found'
116
- });
117
- await expect(handleWixAPIResponse(response)).rejects.toThrowError(['Failed to call Wix API: 404 Not Found.', mockNonHtmlError].join('\n'));
118
- });
119
- });
@@ -1,13 +0,0 @@
1
- import type { z, ZodRawShape, ZodTypeAny } from 'zod';
2
- import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
4
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
- type WixRequestHandlerExtra = RequestHandlerExtra & {};
6
- 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>;
7
- export declare class WixMcpServer extends McpServer {
8
- tool(name: string, cb: WixToolCallback): void;
9
- tool(name: string, description: string, cb: WixToolCallback): void;
10
- tool<Args extends ZodRawShape>(name: string, paramsSchema: Args, cb: WixToolCallback<Args>): void;
11
- tool<Args extends ZodRawShape>(name: string, description: string, paramsSchema: Args, cb: WixToolCallback<Args>): void;
12
- }
13
- export {};
@@ -1,51 +0,0 @@
1
- // import type { PanoramaClientForComponent } from '@wix/panorama-client-node';
2
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- //import { globalConfig, panoramaFactory } from './panorama.js';
4
- import { captureException } from '@sentry/node';
5
- export class WixMcpServer extends McpServer {
6
- tool(...args) {
7
- const cbIndex = args.findIndex((arg) => typeof arg === 'function');
8
- if (cbIndex !== -1) {
9
- const originalCb = args[cbIndex];
10
- const toolName = args[0];
11
- const panoramaComponentId = toolName;
12
- /*const panorama = panoramaFactory.client({
13
- baseParams: {
14
- componentId: panoramaComponentId
15
- }
16
- });*/
17
- /*setTags({
18
- panoramaSessionId: globalConfig.getSessionId()
19
- });*/
20
- const wrappedCb = async (...cbArgs) => {
21
- const argsBeforeExtra = cbArgs.slice(0, cbArgs.length - 1);
22
- const extra = cbArgs[cbArgs.length - 1];
23
- const wrappedExtra = {
24
- ...extra
25
- // panorama: panorama.createClientForComponent()
26
- };
27
- //panorama.transaction(toolName).start();
28
- try {
29
- const cbResult = await originalCb(...argsBeforeExtra, wrappedExtra);
30
- //panorama.transaction(toolName).finish();
31
- return cbResult;
32
- }
33
- catch (e) {
34
- //panorama.errorMonitor().reportError(e as Error);
35
- captureException(e, {
36
- tags: {
37
- componentId: panoramaComponentId,
38
- toolName
39
- }
40
- });
41
- return {
42
- isError: true,
43
- content: [{ type: 'text', text: e.message }]
44
- };
45
- }
46
- };
47
- args[cbIndex] = wrappedCb;
48
- }
49
- return super.tool.apply(this, args);
50
- }
51
- }