@wix/mcp 1.0.27 → 1.0.28

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:
@@ -39304,7 +39304,6 @@ function createWixToolkit(options) {
39304
39304
  docs,
39305
39305
  api,
39306
39306
  defaults = {},
39307
- curryFields = [],
39308
39307
  exclude = [],
39309
39308
  clientName,
39310
39309
  hooks
@@ -39344,7 +39343,7 @@ function createWixToolkit(options) {
39344
39343
  } else {
39345
39344
  addApiCallTool(server, authStrategy);
39346
39345
  }
39347
- const fieldsToRemove = [...Object.keys(defaults), ...curryFields];
39346
+ const fieldsToRemove = Object.keys(defaults);
39348
39347
  const allTools = captured.filter((t) => !exclude.includes(t.name)).map((captured2) => {
39349
39348
  const inputSchema = fieldsToRemove.length > 0 ? buildSchemaWithout(captured2.paramsSchema, fieldsToRemove) : external_exports.object(captured2.paramsSchema);
39350
39349
  const execute = async (args) => {