@payloadcms/plugin-mcp 4.0.0-internal.c2b57ce → 4.0.0-internal.c7d5de4

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 (257) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +7 -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/defineTool.d.ts +8 -8
  8. package/dist/defineTool.d.ts.map +1 -1
  9. package/dist/endpoint/access.d.ts +12 -5
  10. package/dist/endpoint/access.d.ts.map +1 -1
  11. package/dist/endpoint/access.js +75 -88
  12. package/dist/endpoint/access.js.map +1 -1
  13. package/dist/endpoint/index.d.ts +1 -1
  14. package/dist/endpoint/index.d.ts.map +1 -1
  15. package/dist/endpoint/index.js +70 -19
  16. package/dist/endpoint/index.js.map +1 -1
  17. package/dist/exports/client.d.ts +1 -1
  18. package/dist/exports/client.d.ts.map +1 -1
  19. package/dist/exports/client.js +1 -1
  20. package/dist/exports/client.js.map +1 -1
  21. package/dist/exports/internal.d.ts +2 -0
  22. package/dist/exports/internal.d.ts.map +1 -0
  23. package/dist/exports/internal.js +3 -0
  24. package/dist/exports/internal.js.map +1 -0
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +15 -20
  28. package/dist/index.js.map +1 -1
  29. package/dist/mcp/buildMcpServer.d.ts +4 -4
  30. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  31. package/dist/mcp/buildMcpServer.js +133 -73
  32. package/dist/mcp/buildMcpServer.js.map +1 -1
  33. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  34. package/dist/mcp/builtin/collections/authTools.js +44 -6
  35. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  36. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  37. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  38. package/dist/mcp/builtin/collections/countTool.js +68 -0
  39. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  40. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  41. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  42. package/dist/mcp/builtin/collections/countVersionsTool.js +64 -0
  43. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  44. package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
  45. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  46. package/dist/mcp/builtin/collections/createTool.js +50 -41
  47. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  48. package/dist/mcp/builtin/collections/deleteTool.d.ts +1 -1
  49. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  50. package/dist/mcp/builtin/collections/deleteTool.js +15 -22
  51. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  52. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  53. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  54. package/dist/mcp/builtin/collections/duplicateTool.js +96 -0
  55. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  56. package/dist/mcp/builtin/collections/fileInput.d.ts +20 -0
  57. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  58. package/dist/mcp/builtin/collections/fileInput.js +100 -0
  59. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  60. package/dist/mcp/builtin/collections/fileInput.spec.js +72 -0
  61. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
  62. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  63. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  64. package/dist/mcp/builtin/collections/findDistinctTool.js +92 -0
  65. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  66. package/dist/mcp/builtin/collections/findTool.d.ts +1 -1
  67. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  68. package/dist/mcp/builtin/collections/findTool.js +52 -47
  69. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  70. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  71. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  72. package/dist/mcp/builtin/collections/findVersionByIDTool.js +83 -0
  73. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  74. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  75. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  76. package/dist/mcp/builtin/collections/findVersionsTool.js +98 -0
  77. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  78. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
  79. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
  80. package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
  81. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
  82. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
  83. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
  84. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +86 -0
  85. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
  86. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  87. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  88. package/dist/mcp/builtin/collections/restoreVersionTool.js +81 -0
  89. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  90. package/dist/mcp/builtin/collections/updateTool.d.ts +1 -1
  91. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  92. package/dist/mcp/builtin/collections/updateTool.js +106 -89
  93. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  94. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  95. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  96. package/dist/mcp/builtin/getConfigInfoTool.js +68 -0
  97. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  98. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  99. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  100. package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
  101. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  102. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  103. package/dist/mcp/builtin/globals/findTool.js +20 -23
  104. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  105. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  106. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  107. package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
  108. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  109. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  110. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  111. package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
  112. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  113. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  114. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  115. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +65 -0
  116. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  117. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  118. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  119. package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
  120. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  121. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  122. package/dist/mcp/builtin/globals/updateTool.js +33 -38
  123. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  124. package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
  125. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
  126. package/dist/mcp/builtin/validateEntityData.js +82 -0
  127. package/dist/mcp/builtin/validateEntityData.js.map +1 -0
  128. package/dist/mcp/builtinTools.d.ts +144 -19
  129. package/dist/mcp/builtinTools.d.ts.map +1 -1
  130. package/dist/mcp/builtinTools.js +119 -20
  131. package/dist/mcp/builtinTools.js.map +1 -1
  132. package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
  133. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  134. package/dist/mcp/sanitizeMCPConfig.js +121 -58
  135. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  136. package/dist/stdio.d.ts +3 -3
  137. package/dist/stdio.d.ts.map +1 -1
  138. package/dist/stdio.js +82 -45
  139. package/dist/stdio.js.map +1 -1
  140. package/dist/types.d.ts +112 -110
  141. package/dist/types.d.ts.map +1 -1
  142. package/dist/types.js +2 -4
  143. package/dist/types.js.map +1 -1
  144. package/dist/utils/camelCase.d.ts.map +1 -1
  145. package/dist/utils/getPluginConfig.d.ts +1 -1
  146. package/dist/utils/getPluginConfig.js +1 -1
  147. package/dist/utils/getPluginConfig.js.map +1 -1
  148. package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
  149. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
  150. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  151. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  152. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  153. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +13 -0
  154. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
  155. package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
  156. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
  157. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +10 -0
  158. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
  159. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +384 -0
  160. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
  161. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +133 -0
  162. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
  163. package/dist/utils/toStandardSchema.d.ts.map +1 -1
  164. package/dist/utils/whereSchema.d.ts +9 -0
  165. package/dist/utils/whereSchema.d.ts.map +1 -0
  166. package/dist/utils/whereSchema.js +13 -0
  167. package/dist/utils/whereSchema.js.map +1 -0
  168. package/package.json +16 -21
  169. package/src/defaultAccess.ts +3 -0
  170. package/src/endpoint/access.ts +81 -101
  171. package/src/endpoint/index.ts +59 -17
  172. package/src/exports/client.ts +2 -1
  173. package/src/exports/internal.ts +1 -0
  174. package/src/index.ts +12 -20
  175. package/src/mcp/buildMcpServer.ts +169 -109
  176. package/src/mcp/builtin/collections/authTools.ts +45 -9
  177. package/src/mcp/builtin/collections/countTool.ts +73 -0
  178. package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
  179. package/src/mcp/builtin/collections/createTool.ts +67 -62
  180. package/src/mcp/builtin/collections/deleteTool.ts +20 -18
  181. package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
  182. package/src/mcp/builtin/collections/fileInput.spec.ts +79 -0
  183. package/src/mcp/builtin/collections/fileInput.ts +139 -0
  184. package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
  185. package/src/mcp/builtin/collections/findTool.ts +66 -37
  186. package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
  187. package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
  188. package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
  189. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +76 -0
  190. package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
  191. package/src/mcp/builtin/collections/updateTool.ts +132 -110
  192. package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
  193. package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
  194. package/src/mcp/builtin/globals/findTool.ts +28 -19
  195. package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
  196. package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
  197. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
  198. package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
  199. package/src/mcp/builtin/globals/updateTool.ts +52 -55
  200. package/src/mcp/builtin/validateEntityData.ts +132 -0
  201. package/src/mcp/builtinTools.ts +111 -41
  202. package/src/mcp/sanitizeMCPConfig.ts +117 -78
  203. package/src/stdio.ts +77 -45
  204. package/src/types.ts +128 -115
  205. package/src/utils/getPluginConfig.ts +1 -1
  206. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  207. package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
  208. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +96 -0
  209. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +432 -0
  210. package/src/utils/whereSchema.ts +24 -0
  211. package/dist/collection/getAccessField.d.ts +0 -12
  212. package/dist/collection/getAccessField.d.ts.map +0 -1
  213. package/dist/collection/getAccessField.js +0 -57
  214. package/dist/collection/getAccessField.js.map +0 -1
  215. package/dist/collection/index.d.ts +0 -6
  216. package/dist/collection/index.d.ts.map +0 -1
  217. package/dist/collection/index.js +0 -59
  218. package/dist/collection/index.js.map +0 -1
  219. package/dist/components/AccessField/index.client.d.ts +0 -10
  220. package/dist/components/AccessField/index.client.d.ts.map +0 -1
  221. package/dist/components/AccessField/index.client.js +0 -305
  222. package/dist/components/AccessField/index.client.js.map +0 -1
  223. package/dist/components/AccessField/index.css +0 -93
  224. package/dist/utils/localAPIDefaults.d.ts +0 -20
  225. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  226. package/dist/utils/localAPIDefaults.js +0 -19
  227. package/dist/utils/localAPIDefaults.js.map +0 -1
  228. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +0 -7
  229. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +0 -1
  230. package/dist/utils/schemaConversion/prepareCollectionSchema.js +0 -37
  231. package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +0 -1
  232. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  233. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  234. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  235. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  236. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
  237. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
  238. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
  239. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
  240. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
  241. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
  242. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -56
  243. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
  244. package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
  245. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
  246. package/dist/utils/schemaConversion/transformPointFields.js +0 -57
  247. package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
  248. package/src/collection/getAccessField.ts +0 -64
  249. package/src/collection/index.ts +0 -63
  250. package/src/components/AccessField/index.client.tsx +0 -344
  251. package/src/components/AccessField/index.css +0 -93
  252. package/src/utils/localAPIDefaults.ts +0 -22
  253. package/src/utils/schemaConversion/prepareCollectionSchema.ts +0 -39
  254. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  255. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
  256. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -70
  257. package/src/utils/schemaConversion/transformPointFields.ts +0 -56
@@ -1,43 +1,48 @@
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
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
- import { prepareCollectionSchema } from '../../../utils/schemaConversion/prepareCollectionSchema.js';
6
+ import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
7
7
  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({
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.';
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. 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()
39
+ })
35
40
  }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
36
41
  const payload = req.payload;
37
42
  const logger = getLogger({
38
43
  payload
39
44
  });
40
- const { id, data, depth, draft, fallbackLocale, filePath, locale, overrideLock, overwriteExistingFiles, select, where } = input;
45
+ const { id, data, depth, draft, fallbackLocale, file: fileInput, locale, overrideLock, overwriteExistingFiles, publishAllLocales, select, where } = input;
41
46
  logger.info(`Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
42
47
  try {
43
48
  if (!id && !where) {
@@ -50,68 +55,53 @@ export const updateCollectionTool = defineCollectionTool({
50
55
  ]
51
56
  };
52
57
  }
53
- let parsedData = transformPointDataToPayload(data);
54
58
  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
- }
59
+ const inputData = stripVirtualFields(data, virtualFieldNames);
60
+ const validationError = validateCollectionData({
61
+ collectionSlug,
62
+ data: inputData,
63
+ partial: true,
64
+ req
65
+ });
66
+ if (validationError) {
67
+ return validationError;
87
68
  }
69
+ const parsedData = transformPointDataToPayload(inputData);
70
+ const file = await resolveFileInput({
71
+ collectionSlug,
72
+ input: fileInput,
73
+ req
74
+ });
75
+ const whereClause = where ?? {};
88
76
  if (id) {
89
- const updateOptions = {
77
+ const result = await payload.update({
90
78
  id,
91
79
  collection: collectionSlug,
92
80
  data: parsedData,
93
81
  depth,
94
82
  draft,
83
+ overrideAccess: authorizedMCP.overrideAccess,
95
84
  overrideLock,
96
85
  req,
97
- ...localAPIDefaults(authorizedMCP),
98
- ...filePath ? {
99
- filePath
86
+ ...file ? {
87
+ file
100
88
  } : {},
101
89
  ...overwriteExistingFiles ? {
102
90
  overwriteExistingFiles
103
91
  } : {},
92
+ ...publishAllLocales !== undefined ? {
93
+ publishAllLocales
94
+ } : {},
104
95
  ...locale ? {
105
96
  locale
106
97
  } : {},
107
98
  ...fallbackLocale ? {
108
99
  fallbackLocale
109
100
  } : {},
110
- ...selectClause ? {
111
- select: selectClause
101
+ ...select ? {
102
+ select: select
112
103
  } : {}
113
- };
114
- const result = await payload.update(updateOptions);
104
+ });
115
105
  return {
116
106
  content: [
117
107
  {
@@ -122,41 +112,70 @@ export const updateCollectionTool = defineCollectionTool({
122
112
  doc: result
123
113
  };
124
114
  }
125
- const updateOptions = {
115
+ const result = await payload.update({
126
116
  collection: collectionSlug,
127
117
  data: parsedData,
128
118
  depth,
129
119
  draft,
120
+ overrideAccess: authorizedMCP.overrideAccess,
130
121
  overrideLock,
131
122
  req,
132
- ...localAPIDefaults(authorizedMCP),
133
123
  where: whereClause,
134
- ...filePath ? {
135
- filePath
124
+ ...file ? {
125
+ file
136
126
  } : {},
137
127
  ...overwriteExistingFiles ? {
138
128
  overwriteExistingFiles
139
129
  } : {},
130
+ ...publishAllLocales !== undefined ? {
131
+ publishAllLocales
132
+ } : {},
140
133
  ...locale ? {
141
134
  locale
142
135
  } : {},
143
136
  ...fallbackLocale ? {
144
137
  fallbackLocale
145
138
  } : {},
146
- ...selectClause ? {
147
- select: selectClause
139
+ ...select ? {
140
+ select: select
148
141
  } : {}
149
- };
150
- const result = await payload.update(updateOptions);
151
- const bulkResult = result;
152
- const docs = bulkResult.docs || [];
153
- const errors = bulkResult.errors || [];
142
+ });
143
+ const docs = result.docs || [];
144
+ const errors = result.errors || [];
154
145
  let responseText = `Multiple documents updated in collection "${collectionSlug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`;
155
146
  if (docs.length > 0) {
156
147
  responseText += `\n\nUpdated documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``;
157
148
  }
158
149
  if (errors.length > 0) {
159
150
  responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``;
151
+ const errorSchema = getCollectionInputSchema({
152
+ collectionSlug,
153
+ req
154
+ });
155
+ if (errorSchema) {
156
+ responseText += `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(errorSchema)}\n\`\`\``;
157
+ }
158
+ return {
159
+ content: [
160
+ {
161
+ type: 'text',
162
+ text: responseText
163
+ }
164
+ ],
165
+ doc: {
166
+ docs,
167
+ errors
168
+ },
169
+ isError: true,
170
+ ...errorSchema ? {
171
+ structuredContent: {
172
+ collectionSlug,
173
+ docs,
174
+ errors,
175
+ schema: errorSchema
176
+ }
177
+ } : {}
178
+ };
160
179
  }
161
180
  return {
162
181
  content: [
@@ -173,14 +192,12 @@ export const updateCollectionTool = defineCollectionTool({
173
192
  } catch (error) {
174
193
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
175
194
  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
- };
195
+ return formatCollectionError({
196
+ action: 'updating',
197
+ collectionSlug,
198
+ error,
199
+ req
200
+ });
184
201
  }
185
202
  });
186
203
 
@@ -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"],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AAQmB;YAAa,IAAI,CAAC,CAAC;QAClD;QAEA,MAAMI,SAAS,MAAMjB,QAAQkB,MAAM,CAACH;QAEpC,MAAMM,aAAaJ;QACnB,MAAMK,OAAOD,WAAWC,IAAI,IAAI,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 { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\nimport { validateCollectionData } from '../validateEntityData.js'\nimport { fileInputSchema, resolveFileInput } from './fileInput.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\n .record(z.string(), z.unknown())\n .describe(\n 'The fields to update. Only include fields permitted by the schema returned by getCollectionSchema.',\n ),\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(\n '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.',\n )\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 file: fileInputSchema.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 publishAllLocales: z\n .boolean()\n .describe(\n 'For collections with localized publishing status, whether publishing should affect every locale. Set false with locale to publish only that locale.',\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 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 file: fileInput,\n locale,\n overrideLock,\n overwriteExistingFiles,\n publishAllLocales,\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 const file = await resolveFileInput({ collectionSlug, input: fileInput, req })\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 overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n req,\n ...(file ? { file } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(publishAllLocales !== undefined ? { publishAllLocales } : {}),\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 overrideAccess: authorizedMCP.overrideAccess,\n overrideLock,\n req,\n where: whereClause,\n ...(file ? { file } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(publishAllLocales !== undefined ? { publishAllLocales } : {}),\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","getCollectionInputSchema","transformPointDataToPayload","whereSchema","validateCollectionData","fileInputSchema","resolveFileInput","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","file","locale","overrideLock","overwriteExistingFiles","publishAllLocales","select","where","handler","authorizedMCP","req","payload","logger","fileInput","info","content","type","text","virtualFieldNames","config","inputData","validationError","partial","parsedData","whereClause","result","collection","overrideAccess","undefined","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,yCAAwC;AAC/C,SAASC,wBAAwB,QAAQ,0DAAyD;AAClG,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,sBAAsB,QAAQ,2BAA0B;AACjE,SAASC,eAAe,EAAEC,gBAAgB,QAAQ,iBAAgB;AAClE,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBZ,qBAAqB;IACrDa,QAAQ,CAACC,OACPf,cAAce,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,OAAO7B,EAAE8B,MAAM,CAAC;QACdC,IAAI/B,EAAEgC,KAAK,CAAC;YAAChC,EAAEiC,MAAM;YAAIjC,EAAEkC,MAAM;SAAG,EAAEC,QAAQ,CAAC,oCAAoCC,QAAQ;QAC3FC,MAAMrC,EACHsC,MAAM,CAACtC,EAAEiC,MAAM,IAAIjC,EAAEuC,OAAO,IAC5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BAAEC;oBAAMC;gBAAO;gBACpBI,SAAS;gBACT,GAAID,cACA;oBACEE,mBAAmB;wBACjB9D;wBACAwD;wBACAC;wBACAM,QAAQH;oBACV;gBACF,IACA,CAAC,CAAC;YACR;QACF;QAEA,OAAO;YACLrB,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMiB;gBAAa;aAAE;YAC/CH,KAAK;gBAAEC;gBAAMC;YAAO;QACtB;IACF,EAAE,OAAOO,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9D/B,OAAO4B,KAAK,CAAC,CAAC,2BAA2B,EAAEhE,eAAe,EAAE,EAAEiE,cAAc;QAC5E,OAAOzE,sBAAsB;YAAE4E,QAAQ;YAAYpE;YAAgBgE;YAAO9B;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,+BA8D5B,CAAA"}
@@ -0,0 +1,68 @@
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 = req.user;
14
+ const permissions = authorizedMCP.overrideAccess ? null : await getAccessResults({
15
+ req
16
+ });
17
+ const authorizedCollectionSlugs = new Set();
18
+ const authorizedGlobalSlugs = new Set();
19
+ for (const item of authorizedMCP.items){
20
+ if (item.type === 'collectionTool') {
21
+ authorizedCollectionSlugs.add(item.collectionSlug);
22
+ } else if (item.type === 'globalTool') {
23
+ authorizedGlobalSlugs.add(item.globalSlug);
24
+ }
25
+ }
26
+ const collections = [];
27
+ const globals = [];
28
+ for (const collection of req.payload.config.collections){
29
+ if (!authorizedCollectionSlugs.has(collection.slug)) {
30
+ continue;
31
+ }
32
+ if (user && isEntityHidden({
33
+ hidden: collection.admin.hidden,
34
+ user
35
+ })) {
36
+ continue;
37
+ }
38
+ if (!authorizedMCP.overrideAccess && !permissions?.collections?.[collection.slug]?.read) {
39
+ continue;
40
+ }
41
+ collections.push(collection.slug);
42
+ }
43
+ for (const global of req.payload.config.globals){
44
+ if (!authorizedGlobalSlugs.has(global.slug)) {
45
+ continue;
46
+ }
47
+ if (user && isEntityHidden({
48
+ hidden: global.admin.hidden,
49
+ user
50
+ })) {
51
+ continue;
52
+ }
53
+ if (!authorizedMCP.overrideAccess && !permissions?.globals?.[global.slug]?.read) {
54
+ continue;
55
+ }
56
+ globals.push(global.slug);
57
+ }
58
+ return {
59
+ content: [
60
+ {
61
+ type: 'text',
62
+ text: `Collections: ${collections.join(', ') || 'none'}\nGlobals: ${globals.join(', ') || 'none'}`
63
+ }
64
+ ]
65
+ };
66
+ });
67
+
68
+ //# 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 = req.user\n const permissions = authorizedMCP.overrideAccess ? null : await getAccessResults({ req })\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,OAAOD,IAAIC,IAAI;IACrB,MAAMC,cAAcH,cAAcI,cAAc,GAAG,OAAO,MA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AYc,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":"AAUA,eAAO,MAAM,uBAAuB,wCAyDlC,CAAA"}
@@ -0,0 +1,64 @@
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 { whereSchema } from '../../../utils/whereSchema.js';
6
+ const DEFAULT_DESCRIPTION = 'Count global versions in any version-enabled global by passing the global slug and optional where clause.';
7
+ export const countGlobalVersionsTool = defineGlobalTool({
8
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
9
+ annotations: {
10
+ destructiveHint: false,
11
+ idempotentHint: true,
12
+ openWorldHint: false,
13
+ readOnlyHint: true,
14
+ title: 'Count Global Versions'
15
+ },
16
+ description: DEFAULT_DESCRIPTION,
17
+ input: z.object({
18
+ locale: z.string().describe('Optional: locale code to count versions in').optional(),
19
+ where: whereSchema.describe('Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.siteName":{"contains":"test"}}').optional()
20
+ })
21
+ }).handler(async ({ authorizedMCP, globalSlug, input, req })=>{
22
+ const payload = req.payload;
23
+ const logger = getLogger({
24
+ payload
25
+ });
26
+ const { locale, where } = input;
27
+ logger.info(`Counting versions for global: ${globalSlug}`);
28
+ try {
29
+ const result = await payload.countGlobalVersions({
30
+ global: globalSlug,
31
+ overrideAccess: authorizedMCP.overrideAccess,
32
+ req,
33
+ ...locale ? {
34
+ locale
35
+ } : {},
36
+ ...where ? {
37
+ where
38
+ } : {}
39
+ });
40
+ return {
41
+ content: [
42
+ {
43
+ type: 'text',
44
+ text: `Global "${globalSlug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
45
+ }
46
+ ],
47
+ doc: result
48
+ };
49
+ } catch (error) {
50
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
51
+ logger.error(`Error counting versions for global ${globalSlug}: ${errorMessage}`);
52
+ return {
53
+ content: [
54
+ {
55
+ type: 'text',
56
+ text: `❌ **Error counting versions for global "${globalSlug}":** ${errorMessage}`
57
+ }
58
+ ],
59
+ isError: true
60
+ };
61
+ }
62
+ });
63
+
64
+ //# 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 { 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 overrideAccess: authorizedMCP.overrideAccess,\n req,\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","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","overrideAccess","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,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,0BAA0BJ,iBAAiB;IACtDK,QAAQ,CAACC,OACPP,cAAcO,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,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,QAAQvB,EAAEwB,MAAM,GAAGC,QAAQ,C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}
1
+ {"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/findTool.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,cAAc,wCA8FzB,CAAA"}
@@ -1,53 +1,50 @@
1
1
  import { z } from 'zod';
2
+ import { defaultAccess } from '../../../defaultAccess.js';
2
3
  import { defineGlobalTool } from '../../../defineTool.js';
3
4
  import { getLogger } from '../../../utils/getLogger.js';
4
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
5
- const DEFAULT_DESCRIPTION = 'Find a Payload global singleton configuration.';
5
+ const DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.';
6
6
  export const findGlobalTool = defineGlobalTool({
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.read),
8
+ annotations: {
9
+ destructiveHint: false,
10
+ idempotentHint: true,
11
+ openWorldHint: false,
12
+ readOnlyHint: true,
13
+ title: 'Find Global'
14
+ },
7
15
  description: DEFAULT_DESCRIPTION,
8
16
  input: z.object({
9
17
  depth: z.number().int().min(0).max(10).describe('Depth of population for relationships').optional().default(0),
10
18
  fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
11
19
  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(),
12
- select: z.string().describe("Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'").optional()
20
+ populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
21
+ 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()
13
22
  })
14
23
  }).handler(async ({ authorizedMCP, globalSlug, input, req })=>{
15
24
  const payload = req.payload;
16
25
  const logger = getLogger({
17
26
  payload
18
27
  });
19
- const { depth, fallbackLocale, locale, select } = input;
28
+ const { depth, fallbackLocale, locale, populate, select } = input;
20
29
  logger.info(`Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`);
21
30
  try {
22
31
  const findOptions = {
23
32
  slug: globalSlug,
24
33
  depth,
25
- ...localAPIDefaults(authorizedMCP)
34
+ overrideAccess: authorizedMCP.overrideAccess,
35
+ req
26
36
  };
27
- let selectClause;
28
- if (select) {
29
- try {
30
- selectClause = JSON.parse(select);
31
- } catch {
32
- logger.warn(`Invalid select clause JSON for global: ${select}`);
33
- return {
34
- content: [
35
- {
36
- type: 'text',
37
- text: 'Error: Invalid JSON in select clause'
38
- }
39
- ]
40
- };
41
- }
42
- }
43
37
  if (locale) {
44
38
  findOptions.locale = locale;
45
39
  }
46
40
  if (fallbackLocale) {
47
41
  findOptions.fallbackLocale = fallbackLocale;
48
42
  }
49
- if (selectClause) {
50
- findOptions.select = selectClause;
43
+ if (select) {
44
+ findOptions.select = select;
45
+ }
46
+ if (populate) {
47
+ findOptions.populate = populate;
51
48
  }
52
49
  const result = await payload.findGlobal(findOptions);
53
50
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/globals/findTool.ts"],"sourcesContent":["import type { SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\n\nconst DEFAULT_DESCRIPTION = 'Find a Payload global singleton configuration.'\n\nexport const findGlobalTool = defineGlobalTool({\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('Depth of population for relationships')\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 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 select: z\n .string()\n .describe(\n \"Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\\\"title\\\": true}'\",\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const { depth, fallbackLocale, locale, select } = input\n\n logger.info(\n `Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n const findOptions: Parameters<typeof payload.findGlobal>[0] = {\n slug: globalSlug,\n depth,\n ...localAPIDefaults(authorizedMCP),\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 for global: ${select}`)\n return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }\n }\n }\n\n if (locale) {\n findOptions.locale = locale\n }\n if (fallbackLocale) {\n findOptions.fallbackLocale = fallbackLocale\n }\n if (selectClause) {\n findOptions.select = selectClause\n }\n\n const result = await payload.findGlobal(findOptions)\n\n return {\n content: [\n {\n type: 'text',\n text: `Global \"${globalSlug}\":\\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 reading global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n { type: 'text', text: `❌ **Error reading global \"${globalSlug}\":** ${errorMessage}` },\n ],\n }\n }\n})\n"],"names":["z","defineGlobalTool","getLogger","localAPIDefaults","DEFAULT_DESCRIPTION","findGlobalTool","description","input","object","depth","number","int","min","max","describe","optional","default","fallbackLocale","string","locale","select","handler","authorizedMCP","globalSlug","req","payload","logger","info","findOptions","slug","selectClause","JSON","parse","warn","content","type","text","result","findGlobal","stringify","doc","error","errorMessage","Error","message"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAA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AYX,cAAc,GAAGA;QAC/B;QACA,IAAIa,cAAc;YAChBF,YAAYR,MAAM,GAAGU;QACvB;QAEA,MAAMO,SAAS,MAAMZ,QAAQa,UAAU,CAACV;QAExC,OAAO;YACLM,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,QAAQ,EAAEb,WAAW,gBAAgB,EAAEQ,KAAKQ,SAAS,CAACF,QAAQ,QAAQ,CAAC;gBAChF;aACD;YACDG,KAAKH;QACP;IACF,EAAE,OAAOI,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DlB,OAAOe,KAAK,CAAC,CAAC,qBAAqB,EAAElB,WAAW,EAAE,EAAEmB,cAAc;QAClE,OAAO;YACLR,SAAS;gBACP;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,0BAA0B,EAAEb,WAAW,KAAK,EAAEmB,cAAc;gBAAC;aACrF;QACH;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/globals/findTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.'\n\nexport const findGlobalTool = defineGlobalTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.read),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Global',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('Depth of population for relationships')\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 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 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 }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const { depth, fallbackLocale, locale, populate, select } = input\n\n logger.info(\n `Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n const findOptions: Parameters<typeof payload.findGlobal>[0] = {\n slug: globalSlug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n }\n\n if (locale) {\n findOptions.locale = locale\n }\n if (fallbackLocale) {\n findOptions.fallbackLocale = fallbackLocale\n }\n if (select) {\n findOptions.select = select as SelectType\n }\n if (populate) {\n findOptions.populate = populate as PopulateType\n }\n\n const result = await payload.findGlobal(findOptions)\n\n return {\n content: [\n {\n type: 'text',\n text: `Global \"${globalSlug}\":\\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 reading global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n { type: 'text', text: `❌ **Error reading global \"${globalSlug}\":** ${errorMessage}` },\n ],\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","DEFAULT_DESCRIPTION","findGlobalTool","access","args","Boolean","permissions","globals","globalSlug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","depth","number","int","min","max","describe","optional","default","fallbackLocale","string","locale","populate","record","unknown","select","handler","authorizedMCP","req","payload","logger","info","findOptions","slug","overrideAccess","result","findGlobal","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message"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