@wix/mcp 1.0.27 → 1.0.29

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 CHANGED
@@ -81,6 +81,150 @@ Set logging output:
81
81
 
82
82
  > Experimental tools are in early development and may have limited functionality or breaking changes. They must be explicitly enabled with `--experimental`.
83
83
 
84
+ ## Toolkit API (Programmatic Usage)
85
+
86
+ The Toolkit API lets you use `@wix/mcp` tools **in-process** without running an MCP server. This is the recommended approach for AI agent integrations (Vercel AI SDK, LangChain, custom agent loops, etc.).
87
+
88
+ ### Quick Start
89
+
90
+ ```typescript
91
+ import { createWixToolkit, extractText } from '@wix/mcp';
92
+
93
+ const toolkit = createWixToolkit({
94
+ auth: {
95
+ siteToken: async (siteId) => ({ Authorization: `Bearer ${myToken}` }),
96
+ accountToken: async () => ({ Authorization: `Bearer ${myToken}` }),
97
+ },
98
+ docs: { tools: ['REST'], getToKnowWixEnabled: true },
99
+ api: { tools: ['CallWixSiteAPI'] },
100
+ defaults: { siteId: 'my-site-id' },
101
+ clientName: 'my-app',
102
+ });
103
+
104
+ // Get all tools as plain objects
105
+ for (const tool of toolkit.getTools()) {
106
+ console.log(tool.name, tool.description);
107
+ console.log(tool.inputSchema); // Zod schema
108
+ }
109
+
110
+ // Execute a tool
111
+ const result = await toolkit.getTool('SearchWixRESTDocumentation')!
112
+ .execute({ searchTerm: 'query products', reason: 'find endpoint' });
113
+ console.log(extractText(result));
114
+
115
+ // Pre-load WixREADME content for system prompt injection
116
+ const readme = await toolkit.preloadReadme();
117
+ ```
118
+
119
+ ### `createWixToolkit(options)`
120
+
121
+ Returns a `WixToolkit` with the following methods:
122
+
123
+ | Method | Returns | Description |
124
+ |--------|---------|-------------|
125
+ | `getTools()` | `WixTool[]` | All registered tools |
126
+ | `getTool(name)` | `WixTool \| undefined` | Look up a tool by name |
127
+ | `getToolNames()` | `string[]` | List of tool names |
128
+ | `preloadReadme()` | `Promise<string \| null>` | Pre-load WixREADME content |
129
+
130
+ ### Options
131
+
132
+ | Option | Type | Description |
133
+ |--------|------|-------------|
134
+ | `auth` | `WixToolkitAuth` | **Required.** Auth headers for API calls. Either `{ siteToken, accountToken }` functions or a full `McpAuthenticationStrategy`. |
135
+ | `docs` | `WixToolkitDocsConfig` | Docs tools config. `tools` selects sources (`'REST'`, `'SDK'`, etc.). `getToKnowWixEnabled: true` enables `WixREADME`. |
136
+ | `api` | `WixToolkitApiConfig` | API tools config. `tools` selects which API tools to register (`'CallWixSiteAPI'`, `'ListWixSites'`, `'ManageWixSite'`). |
137
+ | `defaults` | `Record<string, any>` | Values to hide from tool schemas and auto-inject at execute time. Commonly used for `siteId`. |
138
+ | `exclude` | `string[]` | Tool names to filter out after registration. |
139
+ | `clientName` | `string` | Consumer identifier for BI tracking. |
140
+ | `hooks` | `WixToolkitHooks` | Lifecycle callbacks for observability (see below). |
141
+
142
+ ### `WixTool` Interface
143
+
144
+ Each tool returned by `getTools()` has:
145
+
146
+ ```typescript
147
+ interface WixTool {
148
+ name: string; // e.g. 'CallWixSiteAPI'
149
+ description: string; // LLM-facing description
150
+ inputSchema: z.ZodObject<any>; // Zod schema for parameters
151
+ annotations?: ToolAnnotations; // MCP annotations (readOnlyHint, etc.)
152
+ execute(args: Record<string, any>): Promise<CallToolResult>;
153
+ }
154
+ ```
155
+
156
+ ### `defaults` — Hiding and Injecting Parameters
157
+
158
+ Use `defaults` to remove fields from tool schemas and auto-inject values at execute time. This is how you handle parameters the LLM shouldn't control (e.g., `siteId`):
159
+
160
+ ```typescript
161
+ const toolkit = createWixToolkit({
162
+ auth: { ... },
163
+ api: { tools: ['CallWixSiteAPI'] },
164
+ defaults: { siteId: 'my-site-id' },
165
+ });
166
+
167
+ // CallWixSiteAPI schema no longer has siteId — the LLM won't see it
168
+ // When execute() is called, siteId is automatically merged into args
169
+ const tool = toolkit.getTool('CallWixSiteAPI')!;
170
+ await tool.execute({ url: 'https://...', method: 'GET', reason: '...' });
171
+ // internally calls the API with { siteId: 'my-site-id', url: '...', method: 'GET', ... }
172
+ ```
173
+
174
+ ### Lifecycle Hooks
175
+
176
+ ```typescript
177
+ const toolkit = createWixToolkit({
178
+ // ...
179
+ hooks: {
180
+ beforeExecute: (toolName, args) => {
181
+ console.log(`[${toolName}] starting`, args);
182
+ },
183
+ afterExecute: (toolName, result, durationMs) => {
184
+ console.log(`[${toolName}] done in ${durationMs}ms`, result.isError ? 'ERROR' : 'OK');
185
+ },
186
+ onError: (toolName, error, durationMs) => {
187
+ console.error(`[${toolName}] threw after ${durationMs}ms`, error);
188
+ },
189
+ },
190
+ });
191
+ ```
192
+
193
+ Hooks are separate from the library's internal Panorama/BI telemetry, which runs automatically.
194
+
195
+ ### `extractText(result)`
196
+
197
+ Helper to extract text content from a `CallToolResult`:
198
+
199
+ ```typescript
200
+ import { extractText } from '@wix/mcp';
201
+
202
+ const result = await tool.execute({ searchTerm: 'products' });
203
+ const text = extractText(result); // concatenated text blocks, non-text filtered out
204
+ ```
205
+
206
+ ### Vercel AI SDK Integration Example
207
+
208
+ ```typescript
209
+ import { createWixToolkit, extractText } from '@wix/mcp';
210
+ import { tool } from 'ai';
211
+ import { zodToJsonSchema } from 'zod-to-json-schema';
212
+
213
+ const toolkit = createWixToolkit({ auth: { ... }, docs: { tools: ['REST'] } });
214
+
215
+ // Convert WixTools to Vercel AI SDK tools
216
+ const aiTools = Object.fromEntries(
217
+ toolkit.getTools().map(t => [
218
+ t.name,
219
+ tool({
220
+ description: t.description,
221
+ parameters: t.inputSchema,
222
+ execute: async (args) => extractText(await t.execute(args)),
223
+ }),
224
+ ])
225
+ );
226
+ ```
227
+
84
228
  ## Resources
85
229
 
86
230
  The resource feature provides access to Wix documentation via the MCP server:
@@ -10772,7 +10772,8 @@ var defaultToolDescriptions = {
10772
10772
  ${SYSTEM_REMINDER}
10773
10773
  `,
10774
10774
  CallWixSiteAPI: dedent_default`
10775
- 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,
10775
+ 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.
10776
+ For POST/PATCH/PUT requests, pass the request body as a JSON object in the "body" parameter with all the required fields and values as described in the API schema, code examples, or docs you retrieved (e.g. body: {"name": "value", "nested": {"key": "value"}}).
10776
10777
  The API endpoint url param MUST ALWAYS be taken from the conversation context.
10777
10778
  By conversation context we mean the endpoint url was given in the user prompt OR got into the conversation context by the "WixREADME" tool OR by the "SearchWixRESTDocumentation" tool OR by the "BrowseWixRESTDocsMenu" tool OR by the "ReadFullDocsArticle" tool.
10778
10779
  Error Handling:
@@ -10789,6 +10790,7 @@ var defaultToolDescriptions = {
10789
10790
  `,
10790
10791
  ManageWixSite: dedent_default`
10791
10792
  Use account level API in order to create a site, update a site and publish site.
10793
+ For POST/PATCH/PUT requests, pass the request body as a JSON object in the "body" parameter with all the required fields and values as described in the API schema, code examples, or docs you retrieved (e.g. body: {"name": "value", "nested": {"key": "value"}}).
10792
10794
  The API endpoint url param MUST ALWAYS be taken from the conversation context.
10793
10795
  By conversation context we mean the endpoint url was given in the user prompt or got into the conversation context by the "WixREADME" tool or by the "SearchWixRESTDocumentation" tool or by the "BrowseWixRESTDocsMenu" tool or by the "ReadFullDocsArticle" tool.
10794
10796
  ${SYSTEM_REMINDER}
@@ -11159,7 +11161,7 @@ var paramDescriptions = {
11159
11161
  `Docs urls like https://dev.wix.com/docs/... are not API urls, if you want to read the docs, use the "ReadFullDocsArticle" tool`
11160
11162
  ].join("\n"),
11161
11163
  method: "The HTTP method to use for the API call (e.g. GET, POST, PUT, DELETE)",
11162
- body: 'The request body object. YOU MUST NEVER MAKE UP A BODY - the body should be based on the conversation context, i.e from the user prompt OR got into the conversation context by the "ReadFullDocsArticle" tool OR by the "ReadFullDocsMethodSchema" tool - i.e based on the API docs, a relevant recipe you read (preferably), a code example you found in the docs, a schema you read etc.. YOU MUST NEVER ASSUME YOU KNOW WHAT THE BODY SCHEMA IS WITHOUT CONCRETE EXAMPLES OR SCHEMA DEFINITIONS FROM THE CONVERSATION CONTEXT. Prefer reading relevant recipes if you have them in context for understand the body schema for API calls.',
11164
+ body: 'The request body as a JSON object with all the required fields and values, including nested objects. Pass the actual object, NOT a JSON string. YOU MUST NEVER MAKE UP A BODY - the body should be based on the conversation context, i.e from the user prompt OR got into the conversation context by the "ReadFullDocsArticle" tool OR by the "ReadFullDocsMethodSchema" tool - i.e based on the API docs, a relevant recipe you read (preferably), a code example you found in the docs, a schema you read etc.. YOU MUST NEVER ASSUME YOU KNOW WHAT THE BODY SCHEMA IS WITHOUT CONCRETE EXAMPLES OR SCHEMA DEFINITIONS FROM THE CONVERSATION CONTEXT. Prefer reading relevant recipes if you have them in context for understand the body schema for API calls.',
11163
11165
  reason: "One sentence explaining the original user request and why you are calling this API to complete it.",
11164
11166
  sourceDocUrl: [
11165
11167
  "The URL of the documentation or recipe where you found this API endpoint.",
@@ -11177,7 +11179,7 @@ var paramDescriptions = {
11177
11179
  ManageWixSite: {
11178
11180
  url: "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",
11179
11181
  method: "The HTTP method to use for the API call (e.g. GET, POST, PUT, DELETE)",
11180
- body: 'The request body object. YOU MUST NEVER MAKE UP A BODY - this should be based on the conversation context, i.e from the user prompt or from the "WixREADME" tool or from the "SearchWixRESTDocumentation" tool or from the "BrowseWixRESTDocsMenu" tool or from the "ReadFullDocsArticle" tool or from the "ReadFullDocsMethodSchema" tool - i.e based on the API docs. YOU MUST NEVER ASSUME YOU KNOW WHAT THE SCHEMA IS WITHOUT CONCRETE EXAMPLES OR SCHEMA DEFINITIONS FROM THE CONVERSATION CONTEXT.'
11182
+ body: 'The request body as a JSON object with all the required fields and values, including nested objects. Pass the actual object, NOT a JSON string. YOU MUST NEVER MAKE UP A BODY - this should be based on the conversation context, i.e from the user prompt or from the "WixREADME" tool or from the "SearchWixRESTDocumentation" tool or from the "BrowseWixRESTDocsMenu" tool or from the "ReadFullDocsArticle" tool or from the "ReadFullDocsMethodSchema" tool - i.e based on the API docs. YOU MUST NEVER ASSUME YOU KNOW WHAT THE SCHEMA IS WITHOUT CONCRETE EXAMPLES OR SCHEMA DEFINITIONS FROM THE CONVERSATION CONTEXT.'
11181
11183
  },
11182
11184
  SearchWixWDSDocumentation: {
11183
11185
  searchTerm: "The search term to search for in the Wix Design System Documentation",