@payloadcms/plugin-mcp 4.0.0-internal.fa183d3 → 4.0.0-internal.fec2230

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/dist/endpoint/access.js +2 -2
  2. package/dist/endpoint/access.js.map +1 -1
  3. package/dist/mcp/buildMcpServer.d.ts +1 -1
  4. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  5. package/dist/mcp/buildMcpServer.js +35 -23
  6. package/dist/mcp/buildMcpServer.js.map +1 -1
  7. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  8. package/dist/mcp/builtin/collections/authTools.js +79 -56
  9. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  10. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
  11. package/dist/mcp/builtin/collections/countTool.js +9 -14
  12. package/dist/mcp/builtin/collections/countTool.js.map +1 -1
  13. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
  14. package/dist/mcp/builtin/collections/countVersionsTool.js +9 -13
  15. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
  16. package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
  17. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  18. package/dist/mcp/builtin/collections/createTool.js +104 -63
  19. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  20. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  21. package/dist/mcp/builtin/collections/deleteTool.js +44 -43
  22. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  23. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
  24. package/dist/mcp/builtin/collections/duplicateTool.js +31 -37
  25. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  26. package/dist/mcp/builtin/collections/fileInput.d.ts +21 -13
  27. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -1
  28. package/dist/mcp/builtin/collections/fileInput.js +52 -64
  29. package/dist/mcp/builtin/collections/fileInput.js.map +1 -1
  30. package/dist/mcp/builtin/collections/fileInput.spec.js +20 -6
  31. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -1
  32. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
  33. package/dist/mcp/builtin/collections/findDistinctTool.js +11 -26
  34. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
  35. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  36. package/dist/mcp/builtin/collections/findTool.js +27 -45
  37. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  38. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
  39. package/dist/mcp/builtin/collections/findVersionByIDTool.js +17 -26
  40. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
  41. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
  42. package/dist/mcp/builtin/collections/findVersionsTool.js +16 -30
  43. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
  44. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  45. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +15 -14
  46. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  47. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
  48. package/dist/mcp/builtin/collections/restoreVersionTool.js +14 -26
  49. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  50. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  51. package/dist/mcp/builtin/collections/updateTool.js +58 -90
  52. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  53. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  54. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  55. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  56. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  57. package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
  58. package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
  59. package/dist/mcp/builtin/formatEntityError.js +55 -0
  60. package/dist/mcp/builtin/formatEntityError.js.map +1 -0
  61. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  62. package/dist/mcp/builtin/getConfigInfoTool.js +3 -2
  63. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  64. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
  65. package/dist/mcp/builtin/globals/countVersionsTool.js +9 -13
  66. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
  67. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  68. package/dist/mcp/builtin/globals/findTool.js +10 -16
  69. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  70. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
  71. package/dist/mcp/builtin/globals/findVersionByIDTool.js +13 -24
  72. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
  73. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
  74. package/dist/mcp/builtin/globals/findVersionsTool.js +13 -29
  75. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
  76. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  77. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +11 -11
  78. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  79. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
  80. package/dist/mcp/builtin/globals/restoreVersionTool.js +15 -22
  81. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
  82. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  83. package/dist/mcp/builtin/globals/updateTool.js +27 -36
  84. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  85. package/dist/mcp/builtinTools.d.ts +6 -0
  86. package/dist/mcp/builtinTools.d.ts.map +1 -1
  87. package/dist/mcp/builtinTools.js +9 -3
  88. package/dist/mcp/builtinTools.js.map +1 -1
  89. package/dist/mcp/sanitizeMCPConfig.js +4 -1
  90. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  91. package/dist/stdio.d.ts.map +1 -1
  92. package/dist/stdio.js +2 -1
  93. package/dist/stdio.js.map +1 -1
  94. package/dist/types.d.ts +4 -4
  95. package/dist/types.d.ts.map +1 -1
  96. package/dist/types.js.map +1 -1
  97. package/package.json +5 -7
  98. package/src/endpoint/access.ts +2 -3
  99. package/src/mcp/buildMcpServer.ts +39 -29
  100. package/src/mcp/builtin/collections/authTools.ts +77 -69
  101. package/src/mcp/builtin/collections/countTool.ts +9 -21
  102. package/src/mcp/builtin/collections/countVersionsTool.ts +9 -18
  103. package/src/mcp/builtin/collections/createTool.ts +110 -86
  104. package/src/mcp/builtin/collections/deleteTool.ts +36 -64
  105. package/src/mcp/builtin/collections/duplicateTool.ts +35 -85
  106. package/src/mcp/builtin/collections/fileInput.spec.ts +20 -6
  107. package/src/mcp/builtin/collections/fileInput.ts +64 -76
  108. package/src/mcp/builtin/collections/findDistinctTool.ts +11 -63
  109. package/src/mcp/builtin/collections/findTool.ts +23 -105
  110. package/src/mcp/builtin/collections/findVersionByIDTool.ts +15 -58
  111. package/src/mcp/builtin/collections/findVersionsTool.ts +14 -85
  112. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +16 -12
  113. package/src/mcp/builtin/collections/restoreVersionTool.ts +14 -56
  114. package/src/mcp/builtin/collections/updateTool.ts +57 -111
  115. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  116. package/src/mcp/builtin/formatEntityError.ts +77 -0
  117. package/src/mcp/builtin/getConfigInfoTool.ts +2 -1
  118. package/src/mcp/builtin/globals/countVersionsTool.ts +9 -17
  119. package/src/mcp/builtin/globals/findTool.ts +12 -51
  120. package/src/mcp/builtin/globals/findVersionByIDTool.ts +13 -52
  121. package/src/mcp/builtin/globals/findVersionsTool.ts +14 -92
  122. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +10 -10
  123. package/src/mcp/builtin/globals/restoreVersionTool.ts +14 -45
  124. package/src/mcp/builtin/globals/updateTool.ts +37 -60
  125. package/src/mcp/builtinTools.ts +9 -2
  126. package/src/mcp/sanitizeMCPConfig.ts +4 -1
  127. package/src/stdio.ts +2 -1
  128. package/src/types.ts +4 -4
  129. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
  130. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
  131. package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
  132. package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
  133. package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
  134. package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
  135. package/dist/mcp/builtin/validateEntityData.js +0 -82
  136. package/dist/mcp/builtin/validateEntityData.js.map +0 -1
  137. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  138. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  139. package/dist/utils/getVirtualFieldNames.js +0 -35
  140. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  141. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +0 -28
  142. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +0 -1
  143. package/dist/utils/schemaConversion/filterFieldsByAccess.js +0 -71
  144. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +0 -1
  145. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -13
  146. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
  147. package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -66
  148. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
  149. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -10
  150. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
  151. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -384
  152. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
  153. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -133
  154. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
  155. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  156. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  157. package/dist/utils/transformPointDataToPayload.js +0 -28
  158. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  159. package/dist/utils/whereSchema.d.ts +0 -9
  160. package/dist/utils/whereSchema.d.ts.map +0 -1
  161. package/dist/utils/whereSchema.js +0 -13
  162. package/dist/utils/whereSchema.js.map +0 -1
  163. package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
  164. package/src/mcp/builtin/validateEntityData.ts +0 -132
  165. package/src/utils/getVirtualFieldNames.ts +0 -53
  166. package/src/utils/schemaConversion/filterFieldsByAccess.ts +0 -123
  167. package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -96
  168. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -96
  169. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -432
  170. package/src/utils/transformPointDataToPayload.ts +0 -40
  171. package/src/utils/whereSchema.ts +0 -24
@@ -1,11 +1,10 @@
1
- import { z } from 'zod';
1
+ import { findVersionsInputSchema } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { whereSchema } from '../../../utils/whereSchema.js';
6
5
  const DEFAULT_DESCRIPTION = 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.';
7
6
  export const findVersionsTool = defineCollectionTool({
8
- access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),
9
8
  annotations: {
10
9
  destructiveHint: false,
11
10
  idempotentHint: true,
@@ -14,36 +13,26 @@ export const findVersionsTool = defineCollectionTool({
14
13
  title: 'Find Versions'
15
14
  },
16
15
  description: DEFAULT_DESCRIPTION,
17
- input: z.object({
18
- depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in version documents').optional().default(0),
19
- fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
20
- limit: z.number().int().min(1).max(100).describe('Maximum number of versions to return (default: 10, max: 100)').optional().default(10),
21
- locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
22
- page: z.number().int().min(1).describe('Page number for pagination (default: 1)').optional().default(1),
23
- pagination: z.boolean().describe('Optional: set to false to skip the count query overhead').optional(),
24
- populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
25
- select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.title": true}').optional(),
26
- showHiddenFields: z.boolean().describe('Optional: include hidden fields in returned version documents').optional(),
27
- sort: z.string().describe('Field to sort by (e.g., "-updatedAt", "-version.updatedAt" for descending)').optional(),
28
- trash: z.boolean().describe('Optional: include versions for soft-deleted documents when trash is enabled').optional(),
29
- where: whereSchema.describe('Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.title":{"contains":"test"}}').optional()
30
- })
31
- }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
16
+ input: findVersionsInputSchema
17
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
32
18
  const payload = req.payload;
33
19
  const logger = getLogger({
34
20
  payload
35
21
  });
36
- const { depth, fallbackLocale, limit, locale, page, pagination, populate, select, showHiddenFields, sort, trash, where } = input;
37
- logger.info(`Finding versions in collection: ${collectionSlug}, limit: ${limit}, page: ${page}`);
22
+ const { depth, draft, fallbackLocale, limit, locale, page, pagination, populate, select, sort, trash, where } = input;
23
+ logger.info(`Finding versions in collection: ${slug}, limit: ${limit}, page: ${page}`);
38
24
  try {
39
25
  const result = await payload.findVersions({
40
- collection: collectionSlug,
26
+ collection: slug,
41
27
  depth,
42
28
  limit,
43
29
  overrideAccess: authorizedMCP.overrideAccess,
44
30
  page,
45
31
  req,
46
- ...fallbackLocale ? {
32
+ ...draft !== undefined ? {
33
+ draft
34
+ } : {},
35
+ ...fallbackLocale !== undefined ? {
47
36
  fallbackLocale
48
37
  } : {},
49
38
  ...locale ? {
@@ -53,13 +42,10 @@ export const findVersionsTool = defineCollectionTool({
53
42
  pagination
54
43
  } : {},
55
44
  ...populate ? {
56
- populate: populate
45
+ populate
57
46
  } : {},
58
47
  ...select ? {
59
- select: select
60
- } : {},
61
- ...showHiddenFields !== undefined ? {
62
- showHiddenFields
48
+ select
63
49
  } : {},
64
50
  ...sort ? {
65
51
  sort
@@ -75,19 +61,19 @@ export const findVersionsTool = defineCollectionTool({
75
61
  content: [
76
62
  {
77
63
  type: 'text',
78
- text: `Versions for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
64
+ text: `Versions for collection "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
79
65
  }
80
66
  ],
81
67
  doc: result
82
68
  };
83
69
  } catch (error) {
84
70
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
85
- logger.error(`Error finding versions in ${collectionSlug}: ${errorMessage}`);
71
+ logger.error(`Error finding versions in ${slug}: ${errorMessage}`);
86
72
  return {
87
73
  content: [
88
74
  {
89
75
  type: 'text',
90
- text: `❌ **Error finding versions in collection "${collectionSlug}":** ${errorMessage}`
76
+ text: `❌ **Error finding versions in collection "${slug}":** ${errorMessage}`
91
77
  }
92
78
  ],
93
79
  isError: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.'\n\nexport const findVersionsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) &&\n Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Versions',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in version documents')\n .optional()\n .default(0),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of versions to return (default: 10, max: 100)')\n .optional()\n .default(10),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n )\n .optional(),\n page: z\n .number()\n .int()\n .min(1)\n .describe('Page number for pagination (default: 1)')\n .optional()\n .default(1),\n pagination: z\n .boolean()\n .describe('Optional: set to false to skip the count query overhead')\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\n )\n .optional(),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"version.title\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in returned version documents')\n .optional(),\n sort: z\n .string()\n .describe('Field to sort by (e.g., \"-updatedAt\", \"-version.updatedAt\" for descending)')\n .optional(),\n trash: z\n .boolean()\n .describe('Optional: include versions for soft-deleted documents when trash is enabled')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering versions. Version document fields are usually under \"version\". Example: {\"version.title\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const {\n depth,\n fallbackLocale,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n showHiddenFields,\n sort,\n trash,\n where,\n } = input\n\n logger.info(`Finding versions in collection: ${collectionSlug}, limit: ${limit}, page: ${page}`)\n\n try {\n const result = await payload.findVersions({\n collection: collectionSlug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(pagination !== undefined ? { pagination } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n ...(sort ? { sort } : {}),\n ...(trash !== undefined ? { trash } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Versions for collection \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding versions in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding versions in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","whereSchema","DEFAULT_DESCRIPTION","findVersionsTool","access","args","Boolean","permissions","collections","collectionSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","depth","number","int","min","max","describe","optional","default","fallbackLocale","string","limit","locale","page","pagination","boolean","populate","record","unknown","select","showHiddenFields","sort","trash","where","handler","authorizedMCP","req","payload","logger","info","result","findVersions","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,mBAAmBJ,qBAAqB;IACnDK,QAAQ,CAACC,OACPP,cAAcO,SACdC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IAChEC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,OAAOvB,EACJwB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJC,QAAQ,CAAC,uEACTC,QAAQ,GACRC,OAAO,CAAC;QACXC,gBAAgB/B,EACbgC,MAAM,GACNJ,QAAQ,CAAC,gFACTC,QAAQ;QACXI,OAAOjC,EACJwB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,KACJC,QAAQ,CAAC,gEACTC,QAAQ,GACRC,OAAO,CAAC;QACXI,QAAQlC,EACLgC,MAAM,GACNJ,QAAQ,CACP,wHAEDC,QAAQ;QACXM,MAAMnC,EACHwB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJE,QAAQ,CAAC,2CACTC,QAAQ,GACRC,OAAO,CAAC;QACXM,YAAYpC,EACTqC,OAAO,GACPT,QAAQ,CAAC,2DACTC,QAAQ;QACXS,UAAUtC,EACPuC,MAAM,CAACvC,EAAEgC,MAAM,IAAIhC,EAAEwC,OAAO,IAC5BZ,QAAQ,CACP,8FAEDC,QAAQ;QACXY,QAAQz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Bc,YAAY;gBAAEd;YAAiB,IAAI,CAAC,CAAC;YAC9D,GAAIC,OAAO;gBAAEA;YAAK,IAAI,CAAC,CAAC;YACxB,GAAIC,UAAUY,YAAY;gBAAEZ;YAAM,IAAI,CAAC,CAAC;YACxC,GAAIC,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLY,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,yBAAyB,EAAE/C,eAAe,gBAAgB,EAAEgD,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBACrG;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,0BAA0B,EAAEnD,eAAe,EAAE,EAAEoD,cAAc;QAC3E,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,0CAA0C,EAAE/C,eAAe,KAAK,EAAEoD,cAAc;gBACzF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"sourcesContent":["import { findVersionsInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.'\n\nexport const findVersionsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Versions',\n },\n description: DEFAULT_DESCRIPTION,\n input: findVersionsInputSchema,\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const {\n depth,\n draft,\n fallbackLocale,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n sort,\n trash,\n where,\n } = input\n\n logger.info(`Finding versions in collection: ${slug}, limit: ${limit}, page: ${page}`)\n\n try {\n const result = await payload.findVersions({\n collection: slug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(draft !== undefined ? { draft } : {}),\n ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(pagination !== undefined ? { pagination } : {}),\n ...(populate ? { populate } : {}),\n ...(select ? { select } : {}),\n ...(sort ? { sort } : {}),\n ...(trash !== undefined ? { trash } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Versions for collection \"${slug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding versions in ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding versions in collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["findVersionsInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findVersionsTool","access","args","Boolean","permissions","collections","slug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","depth","draft","fallbackLocale","limit","locale","page","pagination","populate","select","sort","trash","where","info","result","findVersions","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAAA,SAASA,uBAAuB,QAAQ,UAAS;AAEjD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,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AAM,IAAI,CAAC,CAAC;YACxC,GAAIC,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLO,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,yBAAyB,EAAEnC,KAAK,gBAAgB,EAAEoC,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBAC3F;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9D5B,OAAOyB,KAAK,CAAC,CAAC,0BAA0B,EAAEvC,KAAK,EAAE,EAAEwC,cAAc;QACjE,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,0CAA0C,EAAEnC,KAAK,KAAK,EAAEwC,cAAc;gBAC/E;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,uBAAuB,4CAqElC,CAAA"}
1
+ {"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,uBAAuB,4CA0ElC,CAAA"}
@@ -1,10 +1,9 @@
1
- import { getAccessResults } from 'payload';
1
+ import { getAccessResults, getCollectionInputSchema, getCollectionSchemaInputSchema } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
- import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
5
4
  export const getCollectionSchemaTool = defineCollectionTool({
6
5
  access: (args)=>{
7
- const permissions = args.permissions?.collections?.[args.collectionSlug];
6
+ const permissions = args.permissions?.collections?.[args.slug];
8
7
  return defaultAccess(args) && Boolean(permissions?.create || permissions?.update);
9
8
  },
10
9
  annotations: {
@@ -14,24 +13,25 @@ export const getCollectionSchemaTool = defineCollectionTool({
14
13
  readOnlyHint: true,
15
14
  title: 'Get Collection Schema'
16
15
  },
17
- description: 'Get the input schema for creating or updating documents in a collection.'
18
- }).handler(async ({ authorizedMCP, collectionSlug, req })=>{
16
+ description: 'Get the input schema for creating or updating documents in a collection.',
17
+ input: getCollectionSchemaInputSchema
18
+ }).handler(async ({ slug, authorizedMCP, req })=>{
19
19
  const permissions = authorizedMCP.overrideAccess ? null : (await getAccessResults({
20
20
  req
21
- })).collections?.[collectionSlug];
21
+ })).collections?.[slug];
22
22
  if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {
23
23
  return {
24
24
  content: [
25
25
  {
26
26
  type: 'text',
27
- text: `Error: MCP access to "getCollectionSchema" is not enabled for collection "${collectionSlug}"`
27
+ text: `Error: MCP access to "getCollectionSchema" is not enabled for collection "${slug}"`
28
28
  }
29
29
  ],
30
30
  isError: true
31
31
  };
32
32
  }
33
33
  const inputSchema = getCollectionInputSchema({
34
- collectionSlug,
34
+ collectionSlug: slug,
35
35
  req,
36
36
  ...permissions ? {
37
37
  permissions
@@ -42,13 +42,13 @@ export const getCollectionSchemaTool = defineCollectionTool({
42
42
  content: [
43
43
  {
44
44
  type: 'text',
45
- text: `Error: Collection "${collectionSlug}" not found`
45
+ text: `Error: Collection "${slug}" not found`
46
46
  }
47
47
  ],
48
48
  isError: true
49
49
  };
50
50
  }
51
- const uploadConfig = req.payload.collections[collectionSlug]?.config.upload;
51
+ const uploadConfig = req.payload.collections[slug]?.config.upload;
52
52
  const maxFileSize = req.payload.config.upload.limits?.fileSize;
53
53
  const upload = uploadConfig ? {
54
54
  enabled: true,
@@ -58,9 +58,10 @@ export const getCollectionSchemaTool = defineCollectionTool({
58
58
  ],
59
59
  sources: [
60
60
  ...uploadConfig.pasteURL !== false ? [
61
- 'url'
61
+ 'externalURL'
62
62
  ] : [],
63
- 'base64'
63
+ 'base64',
64
+ 'uploadReference'
64
65
  ],
65
66
  ...typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? {
66
67
  maxFileSize
@@ -72,11 +73,11 @@ export const getCollectionSchemaTool = defineCollectionTool({
72
73
  content: [
73
74
  {
74
75
  type: 'text',
75
- text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``
76
+ text: `Schema for collection "${slug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``
76
77
  }
77
78
  ],
78
79
  structuredContent: {
79
- collectionSlug,
80
+ slug,
80
81
  schema: inputSchema,
81
82
  upload
82
83
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"sourcesContent":["import { getAccessResults } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nexport const getCollectionSchemaTool = defineCollectionTool({\n access: (args) => {\n const permissions = args.permissions?.collections?.[args.collectionSlug]\n\n return defaultAccess(args) && Boolean(permissions?.create || permissions?.update)\n },\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Get Collection Schema',\n },\n description: 'Get the input schema for creating or updating documents in a collection.',\n}).handler(async ({ authorizedMCP, collectionSlug, req }) => {\n const permissions = authorizedMCP.overrideAccess\n ? null\n : (await getAccessResults({ req })).collections?.[collectionSlug]\n\n if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: MCP access to \"getCollectionSchema\" is not enabled for collection \"${collectionSlug}\"`,\n },\n ],\n isError: true,\n }\n }\n\n const inputSchema = getCollectionInputSchema({\n collectionSlug,\n req,\n ...(permissions ? { permissions } : {}),\n })\n\n if (!inputSchema) {\n return {\n content: [{ type: 'text', text: `Error: Collection \"${collectionSlug}\" not found` }],\n isError: true,\n }\n }\n\n const uploadConfig = req.payload.collections[collectionSlug]?.config.upload\n const maxFileSize = req.payload.config.upload.limits?.fileSize\n const upload = uploadConfig\n ? {\n enabled: true,\n filesRequiredOnCreate: uploadConfig.filesRequiredOnCreate !== false,\n mimeTypes: uploadConfig.mimeTypes ?? ['*/*'],\n sources: [...(uploadConfig.pasteURL !== false ? ['url'] : []), 'base64'],\n ...(typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? { maxFileSize } : {}),\n }\n : { enabled: false }\n\n return {\n content: [\n {\n type: 'text',\n text: `Schema for collection \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(inputSchema)}\\n\\`\\`\\`\\nUpload configuration:\\n\\`\\`\\`json\\n${JSON.stringify(upload)}\\n\\`\\`\\``,\n },\n ],\n structuredContent: {\n collectionSlug,\n schema: inputSchema,\n upload,\n },\n }\n})\n"],"names":["getAccessResults","defaultAccess","defineCollectionTool","getCollectionInputSchema","getCollectionSchemaTool","access","args","permissions","collections","collectionSlug","Boolean","create","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","handler","authorizedMCP","req","overrideAccess","content","type","text","isError","inputSchema","uploadConfig","payload","config","upload","maxFileSize","limits","fileSize","enabled","filesRequiredOnCreate","mimeTypes","sources","pasteURL","Number","isFinite","JSON","stringify","structuredContent","schema"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,UAAS;AAE1C,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,wBAAwB,QAAQ,0DAAyD;AAElG,OAAO,MAAMC,0BAA0BF,qBAAqB;IAC1DG,QAAQ,CAACC;QACP,MAAMC,cAAcD,KAAKC,WAAW,EAAEC,a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ACxE,GAAI,OAAOP,gBAAgB,YAAYQ,OAAOC,QAAQ,CAACT,eAAe;YAAEA;QAAY,IAAI,CAAC,CAAC;IAC5F,IACA;QAAEG,SAAS;IAAM;IAErB,OAAO;QACLZ,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,uBAAuB,EAAEjB,eAAe,gBAAgB,EAAEkC,KAAKC,SAAS,CAAChB,aAAa,6CAA6C,EAAEe,KAAKC,SAAS,CAACZ,QAAQ,QAAQ,CAAC;YAC9K;SACD;QACDa,mBAAmB;YACjBpC;YACAqC,QAAQlB;YACRI;QACF;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"sourcesContent":["import { getAccessResults, getCollectionInputSchema, getCollectionSchemaInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\n\nexport const getCollectionSchemaTool = defineCollectionTool({\n access: (args) => {\n const permissions = args.permissions?.collections?.[args.slug]\n\n return defaultAccess(args) && Boolean(permissions?.create || permissions?.update)\n },\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Get Collection Schema',\n },\n description: 'Get the input schema for creating or updating documents in a collection.',\n input: getCollectionSchemaInputSchema,\n}).handler(async ({ slug, authorizedMCP, req }) => {\n const permissions = authorizedMCP.overrideAccess\n ? null\n : (await getAccessResults({ req })).collections?.[slug]\n\n if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: MCP access to \"getCollectionSchema\" is not enabled for collection \"${slug}\"`,\n },\n ],\n isError: true,\n }\n }\n\n const inputSchema = getCollectionInputSchema({\n collectionSlug: slug,\n req,\n ...(permissions ? { permissions } : {}),\n })\n\n if (!inputSchema) {\n return {\n content: [{ type: 'text', text: `Error: Collection \"${slug}\" not found` }],\n isError: true,\n }\n }\n\n const uploadConfig = req.payload.collections[slug]?.config.upload\n const maxFileSize = req.payload.config.upload.limits?.fileSize\n const upload = uploadConfig\n ? {\n enabled: true,\n filesRequiredOnCreate: uploadConfig.filesRequiredOnCreate !== false,\n mimeTypes: uploadConfig.mimeTypes ?? ['*/*'],\n sources: [\n ...(uploadConfig.pasteURL !== false ? ['externalURL'] : []),\n 'base64',\n 'uploadReference',\n ],\n ...(typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? { maxFileSize } : {}),\n }\n : { enabled: false }\n\n return {\n content: [\n {\n type: 'text',\n text: `Schema for collection \"${slug}\":\\n\\`\\`\\`json\\n${JSON.stringify(inputSchema)}\\n\\`\\`\\`\\nUpload configuration:\\n\\`\\`\\`json\\n${JSON.stringify(upload)}\\n\\`\\`\\``,\n },\n ],\n structuredContent: {\n slug,\n schema: inputSchema,\n upload,\n },\n }\n})\n"],"names":["getAccessResults","getCollectionInputSchema","getCollectionSchemaInputSchema","defaultAccess","defineCollectionTool","getCollectionSchemaTool","access","args","permissions","collections","slug","Boolean","create","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","overrideAccess","content","type","text","isError","inputSchema","collectionSlug","uploadConfig","payload","config","upload","maxFileSize","limits","fileSize","enabled","filesRequiredOnCreate","mimeTypes","sources","pasteURL","Number","isFinite","JSON","stringify","structuredContent","schema"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,wBAAwB,EAAEC,8BAA8B,QAAQ,UAAS;AAEpG,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAE7D,OAAO,MAAMC,0BAA0BD,qBAAqB;IAC1DE,QAAQ,CAACC;QACP,MAAMC,cAAcD,KAAKC,WAAW,EAAEC,aAAa,CAACF,KAAKG,IAAI,CAAC;QAE9D,OAAOP,cAAcI,SAASI,QAAQH,aAAaI,UAAUJ,aAAaK;IAC5E;IACAC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QA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A;QAAEG,SAAS;IAAM;IAErB,OAAO;QACLb,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,uBAAuB,EAAElB,KAAK,gBAAgB,EAAEoC,KAAKC,SAAS,CAACjB,aAAa,6CAA6C,EAAEgB,KAAKC,SAAS,CAACZ,QAAQ,QAAQ,CAAC;YACpK;SACD;QACDa,mBAAmB;YACjBtC;YACAuC,QAAQnB;YACRK;QACF;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,kBAAkB,4CA+F7B,CAAA"}
1
+ {"version":3,"file":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,kBAAkB,4CAuD7B,CAAA"}
@@ -1,10 +1,10 @@
1
- import { z } from 'zod';
1
+ import { restoreVersionInputSchema } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
5
  const DEFAULT_DESCRIPTION = 'Restore a document from a previous version in any version-enabled collection.';
6
6
  export const restoreVersionTool = defineCollectionTool({
7
- access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),
8
8
  annotations: {
9
9
  destructiveHint: true,
10
10
  idempotentHint: false,
@@ -13,64 +13,52 @@ export const restoreVersionTool = defineCollectionTool({
13
13
  title: 'Restore Version'
14
14
  },
15
15
  description: DEFAULT_DESCRIPTION,
16
- input: z.object({
17
- id: z.string().describe('The ID of the version to restore'),
18
- depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in response').optional().default(0),
19
- draft: z.boolean().describe('Whether to restore the version as a draft').optional().default(false),
20
- fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
21
- locale: z.string().describe('Optional: locale code to restore in (e.g., "en", "es")').optional(),
22
- populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
23
- select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}').optional(),
24
- showHiddenFields: z.boolean().describe('Optional: include hidden fields in the restored document response').optional()
25
- })
26
- }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
16
+ input: restoreVersionInputSchema
17
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
27
18
  const payload = req.payload;
28
19
  const logger = getLogger({
29
20
  payload
30
21
  });
31
- const { id, depth, draft, fallbackLocale, locale, populate, select, showHiddenFields } = input;
32
- logger.info(`Restoring version in collection: ${collectionSlug} with ID: ${id}`);
22
+ const { id, depth, draft, fallbackLocale, locale, populate, select } = input;
23
+ logger.info(`Restoring version in collection: ${slug} with ID: ${id}`);
33
24
  try {
34
25
  const result = await payload.restoreVersion({
35
- id,
36
- collection: collectionSlug,
26
+ id: String(id),
27
+ collection: slug,
37
28
  depth,
38
29
  draft,
39
30
  overrideAccess: authorizedMCP.overrideAccess,
40
31
  req,
41
- ...fallbackLocale ? {
32
+ ...fallbackLocale !== undefined ? {
42
33
  fallbackLocale
43
34
  } : {},
44
35
  ...locale ? {
45
36
  locale
46
37
  } : {},
47
38
  ...populate ? {
48
- populate: populate
39
+ populate
49
40
  } : {},
50
41
  ...select ? {
51
- select: select
52
- } : {},
53
- ...showHiddenFields !== undefined ? {
54
- showHiddenFields
42
+ select
55
43
  } : {}
56
44
  });
57
45
  return {
58
46
  content: [
59
47
  {
60
48
  type: 'text',
61
- text: `Version "${id}" restored successfully in collection "${collectionSlug}"!\nRestored document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
49
+ text: `Version "${id}" restored successfully in collection "${slug}"!\nRestored document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
62
50
  }
63
51
  ],
64
52
  doc: result
65
53
  };
66
54
  } catch (error) {
67
55
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
68
- logger.error(`Error restoring version ${id} in ${collectionSlug}: ${errorMessage}`);
56
+ logger.error(`Error restoring version ${id} in ${slug}: ${errorMessage}`);
69
57
  return {
70
58
  content: [
71
59
  {
72
60
  type: 'text',
73
- text: `❌ **Error restoring version "${id}" in collection "${collectionSlug}":** ${errorMessage}`
61
+ text: `❌ **Error restoring version "${id}" in collection "${slug}":** ${errorMessage}`
74
62
  }
75
63
  ],
76
64
  isError: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Restore a document from a previous version in any version-enabled collection.'\n\nexport const restoreVersionTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Restore Version',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.string().describe('The ID of the version to restore'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in response')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe('Whether to restore the version as a draft')\n .optional()\n .default(false),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n locale: z\n .string()\n .describe('Optional: locale code to restore in (e.g., \"en\", \"es\")')\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\n )\n .optional(),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"title\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the restored document response')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, draft, fallbackLocale, locale, populate, select, showHiddenFields } = input\n\n logger.info(`Restoring version in collection: ${collectionSlug} with ID: ${id}`)\n\n try {\n const result = await payload.restoreVersion({\n id,\n collection: collectionSlug,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" restored successfully in collection \"${collectionSlug}\"!\\nRestored document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error restoring version ${id} in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error restoring version \"${id}\" in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","restoreVersionTool","access","args","Boolean","permissions","collections","collectionSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","string","describe","depth","number","int","min","max","optional","default","draft","boolean","fallbackLocale","locale","populate","record","unknown","select","showHiddenFields","handler","authorizedMCP","req","payload","logger","info","result","restoreVersion","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message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ACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"sourcesContent":["import { restoreVersionInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Restore a document from a previous version in any version-enabled collection.'\n\nexport const restoreVersionTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Restore Version',\n },\n description: DEFAULT_DESCRIPTION,\n input: restoreVersionInputSchema,\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, draft, fallbackLocale, locale, populate, select } = input\n\n logger.info(`Restoring version in collection: ${slug} with ID: ${id}`)\n\n try {\n const result = await payload.restoreVersion({\n id: String(id),\n collection: slug,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate } : {}),\n ...(select ? { select } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" restored successfully in collection \"${slug}\"!\\nRestored document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error restoring version ${id} in ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error restoring version \"${id}\" in collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["restoreVersionInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","restoreVersionTool","access","args","Boolean","permissions","collections","slug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","id","depth","draft","fallbackLocale","locale","populate","select","info","result","restoreVersion","String","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,UAAS;AAEnD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBH,qBAAqB;IACrDI,QAAQ,CAACC,OACPN,cAAcM,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI,CAAC,EAAEC;IAC7EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOpB;AACT,GAAGqB,OAAO,CAAC,OAAO,EAAEV,IAAI,EAAEW,aAAa,EAAEF,KAAK,EAAEG,GAAG,EAAE;IACnD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAAStB,UAAU;QAAEqB;IAAQ;IACnC,MAAM,EAAEE,EAAE,EAAEC,KAAK,EAAEC,KAAK,EAAEC,cAAc,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGZ;IAEvEK,OAAOQ,IAAI,CAAC,CAAC,iCAAiC,EAAEtB,KAAK,UAAU,EAAEe,IAAI;IAErE,IAAI;QACF,MAAMQ,SAAS,MAAMV,QAAQW,cAAc,CAAC;YAC1CT,IAAIU,OAAOV;YACXW,YAAY1B;YACZgB;YACAC;YACAU,gBAAgBhB,cAAcgB,cAAc;YAC5Cf;YACA,GAAIM,mBAAmBU,YAAY;gBAAEV;YAAe,IAAI,CAAC,CAAC;YAC1D,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAIC,WAAW;gBAAEA;YAAS,IAAI,CAAC,CAAC;YAChC,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;QAC9B;QAEA,OAAO;YACLQ,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,SAAS,EAAEhB,GAAG,uCAAuC,EAAEf,KAAK,oCAAoC,EAAEgC,KAAKC,SAAS,CAACV,QAAQ,QAAQ,CAAC;gBAC3I;aACD;YACDW,KAAKX;QACP;IACF,EAAE,OAAOY,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DxB,OAAOqB,KAAK,CAAC,CAAC,wBAAwB,EAAEpB,GAAG,IAAI,EAAEf,KAAK,EAAE,EAAEoC,cAAc;QACxE,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6BAA6B,EAAEhB,GAAG,iBAAiB,EAAEf,KAAK,KAAK,EAAEoC,cAAc;gBACxF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,kBAAkB,4CA6M7B,CAAA"}
1
+ {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,kBAAkB,4CAuJ7B,CAAA"}
@@ -1,17 +1,12 @@
1
- import { z } from 'zod';
1
+ import { getCollectionInputSchema, getCollectionVirtualFieldNames, parseDocumentID, stripVirtualFields, transformPointDataToPayload, updateDocumentInputSchema, validateCollectionData } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { getCollectionVirtualFieldNames, stripVirtualFields } from '../../../utils/getVirtualFieldNames.js';
6
- import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
7
- import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js';
8
- import { whereSchema } from '../../../utils/whereSchema.js';
9
- import { validateCollectionData } from '../validateEntityData.js';
10
- import { fileInputSchema, resolveFileInput } from './fileInput.js';
11
- import { formatCollectionError } from './formatCollectionError.js';
12
- const DEFAULT_DESCRIPTION = 'Update documents in any collection by passing the collection slug and data.';
5
+ import { formatEntityError } from '../formatEntityError.js';
6
+ import { fileInputSchema, resolveFile } from './fileInput.js';
7
+ const DEFAULT_DESCRIPTION = 'Update documents. Prefer uploadReference after upload, externalURL for URLs, or base64 for small local files.';
13
8
  export const updateDocumentTool = defineCollectionTool({
14
- access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),
9
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),
15
10
  annotations: {
16
11
  destructiveHint: true,
17
12
  idempotentHint: false,
@@ -20,136 +15,108 @@ export const updateDocumentTool = defineCollectionTool({
20
15
  title: 'Update Document'
21
16
  },
22
17
  description: DEFAULT_DESCRIPTION,
23
- input: z.object({
24
- id: z.union([
25
- z.string(),
26
- z.number()
27
- ]).describe('The ID of the document to update').optional(),
28
- data: z.record(z.string(), z.unknown()).describe('The fields to update. Only include fields permitted by the schema returned by getCollectionSchema.'),
29
- depth: z.number().describe('How many levels deep to populate relationships').optional().default(0),
30
- draft: z.boolean().describe('Only if getCollectionSchema includes _status; otherwise _status does not exist. true saves only a draft version; false updates main and versions. data._status: "published" overrides true.').optional().default(false),
31
- fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
32
- file: fileInputSchema.optional(),
33
- locale: z.string().describe('Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale').optional(),
34
- overrideLock: z.boolean().describe('Whether to override document locks').optional().default(true),
35
- overwriteExistingFiles: z.boolean().describe('Whether to overwrite existing files').optional().default(false),
36
- publishAllLocales: z.boolean().describe('For collections with localized publishing status, whether publishing should affect every locale. Set false with locale to publish only that locale.').optional(),
37
- select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}').optional(),
38
- where: whereSchema.describe('Where clause to update multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
18
+ input: updateDocumentInputSchema({
19
+ file: fileInputSchema
39
20
  })
40
- }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
21
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
41
22
  const payload = req.payload;
42
23
  const logger = getLogger({
43
24
  payload
44
25
  });
45
- const { id, data, depth, draft, fallbackLocale, file: fileInput, locale, overrideLock, overwriteExistingFiles, publishAllLocales, select, where } = input;
46
- logger.info(`Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
26
+ const { id, data, depth, draft, fallbackLocale, file: fileInput, limit, locale, overrideLock, populate, publishAllLocales, returning, select, sort, trash, unpublishAllLocales, where } = input;
27
+ logger.info(`Updating document in collection: ${slug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
47
28
  try {
48
- if (!id && !where) {
49
- return {
50
- content: [
51
- {
52
- type: 'text',
53
- text: 'Error: Either id or where clause must be provided'
54
- }
55
- ]
56
- };
57
- }
58
- const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug);
29
+ const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, slug);
59
30
  const inputData = stripVirtualFields(data, virtualFieldNames);
60
- const validationError = validateCollectionData({
61
- collectionSlug,
31
+ validateCollectionData({
32
+ slug,
62
33
  data: inputData,
63
34
  partial: true,
64
35
  req
65
36
  });
66
- if (validationError) {
67
- return validationError;
68
- }
69
37
  const parsedData = transformPointDataToPayload(inputData);
70
- const file = await resolveFileInput({
71
- collectionSlug,
38
+ const file = await resolveFile({
39
+ slug,
72
40
  input: fileInput,
73
41
  req
74
42
  });
75
43
  const whereClause = where ?? {};
76
- if (id) {
44
+ if (id !== undefined) {
77
45
  const result = await payload.update({
78
- id,
79
- collection: collectionSlug,
46
+ id: parseDocumentID({
47
+ id,
48
+ collectionSlug: slug,
49
+ payload
50
+ }),
51
+ collection: slug,
80
52
  data: parsedData,
81
53
  depth,
82
54
  draft,
55
+ fallbackLocale,
56
+ locale,
83
57
  overrideAccess: authorizedMCP.overrideAccess,
84
58
  overrideLock,
59
+ populate,
60
+ publishAllLocales,
85
61
  req,
62
+ select: returning ? select : {
63
+ id: true
64
+ },
65
+ trash,
66
+ unpublishAllLocales,
86
67
  ...file ? {
87
68
  file
88
- } : {},
89
- ...overwriteExistingFiles ? {
90
- overwriteExistingFiles
91
- } : {},
92
- ...publishAllLocales !== undefined ? {
93
- publishAllLocales
94
- } : {},
95
- ...locale ? {
96
- locale
97
- } : {},
98
- ...fallbackLocale ? {
99
- fallbackLocale
100
- } : {},
101
- ...select ? {
102
- select: select
103
69
  } : {}
104
70
  });
71
+ const responseResult = returning ? result : {
72
+ id: result.id
73
+ };
105
74
  return {
106
75
  content: [
107
76
  {
108
77
  type: 'text',
109
- text: `Document updated successfully in collection "${collectionSlug}"!\nUpdated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
78
+ text: `Document updated successfully in collection "${slug}"!\nResult:\n\`\`\`json\n${JSON.stringify(responseResult)}\n\`\`\``
110
79
  }
111
80
  ],
112
- doc: result
81
+ doc: responseResult
113
82
  };
114
83
  }
115
84
  const result = await payload.update({
116
- collection: collectionSlug,
85
+ collection: slug,
117
86
  data: parsedData,
118
87
  depth,
119
88
  draft,
89
+ fallbackLocale,
90
+ limit,
91
+ locale,
120
92
  overrideAccess: authorizedMCP.overrideAccess,
121
93
  overrideLock,
94
+ populate,
95
+ publishAllLocales,
122
96
  req,
97
+ select: returning ? select : {
98
+ id: true
99
+ },
100
+ sort,
101
+ trash,
102
+ unpublishAllLocales,
123
103
  where: whereClause,
124
104
  ...file ? {
125
105
  file
126
- } : {},
127
- ...overwriteExistingFiles ? {
128
- overwriteExistingFiles
129
- } : {},
130
- ...publishAllLocales !== undefined ? {
131
- publishAllLocales
132
- } : {},
133
- ...locale ? {
134
- locale
135
- } : {},
136
- ...fallbackLocale ? {
137
- fallbackLocale
138
- } : {},
139
- ...select ? {
140
- select: select
141
106
  } : {}
142
107
  });
143
- const docs = result.docs || [];
108
+ const docs = returning ? result.docs : result.docs.map(({ id })=>({
109
+ id
110
+ }));
144
111
  const errors = result.errors || [];
145
- let responseText = `Multiple documents updated in collection "${collectionSlug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`;
112
+ let responseText = `Multiple documents updated in collection "${slug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`;
146
113
  if (docs.length > 0) {
147
114
  responseText += `\n\nUpdated documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``;
148
115
  }
149
116
  if (errors.length > 0) {
150
117
  responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``;
151
118
  const errorSchema = getCollectionInputSchema({
152
- collectionSlug,
119
+ collectionSlug: slug,
153
120
  req
154
121
  });
155
122
  if (errorSchema) {
@@ -169,7 +136,7 @@ export const updateDocumentTool = defineCollectionTool({
169
136
  isError: true,
170
137
  ...errorSchema ? {
171
138
  structuredContent: {
172
- collectionSlug,
139
+ slug,
173
140
  docs,
174
141
  errors,
175
142
  schema: errorSchema
@@ -191,10 +158,11 @@ export const updateDocumentTool = defineCollectionTool({
191
158
  };
192
159
  } catch (error) {
193
160
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
194
- logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`);
195
- return formatCollectionError({
161
+ logger.error(`Error updating document in ${slug}: ${errorMessage}`);
162
+ return formatEntityError({
163
+ slug,
196
164
  action: 'updating',
197
- collectionSlug,
165
+ entity: 'collection',
198
166
  error,
199
167
  req
200
168
  });