@payloadcms/plugin-mcp 4.0.0-internal.4cbdd50 → 4.0.0-internal.4e1f822

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 (202) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +7 -0
  3. package/dist/defaultAccess.d.ts.map +1 -1
  4. package/dist/defineTool.d.ts +8 -8
  5. package/dist/defineTool.d.ts.map +1 -1
  6. package/dist/endpoint/access.d.ts +2 -7
  7. package/dist/endpoint/access.d.ts.map +1 -1
  8. package/dist/endpoint/access.js +6 -13
  9. package/dist/endpoint/access.js.map +1 -1
  10. package/dist/endpoint/index.d.ts +1 -1
  11. package/dist/endpoint/index.d.ts.map +1 -1
  12. package/dist/endpoint/index.js +57 -17
  13. package/dist/endpoint/index.js.map +1 -1
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +2 -2
  17. package/dist/index.js.map +1 -1
  18. package/dist/mcp/buildMcpServer.d.ts +5 -5
  19. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  20. package/dist/mcp/buildMcpServer.js +67 -33
  21. package/dist/mcp/buildMcpServer.js.map +1 -1
  22. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  23. package/dist/mcp/builtin/collections/authTools.js +79 -56
  24. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  25. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
  26. package/dist/mcp/builtin/collections/countTool.js +10 -16
  27. package/dist/mcp/builtin/collections/countTool.js.map +1 -1
  28. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
  29. package/dist/mcp/builtin/collections/countVersionsTool.js +10 -15
  30. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
  31. package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
  32. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  33. package/dist/mcp/builtin/collections/createTool.js +104 -54
  34. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  35. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  36. package/dist/mcp/builtin/collections/deleteTool.js +41 -45
  37. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  38. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
  39. package/dist/mcp/builtin/collections/duplicateTool.js +27 -38
  40. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  41. package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
  42. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  43. package/dist/mcp/builtin/collections/fileInput.js +123 -0
  44. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  45. package/dist/mcp/builtin/collections/fileInput.spec.js +86 -0
  46. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
  47. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
  48. package/dist/mcp/builtin/collections/findDistinctTool.js +12 -28
  49. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
  50. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  51. package/dist/mcp/builtin/collections/findTool.js +23 -46
  52. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  53. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
  54. package/dist/mcp/builtin/collections/findVersionByIDTool.js +18 -28
  55. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
  56. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
  57. package/dist/mcp/builtin/collections/findVersionsTool.js +17 -32
  58. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
  59. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  60. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +51 -11
  61. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  62. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
  63. package/dist/mcp/builtin/collections/restoreVersionTool.js +15 -28
  64. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  65. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  66. package/dist/mcp/builtin/collections/updateTool.js +62 -86
  67. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  68. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  69. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  70. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  71. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  72. package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
  73. package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
  74. package/dist/mcp/builtin/formatEntityError.js +55 -0
  75. package/dist/mcp/builtin/formatEntityError.js.map +1 -0
  76. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  77. package/dist/mcp/builtin/getConfigInfoTool.js +5 -7
  78. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  79. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
  80. package/dist/mcp/builtin/globals/countVersionsTool.js +10 -15
  81. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
  82. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  83. package/dist/mcp/builtin/globals/findTool.js +12 -18
  84. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  85. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
  86. package/dist/mcp/builtin/globals/findVersionByIDTool.js +14 -26
  87. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
  88. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
  89. package/dist/mcp/builtin/globals/findVersionsTool.js +14 -31
  90. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
  91. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  92. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +28 -10
  93. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  94. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
  95. package/dist/mcp/builtin/globals/restoreVersionTool.js +16 -24
  96. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
  97. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  98. package/dist/mcp/builtin/globals/updateTool.js +28 -37
  99. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  100. package/dist/mcp/builtinTools.d.ts +6 -0
  101. package/dist/mcp/builtinTools.d.ts.map +1 -1
  102. package/dist/mcp/builtinTools.js +9 -3
  103. package/dist/mcp/builtinTools.js.map +1 -1
  104. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  105. package/dist/mcp/sanitizeMCPConfig.js +5 -1
  106. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  107. package/dist/stdio.d.ts +3 -4
  108. package/dist/stdio.d.ts.map +1 -1
  109. package/dist/stdio.js +61 -42
  110. package/dist/stdio.js.map +1 -1
  111. package/dist/types.d.ts +61 -13
  112. package/dist/types.d.ts.map +1 -1
  113. package/dist/types.js +2 -4
  114. package/dist/types.js.map +1 -1
  115. package/dist/utils/camelCase.d.ts.map +1 -1
  116. package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
  117. package/dist/utils/toStandardSchema.d.ts.map +1 -1
  118. package/package.json +8 -12
  119. package/src/endpoint/access.ts +5 -13
  120. package/src/endpoint/index.ts +45 -16
  121. package/src/index.ts +4 -4
  122. package/src/mcp/buildMcpServer.ts +79 -49
  123. package/src/mcp/builtin/collections/authTools.ts +77 -69
  124. package/src/mcp/builtin/collections/countTool.ts +10 -23
  125. package/src/mcp/builtin/collections/countVersionsTool.ts +10 -20
  126. package/src/mcp/builtin/collections/createTool.ts +110 -77
  127. package/src/mcp/builtin/collections/deleteTool.ts +36 -65
  128. package/src/mcp/builtin/collections/duplicateTool.ts +34 -86
  129. package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
  130. package/src/mcp/builtin/collections/fileInput.ts +169 -0
  131. package/src/mcp/builtin/collections/findDistinctTool.ts +12 -65
  132. package/src/mcp/builtin/collections/findTool.ts +23 -106
  133. package/src/mcp/builtin/collections/findVersionByIDTool.ts +16 -60
  134. package/src/mcp/builtin/collections/findVersionsTool.ts +15 -87
  135. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +48 -14
  136. package/src/mcp/builtin/collections/restoreVersionTool.ts +15 -58
  137. package/src/mcp/builtin/collections/updateTool.ts +61 -100
  138. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  139. package/src/mcp/builtin/formatEntityError.ts +77 -0
  140. package/src/mcp/builtin/getConfigInfoTool.ts +4 -5
  141. package/src/mcp/builtin/globals/countVersionsTool.ts +10 -19
  142. package/src/mcp/builtin/globals/findTool.ts +14 -53
  143. package/src/mcp/builtin/globals/findVersionByIDTool.ts +14 -54
  144. package/src/mcp/builtin/globals/findVersionsTool.ts +15 -94
  145. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +30 -8
  146. package/src/mcp/builtin/globals/restoreVersionTool.ts +15 -47
  147. package/src/mcp/builtin/globals/updateTool.ts +39 -62
  148. package/src/mcp/builtinTools.ts +9 -2
  149. package/src/mcp/sanitizeMCPConfig.ts +5 -1
  150. package/src/stdio.ts +61 -43
  151. package/src/types.ts +61 -13
  152. package/dist/@types/assets.d.js +0 -2
  153. package/dist/@types/assets.d.js.map +0 -1
  154. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
  155. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
  156. package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
  157. package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
  158. package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
  159. package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
  160. package/dist/mcp/builtin/validateEntityData.js +0 -82
  161. package/dist/mcp/builtin/validateEntityData.js.map +0 -1
  162. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  163. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  164. package/dist/utils/getVirtualFieldNames.js +0 -35
  165. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  166. package/dist/utils/localAPIDefaults.d.ts +0 -20
  167. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  168. package/dist/utils/localAPIDefaults.js +0 -19
  169. package/dist/utils/localAPIDefaults.js.map +0 -1
  170. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -11
  171. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
  172. package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -34
  173. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
  174. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  175. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  176. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  177. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  178. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -15
  179. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
  180. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -464
  181. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
  182. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -158
  183. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
  184. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  185. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  186. package/dist/utils/transformPointDataToPayload.js +0 -28
  187. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  188. package/dist/utils/whereSchema.d.ts +0 -9
  189. package/dist/utils/whereSchema.d.ts.map +0 -1
  190. package/dist/utils/whereSchema.js +0 -13
  191. package/dist/utils/whereSchema.js.map +0 -1
  192. package/src/@types/assets.d.ts +0 -3
  193. package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
  194. package/src/mcp/builtin/validateEntityData.ts +0 -132
  195. package/src/utils/getVirtualFieldNames.ts +0 -53
  196. package/src/utils/localAPIDefaults.ts +0 -22
  197. package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -78
  198. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  199. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -103
  200. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -529
  201. package/src/utils/transformPointDataToPayload.ts +0 -40
  202. package/src/utils/whereSchema.ts +0 -24
@@ -1,12 +1,10 @@
1
- import { z } from 'zod';
1
+ import { findDocumentsInputSchema } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
- import { whereSchema } from '../../../utils/whereSchema.js';
7
5
  const DEFAULT_DESCRIPTION = 'Find documents in any collection by passing the collection slug and optional ID or where clause.';
8
6
  export const findDocumentsTool = defineCollectionTool({
9
- access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.read),
10
8
  annotations: {
11
9
  destructiveHint: false,
12
10
  idempotentHint: true,
@@ -15,57 +13,36 @@ export const findDocumentsTool = defineCollectionTool({
15
13
  title: 'Find Documents'
16
14
  },
17
15
  description: DEFAULT_DESCRIPTION,
18
- input: z.object({
19
- id: z.union([
20
- z.string(),
21
- z.number()
22
- ]).describe('Optional: specific document ID to retrieve. If not provided, returns all documents').optional(),
23
- depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships (default: 0)').optional().default(0),
24
- draft: z.boolean().describe('Optional: whether the document should be queried from the versions table/collection or not.').optional(),
25
- fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
26
- joins: z.union([
27
- z.record(z.string(), z.unknown()),
28
- z.literal(false)
29
- ]).describe('Optional: configure join field queries, or pass false to disable all join fields.').optional(),
30
- limit: z.number().int().min(1).max(100).describe('Maximum number of documents to return (default: 10, max: 100)').optional().default(10),
31
- 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(),
32
- page: z.number().int().min(1).describe('Page number for pagination (default: 1)').optional().default(1),
33
- pagination: z.boolean().describe('Optional: set to false to skip the count query overhead').optional(),
34
- populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
35
- 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(),
36
- sort: z.string().describe('Field to sort by (e.g., "createdAt", "-updatedAt" for descending)').optional(),
37
- trash: z.boolean().describe('Optional: include soft-deleted documents when trash is enabled on the collection').optional(),
38
- where: whereSchema.describe('Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
39
- })
40
- }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
16
+ input: findDocumentsInputSchema
17
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
41
18
  const payload = req.payload;
42
19
  const logger = getLogger({
43
20
  payload
44
21
  });
45
22
  const { id, depth, draft, fallbackLocale, joins, limit, locale, page, pagination, populate, select, sort, trash, where } = input;
46
- logger.info(`Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`);
23
+ logger.info(`Reading document from collection: ${slug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`);
47
24
  try {
48
25
  if (id) {
49
26
  try {
50
27
  const doc = await payload.findByID({
51
28
  id,
52
- collection: collectionSlug,
29
+ collection: slug,
53
30
  depth,
31
+ overrideAccess: authorizedMCP.overrideAccess,
54
32
  req,
55
- ...localAPIDefaults(authorizedMCP),
56
33
  ...select && {
57
- select: select
34
+ select
58
35
  },
59
36
  ...populate && {
60
- populate: populate
37
+ populate
61
38
  },
62
39
  ...joins !== undefined && {
63
- joins: joins
40
+ joins
64
41
  },
65
42
  ...locale && {
66
43
  locale
67
44
  },
68
- ...fallbackLocale && {
45
+ ...fallbackLocale !== undefined && {
69
46
  fallbackLocale
70
47
  },
71
48
  ...draft !== undefined && {
@@ -79,43 +56,43 @@ export const findDocumentsTool = defineCollectionTool({
79
56
  content: [
80
57
  {
81
58
  type: 'text',
82
- text: `Document from collection "${collectionSlug}":\n${JSON.stringify(doc)}`
59
+ text: `Document from collection "${slug}":\n${JSON.stringify(doc)}`
83
60
  }
84
61
  ],
85
62
  doc: doc
86
63
  };
87
64
  } catch {
88
- logger.warn(`Document not found with ID: ${id} in collection: ${collectionSlug}`);
65
+ logger.warn(`Document not found with ID: ${id} in collection: ${slug}`);
89
66
  return {
90
67
  content: [
91
68
  {
92
69
  type: 'text',
93
- text: `Error: Document with ID "${id}" not found in collection "${collectionSlug}"`
70
+ text: `Error: Document with ID "${id}" not found in collection "${slug}"`
94
71
  }
95
72
  ]
96
73
  };
97
74
  }
98
75
  }
99
76
  const findOptions = {
100
- collection: collectionSlug,
77
+ collection: slug,
101
78
  depth,
102
79
  limit,
80
+ overrideAccess: authorizedMCP.overrideAccess,
103
81
  page,
104
82
  req,
105
- ...localAPIDefaults(authorizedMCP),
106
83
  ...select && {
107
- select: select
84
+ select
108
85
  },
109
86
  ...populate && {
110
- populate: populate
87
+ populate
111
88
  },
112
89
  ...joins !== undefined && {
113
- joins: joins
90
+ joins
114
91
  },
115
92
  ...locale && {
116
93
  locale
117
94
  },
118
- ...fallbackLocale && {
95
+ ...fallbackLocale !== undefined && {
119
96
  fallbackLocale
120
97
  },
121
98
  ...draft !== undefined && {
@@ -135,7 +112,7 @@ export const findDocumentsTool = defineCollectionTool({
135
112
  findOptions.where = where;
136
113
  }
137
114
  const result = await payload.find(findOptions);
138
- let responseText = `Collection: "${collectionSlug}"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`;
115
+ let responseText = `Collection: "${slug}"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`;
139
116
  for (const doc of result.docs){
140
117
  responseText += `\n\`\`\`json\n${JSON.stringify(doc)}\n\`\`\``;
141
118
  }
@@ -150,12 +127,12 @@ export const findDocumentsTool = defineCollectionTool({
150
127
  };
151
128
  } catch (error) {
152
129
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
153
- logger.error(`Error reading documents from collection ${collectionSlug}: ${errorMessage}`);
130
+ logger.error(`Error reading documents from collection ${slug}: ${errorMessage}`);
154
131
  return {
155
132
  content: [
156
133
  {
157
134
  type: 'text',
158
- text: `❌ **Error reading documents from collection "${collectionSlug}":** ${errorMessage}`
135
+ text: `❌ **Error reading documents from collection "${slug}":** ${errorMessage}`
159
136
  }
160
137
  ]
161
138
  };
@@ -1 +1 @@
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 { localAPIDefaults } from '../../../utils/localAPIDefaults.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 '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 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 req,\n ...localAPIDefaults(authorizedMCP),\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 page,\n req,\n ...localAPIDefaults(authorizedMCP),\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","localAPIDefaults","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","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,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,oBAAoBL,qBAAqB;IACpDM,QAAQ,CAACC,OACPR,cAAcQ,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,OAAOtB,EAAEuB,MAAM,CAAC;QACdC,IAAIxB,EACDyB,KAAK,CAAC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ACLI,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMO;gBAAa;aAAE;YAC/Cb,KAAKW;QACP;IACF,EAAE,OAAOM,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DtB,OAAOmB,KAAK,CAAC,CAAC,wCAAwC,EAAE7D,eAAe,EAAE,EAAE8D,cAAc;QACzF,OAAO;YACLd,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6CAA6C,EAAElD,eAAe,KAAK,EAAE8D,cAAc;gBAC5F;aACD;QACH;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"sourcesContent":["import { findDocumentsInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find 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.slug]?.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: findDocumentsInputSchema,\n}).handler(async ({ slug, authorizedMCP, 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: ${slug}${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: slug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(select && { select }),\n ...(populate && { populate }),\n ...(joins !== undefined && { joins }),\n ...(locale && { locale }),\n ...(fallbackLocale !== undefined && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n ...(trash !== undefined && { trash }),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document from collection \"${slug}\":\\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: ${slug}`)\n return {\n content: [\n {\n type: 'text',\n text: `Error: Document with ID \"${id}\" not found in collection \"${slug}\"`,\n },\n ],\n }\n }\n }\n\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: slug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(select && { select }),\n ...(populate && { populate }),\n ...(joins !== undefined && { joins }),\n ...(locale && { locale }),\n ...(fallbackLocale !== undefined && { 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: \"${slug}\"\\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 ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error reading documents from collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n }\n }\n})\n"],"names":["findDocumentsInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findDocumentsTool","access","args","Boolean","permissions","collections","slug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","id","depth","draft","fallbackLocale","joins","limit","locale","page","pagination","populate","select","sort","trash","where","info","doc","findByID","collection","overrideAccess","undefined","content","type","text","JSON","stringify","warn","findOptions","result","find","responseText","totalDocs","totalPages","docs","error","errorMessage","Error","message"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,UAAS;AAElD,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,oBAAoBH,qBAAqB;IACpDI,QAAQ,CAACC,OACPN,cAAcM,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,IAAI,CAAC,EAAEC;IAC7EC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOpB;AACT,GAAGqB,OAAO,CAAC,OAAO,EAAEV,IAAI,EAAEW,aAAa,EAAEF,KAAK,EAAEG,GAAG,EAAE;IACnD,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAAStB,UAAU;QAAEqB;IAAQ;IAEnC,MAAM,EACJE,EAAE,EACFC,KAAK,EACLC,KAAK,EACLC,cAAc,EACdC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,QAAQ,EACRC,MAAM,EACNC,IAAI,EACJC,KAAK,EACLC,KAAK,EACN,GAAGnB;IAEJK,OAAOe,IAAI,CACT,CAAC,kCAAkC,EAAE7B,OAAOe,KAAK,CAAC,UAAU,EAAEA,IAAI,GAAG,GAAG,SAAS,EAAEK,MAAM,QAAQ,EAAEE,OAAOD,SAAS,CAAC,UAAU,EAAEA,QAAQ,GAAG,IAAI;IAGjJ,IAAI;QACF,IAAIN,IAAI;YACN,IAAI;gBACF,MAAMe,MAAM,MAAMjB,QAAQkB,QAAQ,CA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AC;YAC9C,GAAII,UAAUO,aAAa;gBAAEP;YAAM,CAAC;QACtC;QAEA,IAAID,MAAM;YACRe,YAAYf,IAAI,GAAGA;QACrB;QACA,IAAIE,OAAO;YACTa,YAAYb,KAAK,GAAGA;QACtB;QAEA,MAAMc,SAAS,MAAM7B,QAAQ8B,IAAI,CAACF;QAElC,IAAIG,eAAe,CAAC,aAAa,EAAE5C,KAAK,UAAU,EAAE0C,OAAOG,SAAS,CAAC,kBAAkB,EAAEH,OAAOpB,IAAI,CAAC,IAAI,EAAEoB,OAAOI,UAAU,CAAC,EAAE,CAAC;QAChI,KAAK,MAAMhB,OAAOY,OAAOK,IAAI,CAAE;YAC7BH,gBAAgB,CAAC,cAAc,EAAEN,KAAKC,SAAS,CAACT,KAAK,QAAQ,CAAC;QAChE;QAEA,OAAO;YACLK,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMO;gBAAa;aAAE;YAC/Cd,KAAKY;QACP;IACF,EAAE,OAAOM,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DrC,OAAOkC,KAAK,CAAC,CAAC,wCAAwC,EAAEhD,KAAK,EAAE,EAAEiD,cAAc;QAC/E,OAAO;YACLd,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6CAA6C,EAAErC,KAAK,KAAK,EAAEiD,cAAc;gBAClF;aACD;QACH;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"findVersionByIDTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,mBAAmB,4CAiG9B,CAAA"}
1
+ {"version":3,"file":"findVersionByIDTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,mBAAmB,4CAwD9B,CAAA"}
@@ -1,11 +1,10 @@
1
- import { z } from 'zod';
1
+ import { findVersionByIDInputSchema } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
5
  const DEFAULT_DESCRIPTION = 'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.';
7
6
  export const findVersionByIDTool = defineCollectionTool({
8
- access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),
9
8
  annotations: {
10
9
  destructiveHint: false,
11
10
  idempotentHint: true,
@@ -14,44 +13,35 @@ export const findVersionByIDTool = defineCollectionTool({
14
13
  title: 'Find Version By ID'
15
14
  },
16
15
  description: DEFAULT_DESCRIPTION,
17
- input: z.object({
18
- id: z.string().describe('The ID of the version to retrieve'),
19
- depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in the version document').optional().default(0),
20
- fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
21
- locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
22
- populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
23
- select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.title": true}').optional(),
24
- showHiddenFields: z.boolean().describe('Optional: include hidden fields in the returned version document').optional(),
25
- trash: z.boolean().describe('Optional: include soft-deleted version documents when trash is enabled').optional()
26
- })
27
- }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
16
+ input: findVersionByIDInputSchema
17
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
28
18
  const payload = req.payload;
29
19
  const logger = getLogger({
30
20
  payload
31
21
  });
32
- const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields, trash } = input;
33
- logger.info(`Finding version in collection: ${collectionSlug} with ID: ${id}`);
22
+ const { id, depth, draft, fallbackLocale, locale, populate, select, trash } = input;
23
+ logger.info(`Finding version in collection: ${slug} with ID: ${id}`);
34
24
  try {
35
25
  const result = await payload.findVersionByID({
36
- id,
37
- collection: collectionSlug,
26
+ id: String(id),
27
+ collection: slug,
38
28
  depth,
29
+ overrideAccess: authorizedMCP.overrideAccess,
39
30
  req,
40
- ...localAPIDefaults(authorizedMCP),
41
- ...fallbackLocale ? {
31
+ ...draft !== undefined ? {
32
+ draft
33
+ } : {},
34
+ ...fallbackLocale !== undefined ? {
42
35
  fallbackLocale
43
36
  } : {},
44
37
  ...locale ? {
45
38
  locale
46
39
  } : {},
47
40
  ...populate ? {
48
- populate: populate
41
+ populate
49
42
  } : {},
50
43
  ...select ? {
51
- select: select
52
- } : {},
53
- ...showHiddenFields !== undefined ? {
54
- showHiddenFields
44
+ select
55
45
  } : {},
56
46
  ...trash !== undefined ? {
57
47
  trash
@@ -61,19 +51,19 @@ export const findVersionByIDTool = defineCollectionTool({
61
51
  content: [
62
52
  {
63
53
  type: 'text',
64
- text: `Version "${id}" from collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
54
+ text: `Version "${id}" from collection "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
65
55
  }
66
56
  ],
67
57
  doc: result
68
58
  };
69
59
  } catch (error) {
70
60
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
71
- logger.error(`Error finding version ${id} in ${collectionSlug}: ${errorMessage}`);
61
+ logger.error(`Error finding version ${id} in ${slug}: ${errorMessage}`);
72
62
  return {
73
63
  content: [
74
64
  {
75
65
  type: 'text',
76
- text: `❌ **Error finding version "${id}" in collection "${collectionSlug}":** ${errorMessage}`
66
+ text: `❌ **Error finding version "${id}" in collection "${slug}":** ${errorMessage}`
77
67
  }
78
68
  ],
79
69
  isError: true
@@ -1 +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'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.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 req,\n ...localAPIDefaults(authorizedMCP),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n ...(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","localAPIDefaults","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","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AAErE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,sBAAsBJ,qBAAqB;IACtDK,QAAQ,CAACC,OACPP,cAAcO,SACdC,QAAQD,KAAKE,WAAW,EAAEC,a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MyB,SAAS,MAAMH,QAAQI,eAAe,CAAC;YAC3C1B;YACA2B,YAAYtC;YACZc;YACAkB;YACA,GAAGxC,iBAAiBuC,cAAc;YAClC,GAAIV,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,qBAAqBY,YAAY;gBAAEZ;YAAiB,IAAI,CAAC,CAAC;YAC9D,GAAIE,UAAUU,YAAY;gBAAEV;YAAM,IAAI,CAAC,CAAC;QAC1C;QAEA,OAAO;YACLW,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,SAAS,EAAE/B,GAAG,mBAAmB,EAAEX,eAAe,gBAAgB,EAAE2C,KAAKC,SAAS,CAACR,QAAQ,QAAQ,CAAC;gBAC7G;aACD;YACDS,KAAKT;QACP;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9Df,OAAOY,KAAK,CAAC,CAAC,sBAAsB,EAAEnC,GAAG,IAAI,EAAEX,eAAe,EAAE,EAAE+C,cAAc;QAChF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,2BAA2B,EAAE/B,GAAG,iBAAiB,EAAEX,eAAe,KAAK,EAAE+C,cAAc;gBAChG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"sourcesContent":["import { findVersionByIDInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find 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) && Boolean(args.permissions?.collections?.[args.slug]?.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: findVersionByIDInputSchema,\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, draft, fallbackLocale, locale, populate, select, trash } = input\n\n logger.info(`Finding version in collection: ${slug} with ID: ${id}`)\n\n try {\n const result = await payload.findVersionByID({\n id: String(id),\n collection: slug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(draft !== undefined ? { draft } : {}),\n ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate } : {}),\n ...(select ? { select } : {}),\n ...(trash !== undefined ? { trash } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" from collection \"${slug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding version ${id} in ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding version \"${id}\" in collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["findVersionByIDInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findVersionByIDTool","access","args","Boolean","permissions","collections","slug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","id","depth","draft","fallbackLocale","locale","populate","select","trash","info","result","findVersionByID","String","collection","overrideAccess","undefined","content","type","text","JSON","stringify","do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,CAAC,CAAC;YAC5B,GAAIC,UAAUO,YAAY;gBAAEP;YAAM,IAAI,CAAC,CAAC;QAC1C;QAEA,OAAO;YACLQ,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,SAAS,EAAEjB,GAAG,mBAAmB,EAAEf,KAAK,gBAAgB,EAAEiC,KAAKC,SAAS,CAACV,QAAQ,QAAQ,CAAC;gBACnG;aACD;YACDW,KAAKX;QACP;IACF,EAAE,OAAOY,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DzB,OAAOsB,KAAK,CAAC,CAAC,sBAAsB,EAAErB,GAAG,IAAI,EAAEf,KAAK,EAAE,EAAEqC,cAAc;QACtE,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,2BAA2B,EAAEjB,GAAG,iBAAiB,EAAEf,KAAK,KAAK,EAAEqC,cAAc;gBACtF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"findVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,gBAAgB,4CA6I3B,CAAA"}
1
+ {"version":3,"file":"findVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,gBAAgB,4CAyE3B,CAAA"}
@@ -1,12 +1,10 @@
1
- import { z } from 'zod';
1
+ import { findVersionsInputSchema } from 'payload';
2
2
  import { defaultAccess } from '../../../defaultAccess.js';
3
3
  import { defineCollectionTool } from '../../../defineTool.js';
4
4
  import { getLogger } from '../../../utils/getLogger.js';
5
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
- import { whereSchema } from '../../../utils/whereSchema.js';
7
5
  const DEFAULT_DESCRIPTION = 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.';
8
6
  export const findVersionsTool = defineCollectionTool({
9
- access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),
10
8
  annotations: {
11
9
  destructiveHint: false,
12
10
  idempotentHint: true,
@@ -15,36 +13,26 @@ export const findVersionsTool = defineCollectionTool({
15
13
  title: 'Find Versions'
16
14
  },
17
15
  description: DEFAULT_DESCRIPTION,
18
- input: z.object({
19
- depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in version documents').optional().default(0),
20
- fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
21
- limit: z.number().int().min(1).max(100).describe('Maximum number of versions to return (default: 10, max: 100)').optional().default(10),
22
- 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(),
23
- page: z.number().int().min(1).describe('Page number for pagination (default: 1)').optional().default(1),
24
- pagination: z.boolean().describe('Optional: set to false to skip the count query overhead').optional(),
25
- populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
26
- 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(),
27
- showHiddenFields: z.boolean().describe('Optional: include hidden fields in returned version documents').optional(),
28
- sort: z.string().describe('Field to sort by (e.g., "-updatedAt", "-version.updatedAt" for descending)').optional(),
29
- trash: z.boolean().describe('Optional: include versions for soft-deleted documents when trash is enabled').optional(),
30
- where: whereSchema.describe('Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.title":{"contains":"test"}}').optional()
31
- })
32
- }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
16
+ input: findVersionsInputSchema
17
+ }).handler(async ({ slug, authorizedMCP, input, req })=>{
33
18
  const payload = req.payload;
34
19
  const logger = getLogger({
35
20
  payload
36
21
  });
37
- const { depth, fallbackLocale, limit, locale, page, pagination, populate, select, showHiddenFields, sort, trash, where } = input;
38
- logger.info(`Finding versions in collection: ${collectionSlug}, limit: ${limit}, page: ${page}`);
22
+ const { depth, draft, fallbackLocale, limit, locale, page, pagination, populate, select, sort, trash, where } = input;
23
+ logger.info(`Finding versions in collection: ${slug}, limit: ${limit}, page: ${page}`);
39
24
  try {
40
25
  const result = await payload.findVersions({
41
- collection: collectionSlug,
26
+ collection: slug,
42
27
  depth,
43
28
  limit,
29
+ overrideAccess: authorizedMCP.overrideAccess,
44
30
  page,
45
31
  req,
46
- ...localAPIDefaults(authorizedMCP),
47
- ...fallbackLocale ? {
32
+ ...draft !== undefined ? {
33
+ draft
34
+ } : {},
35
+ ...fallbackLocale !== undefined ? {
48
36
  fallbackLocale
49
37
  } : {},
50
38
  ...locale ? {
@@ -54,13 +42,10 @@ export const findVersionsTool = defineCollectionTool({
54
42
  pagination
55
43
  } : {},
56
44
  ...populate ? {
57
- populate: populate
45
+ populate
58
46
  } : {},
59
47
  ...select ? {
60
- select: select
61
- } : {},
62
- ...showHiddenFields !== undefined ? {
63
- showHiddenFields
48
+ select
64
49
  } : {},
65
50
  ...sort ? {
66
51
  sort
@@ -76,19 +61,19 @@ export const findVersionsTool = defineCollectionTool({
76
61
  content: [
77
62
  {
78
63
  type: 'text',
79
- text: `Versions for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
64
+ text: `Versions for collection "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
80
65
  }
81
66
  ],
82
67
  doc: result
83
68
  };
84
69
  } catch (error) {
85
70
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
86
- logger.error(`Error finding versions in ${collectionSlug}: ${errorMessage}`);
71
+ logger.error(`Error finding versions in ${slug}: ${errorMessage}`);
87
72
  return {
88
73
  content: [
89
74
  {
90
75
  type: 'text',
91
- text: `❌ **Error finding versions in collection "${collectionSlug}":** ${errorMessage}`
76
+ text: `❌ **Error finding versions in collection "${slug}":** ${errorMessage}`
92
77
  }
93
78
  ],
94
79
  isError: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.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 page,\n req,\n ...localAPIDefaults(authorizedMCP),\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","localAPIDefaults","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","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,mBAAmBL,qBAAqB;IACnDM,QAAQ,CAACC,OACPR,cAAcQ,SACdC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IAChEC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOtB,EAAEuB,MAAM,CAAC;QACdC,OAAOxB,EACJyB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJC,QAAQ,CAAC,uEACTC,QAAQ,GACRC,OAAO,CAAC;QACXC,gBAAgBhC,EACbiC,MAAM,GACNJ,QAAQ,CAAC,gFACTC,QAAQ;QACXI,OAAOlC,EACJyB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,KACJC,QAAQ,CAAC,gEACTC,QAAQ,GACRC,OAAO,CAAC;QACXI,QAAQnC,EACLiC,MAAM,GACNJ,QAAQ,CACP,wHAEDC,QAAQ;QACXM,MAAMpC,EACHyB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJE,Q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O,IAAI,CAAC,CAAC;YAC5B,GAAIE,eAAemB,YAAY;gBAAEnB;YAAW,IAAI,CAAC,CAAC;YAClD,GAAIE,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,GAAIC,OAAO;gBAAEA;YAAK,IAAI,CAAC,CAAC;YACxB,GAAIC,UAAUW,YAAY;gBAAEX;YAAM,IAAI,CAAC,CAAC;YACxC,GAAIC,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLW,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,yBAAyB,EAAE9C,eAAe,gBAAgB,EAAE+C,KAAKC,SAAS,CAACR,QAAQ,QAAQ,CAAC;gBACrG;aACD;YACDS,KAAKT;QACP;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9Df,OAAOY,KAAK,CAAC,CAAC,0BAA0B,EAAElD,eAAe,EAAE,EAAEmD,cAAc;QAC3E,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,0CAA0C,EAAE9C,eAAe,KAAK,EAAEmD,cAAc;gBACzF;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionsTool.ts"],"sourcesContent":["import { findVersionsInputSchema } from 'payload'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.'\n\nexport const findVersionsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Versions',\n },\n description: DEFAULT_DESCRIPTION,\n input: findVersionsInputSchema,\n}).handler(async ({ slug, authorizedMCP, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const {\n depth,\n draft,\n fallbackLocale,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n sort,\n trash,\n where,\n } = input\n\n logger.info(`Finding versions in collection: ${slug}, limit: ${limit}, page: ${page}`)\n\n try {\n const result = await payload.findVersions({\n collection: slug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(draft !== undefined ? { draft } : {}),\n ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(pagination !== undefined ? { pagination } : {}),\n ...(populate ? { populate } : {}),\n ...(select ? { select } : {}),\n ...(sort ? { sort } : {}),\n ...(trash !== undefined ? { trash } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Versions for collection \"${slug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding versions in ${slug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding versions in collection \"${slug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["findVersionsInputSchema","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findVersionsTool","access","args","Boolean","permissions","collections","slug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","handler","authorizedMCP","req","payload","logger","depth","draft","fallbackLocale","limit","locale","page","pagination","populate","select","sort","trash","where","info","result","findVersions","collection","overrideAccess","undefined","content","type","text","JS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X;YAAW,IAAI,CAAC,CAAC;YAClD,GAAIC,WAAW;gBAAEA;YAAS,IAAI,CAAC,CAAC;YAChC,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAIC,OAAO;gBAAEA;YAAK,IAAI,CAAC,CAAC;YACxB,GAAIC,UAAUO,YAAY;gBAAEP;YAAM,IAAI,CAAC,CAAC;YACxC,GAAIC,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLO,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,yBAAyB,EAAEnC,KAAK,gBAAgB,EAAEoC,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBAC3F;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9D5B,OAAOyB,KAAK,CAAC,CAAC,0BAA0B,EAAEvC,KAAK,EAAE,EAAEwC,cAAc;QACjE,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,0CAA0C,EAAEnC,KAAK,KAAK,EAAEwC,cAAc;gBAC/E;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,4CAyClC,CAAA"}
1
+ {"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,uBAAuB,4CA0ElC,CAAA"}
@@ -1,10 +1,10 @@
1
+ import { getAccessResults, getCollectionInputSchema, getCollectionSchemaInputSchema } from 'payload';
1
2
  import { defaultAccess } from '../../../defaultAccess.js';
2
3
  import { defineCollectionTool } from '../../../defineTool.js';
3
- import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
4
4
  export const getCollectionSchemaTool = defineCollectionTool({
5
5
  access: (args)=>{
6
- const permissions = args.permissions?.collections?.[args.collectionSlug];
7
- return defaultAccess(args) && Boolean(permissions?.create || permissions?.delete || permissions?.read || permissions?.update);
6
+ const permissions = args.permissions?.collections?.[args.slug];
7
+ return defaultAccess(args) && Boolean(permissions?.create || permissions?.update);
8
8
  },
9
9
  annotations: {
10
10
  destructiveHint: false,
@@ -13,33 +13,73 @@ export const getCollectionSchemaTool = defineCollectionTool({
13
13
  readOnlyHint: true,
14
14
  title: 'Get Collection Schema'
15
15
  },
16
- description: 'Get the input schema for creating or updating documents in a collection.'
17
- }).handler(({ collectionSlug, req })=>{
18
- const inputSchema = getCollectionInputSchema({
19
- collectionSlug,
16
+ description: 'Get the input schema for creating or updating documents in a collection.',
17
+ input: getCollectionSchemaInputSchema
18
+ }).handler(async ({ slug, authorizedMCP, req })=>{
19
+ const permissions = authorizedMCP.overrideAccess ? null : (await getAccessResults({
20
20
  req
21
+ })).collections?.[slug];
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 "${slug}"`
28
+ }
29
+ ],
30
+ isError: true
31
+ };
32
+ }
33
+ const inputSchema = getCollectionInputSchema({
34
+ collectionSlug: slug,
35
+ req,
36
+ ...permissions ? {
37
+ permissions
38
+ } : {}
21
39
  });
22
40
  if (!inputSchema) {
23
41
  return {
24
42
  content: [
25
43
  {
26
44
  type: 'text',
27
- text: `Error: Collection "${collectionSlug}" not found`
45
+ text: `Error: Collection "${slug}" not found`
28
46
  }
29
47
  ],
30
48
  isError: true
31
49
  };
32
50
  }
51
+ const uploadConfig = req.payload.collections[slug]?.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
+ };
33
72
  return {
34
73
  content: [
35
74
  {
36
75
  type: 'text',
37
- text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``
76
+ text: `Schema for collection "${slug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``
38
77
  }
39
78
  ],
40
79
  structuredContent: {
41
- collectionSlug,
42
- schema: inputSchema
80
+ slug,
81
+ schema: inputSchema,
82
+ upload
43
83
  }
44
84
  };
45
85
  });