@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,23 +1,20 @@
1
- import type { SelectType } from 'payload'
2
-
3
- import { z } from 'zod'
1
+ import {
2
+ getGlobalVirtualFieldNames,
3
+ stripVirtualFields,
4
+ transformPointDataToPayload,
5
+ updateGlobalInputSchema,
6
+ validateGlobalData,
7
+ } from 'payload'
4
8
 
5
9
  import { defaultAccess } from '../../../defaultAccess.js'
6
10
  import { defineGlobalTool } from '../../../defineTool.js'
7
11
  import { getLogger } from '../../../utils/getLogger.js'
8
- import {
9
- getGlobalVirtualFieldNames,
10
- stripVirtualFields,
11
- } from '../../../utils/getVirtualFieldNames.js'
12
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
13
- import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
14
- import { validateGlobalData } from '../validateEntityData.js'
12
+ import { formatEntityError } from '../formatEntityError.js'
15
13
 
16
14
  const DEFAULT_DESCRIPTION = 'Update any Payload global by passing the global slug and data.'
17
15
 
18
16
  export const updateGlobalTool = defineGlobalTool({
19
- access: (args) =>
20
- defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),
17
+ access: (args) => defaultAccess(args) && Boolean(args.permissions?.globals?.[args.slug]?.update),
21
18
  annotations: {
22
19
  destructiveHint: true,
23
20
  idempotentHint: false,
@@ -26,72 +23,54 @@ export const updateGlobalTool = defineGlobalTool({
26
23
  title: 'Update Global',
27
24
  },
28
25
  description: DEFAULT_DESCRIPTION,
29
- input: z.object({
30
- data: z.record(z.string(), z.unknown()).describe('The global fields to update'),
31
- depth: z
32
- .number()
33
- .describe('Optional: Depth of relationships to populate')
34
- .optional()
35
- .default(0),
36
- draft: z
37
- .boolean()
38
- .describe('Optional: Whether to save as draft (default: false)')
39
- .optional()
40
- .default(false),
41
- fallbackLocale: z
42
- .string()
43
- .describe('Optional: fallback locale code to use when requested locale is not available')
44
- .optional(),
45
- locale: z
46
- .string()
47
- .describe(
48
- 'Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields',
49
- )
50
- .optional(),
51
- select: z
52
- .record(z.string(), z.unknown())
53
- .describe(
54
- 'Optional: define exactly which fields you\'d like to return in the response, e.g., {"siteName": true}',
55
- )
56
- .optional(),
57
- }),
58
- }).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
26
+ input: updateGlobalInputSchema,
27
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
59
28
  const payload = req.payload
60
29
  const logger = getLogger({ payload })
61
30
 
62
- const { data, depth, draft, fallbackLocale, locale, select } = input
31
+ const {
32
+ data,
33
+ depth,
34
+ draft,
35
+ fallbackLocale,
36
+ locale,
37
+ overrideLock,
38
+ populate,
39
+ publishAllLocales,
40
+ select,
41
+ unpublishAllLocales,
42
+ } = input
63
43
 
64
- logger.info(
65
- `Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
66
- )
44
+ logger.info(`Updating global: ${slug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`)
67
45
 
68
46
  try {
69
- const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)
47
+ const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, slug)
70
48
  const inputData = stripVirtualFields(data, virtualFieldNames)
71
- const validationError = validateGlobalData({ data: inputData, globalSlug, req })
72
-
73
- if (validationError) {
74
- return validationError
75
- }
49
+ validateGlobalData({ slug, data: inputData, req })
76
50
 
77
51
  const parsedData = transformPointDataToPayload(inputData)
78
52
 
79
53
  const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {
80
- slug: globalSlug,
54
+ slug,
81
55
  data: parsedData,
82
56
  depth,
83
57
  draft,
84
- ...localAPIDefaults(authorizedMCP),
58
+ overrideAccess: authorizedMCP.overrideAccess,
59
+ overrideLock,
60
+ populate,
61
+ publishAllLocales,
62
+ req,
63
+ unpublishAllLocales,
85
64
  }
86
65
 
87
66
  if (locale) {
88
67
  updateOptions.locale = locale
89
68
  }
90
- if (fallbackLocale) {
69
+ if (fallbackLocale !== undefined) {
91
70
  updateOptions.fallbackLocale = fallbackLocale
92
71
  }
93
72
  if (select) {
94
- updateOptions.select = select as SelectType
73
+ updateOptions.select = select
95
74
  }
96
75
 
97
76
  const result = await payload.updateGlobal(updateOptions)
@@ -100,16 +79,14 @@ export const updateGlobalTool = defineGlobalTool({
100
79
  content: [
101
80
  {
102
81
  type: 'text',
103
- text: `Global "${globalSlug}" updated successfully!\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
82
+ text: `Global "${slug}" updated successfully!\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
104
83
  },
105
84
  ],
106
85
  doc: result as Record<string, unknown>,
107
86
  }
108
87
  } catch (error) {
109
- const errorMessage = error instanceof Error ? error.message : 'Unknown error'
110
- logger.error(`Error updating global ${globalSlug}: ${errorMessage}`)
111
- return {
112
- content: [{ type: 'text', text: `Error updating global "${globalSlug}": ${errorMessage}` }],
113
- }
88
+ const message = error instanceof Error ? error.message : 'Unknown error'
89
+ logger.error(`Error updating global ${slug}: ${message}`)
90
+ return formatEntityError({ slug, action: 'updating', entity: 'global', error, req })
114
91
  }
115
92
  })
@@ -10,7 +10,7 @@ import {
10
10
  } from './builtin/collections/authTools.js'
11
11
  import { countDocumentsTool } from './builtin/collections/countTool.js'
12
12
  import { countVersionsTool } from './builtin/collections/countVersionsTool.js'
13
- import { createDocumentTool } from './builtin/collections/createTool.js'
13
+ import { createDocumentsTool } from './builtin/collections/createTool.js'
14
14
  import { deleteDocumentsTool } from './builtin/collections/deleteTool.js'
15
15
  import { duplicateDocumentTool } from './builtin/collections/duplicateTool.js'
16
16
  import { findDistinctTool } from './builtin/collections/findDistinctTool.js'
@@ -20,6 +20,7 @@ import { findVersionsTool } from './builtin/collections/findVersionsTool.js'
20
20
  import { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js'
21
21
  import { restoreVersionTool } from './builtin/collections/restoreVersionTool.js'
22
22
  import { updateDocumentTool } from './builtin/collections/updateTool.js'
23
+ import { getUploadInstructionsTool } from './builtin/collections/uploadInstructionsTool.js'
23
24
  import { getConfigInfoTool } from './builtin/getConfigInfoTool.js'
24
25
  import { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js'
25
26
  import { findGlobalTool } from './builtin/globals/findTool.js'
@@ -32,6 +33,7 @@ import { updateGlobalTool } from './builtin/globals/updateTool.js'
32
33
  type CollectionBuiltin = {
33
34
  mcpName: string
34
35
  requiresDuplicateEnabled?: boolean
36
+ requiresUpload?: boolean
35
37
  requiresVersions?: boolean
36
38
  tool: CollectionTool
37
39
  }
@@ -54,7 +56,7 @@ export const TOOL_BUILTINS = {
54
56
  export const COLLECTION_BUILTINS = {
55
57
  count: { mcpName: 'countDocuments', tool: countDocumentsTool },
56
58
  countVersions: { mcpName: 'countVersions', requiresVersions: true, tool: countVersionsTool },
57
- create: { mcpName: 'createDocument', tool: createDocumentTool },
59
+ create: { mcpName: 'createDocuments', tool: createDocumentsTool },
58
60
  delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },
59
61
  duplicate: {
60
62
  mcpName: 'duplicateDocument',
@@ -70,6 +72,11 @@ export const COLLECTION_BUILTINS = {
70
72
  },
71
73
  findVersions: { mcpName: 'findVersions', requiresVersions: true, tool: findVersionsTool },
72
74
  getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },
75
+ getUploadInstructions: {
76
+ mcpName: 'getUploadInstructions',
77
+ requiresUpload: true,
78
+ tool: getUploadInstructionsTool,
79
+ },
73
80
  restoreVersion: { mcpName: 'restoreVersion', requiresVersions: true, tool: restoreVersionTool },
74
81
  update: { mcpName: 'updateDocument', tool: updateDocumentTool },
75
82
  } satisfies Record<string, CollectionBuiltin>
@@ -100,6 +100,7 @@ export const sanitizeMCPConfig = ({
100
100
 
101
101
  return {
102
102
  disabled: pluginConfig.disabled,
103
+ hooks: pluginConfig.hooks,
103
104
  items,
104
105
  mcp: pluginConfig.mcp,
105
106
  overrideGetAuthorizedMCP: pluginConfig.overrideGetAuthorizedMCP,
@@ -126,7 +127,7 @@ const sanitizeCollectionConfig = ({
126
127
 
127
128
  for (const [
128
129
  toolKey,
129
- { mcpName, requiresDuplicateEnabled, requiresVersions, tool },
130
+ { mcpName, requiresDuplicateEnabled, requiresUpload, requiresVersions, tool },
130
131
  ] of COLLECTION_BUILTIN_ENTRIES) {
131
132
  if (requiresVersions && !collection.versions) {
132
133
  continue
@@ -134,6 +135,9 @@ const sanitizeCollectionConfig = ({
134
135
  if (requiresDuplicateEnabled && isDuplicateDisabled) {
135
136
  continue
136
137
  }
138
+ if (requiresUpload && !collection.upload) {
139
+ continue
140
+ }
137
141
  const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]
138
142
  if (matchedConfigEntry === false) {
139
143
  continue
package/src/stdio.ts CHANGED
@@ -1,10 +1,10 @@
1
- import type { MaybePromise, Plugin, SanitizedConfig } from 'payload'
1
+ import type { Config, Plugin, SanitizedConfig } from 'payload'
2
2
 
3
3
  /* eslint-disable no-console */
4
- import { StdioServerTransport } from '@modelcontextprotocol/server'
4
+ import { serveStdio } from '@modelcontextprotocol/server/stdio'
5
5
  import { fileURLToPath, pathToFileURL } from 'node:url'
6
6
  import { createLocalReq, getPayload } from 'payload'
7
- import { findConfig } from 'payload/node'
7
+ import { findConfig, loadEnv } from 'payload/node'
8
8
 
9
9
  import type { SanitizedMCPPluginConfig } from './types.js'
10
10
 
@@ -15,53 +15,62 @@ import { getPluginConfig } from './utils/getPluginConfig.js'
15
15
  import { resolveProjectRoot } from './utils/resolveProjectRoot.js'
16
16
 
17
17
  /**
18
- * Stdio adapter for the Payload MCP server.
18
+ * Starts Payload's MCP server over stdin and stdout.
19
19
  *
20
- * Pass PAYLOAD_MCP_AUTHORIZATION when stdio should authenticate with the same
21
- * Payload auth header as HTTP. In development, PAYLOAD_MCP_OVERRIDE_ACCESS=true
22
- * skips access control for local setup.
20
+ * Set `PAYLOAD_MCP_AUTHORIZATION` to authenticate. In development,
21
+ * `PAYLOAD_MCP_OVERRIDE_ACCESS=true` skips access checks.
23
22
  */
24
23
  export const runMcpStdio = async (): Promise<void> => {
25
- /**
26
- * If MCP clients spawn stdio servers from an arbitrary working directory,
27
- * Payload's cwd-anchored `findConfig()` can't locate the project on
28
- * its own. This module always lives inside the project's `node_modules`, so
29
- * we derive the project root from its own path and `chdir` into it.
30
- *
31
- * An absolute `PAYLOAD_CONFIG_PATH` still overrides everything; unusual
32
- * layouts (e.g. a monorepo where the package is hoisted above the app) can
33
- * fall back to it. See the implementation of findConfig for details.
34
- */
24
+ // MCP clients may start this command from another folder. Move to the Payload
25
+ // project so findConfig() can find the config.
35
26
  const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url))
36
27
  if (projectRoot) {
37
28
  process.chdir(projectRoot)
38
29
  }
39
30
 
31
+ loadEnv()
40
32
  const configPath = findConfig()
41
33
  const configModule = await import(pathToFileURL(configPath).toString())
42
- const config = (await (configModule.default ?? configModule)) as MaybePromise<SanitizedConfig>
43
-
44
- const payload = await getPayload({ config })
34
+ const config = (await (configModule.default ?? configModule)) as SanitizedConfig
45
35
 
46
36
  /**
47
- * If the user added `mcpPlugin({...})` to their `plugins` array, read the
48
- * sanitized config they registered. Otherwise fall back to the defaults. That way,
49
- * the mcp works on any project that has `@payloadcms/plugin-mcp` installed,
50
- * even if the plugin is not added to the plugins array.
37
+ * stdout is only for MCP messages. The spec says the server must not write
38
+ * logs there and may write them to stderr instead.
39
+ *
40
+ * The 2.0 client library recovers from stray stdout logs, but that behavior is not
41
+ * guaranteed. Move Payload logs to stderr so Payload does not add invalid data
42
+ * to stdout. Keep options from configurable loggers. Replace pre-built loggers
43
+ * because their output cannot be redirected.
44
+ *
45
+ * @see https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#stdio
51
46
  */
47
+ const loggerConfig: { logger?: Config['logger'] } = config
48
+ if (
49
+ loggerConfig.logger &&
50
+ typeof loggerConfig.logger === 'object' &&
51
+ 'options' in loggerConfig.logger
52
+ ) {
53
+ loggerConfig.logger.destination = process.stderr
54
+ } else {
55
+ loggerConfig.logger = { destination: process.stderr, options: {} }
56
+ }
57
+
58
+ const payload = await getPayload({ config, cron: false, disableOnInit: true })
59
+
52
60
  let pluginConfig: SanitizedMCPPluginConfig
53
61
  try {
54
62
  pluginConfig = getPluginConfig({ config: payload.config })
55
63
  } catch {
64
+ // The command also works when mcpPlugin() is not in the Payload config.
56
65
  pluginConfig = sanitizeMCPConfig({ config: payload.config, pluginConfig: {} })
57
66
 
58
- const fakePluginFn: Plugin = (config) => config
59
- fakePluginFn.slug = '@payloadcms/plugin-mcp'
60
- // @ts-expect-error
61
- fakePluginFn.sanitizedOptions = pluginConfig
62
-
63
- // Push to payload config, to ensure consecutive calls to `getPluginConfig()` work
64
- ;(payload.config.plugins ??= []).push(fakePluginFn)
67
+ const fallbackPlugin: Plugin = (config) => config
68
+ Object.assign(fallbackPlugin, {
69
+ slug: '@payloadcms/plugin-mcp',
70
+ sanitizedOptions: pluginConfig,
71
+ })
72
+ payload.config.plugins ??= []
73
+ payload.config.plugins.push(fallbackPlugin)
65
74
  }
66
75
 
67
76
  const overrideAccessEnv = process.env.PAYLOAD_MCP_OVERRIDE_ACCESS
@@ -86,28 +95,37 @@ export const runMcpStdio = async (): Promise<void> => {
86
95
  req.payloadAPI = 'MCP' as const
87
96
  const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
88
97
 
89
- const server = buildMcpServer({ authorizedMCP, pluginConfig, req })
90
-
91
- const transport = new StdioServerTransport()
92
- await server.connect(transport)
98
+ const stdioServer = serveStdio(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {
99
+ onerror: (err) => {
100
+ // MCP messages use stdout, so write SDK errors to stderr.
101
+ console.error('[payload-mcp] error serving MCP over stdio:', err)
102
+ },
103
+ })
104
+
105
+ // Close the MCP server and Payload when the client disconnects or the process stops.
106
+ let isShuttingDown = false
107
+ const shutdown = async () => {
108
+ if (isShuttingDown) {
109
+ return
110
+ }
111
+ isShuttingDown = true
93
112
 
94
- // Process now lives until stdin closes. Wire graceful shutdown so DB
95
- // connections (and any other Payload-managed resources) get released.
96
- const shutdown = async (code = 0) => {
97
113
  try {
98
- await server.close()
114
+ await stdioServer.close()
99
115
  } catch (err) {
100
116
  console.error('[payload-mcp] error closing server:', err)
101
117
  }
118
+
102
119
  try {
103
120
  await payload.destroy()
104
121
  } catch (err) {
105
122
  console.error('[payload-mcp] error destroying payload:', err)
106
123
  }
107
- process.exit(code)
124
+
125
+ process.exit(0)
108
126
  }
109
127
 
110
- process.on('SIGINT', () => void shutdown(0))
111
- process.on('SIGTERM', () => void shutdown(0))
112
- process.stdin.on('close', () => void shutdown(0))
128
+ process.once('SIGINT', () => void shutdown())
129
+ process.once('SIGTERM', () => void shutdown())
130
+ process.stdin.once('close', () => void shutdown())
113
131
  }
package/src/types.ts CHANGED
@@ -15,7 +15,6 @@ import type {
15
15
  MaybePromise,
16
16
  PayloadRequest,
17
17
  SanitizedPermissions,
18
- TypedUser,
19
18
  } from 'payload'
20
19
 
21
20
  import type { GetAuthorizedMCPArgs } from './endpoint/access.js'
@@ -32,7 +31,8 @@ export type { JsonSchemaType, StandardSchemaWithJSON, ToolAnnotations }
32
31
 
33
32
  /**
34
33
  * What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw
35
- * JSON Schema literal, or a Standard Schema instance (Zod, Valibot, …).
34
+ * JSON Schema 2020-12 literal, or a Standard Schema instance (Zod, Valibot, …).
35
+ * Raw schemas may omit `$schema`; when present it must declare the 2020-12 dialect.
36
36
  */
37
37
  export type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON
38
38
 
@@ -52,6 +52,13 @@ export type MCPResponseOverride = (
52
52
  req: PayloadRequest,
53
53
  ) => MCPToolResponse
54
54
 
55
+ export type MCPAfterToolCallHook = (args: {
56
+ input: unknown
57
+ req: PayloadRequest
58
+ response: MCPToolResponse
59
+ toolName: string
60
+ }) => MaybePromise<MCPToolResponse>
61
+
55
62
  /**
56
63
  * The handler's `input` type. A specific Standard Schema (Zod, Valibot, …) gets
57
64
  * its inferred output; anything else falls back to `Record<string, unknown>`.
@@ -68,11 +75,11 @@ export type MCPAccessArgs = {
68
75
  }
69
76
 
70
77
  export type CollectionMCPAccessArgs = {
71
- collectionSlug: CollectionSlug
78
+ slug: CollectionSlug
72
79
  } & MCPAccessArgs
73
80
 
74
81
  export type GlobalMCPAccessArgs = {
75
- globalSlug: GlobalSlug
82
+ slug: GlobalSlug
76
83
  } & MCPAccessArgs
77
84
 
78
85
  export type ToolHandlerArgs<TSchema = undefined> = {
@@ -83,14 +90,19 @@ export type ToolHandlerArgs<TSchema = undefined> = {
83
90
  }
84
91
 
85
92
  export type CollectionToolHandlerArgs<TSchema = undefined> = {
86
- collectionSlug: CollectionSlug
93
+ slug: CollectionSlug
87
94
  } & ToolHandlerArgs<TSchema>
88
95
 
89
96
  export type GlobalToolHandlerArgs<TSchema = undefined> = {
90
- globalSlug: GlobalSlug
97
+ slug: GlobalSlug
91
98
  } & ToolHandlerArgs<TSchema>
92
99
 
93
100
  export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
101
+ /**
102
+ * Runs while authorizing each MCP request, before the tool is advertised or called. Return
103
+ * `false` to make the tool unavailable for that request. This is skipped when `overrideAccess`
104
+ * is enabled.
105
+ */
94
106
  access?: (args: MCPAccessArgs) => MaybePromise<boolean>
95
107
  annotations?: ToolAnnotations
96
108
  description: string
@@ -105,6 +117,12 @@ export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema |
105
117
  export type CollectionTool<
106
118
  TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,
107
119
  > = {
120
+ /**
121
+ * Runs while authorizing each MCP request for this collection. Return `false` to reject calls
122
+ * to this tool for the collection. The shared tool is not advertised when no collections allow
123
+ * it, but can remain advertised when it is available for another collection. This is skipped
124
+ * when `overrideAccess` is enabled.
125
+ */
108
126
  access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>
109
127
  handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
110
128
  input?: TSchema
@@ -112,6 +130,12 @@ export type CollectionTool<
112
130
 
113
131
  export type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> =
114
132
  {
133
+ /**
134
+ * Runs while authorizing each MCP request for this global. Return `false` to reject calls to
135
+ * this tool for the global. The shared tool is not advertised when no globals allow it, but
136
+ * can remain advertised when it is available for another global. This is skipped when
137
+ * `overrideAccess` is enabled.
138
+ */
115
139
  access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>
116
140
  handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
117
141
  input?: TSchema
@@ -123,6 +147,10 @@ export type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSc
123
147
  * required handler) from being silently accepted at a built-in key slot.
124
148
  */
125
149
  export type MCPBuiltInCollectionToolOverride = {
150
+ /**
151
+ * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
152
+ * this collection. This is skipped when `overrideAccess` is enabled.
153
+ */
126
154
  access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>
127
155
  annotations?: ToolAnnotations
128
156
  description?: string
@@ -131,6 +159,10 @@ export type MCPBuiltInCollectionToolOverride = {
131
159
  }
132
160
 
133
161
  export type MCPBuiltInGlobalToolOverride = {
162
+ /**
163
+ * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
164
+ * this global. This is skipped when `overrideAccess` is enabled.
165
+ */
134
166
  access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>
135
167
  annotations?: ToolAnnotations
136
168
  description?: string
@@ -175,6 +207,11 @@ export type PromptHandlerArgs<TSchema = undefined> = {
175
207
  }
176
208
 
177
209
  export type Prompt<TSchema extends ToolInputSchema = ToolInputSchema> = {
210
+ /**
211
+ * Runs while authorizing each MCP request, before the prompt is advertised or used. Return
212
+ * `false` to make the prompt unavailable for that request. This is skipped when
213
+ * `overrideAccess` is enabled.
214
+ */
178
215
  access?: (args: MCPAccessArgs) => MaybePromise<boolean>
179
216
  argsSchema: TSchema
180
217
  description: string
@@ -193,6 +230,11 @@ export type ResourceHandlerArgs = {
193
230
  }
194
231
 
195
232
  export type Resource = {
233
+ /**
234
+ * Runs while authorizing each MCP request, before the resource is advertised or read. Return
235
+ * `false` to make the resource unavailable for that request. This is skipped when
236
+ * `overrideAccess` is enabled.
237
+ */
196
238
  access?: (args: MCPAccessArgs) => MaybePromise<boolean>
197
239
  description: string
198
240
  handler: (args: ResourceHandlerArgs) => MaybePromise<{
@@ -232,11 +274,20 @@ export type MCPPluginConfig = {
232
274
  globals?: {
233
275
  [Slug in GlobalSlug]?: MCPPluginGlobalConfig
234
276
  }
277
+ hooks?: {
278
+ /** Transform a tool response after its handler returns */
279
+ afterToolCall?: MCPAfterToolCallHook[]
280
+ }
235
281
  mcp?: {
236
282
  serverOptions?: MCPServerOptions
237
283
  verboseLogs?: boolean
238
284
  }
239
- /** Replace the default MCP authorization resolver. */
285
+ /**
286
+ * Replace the default MCP authorization resolver.
287
+ *
288
+ * This hook replaces the default authentication flow. It must set `req.user` to the
289
+ * authenticated Payload user, or to `null` for an anonymous caller, before returning.
290
+ */
240
291
  overrideGetAuthorizedMCP?: (
241
292
  args: {
242
293
  pluginConfig: SanitizedMCPPluginConfig
@@ -250,7 +301,7 @@ export type MCPPluginConfig = {
250
301
 
251
302
  export type SanitizedMCPPluginConfig = {
252
303
  items: MCPItem[]
253
- } & Pick<MCPPluginConfig, 'disabled' | 'mcp' | 'overrideGetAuthorizedMCP'>
304
+ } & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>
254
305
 
255
306
  export type MCPServerOptions = {
256
307
  options?: ConstructorParameters<typeof McpServer>[1]
@@ -300,13 +351,10 @@ export type MCPItem =
300
351
  | GlobalMCPItem
301
352
 
302
353
  /**
303
- * The caller's identity + the MCP items authorized for this request. Disabled
304
- * items and items blocked by access callbacks or Payload operation access are
305
- * absent from `items`. Tool handlers receive this via `args.authorizedMCP` so
306
- * they can spread `localAPIDefaults(authorizedMCP)` into every local API call.
354
+ * The MCP items and access mode authorized for this request. The authenticated user is available
355
+ * as `req.user`.
307
356
  */
308
357
  export type AuthorizedMCP = {
309
358
  items: MCPItem[]
310
359
  overrideAccess: boolean
311
- user: null | TypedUser
312
360
  }
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=assets.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/@types/assets.d.ts"],"names":[],"mappings":""}
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
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,GAAI,yCAKnC;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"}
@@ -1,60 +0,0 @@
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
@@ -1 +0,0 @@
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"}