@wix/mcp 1.0.0 → 1.0.1

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.
@@ -0,0 +1,119 @@
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
+ });
@@ -0,0 +1,16 @@
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 type { PanoramaClientForComponent } from '@wix/panorama-client-node';
5
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
6
+ type WixRequestHandlerExtra = RequestHandlerExtra & {
7
+ panorama: PanoramaClientForComponent;
8
+ };
9
+ 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>;
10
+ export declare class WixMcpServer extends McpServer {
11
+ tool(name: string, cb: WixToolCallback): void;
12
+ tool(name: string, description: string, cb: WixToolCallback): void;
13
+ tool<Args extends ZodRawShape>(name: string, paramsSchema: Args, cb: WixToolCallback<Args>): void;
14
+ tool<Args extends ZodRawShape>(name: string, description: string, paramsSchema: Args, cb: WixToolCallback<Args>): void;
15
+ }
16
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/mcp",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A Model Context Protocol server for Wix AI tools",
5
5
  "type": "module",
6
6
  "bin": "./bin.js",
@@ -11,10 +11,10 @@
11
11
  "build": "tsc",
12
12
  "test": "vitest run",
13
13
  "test:watch": "vitest",
14
- "start": "npm run build && node ./build/index.js",
14
+ "start": "npm run build && node ./build/bin.js",
15
15
  "watch": "tsc --watch",
16
16
  "lint": "eslint .",
17
- "inspector": "npx @modelcontextprotocol/inspector build/index.js"
17
+ "inspector": "npx @modelcontextprotocol/inspector build/bin.js"
18
18
  },
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org/",
@@ -22,32 +22,33 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@modelcontextprotocol/sdk": "^1.9.0",
25
- "@sentry/node": "^9.12.0",
25
+ "@sentry/node": "^9.13.0",
26
26
  "@wix/panorama-client-node": "^3.227.0",
27
27
  "execa": "^9.5.2",
28
28
  "minimist": "^1.2.8",
29
29
  "strip-ansi": "^7.1.0",
30
30
  "uuid": "^11.1.0",
31
31
  "wait-for-expect": "^3.0.2",
32
- "zod": "^3.24.2"
32
+ "zod": "^3.24.3"
33
33
  },
34
34
  "devDependencies": {
35
- "@eslint/js": "^9.24.0",
35
+ "@eslint/js": "^9.25.0",
36
36
  "@types/express": "^5.0.1",
37
37
  "@types/minimist": "^1.2.5",
38
38
  "@types/node": "^20.17.30",
39
- "eslint": "^9.24.0",
39
+ "eslint": "^9.25.0",
40
40
  "eslint-config-prettier": "^10.1.2",
41
41
  "eslint-plugin-prettier": "^5.2.6",
42
42
  "globals": "^16.0.0",
43
43
  "prettier": "^3.5.3",
44
44
  "typescript": "^5.8.3",
45
45
  "typescript-eslint": "^8.30.1",
46
- "vitest": "^3.1.1"
46
+ "vitest": "^3.1.2"
47
47
  },
48
48
  "exports": {
49
49
  ".": {
50
- "import": "./build/index.js"
50
+ "import": "./build/index.js",
51
+ "types": "./build/index.d.ts"
51
52
  },
52
53
  "./package.json": "./package.json"
53
54
  },
@@ -62,5 +63,5 @@
62
63
  ]
63
64
  }
64
65
  },
65
- "falconPackageHash": "bf847433e48397ca724ff50a4883a0a7a5aedc5c5cb6af9048001461"
66
+ "falconPackageHash": "45d0dbf4ab7e282591f50831a041971ab0ea17988030cb5d68ab0d86"
66
67
  }