@payloadcms/plugin-mcp 4.0.0-internal.1f9ae9a → 4.0.0-internal.2fddfc0

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 (227) hide show
  1. package/dist/@types/assets.d.js +2 -0
  2. package/dist/@types/assets.d.js.map +1 -0
  3. package/dist/defaultAccess.d.ts +3 -0
  4. package/dist/defaultAccess.d.ts.map +1 -0
  5. package/dist/defaultAccess.js +3 -0
  6. package/dist/defaultAccess.js.map +1 -0
  7. package/dist/endpoint/access.d.ts +17 -5
  8. package/dist/endpoint/access.d.ts.map +1 -1
  9. package/dist/endpoint/access.js +82 -88
  10. package/dist/endpoint/access.js.map +1 -1
  11. package/dist/endpoint/index.d.ts.map +1 -1
  12. package/dist/endpoint/index.js +11 -0
  13. package/dist/endpoint/index.js.map +1 -1
  14. package/dist/exports/client.d.ts +1 -1
  15. package/dist/exports/client.d.ts.map +1 -1
  16. package/dist/exports/client.js +1 -1
  17. package/dist/exports/client.js.map +1 -1
  18. package/dist/exports/internal.d.ts +2 -0
  19. package/dist/exports/internal.d.ts.map +1 -0
  20. package/dist/exports/internal.js +3 -0
  21. package/dist/exports/internal.js.map +1 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +13 -18
  24. package/dist/index.js.map +1 -1
  25. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  26. package/dist/mcp/buildMcpServer.js +102 -64
  27. package/dist/mcp/buildMcpServer.js.map +1 -1
  28. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  29. package/dist/mcp/builtin/collections/authTools.js +44 -6
  30. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  31. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  32. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  33. package/dist/mcp/builtin/collections/countTool.js +69 -0
  34. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  35. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  36. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  37. package/dist/mcp/builtin/collections/countVersionsTool.js +65 -0
  38. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  39. package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
  40. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  41. package/dist/mcp/builtin/collections/createTool.js +38 -38
  42. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  43. package/dist/mcp/builtin/collections/deleteTool.d.ts +1 -1
  44. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  45. package/dist/mcp/builtin/collections/deleteTool.js +14 -20
  46. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  47. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  48. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  49. package/dist/mcp/builtin/collections/duplicateTool.js +97 -0
  50. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  51. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  52. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  53. package/dist/mcp/builtin/collections/findDistinctTool.js +93 -0
  54. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  55. package/dist/mcp/builtin/collections/findTool.d.ts +1 -1
  56. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  57. package/dist/mcp/builtin/collections/findTool.js +49 -43
  58. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  59. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  60. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  61. package/dist/mcp/builtin/collections/findVersionByIDTool.js +84 -0
  62. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  63. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  64. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  65. package/dist/mcp/builtin/collections/findVersionsTool.js +99 -0
  66. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  67. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
  68. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
  69. package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
  70. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
  71. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
  72. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
  73. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +47 -0
  74. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
  75. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  76. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  77. package/dist/mcp/builtin/collections/restoreVersionTool.js +82 -0
  78. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  79. package/dist/mcp/builtin/collections/updateTool.d.ts +1 -1
  80. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  81. package/dist/mcp/builtin/collections/updateTool.js +87 -82
  82. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  83. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  84. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  85. package/dist/mcp/builtin/getConfigInfoTool.js +71 -0
  86. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  87. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  88. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  89. package/dist/mcp/builtin/globals/countVersionsTool.js +65 -0
  90. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  91. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  92. package/dist/mcp/builtin/globals/findTool.js +18 -21
  93. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  94. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  95. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  96. package/dist/mcp/builtin/globals/findVersionByIDTool.js +80 -0
  97. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  98. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  99. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  100. package/dist/mcp/builtin/globals/findVersionsTool.js +95 -0
  101. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  102. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  103. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  104. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +47 -0
  105. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  106. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  107. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  108. package/dist/mcp/builtin/globals/restoreVersionTool.js +78 -0
  109. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  110. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  111. package/dist/mcp/builtin/globals/updateTool.js +31 -36
  112. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  113. package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
  114. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
  115. package/dist/mcp/builtin/validateEntityData.js +82 -0
  116. package/dist/mcp/builtin/validateEntityData.js.map +1 -0
  117. package/dist/mcp/builtinTools.d.ts +144 -19
  118. package/dist/mcp/builtinTools.d.ts.map +1 -1
  119. package/dist/mcp/builtinTools.js +119 -20
  120. package/dist/mcp/builtinTools.js.map +1 -1
  121. package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
  122. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  123. package/dist/mcp/sanitizeMCPConfig.js +120 -58
  124. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  125. package/dist/stdio.d.ts +3 -2
  126. package/dist/stdio.d.ts.map +1 -1
  127. package/dist/stdio.js +27 -8
  128. package/dist/stdio.js.map +1 -1
  129. package/dist/types.d.ts +62 -108
  130. package/dist/types.d.ts.map +1 -1
  131. package/dist/types.js +4 -4
  132. package/dist/types.js.map +1 -1
  133. package/dist/utils/getPluginConfig.d.ts +1 -1
  134. package/dist/utils/getPluginConfig.js +1 -1
  135. package/dist/utils/getPluginConfig.js.map +1 -1
  136. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +11 -0
  137. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
  138. package/dist/utils/schemaConversion/getEntityInputSchema.js +34 -0
  139. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
  140. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +15 -0
  141. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
  142. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +464 -0
  143. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
  144. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +158 -0
  145. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
  146. package/dist/utils/whereSchema.d.ts +9 -0
  147. package/dist/utils/whereSchema.d.ts.map +1 -0
  148. package/dist/utils/whereSchema.js +13 -0
  149. package/dist/utils/whereSchema.js.map +1 -0
  150. package/package.json +8 -11
  151. package/src/@types/assets.d.ts +3 -0
  152. package/src/defaultAccess.ts +3 -0
  153. package/src/endpoint/access.ts +88 -101
  154. package/src/endpoint/index.ts +14 -1
  155. package/src/exports/client.ts +2 -1
  156. package/src/exports/internal.ts +1 -0
  157. package/src/index.ts +8 -16
  158. package/src/mcp/buildMcpServer.ts +130 -90
  159. package/src/mcp/builtin/collections/authTools.ts +45 -9
  160. package/src/mcp/builtin/collections/countTool.ts +74 -0
  161. package/src/mcp/builtin/collections/countVersionsTool.ts +70 -0
  162. package/src/mcp/builtin/collections/createTool.ts +55 -59
  163. package/src/mcp/builtin/collections/deleteTool.ts +19 -16
  164. package/src/mcp/builtin/collections/duplicateTool.ts +135 -0
  165. package/src/mcp/builtin/collections/findDistinctTool.ts +120 -0
  166. package/src/mcp/builtin/collections/findTool.ts +63 -33
  167. package/src/mcp/builtin/collections/findVersionByIDTool.ts +110 -0
  168. package/src/mcp/builtin/collections/findVersionsTool.ts +155 -0
  169. package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
  170. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +46 -0
  171. package/src/mcp/builtin/collections/restoreVersionTool.ts +108 -0
  172. package/src/mcp/builtin/collections/updateTool.ts +111 -105
  173. package/src/mcp/builtin/getConfigInfoTool.ts +69 -0
  174. package/src/mcp/builtin/globals/countVersionsTool.ts +69 -0
  175. package/src/mcp/builtin/globals/findTool.ts +26 -17
  176. package/src/mcp/builtin/globals/findVersionByIDTool.ts +104 -0
  177. package/src/mcp/builtin/globals/findVersionsTool.ts +148 -0
  178. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +41 -0
  179. package/src/mcp/builtin/globals/restoreVersionTool.ts +100 -0
  180. package/src/mcp/builtin/globals/updateTool.ts +50 -53
  181. package/src/mcp/builtin/validateEntityData.ts +132 -0
  182. package/src/mcp/builtinTools.ts +111 -41
  183. package/src/mcp/sanitizeMCPConfig.ts +116 -78
  184. package/src/stdio.ts +23 -8
  185. package/src/types.ts +77 -112
  186. package/src/utils/getPluginConfig.ts +1 -1
  187. package/src/utils/schemaConversion/getEntityInputSchema.ts +78 -0
  188. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +103 -0
  189. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +529 -0
  190. package/src/utils/whereSchema.ts +24 -0
  191. package/dist/collection/getAccessField.d.ts +0 -12
  192. package/dist/collection/getAccessField.d.ts.map +0 -1
  193. package/dist/collection/getAccessField.js +0 -57
  194. package/dist/collection/getAccessField.js.map +0 -1
  195. package/dist/collection/index.d.ts +0 -6
  196. package/dist/collection/index.d.ts.map +0 -1
  197. package/dist/collection/index.js +0 -59
  198. package/dist/collection/index.js.map +0 -1
  199. package/dist/components/AccessField/index.client.d.ts +0 -10
  200. package/dist/components/AccessField/index.client.d.ts.map +0 -1
  201. package/dist/components/AccessField/index.client.js +0 -305
  202. package/dist/components/AccessField/index.client.js.map +0 -1
  203. package/dist/components/AccessField/index.css +0 -93
  204. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +0 -7
  205. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +0 -1
  206. package/dist/utils/schemaConversion/prepareCollectionSchema.js +0 -37
  207. package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +0 -1
  208. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
  209. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
  210. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
  211. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
  212. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
  213. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
  214. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -56
  215. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
  216. package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
  217. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
  218. package/dist/utils/schemaConversion/transformPointFields.js +0 -57
  219. package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
  220. package/src/collection/getAccessField.ts +0 -64
  221. package/src/collection/index.ts +0 -63
  222. package/src/components/AccessField/index.client.tsx +0 -344
  223. package/src/components/AccessField/index.css +0 -93
  224. package/src/utils/schemaConversion/prepareCollectionSchema.ts +0 -39
  225. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
  226. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -70
  227. package/src/utils/schemaConversion/transformPointFields.ts +0 -56
@@ -0,0 +1,82 @@
1
+ import { z } from 'zod';
2
+ import { defaultAccess } from '../../../defaultAccess.js';
3
+ import { defineCollectionTool } from '../../../defineTool.js';
4
+ import { getLogger } from '../../../utils/getLogger.js';
5
+ import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
+ const DEFAULT_DESCRIPTION = 'Restore a document from a previous version in any version-enabled collection.';
7
+ export const restoreVersionTool = defineCollectionTool({
8
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),
9
+ annotations: {
10
+ destructiveHint: true,
11
+ idempotentHint: false,
12
+ openWorldHint: false,
13
+ readOnlyHint: false,
14
+ title: 'Restore Version'
15
+ },
16
+ description: DEFAULT_DESCRIPTION,
17
+ input: z.object({
18
+ id: z.string().describe('The ID of the version to restore'),
19
+ depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in response').optional().default(0),
20
+ draft: z.boolean().describe('Whether to restore the version as a draft').optional().default(false),
21
+ fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
22
+ locale: z.string().describe('Optional: locale code to restore in (e.g., "en", "es")').optional(),
23
+ populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
24
+ 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(),
25
+ showHiddenFields: z.boolean().describe('Optional: include hidden fields in the restored document response').optional()
26
+ })
27
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
28
+ const payload = req.payload;
29
+ const logger = getLogger({
30
+ payload
31
+ });
32
+ const { id, depth, draft, fallbackLocale, locale, populate, select, showHiddenFields } = input;
33
+ logger.info(`Restoring version in collection: ${collectionSlug} with ID: ${id}`);
34
+ try {
35
+ const result = await payload.restoreVersion({
36
+ id,
37
+ collection: collectionSlug,
38
+ depth,
39
+ draft,
40
+ req,
41
+ ...localAPIDefaults(authorizedMCP),
42
+ ...fallbackLocale ? {
43
+ fallbackLocale
44
+ } : {},
45
+ ...locale ? {
46
+ locale
47
+ } : {},
48
+ ...populate ? {
49
+ populate: populate
50
+ } : {},
51
+ ...select ? {
52
+ select: select
53
+ } : {},
54
+ ...showHiddenFields !== undefined ? {
55
+ showHiddenFields
56
+ } : {}
57
+ });
58
+ return {
59
+ content: [
60
+ {
61
+ type: 'text',
62
+ text: `Version "${id}" restored successfully in collection "${collectionSlug}"!\nRestored document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
63
+ }
64
+ ],
65
+ doc: result
66
+ };
67
+ } catch (error) {
68
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
69
+ logger.error(`Error restoring version ${id} in ${collectionSlug}: ${errorMessage}`);
70
+ return {
71
+ content: [
72
+ {
73
+ type: 'text',
74
+ text: `❌ **Error restoring version "${id}" in collection "${collectionSlug}":** ${errorMessage}`
75
+ }
76
+ ],
77
+ isError: true
78
+ };
79
+ }
80
+ });
81
+
82
+ //# sourceMappingURL=restoreVersionTool.js.map
@@ -0,0 +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'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.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 req,\n ...localAPIDefaults(authorizedMCP),\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","localAPIDefaults","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","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,gBAAgB,QAAQ,qCAAoC;AAErE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBJ,qBAAqB;IACrDK,QAAQ,CAACC,OACPP,cAAcO,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IACvFC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,IAAIvB,EAAEwB,MAAM,GAAGC,QAAQ,CAAC;QACxBC,OAAO1B,EACJ2B,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJL,QAAQ,CAAC,8DACTM,QAAQ,GACRC,OAAO,CAAC;QACXC,OAAOjC,EACJkC,OAAO,GACPT,QAAQ,CAAC,6CACTM,QAAQ,GACRC,OAAO,CAAC;QACXG,gBAAgBnC,EACbwB,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;oBACEC,MAAM;oBACNC,MAAM,CAAC,SAAS,EAAE/B,GAAG,uCAAuC,EAAEX,eAAe,oCAAoC,EAAE2C,KAAKC,SAAS,CAACR,QAAQ,QAAQ,CAAC;gBACrJ;aACD;YACDS,KAAKT;QACP;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9Df,OAAOY,KAAK,CAAC,CAAC,wBAAwB,EAAEnC,GAAG,IAAI,EAAEX,eAAe,EAAE,EAAE+C,cAAc;QAClF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6BAA6B,EAAE/B,GAAG,iBAAiB,EAAEX,eAAe,KAAK,EAAE+C,cAAc;gBAClG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1,2 +1,2 @@
1
- export declare const updateCollectionTool: import("../../../types.js").CollectionTool;
1
+ export declare const updateDocumentTool: import("../../../types.js").CollectionTool;
2
2
  //# sourceMappingURL=updateTool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,oBAAoB,4CA4L/B,CAAA"}
1
+ {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,kBAAkB,4CA6L7B,CAAA"}
@@ -1,37 +1,41 @@
1
1
  import { z } from 'zod';
2
+ import { defaultAccess } from '../../../defaultAccess.js';
2
3
  import { defineCollectionTool } from '../../../defineTool.js';
3
4
  import { getLogger } from '../../../utils/getLogger.js';
4
5
  import { getCollectionVirtualFieldNames, stripVirtualFields } from '../../../utils/getVirtualFieldNames.js';
5
6
  import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
- import { prepareCollectionSchema } from '../../../utils/schemaConversion/prepareCollectionSchema.js';
7
+ import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
7
8
  import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js';
8
- const DEFAULT_DESCRIPTION = 'Update documents in a collection by ID or where clause.';
9
- export const updateCollectionTool = defineCollectionTool({
9
+ import { whereSchema } from '../../../utils/whereSchema.js';
10
+ import { validateCollectionData } from '../validateEntityData.js';
11
+ import { formatCollectionError } from './formatCollectionError.js';
12
+ const DEFAULT_DESCRIPTION = 'Update documents in any collection by passing the collection slug and data.';
13
+ export const updateDocumentTool = defineCollectionTool({
14
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),
15
+ annotations: {
16
+ destructiveHint: true,
17
+ idempotentHint: false,
18
+ openWorldHint: false,
19
+ readOnlyHint: false,
20
+ title: 'Update Document'
21
+ },
10
22
  description: DEFAULT_DESCRIPTION,
11
- input: ({ collectionSchema })=>{
12
- const partialSchema = prepareCollectionSchema(collectionSchema);
13
- // Collection updates do not require all required fields to be passed => delete .required.
14
- //
15
- // Local API equivalent: packages/payload/src/collections/operations/local/update.ts#BaseOptions#data:
16
- // data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>
17
- delete partialSchema.required;
18
- return z.object({
19
- id: z.union([
20
- z.string(),
21
- z.number()
22
- ]).describe('The ID of the document to update').optional(),
23
- data: z.fromJSONSchema(partialSchema).describe('The fields to update'),
24
- depth: z.number().describe('How many levels deep to populate relationships').optional().default(0),
25
- draft: z.boolean().describe('Whether to update the document as a draft').optional().default(false),
26
- fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
27
- filePath: z.string().describe('File path for file uploads').optional(),
28
- locale: z.string().describe('Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale').optional(),
29
- overrideLock: z.boolean().describe('Whether to override document locks').optional().default(true),
30
- overwriteExistingFiles: z.boolean().describe('Whether to overwrite existing files').optional().default(false),
31
- select: z.string().describe('Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"title": "My Post"}\'').optional(),
32
- where: z.string().describe('JSON string for where clause to update multiple documents').optional()
33
- });
34
- }
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'),
29
+ depth: z.number().describe('How many levels deep to populate relationships').optional().default(0),
30
+ draft: z.boolean().describe('Whether to update the document as a draft').optional().default(false),
31
+ fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
32
+ filePath: z.string().describe('File path for file uploads').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
+ 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(),
37
+ 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()
38
+ })
35
39
  }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
36
40
  const payload = req.payload;
37
41
  const logger = getLogger({
@@ -50,43 +54,21 @@ export const updateCollectionTool = defineCollectionTool({
50
54
  ]
51
55
  };
52
56
  }
53
- let parsedData = transformPointDataToPayload(data);
54
57
  const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug);
55
- parsedData = stripVirtualFields(parsedData, virtualFieldNames);
56
- let whereClause = {};
57
- if (where) {
58
- try {
59
- whereClause = JSON.parse(where);
60
- } catch {
61
- logger.error(`Invalid where clause JSON: ${where}`);
62
- return {
63
- content: [
64
- {
65
- type: 'text',
66
- text: 'Error: Invalid JSON in where clause'
67
- }
68
- ]
69
- };
70
- }
71
- }
72
- let selectClause;
73
- if (select) {
74
- try {
75
- selectClause = JSON.parse(select);
76
- } catch {
77
- logger.warn(`Invalid select clause JSON: ${select}`);
78
- return {
79
- content: [
80
- {
81
- type: 'text',
82
- text: 'Error: Invalid JSON in select clause'
83
- }
84
- ]
85
- };
86
- }
58
+ const inputData = stripVirtualFields(data, virtualFieldNames);
59
+ const validationError = validateCollectionData({
60
+ collectionSlug,
61
+ data: inputData,
62
+ partial: true,
63
+ req
64
+ });
65
+ if (validationError) {
66
+ return validationError;
87
67
  }
68
+ const parsedData = transformPointDataToPayload(inputData);
69
+ const whereClause = where ?? {};
88
70
  if (id) {
89
- const updateOptions = {
71
+ const result = await payload.update({
90
72
  id,
91
73
  collection: collectionSlug,
92
74
  data: parsedData,
@@ -107,11 +89,10 @@ export const updateCollectionTool = defineCollectionTool({
107
89
  ...fallbackLocale ? {
108
90
  fallbackLocale
109
91
  } : {},
110
- ...selectClause ? {
111
- select: selectClause
92
+ ...select ? {
93
+ select: select
112
94
  } : {}
113
- };
114
- const result = await payload.update(updateOptions);
95
+ });
115
96
  return {
116
97
  content: [
117
98
  {
@@ -122,15 +103,15 @@ export const updateCollectionTool = defineCollectionTool({
122
103
  doc: result
123
104
  };
124
105
  }
125
- const updateOptions = {
106
+ const result = await payload.update({
126
107
  collection: collectionSlug,
127
108
  data: parsedData,
128
109
  depth,
129
110
  draft,
130
111
  overrideLock,
131
112
  req,
132
- ...localAPIDefaults(authorizedMCP),
133
113
  where: whereClause,
114
+ ...localAPIDefaults(authorizedMCP),
134
115
  ...filePath ? {
135
116
  filePath
136
117
  } : {},
@@ -143,20 +124,46 @@ export const updateCollectionTool = defineCollectionTool({
143
124
  ...fallbackLocale ? {
144
125
  fallbackLocale
145
126
  } : {},
146
- ...selectClause ? {
147
- select: selectClause
127
+ ...select ? {
128
+ select: select
148
129
  } : {}
149
- };
150
- const result = await payload.update(updateOptions);
151
- const bulkResult = result;
152
- const docs = bulkResult.docs || [];
153
- const errors = bulkResult.errors || [];
130
+ });
131
+ const docs = result.docs || [];
132
+ const errors = result.errors || [];
154
133
  let responseText = `Multiple documents updated in collection "${collectionSlug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`;
155
134
  if (docs.length > 0) {
156
135
  responseText += `\n\nUpdated documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``;
157
136
  }
158
137
  if (errors.length > 0) {
159
138
  responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``;
139
+ const errorSchema = getCollectionInputSchema({
140
+ collectionSlug,
141
+ req
142
+ });
143
+ if (errorSchema) {
144
+ responseText += `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(errorSchema)}\n\`\`\``;
145
+ }
146
+ return {
147
+ content: [
148
+ {
149
+ type: 'text',
150
+ text: responseText
151
+ }
152
+ ],
153
+ doc: {
154
+ docs,
155
+ errors
156
+ },
157
+ isError: true,
158
+ ...errorSchema ? {
159
+ structuredContent: {
160
+ collectionSlug,
161
+ docs,
162
+ errors,
163
+ schema: errorSchema
164
+ }
165
+ } : {}
166
+ };
160
167
  }
161
168
  return {
162
169
  content: [
@@ -173,14 +180,12 @@ export const updateCollectionTool = defineCollectionTool({
173
180
  } catch (error) {
174
181
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
175
182
  logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`);
176
- return {
177
- content: [
178
- {
179
- type: 'text',
180
- text: `Error updating document in collection "${collectionSlug}": ${errorMessage}`
181
- }
182
- ]
183
- };
183
+ return formatCollectionError({
184
+ action: 'updating',
185
+ collectionSlug,
186
+ error,
187
+ req
188
+ });
184
189
  }
185
190
  });
186
191
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"sourcesContent":["import type { SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\nimport { prepareCollectionSchema } from '../../../utils/schemaConversion/prepareCollectionSchema.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'\n\nconst DEFAULT_DESCRIPTION = 'Update documents in a collection by ID or where clause.'\n\nexport const updateCollectionTool = defineCollectionTool({\n description: DEFAULT_DESCRIPTION,\n input: ({ collectionSchema }) => {\n const partialSchema = prepareCollectionSchema(collectionSchema)\n\n // Collection updates do not require all required fields to be passed => delete .required.\n //\n // Local API equivalent: packages/payload/src/collections/operations/local/update.ts#BaseOptions#data:\n // data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>\n delete partialSchema.required\n\n return z.object({\n id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),\n data: z\n .fromJSONSchema(partialSchema as unknown as z.core.JSONSchema.JSONSchema)\n .describe('The fields to update'),\n depth: z\n .number()\n .describe('How many levels deep to populate relationships')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe('Whether to update the document 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 filePath: z.string().describe('File path for file uploads').optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to update the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n )\n .optional(),\n overrideLock: z\n .boolean()\n .describe('Whether to override document locks')\n .optional()\n .default(true),\n overwriteExistingFiles: z\n .boolean()\n .describe('Whether to overwrite existing files')\n .optional()\n .default(false),\n select: z\n .string()\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response (JSON), e.g., \\'{\"title\": \"My Post\"}\\'',\n )\n .optional(),\n where: z\n .string()\n .describe('JSON string for where clause to update multiple documents')\n .optional(),\n })\n },\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const {\n id,\n data,\n depth,\n draft,\n fallbackLocale,\n filePath,\n locale,\n overrideLock,\n overwriteExistingFiles,\n select,\n where,\n } = input\n\n logger.info(\n `Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n if (!id && !where) {\n return {\n content: [{ type: 'text', text: 'Error: Either id or where clause must be provided' }],\n }\n }\n\n let parsedData = transformPointDataToPayload(data as Record<string, unknown>)\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n parsedData = stripVirtualFields(parsedData, virtualFieldNames)\n\n let whereClause: Record<string, unknown> = {}\n if (where) {\n try {\n whereClause = JSON.parse(where) as Record<string, unknown>\n } catch {\n logger.error(`Invalid where clause JSON: ${where}`)\n return { content: [{ type: 'text', text: 'Error: Invalid JSON in where clause' }] }\n }\n }\n\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch {\n logger.warn(`Invalid select clause JSON: ${select}`)\n return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }\n }\n }\n\n if (id) {\n const updateOptions = {\n id,\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideLock,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(filePath ? { filePath } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(selectClause ? { select: selectClause } : {}),\n }\n\n const result = await payload.update(updateOptions as any)\n\n return {\n content: [\n {\n type: 'text',\n text: `Document updated successfully in collection \"${collectionSlug}\"!\\nUpdated document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n }\n\n const updateOptions = {\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideLock,\n req,\n ...localAPIDefaults(authorizedMCP),\n where: whereClause,\n ...(filePath ? { filePath } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(selectClause ? { select: selectClause } : {}),\n }\n\n const result = await payload.update(updateOptions as any)\n\n const bulkResult = result as { docs?: unknown[]; errors?: unknown[] }\n const docs = bulkResult.docs || []\n const errors = bulkResult.errors || []\n\n let responseText = `Multiple documents updated in collection \"${collectionSlug}\"!\\nUpdated: ${docs.length} documents\\nErrors: ${errors.length}\\n---`\n if (docs.length > 0) {\n responseText += `\\n\\nUpdated documents:\\n\\`\\`\\`json\\n${JSON.stringify(docs)}\\n\\`\\`\\``\n }\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\\n\\`\\`\\`json\\n${JSON.stringify(errors)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `Error updating document in collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n }\n }\n})\n"],"names":["z","defineCollectionTool","getLogger","getCollectionVirtualFieldNames","stripVirtualFields","localAPIDefaults","prepareCollectionSchema","transformPointDataToPayload","DEFAULT_DESCRIPTION","updateCollectionTool","description","input","collectionSchema","partialSchema","required","object","id","union","string","number","describe","optional","data","fromJSONSchema","depth","default","draft","boolean","fallbackLocale","filePath","locale","overrideLock","overwriteExistingFiles","select","where","handler","authorizedMCP","collectionSlug","req","payload","logger","info","content","type","text","parsedData","virtualFieldNames","config","whereClause","JSON","parse","error","selectClause","warn","updateOptions","collection","result","update","stringify","doc","bulkResult","docs","errors","responseText","length","errorMessage","Error","message"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SACEC,8BAA8B,EAC9BC,kBAAkB,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EAAE;QAClC,MAAMC,SAASF,WAAWE,MAAM,IAAI,EAAE;QAEtC,IAAIC,eAAe,CAAC,0CAA0C,EAAE1B,eAAe,aAAa,EAAEwB,KAAKG,MAAM,CAAC,oBAAoB,EAAEF,OAAOE,MAAM,CAAC,KAAK,CAAC;QACpJ,IAAIH,KAAKG,MAAM,GAAG,GAAG;YACnBD,gBAAgB,CAAC,oCAAoC,EAAEd,KAAKS,SAAS,CAACG,MAAM,QAAQ,CAAC;QACvF;QACA,IAAIC,OAAOE,MAAM,GAAG,GAAG;YACrBD,gBAAgB,CAAC,yBAAyB,EAAEd,KAAKS,SAAS,CAACI,QAAQ,QAAQ,CAAC;QAC9E;QAEA,OAAO;YACLpB,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMmB;gBAAa;aAAE;YAC/CJ,KAAK;gBAAEE;gBAAMC;YAAO;QACtB;IACF,EAAE,OAAOX,OAAO;QACd,MAAMc,eAAed,iBAAiBe,QAAQf,MAAMgB,OAAO,GAAG;QAC9D3B,OAAOW,KAAK,CAAC,CAAC,2BAA2B,EAAEd,eAAe,EAAE,EAAE4B,cAAc;QAC5E,OAAO;YACLvB,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,uCAAuC,EAAEP,eAAe,GAAG,EAAE4B,cAAc;gBACpF;aACD;QACH;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"sourcesContent":["import type { SelectType, Where } 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 {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\nimport { validateCollectionData } from '../validateEntityData.js'\nimport { formatCollectionError } from './formatCollectionError.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Update documents in any collection by passing the collection slug and data.'\n\nexport const updateDocumentTool = 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: 'Update Document',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),\n data: z.record(z.string(), z.unknown()).describe('The fields to update'),\n depth: z\n .number()\n .describe('How many levels deep to populate relationships')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe('Whether to update the document 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 filePath: z.string().describe('File path for file uploads').optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to update the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n )\n .optional(),\n overrideLock: z\n .boolean()\n .describe('Whether to override document locks')\n .optional()\n .default(true),\n overwriteExistingFiles: z\n .boolean()\n .describe('Whether to overwrite existing files')\n .optional()\n .default(false),\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 where: whereSchema\n .describe(\n 'Where clause to update multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {\"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\n const {\n id,\n data,\n depth,\n draft,\n fallbackLocale,\n filePath,\n locale,\n overrideLock,\n overwriteExistingFiles,\n select,\n where,\n } = input\n\n logger.info(\n `Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n if (!id && !where) {\n return {\n content: [{ type: 'text', text: 'Error: Either id or where clause must be provided' }],\n }\n }\n\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n const inputData = stripVirtualFields(data, virtualFieldNames)\n const validationError = validateCollectionData({\n collectionSlug,\n data: inputData,\n partial: true,\n req,\n })\n\n if (validationError) {\n return validationError\n }\n\n const parsedData = transformPointDataToPayload(inputData)\n\n const whereClause: Where = where ?? {}\n\n if (id) {\n const result = await payload.update({\n id,\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideLock,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(filePath ? { filePath } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(select ? { select: select as SelectType } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document updated successfully in collection \"${collectionSlug}\"!\\nUpdated document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n }\n\n const result = await payload.update({\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideLock,\n req,\n where: whereClause,\n ...localAPIDefaults(authorizedMCP),\n ...(filePath ? { filePath } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(select ? { select: select as SelectType } : {}),\n })\n\n const docs = result.docs || []\n const errors = result.errors || []\n\n let responseText = `Multiple documents updated in collection \"${collectionSlug}\"!\\nUpdated: ${docs.length} documents\\nErrors: ${errors.length}\\n---`\n if (docs.length > 0) {\n responseText += `\\n\\nUpdated documents:\\n\\`\\`\\`json\\n${JSON.stringify(docs)}\\n\\`\\`\\``\n }\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\\n\\`\\`\\`json\\n${JSON.stringify(errors)}\\n\\`\\`\\``\n\n const errorSchema = getCollectionInputSchema({ collectionSlug, req })\n\n if (errorSchema) {\n responseText += `\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(errorSchema)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n isError: true,\n ...(errorSchema\n ? {\n structuredContent: {\n collectionSlug,\n docs,\n errors,\n schema: errorSchema,\n },\n }\n : {}),\n }\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`)\n return formatCollectionError({ action: 'updating', collectionSlug, error, req })\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","getCollectionVirtualFieldNames","stripVirtualFields","localAPIDefaults","getCollectionInputSchema","transformPointDataToPayload","whereSchema","validateCollectionData","formatCollectionError","DEFAULT_DESCRIPTION","updateDocumentTool","access","args","Boolean","permissions","collections","collectionSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","union","string","number","describe","optional","data","record","unknown","depth","default","draft","boolean","fallbackLocale","filePath","locale","overrideLock","overwriteExistingFiles","select","where","handler","authorizedMCP","req","payload","logger","info","content","type","text","virtualFieldNames","config","inputData","validationError","partial","parsedData","whereClause","result","collection","JSON","stringify","doc","docs","errors","responseText","length","errorSchema","isError","structuredContent","schema","error","errorMessage","Error","message","action"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SACEC,8BAA8B,EAC9BC,kBAAkB,QACb,yCA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nBD,gBAAgB,CAAC,oCAAoC,EAAEL,KAAKC,SAAS,CAACE,MAAM,QAAQ,CAAC;QACvF;QACA,IAAIC,OAAOE,MAAM,GAAG,GAAG;YACrBD,gBAAgB,CAAC,yBAAyB,EAAEL,KAAKC,SAAS,CAACG,QAAQ,QAAQ,CAAC;YAE5E,MAAMG,cAAcpE,yBAAyB;gBAAEY;gBAAgBiC;YAAI;YAEnE,IAAIuB,aAAa;gBACfF,gBAAgB,CAAC,2CAA2C,EAAEL,KAAKC,SAAS,CAACM,aAAa,QAAQ,CAAC;YACrG;YAEA,OAAO;gBACLnB,SAAS;oBAAC;wBAAEC,MAAM;wBAAQC,MAAMe;oBAAa;iBAAE;gBAC/CH,KAAK;oBAAEC;oBAAMC;gBAAO;gBACpBI,SAAS;gBACT,GAAID,cACA;oBACEE,mBAAmB;wBACjB1D;wBACAoD;wBACAC;wBACAM,QAAQH;oBACV;gBACF,IACA,CAAC,CAAC;YACR;QACF;QAEA,OAAO;YACLnB,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMe;gBAAa;aAAE;YAC/CH,KAAK;gBAAEC;gBAAMC;YAAO;QACtB;IACF,EAAE,OAAOO,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9D5B,OAAOyB,KAAK,CAAC,CAAC,2BAA2B,EAAE5D,eAAe,EAAE,EAAE6D,cAAc;QAC5E,OAAOrE,sBAAsB;YAAEwE,QAAQ;YAAYhE;YAAgB4D;YAAO3B;QAAI;IAChF;AACF,GAAE"}
@@ -0,0 +1,2 @@
1
+ export declare const getConfigInfoTool: import("../../types.js").Tool;
2
+ //# sourceMappingURL=getConfigInfoTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getConfigInfoTool.d.ts","sourceRoot":"","sources":["../../../src/mcp/builtin/getConfigInfoTool.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,+BAgE5B,CAAA"}
@@ -0,0 +1,71 @@
1
+ import { getAccessResults, isEntityHidden } from 'payload';
2
+ import { defineTool } from '../../defineTool.js';
3
+ export const getConfigInfoTool = defineTool({
4
+ annotations: {
5
+ destructiveHint: false,
6
+ idempotentHint: true,
7
+ openWorldHint: false,
8
+ readOnlyHint: true,
9
+ title: 'Config Info'
10
+ },
11
+ description: 'List the Payload collection and global slugs visible to this MCP client.'
12
+ }).handler(async ({ authorizedMCP, req })=>{
13
+ const user = authorizedMCP.user;
14
+ const permissions = authorizedMCP.overrideAccess ? null : await getAccessResults({
15
+ req: {
16
+ ...req,
17
+ user
18
+ }
19
+ });
20
+ const authorizedCollectionSlugs = new Set();
21
+ const authorizedGlobalSlugs = new Set();
22
+ for (const item of authorizedMCP.items){
23
+ if (item.type === 'collectionTool') {
24
+ authorizedCollectionSlugs.add(item.collectionSlug);
25
+ } else if (item.type === 'globalTool') {
26
+ authorizedGlobalSlugs.add(item.globalSlug);
27
+ }
28
+ }
29
+ const collections = [];
30
+ const globals = [];
31
+ for (const collection of req.payload.config.collections){
32
+ if (!authorizedCollectionSlugs.has(collection.slug)) {
33
+ continue;
34
+ }
35
+ if (user && isEntityHidden({
36
+ hidden: collection.admin.hidden,
37
+ user
38
+ })) {
39
+ continue;
40
+ }
41
+ if (!authorizedMCP.overrideAccess && !permissions?.collections?.[collection.slug]?.read) {
42
+ continue;
43
+ }
44
+ collections.push(collection.slug);
45
+ }
46
+ for (const global of req.payload.config.globals){
47
+ if (!authorizedGlobalSlugs.has(global.slug)) {
48
+ continue;
49
+ }
50
+ if (user && isEntityHidden({
51
+ hidden: global.admin.hidden,
52
+ user
53
+ })) {
54
+ continue;
55
+ }
56
+ if (!authorizedMCP.overrideAccess && !permissions?.globals?.[global.slug]?.read) {
57
+ continue;
58
+ }
59
+ globals.push(global.slug);
60
+ }
61
+ return {
62
+ content: [
63
+ {
64
+ type: 'text',
65
+ text: `Collections: ${collections.join(', ') || 'none'}\nGlobals: ${globals.join(', ') || 'none'}`
66
+ }
67
+ ]
68
+ };
69
+ });
70
+
71
+ //# sourceMappingURL=getConfigInfoTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/mcp/builtin/getConfigInfoTool.ts"],"sourcesContent":["import { getAccessResults, isEntityHidden } from 'payload'\n\nimport { defineTool } from '../../defineTool.js'\n\nexport const getConfigInfoTool = defineTool({\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Config Info',\n },\n description: 'List the Payload collection and global slugs visible to this MCP client.',\n}).handler(async ({ authorizedMCP, req }) => {\n const user = authorizedMCP.user\n const permissions = authorizedMCP.overrideAccess\n ? null\n : await getAccessResults({ req: { ...req, user } })\n const authorizedCollectionSlugs = new Set<string>()\n const authorizedGlobalSlugs = new Set<string>()\n\n for (const item of authorizedMCP.items) {\n if (item.type === 'collectionTool') {\n authorizedCollectionSlugs.add(item.collectionSlug)\n } else if (item.type === 'globalTool') {\n authorizedGlobalSlugs.add(item.globalSlug)\n }\n }\n\n const collections: string[] = []\n const globals: string[] = []\n\n for (const collection of req.payload.config.collections) {\n if (!authorizedCollectionSlugs.has(collection.slug)) {\n continue\n }\n if (user && isEntityHidden({ hidden: collection.admin.hidden, user })) {\n continue\n }\n if (!authorizedMCP.overrideAccess && !permissions?.collections?.[collection.slug]?.read) {\n continue\n }\n\n collections.push(collection.slug)\n }\n\n for (const global of req.payload.config.globals) {\n if (!authorizedGlobalSlugs.has(global.slug)) {\n continue\n }\n if (user && isEntityHidden({ hidden: global.admin.hidden, user })) {\n continue\n }\n if (!authorizedMCP.overrideAccess && !permissions?.globals?.[global.slug]?.read) {\n continue\n }\n\n globals.push(global.slug)\n }\n\n return {\n content: [\n {\n type: 'text',\n text: `Collections: ${collections.join(', ') || 'none'}\\nGlobals: ${globals.join(', ') || 'none'}`,\n },\n ],\n }\n})\n"],"names":["getAccessResults","isEntityHidden","defineTool","getConfigInfoTool","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","handler","authorizedMCP","req","user","permissions","overrideAccess","authorizedCollectionSlugs","Set","authorizedGlobalSlugs","item","items","type","add","collectionSlug","globalSlug","collections","globals","collection","payload","config","has","slug","hidden","admin","read","push","global","content","text","join"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,cAAc,QAAQ,UAAS;AAE1D,SAASC,UAAU,QAAQ,sBAAqB;AAEhD,OAAO,MAAMC,oBAAoBD,WAAW;IAC1CE,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;AACf,GAAGC,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEC,GAAG,EAAE;IACtC,MAAMC,OAAOF,cAAcE,IAAI;IAC/B,MAAMC,cAAcH,cAAcI,cAAc,GAC5C,OACA,MAAMhB,iBAAiB;QAAEa,KAAK;YAAE,GAAGA,GAAG;YAAEC;QAAK;IAAE;IACnD,MAAMG,4BAA4B,IAAIC;IACtC,MAAMC,wBAAwB,IAAID;IAElC,KAAK,MAAME,QAAQR,cAAcS,KAAK,CAAE;QACtC,IAAID,KAAKE,IAAI,KAAK,kBAAkB;YAClCL,0BAA0BM,GAAG,CAACH,KAAKI,cAAc;QACnD,OAAO,IAAIJ,KAAKE,IAAI,KAAK,cAAc;YACrCH,sBAAsBI,GAAG,CAACH,KAAKK,UAAU;QAC3C;IACF;IAEA,MAAMC,cAAwB,EAAE;IAChC,MAAMC,UAAoB,EAAE;IAE5B,KAAK,MAAMC,cAAcf,IAAIgB,OAAO,CAACC,MAAM,CAACJ,WAAW,CAAE;QACvD,IAAI,CAACT,0BAA0Bc,GAAG,CAACH,WAAWI,IAAI,GAAG;YACnD;QACF;QACA,IAAIlB,QAAQb,eAAe;YAAEgC,QAAQL,WAAWM,KAAK,CAACD,MAAM;YAAEnB;QAAK,IAAI;YACrE;QACF;QACA,IAAI,CAACF,cAAcI,cAAc,IAAI,CAACD,aAAaW,aAAa,CAACE,WAAWI,IAAI,CAAC,EAAEG,MAAM;YACvF;QACF;QAEAT,YAAYU,IAAI,CAACR,WAAWI,IAAI;IAClC;IAEA,KAAK,MAAMK,UAAUxB,IAAIgB,OAAO,CAACC,MAAM,CAACH,OAAO,CAAE;QAC/C,IAAI,CAACR,sBAAsBY,GAAG,CAACM,OAAOL,IAAI,GAAG;YAC3C;QACF;QACA,IAAIlB,QAAQb,eAAe;YAAEgC,QAAQI,OAAOH,KAAK,CAACD,MAAM;YAAEnB;QAAK,IAAI;YACjE;QACF;QACA,IAAI,CAACF,cAAcI,cAAc,IAAI,CAACD,aAAaY,SAAS,CAACU,OAAOL,IAAI,CAAC,EAAEG,MAAM;YAC/E;QACF;QAEAR,QAAQS,IAAI,CAACC,OAAOL,IAAI;IAC1B;IAEA,OAAO;QACLM,SAAS;YACP;gBACEhB,MAAM;gBACNiB,MAAM,CAAC,aAAa,EAAEb,YAAYc,IAAI,CAAC,SAAS,OAAO,WAAW,EAAEb,QAAQa,IAAI,CAAC,SAAS,QAAQ;YACpG;SACD;IACH;AACF,GAAE"}
@@ -0,0 +1,2 @@
1
+ export declare const countGlobalVersionsTool: import("../../../types.js").GlobalTool;
2
+ //# sourceMappingURL=countVersionsTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/countVersionsTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,uBAAuB,wCAyDlC,CAAA"}
@@ -0,0 +1,65 @@
1
+ import { z } from 'zod';
2
+ import { defaultAccess } from '../../../defaultAccess.js';
3
+ import { defineGlobalTool } from '../../../defineTool.js';
4
+ import { getLogger } from '../../../utils/getLogger.js';
5
+ import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
+ import { whereSchema } from '../../../utils/whereSchema.js';
7
+ const DEFAULT_DESCRIPTION = 'Count global versions in any version-enabled global by passing the global slug and optional where clause.';
8
+ export const countGlobalVersionsTool = defineGlobalTool({
9
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
10
+ annotations: {
11
+ destructiveHint: false,
12
+ idempotentHint: true,
13
+ openWorldHint: false,
14
+ readOnlyHint: true,
15
+ title: 'Count Global Versions'
16
+ },
17
+ description: DEFAULT_DESCRIPTION,
18
+ input: z.object({
19
+ locale: z.string().describe('Optional: locale code to count versions in').optional(),
20
+ where: whereSchema.describe('Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.siteName":{"contains":"test"}}').optional()
21
+ })
22
+ }).handler(async ({ authorizedMCP, globalSlug, input, req })=>{
23
+ const payload = req.payload;
24
+ const logger = getLogger({
25
+ payload
26
+ });
27
+ const { locale, where } = input;
28
+ logger.info(`Counting versions for global: ${globalSlug}`);
29
+ try {
30
+ const result = await payload.countGlobalVersions({
31
+ global: globalSlug,
32
+ req,
33
+ ...localAPIDefaults(authorizedMCP),
34
+ ...locale ? {
35
+ locale
36
+ } : {},
37
+ ...where ? {
38
+ where
39
+ } : {}
40
+ });
41
+ return {
42
+ content: [
43
+ {
44
+ type: 'text',
45
+ text: `Global "${globalSlug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
46
+ }
47
+ ],
48
+ doc: result
49
+ };
50
+ } catch (error) {
51
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
52
+ logger.error(`Error counting versions for global ${globalSlug}: ${errorMessage}`);
53
+ return {
54
+ content: [
55
+ {
56
+ type: 'text',
57
+ text: `❌ **Error counting versions for global "${globalSlug}":** ${errorMessage}`
58
+ }
59
+ ],
60
+ isError: true
61
+ };
62
+ }
63
+ });
64
+
65
+ //# sourceMappingURL=countVersionsTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/globals/countVersionsTool.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Count global versions in any version-enabled global by passing the global slug and optional where clause.'\n\nexport const countGlobalVersionsTool = defineGlobalTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Count Global Versions',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n locale: z.string().describe('Optional: locale code to count versions in').optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering versions. Version document fields are usually under \"version\". Example: {\"version.siteName\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { locale, where } = input\n\n logger.info(`Counting versions for global: ${globalSlug}`)\n\n try {\n const result = await payload.countGlobalVersions({\n global: globalSlug,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(locale ? { locale } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Global \"${globalSlug}\" contains ${result.totalDocs} matching versions.\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error counting versions for global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error counting versions for global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","localAPIDefaults","whereSchema","DEFAULT_DESCRIPTION","countGlobalVersionsTool","access","args","Boolean","permissions","globals","globalSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","locale","string","describe","optional","where","handler","authorizedMCP","req","payload","logger","info","result","countGlobalVersions","global","content","type","text","totalDocs","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,0BAA0BL,iBAAiB;IACtDM,QAAQ,CAACC,OACPR,cAAcQ,SAASC,QAAQD,KAAKE,WAAW,EAAEC,SAAS,CAACH,KAAKI,UAAU,CAAC,EAAEC;IAC/EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOtB,EAAEuB,MAAM,CAAC;QACdC,QAAQxB,EAAEyB,MAAM,GAAGC,QAAQ,CAAC,8CAA8CC,QAAQ;QAClFC,OAAOvB,YACJqB,QAAQ,CACP,yJAEDC,QAAQ;IACb;AACF,GAAGE,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEjB,UAAU,EAAES,KAAK,EAAES,GAAG,EAAE;IACzD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAAS9B,UAAU;QAAE6B;IAAQ;IACnC,MAAM,EAAER,MAAM,EAAEI,KAAK,EAAE,GAAGN;IAE1BW,OAAOC,IAAI,CAAC,CAAC,8BAA8B,EAAErB,YAAY;IAEzD,IAAI;QACF,MAAMsB,SAAS,MAAMH,QAAQI,mBAAmB,CAAC;YAC/CC,QAAQxB;YACRkB;YACA,GAAG3B,iBAAiB0B,cAAc;YAClC,GAAIN,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAII,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLU,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,QAAQ,EAAE3B,WAAW,WAAW,EAAEsB,OAAOM,SAAS,CAAC,iCAAiC,EAAEC,KAAKC,SAAS,CAACR,QAAQ,QAAQ,CAAC;gBAC/H;aACD;YACDS,KAAKT;QACP;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9Df,OAAOY,KAAK,CAAC,CAAC,mCAAmC,EAAEhC,WAAW,EAAE,EAAEiC,cAAc;QAChF,OAAO;YACLR,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,wCAAwC,EAAE3B,WAAW,KAAK,EAAEiC,cAAc;gBACnF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/findTool.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,cAAc,wCAqFzB,CAAA"}
1
+ {"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/findTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,cAAc,wCA6FzB,CAAA"}