@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
@@ -1,9 +1,18 @@
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
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
5
- const DEFAULT_DESCRIPTION = 'Find documents in a collection by ID or where clause using Find or FindByID.';
6
- export const findCollectionTool = defineCollectionTool({
5
+ import { whereSchema } from '../../../utils/whereSchema.js';
6
+ const DEFAULT_DESCRIPTION = 'Find documents in any collection by passing the collection slug and optional ID or where clause.';
7
+ export const findDocumentsTool = 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 Documents'
15
+ },
7
16
  description: DEFAULT_DESCRIPTION,
8
17
  input: z.object({
9
18
  id: z.union([
@@ -11,65 +20,46 @@ export const findCollectionTool = defineCollectionTool({
11
20
  z.number()
12
21
  ]).describe('Optional: specific document ID to retrieve. If not provided, returns all documents').optional(),
13
22
  depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships (default: 0)').optional().default(0),
14
- draft: z.boolean().describe('Optional: whether the document should be queried from the versions table/collection or not.').optional(),
23
+ draft: z.boolean().describe('For versioned collections, true returns the latest draft version when available. False reads the main document.').optional(),
15
24
  fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
25
+ joins: z.union([
26
+ z.record(z.string(), z.unknown()),
27
+ z.literal(false)
28
+ ]).describe('Optional: configure join field queries, or pass false to disable all join fields.').optional(),
16
29
  limit: z.number().int().min(1).max(100).describe('Maximum number of documents to return (default: 10, max: 100)').optional().default(10),
17
30
  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(),
18
31
  page: z.number().int().min(1).describe('Page number for pagination (default: 1)').optional().default(1),
19
- select: z.string().describe("Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'").optional(),
32
+ pagination: z.boolean().describe('Optional: set to false to skip the count query overhead').optional(),
33
+ populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
34
+ 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(),
20
35
  sort: z.string().describe('Field to sort by (e.g., "createdAt", "-updatedAt" for descending)').optional(),
21
- where: z.string().describe('Optional JSON string for where clause filtering (e.g., \'{"title": {"contains": "test"}}\')').optional()
36
+ trash: z.boolean().describe('Optional: include soft-deleted documents when trash is enabled on the collection').optional(),
37
+ where: whereSchema.describe('Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
22
38
  })
23
39
  }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
24
40
  const payload = req.payload;
25
41
  const logger = getLogger({
26
42
  payload
27
43
  });
28
- const { id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where } = input;
44
+ const { id, depth, draft, fallbackLocale, joins, limit, locale, page, pagination, populate, select, sort, trash, where } = input;
29
45
  logger.info(`Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`);
30
46
  try {
31
- let whereClause = {};
32
- if (where) {
33
- try {
34
- whereClause = JSON.parse(where);
35
- } catch {
36
- logger.warn(`Invalid where clause JSON: ${where}`);
37
- return {
38
- content: [
39
- {
40
- type: 'text',
41
- text: 'Error: Invalid JSON in where clause'
42
- }
43
- ]
44
- };
45
- }
46
- }
47
- let selectClause;
48
- if (select) {
49
- try {
50
- selectClause = JSON.parse(select);
51
- } catch {
52
- logger.warn(`Invalid select clause JSON: ${select}`);
53
- return {
54
- content: [
55
- {
56
- type: 'text',
57
- text: 'Error: Invalid JSON in select clause'
58
- }
59
- ]
60
- };
61
- }
62
- }
63
47
  if (id) {
64
48
  try {
65
49
  const doc = await payload.findByID({
66
50
  id,
67
51
  collection: collectionSlug,
68
52
  depth,
53
+ overrideAccess: authorizedMCP.overrideAccess,
69
54
  req,
70
- ...localAPIDefaults(authorizedMCP),
71
- ...selectClause && {
72
- select: selectClause
55
+ ...select && {
56
+ select: select
57
+ },
58
+ ...populate && {
59
+ populate: populate
60
+ },
61
+ ...joins !== undefined && {
62
+ joins: joins
73
63
  },
74
64
  ...locale && {
75
65
  locale
@@ -79,6 +69,9 @@ export const findCollectionTool = defineCollectionTool({
79
69
  },
80
70
  ...draft !== undefined && {
81
71
  draft
72
+ },
73
+ ...trash !== undefined && {
74
+ trash
82
75
  }
83
76
  });
84
77
  return {
@@ -106,11 +99,17 @@ export const findCollectionTool = defineCollectionTool({
106
99
  collection: collectionSlug,
107
100
  depth,
108
101
  limit,
102
+ overrideAccess: authorizedMCP.overrideAccess,
109
103
  page,
110
104
  req,
111
- ...localAPIDefaults(authorizedMCP),
112
- ...selectClause && {
113
- select: selectClause
105
+ ...select && {
106
+ select: select
107
+ },
108
+ ...populate && {
109
+ populate: populate
110
+ },
111
+ ...joins !== undefined && {
112
+ joins: joins
114
113
  },
115
114
  ...locale && {
116
115
  locale
@@ -120,13 +119,19 @@ export const findCollectionTool = defineCollectionTool({
120
119
  },
121
120
  ...draft !== undefined && {
122
121
  draft
122
+ },
123
+ ...pagination !== undefined && {
124
+ pagination
125
+ },
126
+ ...trash !== undefined && {
127
+ trash
123
128
  }
124
129
  };
125
130
  if (sort) {
126
131
  findOptions.sort = sort;
127
132
  }
128
- if (Object.keys(whereClause).length > 0) {
129
- findOptions.where = whereClause;
133
+ if (where) {
134
+ findOptions.where = where;
130
135
  }
131
136
  const result = await payload.find(findOptions);
132
137
  let responseText = `Collection: "${collectionSlug}"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/findTool.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 { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find documents in a collection by ID or where clause using Find or FindByID.'\n\nexport const findCollectionTool = defineCollectionTool({\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z\n .union([z.string(), z.number()])\n .describe(\n 'Optional: specific document ID to retrieve. If not provided, returns all documents',\n )\n .optional(),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships (default: 0)')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe(\n 'Optional: whether the document should be queried from the versions table/collection or not.',\n )\n .optional(),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of documents to return (default: 10, max: 100)')\n .optional()\n .default(10),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n )\n .optional(),\n page: z\n .number()\n .int()\n .min(1)\n .describe('Page number for pagination (default: 1)')\n .optional()\n .default(1),\n 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 sort: z\n .string()\n .describe('Field to sort by (e.g., \"createdAt\", \"-updatedAt\" for descending)')\n .optional(),\n where: z\n .string()\n .describe(\n 'Optional JSON string for where clause filtering (e.g., \\'{\"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 { id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where } = input\n\n logger.info(\n `Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n let whereClause: Record<string, unknown> = {}\n if (where) {\n try {\n whereClause = JSON.parse(where) as Record<string, unknown>\n } catch {\n logger.warn(`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 try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n depth,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(selectClause && { select: selectClause }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document from collection \"${collectionSlug}\":\\n${JSON.stringify(doc)}`,\n },\n ],\n doc: doc as Record<string, unknown>,\n }\n } catch {\n logger.warn(`Document not found with ID: ${id} in collection: ${collectionSlug}`)\n return {\n content: [\n {\n type: 'text',\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n }\n }\n\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n depth,\n limit,\n page,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(selectClause && { select: selectClause }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n if (Object.keys(whereClause).length > 0) {\n findOptions.where = whereClause as Parameters<typeof payload.find>[0]['where']\n }\n\n const result = await payload.find(findOptions)\n\n let responseText = `Collection: \"${collectionSlug}\"\\nTotal: ${result.totalDocs} documents\\nPage: ${result.page} of ${result.totalPages}\\n`\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\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 reading documents from collection ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error reading documents from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n }\n})\n"],"names":["z","defineCollectionTool","getLogger","localAPIDefaults","DEFAULT_DESCRIPTION","findCollectionTool","description","input","object","id","union","string","number","describe","optional","depth","int","min","max","default","draft","boolean","fallbackLocale","limit","locale","page","select","sort","where","handler","authorizedMCP","collectionSlug","req","payload","logger","info","whereClause","JSON","parse","warn","content","type","text","selectClause","doc","findByID","collection","undefined","stringify","findOptions","Object","keys","length","result","find","responseText","totalDocs","totalPages","docs","error","errorMessage","Error","message"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AAErE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBJ,qBAAqB;IACrDK,aAAaF;IACbG,OAAOP,EAAEQ,MAAM,CAAC;QACdC,IAAIT,EACDU,KAAK,CAAC;YAACV,EAAEW,MAAM;YAAIX,EAAEY,MAAM;SAAG,EAC9BC,QAAQ,CACP,sFAEDC,QAAQ;QACXC,OAAOf,EACJY,MAAM,GACNI,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJL,QAAQ,CAAC,+DACTC,QAAQ,GACRK,OAAO,CAAC;QACXC,OAAOpB,EACJqB,OAAO,GACPR,QAAQ,CACP,+FAEDC,QAAQ;QACXQ,gBAAgBtB,EACbW,MAAM,GACNE,QAAQ,CAAC,gFACTC,QAAQ;QACXS,OAAOvB,EACJY,MAAM,GACNI,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,KACJL,QAAQ,CAAC,iEACTC,QAAQ,GACRK,OAAO,CAAC;QACXK,QAAQxB,EACLW,MAAM,GACNE,QAAQ,CACP,wHAEDC,QAAQ;QACXW,MAAMzB,EACHY,MAAM,GACNI,GAAG,GACHC,GAAG,CAAC,GAC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AK,GAAGQ;QACtB;QAEA,MAAMiB,SAAS,MAAMpB,QAAQqB,IAAI,CAACL;QAElC,IAAIM,eAAe,CAAC,aAAa,EAAExB,eAAe,UAAU,EAAEsB,OAAOG,SAAS,CAAC,kBAAkB,EAAEH,OAAO5B,IAAI,CAAC,IAAI,EAAE4B,OAAOI,UAAU,CAAC,EAAE,CAAC;QAC1I,KAAK,MAAMb,OAAOS,OAAOK,IAAI,CAAE;YAC7BH,gBAAgB,CAAC,cAAc,EAAElB,KAAKW,SAAS,CAACJ,KAAK,QAAQ,CAAC;QAChE;QAEA,OAAO;YACLJ,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMa;gBAAa;aAAE;YAC/CX,KAAKS;QACP;IACF,EAAE,OAAOM,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9D5B,OAAOyB,KAAK,CAAC,CAAC,wCAAwC,EAAE5B,eAAe,EAAE,EAAE6B,cAAc;QACzF,OAAO;YACLpB,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6CAA6C,EAAEX,eAAe,KAAK,EAAE6B,cAAc;gBAC5F;aACD;QACH;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"sourcesContent":["import type { JoinQuery, PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find documents in any collection by passing the collection slug and optional ID or where clause.'\n\nexport const findDocumentsTool = 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 Documents',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z\n .union([z.string(), z.number()])\n .describe(\n 'Optional: specific document ID to retrieve. If not provided, returns all documents',\n )\n .optional(),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships (default: 0)')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe(\n 'For versioned collections, true returns the latest draft version when available. False reads the main document.',\n )\n .optional(),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n joins: z\n .union([z.record(z.string(), z.unknown()), z.literal(false)])\n .describe('Optional: configure join field queries, or pass false to disable all join fields.')\n .optional(),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of documents to return (default: 10, max: 100)')\n .optional()\n .default(10),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n )\n .optional(),\n page: z\n .number()\n .int()\n .min(1)\n .describe('Page number for pagination (default: 1)')\n .optional()\n .default(1),\n pagination: z\n .boolean()\n .describe('Optional: set to false to skip the count query overhead')\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\n )\n .optional(),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"title\": true}',\n )\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\n const {\n id,\n depth,\n draft,\n fallbackLocale,\n joins,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n sort,\n trash,\n where,\n } = input\n\n logger.info(\n `Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(select && { select: select as SelectType }),\n ...(populate && { populate: populate as PopulateType }),\n ...(joins !== undefined && { joins: joins as JoinQuery }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n ...(trash !== undefined && { trash }),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document from collection \"${collectionSlug}\":\\n${JSON.stringify(doc)}`,\n },\n ],\n doc: doc as Record<string, unknown>,\n }\n } catch {\n logger.warn(`Document not found with ID: ${id} in collection: ${collectionSlug}`)\n return {\n content: [\n {\n type: 'text',\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n }\n }\n\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(select && { select: select as SelectType }),\n ...(populate && { populate: populate as PopulateType }),\n ...(joins !== undefined && { joins: joins as JoinQuery }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n ...(pagination !== undefined && { pagination }),\n ...(trash !== undefined && { trash }),\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n if (where) {\n findOptions.where = where\n }\n\n const result = await payload.find(findOptions)\n\n let responseText = `Collection: \"${collectionSlug}\"\\nTotal: ${result.totalDocs} documents\\nPage: ${result.page} of ${result.totalPages}\\n`\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\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 reading documents from collection ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error reading documents from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","whereSchema","DEFAULT_DESCRIPTION","findDocumentsTool","access","args","Boolean","permissions","collections","collectionSlug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","union","string","number","describe","optional","depth","int","min","max","default","draft","boolean","fallbackLocale","joins","record","unknown","literal","limit","locale","page","pagination","populate","select","sort","trash","where","handler","authorizedMCP","req","payload","logger","info","doc","findByID","collection","overrideAccess","undefined","content","type","text","JSON","stringify","warn","findOptions","result","find","responseText","totalDocs","totalPages","docs","error","errorMessage","Error","message"],"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,oBAAoBJ,qBAAqB;IACpDK,QAAQ,CAACC,OACPP,cAAcO,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IACvFC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,IAAIvB,EACDwB,KAAK,CAAC;YAACxB,EAAEyB,MAAM;YAAIzB,EAAE0B,MAAM;SAAG,EAC9BC,QAAQ,CACP,sFAEDC,QAAQ;QACXC,OAAO7B,EACJ0B,MAAM,GACNI,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d,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DvB,OAAOoB,KAAK,CAAC,CAAC,wCAAwC,EAAE9D,eAAe,EAAE,EAAE+D,cAAc;QACzF,OAAO;YACLd,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6CAA6C,EAAEnD,eAAe,KAAK,EAAE+D,cAAc;gBAC5F;aACD;QACH;IACF;AACF,GAAE"}
@@ -0,0 +1,2 @@
1
+ export declare const findVersionByIDTool: import("../../../types.js").CollectionTool;
2
+ //# sourceMappingURL=findVersionByIDTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findVersionByIDTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,mBAAmB,4CAiG9B,CAAA"}
@@ -0,0 +1,83 @@
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
+ const DEFAULT_DESCRIPTION = 'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.';
6
+ export const findVersionByIDTool = defineCollectionTool({
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
8
+ annotations: {
9
+ destructiveHint: false,
10
+ idempotentHint: true,
11
+ openWorldHint: false,
12
+ readOnlyHint: true,
13
+ title: 'Find Version By ID'
14
+ },
15
+ description: DEFAULT_DESCRIPTION,
16
+ input: z.object({
17
+ id: z.string().describe('The ID of the version to retrieve'),
18
+ depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in the version document').optional().default(0),
19
+ fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
20
+ 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(),
21
+ populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
22
+ select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.title": true}').optional(),
23
+ showHiddenFields: z.boolean().describe('Optional: include hidden fields in the returned version document').optional(),
24
+ trash: z.boolean().describe('Optional: include soft-deleted version documents when trash is enabled').optional()
25
+ })
26
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
27
+ const payload = req.payload;
28
+ const logger = getLogger({
29
+ payload
30
+ });
31
+ const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields, trash } = input;
32
+ logger.info(`Finding version in collection: ${collectionSlug} with ID: ${id}`);
33
+ try {
34
+ const result = await payload.findVersionByID({
35
+ id,
36
+ collection: collectionSlug,
37
+ depth,
38
+ overrideAccess: authorizedMCP.overrideAccess,
39
+ req,
40
+ ...fallbackLocale ? {
41
+ fallbackLocale
42
+ } : {},
43
+ ...locale ? {
44
+ locale
45
+ } : {},
46
+ ...populate ? {
47
+ populate: populate
48
+ } : {},
49
+ ...select ? {
50
+ select: select
51
+ } : {},
52
+ ...showHiddenFields !== undefined ? {
53
+ showHiddenFields
54
+ } : {},
55
+ ...trash !== undefined ? {
56
+ trash
57
+ } : {}
58
+ });
59
+ return {
60
+ content: [
61
+ {
62
+ type: 'text',
63
+ text: `Version "${id}" from collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
64
+ }
65
+ ],
66
+ doc: result
67
+ };
68
+ } catch (error) {
69
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
70
+ logger.error(`Error finding version ${id} in ${collectionSlug}: ${errorMessage}`);
71
+ return {
72
+ content: [
73
+ {
74
+ type: 'text',
75
+ text: `❌ **Error finding version "${id}" in collection "${collectionSlug}":** ${errorMessage}`
76
+ }
77
+ ],
78
+ isError: true
79
+ };
80
+ }
81
+ });
82
+
83
+ //# sourceMappingURL=findVersionByIDTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.'\n\nexport const findVersionByIDTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) &&\n Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Version By ID',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.string().describe('The ID of the version to retrieve'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in the version document')\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., {\"version.title\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the returned version document')\n .optional(),\n trash: z\n .boolean()\n .describe('Optional: include soft-deleted version documents when trash is enabled')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields, trash } = input\n\n logger.info(`Finding version in collection: ${collectionSlug} with ID: ${id}`)\n\n try {\n const result = await payload.findVersionByID({\n id,\n collection: collectionSlug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n ...(trash !== undefined ? { trash } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" from 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 version ${id} in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding version \"${id}\" in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findVersionByIDTool","access","args","Boolean","permissions","collections","collectionSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","string","describe","depth","number","int","min","max","optional","default","fallbackLocale","locale","populate","record","unknown","select","showHiddenFields","boolean","trash","handler","authorizedMCP","req","payload","logger","info","result","findVersionByID","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;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,sBAAsBH,qBAAqB;IACtDI,QAAQ,CAACC,OACPN,cAAcM,SACdC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IAChEC,aAAa;QACXC,iBAAiB;Q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;YACAyB,gBAAgBR,cAAcQ,cAAc;YAC5CP;YACA,GAAIX,iBAAiB;gBAAEA;YAAe,IAAI,CAAC,CAAC;YAC5C,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAIC,WAAW;gBAAEA,UAAUA;YAAyB,IAAI,CAAC,CAAC;YAC1D,GAAIG,SAAS;gBAAEA,QAAQA;YAAqB,IAAI,CAAC,CAAC;YAClD,GAAIC,qBAAqBa,YAAY;gBAAEb;YAAiB,IAAI,CAAC,CAAC;YAC9D,GAAIE,UAAUW,YAAY;gBAAEX;YAAM,IAAI,CAAC,CAAC;QAC1C;QAEA,OAAO;YACLY,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,SAAS,EAAEhC,GAAG,mBAAmB,EAAEX,eAAe,gBAAgB,EAAE4C,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBAC7G;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,sBAAsB,EAAEpC,GAAG,IAAI,EAAEX,eAAe,EAAE,EAAEgD,cAAc;QAChF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,2BAA2B,EAAEhC,GAAG,iBAAiB,EAAEX,eAAe,KAAK,EAAEgD,cAAc;gBAChG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -0,0 +1,2 @@
1
+ export declare const findVersionsTool: import("../../../types.js").CollectionTool;
2
+ //# sourceMappingURL=findVersionsTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,gBAAgB,4CA6I3B,CAAA"}
@@ -0,0 +1,98 @@
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 document versions in any version-enabled collection by passing the collection slug and optional where clause.';
7
+ export const findVersionsTool = defineCollectionTool({
8
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
9
+ annotations: {
10
+ destructiveHint: false,
11
+ idempotentHint: true,
12
+ openWorldHint: false,
13
+ readOnlyHint: true,
14
+ title: 'Find Versions'
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 version documents').optional().default(0),
19
+ fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
20
+ limit: z.number().int().min(1).max(100).describe('Maximum number of versions to return (default: 10, max: 100)').optional().default(10),
21
+ locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
22
+ page: z.number().int().min(1).describe('Page number for pagination (default: 1)').optional().default(1),
23
+ pagination: z.boolean().describe('Optional: set to false to skip the count query overhead').optional(),
24
+ populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
25
+ select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.title": true}').optional(),
26
+ showHiddenFields: z.boolean().describe('Optional: include hidden fields in returned version documents').optional(),
27
+ sort: z.string().describe('Field to sort by (e.g., "-updatedAt", "-version.updatedAt" for descending)').optional(),
28
+ trash: z.boolean().describe('Optional: include versions for soft-deleted documents when trash is enabled').optional(),
29
+ where: whereSchema.describe('Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.title":{"contains":"test"}}').optional()
30
+ })
31
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
32
+ const payload = req.payload;
33
+ const logger = getLogger({
34
+ payload
35
+ });
36
+ const { depth, fallbackLocale, limit, locale, page, pagination, populate, select, showHiddenFields, sort, trash, where } = input;
37
+ logger.info(`Finding versions in collection: ${collectionSlug}, limit: ${limit}, page: ${page}`);
38
+ try {
39
+ const result = await payload.findVersions({
40
+ collection: collectionSlug,
41
+ depth,
42
+ limit,
43
+ overrideAccess: authorizedMCP.overrideAccess,
44
+ page,
45
+ req,
46
+ ...fallbackLocale ? {
47
+ fallbackLocale
48
+ } : {},
49
+ ...locale ? {
50
+ locale
51
+ } : {},
52
+ ...pagination !== undefined ? {
53
+ pagination
54
+ } : {},
55
+ ...populate ? {
56
+ populate: populate
57
+ } : {},
58
+ ...select ? {
59
+ select: select
60
+ } : {},
61
+ ...showHiddenFields !== undefined ? {
62
+ showHiddenFields
63
+ } : {},
64
+ ...sort ? {
65
+ sort
66
+ } : {},
67
+ ...trash !== undefined ? {
68
+ trash
69
+ } : {},
70
+ ...where ? {
71
+ where
72
+ } : {}
73
+ });
74
+ return {
75
+ content: [
76
+ {
77
+ type: 'text',
78
+ text: `Versions for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
79
+ }
80
+ ],
81
+ doc: result
82
+ };
83
+ } catch (error) {
84
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
85
+ logger.error(`Error finding versions in ${collectionSlug}: ${errorMessage}`);
86
+ return {
87
+ content: [
88
+ {
89
+ type: 'text',
90
+ text: `❌ **Error finding versions in collection "${collectionSlug}":** ${errorMessage}`
91
+ }
92
+ ],
93
+ isError: true
94
+ };
95
+ }
96
+ });
97
+
98
+ //# sourceMappingURL=findVersionsTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.'\n\nexport const findVersionsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) &&\n Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Versions',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in version documents')\n .optional()\n .default(0),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of versions to return (default: 10, max: 100)')\n .optional()\n .default(10),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n )\n .optional(),\n page: z\n .number()\n .int()\n .min(1)\n .describe('Page number for pagination (default: 1)')\n .optional()\n .default(1),\n pagination: z\n .boolean()\n .describe('Optional: set to false to skip the count query overhead')\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\n )\n .optional(),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"version.title\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in returned version documents')\n .optional(),\n sort: z\n .string()\n .describe('Field to sort by (e.g., \"-updatedAt\", \"-version.updatedAt\" for descending)')\n .optional(),\n trash: z\n .boolean()\n .describe('Optional: include versions for soft-deleted documents when trash is enabled')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering versions. Version document fields are usually under \"version\". Example: {\"version.title\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const {\n depth,\n fallbackLocale,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n showHiddenFields,\n sort,\n trash,\n where,\n } = input\n\n logger.info(`Finding versions in collection: ${collectionSlug}, limit: ${limit}, page: ${page}`)\n\n try {\n const result = await payload.findVersions({\n collection: collectionSlug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(pagination !== undefined ? { pagination } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n ...(sort ? { sort } : {}),\n ...(trash !== undefined ? { trash } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Versions for collection \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding versions in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding versions in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","whereSchema","DEFAULT_DESCRIPTION","findVersionsTool","access","args","Boolean","permissions","collections","collectionSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","depth","number","int","min","max","describe","optional","default","fallbackLocale","string","limit","locale","page","pagination","boolean","populate","record","unknown","select","showHiddenFields","sort","trash","where","handler","authorizedMCP","req","payload","logger","info","result","findVersions","collection","overrideAccess","undefined","content","type","text","JSON","stringify","do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C,OAAO;gBAAEA;YAAK,IAAI,CAAC,CAAC;YACxB,GAAIC,UAAUY,YAAY;gBAAEZ;YAAM,IAAI,CAAC,CAAC;YACxC,GAAIC,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLY,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,yBAAyB,EAAE/C,eAAe,gBAAgB,EAAEgD,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBACrG;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,0BAA0B,EAAEnD,eAAe,EAAE,EAAEoD,cAAc;QAC3E,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,0CAA0C,EAAE/C,eAAe,KAAK,EAAEoD,cAAc;gBACzF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -0,0 +1,9 @@
1
+ import type { CollectionSlug, PayloadRequest } from 'payload';
2
+ import type { MCPToolResponse } from '../../../types.js';
3
+ export declare const formatCollectionError: ({ action, collectionSlug, error, req, }: {
4
+ action: 'creating' | 'duplicating' | 'updating';
5
+ collectionSlug: CollectionSlug;
6
+ error: unknown;
7
+ req: PayloadRequest;
8
+ }) => MCPToolResponse;
9
+ //# sourceMappingURL=formatCollectionError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatCollectionError.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/formatCollectionError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAgCxD,eAAO,MAAM,qBAAqB,4CAK/B;IACD,MAAM,EAAE,UAAU,GAAG,aAAa,GAAG,UAAU,CAAA;IAC/C,cAAc,EAAE,cAAc,CAAA;IAC9B,KAAK,EAAE,OAAO,CAAA;IACd,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAuCH,CAAA"}
@@ -0,0 +1,60 @@
1
+ import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
2
+ const getValidationErrors = (error)=>{
3
+ if (!error || typeof error !== 'object') {
4
+ return undefined;
5
+ }
6
+ const data = 'data' in error ? error.data : undefined;
7
+ if (!data || typeof data !== 'object' || !('errors' in data) || !Array.isArray(data.errors)) {
8
+ return undefined;
9
+ }
10
+ return data.errors;
11
+ };
12
+ const isSchemaError = (error, message)=>{
13
+ if (getValidationErrors(error)) {
14
+ return true;
15
+ }
16
+ const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined;
17
+ return name === 'CastError' || name === 'ValidationError' || message.includes('Cast to ') || message.includes('validation failed');
18
+ };
19
+ export const formatCollectionError = ({ action, collectionSlug, error, req })=>{
20
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
21
+ const errors = getValidationErrors(error) ?? [
22
+ {
23
+ message: errorMessage
24
+ }
25
+ ];
26
+ if (!isSchemaError(error, errorMessage)) {
27
+ return {
28
+ content: [
29
+ {
30
+ type: 'text',
31
+ text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}`
32
+ }
33
+ ],
34
+ isError: true
35
+ };
36
+ }
37
+ const schema = getCollectionInputSchema({
38
+ collectionSlug,
39
+ req
40
+ });
41
+ const schemaText = schema ? `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\`` : '';
42
+ return {
43
+ content: [
44
+ {
45
+ type: 'text',
46
+ text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}${schemaText}`
47
+ }
48
+ ],
49
+ isError: true,
50
+ ...schema ? {
51
+ structuredContent: {
52
+ collectionSlug,
53
+ errors,
54
+ schema
55
+ }
56
+ } : {}
57
+ };
58
+ };
59
+
60
+ //# sourceMappingURL=formatCollectionError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/formatCollectionError.ts"],"sourcesContent":["import type { CollectionSlug, PayloadRequest } from 'payload'\n\nimport type { MCPToolResponse } from '../../../types.js'\n\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nconst getValidationErrors = (error: unknown): undefined | unknown[] => {\n if (!error || typeof error !== 'object') {\n return undefined\n }\n\n const data = 'data' in error ? error.data : undefined\n if (!data || typeof data !== 'object' || !('errors' in data) || !Array.isArray(data.errors)) {\n return undefined\n }\n\n return data.errors\n}\n\nconst isSchemaError = (error: unknown, message: string): boolean => {\n if (getValidationErrors(error)) {\n return true\n }\n\n const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined\n\n return (\n name === 'CastError' ||\n name === 'ValidationError' ||\n message.includes('Cast to ') ||\n message.includes('validation failed')\n )\n}\n\nexport const formatCollectionError = ({\n action,\n collectionSlug,\n error,\n req,\n}: {\n action: 'creating' | 'duplicating' | 'updating'\n collectionSlug: CollectionSlug\n error: unknown\n req: PayloadRequest\n}): MCPToolResponse => {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n const errors = getValidationErrors(error) ?? [{ message: errorMessage }]\n\n if (!isSchemaError(error, errorMessage)) {\n return {\n content: [\n {\n type: 'text',\n text: `Error ${action} document in collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n\n const schema = getCollectionInputSchema({ collectionSlug, req })\n const schemaText = schema\n ? `\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(schema)}\\n\\`\\`\\``\n : ''\n\n return {\n content: [\n {\n type: 'text',\n text: `Error ${action} document in collection \"${collectionSlug}\": ${errorMessage}${schemaText}`,\n },\n ],\n isError: true,\n ...(schema\n ? {\n structuredContent: {\n collectionSlug,\n errors,\n schema,\n },\n }\n : {}),\n }\n}\n"],"names":["getCollectionInputSchema","getValidationErrors","error","undefined","data","Array","isArray","errors","isSchemaError","message","name","includes","formatCollectionError","action","collectionSlug","req","errorMessage","Error","content","type","text","isError","schema","schemaText","JSON","stringify","structuredContent"],"mappings":"AAIA,SAASA,wBAAwB,QAAQ,0DAAyD;AAElG,MAAMC,sBAAsB,CAACC;IAC3B,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAOC;IACT;IAEA,MAAMC,OAAO,UAAUF,QAAQA,MAAME,IAAI,GAAGD;IAC5C,IAAI,CAACC,QAAQ,OAAOA,SAAS,YAAY,CAAE,CAAA,YAAYA,IAAG,KAAM,CAACC,MAAMC,OAAO,CAACF,KAAKG,MAAM,GAAG;QAC3F,OAAOJ;IACT;IAEA,OAAOC,KAAKG,MAAM;AACpB;AAEA,MAAMC,gBAAgB,CAACN,OAAgBO;IACrC,IAAIR,oBAAoBC,QAAQ;QAC9B,OAAO;IACT;IAEA,MAAMQ,OAAOR,SAAS,OAAOA,UAAU,YAAY,UAAUA,QAAQA,MAAMQ,IAAI,GAAGP;IAElF,OACEO,SAAS,eACTA,SAAS,qBACTD,QAAQE,QAAQ,CAAC,eACjBF,QAAQE,QAAQ,CAAC;AAErB;AAEA,OAAO,MAAMC,wBAAwB,CAAC,EACpCC,MAAM,EACNC,cAAc,EACdZ,KAAK,EACLa,GAAG,EAMJ;IACC,MAAMC,eAAed,iBAAiBe,QAAQf,MAAMO,OAAO,GAAG;IAC9D,MAAMF,SAASN,oBAAoBC,UAAU;QAAC;YAAEO,SAASO;QAAa;KAAE;IAExE,IAAI,CAACR,cAAcN,OAAOc,eAAe;QACvC,OAAO;YACLE,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,MAAM,EAAEP,OAAO,yBAAyB,EAAEC,eAAe,GAAG,EAAEE,cAAc;gBACrF;aACD;YACDK,SAAS;QACX;IACF;IAEA,MAAMC,SAAStB,yBAAyB;QAAEc;QAAgBC;IAAI;IAC9D,MAAMQ,aAAaD,SACf,CAAC,2CAA2C,EAAEE,KAAKC,SAAS,CAACH,QAAQ,QAAQ,CAAC,GAC9E;IAEJ,OAAO;QACLJ,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,MAAM,EAAEP,OAAO,yBAAyB,EAAEC,eAAe,GAAG,EAAEE,eAAeO,YAAY;YAClG;SACD;QACDF,SAAS;QACT,GAAIC,SACA;YACEI,mBAAmB;gBACjBZ;gBACAP;gBACAe;YACF;QACF,IACA,CAAC,CAAC;IACR;AACF,EAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const getCollectionSchemaTool: import("../../../types.js").CollectionTool;
2
+ //# sourceMappingURL=getCollectionSchemaTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,uBAAuB,4CAyElC,CAAA"}
@@ -0,0 +1,87 @@
1
+ import { getAccessResults } from 'payload';
2
+ import { defaultAccess } from '../../../defaultAccess.js';
3
+ import { defineCollectionTool } from '../../../defineTool.js';
4
+ import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
5
+ export const getCollectionSchemaTool = defineCollectionTool({
6
+ access: (args)=>{
7
+ const permissions = args.permissions?.collections?.[args.collectionSlug];
8
+ return defaultAccess(args) && Boolean(permissions?.create || permissions?.update);
9
+ },
10
+ annotations: {
11
+ destructiveHint: false,
12
+ idempotentHint: true,
13
+ openWorldHint: false,
14
+ readOnlyHint: true,
15
+ title: 'Get Collection Schema'
16
+ },
17
+ description: 'Get the input schema for creating or updating documents in a collection.'
18
+ }).handler(async ({ authorizedMCP, collectionSlug, req })=>{
19
+ const permissions = authorizedMCP.overrideAccess ? null : (await getAccessResults({
20
+ req
21
+ })).collections?.[collectionSlug];
22
+ if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {
23
+ return {
24
+ content: [
25
+ {
26
+ type: 'text',
27
+ text: `Error: MCP access to "getCollectionSchema" is not enabled for collection "${collectionSlug}"`
28
+ }
29
+ ],
30
+ isError: true
31
+ };
32
+ }
33
+ const inputSchema = getCollectionInputSchema({
34
+ collectionSlug,
35
+ req,
36
+ ...permissions ? {
37
+ permissions
38
+ } : {}
39
+ });
40
+ if (!inputSchema) {
41
+ return {
42
+ content: [
43
+ {
44
+ type: 'text',
45
+ text: `Error: Collection "${collectionSlug}" not found`
46
+ }
47
+ ],
48
+ isError: true
49
+ };
50
+ }
51
+ const uploadConfig = req.payload.collections[collectionSlug]?.config.upload;
52
+ const maxFileSize = req.payload.config.upload.limits?.fileSize;
53
+ const upload = uploadConfig ? {
54
+ enabled: true,
55
+ filesRequiredOnCreate: uploadConfig.filesRequiredOnCreate !== false,
56
+ mimeTypes: uploadConfig.mimeTypes ?? [
57
+ '*/*'
58
+ ],
59
+ sources: [
60
+ ...uploadConfig.pasteURL !== false ? [
61
+ 'externalURL'
62
+ ] : [],
63
+ 'base64',
64
+ 'uploadReference'
65
+ ],
66
+ ...typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? {
67
+ maxFileSize
68
+ } : {}
69
+ } : {
70
+ enabled: false
71
+ };
72
+ return {
73
+ content: [
74
+ {
75
+ type: 'text',
76
+ text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``
77
+ }
78
+ ],
79
+ structuredContent: {
80
+ collectionSlug,
81
+ schema: inputSchema,
82
+ upload
83
+ }
84
+ };
85
+ });
86
+
87
+ //# sourceMappingURL=getCollectionSchemaTool.js.map