@payloadcms/plugin-mcp 4.0.0-internal.a0ef1b8 → 4.0.0-internal.a6582c6

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 (250) 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 +68 -17
  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 -80
  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 +110 -63
  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 +28 -0
  57. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  58. package/dist/mcp/builtin/collections/fileInput.js +124 -0
  59. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  60. package/dist/mcp/builtin/collections/fileInput.spec.js +86 -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 +87 -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 -93
  93. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  94. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  95. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  96. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  97. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  98. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  99. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  100. package/dist/mcp/builtin/getConfigInfoTool.js +68 -0
  101. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  102. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  103. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  104. package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
  105. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  106. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  107. package/dist/mcp/builtin/globals/findTool.js +20 -23
  108. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  109. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  110. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  111. package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
  112. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  113. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  114. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  115. package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
  116. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  117. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  118. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  119. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +65 -0
  120. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  121. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  122. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  123. package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
  124. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  125. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  126. package/dist/mcp/builtin/globals/updateTool.js +33 -42
  127. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  128. package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
  129. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
  130. package/dist/mcp/builtin/validateEntityData.js +82 -0
  131. package/dist/mcp/builtin/validateEntityData.js.map +1 -0
  132. package/dist/mcp/builtinTools.d.ts +150 -19
  133. package/dist/mcp/builtinTools.d.ts.map +1 -1
  134. package/dist/mcp/builtinTools.js +125 -20
  135. package/dist/mcp/builtinTools.js.map +1 -1
  136. package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
  137. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  138. package/dist/mcp/sanitizeMCPConfig.js +124 -58
  139. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  140. package/dist/stdio.d.ts +3 -3
  141. package/dist/stdio.d.ts.map +1 -1
  142. package/dist/stdio.js +84 -46
  143. package/dist/stdio.js.map +1 -1
  144. package/dist/types.d.ts +112 -110
  145. package/dist/types.d.ts.map +1 -1
  146. package/dist/types.js +2 -4
  147. package/dist/types.js.map +1 -1
  148. package/dist/utils/camelCase.d.ts.map +1 -1
  149. package/dist/utils/getPluginConfig.d.ts +1 -1
  150. package/dist/utils/getPluginConfig.js +1 -1
  151. package/dist/utils/getPluginConfig.js.map +1 -1
  152. package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
  153. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
  154. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  155. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  156. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  157. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +13 -0
  158. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
  159. package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
  160. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
  161. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +5 -10
  162. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
  163. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +15 -95
  164. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -1
  165. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +15 -40
  166. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
  167. package/dist/utils/toStandardSchema.d.ts.map +1 -1
  168. package/dist/utils/whereSchema.d.ts +9 -0
  169. package/dist/utils/whereSchema.d.ts.map +1 -0
  170. package/dist/utils/whereSchema.js +13 -0
  171. package/dist/utils/whereSchema.js.map +1 -0
  172. package/package.json +10 -15
  173. package/src/defaultAccess.ts +3 -0
  174. package/src/endpoint/access.ts +81 -101
  175. package/src/endpoint/index.ts +58 -16
  176. package/src/exports/client.ts +2 -1
  177. package/src/exports/internal.ts +1 -0
  178. package/src/index.ts +12 -20
  179. package/src/mcp/buildMcpServer.ts +170 -115
  180. package/src/mcp/builtin/collections/authTools.ts +45 -9
  181. package/src/mcp/builtin/collections/countTool.ts +73 -0
  182. package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
  183. package/src/mcp/builtin/collections/createTool.ts +130 -78
  184. package/src/mcp/builtin/collections/deleteTool.ts +20 -18
  185. package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
  186. package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
  187. package/src/mcp/builtin/collections/fileInput.ts +164 -0
  188. package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
  189. package/src/mcp/builtin/collections/findTool.ts +66 -37
  190. package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
  191. package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
  192. package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
  193. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +80 -0
  194. package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
  195. package/src/mcp/builtin/collections/updateTool.ts +132 -115
  196. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  197. package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
  198. package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
  199. package/src/mcp/builtin/globals/findTool.ts +28 -19
  200. package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
  201. package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
  202. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
  203. package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
  204. package/src/mcp/builtin/globals/updateTool.ts +52 -57
  205. package/src/mcp/builtin/validateEntityData.ts +132 -0
  206. package/src/mcp/builtinTools.ts +118 -41
  207. package/src/mcp/sanitizeMCPConfig.ts +120 -78
  208. package/src/stdio.ts +79 -46
  209. package/src/types.ts +128 -115
  210. package/src/utils/getPluginConfig.ts +1 -1
  211. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  212. package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
  213. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +12 -19
  214. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +17 -114
  215. package/src/utils/whereSchema.ts +24 -0
  216. package/dist/@types/assets.d.js +0 -2
  217. package/dist/@types/assets.d.js.map +0 -1
  218. package/dist/collection/getAccessField.d.ts +0 -12
  219. package/dist/collection/getAccessField.d.ts.map +0 -1
  220. package/dist/collection/getAccessField.js +0 -57
  221. package/dist/collection/getAccessField.js.map +0 -1
  222. package/dist/collection/index.d.ts +0 -6
  223. package/dist/collection/index.d.ts.map +0 -1
  224. package/dist/collection/index.js +0 -60
  225. package/dist/collection/index.js.map +0 -1
  226. package/dist/components/AccessField/index.client.d.ts +0 -10
  227. package/dist/components/AccessField/index.client.d.ts.map +0 -1
  228. package/dist/components/AccessField/index.client.js +0 -305
  229. package/dist/components/AccessField/index.client.js.map +0 -1
  230. package/dist/components/AccessField/index.css +0 -93
  231. package/dist/utils/localAPIDefaults.d.ts +0 -20
  232. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  233. package/dist/utils/localAPIDefaults.js +0 -19
  234. package/dist/utils/localAPIDefaults.js.map +0 -1
  235. package/dist/utils/schemaConversion/buildToolInput.d.ts +0 -29
  236. package/dist/utils/schemaConversion/buildToolInput.d.ts.map +0 -1
  237. package/dist/utils/schemaConversion/buildToolInput.js +0 -51
  238. package/dist/utils/schemaConversion/buildToolInput.js.map +0 -1
  239. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  240. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  241. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  242. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  243. package/src/@types/assets.d.ts +0 -3
  244. package/src/collection/getAccessField.ts +0 -64
  245. package/src/collection/index.ts +0 -64
  246. package/src/components/AccessField/index.client.tsx +0 -344
  247. package/src/components/AccessField/index.css +0 -93
  248. package/src/utils/localAPIDefaults.ts +0 -22
  249. package/src/utils/schemaConversion/buildToolInput.ts +0 -68
  250. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
@@ -0,0 +1,96 @@
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 { getCollectionVirtualFieldNames, stripVirtualFields } from '../../../utils/getVirtualFieldNames.js';
6
+ import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js';
7
+ import { formatCollectionError } from './formatCollectionError.js';
8
+ const DEFAULT_DESCRIPTION = 'Duplicate a document in any collection by passing the collection slug and source document ID.';
9
+ export const duplicateDocumentTool = defineCollectionTool({
10
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.create),
11
+ annotations: {
12
+ destructiveHint: false,
13
+ idempotentHint: false,
14
+ openWorldHint: false,
15
+ readOnlyHint: false,
16
+ title: 'Duplicate Document'
17
+ },
18
+ description: DEFAULT_DESCRIPTION,
19
+ input: z.object({
20
+ id: z.union([
21
+ z.string(),
22
+ z.number()
23
+ ]).describe('The ID of the document to duplicate'),
24
+ data: z.record(z.string(), z.unknown()).describe('Optional: fields to override on the duplicated document').optional(),
25
+ depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in response').optional().default(0),
26
+ draft: z.boolean().describe('Whether to create the duplicate as a draft').optional().default(false),
27
+ fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
28
+ locale: z.string().describe('Optional: locale code to duplicate in (e.g., "en", "es"). Defaults to the default locale').optional(),
29
+ populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
30
+ 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(),
31
+ selectedLocales: z.array(z.string()).describe('Optional: localized field locales to include in the duplicated document').optional(),
32
+ showHiddenFields: z.boolean().describe('Optional: include hidden fields in the duplicated document response').optional()
33
+ })
34
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
35
+ const payload = req.payload;
36
+ const logger = getLogger({
37
+ payload
38
+ });
39
+ const { id, data, depth, draft, fallbackLocale, locale, populate, select, selectedLocales, showHiddenFields } = input;
40
+ logger.info(`Duplicating document in collection: ${collectionSlug} with ID: ${id}`);
41
+ try {
42
+ const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug);
43
+ const inputData = data ? stripVirtualFields(data, virtualFieldNames) : undefined;
44
+ const parsedData = inputData ? transformPointDataToPayload(inputData) : undefined;
45
+ const result = await payload.duplicate({
46
+ id,
47
+ collection: collectionSlug,
48
+ depth,
49
+ draft,
50
+ overrideAccess: authorizedMCP.overrideAccess,
51
+ req,
52
+ ...parsedData ? {
53
+ data: parsedData
54
+ } : {},
55
+ ...locale ? {
56
+ locale
57
+ } : {},
58
+ ...fallbackLocale ? {
59
+ fallbackLocale
60
+ } : {},
61
+ ...populate ? {
62
+ populate: populate
63
+ } : {},
64
+ ...select ? {
65
+ select: select
66
+ } : {},
67
+ ...selectedLocales ? {
68
+ selectedLocales
69
+ } : {},
70
+ ...showHiddenFields !== undefined ? {
71
+ showHiddenFields
72
+ } : {}
73
+ });
74
+ logger.info(`Successfully duplicated document in ${collectionSlug} from ID: ${id}`);
75
+ return {
76
+ content: [
77
+ {
78
+ type: 'text',
79
+ text: `Document duplicated successfully in collection "${collectionSlug}"!\nDuplicated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
80
+ }
81
+ ],
82
+ doc: result
83
+ };
84
+ } catch (error) {
85
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
86
+ logger.error(`Error duplicating document in ${collectionSlug}: ${errorMessage}`);
87
+ return formatCollectionError({
88
+ action: 'duplicating',
89
+ collectionSlug,
90
+ error,
91
+ req
92
+ });
93
+ }
94
+ });
95
+
96
+ //# sourceMappingURL=duplicateTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/duplicateTool.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 {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'\nimport { formatCollectionError } from './formatCollectionError.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Duplicate a document in any collection by passing the collection slug and source document ID.'\n\nexport const duplicateDocumentTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.create),\n annotations: {\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Duplicate 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 duplicate'),\n data: z\n .record(z.string(), z.unknown())\n .describe('Optional: fields to override on the duplicated document')\n .optional(),\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 create the duplicate 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(\n 'Optional: locale code to duplicate in (e.g., \"en\", \"es\"). Defaults to the default locale',\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 selectedLocales: z\n .array(z.string())\n .describe('Optional: localized field locales to include in the duplicated document')\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the duplicated document response')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const {\n id,\n data,\n depth,\n draft,\n fallbackLocale,\n locale,\n populate,\n select,\n selectedLocales,\n showHiddenFields,\n } = input\n\n logger.info(`Duplicating document in collection: ${collectionSlug} with ID: ${id}`)\n\n try {\n const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n const inputData = data ? stripVirtualFields(data, virtualFieldNames) : undefined\n const parsedData = inputData ? transformPointDataToPayload(inputData) : undefined\n\n const result = await payload.duplicate({\n id,\n collection: collectionSlug,\n depth,\n draft,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(parsedData ? { data: parsedData } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(selectedLocales ? { selectedLocales } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n })\n\n logger.info(`Successfully duplicated document in ${collectionSlug} from ID: ${id}`)\n\n return {\n content: [\n {\n type: 'text',\n text: `Document duplicated successfully in collection \"${collectionSlug}\"!\\nDuplicated 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 duplicating document in ${collectionSlug}: ${errorMessage}`)\n return formatCollectionError({ action: 'duplicating', collectionSlug, error, req })\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","getCollectionVirtualFieldNames","stripVirtualFields","transformPointDataToPayload","formatCollectionError","DEFAULT_DESCRIPTION","duplicateDocumentTool","access","args","Boolean","permissions","collections","collectionSlug","create","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","union","string","number","describe","data","record","unknown","optional","depth","int","min","max","default","draft","boolean","fallbackLocale","locale","populate","select","selectedLocales","array","showHiddenFields","handler","authorizedMCP","req","payload","logger","info","virtualFieldNames","config","inputData","undefined","parsedData","result","duplicate","collection","overrideAccess","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","action"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB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V;YAAiB,IAAI,CAAC,CAAC;QAChE;QAEAK,OAAOC,IAAI,CAAC,CAAC,oCAAoC,EAAEvC,eAAe,UAAU,EAAEW,IAAI;QAElF,OAAO;YACLsC,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,gDAAgD,EAAEnD,eAAe,sCAAsC,EAAEoD,KAAKC,SAAS,CAACR,QAAQ,QAAQ,CAAC;gBAClJ;aACD;YACDS,KAAKT;QACP;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DpB,OAAOiB,KAAK,CAAC,CAAC,8BAA8B,EAAEvD,eAAe,EAAE,EAAEwD,cAAc;QAC/E,OAAOhE,sBAAsB;YAAEmE,QAAQ;YAAe3D;YAAgBuD;YAAOnB;QAAI;IACnF;AACF,GAAE"}
@@ -0,0 +1,28 @@
1
+ import type { CollectionSlug, File, PayloadRequest } from 'payload';
2
+ import { z } from 'zod';
3
+ export declare const fileInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
4
+ name: z.ZodString;
5
+ data: z.ZodString;
6
+ mimeType: z.ZodString;
7
+ source: z.ZodLiteral<"base64">;
8
+ }, z.core.$strip>, z.ZodObject<{
9
+ name: z.ZodOptional<z.ZodString>;
10
+ source: z.ZodLiteral<"externalURL">;
11
+ url: z.ZodURL;
12
+ }, z.core.$strip>, z.ZodObject<{
13
+ file: z.ZodObject<{
14
+ filename: z.ZodString;
15
+ mimeType: z.ZodString;
16
+ size: z.ZodNumber;
17
+ uploadReference: z.ZodRecord<z.ZodString, z.ZodUnknown>;
18
+ }, z.core.$strip>;
19
+ source: z.ZodLiteral<"uploadReference">;
20
+ }, z.core.$strip>], "source">;
21
+ type FileInput = z.infer<typeof fileInputSchema>;
22
+ export declare function resolveFile({ collectionSlug, input, req, }: {
23
+ collectionSlug: CollectionSlug;
24
+ input?: FileInput;
25
+ req: PayloadRequest;
26
+ }): Promise<File | undefined>;
27
+ export {};
28
+ //# sourceMappingURL=fileInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileInput.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/fileInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAY,cAAc,EAAE,MAAM,SAAS,CAAA;AAK7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAavB,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;6BAoBzB,CAAA;AAEH,KAAK,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA;AAEhD,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,KAAK,EACL,GAAG,GACJ,EAAE;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CA8E5B"}
@@ -0,0 +1,124 @@
1
+ import { APIError } from 'payload';
2
+ import { getExternalFile, getFileFromUploadInstructions, isURLAllowed } from 'payload/internal';
3
+ import { sanitizeFilename } from 'payload/shared';
4
+ import { z } from 'zod';
5
+ const mimeTypeSchema = z.string().regex(/^[!#$%&'*+.^`|~\w-]+\/[!#$%&'*+.^`|~\w-]+$/, 'MIME type must use the type/subtype format');
6
+ const uploadFileSchema = z.object({
7
+ filename: z.string(),
8
+ mimeType: z.string(),
9
+ size: z.number().int().nonnegative(),
10
+ uploadReference: z.record(z.string(), z.unknown())
11
+ });
12
+ export const fileInputSchema = z.discriminatedUnion('source', [
13
+ z.object({
14
+ name: z.string().min(1).describe('The file name, including its extension'),
15
+ data: z.string().describe('The base64-encoded file bytes, without a data URL prefix'),
16
+ mimeType: mimeTypeSchema.describe('The file MIME type, for example image/png'),
17
+ source: z.literal('base64')
18
+ }),
19
+ z.object({
20
+ name: z.string().min(1).describe('Optional file name override').optional(),
21
+ source: z.literal('externalURL'),
22
+ url: z.url().describe('The http or https URL to download')
23
+ }),
24
+ z.object({
25
+ file: uploadFileSchema.describe('getUploadInstructions file field post-upload'),
26
+ source: z.literal('uploadReference')
27
+ })
28
+ ]).describe('A file for an upload collection. Prefer uploadReference after its upload succeeds; use base64 only for small local files or externalURL for an online file.');
29
+ export async function resolveFile({ collectionSlug, input, req }) {
30
+ if (!input) {
31
+ return undefined;
32
+ }
33
+ if (input.source === 'uploadReference') {
34
+ try {
35
+ return await getFileFromUploadInstructions({
36
+ collectionSlug,
37
+ file: input.file,
38
+ req
39
+ });
40
+ } catch (error) {
41
+ if (error instanceof Error && error.message === 'Staged upload was not found.') {
42
+ throw new APIError('Staged upload not found. Complete the upload action first, or use base64 for small local files.', 400);
43
+ }
44
+ throw error;
45
+ }
46
+ }
47
+ const uploadConfig = req.payload.collections[collectionSlug]?.config.upload;
48
+ if (!uploadConfig) {
49
+ throw new APIError(`Collection "${collectionSlug}" does not support file uploads.`, 400);
50
+ }
51
+ const maxFileSize = req.payload.config.upload.limits?.fileSize;
52
+ let file;
53
+ if (input.source === 'base64') {
54
+ const data = decodeBase64({
55
+ maxFileSize,
56
+ value: input.data
57
+ });
58
+ file = {
59
+ name: sanitizeFilename(input.name),
60
+ data,
61
+ mimetype: input.mimeType,
62
+ size: data.length
63
+ };
64
+ } else {
65
+ if (uploadConfig.pasteURL === false) {
66
+ throw new APIError(`Uploading files from URLs is disabled for collection "${collectionSlug}".`, 400);
67
+ }
68
+ const url = new URL(input.url);
69
+ if (![
70
+ 'http:',
71
+ 'https:'
72
+ ].includes(url.protocol)) {
73
+ throw new APIError('File URLs must use http or https.', 400);
74
+ }
75
+ if (typeof uploadConfig.pasteURL === 'object' && !isURLAllowed(input.url, uploadConfig.pasteURL.allowList)) {
76
+ throw new APIError('The provided file URL is not allowed.', 400);
77
+ }
78
+ file = await getExternalFile({
79
+ data: {
80
+ filename: sanitizeFilename(input.name || getURLFilename(url)),
81
+ url: input.url
82
+ },
83
+ req,
84
+ uploadConfig: {
85
+ ...uploadConfig,
86
+ externalFileHeaderFilter: uploadConfig.externalFileHeaderFilter ?? (()=>({}))
87
+ }
88
+ });
89
+ file.mimetype = file.mimetype?.split(';')[0] || 'application/octet-stream';
90
+ file.size = file.data.length;
91
+ }
92
+ if (maxFileSize !== undefined && Number.isFinite(maxFileSize) && file.size > maxFileSize) {
93
+ throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400);
94
+ }
95
+ return file;
96
+ }
97
+ function decodeBase64({ maxFileSize, value }) {
98
+ const normalized = value.replace(/\s/g, '');
99
+ if (!/^[a-z0-9+/]*={0,2}$/i.test(normalized) || normalized.length % 4 === 1) {
100
+ throw new APIError('File data must be valid base64.', 400);
101
+ }
102
+ if (maxFileSize !== undefined && Number.isFinite(maxFileSize)) {
103
+ const paddingLength = normalized.endsWith('==') ? 2 : normalized.endsWith('=') ? 1 : 0;
104
+ const decodedSize = Math.floor(normalized.length * 3 / 4) - paddingLength;
105
+ if (decodedSize > maxFileSize) {
106
+ throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400);
107
+ }
108
+ }
109
+ const data = Buffer.from(normalized, 'base64');
110
+ if (data.toString('base64').replace(/=+$/, '') !== normalized.replace(/=+$/, '')) {
111
+ throw new APIError('File data must be valid base64.', 400);
112
+ }
113
+ return data;
114
+ }
115
+ function getURLFilename(url) {
116
+ const pathSegment = url.pathname.split('/').pop() || 'upload';
117
+ try {
118
+ return decodeURIComponent(pathSegment);
119
+ } catch {
120
+ return pathSegment;
121
+ }
122
+ }
123
+
124
+ //# sourceMappingURL=fileInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/fileInput.ts"],"sourcesContent":["import type { CollectionSlug, File, FileData, PayloadRequest } from 'payload'\n\nimport { APIError } from 'payload'\nimport { getExternalFile, getFileFromUploadInstructions, isURLAllowed } from 'payload/internal'\nimport { sanitizeFilename } from 'payload/shared'\nimport { z } from 'zod'\n\nconst mimeTypeSchema = z\n .string()\n .regex(/^[!#$%&'*+.^`|~\\w-]+\\/[!#$%&'*+.^`|~\\w-]+$/, 'MIME type must use the type/subtype format')\n\nconst uploadFileSchema = z.object({\n filename: z.string(),\n mimeType: z.string(),\n size: z.number().int().nonnegative(),\n uploadReference: z.record(z.string(), z.unknown()),\n})\n\nexport const fileInputSchema = z\n .discriminatedUnion('source', [\n z.object({\n name: z.string().min(1).describe('The file name, including its extension'),\n data: z.string().describe('The base64-encoded file bytes, without a data URL prefix'),\n mimeType: mimeTypeSchema.describe('The file MIME type, for example image/png'),\n source: z.literal('base64'),\n }),\n z.object({\n name: z.string().min(1).describe('Optional file name override').optional(),\n source: z.literal('externalURL'),\n url: z.url().describe('The http or https URL to download'),\n }),\n z.object({\n file: uploadFileSchema.describe('getUploadInstructions file field post-upload'),\n source: z.literal('uploadReference'),\n }),\n ])\n .describe(\n 'A file for an upload collection. Prefer uploadReference after its upload succeeds; use base64 only for small local files or externalURL for an online file.',\n )\n\ntype FileInput = z.infer<typeof fileInputSchema>\n\nexport async function resolveFile({\n collectionSlug,\n input,\n req,\n}: {\n collectionSlug: CollectionSlug\n input?: FileInput\n req: PayloadRequest\n}): Promise<File | undefined> {\n if (!input) {\n return undefined\n }\n\n if (input.source === 'uploadReference') {\n try {\n return await getFileFromUploadInstructions({ collectionSlug, file: input.file, req })\n } catch (error) {\n if (error instanceof Error && error.message === 'Staged upload was not found.') {\n throw new APIError(\n 'Staged upload not found. Complete the upload action first, or use base64 for small local files.',\n 400,\n )\n }\n throw error\n }\n }\n\n const uploadConfig = req.payload.collections[collectionSlug]?.config.upload\n\n if (!uploadConfig) {\n throw new APIError(`Collection \"${collectionSlug}\" does not support file uploads.`, 400)\n }\n\n const maxFileSize = req.payload.config.upload.limits?.fileSize\n let file: File\n\n if (input.source === 'base64') {\n const data = decodeBase64({ maxFileSize, value: input.data })\n\n file = {\n name: sanitizeFilename(input.name),\n data,\n mimetype: input.mimeType,\n size: data.length,\n }\n } else {\n if (uploadConfig.pasteURL === false) {\n throw new APIError(\n `Uploading files from URLs is disabled for collection \"${collectionSlug}\".`,\n 400,\n )\n }\n\n const url = new URL(input.url)\n\n if (!['http:', 'https:'].includes(url.protocol)) {\n throw new APIError('File URLs must use http or https.', 400)\n }\n\n if (\n typeof uploadConfig.pasteURL === 'object' &&\n !isURLAllowed(input.url, uploadConfig.pasteURL.allowList)\n ) {\n throw new APIError('The provided file URL is not allowed.', 400)\n }\n\n file = await getExternalFile({\n data: {\n filename: sanitizeFilename(input.name || getURLFilename(url)),\n url: input.url,\n } as FileData,\n req,\n uploadConfig: {\n ...uploadConfig,\n externalFileHeaderFilter: uploadConfig.externalFileHeaderFilter ?? (() => ({})),\n },\n })\n file.mimetype = file.mimetype?.split(';')[0] || 'application/octet-stream'\n file.size = file.data.length\n }\n\n if (maxFileSize !== undefined && Number.isFinite(maxFileSize) && file.size > maxFileSize) {\n throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400)\n }\n\n return file\n}\n\nfunction decodeBase64({ maxFileSize, value }: { maxFileSize?: number; value: string }): Buffer {\n const normalized = value.replace(/\\s/g, '')\n\n if (!/^[a-z0-9+/]*={0,2}$/i.test(normalized) || normalized.length % 4 === 1) {\n throw new APIError('File data must be valid base64.', 400)\n }\n\n if (maxFileSize !== undefined && Number.isFinite(maxFileSize)) {\n const paddingLength = normalized.endsWith('==') ? 2 : normalized.endsWith('=') ? 1 : 0\n const decodedSize = Math.floor((normalized.length * 3) / 4) - paddingLength\n\n if (decodedSize > maxFileSize) {\n throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400)\n }\n }\n\n const data = Buffer.from(normalized, 'base64')\n\n if (data.toString('base64').replace(/=+$/, '') !== normalized.replace(/=+$/, '')) {\n throw new APIError('File data must be valid base64.', 400)\n }\n\n return data\n}\n\nfunction getURLFilename(url: URL): string {\n const pathSegment = url.pathname.split('/').pop() || 'upload'\n\n try {\n return decodeURIComponent(pathSegment)\n } catch {\n return pathSegment\n }\n}\n"],"names":["APIError","getExternalFile","getFileFromUploadInstructions","isURLAllowed","sanitizeFilename","z","mimeTypeSchema","string","regex","uploadFileSchema","object","filename","mimeType","size","number","int","nonnegative","uploadReference","record","unknown","fileInputSchema","discriminatedUnion","name","min","describe","data","source","literal","optional","url","file","resolveFile","collectionSlug","input","req","undefined","error","Error","message","uploadConfig","payload","collections","config","upload","maxFileSize","limits","fileSize","decodeBase64","value","mimetype","length","pasteURL","URL","includes","protocol","allowList","getURLFilename","externalFileHeaderFilter","split","Number","isFinite","normalized","replace","test","paddingLength","endsWith","decodedSize","Math","floor","Buffer","from","toString","pathSegment","pathname","pop","decodeURIComponent"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,eAAe,EAAEC,6BAA6B,EAAEC,YAAY,QAAQ,mBAAkB;AAC/F,SAASC,gBAAgB,QAAQ,iBAAgB;AACjD,SAASC,CAAC,QAAQ,MAAK;AAEvB,MAAMC,iBAAiBD,EACpBE,MAAM,GACNC,KAAK,CAAC,8CAA8C;AAEvD,MAAMC,mBAAmBJ,EAAEK,MAAM,CAAC;IAChCC,UAAUN,EAAEE,MAAM;IAClBK,UAAUP,EAAEE,MAAM;IAClBM,MAAMR,EAAES,MAAM,GAAGC,GAAG,GAAGC,WAAW;IAClCC,iBAAiBZ,EAAEa,MAAM,CAACb,EAAEE,MAAM,IAAIF,EAAEc,OAAO;AACjD;AAEA,OAAO,MAAMC,kBAAkBf,EAC5BgB,kBAAkB,CAAC,UAAU;IAC5BhB,EAAEK,MAAM,CAAC;QACPY,MAAMjB,EAAEE,MAAM,GAAGgB,GAAG,CAAC,GAAGC,QAAQ,CAAC;QACjCC,MAAMpB,EAAEE,MAAM,GAAGiB,QAAQ,CAAC;QAC1BZ,UAAUN,eAAekB,QAAQ,CAAC;QAClCE,QAAQrB,EAAEsB,OAAO,CAAC;IACpB;IACAtB,EAAEK,MAAM,CAAC;QACPY,MAAMjB,EAAEE,MAAM,GAAGgB,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BAAgBT,aAAawB,OAAOC,QAAQ,CAAChB,cAAc;QAC7D,MAAMoB,gBAAgBH,WAAWI,QAAQ,CAAC,QAAQ,IAAIJ,WAAWI,QAAQ,CAAC,OAAO,IAAI;QACrF,MAAMC,cAAcC,KAAKC,KAAK,CAAC,AAACP,WAAWX,MAAM,GAAG,IAAK,KAAKc;QAE9D,IAAIE,cAActB,aAAa;YAC7B,MAAM,IAAI5C,SAAS,CAAC,iBAAiB,EAAE4C,YAAY,mBAAmB,CAAC,EAAE;QAC3E;IACF;IAEA,MAAMnB,OAAO4C,OAAOC,IAAI,CAACT,YAAY;IAErC,IAAIpC,KAAK8C,QAAQ,CAAC,UAAUT,OAAO,CAAC,OAAO,QAAQD,WAAWC,OAAO,CAAC,OAAO,KAAK;QAChF,MAAM,IAAI9D,SAAS,mCAAmC;IACxD;IAEA,OAAOyB;AACT;AAEA,SAAS+B,eAAe3B,GAAQ;IAC9B,MAAM2C,cAAc3C,IAAI4C,QAAQ,CAACf,KAAK,CAAC,KAAKgB,GAAG,MAAM;IAErD,IAAI;QACF,OAAOC,mBAAmBH;IAC5B,EAAE,OAAM;QACN,OAAOA;IACT;AACF"}
@@ -0,0 +1,86 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { fileInputSchema, resolveFile } from './fileInput.js';
3
+ describe('MCP file input', ()=>{
4
+ it('should reject malformed MIME types', ()=>{
5
+ const result = fileInputSchema.safeParse({
6
+ data: 'aGVsbG8=',
7
+ mimeType: 'text/plain\r\nx-test: value',
8
+ name: 'hello.txt',
9
+ source: 'base64'
10
+ });
11
+ expect(result.success).toBe(false);
12
+ });
13
+ it('should accept a prepared upload', ()=>{
14
+ const result = fileInputSchema.safeParse({
15
+ file: {
16
+ filename: 'image.png',
17
+ mimeType: 'image/png',
18
+ size: 123,
19
+ uploadReference: {
20
+ uploadId: 'upload-id'
21
+ }
22
+ },
23
+ source: 'uploadReference'
24
+ });
25
+ expect(result.success).toBe(true);
26
+ });
27
+ it('should reject oversized base64 files', async ()=>{
28
+ const req = createRequest({
29
+ maxFileSize: 4
30
+ });
31
+ await expect(resolveFile({
32
+ collectionSlug: 'media',
33
+ input: {
34
+ data: Buffer.from('hello').toString('base64'),
35
+ mimeType: 'text/plain',
36
+ name: 'hello.txt',
37
+ source: 'base64'
38
+ },
39
+ req
40
+ })).rejects.toThrow('File exceeds the 4 byte upload limit.');
41
+ });
42
+ it('should reject URLs outside the collection allowlist', async ()=>{
43
+ const req = createRequest({
44
+ allowList: [
45
+ {
46
+ hostname: 'assets.example.com',
47
+ protocol: 'https'
48
+ }
49
+ ]
50
+ });
51
+ await expect(resolveFile({
52
+ collectionSlug: 'media',
53
+ input: {
54
+ source: 'externalURL',
55
+ url: 'https://example.com/image.png'
56
+ },
57
+ req
58
+ })).rejects.toThrow('The provided file URL is not allowed.');
59
+ });
60
+ });
61
+ function createRequest({ allowList, maxFileSize }) {
62
+ return {
63
+ payload: {
64
+ collections: {
65
+ media: {
66
+ config: {
67
+ upload: allowList ? {
68
+ pasteURL: {
69
+ allowList
70
+ }
71
+ } : {}
72
+ }
73
+ }
74
+ },
75
+ config: {
76
+ upload: {
77
+ limits: {
78
+ fileSize: maxFileSize
79
+ }
80
+ }
81
+ }
82
+ }
83
+ };
84
+ }
85
+
86
+ //# sourceMappingURL=fileInput.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/fileInput.spec.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { fileInputSchema, resolveFile } from './fileInput.js'\n\ndescribe('MCP file input', () => {\n it('should reject malformed MIME types', () => {\n const result = fileInputSchema.safeParse({\n data: 'aGVsbG8=',\n mimeType: 'text/plain\\r\\nx-test: value',\n name: 'hello.txt',\n source: 'base64',\n })\n\n expect(result.success).toBe(false)\n })\n\n it('should accept a prepared upload', () => {\n const result = fileInputSchema.safeParse({\n file: {\n filename: 'image.png',\n mimeType: 'image/png',\n size: 123,\n uploadReference: { uploadId: 'upload-id' },\n },\n source: 'uploadReference',\n })\n\n expect(result.success).toBe(true)\n })\n\n it('should reject oversized base64 files', async () => {\n const req = createRequest({ maxFileSize: 4 })\n\n await expect(\n resolveFile({\n collectionSlug: 'media',\n input: {\n data: Buffer.from('hello').toString('base64'),\n mimeType: 'text/plain',\n name: 'hello.txt',\n source: 'base64',\n },\n req,\n }),\n ).rejects.toThrow('File exceeds the 4 byte upload limit.')\n })\n\n it('should reject URLs outside the collection allowlist', async () => {\n const req = createRequest({\n allowList: [{ hostname: 'assets.example.com', protocol: 'https' }],\n })\n\n await expect(\n resolveFile({\n collectionSlug: 'media',\n input: {\n source: 'externalURL',\n url: 'https://example.com/image.png',\n },\n req,\n }),\n ).rejects.toThrow('The provided file URL is not allowed.')\n })\n})\n\nfunction createRequest({\n allowList,\n maxFileSize,\n}: {\n allowList?: Array<{ hostname: string; protocol: 'http' | 'https' }>\n maxFileSize?: number\n}): PayloadRequest {\n return {\n payload: {\n collections: {\n media: {\n config: {\n upload: allowList ? { pasteURL: { allowList } } : {},\n },\n },\n },\n config: {\n upload: {\n limits: {\n fileSize: maxFileSize,\n },\n },\n },\n },\n } as unknown as PayloadRequest\n}\n"],"names":["describe","expect","it","fileInputSchema","resolveFile","result","safeParse","data","mimeType","name","source","success","toBe","file","filename","size","uploadReference","uploadId","req","createRequest","maxFileSize","collectionSlug","input","Buffer","from","toString","rejects","toThrow","allowList","hostname","protocol","url","payload","collections","media","config","upload","pasteURL","limits","fileSize"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,eAAe,EAAEC,WAAW,QAAQ,iBAAgB;AAE7DJ,SAAS,kBAAkB;IACzBE,GAAG,sCAAsC;QACvC,MAAMG,SAASF,gBAAgBG,SAAS,CAAC;YACvCC,MAAM;YACNC,UAAU;YACVC,MAAM;YACNC,QAAQ;QACV;QAEAT,OAAOI,OAAOM,OAAO,EAAEC,IAAI,CAAC;IAC9B;IAEAV,GAAG,mCAAmC;QACpC,MAAMG,SAASF,gBAAgBG,SAAS,CAAC;YACvCO,MAAM;gBACJC,UAAU;gBACVN,UAAU;gBACVO,MAAM;gBACNC,iBAAiB;oBAAEC,UAAU;gBAAY;YAC3C;YACAP,QAAQ;QACV;QAEAT,OAAOI,OAAOM,OAAO,EAAEC,IAAI,CAAC;IAC9B;IAEAV,GAAG,wCAAwC;QACzC,MAAMgB,MAAMC,cAAc;YAAEC,aAAa;QAAE;QAE3C,MAAMnB,OACJG,YAAY;YACViB,gBAAgB;YAChBC,OAAO;gBACLf,MAAMgB,OAAOC,IAAI,CAAC,SAASC,QAAQ,CAAC;gBACpCjB,UAAU;gBACVC,MAAM;gBACNC,QAAQ;YACV;YACAQ;QACF,IACAQ,OAAO,CAACC,OAAO,CAAC;IACpB;IAEAzB,GAAG,uDAAuD;QACxD,MAAMgB,MAAMC,cAAc;YACxBS,WAAW;gBAAC;oBAAEC,UAAU;oBAAsBC,UAAU;gBAAQ;aAAE;QACpE;QAEA,MAAM7B,OACJG,YAAY;YACViB,gBAAgB;YAChBC,OAAO;gBACLZ,QAAQ;gBACRqB,KAAK;YACP;YACAb;QACF,IACAQ,OAAO,CAACC,OAAO,CAAC;IACpB;AACF;AAEA,SAASR,cAAc,EACrBS,SAAS,EACTR,WAAW,EAIZ;IACC,OAAO;QACLY,SAAS;YACPC,aAAa;gBACXC,OAAO;oBACLC,QAAQ;wBACNC,QAAQR,YAAY;4BAAES,UAAU;gCAAET;4BAAU;wBAAE,IAAI,CAAC;oBACrD;gBACF;YACF;YACAO,QAAQ;gBACNC,QAAQ;oBACNE,QAAQ;wBACNC,UAAUnB;oBACZ;gBACF;YACF;QACF;IACF;AACF"}
@@ -0,0 +1,2 @@
1
+ export declare const findDistinctTool: import("../../../types.js").CollectionTool;
2
+ //# sourceMappingURL=findDistinctTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findDistinctTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findDistinctTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,gBAAgB,4CA0G3B,CAAA"}
@@ -0,0 +1,92 @@
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 { whereSchema } from '../../../utils/whereSchema.js';
6
+ const DEFAULT_DESCRIPTION = 'Find distinct values for a field in any collection by passing the collection slug and field path.';
7
+ export const findDistinctTool = defineCollectionTool({
8
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),
9
+ annotations: {
10
+ destructiveHint: false,
11
+ idempotentHint: true,
12
+ openWorldHint: false,
13
+ readOnlyHint: true,
14
+ title: 'Find Distinct'
15
+ },
16
+ description: DEFAULT_DESCRIPTION,
17
+ input: z.object({
18
+ depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in distinct values').optional().default(0),
19
+ field: z.string().describe('The field path to get distinct values for'),
20
+ limit: z.number().int().min(1).max(100).describe('Maximum number of distinct values to return (max: 100)').optional(),
21
+ locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
22
+ page: z.number().int().min(1).describe('Page number for pagination').optional(),
23
+ populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
24
+ showHiddenFields: z.boolean().describe('Optional: include hidden fields in the distinct query').optional(),
25
+ sort: z.string().describe('Field to sort by (e.g., "createdAt", "-updatedAt" for descending)').optional(),
26
+ trash: z.boolean().describe('Optional: include soft-deleted documents when trash is enabled on the collection').optional(),
27
+ where: whereSchema.describe('Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
28
+ })
29
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
30
+ const payload = req.payload;
31
+ const logger = getLogger({
32
+ payload
33
+ });
34
+ const { depth, field, limit, locale, page, populate, showHiddenFields, sort, trash, where } = input;
35
+ logger.info(`Finding distinct values in collection: ${collectionSlug}, field: ${field}`);
36
+ try {
37
+ const result = await payload.findDistinct({
38
+ collection: collectionSlug,
39
+ depth,
40
+ field,
41
+ overrideAccess: authorizedMCP.overrideAccess,
42
+ req,
43
+ ...limit ? {
44
+ limit
45
+ } : {},
46
+ ...locale ? {
47
+ locale
48
+ } : {},
49
+ ...page ? {
50
+ page
51
+ } : {},
52
+ ...populate ? {
53
+ populate: populate
54
+ } : {},
55
+ ...showHiddenFields !== undefined ? {
56
+ showHiddenFields
57
+ } : {},
58
+ ...sort ? {
59
+ sort
60
+ } : {},
61
+ ...trash !== undefined ? {
62
+ trash
63
+ } : {},
64
+ ...where ? {
65
+ where
66
+ } : {}
67
+ });
68
+ return {
69
+ content: [
70
+ {
71
+ type: 'text',
72
+ text: `Distinct values for "${field}" in collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
73
+ }
74
+ ],
75
+ doc: result
76
+ };
77
+ } catch (error) {
78
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
79
+ logger.error(`Error finding distinct values in ${collectionSlug}: ${errorMessage}`);
80
+ return {
81
+ content: [
82
+ {
83
+ type: 'text',
84
+ text: `❌ **Error finding distinct values in collection "${collectionSlug}":** ${errorMessage}`
85
+ }
86
+ ],
87
+ isError: true
88
+ };
89
+ }
90
+ });
91
+
92
+ //# sourceMappingURL=findDistinctTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findDistinctTool.ts"],"sourcesContent":["import type { PopulateType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find distinct values for a field in any collection by passing the collection slug and field path.'\n\nexport const findDistinctTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Distinct',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in distinct values')\n .optional()\n .default(0),\n field: z.string().describe('The field path to get distinct values for'),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of distinct values to return (max: 100)')\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 page: z.number().int().min(1).describe('Page number for pagination').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 showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the distinct query')\n .optional(),\n sort: z\n .string()\n .describe('Field to sort by (e.g., \"createdAt\", \"-updatedAt\" for descending)')\n .optional(),\n trash: z\n .boolean()\n .describe('Optional: include soft-deleted documents when trash is enabled on the collection')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering. 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 const { depth, field, limit, locale, page, populate, showHiddenFields, sort, trash, where } =\n input\n\n logger.info(`Finding distinct values in collection: ${collectionSlug}, field: ${field}`)\n\n try {\n const result = await payload.findDistinct({\n collection: collectionSlug,\n depth,\n field,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(limit ? { limit } : {}),\n ...(locale ? { locale } : {}),\n ...(page ? { page } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n ...(sort ? { sort } : {}),\n ...(trash !== undefined ? { trash } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Distinct values for \"${field}\" in collection \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding distinct values in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding distinct values in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","whereSchema","DEFAULT_DESCRIPTION","findDistinctTool","access","args","Boolean","permissions","collections","collectionSlug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","depth","number","int","min","max","describe","optional","default","field","string","limit","locale","page","populate","record","unknown","showHiddenFields","boolean","sort","trash","where","handler","authorizedMCP","req","payload","logger","info","result","findDistinct","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,mBAAmBJ,qBAAqB;IACnDK,QAAQ,CAACC,OACPP,cAAcO,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IACvFC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT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EAAErC,eAAe,SAAS,EAAEmB,OAAO;IAEvF,IAAI;QACF,MAAMmB,SAAS,MAAMH,QAAQI,YAAY,CAAC;YACxCC,YAAYxC;YACZW;YACAQ;YACAsB,gBAAgBR,cAAcQ,cAAc;YAC5CP;YACA,GAAIb,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;YAC1B,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAIC,OAAO;gBAAEA;YAAK,IAAI,CAAC,CAAC;YACxB,GAAIC,WAAW;gBAAEA,UAAUA;YAAyB,IAAI,CAAC,CAAC;YAC1D,GAAIG,qBAAqBe,YAAY;gBAAEf;YAAiB,IAAI,CAAC,CAAC;YAC9D,GAAIE,OAAO;gBAAEA;YAAK,IAAI,CAAC,CAAC;YACxB,GAAIC,UAAUY,YAAY;gBAAEZ;YAAM,IAAI,CAAC,CAAC;YACxC,GAAIC,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLY,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,qBAAqB,EAAE1B,MAAM,iBAAiB,EAAEnB,eAAe,gBAAgB,EAAE8C,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBAC1H;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,iCAAiC,EAAEjD,eAAe,EAAE,EAAEkD,cAAc;QAClF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,iDAAiD,EAAE7C,eAAe,KAAK,EAAEkD,cAAc;gBAChG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1,2 +1,2 @@
1
- export declare const findCollectionTool: import("../../../types.js").CollectionTool;
1
+ export declare const findDocumentsTool: import("../../../types.js").CollectionTool;
2
2
  //# sourceMappingURL=findTool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,kBAAkB,4CA+K7B,CAAA"}
1
+ {"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,iBAAiB,4CA2M5B,CAAA"}