@01.software/cli 0.8.0 → 0.9.0

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.
@@ -1,9 +1,6 @@
1
1
  // src/server.ts
2
2
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
 
4
- // src/tools/query-collection.ts
5
- import { z } from "zod";
6
-
7
4
  // src/lib/request-context.ts
8
5
  import { AsyncLocalStorage } from "async_hooks";
9
6
  var requestContext = new AsyncLocalStorage();
@@ -14,6 +11,360 @@ function hasRequestContext() {
14
11
  return requestContext.getStore() !== void 0;
15
12
  }
16
13
 
14
+ // src/lib/tool-utils.ts
15
+ function toolSuccess(data) {
16
+ return JSON.stringify({ success: true, ...data }, null, 2);
17
+ }
18
+ function toolError(error) {
19
+ const base = { success: false };
20
+ const isStructured = !!error && typeof error === "object" && ("code" in error || "reason" in error);
21
+ if (isStructured) {
22
+ const sdkErr = error;
23
+ base.error = sdkErr.message || "Unknown error";
24
+ if (sdkErr.status) base.status = sdkErr.status;
25
+ if (sdkErr.code) base.code = sdkErr.code;
26
+ if (sdkErr.reason) base.reason = sdkErr.reason;
27
+ if (sdkErr.requestId) base.requestId = sdkErr.requestId;
28
+ if (sdkErr.suggestion) base.suggestion = sdkErr.suggestion;
29
+ if (sdkErr.details?.errors) base.errors = sdkErr.details.errors;
30
+ } else {
31
+ base.error = error instanceof Error ? error.message : "Unknown error";
32
+ }
33
+ return JSON.stringify(base, null, 2);
34
+ }
35
+ var MAX_QUERY_DEPTH = 5;
36
+ function checkDepth(obj, depth = 0) {
37
+ if (depth > MAX_QUERY_DEPTH) return false;
38
+ if (obj && typeof obj === "object") {
39
+ for (const val of Object.values(obj)) {
40
+ if (!checkDepth(val, depth + 1)) return false;
41
+ }
42
+ }
43
+ return true;
44
+ }
45
+ function parseJsonWhere(where) {
46
+ try {
47
+ const parsed = JSON.parse(where);
48
+ if (!checkDepth(parsed)) {
49
+ return {
50
+ success: false,
51
+ error: JSON.stringify(
52
+ {
53
+ success: false,
54
+ error: `Query exceeds maximum nesting depth of ${MAX_QUERY_DEPTH}`
55
+ },
56
+ null,
57
+ 2
58
+ )
59
+ };
60
+ }
61
+ return { success: true, data: parsed };
62
+ } catch {
63
+ return {
64
+ success: false,
65
+ error: JSON.stringify(
66
+ {
67
+ success: false,
68
+ error: `Invalid JSON in "where" parameter: ${where.length > 100 ? where.substring(0, 100) + "..." : where}`
69
+ },
70
+ null,
71
+ 2
72
+ )
73
+ };
74
+ }
75
+ }
76
+
77
+ // ../../packages/auth-contracts/dist/index.js
78
+ var MCP_RESOURCE_AUDIENCE = "https://mcp.01.software/mcp";
79
+ var MCP_OAUTH_ISSUER = "https://01.software";
80
+ var MCP_PROTECTED_RESOURCE_METADATA_PATH = "/.well-known/oauth-protected-resource/mcp";
81
+ var MCP_TENANT_CLAIM = "tenant_id";
82
+ var MCP_TENANT_ROLE_CLAIM = "tenant_role";
83
+ var MCP_SCOPES = {
84
+ read: "mcp:read",
85
+ write: "mcp:write"
86
+ };
87
+ var MCP_CONSOLE_SERVICE_AUDIENCE = "https://api.01.software/internal/mcp";
88
+ var MCP_CONSOLE_SERVICE_SCOPE = "console:mcp_proxy";
89
+ var MCP_SERVICE_TOKEN_LIFETIME_SECONDS = 60;
90
+
91
+ // src/tool-policy.ts
92
+ var READ_ONLY_ANNOTATION = {
93
+ readOnly: true,
94
+ destructive: false,
95
+ idempotent: true,
96
+ openWorld: false
97
+ };
98
+ var NON_DESTRUCTIVE_MUTATION_ANNOTATION = {
99
+ readOnly: false,
100
+ destructive: false,
101
+ idempotent: false,
102
+ openWorld: false
103
+ };
104
+ var NON_DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION = {
105
+ readOnly: false,
106
+ destructive: false,
107
+ idempotent: true,
108
+ openWorld: false
109
+ };
110
+ var DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION = {
111
+ readOnly: false,
112
+ destructive: true,
113
+ idempotent: false,
114
+ openWorld: false
115
+ };
116
+ var DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION = {
117
+ readOnly: false,
118
+ destructive: true,
119
+ idempotent: true,
120
+ openWorld: false
121
+ };
122
+ var REASON_IDEMPOTENT_DESTRUCTIVE_UPDATE = "Update operations mutate persisted state but converge to the same end state under repeated identical input.";
123
+ var REASON_CART_EPHEMERAL = "Cart is pre-checkout ephemeral state; reversal is possible by reissuing the prior input. Console enforces tenant scope.";
124
+ var TOOL_POLICY_MANIFEST = {
125
+ // ── Read-only collection / validation (mcp:read, tenant-viewer) ──
126
+ "query-collection": {
127
+ category: "read-only-collection",
128
+ oauthScope: MCP_SCOPES.read,
129
+ consoleRole: "tenant-viewer",
130
+ consoleSurface: "GET /api/{collection}",
131
+ annotationPolicy: READ_ONLY_ANNOTATION
132
+ },
133
+ "get-collection-by-id": {
134
+ category: "read-only-collection",
135
+ oauthScope: MCP_SCOPES.read,
136
+ consoleRole: "tenant-viewer",
137
+ consoleSurface: "GET /api/{collection}/{id}",
138
+ annotationPolicy: READ_ONLY_ANNOTATION
139
+ },
140
+ "get-order": {
141
+ category: "read-only-collection",
142
+ oauthScope: MCP_SCOPES.read,
143
+ consoleRole: "tenant-viewer",
144
+ consoleSurface: "GET /api/orders/{id}",
145
+ annotationPolicy: READ_ONLY_ANNOTATION
146
+ },
147
+ "stock-check": {
148
+ category: "read-only-collection",
149
+ oauthScope: MCP_SCOPES.read,
150
+ consoleRole: "tenant-viewer",
151
+ consoleSurface: "GET /api/products/{id}/stock",
152
+ annotationPolicy: READ_ONLY_ANNOTATION
153
+ },
154
+ "validate-discount": {
155
+ category: "read-only-collection",
156
+ oauthScope: MCP_SCOPES.read,
157
+ consoleRole: "tenant-viewer",
158
+ consoleSurface: "POST /api/discounts/validate",
159
+ annotationPolicy: READ_ONLY_ANNOTATION
160
+ },
161
+ "calculate-shipping": {
162
+ category: "read-only-collection",
163
+ oauthScope: MCP_SCOPES.read,
164
+ consoleRole: "tenant-viewer",
165
+ consoleSurface: "POST /api/shipping/calculate",
166
+ annotationPolicy: READ_ONLY_ANNOTATION
167
+ },
168
+ "get-collection-schema": {
169
+ category: "read-only-collection",
170
+ oauthScope: MCP_SCOPES.read,
171
+ consoleRole: "tenant-viewer",
172
+ consoleSurface: "GET /api/tenants/schema/{collectionSlug}",
173
+ annotationPolicy: READ_ONLY_ANNOTATION
174
+ },
175
+ "list-configurable-fields": {
176
+ category: "read-only-collection",
177
+ oauthScope: MCP_SCOPES.read,
178
+ consoleRole: "tenant-viewer",
179
+ consoleSurface: "GET /api/tenants/field-config",
180
+ annotationPolicy: READ_ONLY_ANNOTATION
181
+ },
182
+ // ── Tenant context (mcp:read, tenant-viewer) ──
183
+ "get-tenant-context": {
184
+ category: "read-only-tenant",
185
+ oauthScope: MCP_SCOPES.read,
186
+ consoleRole: "tenant-viewer",
187
+ consoleSurface: "GET /api/tenants/context",
188
+ annotationPolicy: READ_ONLY_ANNOTATION
189
+ },
190
+ // ── Cart mutations (mcp:write, tenant-editor) ──
191
+ "add-cart-item": {
192
+ category: "mutation-cart",
193
+ oauthScope: MCP_SCOPES.write,
194
+ consoleRole: "tenant-editor",
195
+ consoleSurface: "POST /api/carts/{id}/items",
196
+ annotationPolicy: NON_DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION
197
+ },
198
+ "update-cart-item": {
199
+ category: "mutation-cart",
200
+ oauthScope: MCP_SCOPES.write,
201
+ consoleRole: "tenant-editor",
202
+ consoleSurface: "PATCH /api/carts/{id}/items/{itemId}",
203
+ annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
204
+ exemptionReason: REASON_CART_EPHEMERAL
205
+ },
206
+ "remove-cart-item": {
207
+ category: "mutation-cart",
208
+ oauthScope: MCP_SCOPES.write,
209
+ consoleRole: "tenant-editor",
210
+ consoleSurface: "DELETE /api/carts/{id}/items/{itemId}",
211
+ annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
212
+ exemptionReason: REASON_CART_EPHEMERAL
213
+ },
214
+ "clear-cart": {
215
+ category: "mutation-cart",
216
+ oauthScope: MCP_SCOPES.write,
217
+ consoleRole: "tenant-editor",
218
+ consoleSurface: "POST /api/carts/{id}/clear",
219
+ annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
220
+ exemptionReason: REASON_CART_EPHEMERAL
221
+ },
222
+ "apply-discount": {
223
+ category: "mutation-cart",
224
+ oauthScope: MCP_SCOPES.write,
225
+ consoleRole: "tenant-editor",
226
+ consoleSurface: "POST /api/carts/{id}/discount",
227
+ annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
228
+ exemptionReason: REASON_CART_EPHEMERAL
229
+ },
230
+ "remove-discount": {
231
+ category: "mutation-cart",
232
+ oauthScope: MCP_SCOPES.write,
233
+ consoleRole: "tenant-editor",
234
+ consoleSurface: "DELETE /api/carts/{id}/discount",
235
+ annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
236
+ exemptionReason: REASON_CART_EPHEMERAL
237
+ },
238
+ // ── Order mutations (mcp:write, tenant-admin) ──
239
+ "checkout": {
240
+ category: "mutation-order",
241
+ oauthScope: MCP_SCOPES.write,
242
+ consoleRole: "tenant-admin",
243
+ consoleSurface: "POST /api/checkout",
244
+ annotationPolicy: DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION
245
+ },
246
+ "create-order": {
247
+ category: "mutation-order",
248
+ oauthScope: MCP_SCOPES.write,
249
+ consoleRole: "tenant-admin",
250
+ consoleSurface: "POST /api/orders",
251
+ annotationPolicy: DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION
252
+ },
253
+ "update-order": {
254
+ category: "mutation-order",
255
+ oauthScope: MCP_SCOPES.write,
256
+ consoleRole: "tenant-admin",
257
+ consoleSurface: "PATCH /api/orders/{id}",
258
+ annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
259
+ exemptionReason: REASON_IDEMPOTENT_DESTRUCTIVE_UPDATE
260
+ },
261
+ // ── Fulfillment mutations (mcp:write, tenant-admin) ──
262
+ "create-fulfillment": {
263
+ category: "mutation-fulfillment",
264
+ oauthScope: MCP_SCOPES.write,
265
+ consoleRole: "tenant-admin",
266
+ consoleSurface: "POST /api/orders/{id}/fulfillments",
267
+ annotationPolicy: NON_DESTRUCTIVE_MUTATION_ANNOTATION
268
+ },
269
+ "update-fulfillment": {
270
+ category: "mutation-fulfillment",
271
+ oauthScope: MCP_SCOPES.write,
272
+ consoleRole: "tenant-admin",
273
+ consoleSurface: "PATCH /api/fulfillments/{id}",
274
+ annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
275
+ exemptionReason: REASON_IDEMPOTENT_DESTRUCTIVE_UPDATE
276
+ },
277
+ // ── Return mutations (mcp:write, tenant-admin) ──
278
+ "create-return": {
279
+ category: "mutation-return",
280
+ oauthScope: MCP_SCOPES.write,
281
+ consoleRole: "tenant-admin",
282
+ consoleSurface: "POST /api/returns",
283
+ annotationPolicy: DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION
284
+ },
285
+ "update-return": {
286
+ category: "mutation-return",
287
+ oauthScope: MCP_SCOPES.write,
288
+ consoleRole: "tenant-admin",
289
+ consoleSurface: "PATCH /api/returns/{id}",
290
+ annotationPolicy: DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION,
291
+ exemptionReason: REASON_IDEMPOTENT_DESTRUCTIVE_UPDATE
292
+ },
293
+ "return-with-refund": {
294
+ category: "mutation-return",
295
+ oauthScope: MCP_SCOPES.write,
296
+ consoleRole: "tenant-admin",
297
+ consoleSurface: "POST /api/returns/with-refund",
298
+ annotationPolicy: DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION
299
+ },
300
+ // ── Transaction mutations (mcp:write, tenant-admin) ──
301
+ "update-transaction": {
302
+ category: "mutation-transaction",
303
+ oauthScope: MCP_SCOPES.write,
304
+ consoleRole: "tenant-admin",
305
+ consoleSurface: "PATCH /api/transactions/{id}",
306
+ annotationPolicy: DESTRUCTIVE_NON_IDEMPOTENT_MUTATION_ANNOTATION
307
+ },
308
+ // ── Field-config mutations (mcp:write, tenant-admin) ──
309
+ "update-field-config": {
310
+ category: "mutation-field-config",
311
+ oauthScope: MCP_SCOPES.write,
312
+ consoleRole: "tenant-admin",
313
+ consoleSurface: "PATCH /api/tenants/field-config",
314
+ annotationPolicy: NON_DESTRUCTIVE_IDEMPOTENT_MUTATION_ANNOTATION
315
+ },
316
+ // ── SDK doc tools (mcp:read, tenant-viewer, sdk-static surface) ──
317
+ "sdk-get-recipe": {
318
+ category: "sdk-doc",
319
+ oauthScope: MCP_SCOPES.read,
320
+ consoleRole: "tenant-viewer",
321
+ consoleSurface: "sdk-static",
322
+ annotationPolicy: READ_ONLY_ANNOTATION
323
+ },
324
+ "sdk-search-docs": {
325
+ category: "sdk-doc",
326
+ oauthScope: MCP_SCOPES.read,
327
+ consoleRole: "tenant-viewer",
328
+ consoleSurface: "sdk-static",
329
+ annotationPolicy: READ_ONLY_ANNOTATION
330
+ },
331
+ "sdk-get-auth-setup": {
332
+ category: "sdk-doc",
333
+ oauthScope: MCP_SCOPES.read,
334
+ consoleRole: "tenant-viewer",
335
+ consoleSurface: "sdk-static",
336
+ annotationPolicy: READ_ONLY_ANNOTATION
337
+ },
338
+ "sdk-get-collection-pattern": {
339
+ category: "sdk-doc",
340
+ oauthScope: MCP_SCOPES.read,
341
+ consoleRole: "tenant-viewer",
342
+ consoleSurface: "sdk-static",
343
+ annotationPolicy: READ_ONLY_ANNOTATION
344
+ }
345
+ };
346
+ function evaluateToolPolicy(toolName, scopes) {
347
+ const entry = TOOL_POLICY_MANIFEST[toolName];
348
+ if (!entry) {
349
+ return {
350
+ allowed: false,
351
+ reason: "tool_policy_missing",
352
+ message: `No tool-policy entry for ${toolName}`
353
+ };
354
+ }
355
+ if (!scopes.includes(entry.oauthScope)) {
356
+ return {
357
+ allowed: false,
358
+ reason: "insufficient_scope",
359
+ message: `Tool ${toolName} requires ${entry.oauthScope}`
360
+ };
361
+ }
362
+ return { allowed: true, entry };
363
+ }
364
+
365
+ // src/tools/query-collection.ts
366
+ import { z } from "zod";
367
+
17
368
  // src/lib/client.ts
18
369
  import {
19
370
  CollectionClient,
@@ -25,14 +376,6 @@ import {
25
376
 
26
377
  // src/service-auth.ts
27
378
  import { createPrivateKey, randomUUID, sign as signBytes } from "crypto";
28
- import {
29
- MCP_CONSOLE_SERVICE_AUDIENCE,
30
- MCP_CONSOLE_SERVICE_SCOPE,
31
- MCP_OAUTH_ISSUER,
32
- MCP_SERVICE_TOKEN_LIFETIME_SECONDS,
33
- MCP_TENANT_CLAIM,
34
- MCP_TENANT_ROLE_CLAIM
35
- } from "@01.software/auth-contracts";
36
379
  var KEYSET_ENV = "MCP_SERVICE_KEYSET";
37
380
  function assertProductionKeysetUse(source) {
38
381
  const vercelEnv = process.env.VERCEL_ENV;
@@ -218,68 +561,6 @@ function getClient() {
218
561
 
219
562
  // src/tools/query-collection.ts
220
563
  import { COLLECTIONS } from "@01.software/sdk";
221
-
222
- // src/lib/tool-utils.ts
223
- function toolSuccess(data) {
224
- return JSON.stringify({ success: true, ...data }, null, 2);
225
- }
226
- function toolError(error) {
227
- const base = { success: false };
228
- if (error && typeof error === "object" && "code" in error) {
229
- const sdkErr = error;
230
- base.error = sdkErr.message || "Unknown error";
231
- if (sdkErr.status) base.status = sdkErr.status;
232
- if (sdkErr.code) base.code = sdkErr.code;
233
- if (sdkErr.suggestion) base.suggestion = sdkErr.suggestion;
234
- if (sdkErr.details?.errors) base.errors = sdkErr.details.errors;
235
- } else {
236
- base.error = error instanceof Error ? error.message : "Unknown error";
237
- }
238
- return JSON.stringify(base, null, 2);
239
- }
240
- var MAX_QUERY_DEPTH = 5;
241
- function checkDepth(obj, depth = 0) {
242
- if (depth > MAX_QUERY_DEPTH) return false;
243
- if (obj && typeof obj === "object") {
244
- for (const val of Object.values(obj)) {
245
- if (!checkDepth(val, depth + 1)) return false;
246
- }
247
- }
248
- return true;
249
- }
250
- function parseJsonWhere(where) {
251
- try {
252
- const parsed = JSON.parse(where);
253
- if (!checkDepth(parsed)) {
254
- return {
255
- success: false,
256
- error: JSON.stringify(
257
- {
258
- success: false,
259
- error: `Query exceeds maximum nesting depth of ${MAX_QUERY_DEPTH}`
260
- },
261
- null,
262
- 2
263
- )
264
- };
265
- }
266
- return { success: true, data: parsed };
267
- } catch {
268
- return {
269
- success: false,
270
- error: JSON.stringify(
271
- {
272
- success: false,
273
- error: `Invalid JSON in "where" parameter: ${where.length > 100 ? where.substring(0, 100) + "..." : where}`
274
- },
275
- null,
276
- 2
277
- )
278
- };
279
- }
280
- }
281
-
282
- // src/tools/query-collection.ts
283
564
  var schema = {
284
565
  collection: z.enum(COLLECTIONS).describe("Collection name (required)"),
285
566
  where: z.string().optional().describe(
@@ -348,223 +629,34 @@ var schema2 = {
348
629
  id: z2.string().min(1).describe("Item ID (required)")
349
630
  };
350
631
  var metadata2 = {
351
- name: "get-collection-by-id",
352
- description: "Get a specific collection item by ID",
353
- annotations: {
354
- title: "Get collection item by ID",
355
- readOnlyHint: true,
356
- destructiveHint: false,
357
- idempotentHint: true
358
- }
359
- };
360
- async function getCollectionById({
361
- collection,
362
- id
363
- }) {
364
- try {
365
- const client = getClient().collections;
366
- const result = await client.from(collection).findById(id);
367
- return toolSuccess({ data: result });
368
- } catch (error) {
369
- return toolError(error);
370
- }
371
- }
372
-
373
- // src/tools/create-collection.ts
374
- import { z as z3 } from "zod";
375
- import { COLLECTIONS as COLLECTIONS3 } from "@01.software/sdk";
376
- var schema3 = {
377
- collection: z3.enum(COLLECTIONS3).describe("Collection name (required)"),
378
- data: z3.record(z3.string(), z3.unknown()).describe(
379
- "Data to create (required). Use get-collection-schema first to understand writable fields, hidden fields, and required metadata. Server will validate and reject invalid fields."
380
- )
381
- };
382
- var metadata3 = {
383
- name: "create-collection",
384
- description: "Create a new collection item",
385
- annotations: {
386
- title: "Create collection item",
387
- readOnlyHint: false,
388
- destructiveHint: false,
389
- idempotentHint: false
390
- }
391
- };
392
- async function createCollection({
393
- collection,
394
- data
395
- }) {
396
- try {
397
- const client = getClient().collections;
398
- const result = await client.from(collection).create(data);
399
- return toolSuccess({ data: result.doc, message: result.message });
400
- } catch (error) {
401
- return toolError(error);
402
- }
403
- }
404
-
405
- // src/tools/update-collection.ts
406
- import { z as z4 } from "zod";
407
- import { COLLECTIONS as COLLECTIONS4 } from "@01.software/sdk";
408
- var schema4 = {
409
- collection: z4.enum(COLLECTIONS4).describe("Collection name (required)"),
410
- id: z4.string().min(1).describe("Item ID (required)"),
411
- data: z4.record(z4.string(), z4.unknown()).describe(
412
- "Data to update (required). Use get-collection-by-id first to check current structure, then get-collection-schema to confirm writable fields and required metadata. Server will validate and reject invalid fields."
413
- )
414
- };
415
- var metadata4 = {
416
- name: "update-collection",
417
- description: "Update an existing collection item",
418
- annotations: {
419
- title: "Update collection item",
420
- readOnlyHint: false,
421
- destructiveHint: true,
422
- idempotentHint: true
423
- }
424
- };
425
- async function updateCollection({
426
- collection,
427
- id,
428
- data
429
- }) {
430
- try {
431
- const client = getClient().collections;
432
- const result = await client.from(collection).update(id, data);
433
- return toolSuccess({ data: result.doc, message: result.message });
434
- } catch (error) {
435
- return toolError(error);
436
- }
437
- }
438
-
439
- // src/tools/delete-collection.ts
440
- import { z as z5 } from "zod";
441
- import { COLLECTIONS as COLLECTIONS5 } from "@01.software/sdk";
442
- var schema5 = {
443
- collection: z5.enum(COLLECTIONS5).describe("Collection name (required)"),
444
- id: z5.string().min(1).describe("Item ID (required)")
445
- };
446
- var metadata5 = {
447
- name: "delete-collection",
448
- description: "Delete a collection item",
449
- annotations: {
450
- title: "Delete collection item",
451
- readOnlyHint: false,
452
- destructiveHint: true,
453
- idempotentHint: true
454
- }
455
- };
456
- async function deleteCollection({
457
- collection,
458
- id
459
- }) {
460
- try {
461
- const client = getClient();
462
- await client.collections.from(collection).remove(id);
463
- return toolSuccess({ message: "Deleted successfully." });
464
- } catch (error) {
465
- return toolError(error);
466
- }
467
- }
468
-
469
- // src/tools/delete-many-collection.ts
470
- import { z as z6 } from "zod";
471
- import { COLLECTIONS as COLLECTIONS6 } from "@01.software/sdk";
472
- var schema6 = {
473
- collection: z6.enum(COLLECTIONS6).describe("Collection name (required)"),
474
- where: z6.string().describe(
475
- `Filter conditions (JSON string, required). Determines which items to delete. Example: '{"status":{"equals":"archived"}}'`
476
- )
477
- };
478
- var metadata6 = {
479
- name: "delete-many-collection",
480
- description: "Bulk delete collection items matching a filter. All matching items will be permanently deleted.",
481
- annotations: {
482
- title: "Bulk delete collection items",
483
- readOnlyHint: false,
484
- destructiveHint: true,
485
- idempotentHint: true
486
- }
487
- };
488
- async function deleteManyCollection({
489
- collection,
490
- where
491
- }) {
492
- try {
493
- const client = getClient().collections;
494
- const parsed = parseJsonWhere(where);
495
- if (!parsed.success) return parsed.error;
496
- if (!parsed.data || typeof parsed.data !== "object" || Object.keys(parsed.data).length === 0) {
497
- return toolError(
498
- new Error(
499
- 'Empty "where" filter is not allowed for bulk deletes. Provide at least one filter condition.'
500
- )
501
- );
502
- }
503
- const result = await client.from(collection).removeMany(parsed.data);
504
- return toolSuccess({
505
- totalDocs: result.totalDocs,
506
- message: `Deleted ${result.totalDocs} item(s).`
507
- });
508
- } catch (error) {
509
- return toolError(error);
510
- }
511
- }
512
-
513
- // src/tools/update-many-collection.ts
514
- import { z as z7 } from "zod";
515
- import { COLLECTIONS as COLLECTIONS7 } from "@01.software/sdk";
516
- var schema7 = {
517
- collection: z7.enum(COLLECTIONS7).describe("Collection name (required)"),
518
- where: z7.string().describe(
519
- `Filter conditions (JSON string, required). Determines which items to update. Example: '{"status":{"equals":"draft"}}'`
520
- ),
521
- data: z7.record(z7.string(), z7.unknown()).describe(
522
- "Data to update (required). Partial updates supported. Server will validate and reject invalid fields."
523
- )
524
- };
525
- var metadata7 = {
526
- name: "update-many-collection",
527
- description: "Bulk update collection items matching a filter. All matching items will be updated with the provided data.",
632
+ name: "get-collection-by-id",
633
+ description: "Get a specific collection item by ID",
528
634
  annotations: {
529
- title: "Bulk update collection items",
530
- readOnlyHint: false,
531
- destructiveHint: true,
635
+ title: "Get collection item by ID",
636
+ readOnlyHint: true,
637
+ destructiveHint: false,
532
638
  idempotentHint: true
533
639
  }
534
640
  };
535
- async function updateManyCollection({
641
+ async function getCollectionById({
536
642
  collection,
537
- where,
538
- data
643
+ id
539
644
  }) {
540
645
  try {
541
646
  const client = getClient().collections;
542
- const parsed = parseJsonWhere(where);
543
- if (!parsed.success) return parsed.error;
544
- if (!parsed.data || typeof parsed.data !== "object" || Object.keys(parsed.data).length === 0) {
545
- return toolError(
546
- new Error(
547
- 'Empty "where" filter is not allowed for bulk updates. Provide at least one filter condition.'
548
- )
549
- );
550
- }
551
- const result = await client.from(collection).updateMany(parsed.data, data);
552
- return toolSuccess({
553
- data: result.docs,
554
- totalDocs: result.totalDocs,
555
- message: `Updated ${result.totalDocs} item(s).`
556
- });
647
+ const result = await client.from(collection).findById(id);
648
+ return toolSuccess({ data: result });
557
649
  } catch (error) {
558
650
  return toolError(error);
559
651
  }
560
652
  }
561
653
 
562
654
  // src/tools/get-order.ts
563
- import { z as z8 } from "zod";
564
- var schema8 = {
565
- orderNumber: z8.string().min(1).describe("Order number to look up (required)")
655
+ import { z as z3 } from "zod";
656
+ var schema3 = {
657
+ orderNumber: z3.string().min(1).describe("Order number to look up (required)")
566
658
  };
567
- var metadata8 = {
659
+ var metadata3 = {
568
660
  name: "get-order",
569
661
  description: "Get order details by order number. Returns order with related data (depth:1).",
570
662
  annotations: {
@@ -592,26 +684,26 @@ async function getOrder({
592
684
  }
593
685
 
594
686
  // src/tools/create-order.ts
595
- import { z as z9 } from "zod";
596
- var schema9 = {
597
- pgPaymentId: z9.string().optional().describe("PG payment ID (optional \u2014 omit for free orders)"),
598
- orderNumber: z9.string().min(1).describe("Unique order number (required)"),
599
- customerSnapshot: z9.object({
600
- name: z9.string().optional().describe("Customer name"),
601
- email: z9.string().describe("Customer email (required)"),
602
- phone: z9.string().optional().describe("Customer phone")
687
+ import { z as z4 } from "zod";
688
+ var schema4 = {
689
+ pgPaymentId: z4.string().optional().describe("PG payment ID (optional \u2014 omit for free orders)"),
690
+ orderNumber: z4.string().min(1).describe("Unique order number (required)"),
691
+ customerSnapshot: z4.object({
692
+ name: z4.string().optional().describe("Customer name"),
693
+ email: z4.string().describe("Customer email (required)"),
694
+ phone: z4.string().optional().describe("Customer phone")
603
695
  }).describe("Customer snapshot at time of order (required)"),
604
- shippingAddress: z9.record(z9.string(), z9.unknown()).describe(
696
+ shippingAddress: z4.record(z4.string(), z4.unknown()).describe(
605
697
  "Shipping address object (required). Fields: postalCode, address1, address2, deliveryMessage, recipientName, phone"
606
698
  ),
607
- orderItems: z9.array(z9.record(z9.string(), z9.unknown())).describe(
699
+ orderItems: z4.array(z4.record(z4.string(), z4.unknown())).describe(
608
700
  "Array of order item objects (required). Each: { product, variant, option, quantity, unitPrice?, totalPrice? }"
609
701
  ),
610
- totalAmount: z9.number().nonnegative().describe("Total order amount (required, min 0)"),
611
- shippingAmount: z9.number().nonnegative().optional().describe("Shipping amount (optional, default 0)"),
612
- discountCode: z9.string().optional().describe("Discount code to apply (optional)")
702
+ totalAmount: z4.number().nonnegative().describe("Total order amount (required, min 0)"),
703
+ shippingAmount: z4.number().nonnegative().optional().describe("Shipping amount (optional, default 0)"),
704
+ discountCode: z4.string().optional().describe("Discount code to apply (optional)")
613
705
  };
614
- var metadata9 = {
706
+ var metadata4 = {
615
707
  name: "create-order",
616
708
  description: "Create a new order with products and shipping information. Supports idempotency.",
617
709
  annotations: {
@@ -634,10 +726,10 @@ async function createOrder(params) {
634
726
  }
635
727
 
636
728
  // src/tools/update-order.ts
637
- import { z as z10 } from "zod";
638
- var schema10 = {
639
- orderNumber: z10.string().min(1).describe("Order number (required)"),
640
- status: z10.enum([
729
+ import { z as z5 } from "zod";
730
+ var schema5 = {
731
+ orderNumber: z5.string().min(1).describe("Order number (required)"),
732
+ status: z5.enum([
641
733
  "pending",
642
734
  "paid",
643
735
  "failed",
@@ -650,7 +742,7 @@ var schema10 = {
650
742
  "New order status. Return-related statuses (return_requested, return_processing, returned) must be set via Return endpoints."
651
743
  )
652
744
  };
653
- var metadata10 = {
745
+ var metadata5 = {
654
746
  name: "update-order",
655
747
  description: "Update order status. Automatically adjusts stock on status changes (e.g., canceled restores stock).",
656
748
  annotations: {
@@ -674,17 +766,17 @@ async function updateOrder({
674
766
  }
675
767
 
676
768
  // src/tools/checkout.ts
677
- import { z as z11 } from "zod";
678
- var schema11 = {
679
- cartId: z11.string().min(1).describe("Cart ID to convert to order (required)"),
680
- pgPaymentId: z11.string().optional().describe("PG payment ID (optional \u2014 omit for free orders)"),
681
- orderNumber: z11.string().min(1).describe("Unique order number (required)"),
682
- customerSnapshot: z11.record(z11.string(), z11.unknown()).describe(
769
+ import { z as z6 } from "zod";
770
+ var schema6 = {
771
+ cartId: z6.string().min(1).describe("Cart ID to convert to order (required)"),
772
+ pgPaymentId: z6.string().optional().describe("PG payment ID (optional \u2014 omit for free orders)"),
773
+ orderNumber: z6.string().min(1).describe("Unique order number (required)"),
774
+ customerSnapshot: z6.record(z6.string(), z6.unknown()).describe(
683
775
  "Customer snapshot object (required). Fields: { name?, email, phone? }"
684
776
  ),
685
- discountCode: z11.string().optional().describe("Discount code to apply (optional)")
777
+ discountCode: z6.string().optional().describe("Discount code to apply (optional)")
686
778
  };
687
- var metadata11 = {
779
+ var metadata6 = {
688
780
  name: "checkout",
689
781
  description: "Convert a cart to an order. Validates stock, creates order and transaction, marks cart as completed. Supports idempotency.",
690
782
  annotations: {
@@ -707,21 +799,21 @@ async function checkout(params) {
707
799
  }
708
800
 
709
801
  // src/tools/create-fulfillment.ts
710
- import { z as z12 } from "zod";
711
- var schema12 = {
712
- orderNumber: z12.string().min(1).describe("Order number (required)"),
713
- carrier: z12.string().optional().describe("Shipping carrier name (optional)"),
714
- trackingNumber: z12.string().optional().describe(
802
+ import { z as z7 } from "zod";
803
+ var schema7 = {
804
+ orderNumber: z7.string().min(1).describe("Order number (required)"),
805
+ carrier: z7.string().optional().describe("Shipping carrier name (optional)"),
806
+ trackingNumber: z7.string().optional().describe(
715
807
  'Tracking number (optional). Setting carrier + tracking triggers "shipped" status'
716
808
  ),
717
- items: z12.array(
718
- z12.object({
719
- orderItem: z12.string().min(1).describe("Order item ID"),
720
- quantity: z12.number().int().positive().describe("Quantity to fulfill")
809
+ items: z7.array(
810
+ z7.object({
811
+ orderItem: z7.string().min(1).describe("Order item ID"),
812
+ quantity: z7.number().int().positive().describe("Quantity to fulfill")
721
813
  })
722
814
  ).describe("Array of items to fulfill (required)")
723
815
  };
724
- var metadata12 = {
816
+ var metadata7 = {
725
817
  name: "create-fulfillment",
726
818
  description: "Create a shipment/fulfillment for order items. Auto-updates order status (paid \u2192 preparing \u2192 shipped).",
727
819
  annotations: {
@@ -752,20 +844,20 @@ async function createFulfillment({
752
844
  }
753
845
 
754
846
  // src/tools/update-fulfillment.ts
755
- import { z as z13 } from "zod";
756
- var schema13 = {
757
- fulfillmentId: z13.string().min(1).describe("Fulfillment ID (required)"),
758
- status: z13.enum(["packed", "shipped", "delivered", "failed"]).describe(
847
+ import { z as z8 } from "zod";
848
+ var schema8 = {
849
+ fulfillmentId: z8.string().min(1).describe("Fulfillment ID (required)"),
850
+ status: z8.enum(["packed", "shipped", "delivered", "failed"]).describe(
759
851
  "New fulfillment status (required). FSM: pending\u2192packed/shipped/failed, packed\u2192shipped/failed, shipped\u2192delivered/failed"
760
852
  ),
761
- carrier: z13.string().optional().describe(
853
+ carrier: z8.string().optional().describe(
762
854
  "Shipping carrier (optional, changeable only in pending/packed status)"
763
855
  ),
764
- trackingNumber: z13.string().optional().describe(
856
+ trackingNumber: z8.string().optional().describe(
765
857
  "Tracking number (optional, changeable only in pending/packed status)"
766
858
  )
767
859
  };
768
- var metadata13 = {
860
+ var metadata8 = {
769
861
  name: "update-fulfillment",
770
862
  description: "Update fulfillment status, carrier, and tracking number. Auto-updates order status when all fulfillments are delivered.",
771
863
  annotations: {
@@ -795,15 +887,134 @@ async function updateFulfillment({
795
887
  }
796
888
  }
797
889
 
890
+ // ../../packages/contracts/src/tenant/index.ts
891
+ import { z as z9 } from "zod";
892
+ var tenantFieldConfigStateSchema = z9.object({
893
+ hiddenFields: z9.array(z9.string()),
894
+ isHidden: z9.boolean()
895
+ }).strict();
896
+ var tenantContextQuerySchema = z9.object({
897
+ counts: z9.literal("true").optional()
898
+ }).strict();
899
+ var tenantContextToolInputSchema = z9.object({
900
+ includeCounts: z9.boolean().optional().default(false).describe(
901
+ "Include per-collection document counts and config status (bypasses cache, slower)"
902
+ )
903
+ }).strict();
904
+ var tenantContextResponseSchema = z9.object({
905
+ tenant: z9.object({
906
+ id: z9.string(),
907
+ name: z9.string(),
908
+ plan: z9.string(),
909
+ planSource: z9.string().optional(),
910
+ authoritative: z9.boolean().optional(),
911
+ capabilityVersion: z9.string().optional(),
912
+ isDevMode: z9.boolean()
913
+ }).strict(),
914
+ features: z9.array(z9.string()),
915
+ collections: z9.object({
916
+ active: z9.array(z9.string()),
917
+ inactive: z9.array(z9.string())
918
+ }).strict(),
919
+ fieldConfigs: z9.record(z9.string(), tenantFieldConfigStateSchema),
920
+ counts: z9.record(z9.string(), z9.number()).optional(),
921
+ config: z9.object({
922
+ webhookConfigured: z9.boolean()
923
+ }).strict().optional()
924
+ }).strict();
925
+ var COLLECTION_SCHEMA_CONTRACT_VERSION = 1;
926
+ var collectionSchemaEndpointParamsSchema = z9.object({
927
+ collectionSlug: z9.string().min(1, "collectionSlug is required")
928
+ }).strict();
929
+ function createCollectionSchemaToolInputSchema(collections) {
930
+ return z9.object({
931
+ collection: z9.enum(collections).describe("Collection name (required)")
932
+ }).strict();
933
+ }
934
+ var collectionFieldOptionSchema = z9.object({
935
+ label: z9.string(),
936
+ value: z9.string()
937
+ }).strict();
938
+ var collectionFieldSchema = z9.lazy(
939
+ () => z9.object({
940
+ name: z9.string(),
941
+ path: z9.string(),
942
+ type: z9.string(),
943
+ required: z9.literal(true).optional(),
944
+ unique: z9.literal(true).optional(),
945
+ hasMany: z9.literal(true).optional(),
946
+ relationTo: z9.union([z9.string(), z9.array(z9.string())]).optional(),
947
+ options: z9.array(collectionFieldOptionSchema).optional(),
948
+ hidden: z9.literal(true).optional(),
949
+ systemManaged: z9.literal(true).optional(),
950
+ writable: z9.boolean().optional(),
951
+ fields: z9.array(collectionFieldSchema).optional()
952
+ }).strict()
953
+ );
954
+ var collectionSchemaResponseSchema = z9.object({
955
+ contractVersion: z9.literal(COLLECTION_SCHEMA_CONTRACT_VERSION),
956
+ mode: z9.literal("effective"),
957
+ collection: z9.object({
958
+ slug: z9.string(),
959
+ timestamps: z9.boolean(),
960
+ alwaysActive: z9.boolean(),
961
+ feature: z9.string().nullable(),
962
+ systemFields: z9.array(z9.string()),
963
+ visibility: z9.object({
964
+ collectionHidden: z9.boolean(),
965
+ hiddenFields: z9.array(z9.string())
966
+ }).strict(),
967
+ fields: z9.array(collectionFieldSchema)
968
+ }).strict()
969
+ }).strict();
970
+
971
+ // ../../packages/contracts/src/ecommerce/index.ts
972
+ import { z as z10 } from "zod";
973
+ var transactionStatusSchema = z10.enum([
974
+ "pending",
975
+ "paid",
976
+ "failed",
977
+ "canceled"
978
+ ]);
979
+ var updateTransactionSchema = z10.object({
980
+ pgPaymentId: z10.string().min(1, "pgPaymentId is required").describe("PG payment ID (required)"),
981
+ status: transactionStatusSchema.describe(
982
+ "New transaction status (required)"
983
+ ),
984
+ paymentMethod: z10.string().optional().describe("Payment method (optional)"),
985
+ receiptUrl: z10.string().optional().describe("Receipt URL (optional)"),
986
+ paymentKey: z10.string().min(1).optional().describe("Provider payment key for verified paid confirmation"),
987
+ amount: z10.number().int().positive().optional().describe("Provider-confirmed amount for verified paid confirmation")
988
+ }).strict();
989
+ var UpdateTransactionSchema = updateTransactionSchema;
990
+ var returnReasonSchema = z10.enum([
991
+ "change_of_mind",
992
+ "defective",
993
+ "wrong_delivery",
994
+ "damaged",
995
+ "other"
996
+ ]);
997
+ var restockActionSchema = z10.enum(["return_to_stock", "discard"]);
998
+ var returnWithRefundItemSchema = z10.object({
999
+ orderItem: z10.union([z10.string(), z10.number()]).transform(String),
1000
+ quantity: z10.number().int().positive("quantity must be a positive integer"),
1001
+ restockAction: restockActionSchema.default("return_to_stock")
1002
+ }).strict();
1003
+ var returnWithRefundSchema = z10.object({
1004
+ orderNumber: z10.string().min(1, "orderNumber is required").describe("Order number (required)"),
1005
+ reason: returnReasonSchema.optional().describe("Return reason (optional)"),
1006
+ reasonDetail: z10.string().optional().describe("Detailed reason text (optional)"),
1007
+ returnItems: z10.array(returnWithRefundItemSchema).min(1, "At least one return item is required").max(100, "Too many return items").describe("Array of products to return (required)"),
1008
+ refundAmount: z10.number().min(0, "refundAmount must be non-negative").describe("Refund amount (required, min 0)"),
1009
+ pgPaymentId: z10.string().min(1, "pgPaymentId is required").describe("PG payment ID for refund (required)"),
1010
+ paymentKey: z10.string().min(1).optional().describe("Provider payment key for verified refund"),
1011
+ refundReceiptUrl: z10.string().optional().describe("Refund receipt URL (optional)")
1012
+ }).strict();
1013
+ var ReturnWithRefundSchema = returnWithRefundSchema;
1014
+
798
1015
  // src/tools/update-transaction.ts
799
- import { z as z14 } from "zod";
800
- var schema14 = {
801
- pgPaymentId: z14.string().min(1).describe("PG payment ID (required)"),
802
- status: z14.enum(["pending", "paid", "failed", "canceled"]).describe("New transaction status (required)"),
803
- paymentMethod: z14.string().optional().describe("Payment method (optional)"),
804
- receiptUrl: z14.string().optional().describe("Receipt URL (optional)")
805
- };
806
- var metadata14 = {
1016
+ var schema9 = UpdateTransactionSchema.shape;
1017
+ var metadata9 = {
807
1018
  name: "update-transaction",
808
1019
  description: "Update transaction status, payment method, and receipt URL.",
809
1020
  annotations: {
@@ -817,16 +1028,21 @@ async function updateTransaction({
817
1028
  pgPaymentId,
818
1029
  status,
819
1030
  paymentMethod,
820
- receiptUrl
1031
+ receiptUrl,
1032
+ paymentKey,
1033
+ amount
821
1034
  }) {
822
1035
  try {
823
1036
  const client = getClient();
824
- const result = await client.commerce.orders.updateTransaction({
1037
+ const params = {
825
1038
  pgPaymentId,
826
1039
  status,
827
1040
  paymentMethod,
828
- receiptUrl
829
- });
1041
+ receiptUrl,
1042
+ paymentKey,
1043
+ amount
1044
+ };
1045
+ const result = await client.commerce.orders.updateTransaction(params);
830
1046
  return toolSuccess({ data: result });
831
1047
  } catch (error) {
832
1048
  return toolError(error);
@@ -834,20 +1050,20 @@ async function updateTransaction({
834
1050
  }
835
1051
 
836
1052
  // src/tools/create-return.ts
837
- import { z as z15 } from "zod";
838
- var schema15 = {
839
- orderNumber: z15.string().min(1).describe("Order number (required)"),
840
- reason: z15.enum(["change_of_mind", "defective", "wrong_delivery", "damaged", "other"]).optional().describe("Return reason (optional)"),
841
- reasonDetail: z15.string().optional().describe("Detailed reason text (optional)"),
842
- returnItems: z15.array(
843
- z15.object({
844
- orderItem: z15.string().min(1).describe("Order item ID"),
845
- quantity: z15.number().int().positive().describe("Quantity to return")
1053
+ import { z as z11 } from "zod";
1054
+ var schema10 = {
1055
+ orderNumber: z11.string().min(1).describe("Order number (required)"),
1056
+ reason: z11.enum(["change_of_mind", "defective", "wrong_delivery", "damaged", "other"]).optional().describe("Return reason (optional)"),
1057
+ reasonDetail: z11.string().optional().describe("Detailed reason text (optional)"),
1058
+ returnItems: z11.array(
1059
+ z11.object({
1060
+ orderItem: z11.string().min(1).describe("Order item ID"),
1061
+ quantity: z11.number().int().positive().describe("Quantity to return")
846
1062
  })
847
1063
  ).describe("Array of products to return (required)"),
848
- refundAmount: z15.number().nonnegative().describe("Refund amount (required, min 0)")
1064
+ refundAmount: z11.number().nonnegative().describe("Refund amount (required, min 0)")
849
1065
  };
850
- var metadata15 = {
1066
+ var metadata10 = {
851
1067
  name: "create-return",
852
1068
  description: "Create a return request for an order. Only works for delivered/confirmed orders. Updates order status to return_requested.",
853
1069
  annotations: {
@@ -880,14 +1096,14 @@ async function createReturn({
880
1096
  }
881
1097
 
882
1098
  // src/tools/update-return.ts
883
- import { z as z16 } from "zod";
884
- var schema16 = {
885
- returnId: z16.string().min(1).describe("Return ID (required)"),
886
- status: z16.enum(["processing", "approved", "rejected", "completed"]).describe(
1099
+ import { z as z12 } from "zod";
1100
+ var schema11 = {
1101
+ returnId: z12.string().min(1).describe("Return ID (required)"),
1102
+ status: z12.enum(["processing", "approved", "rejected", "completed"]).describe(
887
1103
  "New return status (required). Valid transitions: requested\u2192processing/rejected, processing\u2192approved/rejected, approved\u2192completed"
888
1104
  )
889
1105
  };
890
- var metadata16 = {
1106
+ var metadata11 = {
891
1107
  name: "update-return",
892
1108
  description: "Update return status with FSM validation. Restores inventory on completion, reverts order status on rejection.",
893
1109
  annotations: {
@@ -911,22 +1127,8 @@ async function updateReturn({
911
1127
  }
912
1128
 
913
1129
  // src/tools/return-with-refund.ts
914
- import { z as z17 } from "zod";
915
- var schema17 = {
916
- orderNumber: z17.string().min(1).describe("Order number (required)"),
917
- reason: z17.enum(["change_of_mind", "defective", "wrong_delivery", "damaged", "other"]).optional().describe("Return reason (optional)"),
918
- reasonDetail: z17.string().optional().describe("Detailed reason text (optional)"),
919
- returnItems: z17.array(
920
- z17.object({
921
- orderItem: z17.string().min(1).describe("Order item ID"),
922
- quantity: z17.number().int().positive().describe("Quantity to return")
923
- })
924
- ).describe("Array of products to return (required)"),
925
- refundAmount: z17.number().nonnegative().describe("Refund amount (required, min 0)"),
926
- pgPaymentId: z17.string().min(1).describe("PG payment ID for refund (required)"),
927
- refundReceiptUrl: z17.string().optional().describe("Refund receipt URL (optional)")
928
- };
929
- var metadata17 = {
1130
+ var schema12 = ReturnWithRefundSchema.shape;
1131
+ var metadata12 = {
930
1132
  name: "return-with-refund",
931
1133
  description: "Combined return + refund operation. Creates return, restores stock, cancels transaction, updates order status.",
932
1134
  annotations: {
@@ -943,19 +1145,22 @@ async function returnWithRefund({
943
1145
  returnItems,
944
1146
  refundAmount,
945
1147
  pgPaymentId,
1148
+ paymentKey,
946
1149
  refundReceiptUrl
947
1150
  }) {
948
1151
  try {
949
1152
  const client = getClient();
950
- const result = await client.commerce.orders.returnWithRefund({
1153
+ const params = {
951
1154
  orderNumber,
952
1155
  reason,
953
1156
  reasonDetail,
954
1157
  returnItems,
955
1158
  refundAmount,
956
1159
  pgPaymentId,
1160
+ paymentKey,
957
1161
  refundReceiptUrl
958
- });
1162
+ };
1163
+ const result = await client.commerce.orders.returnWithRefund(params);
959
1164
  return toolSuccess({ data: result });
960
1165
  } catch (error) {
961
1166
  return toolError(error);
@@ -963,15 +1168,15 @@ async function returnWithRefund({
963
1168
  }
964
1169
 
965
1170
  // src/tools/add-cart-item.ts
966
- import { z as z18 } from "zod";
967
- var schema18 = {
968
- cartId: z18.string().min(1).describe("Cart ID (required)"),
969
- product: z18.string().min(1).describe("Product ID (required)"),
970
- variant: z18.string().min(1).describe("Product variant ID (required)"),
971
- option: z18.string().min(1).describe("Product option ID (required)"),
972
- quantity: z18.number().int().positive().describe("Quantity to add (required, positive integer)")
1171
+ import { z as z13 } from "zod";
1172
+ var schema13 = {
1173
+ cartId: z13.string().min(1).describe("Cart ID (required)"),
1174
+ product: z13.string().min(1).describe("Product ID (required)"),
1175
+ variant: z13.string().min(1).describe("Product variant ID (required)"),
1176
+ option: z13.string().min(1).describe("Product option ID (required)"),
1177
+ quantity: z13.number().int().positive().describe("Quantity to add (required, positive integer)")
973
1178
  };
974
- var metadata18 = {
1179
+ var metadata13 = {
975
1180
  name: "add-cart-item",
976
1181
  description: "Add a product to cart. Validates stock, merges quantity if item already exists, recalculates totals.",
977
1182
  annotations: {
@@ -1004,12 +1209,12 @@ async function addCartItem({
1004
1209
  }
1005
1210
 
1006
1211
  // src/tools/update-cart-item.ts
1007
- import { z as z19 } from "zod";
1008
- var schema19 = {
1009
- cartItemId: z19.string().min(1).describe("Cart item ID (required)"),
1010
- quantity: z19.number().int().positive().describe("New quantity (required, positive integer)")
1212
+ import { z as z14 } from "zod";
1213
+ var schema14 = {
1214
+ cartItemId: z14.string().min(1).describe("Cart item ID (required)"),
1215
+ quantity: z14.number().int().positive().describe("New quantity (required, positive integer)")
1011
1216
  };
1012
- var metadata19 = {
1217
+ var metadata14 = {
1013
1218
  name: "update-cart-item",
1014
1219
  description: "Update cart item quantity. Validates stock availability, recalculates cart totals.",
1015
1220
  annotations: {
@@ -1033,11 +1238,11 @@ async function updateCartItem({
1033
1238
  }
1034
1239
 
1035
1240
  // src/tools/remove-cart-item.ts
1036
- import { z as z20 } from "zod";
1037
- var schema20 = {
1038
- cartItemId: z20.string().min(1).describe("Cart item ID to remove (required)")
1241
+ import { z as z15 } from "zod";
1242
+ var schema15 = {
1243
+ cartItemId: z15.string().min(1).describe("Cart item ID to remove (required)")
1039
1244
  };
1040
- var metadata20 = {
1245
+ var metadata15 = {
1041
1246
  name: "remove-cart-item",
1042
1247
  description: "Remove an item from cart. Recalculates cart totals after removal.",
1043
1248
  annotations: {
@@ -1060,12 +1265,12 @@ async function removeCartItem({
1060
1265
  }
1061
1266
 
1062
1267
  // src/tools/apply-discount.ts
1063
- import { z as z21 } from "zod";
1064
- var schema21 = {
1065
- cartId: z21.string().min(1).describe("Cart ID (required)"),
1066
- discountCode: z21.string().describe("Discount code to apply (required)")
1268
+ import { z as z16 } from "zod";
1269
+ var schema16 = {
1270
+ cartId: z16.string().min(1).describe("Cart ID (required)"),
1271
+ discountCode: z16.string().describe("Discount code to apply (required)")
1067
1272
  };
1068
- var metadata21 = {
1273
+ var metadata16 = {
1069
1274
  name: "apply-discount",
1070
1275
  description: "Apply a discount code to a cart. Validates the code, updates cart totals, and sets free shipping if applicable.",
1071
1276
  annotations: {
@@ -1089,11 +1294,11 @@ async function applyDiscount({
1089
1294
  }
1090
1295
 
1091
1296
  // src/tools/remove-discount.ts
1092
- import { z as z22 } from "zod";
1093
- var schema22 = {
1094
- cartId: z22.string().min(1).describe("Cart ID (required)")
1297
+ import { z as z17 } from "zod";
1298
+ var schema17 = {
1299
+ cartId: z17.string().min(1).describe("Cart ID (required)")
1095
1300
  };
1096
- var metadata22 = {
1301
+ var metadata17 = {
1097
1302
  name: "remove-discount",
1098
1303
  description: "Remove the applied discount code from a cart and recalculate totals.",
1099
1304
  annotations: {
@@ -1116,11 +1321,11 @@ async function removeDiscount({
1116
1321
  }
1117
1322
 
1118
1323
  // src/tools/clear-cart.ts
1119
- import { z as z23 } from "zod";
1120
- var schema23 = {
1121
- cartId: z23.string().min(1).describe("Cart ID (required)")
1324
+ import { z as z18 } from "zod";
1325
+ var schema18 = {
1326
+ cartId: z18.string().min(1).describe("Cart ID (required)")
1122
1327
  };
1123
- var metadata23 = {
1328
+ var metadata18 = {
1124
1329
  name: "clear-cart",
1125
1330
  description: "Remove all items from a cart, reset discount and amounts. Shipping fee is preserved.",
1126
1331
  annotations: {
@@ -1143,12 +1348,12 @@ async function clearCart({
1143
1348
  }
1144
1349
 
1145
1350
  // src/tools/validate-discount.ts
1146
- import { z as z24 } from "zod";
1147
- var schema24 = {
1148
- code: z24.string().describe("Discount code to validate (required)"),
1149
- orderAmount: z24.number().describe("Order amount for validation (required)")
1351
+ import { z as z19 } from "zod";
1352
+ var schema19 = {
1353
+ code: z19.string().describe("Discount code to validate (required)"),
1354
+ orderAmount: z19.number().describe("Order amount for validation (required)")
1150
1355
  };
1151
- var metadata24 = {
1356
+ var metadata19 = {
1152
1357
  name: "validate-discount",
1153
1358
  description: "Validate a discount code. Checks active status, date range, usage limits, minimum order amount, and calculates discount.",
1154
1359
  annotations: {
@@ -1175,13 +1380,13 @@ async function validateDiscount({
1175
1380
  }
1176
1381
 
1177
1382
  // src/tools/calculate-shipping.ts
1178
- import { z as z25 } from "zod";
1179
- var schema25 = {
1180
- shippingPolicyId: z25.string().optional().describe("Shipping policy ID (uses default policy if omitted)"),
1181
- orderAmount: z25.number().describe("Order amount for fee calculation (required)"),
1182
- postalCode: z25.string().optional().describe("Postal code for Jeju surcharge detection (63000-63644)")
1383
+ import { z as z20 } from "zod";
1384
+ var schema20 = {
1385
+ shippingPolicyId: z20.string().optional().describe("Shipping policy ID (uses default policy if omitted)"),
1386
+ orderAmount: z20.number().describe("Order amount for fee calculation (required)"),
1387
+ postalCode: z20.string().optional().describe("Postal code for Jeju surcharge detection (63000-63644)")
1183
1388
  };
1184
- var metadata25 = {
1389
+ var metadata20 = {
1185
1390
  name: "calculate-shipping",
1186
1391
  description: "Calculate shipping fee based on order amount and postal code. Supports free shipping threshold and Jeju surcharge.",
1187
1392
  annotations: {
@@ -1210,18 +1415,18 @@ async function calculateShipping({
1210
1415
  }
1211
1416
 
1212
1417
  // src/tools/stock-check.ts
1213
- import { z as z26 } from "zod";
1214
- var schema26 = {
1215
- items: z26.array(
1216
- z26.object({
1217
- variantId: z26.string().describe("Product variant ID"),
1218
- quantity: z26.number().int().positive().describe("Requested quantity")
1418
+ import { z as z21 } from "zod";
1419
+ var schema21 = {
1420
+ items: z21.array(
1421
+ z21.object({
1422
+ variantId: z21.string().describe("Product variant ID"),
1423
+ quantity: z21.number().int().positive().describe("Requested quantity")
1219
1424
  })
1220
1425
  ).describe(
1221
1426
  "Array of items to check stock for (required, max 100). Each: { variantId, quantity }"
1222
1427
  )
1223
1428
  };
1224
- var metadata26 = {
1429
+ var metadata21 = {
1225
1430
  name: "stock-check",
1226
1431
  description: "Batch check product option stock availability. Returns per-item availability and an allAvailable flag.",
1227
1432
  annotations: {
@@ -1244,8 +1449,7 @@ async function stockCheck({
1244
1449
  }
1245
1450
 
1246
1451
  // src/tools/get-collection-schema.ts
1247
- import { z as z27 } from "zod";
1248
- import { COLLECTIONS as COLLECTIONS8 } from "@01.software/sdk";
1452
+ import { COLLECTIONS as COLLECTIONS3 } from "@01.software/sdk";
1249
1453
 
1250
1454
  // src/lib/console-api.ts
1251
1455
  import { createHash } from "crypto";
@@ -1340,17 +1544,16 @@ async function consolePost(path, body, apiKey) {
1340
1544
  // src/lib/collection-schema.ts
1341
1545
  async function getCollectionSchema(collection) {
1342
1546
  const apiKey = resolveApiKey();
1343
- return consoleGet(
1547
+ const data = await consoleGet(
1344
1548
  `/api/tenants/schema/${encodeURIComponent(collection)}`,
1345
1549
  apiKey
1346
1550
  );
1551
+ return collectionSchemaResponseSchema.parse(data);
1347
1552
  }
1348
1553
 
1349
1554
  // src/tools/get-collection-schema.ts
1350
- var schema27 = {
1351
- collection: z27.enum(COLLECTIONS8).describe("Collection name (required)")
1352
- };
1353
- var metadata27 = {
1555
+ var schema22 = createCollectionSchemaToolInputSchema(COLLECTIONS3).shape;
1556
+ var metadata22 = {
1354
1557
  name: "get-collection-schema",
1355
1558
  description: "Get the authoritative tenant-aware collection schema from console. Use this before create/update to understand writable fields, hidden fields, required metadata, and collection-level visibility.",
1356
1559
  annotations: {
@@ -1374,9 +1577,6 @@ async function getCollectionSchemaTool({
1374
1577
  }
1375
1578
  }
1376
1579
 
1377
- // src/tools/get-tenant-context.ts
1378
- import { z as z28 } from "zod";
1379
-
1380
1580
  // src/lib/tenant-context.ts
1381
1581
  function getTenantContextPath(includeCounts) {
1382
1582
  return includeCounts ? "/api/tenants/context?counts=true" : "/api/tenants/context";
@@ -1387,16 +1587,12 @@ async function getTenantContext(includeCounts = false) {
1387
1587
  getTenantContextPath(includeCounts),
1388
1588
  apiKey
1389
1589
  );
1390
- return data;
1391
- }
1392
- function invalidateTenantContextCache() {
1590
+ return tenantContextResponseSchema.parse(data);
1393
1591
  }
1394
1592
 
1395
1593
  // src/tools/get-tenant-context.ts
1396
- var schema28 = {
1397
- includeCounts: z28.boolean().optional().default(false).describe("Include per-collection document counts and config status (bypasses cache, slower)")
1398
- };
1399
- var metadata28 = {
1594
+ var schema23 = tenantContextToolInputSchema.shape;
1595
+ var metadata23 = {
1400
1596
  name: "get-tenant-context",
1401
1597
  description: "Get current tenant features, active collections, and field visibility. Call this at the start of every session. Use includeCounts=true to also get per-collection document counts for setup diagnostics.",
1402
1598
  annotations: {
@@ -1406,7 +1602,9 @@ var metadata28 = {
1406
1602
  idempotentHint: true
1407
1603
  }
1408
1604
  };
1409
- async function handler({ includeCounts }) {
1605
+ async function handler({
1606
+ includeCounts
1607
+ }) {
1410
1608
  try {
1411
1609
  const ctx = await getTenantContext(includeCounts);
1412
1610
  const lines = [
@@ -1459,11 +1657,10 @@ async function handler({ includeCounts }) {
1459
1657
  }
1460
1658
  }
1461
1659
  if (ctx.config) {
1660
+ lines.push("", "## Config Status");
1462
1661
  lines.push(
1463
- "",
1464
- "## Config Status"
1662
+ `- Webhook configured: ${ctx.config.webhookConfigured ? "Yes" : "No"}`
1465
1663
  );
1466
- lines.push(`- Webhook configured: ${ctx.config.webhookConfigured ? "Yes" : "No"}`);
1467
1664
  }
1468
1665
  return toolSuccess({ context: lines.join("\n") });
1469
1666
  } catch (error) {
@@ -1472,7 +1669,7 @@ async function handler({ includeCounts }) {
1472
1669
  }
1473
1670
 
1474
1671
  // src/tools/list-configurable-fields.ts
1475
- import { z as z29 } from "zod";
1672
+ import { z as z22 } from "zod";
1476
1673
 
1477
1674
  // src/lib/field-config.ts
1478
1675
  async function fetchFieldConfigs() {
@@ -1495,12 +1692,12 @@ function invalidateFieldConfigCache() {
1495
1692
  }
1496
1693
 
1497
1694
  // src/tools/list-configurable-fields.ts
1498
- var schema29 = {
1499
- collection: z29.string().optional().describe(
1695
+ var schema24 = {
1696
+ collection: z22.string().optional().describe(
1500
1697
  "Filter by collection slug (optional \u2014 returns all if omitted). Use this filter to reduce response size when you know which collection to check."
1501
1698
  )
1502
1699
  };
1503
- var metadata29 = {
1700
+ var metadata24 = {
1504
1701
  name: "list-configurable-fields",
1505
1702
  description: "List all configurable fields for tenant collections with current visibility state. Shows which fields can be shown/hidden and their current status. Returns all collections including inactive features \u2014 cross-reference with get-tenant-context for active features. Response includes ~300 fields across 47 collections \u2014 use collection filter when possible.",
1506
1703
  annotations: {
@@ -1531,17 +1728,17 @@ async function listConfigurableFields(params) {
1531
1728
  }
1532
1729
 
1533
1730
  // src/tools/update-field-config.ts
1534
- import { z as z30 } from "zod";
1535
- var schema30 = {
1536
- collection: z30.string().min(1).describe("Collection slug (required)"),
1537
- hiddenFields: z30.array(z30.string().min(1).max(200)).max(300).describe(
1731
+ import { z as z23 } from "zod";
1732
+ var schema25 = {
1733
+ collection: z23.string().min(1).describe("Collection slug (required)"),
1734
+ hiddenFields: z23.array(z23.string().min(1).max(200)).max(300).describe(
1538
1735
  "Fields to hide (required). This is a FULL REPLACE \u2014 fields NOT in this list will be shown. Pass [] to show all fields. Use list-configurable-fields first to see available field paths."
1539
1736
  ),
1540
- isHidden: z30.boolean().optional().describe(
1737
+ isHidden: z23.boolean().optional().describe(
1541
1738
  "Hide the entire collection from Admin Panel (optional). When true, individual hiddenFields are irrelevant."
1542
1739
  )
1543
1740
  };
1544
- var metadata30 = {
1741
+ var metadata25 = {
1545
1742
  name: "update-field-config",
1546
1743
  description: "Update field visibility configuration for a tenant collection. Hidden fields are removed from the Admin Panel UI. IMPORTANT: hiddenFields is a full replace, not a merge. Always call list-configurable-fields first to see current state.",
1547
1744
  annotations: {
@@ -1559,7 +1756,6 @@ async function updateFieldConfig(params) {
1559
1756
  isHidden: params.isHidden
1560
1757
  });
1561
1758
  invalidateFieldConfigCache();
1562
- invalidateTenantContextCache();
1563
1759
  return toolSuccess({
1564
1760
  message: `Field config updated for '${params.collection}'`,
1565
1761
  data: result
@@ -1570,7 +1766,7 @@ async function updateFieldConfig(params) {
1570
1766
  }
1571
1767
 
1572
1768
  // src/tools/sdk-get-recipe.ts
1573
- import { z as z31 } from "zod";
1769
+ import { z as z24 } from "zod";
1574
1770
 
1575
1771
  // src/lib/sdk-recipes.ts
1576
1772
  var recipes = {
@@ -1722,7 +1918,7 @@ const result = await client.collections.from('products').create({
1722
1918
  "Returns result.doc (not the document directly)"
1723
1919
  ],
1724
1920
  relatedResources: ["docs://sdk/query-builder"],
1725
- relatedTools: ["create-collection"]
1921
+ relatedTools: ["query-collection", "get-collection-schema"]
1726
1922
  }
1727
1923
  },
1728
1924
  "update-item": {
@@ -1751,7 +1947,7 @@ const result = await client.collections.from('products').update('product-id', {
1751
1947
  "Partial updates are supported \u2014 omitted fields retain their current value"
1752
1948
  ],
1753
1949
  relatedResources: ["docs://sdk/query-builder"],
1754
- relatedTools: ["update-collection"]
1950
+ relatedTools: ["get-collection-by-id", "get-collection-schema"]
1755
1951
  }
1756
1952
  },
1757
1953
  "delete-item": {
@@ -1775,7 +1971,7 @@ console.log('Deleted:', deleted.title)`,
1775
1971
  "Throws if the item does not exist"
1776
1972
  ],
1777
1973
  relatedResources: ["docs://sdk/query-builder"],
1778
- relatedTools: ["delete-collection"]
1974
+ relatedTools: ["get-collection-by-id", "query-collection"]
1779
1975
  }
1780
1976
  },
1781
1977
  "infinite-scroll": {
@@ -1952,7 +2148,7 @@ const result = await client.collections.from('images').create(formData as unknow
1952
2148
  "Always set alt text for accessibility"
1953
2149
  ],
1954
2150
  relatedResources: ["docs://sdk/query-builder"],
1955
- relatedTools: ["create-collection"]
2151
+ relatedTools: ["query-collection", "get-collection-schema"]
1956
2152
  }
1957
2153
  },
1958
2154
  "bulk-operations": {
@@ -1988,7 +2184,7 @@ const removed = await client.collections.from('products').removeMany(
1988
2184
  "Very broad where clauses (or empty) will affect all documents in the collection"
1989
2185
  ],
1990
2186
  relatedResources: ["docs://sdk/query-builder"],
1991
- relatedTools: ["update-many-collection", "delete-many-collection"]
2187
+ relatedTools: ["query-collection", "get-collection-schema"]
1992
2188
  }
1993
2189
  }
1994
2190
  };
@@ -2002,8 +2198,8 @@ function getRecipe(goal, runtime = "both") {
2002
2198
  }
2003
2199
 
2004
2200
  // src/tools/sdk-get-recipe.ts
2005
- var schema31 = {
2006
- goal: z31.enum([
2201
+ var schema26 = {
2202
+ goal: z24.enum([
2007
2203
  "fetch-list",
2008
2204
  "fetch-by-id",
2009
2205
  "create-item",
@@ -2015,11 +2211,11 @@ var schema31 = {
2015
2211
  "file-upload",
2016
2212
  "bulk-operations"
2017
2213
  ]).describe("What the user wants to accomplish"),
2018
- runtime: z31.enum(["browser", "server", "both"]).default("both").describe("Target runtime environment"),
2019
- collection: z31.string().optional().describe("Specific collection name if applicable"),
2020
- includeExample: z31.boolean().default(true).describe("Whether to include a full code example")
2214
+ runtime: z24.enum(["browser", "server", "both"]).default("both").describe("Target runtime environment"),
2215
+ collection: z24.string().optional().describe("Specific collection name if applicable"),
2216
+ includeExample: z24.boolean().default(true).describe("Whether to include a full code example")
2021
2217
  };
2022
- var metadata31 = {
2218
+ var metadata26 = {
2023
2219
  name: "sdk-get-recipe",
2024
2220
  description: "Get a complete SDK code recipe for a specific task. Returns recommended approach, code example, and related documentation links. Use this FIRST when the user asks how to do something with the SDK.",
2025
2221
  annotations: {
@@ -2062,7 +2258,7 @@ function handler2({
2062
2258
  }
2063
2259
 
2064
2260
  // src/tools/sdk-search-docs.ts
2065
- import { z as z32 } from "zod";
2261
+ import { z as z25 } from "zod";
2066
2262
 
2067
2263
  // src/lib/sdk-doc-index.ts
2068
2264
  var docIndex = [
@@ -2237,11 +2433,11 @@ function searchDocs(query, limit = 5) {
2237
2433
  }
2238
2434
 
2239
2435
  // src/tools/sdk-search-docs.ts
2240
- var schema32 = {
2241
- query: z32.string().min(2).describe('Search keyword or phrase (e.g. "infinite scroll", "webhook", "customer login")'),
2242
- limit: z32.number().min(1).max(10).default(5).describe("Maximum results to return (1-10, default: 5)")
2436
+ var schema27 = {
2437
+ query: z25.string().min(2).describe('Search keyword or phrase (e.g. "infinite scroll", "webhook", "customer login")'),
2438
+ limit: z25.number().min(1).max(10).default(5).describe("Maximum results to return (1-10, default: 5)")
2243
2439
  };
2244
- var metadata32 = {
2440
+ var metadata27 = {
2245
2441
  name: "sdk-search-docs",
2246
2442
  description: "Search SDK documentation by keyword. Returns matching topics with summaries and resource links. Use when looking for specific SDK features or patterns.",
2247
2443
  annotations: {
@@ -2276,9 +2472,9 @@ function handler3({
2276
2472
  }
2277
2473
 
2278
2474
  // src/tools/sdk-get-auth-setup.ts
2279
- import { z as z33 } from "zod";
2280
- var schema33 = {
2281
- scenario: z33.enum([
2475
+ import { z as z26 } from "zod";
2476
+ var schema28 = {
2477
+ scenario: z26.enum([
2282
2478
  "browser-client",
2283
2479
  "server-client",
2284
2480
  "customer-auth",
@@ -2287,7 +2483,7 @@ var schema33 = {
2287
2483
  "webhook-verification"
2288
2484
  ]).describe("Authentication scenario")
2289
2485
  };
2290
- var metadata33 = {
2486
+ var metadata28 = {
2291
2487
  name: "sdk-get-auth-setup",
2292
2488
  description: "Get the current authentication setup for a specific scenario. Returns env var names, code snippets, and security notes.",
2293
2489
  annotations: {
@@ -2441,14 +2637,14 @@ function handler4({
2441
2637
  }
2442
2638
 
2443
2639
  // src/tools/sdk-get-collection-pattern.ts
2444
- import { z as z34 } from "zod";
2445
- import { COLLECTIONS as COLLECTIONS9 } from "@01.software/sdk";
2446
- var schema34 = {
2447
- collection: z34.enum(COLLECTIONS9).describe("Collection name"),
2448
- operation: z34.enum(["read", "write", "full-crud"]).default("read").describe("What operations are needed"),
2449
- surface: z34.enum(["query-builder", "react-query", "server-api"]).default("query-builder").describe("Preferred API surface")
2640
+ import { z as z27 } from "zod";
2641
+ import { COLLECTIONS as COLLECTIONS4 } from "@01.software/sdk";
2642
+ var schema29 = {
2643
+ collection: z27.enum(COLLECTIONS4).describe("Collection name"),
2644
+ operation: z27.enum(["read", "write", "full-crud"]).default("read").describe("What operations are needed"),
2645
+ surface: z27.enum(["query-builder", "react-query", "server-api"]).default("query-builder").describe("Preferred API surface")
2450
2646
  };
2451
- var metadata34 = {
2647
+ var metadata29 = {
2452
2648
  name: "sdk-get-collection-pattern",
2453
2649
  description: "Get the recommended CRUD pattern for a specific collection. Returns code examples for the chosen API surface and operation type.",
2454
2650
  annotations: {
@@ -2615,7 +2811,6 @@ function handler5({
2615
2811
  relatedTools: [
2616
2812
  "query-collection",
2617
2813
  "get-collection-by-id",
2618
- ...operation !== "read" ? ["create-collection", "update-collection", "delete-collection"] : [],
2619
2814
  "get-collection-schema"
2620
2815
  ],
2621
2816
  relatedResources: [
@@ -2629,14 +2824,14 @@ function handler5({
2629
2824
  }
2630
2825
 
2631
2826
  // src/prompts/sdk-usage-guide.ts
2632
- import { z as z35 } from "zod";
2633
- var schema35 = {
2634
- goal: z35.string().describe('What the user wants to accomplish (e.g., "query product list", "create order")'),
2635
- runtime: z35.enum(["browser", "server"]).optional().describe("Target runtime: browser (React/Next.js client) or server (Node.js)"),
2636
- surface: z35.enum(["query-builder", "react-query", "customer-api", "server-api"]).optional().describe("Preferred API surface"),
2637
- collection: z35.string().optional().describe("Specific collection if relevant")
2827
+ import { z as z28 } from "zod";
2828
+ var schema30 = {
2829
+ goal: z28.string().describe('What the user wants to accomplish (e.g., "query product list", "create order")'),
2830
+ runtime: z28.enum(["browser", "server"]).optional().describe("Target runtime: browser (React/Next.js client) or server (Node.js)"),
2831
+ surface: z28.enum(["query-builder", "react-query", "customer-api", "server-api"]).optional().describe("Preferred API surface"),
2832
+ collection: z28.string().optional().describe("Specific collection if relevant")
2638
2833
  };
2639
- var metadata35 = {
2834
+ var metadata30 = {
2640
2835
  name: "sdk-usage-guide",
2641
2836
  title: "SDK Usage Guide",
2642
2837
  description: "Provides guidance on how to perform a specific task using the 01.software SDK",
@@ -2773,14 +2968,14 @@ You can perform the "${goal}" task by following the patterns above.`;
2773
2968
  }
2774
2969
 
2775
2970
  // src/prompts/collection-query-help.ts
2776
- import { z as z36 } from "zod";
2777
- import { COLLECTIONS as COLLECTIONS10 } from "@01.software/sdk";
2778
- var schema36 = {
2779
- collection: z36.enum(COLLECTIONS10).describe("Collection name"),
2780
- operation: z36.enum(["find", "create", "update", "delete"]).describe("Operation to perform (find, create, update, delete)"),
2781
- filters: z36.string().optional().describe("Filter conditions (JSON string, optional)")
2971
+ import { z as z29 } from "zod";
2972
+ import { COLLECTIONS as COLLECTIONS5 } from "@01.software/sdk";
2973
+ var schema31 = {
2974
+ collection: z29.enum(COLLECTIONS5).describe("Collection name"),
2975
+ operation: z29.enum(["find", "create", "update", "delete"]).describe("Operation to perform (find, create, update, delete)"),
2976
+ filters: z29.string().optional().describe("Filter conditions (JSON string, optional)")
2782
2977
  };
2783
- var metadata36 = {
2978
+ var metadata31 = {
2784
2979
  name: "collection-query-help",
2785
2980
  title: "Collection Query Help",
2786
2981
  description: "Provides guidance on how to write queries for a specific collection",
@@ -2867,16 +3062,16 @@ ${operation === "find" ? `- Use \`where\` option for filtering (Payload query sy
2867
3062
  }
2868
3063
 
2869
3064
  // src/prompts/order-flow-guide.ts
2870
- import { z as z37 } from "zod";
2871
- var schema37 = {
2872
- scenario: z37.enum([
3065
+ import { z as z30 } from "zod";
3066
+ var schema32 = {
3067
+ scenario: z30.enum([
2873
3068
  "simple-order",
2874
3069
  "cart-checkout",
2875
3070
  "return-refund",
2876
3071
  "fulfillment-tracking"
2877
3072
  ]).describe("Order flow scenario")
2878
3073
  };
2879
- var metadata37 = {
3074
+ var metadata32 = {
2880
3075
  name: "order-flow-guide",
2881
3076
  title: "Order Flow Guide",
2882
3077
  description: "Provides step-by-step guidance for ecommerce order flows including creation, checkout, returns, and fulfillment.",
@@ -2891,8 +3086,8 @@ var SCENARIOS = {
2891
3086
  - Provide: orderNumber, customerSnapshot (email required), shippingAddress, orderItems, totalAmount
2892
3087
  - Optional: pgPaymentId (omit for free orders), shippingAmount, discountCode
2893
3088
 
2894
- 2. **Payment Confirmation** \u2192 \`update-order\` tool
2895
- - Update status to \`paid\` after payment gateway confirms
3089
+ 2. **Payment Confirmation** \u2192 \`update-transaction\` tool
3090
+ - Confirm provider payment with pgPaymentId, paymentKey, and amount
2896
3091
  - Stock is automatically adjusted (stock -= qty, reservedStock += qty)
2897
3092
 
2898
3093
  3. **Fulfillment** \u2192 \`create-fulfillment\` tool
@@ -2919,8 +3114,13 @@ const order = await client.commerce.orders.create({
2919
3114
  pgPaymentId: 'pay_xxx' // omit for free orders
2920
3115
  })
2921
3116
 
2922
- // 2. After payment confirmed
2923
- await client.commerce.orders.update({ orderNumber: 'ORD-240101-001', status: 'paid' })
3117
+ // 2. After payment confirmed by provider
3118
+ await client.commerce.orders.updateTransaction({
3119
+ pgPaymentId: 'pay_xxx',
3120
+ status: 'paid',
3121
+ paymentKey: 'payment_key_xxx',
3122
+ amount: 59800
3123
+ })
2924
3124
 
2925
3125
  // 3. Ship items
2926
3126
  await client.commerce.orders.createFulfillment({
@@ -2938,7 +3138,7 @@ await client.commerce.orders.createFulfillment({
2938
3138
  2. **Apply Discount** (optional) \u2192 \`apply-discount\` tool
2939
3139
  3. **Calculate Shipping** \u2192 \`calculate-shipping\` tool
2940
3140
  4. **Checkout** \u2192 \`checkout\` tool (converts cart to order)
2941
- 5. **Payment** \u2192 \`update-order\` or \`update-transaction\`
3141
+ 5. **Payment** \u2192 \`update-transaction\` for provider-verified paid transitions
2942
3142
 
2943
3143
  ### Key Points
2944
3144
  - Cart has a customer linked \u2014 auto-copied to order on checkout
@@ -2975,7 +3175,7 @@ const order = await client.commerce.orders.checkout({
2975
3175
  1. **Return with Refund** \u2192 \`return-with-refund\` tool
2976
3176
  - Handles return + stock restoration + transaction update in one call
2977
3177
  - Return immediately completed (bypasses FSM)
2978
- - Requires pgPaymentId to identify which transaction to refund
3178
+ - Requires pgPaymentId and paymentKey for provider-verified refund
2979
3179
 
2980
3180
  ### Key Points
2981
3181
  - Full refund: original transaction \u2192 \`canceled\`
@@ -2992,7 +3192,8 @@ await client.commerce.orders.returnWithRefund({
2992
3192
  reasonDetail: 'Product arrived damaged',
2993
3193
  returnItems: [{ orderItem: 'oi-id', quantity: 1 }],
2994
3194
  refundAmount: 29900,
2995
- pgPaymentId: 'pay_xxx'
3195
+ pgPaymentId: 'pay_xxx',
3196
+ paymentKey: 'payment_key_xxx'
2996
3197
  })
2997
3198
  \`\`\``,
2998
3199
  "fulfillment-tracking": `## Fulfillment & Tracking
@@ -3055,9 +3256,9 @@ ${SCENARIOS[scenario] || "Unknown scenario."}
3055
3256
  }
3056
3257
 
3057
3258
  // src/prompts/feature-setup-guide.ts
3058
- import { z as z38 } from "zod";
3059
- var schema38 = {
3060
- feature: z38.enum([
3259
+ import { z as z31 } from "zod";
3260
+ var schema33 = {
3261
+ feature: z31.enum([
3061
3262
  "ecommerce",
3062
3263
  "customers",
3063
3264
  "articles",
@@ -3072,7 +3273,7 @@ var schema38 = {
3072
3273
  "community"
3073
3274
  ]).describe("Feature to get setup guide for")
3074
3275
  };
3075
- var metadata38 = {
3276
+ var metadata33 = {
3076
3277
  name: "feature-setup-guide",
3077
3278
  title: "Feature Setup Guide",
3078
3279
  description: "Setup checklist and remediation guide for a tenant feature. Load before using get-tenant-context to diagnose setup gaps.",
@@ -3085,8 +3286,8 @@ var FEATURES = {
3085
3286
 
3086
3287
  ### Required Collections (count > 0)
3087
3288
 
3088
- 1. **products** \u2014 Use \`create-collection\` with \`collection='products'\`
3089
- - Minimum fields: \`{ title, slug, status: 'active' }\`
3289
+ 1. **products** \u2014 Create via Console UI or SDK \`client.collections.from('products').create({ ... })\`
3290
+ - Minimum fields: \`{ title, slug, status: 'published', _status: 'published' }\`
3090
3291
 
3091
3292
  2. **product-variants** \u2014 At least 1 sellable variant per product
3092
3293
  - Minimum fields: \`{ product, title, price, stock }\`
@@ -3119,7 +3320,7 @@ customer-addresses
3119
3320
 
3120
3321
  ### Optional Collections
3121
3322
 
3122
- customer-groups \u2014 Use \`create-collection\` with \`collection='customer-groups'\`, \`{ title }\`
3323
+ customer-groups \u2014 Create via Console UI or SDK \`client.collections.from('customer-groups').create({ title })\`
3123
3324
 
3124
3325
  ### Config
3125
3326
 
@@ -3158,10 +3359,10 @@ document-categories`,
3158
3359
  ### Required Collections (count > 0)
3159
3360
 
3160
3361
  1. **playlists** \u2014 At least 1 playlist
3161
- - Minimum fields: \`{ title, slug }\`
3362
+ - Minimum fields: \`{ title, slug, status: 'published', _status: 'published' }\`
3162
3363
 
3163
3364
  2. **tracks** \u2014 At least 1 track
3164
- - Minimum fields: \`{ title }\`
3365
+ - Minimum fields: \`{ title, sourceUrl, status: 'published', _status: 'published' }\`
3165
3366
 
3166
3367
  3. **playlists.tracks** \u2014 Link at least 1 track from a playlist
3167
3368
  - Minimum fields: \`{ tracks: [trackId] }\`
@@ -3174,11 +3375,11 @@ playlist-categories, playlist-tags, track-categories, track-tags, track-assets`,
3174
3375
  ### Required Collections (count > 0)
3175
3376
 
3176
3377
  1. **galleries** \u2014 At least 1 gallery
3177
- - Minimum fields: \`{ title, slug }\`
3378
+ - Minimum fields: \`{ title, slug, status: 'published', _status: 'published' }\`
3178
3379
 
3179
3380
  2. **gallery-items** \u2014 At least 1 item per gallery
3180
3381
  - References \`images\` collection (non-upload)
3181
- - Minimum fields: \`{ gallery, image }\`
3382
+ - Minimum fields: \`{ gallery, image, _status: 'published' }\`
3182
3383
 
3183
3384
  ### Optional Collections
3184
3385
 
@@ -3188,7 +3389,7 @@ gallery-categories, gallery-tags`,
3188
3389
  ### Required Collections (count > 0)
3189
3390
 
3190
3391
  1. **links** \u2014 At least 1 link
3191
- - Minimum fields: \`{ title, slug, url }\`
3392
+ - Minimum fields: \`{ title, slug, url, status: 'published', _status: 'published' }\`
3192
3393
 
3193
3394
  ### Optional Collections
3194
3395
 
@@ -3269,12 +3470,12 @@ ${FEATURES[feature] || "Unknown feature."}
3269
3470
 
3270
3471
  ## Related MCP Tools
3271
3472
  - \`get-tenant-context\` \u2014 check current collection counts and feature status
3272
- - \`create-collection\` \u2014 create required collection documents
3273
- - \`query-collection\` \u2014 verify existing documents in a collection`;
3473
+ - \`query-collection\` \u2014 verify existing documents in a collection
3474
+ - \`get-collection-schema\` \u2014 inspect tenant-aware fields before creating data via SDK or Console UI`;
3274
3475
  }
3275
3476
 
3276
3477
  // src/resources/(config)/app.ts
3277
- var metadata39 = {
3478
+ var metadata34 = {
3278
3479
  name: "app-config",
3279
3480
  title: "Application Config",
3280
3481
  description: "01.software SDK and MCP server configuration information"
@@ -3296,16 +3497,13 @@ HTTP MCP uses OAuth discovery and Authorization Code + PKCE.
3296
3497
  url = "https://mcp.01.software/mcp"
3297
3498
  \`\`\`
3298
3499
 
3299
- ## Available Tools (34)
3500
+ ## Available Tools (29)
3501
+
3502
+ > Generic write tools (create/update/delete/update-many/delete-many) are intentionally absent. Use the dedicated workflow tools below or the SDK (\`client.collections.from(slug).create()\` / \`update()\` / \`remove()\` / \`updateMany()\` / \`removeMany()\`) for stateful mutations.
3300
3503
 
3301
- ### Generic CRUD (7)
3504
+ ### Generic Read (2)
3302
3505
  - \`query-collection\` - Query collection with filters, pagination, sorting
3303
3506
  - \`get-collection-by-id\` - Get single item by ID
3304
- - \`create-collection\` - Create new item
3305
- - \`update-collection\` - Update existing item
3306
- - \`delete-collection\` - Delete item (destructive)
3307
- - \`update-many-collection\` - Bulk update items matching filter
3308
- - \`delete-many-collection\` - Bulk delete items matching filter (destructive)
3309
3507
 
3310
3508
  ### Orders (7)
3311
3509
  - \`create-order\` - Create a new order with products and shipping
@@ -3363,80 +3561,86 @@ Rate limits depend on your tenant plan:
3363
3561
  }
3364
3562
 
3365
3563
  // src/resources/(collections)/schema.ts
3366
- import { COLLECTIONS as COLLECTIONS11 } from "@01.software/sdk";
3367
- var metadata40 = {
3564
+ import { COLLECTIONS as COLLECTIONS6 } from "@01.software/sdk";
3565
+ var metadata35 = {
3368
3566
  name: "collections-schema",
3369
3567
  title: "Collection Schema Info",
3370
3568
  description: "Available collections and their schema information"
3371
3569
  };
3570
+ var COLLECTIONS_BY_CATEGORY = {
3571
+ "Tenant Management": ["tenants", "tenant-metadata", "tenant-logos"],
3572
+ Products: [
3573
+ "products",
3574
+ "product-variants",
3575
+ "product-options",
3576
+ "product-option-values",
3577
+ "product-categories",
3578
+ "product-tags",
3579
+ "product-collections"
3580
+ ],
3581
+ Brands: ["brands", "brand-logos"],
3582
+ "Orders & Fulfillment": [
3583
+ "orders",
3584
+ "order-items",
3585
+ "transactions",
3586
+ "fulfillments",
3587
+ "fulfillment-items"
3588
+ ],
3589
+ "Shipping & Returns": ["returns", "return-items", "shipping-policies"],
3590
+ Customers: [
3591
+ "customers",
3592
+ "customer-profiles",
3593
+ "customer-addresses",
3594
+ "customer-groups"
3595
+ ],
3596
+ Carts: ["carts", "cart-items"],
3597
+ "Discounts & Promotions": ["discounts", "promotions"],
3598
+ Documents: ["documents", "document-categories", "document-types"],
3599
+ Articles: ["articles", "article-authors", "article-categories", "article-tags"],
3600
+ Community: [
3601
+ "posts",
3602
+ "comments",
3603
+ "reactions",
3604
+ "reaction-types",
3605
+ "bookmarks",
3606
+ "post-categories",
3607
+ "reports",
3608
+ "community-bans"
3609
+ ],
3610
+ Playlists: [
3611
+ "playlists",
3612
+ "tracks",
3613
+ "playlist-categories",
3614
+ "playlist-tags",
3615
+ "track-categories",
3616
+ "track-tags"
3617
+ ],
3618
+ Galleries: ["galleries", "gallery-items", "gallery-categories", "gallery-tags"],
3619
+ Links: ["links", "link-categories", "link-tags"],
3620
+ Canvas: [
3621
+ "canvases",
3622
+ "canvas-node-types",
3623
+ "canvas-edge-types",
3624
+ "canvas-categories",
3625
+ "canvas-tags",
3626
+ "canvas-nodes",
3627
+ "canvas-edges"
3628
+ ],
3629
+ Videos: ["videos", "video-categories", "video-tags"],
3630
+ "Live Streams": ["live-streams"],
3631
+ Images: ["images"],
3632
+ Forms: ["forms", "form-submissions"],
3633
+ Events: [
3634
+ "event-calendars",
3635
+ "events",
3636
+ "event-categories",
3637
+ "event-occurrences",
3638
+ "event-tags"
3639
+ ]
3640
+ };
3372
3641
  function handler7() {
3373
- const collectionsByCategory = {
3374
- "Tenant Management": ["tenants", "tenant-metadata", "tenant-logos"],
3375
- Products: [
3376
- "products",
3377
- "product-variants",
3378
- "product-options",
3379
- "product-categories",
3380
- "product-tags",
3381
- "product-collections"
3382
- ],
3383
- Brands: ["brands", "brand-logos"],
3384
- "Orders & Fulfillment": [
3385
- "orders",
3386
- "order-items",
3387
- "transactions",
3388
- "fulfillments",
3389
- "fulfillment-items"
3390
- ],
3391
- "Shipping & Returns": [
3392
- "returns",
3393
- "return-items",
3394
- "shipping-policies"
3395
- ],
3396
- Customers: ["customers", "customer-addresses", "customer-groups"],
3397
- Carts: ["carts", "cart-items"],
3398
- Discounts: ["discounts"],
3399
- Documents: ["documents", "document-categories", "document-types"],
3400
- Articles: ["articles", "article-authors", "article-categories", "article-tags"],
3401
- Community: [
3402
- "posts",
3403
- "comments",
3404
- "reactions",
3405
- "reaction-types",
3406
- "bookmarks",
3407
- "post-categories",
3408
- "reports",
3409
- "community-bans"
3410
- ],
3411
- Playlists: [
3412
- "playlists",
3413
- "tracks",
3414
- "track-assets",
3415
- "playlist-categories",
3416
- "playlist-tags",
3417
- "track-categories",
3418
- "track-tags"
3419
- ],
3420
- Galleries: [
3421
- "galleries",
3422
- "gallery-items",
3423
- "gallery-categories",
3424
- "gallery-tags"
3425
- ],
3426
- Canvas: [
3427
- "canvases",
3428
- "canvas-node-types",
3429
- "canvas-edge-types",
3430
- "canvas-categories",
3431
- "canvas-tags"
3432
- ],
3433
- Videos: ["videos", "video-categories", "video-tags"],
3434
- "Live Streams": ["live-streams"],
3435
- Images: ["images"],
3436
- Forms: ["forms", "form-submissions"]
3437
- };
3438
- const categoryDocs = Object.entries(collectionsByCategory).map(([category, collections]) => {
3439
- const collectionList = collections.filter((c) => COLLECTIONS11.includes(c)).map((c) => `- **${c}**`).join("\n");
3642
+ const categoryDocs = Object.entries(COLLECTIONS_BY_CATEGORY).map(([category, collections]) => {
3643
+ const collectionList = collections.filter((c) => COLLECTIONS6.includes(c)).map((c) => `- **${c}**`).join("\n");
3440
3644
  return `## ${category}
3441
3645
  ${collectionList}`;
3442
3646
  }).join("\n\n");
@@ -3457,6 +3661,9 @@ Each collection supports the following operations:
3457
3661
  - \`updateMany(where, data)\` - Bulk update items matching filter
3458
3662
  - \`removeMany(where)\` - Bulk delete items matching filter
3459
3663
 
3664
+ Draft-enabled public collections expose only \`_status: 'published'\` rows to
3665
+ publishable-key reads unless server-side access explicitly includes drafts.
3666
+
3460
3667
  ## Query Examples
3461
3668
 
3462
3669
  ### Filtering
@@ -3478,11 +3685,11 @@ Each collection supports the following operations:
3478
3685
  }
3479
3686
  \`\`\`
3480
3687
 
3481
- Total available collections: ${COLLECTIONS11.length}`;
3688
+ Total available collections: ${COLLECTIONS6.length}`;
3482
3689
  }
3483
3690
 
3484
3691
  // src/resources/(docs)/getting-started.ts
3485
- var metadata41 = {
3692
+ var metadata36 = {
3486
3693
  name: "docs-getting-started",
3487
3694
  title: "Getting Started",
3488
3695
  description: "01.software SDK getting started guide"
@@ -3527,7 +3734,7 @@ const result = await client.collections.from('products').find({
3527
3734
  }
3528
3735
 
3529
3736
  // src/resources/(docs)/guides.ts
3530
- var metadata42 = {
3737
+ var metadata37 = {
3531
3738
  name: "docs-guides",
3532
3739
  title: "Guides",
3533
3740
  description: "01.software SDK usage guides"
@@ -3738,7 +3945,7 @@ For more detailed guides, see the [Guides page](/docs/guides).`;
3738
3945
  }
3739
3946
 
3740
3947
  // src/resources/(docs)/api.ts
3741
- var metadata43 = {
3948
+ var metadata38 = {
3742
3949
  name: "docs-api",
3743
3950
  title: "API Reference",
3744
3951
  description: "01.software SDK API reference documentation"
@@ -4024,7 +4231,7 @@ For more details, see the [full API documentation](/docs/api).`;
4024
4231
  }
4025
4232
 
4026
4233
  // src/resources/(docs)/query-builder.ts
4027
- var metadata44 = {
4234
+ var metadata39 = {
4028
4235
  name: "docs-query-builder",
4029
4236
  title: "Query Builder",
4030
4237
  description: "01.software SDK Query Builder API reference (client.collections.from)"
@@ -4218,7 +4425,7 @@ console.log(result.hasNextPage) // true
4218
4425
  }
4219
4426
 
4220
4427
  // src/resources/(docs)/react-query.ts
4221
- var metadata45 = {
4428
+ var metadata40 = {
4222
4429
  name: "docs-react-query",
4223
4430
  title: "React Query Hooks",
4224
4431
  description: "01.software SDK React Query hooks reference (client.query)"
@@ -4466,7 +4673,7 @@ export function ProductList() {
4466
4673
  }
4467
4674
 
4468
4675
  // src/resources/(docs)/server-api.ts
4469
- var metadata46 = {
4676
+ var metadata41 = {
4470
4677
  name: "docs-server-api",
4471
4678
  title: "Server-side API",
4472
4679
  description: "01.software SDK server-side API reference (client.commerce) for orders, fulfillments, returns, carts, and validation"
@@ -4607,7 +4814,7 @@ const ret = await client.commerce.orders.updateReturn({
4607
4814
  \`\`\`
4608
4815
 
4609
4816
  ### returnWithRefund()
4610
- Create a return and process refund in one atomic operation.
4817
+ Create a return and process a provider-verified refund in one atomic operation.
4611
4818
 
4612
4819
  \`\`\`typescript
4613
4820
  const result = await client.commerce.orders.returnWithRefund({
@@ -4619,6 +4826,7 @@ const result = await client.commerce.orders.returnWithRefund({
4619
4826
  ],
4620
4827
  refundAmount: 29900,
4621
4828
  pgPaymentId: 'toss-payment-id', // required
4829
+ paymentKey: 'toss-payment-key', // required for provider refund
4622
4830
  refundReceiptUrl?: 'https://...',
4623
4831
  })
4624
4832
  \`\`\`
@@ -4626,12 +4834,15 @@ const result = await client.commerce.orders.returnWithRefund({
4626
4834
  ## Transaction API
4627
4835
 
4628
4836
  ### updateTransaction()
4629
- Update a transaction status (after PG callback).
4837
+ Confirm or annotate a transaction. Paid transitions require provider
4838
+ verification; non-financial annotations can still update pending transactions.
4630
4839
 
4631
4840
  \`\`\`typescript
4632
4841
  const tx = await client.commerce.orders.updateTransaction({
4633
4842
  pgPaymentId: 'toss-payment-id',
4634
- status: 'paid', // paid | failed | canceled
4843
+ status: 'paid', // pending | paid | failed | canceled
4844
+ paymentKey: 'toss-payment-key', // required when status is paid
4845
+ amount: 29900, // required when status is paid
4635
4846
  })
4636
4847
  \`\`\`
4637
4848
 
@@ -4724,7 +4935,7 @@ const result = await client.commerce.shipping.calculate({
4724
4935
  }
4725
4936
 
4726
4937
  // src/resources/(docs)/customer-auth.ts
4727
- var metadata47 = {
4938
+ var metadata42 = {
4728
4939
  name: "docs-customer-auth",
4729
4940
  title: "Customer Auth API",
4730
4941
  description: "01.software SDK Customer Auth API reference (client.customer)"
@@ -4902,7 +5113,7 @@ async function loadProfile() {
4902
5113
  }
4903
5114
 
4904
5115
  // src/resources/(docs)/browser-vs-server.ts
4905
- var metadata48 = {
5116
+ var metadata43 = {
4906
5117
  name: "docs-browser-vs-server",
4907
5118
  title: "Client vs ServerClient",
4908
5119
  description: "When to use Client (createClient) vs ServerClient (createServerClient) in the 01.software SDK"
@@ -5061,7 +5272,7 @@ export function ProductList() {
5061
5272
  }
5062
5273
 
5063
5274
  // src/resources/(docs)/file-upload.ts
5064
- var metadata49 = {
5275
+ var metadata44 = {
5065
5276
  name: "docs-file-upload",
5066
5277
  title: "File Upload",
5067
5278
  description: "01.software SDK file upload patterns using the images collection"
@@ -5212,7 +5423,7 @@ The platform stores files in Cloudflare R2 and serves via CDN (\`cdn.01.software
5212
5423
  }
5213
5424
 
5214
5425
  // src/resources/(docs)/webhook.ts
5215
- var metadata50 = {
5426
+ var metadata45 = {
5216
5427
  name: "docs-webhook",
5217
5428
  title: "Webhooks",
5218
5429
  description: "01.software SDK webhook verification and event handling"
@@ -5326,28 +5537,54 @@ Configure webhook URLs in the 01.software console under Tenant Settings > Webhoo
5326
5537
  }
5327
5538
 
5328
5539
  // src/server.ts
5329
- function registerTool(server, schema39, meta, handler18) {
5540
+ var REGISTERED_TOOLS_BY_SERVER = /* @__PURE__ */ new WeakMap();
5541
+ function registerTool(server, schema34, meta, handler18) {
5542
+ let registered = REGISTERED_TOOLS_BY_SERVER.get(server);
5543
+ if (!registered) {
5544
+ registered = /* @__PURE__ */ new Set();
5545
+ REGISTERED_TOOLS_BY_SERVER.set(server, registered);
5546
+ }
5547
+ registered.add(meta.name);
5330
5548
  server.registerTool(
5331
5549
  meta.name,
5332
5550
  {
5333
5551
  description: meta.description,
5334
- inputSchema: schema39,
5552
+ inputSchema: schema34,
5335
5553
  annotations: meta.annotations
5336
5554
  },
5337
5555
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5338
5556
  async (params) => {
5557
+ const ctx = tenantAuthContext();
5558
+ if (ctx) {
5559
+ const decision = evaluateToolPolicy(meta.name, ctx.scopes);
5560
+ if (!decision.allowed) {
5561
+ const status = decision.reason === "insufficient_scope" ? 403 : 500;
5562
+ return {
5563
+ content: [
5564
+ {
5565
+ type: "text",
5566
+ text: toolError({
5567
+ status,
5568
+ reason: decision.reason,
5569
+ message: decision.message
5570
+ })
5571
+ }
5572
+ ]
5573
+ };
5574
+ }
5575
+ }
5339
5576
  const result = await handler18(params);
5340
5577
  return { content: [{ type: "text", text: result }] };
5341
5578
  }
5342
5579
  );
5343
5580
  }
5344
- function registerPrompt(server, schema39, meta, handler18) {
5581
+ function registerPrompt(server, schema34, meta, handler18) {
5345
5582
  server.registerPrompt(
5346
5583
  meta.name,
5347
5584
  {
5348
5585
  title: meta.title,
5349
5586
  description: meta.description,
5350
- argsSchema: schema39
5587
+ argsSchema: schema34
5351
5588
  },
5352
5589
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5353
5590
  (params) => ({
@@ -5383,61 +5620,62 @@ function createServer(options = {}) {
5383
5620
  if (toolSurface === "full") {
5384
5621
  registerTool(server, schema, metadata, queryCollection);
5385
5622
  registerTool(server, schema2, metadata2, getCollectionById);
5386
- registerTool(server, schema3, metadata3, createCollection);
5387
- registerTool(server, schema4, metadata4, updateCollection);
5388
- registerTool(server, schema5, metadata5, deleteCollection);
5389
- registerTool(server, schema6, metadata6, deleteManyCollection);
5390
- registerTool(server, schema7, metadata7, updateManyCollection);
5391
- registerTool(server, schema8, metadata8, getOrder);
5392
- registerTool(server, schema9, metadata9, createOrder);
5393
- registerTool(server, schema10, metadata10, updateOrder);
5394
- registerTool(server, schema11, metadata11, checkout);
5395
- registerTool(server, schema12, metadata12, createFulfillment);
5396
- registerTool(server, schema13, metadata13, updateFulfillment);
5397
- registerTool(server, schema14, metadata14, updateTransaction);
5398
- registerTool(server, schema15, metadata15, createReturn);
5399
- registerTool(server, schema16, metadata16, updateReturn);
5400
- registerTool(server, schema17, metadata17, returnWithRefund);
5401
- registerTool(server, schema18, metadata18, addCartItem);
5402
- registerTool(server, schema19, metadata19, updateCartItem);
5403
- registerTool(server, schema20, metadata20, removeCartItem);
5404
- registerTool(server, schema21, metadata21, applyDiscount);
5405
- registerTool(server, schema22, metadata22, removeDiscount);
5406
- registerTool(server, schema23, metadata23, clearCart);
5407
- registerTool(server, schema24, metadata24, validateDiscount);
5408
- registerTool(server, schema25, metadata25, calculateShipping);
5409
- registerTool(server, schema26, metadata26, stockCheck);
5623
+ registerTool(server, schema3, metadata3, getOrder);
5624
+ registerTool(server, schema4, metadata4, createOrder);
5625
+ registerTool(server, schema5, metadata5, updateOrder);
5626
+ registerTool(server, schema6, metadata6, checkout);
5627
+ registerTool(server, schema7, metadata7, createFulfillment);
5628
+ registerTool(server, schema8, metadata8, updateFulfillment);
5629
+ registerTool(server, schema9, metadata9, updateTransaction);
5630
+ registerTool(server, schema10, metadata10, createReturn);
5631
+ registerTool(server, schema11, metadata11, updateReturn);
5632
+ registerTool(server, schema12, metadata12, returnWithRefund);
5633
+ registerTool(server, schema13, metadata13, addCartItem);
5634
+ registerTool(server, schema14, metadata14, updateCartItem);
5635
+ registerTool(server, schema15, metadata15, removeCartItem);
5636
+ registerTool(server, schema16, metadata16, applyDiscount);
5637
+ registerTool(server, schema17, metadata17, removeDiscount);
5638
+ registerTool(server, schema18, metadata18, clearCart);
5639
+ registerTool(server, schema19, metadata19, validateDiscount);
5640
+ registerTool(server, schema20, metadata20, calculateShipping);
5641
+ registerTool(server, schema21, metadata21, stockCheck);
5410
5642
  }
5411
- registerTool(server, schema27, metadata27, getCollectionSchemaTool);
5412
- registerTool(server, schema28, metadata28, handler);
5413
- registerTool(server, schema29, metadata29, listConfigurableFields);
5414
- registerTool(server, schema30, metadata30, updateFieldConfig);
5415
- registerTool(server, schema31, metadata31, handler2);
5416
- registerTool(server, schema32, metadata32, handler3);
5417
- registerTool(server, schema33, metadata33, handler4);
5418
- registerTool(server, schema34, metadata34, handler5);
5419
- registerPrompt(server, schema35, metadata35, sdkUsageGuide);
5420
- registerPrompt(server, schema36, metadata36, collectionQueryHelp);
5421
- registerPrompt(server, schema37, metadata37, orderFlowGuide);
5422
- registerPrompt(server, schema38, metadata38, featureSetupGuide);
5423
- registerStaticResource(server, "config://app", metadata39, handler6);
5424
- registerStaticResource(server, "collections://schema", metadata40, handler7);
5425
- registerStaticResource(server, "docs://sdk/getting-started", metadata41, handler8);
5426
- registerStaticResource(server, "docs://sdk/guides", metadata42, handler9);
5427
- registerStaticResource(server, "docs://sdk/api", metadata43, handler10);
5428
- registerStaticResource(server, "docs://sdk/query-builder", metadata44, handler11);
5429
- registerStaticResource(server, "docs://sdk/react-query", metadata45, handler12);
5430
- registerStaticResource(server, "docs://sdk/server-api", metadata46, handler13);
5431
- registerStaticResource(server, "docs://sdk/customer-auth", metadata47, handler14);
5432
- registerStaticResource(server, "docs://sdk/browser-vs-server", metadata48, handler15);
5433
- registerStaticResource(server, "docs://sdk/file-upload", metadata49, handler16);
5434
- registerStaticResource(server, "docs://sdk/webhook", metadata50, handler17);
5643
+ registerTool(server, schema22, metadata22, getCollectionSchemaTool);
5644
+ registerTool(server, schema23, metadata23, handler);
5645
+ registerTool(server, schema24, metadata24, listConfigurableFields);
5646
+ registerTool(server, schema25, metadata25, updateFieldConfig);
5647
+ registerTool(server, schema26, metadata26, handler2);
5648
+ registerTool(server, schema27, metadata27, handler3);
5649
+ registerTool(server, schema28, metadata28, handler4);
5650
+ registerTool(server, schema29, metadata29, handler5);
5651
+ registerPrompt(server, schema30, metadata30, sdkUsageGuide);
5652
+ registerPrompt(server, schema31, metadata31, collectionQueryHelp);
5653
+ registerPrompt(server, schema32, metadata32, orderFlowGuide);
5654
+ registerPrompt(server, schema33, metadata33, featureSetupGuide);
5655
+ registerStaticResource(server, "config://app", metadata34, handler6);
5656
+ registerStaticResource(server, "collections://schema", metadata35, handler7);
5657
+ registerStaticResource(server, "docs://sdk/getting-started", metadata36, handler8);
5658
+ registerStaticResource(server, "docs://sdk/guides", metadata37, handler9);
5659
+ registerStaticResource(server, "docs://sdk/api", metadata38, handler10);
5660
+ registerStaticResource(server, "docs://sdk/query-builder", metadata39, handler11);
5661
+ registerStaticResource(server, "docs://sdk/react-query", metadata40, handler12);
5662
+ registerStaticResource(server, "docs://sdk/server-api", metadata41, handler13);
5663
+ registerStaticResource(server, "docs://sdk/customer-auth", metadata42, handler14);
5664
+ registerStaticResource(server, "docs://sdk/browser-vs-server", metadata43, handler15);
5665
+ registerStaticResource(server, "docs://sdk/file-upload", metadata44, handler16);
5666
+ registerStaticResource(server, "docs://sdk/webhook", metadata45, handler17);
5435
5667
  return server;
5436
5668
  }
5437
5669
 
5438
5670
  export {
5671
+ MCP_RESOURCE_AUDIENCE,
5672
+ MCP_OAUTH_ISSUER,
5673
+ MCP_PROTECTED_RESOURCE_METADATA_PATH,
5674
+ MCP_TENANT_CLAIM,
5675
+ MCP_TENANT_ROLE_CLAIM,
5676
+ MCP_SCOPES,
5439
5677
  requestContext,
5440
5678
  mcpServicePublicJwks,
5441
5679
  createServer
5442
5680
  };
5443
- //# sourceMappingURL=chunk-45ZCPS57.js.map
5681
+ //# sourceMappingURL=chunk-GJOQ4SE2.js.map