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

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 (166) hide show
  1. package/dist/endpoint/access.js +2 -2
  2. package/dist/endpoint/access.js.map +1 -1
  3. package/dist/mcp/buildMcpServer.d.ts +1 -1
  4. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  5. package/dist/mcp/buildMcpServer.js +35 -23
  6. package/dist/mcp/buildMcpServer.js.map +1 -1
  7. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  8. package/dist/mcp/builtin/collections/authTools.js +79 -56
  9. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  10. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
  11. package/dist/mcp/builtin/collections/countTool.js +9 -14
  12. package/dist/mcp/builtin/collections/countTool.js.map +1 -1
  13. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
  14. package/dist/mcp/builtin/collections/countVersionsTool.js +9 -13
  15. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
  16. package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
  17. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  18. package/dist/mcp/builtin/collections/createTool.js +94 -60
  19. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  20. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  21. package/dist/mcp/builtin/collections/deleteTool.js +40 -43
  22. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  23. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
  24. package/dist/mcp/builtin/collections/duplicateTool.js +15 -34
  25. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  26. package/dist/mcp/builtin/collections/fileInput.d.ts +21 -13
  27. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -1
  28. package/dist/mcp/builtin/collections/fileInput.js +40 -17
  29. package/dist/mcp/builtin/collections/fileInput.js.map +1 -1
  30. package/dist/mcp/builtin/collections/fileInput.spec.js +20 -6
  31. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -1
  32. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
  33. package/dist/mcp/builtin/collections/findDistinctTool.js +11 -26
  34. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
  35. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  36. package/dist/mcp/builtin/collections/findTool.js +21 -43
  37. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  38. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
  39. package/dist/mcp/builtin/collections/findVersionByIDTool.js +17 -26
  40. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
  41. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
  42. package/dist/mcp/builtin/collections/findVersionsTool.js +16 -30
  43. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
  44. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +2 -2
  45. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
  46. package/dist/mcp/builtin/collections/formatCollectionError.js +6 -6
  47. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -1
  48. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  49. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +15 -14
  50. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  51. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
  52. package/dist/mcp/builtin/collections/restoreVersionTool.js +14 -26
  53. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  54. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  55. package/dist/mcp/builtin/collections/updateTool.js +38 -80
  56. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  57. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  58. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  59. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  60. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  61. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  62. package/dist/mcp/builtin/getConfigInfoTool.js +3 -2
  63. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  64. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
  65. package/dist/mcp/builtin/globals/countVersionsTool.js +9 -13
  66. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
  67. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  68. package/dist/mcp/builtin/globals/findTool.js +10 -16
  69. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  70. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
  71. package/dist/mcp/builtin/globals/findVersionByIDTool.js +13 -24
  72. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
  73. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
  74. package/dist/mcp/builtin/globals/findVersionsTool.js +13 -29
  75. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
  76. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  77. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +11 -11
  78. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  79. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
  80. package/dist/mcp/builtin/globals/restoreVersionTool.js +15 -22
  81. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
  82. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  83. package/dist/mcp/builtin/globals/updateTool.js +18 -23
  84. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  85. package/dist/mcp/builtin/validateEntityData.d.ts +4 -4
  86. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
  87. package/dist/mcp/builtin/validateEntityData.js +7 -7
  88. package/dist/mcp/builtin/validateEntityData.js.map +1 -1
  89. package/dist/mcp/builtinTools.d.ts +6 -0
  90. package/dist/mcp/builtinTools.d.ts.map +1 -1
  91. package/dist/mcp/builtinTools.js +9 -3
  92. package/dist/mcp/builtinTools.js.map +1 -1
  93. package/dist/mcp/sanitizeMCPConfig.js +4 -1
  94. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  95. package/dist/stdio.d.ts.map +1 -1
  96. package/dist/stdio.js +2 -1
  97. package/dist/stdio.js.map +1 -1
  98. package/dist/types.d.ts +4 -4
  99. package/dist/types.d.ts.map +1 -1
  100. package/dist/types.js.map +1 -1
  101. package/package.json +6 -8
  102. package/src/endpoint/access.ts +2 -3
  103. package/src/mcp/buildMcpServer.ts +39 -29
  104. package/src/mcp/builtin/collections/authTools.ts +77 -69
  105. package/src/mcp/builtin/collections/countTool.ts +9 -21
  106. package/src/mcp/builtin/collections/countVersionsTool.ts +9 -18
  107. package/src/mcp/builtin/collections/createTool.ts +87 -84
  108. package/src/mcp/builtin/collections/deleteTool.ts +36 -64
  109. package/src/mcp/builtin/collections/duplicateTool.ts +21 -83
  110. package/src/mcp/builtin/collections/fileInput.spec.ts +20 -6
  111. package/src/mcp/builtin/collections/fileInput.ts +53 -23
  112. package/src/mcp/builtin/collections/findDistinctTool.ts +11 -63
  113. package/src/mcp/builtin/collections/findTool.ts +21 -103
  114. package/src/mcp/builtin/collections/findVersionByIDTool.ts +15 -58
  115. package/src/mcp/builtin/collections/findVersionsTool.ts +14 -85
  116. package/src/mcp/builtin/collections/formatCollectionError.ts +8 -8
  117. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +16 -12
  118. package/src/mcp/builtin/collections/restoreVersionTool.ts +14 -56
  119. package/src/mcp/builtin/collections/updateTool.ts +47 -101
  120. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  121. package/src/mcp/builtin/getConfigInfoTool.ts +2 -1
  122. package/src/mcp/builtin/globals/countVersionsTool.ts +9 -17
  123. package/src/mcp/builtin/globals/findTool.ts +12 -51
  124. package/src/mcp/builtin/globals/findVersionByIDTool.ts +13 -52
  125. package/src/mcp/builtin/globals/findVersionsTool.ts +14 -92
  126. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +10 -10
  127. package/src/mcp/builtin/globals/restoreVersionTool.ts +14 -45
  128. package/src/mcp/builtin/globals/updateTool.ts +34 -52
  129. package/src/mcp/builtin/validateEntityData.ts +10 -13
  130. package/src/mcp/builtinTools.ts +9 -2
  131. package/src/mcp/sanitizeMCPConfig.ts +4 -1
  132. package/src/stdio.ts +2 -1
  133. package/src/types.ts +4 -4
  134. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  135. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  136. package/dist/utils/getVirtualFieldNames.js +0 -35
  137. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  138. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +0 -28
  139. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +0 -1
  140. package/dist/utils/schemaConversion/filterFieldsByAccess.js +0 -71
  141. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +0 -1
  142. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -13
  143. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
  144. package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -66
  145. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
  146. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -10
  147. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
  148. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -384
  149. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
  150. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -133
  151. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
  152. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  153. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  154. package/dist/utils/transformPointDataToPayload.js +0 -28
  155. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  156. package/dist/utils/whereSchema.d.ts +0 -9
  157. package/dist/utils/whereSchema.d.ts.map +0 -1
  158. package/dist/utils/whereSchema.js +0 -13
  159. package/dist/utils/whereSchema.js.map +0 -1
  160. package/src/utils/getVirtualFieldNames.ts +0 -53
  161. package/src/utils/schemaConversion/filterFieldsByAccess.ts +0 -123
  162. package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -96
  163. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -96
  164. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -432
  165. package/src/utils/transformPointDataToPayload.ts +0 -40
  166. package/src/utils/whereSchema.ts +0 -24
@@ -1,6 +1,4 @@
1
- import type { PopulateType, SelectType } from 'payload'
2
-
3
- import { z } from 'zod'
1
+ import { findGlobalVersionByIDInputSchema } from 'payload'
4
2
 
5
3
  import { defaultAccess } from '../../../defaultAccess.js'
6
4
  import { defineGlobalTool } from '../../../defineTool.js'
@@ -11,7 +9,7 @@ const DEFAULT_DESCRIPTION =
11
9
 
12
10
  export const findGlobalVersionByIDTool = defineGlobalTool({
13
11
  access: (args) =>
14
- defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
12
+ defaultAccess(args) && Boolean(args.permissions?.globals?.[args.slug]?.readVersions),
15
13
  annotations: {
16
14
  destructiveHint: false,
17
15
  idempotentHint: true,
@@ -20,81 +18,44 @@ export const findGlobalVersionByIDTool = defineGlobalTool({
20
18
  title: 'Find Global Version By ID',
21
19
  },
22
20
  description: DEFAULT_DESCRIPTION,
23
- input: z.object({
24
- id: z.string().describe('The ID of the global version to retrieve'),
25
- depth: z
26
- .number()
27
- .int()
28
- .min(0)
29
- .max(10)
30
- .describe('How many levels deep to populate relationships in the global version document')
31
- .optional()
32
- .default(0),
33
- fallbackLocale: z
34
- .string()
35
- .describe('Optional: fallback locale code to use when requested locale is not available')
36
- .optional(),
37
- locale: z
38
- .string()
39
- .describe(
40
- 'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
41
- )
42
- .optional(),
43
- populate: z
44
- .record(z.string(), z.unknown())
45
- .describe(
46
- 'Optional: control which fields to include from populated relationship or upload documents.',
47
- )
48
- .optional(),
49
- select: z
50
- .record(z.string(), z.unknown())
51
- .describe(
52
- 'Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.siteName": true}',
53
- )
54
- .optional(),
55
- showHiddenFields: z
56
- .boolean()
57
- .describe('Optional: include hidden fields in the returned global version document')
58
- .optional(),
59
- }),
60
- }).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
21
+ input: findGlobalVersionByIDInputSchema,
22
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
61
23
  const payload = req.payload
62
24
  const logger = getLogger({ payload })
63
- const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields } = input
25
+ const { id, depth, fallbackLocale, locale, populate, select } = input
64
26
 
65
- logger.info(`Finding version for global: ${globalSlug} with ID: ${id}`)
27
+ logger.info(`Finding version for global: ${slug} with ID: ${id}`)
66
28
 
67
29
  try {
68
30
  const result = await payload.findGlobalVersionByID({
69
31
  id,
70
- slug: globalSlug,
32
+ slug,
71
33
  depth,
72
34
  overrideAccess: authorizedMCP.overrideAccess,
73
35
  req,
74
- ...(fallbackLocale ? { fallbackLocale } : {}),
36
+ ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),
75
37
  ...(locale ? { locale } : {}),
76
- ...(populate ? { populate: populate as PopulateType } : {}),
77
- ...(select ? { select: select as SelectType } : {}),
78
- ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
38
+ ...(populate ? { populate } : {}),
39
+ ...(select ? { select } : {}),
79
40
  })
80
41
 
81
42
  return {
82
43
  content: [
83
44
  {
84
45
  type: 'text',
85
- text: `Version "${id}" from global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
46
+ text: `Version "${id}" from global "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
86
47
  },
87
48
  ],
88
49
  doc: result as unknown as Record<string, unknown>,
89
50
  }
90
51
  } catch (error) {
91
52
  const errorMessage = error instanceof Error ? error.message : 'Unknown error'
92
- logger.error(`Error finding version ${id} for global ${globalSlug}: ${errorMessage}`)
53
+ logger.error(`Error finding version ${id} for global ${slug}: ${errorMessage}`)
93
54
  return {
94
55
  content: [
95
56
  {
96
57
  type: 'text',
97
- text: `❌ **Error finding version "${id}" for global "${globalSlug}":** ${errorMessage}`,
58
+ text: `❌ **Error finding version "${id}" for global "${slug}":** ${errorMessage}`,
98
59
  },
99
60
  ],
100
61
  isError: true,
@@ -1,18 +1,15 @@
1
- import type { PopulateType, SelectType } from 'payload'
2
-
3
- import { z } from 'zod'
1
+ import { findGlobalVersionsInputSchema } from 'payload'
4
2
 
5
3
  import { defaultAccess } from '../../../defaultAccess.js'
6
4
  import { defineGlobalTool } from '../../../defineTool.js'
7
5
  import { getLogger } from '../../../utils/getLogger.js'
8
- import { whereSchema } from '../../../utils/whereSchema.js'
9
6
 
10
7
  const DEFAULT_DESCRIPTION =
11
8
  'Find global versions in any version-enabled global by passing the global slug and optional where clause.'
12
9
 
13
10
  export const findGlobalVersionsTool = defineGlobalTool({
14
11
  access: (args) =>
15
- defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
12
+ defaultAccess(args) && Boolean(args.permissions?.globals?.[args.slug]?.readVersions),
16
13
  annotations: {
17
14
  destructiveHint: false,
18
15
  idempotentHint: true,
@@ -21,103 +18,28 @@ export const findGlobalVersionsTool = defineGlobalTool({
21
18
  title: 'Find Global Versions',
22
19
  },
23
20
  description: DEFAULT_DESCRIPTION,
24
- input: z.object({
25
- depth: z
26
- .number()
27
- .int()
28
- .min(0)
29
- .max(10)
30
- .describe('How many levels deep to populate relationships in global version documents')
31
- .optional()
32
- .default(0),
33
- fallbackLocale: z
34
- .string()
35
- .describe('Optional: fallback locale code to use when requested locale is not available')
36
- .optional(),
37
- limit: z
38
- .number()
39
- .int()
40
- .min(1)
41
- .max(100)
42
- .describe('Maximum number of versions to return (default: 10, max: 100)')
43
- .optional()
44
- .default(10),
45
- locale: z
46
- .string()
47
- .describe(
48
- 'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
49
- )
50
- .optional(),
51
- page: z
52
- .number()
53
- .int()
54
- .min(1)
55
- .describe('Page number for pagination (default: 1)')
56
- .optional()
57
- .default(1),
58
- pagination: z
59
- .boolean()
60
- .describe('Optional: set to false to skip the count query overhead')
61
- .optional(),
62
- populate: z
63
- .record(z.string(), z.unknown())
64
- .describe(
65
- 'Optional: control which fields to include from populated relationship or upload documents.',
66
- )
67
- .optional(),
68
- select: z
69
- .record(z.string(), z.unknown())
70
- .describe(
71
- 'Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.siteName": true}',
72
- )
73
- .optional(),
74
- showHiddenFields: z
75
- .boolean()
76
- .describe('Optional: include hidden fields in returned global version documents')
77
- .optional(),
78
- sort: z
79
- .string()
80
- .describe('Field to sort by (e.g., "-updatedAt", "-version.updatedAt" for descending)')
81
- .optional(),
82
- where: whereSchema
83
- .describe(
84
- 'Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.siteName":{"contains":"test"}}',
85
- )
86
- .optional(),
87
- }),
88
- }).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
21
+ input: findGlobalVersionsInputSchema,
22
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
89
23
  const payload = req.payload
90
24
  const logger = getLogger({ payload })
91
- const {
92
- depth,
93
- fallbackLocale,
94
- limit,
95
- locale,
96
- page,
97
- pagination,
98
- populate,
99
- select,
100
- showHiddenFields,
101
- sort,
102
- where,
103
- } = input
25
+ const { depth, fallbackLocale, limit, locale, page, pagination, populate, select, sort, where } =
26
+ input
104
27
 
105
- logger.info(`Finding versions for global: ${globalSlug}, limit: ${limit}, page: ${page}`)
28
+ logger.info(`Finding versions for global: ${slug}, limit: ${limit}, page: ${page}`)
106
29
 
107
30
  try {
108
31
  const result = await payload.findGlobalVersions({
109
- slug: globalSlug,
32
+ slug,
110
33
  depth,
111
34
  limit,
112
35
  overrideAccess: authorizedMCP.overrideAccess,
113
36
  page,
114
37
  req,
115
- ...(fallbackLocale ? { fallbackLocale } : {}),
38
+ ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),
116
39
  ...(locale ? { locale } : {}),
117
40
  ...(pagination !== undefined ? { pagination } : {}),
118
- ...(populate ? { populate: populate as PopulateType } : {}),
119
- ...(select ? { select: select as SelectType } : {}),
120
- ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
41
+ ...(populate ? { populate } : {}),
42
+ ...(select ? { select } : {}),
121
43
  ...(sort ? { sort } : {}),
122
44
  ...(where ? { where } : {}),
123
45
  })
@@ -126,19 +48,19 @@ export const findGlobalVersionsTool = defineGlobalTool({
126
48
  content: [
127
49
  {
128
50
  type: 'text',
129
- text: `Versions for global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
51
+ text: `Versions for global "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
130
52
  },
131
53
  ],
132
54
  doc: result as unknown as Record<string, unknown>,
133
55
  }
134
56
  } catch (error) {
135
57
  const errorMessage = error instanceof Error ? error.message : 'Unknown error'
136
- logger.error(`Error finding versions for global ${globalSlug}: ${errorMessage}`)
58
+ logger.error(`Error finding versions for global ${slug}: ${errorMessage}`)
137
59
  return {
138
60
  content: [
139
61
  {
140
62
  type: 'text',
141
- text: `❌ **Error finding versions for global "${globalSlug}":** ${errorMessage}`,
63
+ text: `❌ **Error finding versions for global "${slug}":** ${errorMessage}`,
142
64
  },
143
65
  ],
144
66
  isError: true,
@@ -1,12 +1,11 @@
1
- import { getAccessResults } from 'payload'
1
+ import { getAccessResults, getGlobalInputSchema, getGlobalSchemaInputSchema } from 'payload'
2
2
 
3
3
  import { defaultAccess } from '../../../defaultAccess.js'
4
4
  import { defineGlobalTool } from '../../../defineTool.js'
5
- import { getGlobalInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
6
5
 
7
6
  export const getGlobalSchemaTool = defineGlobalTool({
8
7
  access: (args) => {
9
- const permissions = args.permissions?.globals?.[args.globalSlug]
8
+ const permissions = args.permissions?.globals?.[args.slug]
10
9
 
11
10
  return defaultAccess(args) && Boolean(permissions?.update)
12
11
  },
@@ -18,17 +17,18 @@ export const getGlobalSchemaTool = defineGlobalTool({
18
17
  title: 'Get Global Schema',
19
18
  },
20
19
  description: 'Get the input schema for updating a global.',
21
- }).handler(async ({ authorizedMCP, globalSlug, req }) => {
20
+ input: getGlobalSchemaInputSchema,
21
+ }).handler(async ({ slug, authorizedMCP, req }) => {
22
22
  const permissions = authorizedMCP.overrideAccess
23
23
  ? null
24
- : (await getAccessResults({ req })).globals?.[globalSlug]
24
+ : (await getAccessResults({ req })).globals?.[slug]
25
25
 
26
26
  if (!authorizedMCP.overrideAccess && !permissions?.update) {
27
27
  return {
28
28
  content: [
29
29
  {
30
30
  type: 'text',
31
- text: `Error: MCP access to "getGlobalSchema" is not enabled for global "${globalSlug}"`,
31
+ text: `Error: MCP access to "getGlobalSchema" is not enabled for global "${slug}"`,
32
32
  },
33
33
  ],
34
34
  isError: true,
@@ -36,14 +36,14 @@ export const getGlobalSchemaTool = defineGlobalTool({
36
36
  }
37
37
 
38
38
  const inputSchema = getGlobalInputSchema({
39
- globalSlug,
39
+ globalSlug: slug,
40
40
  req,
41
41
  ...(permissions ? { permissions } : {}),
42
42
  })
43
43
 
44
44
  if (!inputSchema) {
45
45
  return {
46
- content: [{ type: 'text', text: `Error: Global "${globalSlug}" not found` }],
46
+ content: [{ type: 'text', text: `Error: Global "${slug}" not found` }],
47
47
  isError: true,
48
48
  }
49
49
  }
@@ -52,11 +52,11 @@ export const getGlobalSchemaTool = defineGlobalTool({
52
52
  content: [
53
53
  {
54
54
  type: 'text',
55
- text: `Schema for global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``,
55
+ text: `Schema for global "${slug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``,
56
56
  },
57
57
  ],
58
58
  structuredContent: {
59
- globalSlug,
59
+ slug,
60
60
  schema: inputSchema,
61
61
  },
62
62
  }
@@ -1,6 +1,4 @@
1
- import type { PopulateType } from 'payload'
2
-
3
- import { z } from 'zod'
1
+ import { restoreGlobalVersionInputSchema } from 'payload'
4
2
 
5
3
  import { defaultAccess } from '../../../defaultAccess.js'
6
4
  import { defineGlobalTool } from '../../../defineTool.js'
@@ -10,8 +8,7 @@ const DEFAULT_DESCRIPTION =
10
8
  'Restore a global from a previous version in any version-enabled global.'
11
9
 
12
10
  export const restoreGlobalVersionTool = defineGlobalTool({
13
- access: (args) =>
14
- defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),
11
+ access: (args) => defaultAccess(args) && Boolean(args.permissions?.globals?.[args.slug]?.update),
15
12
  annotations: {
16
13
  destructiveHint: true,
17
14
  idempotentHint: false,
@@ -20,53 +17,25 @@ export const restoreGlobalVersionTool = defineGlobalTool({
20
17
  title: 'Restore Global Version',
21
18
  },
22
19
  description: DEFAULT_DESCRIPTION,
23
- input: z.object({
24
- id: z.string().describe('The ID of the global version to restore'),
25
- depth: z
26
- .number()
27
- .int()
28
- .min(0)
29
- .max(10)
30
- .describe('How many levels deep to populate relationships in response')
31
- .optional()
32
- .default(0),
33
- fallbackLocale: z
34
- .string()
35
- .describe('Optional: fallback locale code to use when requested locale is not available')
36
- .optional(),
37
- locale: z
38
- .string()
39
- .describe('Optional: locale code to restore in (e.g., "en", "es")')
40
- .optional(),
41
- populate: z
42
- .record(z.string(), z.unknown())
43
- .describe(
44
- 'Optional: control which fields to include from populated relationship or upload documents.',
45
- )
46
- .optional(),
47
- showHiddenFields: z
48
- .boolean()
49
- .describe('Optional: include hidden fields in the restored global response')
50
- .optional(),
51
- }),
52
- }).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
20
+ input: restoreGlobalVersionInputSchema,
21
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
53
22
  const payload = req.payload
54
23
  const logger = getLogger({ payload })
55
- const { id, depth, fallbackLocale, locale, populate, showHiddenFields } = input
24
+ const { id, depth, fallbackLocale, locale, populate, select } = input
56
25
 
57
- logger.info(`Restoring version for global: ${globalSlug} with ID: ${id}`)
26
+ logger.info(`Restoring version for global: ${slug} with ID: ${id}`)
58
27
 
59
28
  try {
60
29
  const result = await payload.restoreGlobalVersion({
61
- id,
62
- slug: globalSlug,
30
+ id: String(id),
31
+ slug,
63
32
  depth,
64
33
  overrideAccess: authorizedMCP.overrideAccess,
65
34
  req,
66
- ...(fallbackLocale ? { fallbackLocale } : {}),
35
+ ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),
67
36
  ...(locale ? { locale } : {}),
68
- ...(populate ? { populate: populate as PopulateType } : {}),
69
- ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
37
+ ...(populate ? { populate } : {}),
38
+ ...(select ? { select } : {}),
70
39
  })
71
40
  const resultObject = result as Record<string, unknown>
72
41
  const restoredGlobal =
@@ -78,19 +47,19 @@ export const restoreGlobalVersionTool = defineGlobalTool({
78
47
  content: [
79
48
  {
80
49
  type: 'text',
81
- text: `Version "${id}" restored successfully for global "${globalSlug}"!\nRestored global:\n\`\`\`json\n${JSON.stringify(restoredGlobal)}\n\`\`\``,
50
+ text: `Version "${id}" restored successfully for global "${slug}"!\nRestored global:\n\`\`\`json\n${JSON.stringify(restoredGlobal)}\n\`\`\``,
82
51
  },
83
52
  ],
84
53
  doc: restoredGlobal,
85
54
  }
86
55
  } catch (error) {
87
56
  const errorMessage = error instanceof Error ? error.message : 'Unknown error'
88
- logger.error(`Error restoring version ${id} for global ${globalSlug}: ${errorMessage}`)
57
+ logger.error(`Error restoring version ${id} for global ${slug}: ${errorMessage}`)
89
58
  return {
90
59
  content: [
91
60
  {
92
61
  type: 'text',
93
- text: `❌ **Error restoring version "${id}" for global "${globalSlug}":** ${errorMessage}`,
62
+ text: `❌ **Error restoring version "${id}" for global "${slug}":** ${errorMessage}`,
94
63
  },
95
64
  ],
96
65
  isError: true,
@@ -1,22 +1,19 @@
1
- import type { SelectType } from 'payload'
2
-
3
- import { z } from 'zod'
1
+ import {
2
+ getGlobalVirtualFieldNames,
3
+ stripVirtualFields,
4
+ transformPointDataToPayload,
5
+ updateGlobalInputSchema,
6
+ } from 'payload'
4
7
 
5
8
  import { defaultAccess } from '../../../defaultAccess.js'
6
9
  import { defineGlobalTool } from '../../../defineTool.js'
7
10
  import { getLogger } from '../../../utils/getLogger.js'
8
- import {
9
- getGlobalVirtualFieldNames,
10
- stripVirtualFields,
11
- } from '../../../utils/getVirtualFieldNames.js'
12
- import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
13
11
  import { validateGlobalData } from '../validateEntityData.js'
14
12
 
15
13
  const DEFAULT_DESCRIPTION = 'Update any Payload global by passing the global slug and data.'
16
14
 
17
15
  export const updateGlobalTool = defineGlobalTool({
18
- access: (args) =>
19
- defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),
16
+ access: (args) => defaultAccess(args) && Boolean(args.permissions?.globals?.[args.slug]?.update),
20
17
  annotations: {
21
18
  destructiveHint: true,
22
19
  idempotentHint: false,
@@ -25,49 +22,30 @@ export const updateGlobalTool = defineGlobalTool({
25
22
  title: 'Update Global',
26
23
  },
27
24
  description: DEFAULT_DESCRIPTION,
28
- input: z.object({
29
- data: z.record(z.string(), z.unknown()).describe('The global fields to update'),
30
- depth: z
31
- .number()
32
- .describe('Optional: Depth of relationships to populate')
33
- .optional()
34
- .default(0),
35
- draft: z
36
- .boolean()
37
- .describe('Optional: Whether to save as draft (default: false)')
38
- .optional()
39
- .default(false),
40
- fallbackLocale: z
41
- .string()
42
- .describe('Optional: fallback locale code to use when requested locale is not available')
43
- .optional(),
44
- locale: z
45
- .string()
46
- .describe(
47
- 'Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields',
48
- )
49
- .optional(),
50
- select: z
51
- .record(z.string(), z.unknown())
52
- .describe(
53
- 'Optional: define exactly which fields you\'d like to return in the response, e.g., {"siteName": true}',
54
- )
55
- .optional(),
56
- }),
57
- }).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
25
+ input: updateGlobalInputSchema,
26
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
58
27
  const payload = req.payload
59
28
  const logger = getLogger({ payload })
60
29
 
61
- const { data, depth, draft, fallbackLocale, locale, select } = input
30
+ const {
31
+ data,
32
+ depth,
33
+ draft,
34
+ fallbackLocale,
35
+ locale,
36
+ overrideLock,
37
+ populate,
38
+ publishAllLocales,
39
+ select,
40
+ unpublishAllLocales,
41
+ } = input
62
42
 
63
- logger.info(
64
- `Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
65
- )
43
+ logger.info(`Updating global: ${slug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`)
66
44
 
67
45
  try {
68
- const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)
46
+ const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, slug)
69
47
  const inputData = stripVirtualFields(data, virtualFieldNames)
70
- const validationError = validateGlobalData({ data: inputData, globalSlug, req })
48
+ const validationError = validateGlobalData({ slug, data: inputData, req })
71
49
 
72
50
  if (validationError) {
73
51
  return validationError
@@ -76,22 +54,26 @@ export const updateGlobalTool = defineGlobalTool({
76
54
  const parsedData = transformPointDataToPayload(inputData)
77
55
 
78
56
  const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {
79
- slug: globalSlug,
57
+ slug,
80
58
  data: parsedData,
81
59
  depth,
82
60
  draft,
83
61
  overrideAccess: authorizedMCP.overrideAccess,
62
+ overrideLock,
63
+ populate,
64
+ publishAllLocales,
84
65
  req,
66
+ unpublishAllLocales,
85
67
  }
86
68
 
87
69
  if (locale) {
88
70
  updateOptions.locale = locale
89
71
  }
90
- if (fallbackLocale) {
72
+ if (fallbackLocale !== undefined) {
91
73
  updateOptions.fallbackLocale = fallbackLocale
92
74
  }
93
75
  if (select) {
94
- updateOptions.select = select as SelectType
76
+ updateOptions.select = select
95
77
  }
96
78
 
97
79
  const result = await payload.updateGlobal(updateOptions)
@@ -100,16 +82,16 @@ export const updateGlobalTool = defineGlobalTool({
100
82
  content: [
101
83
  {
102
84
  type: 'text',
103
- text: `Global "${globalSlug}" updated successfully!\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
85
+ text: `Global "${slug}" updated successfully!\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
104
86
  },
105
87
  ],
106
88
  doc: result as Record<string, unknown>,
107
89
  }
108
90
  } catch (error) {
109
91
  const errorMessage = error instanceof Error ? error.message : 'Unknown error'
110
- logger.error(`Error updating global ${globalSlug}: ${errorMessage}`)
92
+ logger.error(`Error updating global ${slug}: ${errorMessage}`)
111
93
  return {
112
- content: [{ type: 'text', text: `Error updating global "${globalSlug}": ${errorMessage}` }],
94
+ content: [{ type: 'text', text: `Error updating global "${slug}": ${errorMessage}` }],
113
95
  }
114
96
  }
115
97
  })
@@ -1,14 +1,10 @@
1
1
  import type { CollectionSlug, GlobalSlug, PayloadRequest, SanitizedConfig } from 'payload'
2
2
 
3
3
  import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server/validators/cf-worker'
4
+ import { getCollectionInputSchema, getGlobalInputSchema } from 'payload'
4
5
 
5
6
  import type { JsonSchemaType, MCPToolResponse } from '../../types.js'
6
7
 
7
- import {
8
- getCollectionInputSchema,
9
- getGlobalInputSchema,
10
- } from '../../utils/schemaConversion/getEntityInputSchema.js'
11
-
12
8
  /**
13
9
  * Keep the default `shortcircuit: true` - `false` makes validating nested rich text exponentially slow.
14
10
  */
@@ -26,19 +22,20 @@ type EntityValidator = {
26
22
  const validatorCache = new WeakMap<SanitizedConfig, Map<string, EntityValidator>>()
27
23
 
28
24
  export const validateCollectionData = ({
29
- collectionSlug,
25
+ slug,
30
26
  data,
31
27
  partial,
32
28
  req,
33
29
  }: {
34
- collectionSlug: CollectionSlug
35
30
  data: Record<string, unknown>
36
31
  partial?: boolean
37
32
  req: PayloadRequest
33
+ slug: CollectionSlug
38
34
  }): MCPToolResponse | null =>
39
35
  validateData({
40
- slug: collectionSlug,
41
- buildSchema: () => getCollectionInputSchema({ collectionSlug, req }),
36
+ slug,
37
+ buildSchema: () =>
38
+ getCollectionInputSchema({ collectionSlug: slug, req }) as JsonSchemaType | null,
42
39
  data,
43
40
  entity: 'collection',
44
41
  partial,
@@ -46,17 +43,17 @@ export const validateCollectionData = ({
46
43
  })
47
44
 
48
45
  export const validateGlobalData = ({
46
+ slug,
49
47
  data,
50
- globalSlug,
51
48
  req,
52
49
  }: {
53
50
  data: Record<string, unknown>
54
- globalSlug: GlobalSlug
55
51
  req: PayloadRequest
52
+ slug: GlobalSlug
56
53
  }): MCPToolResponse | null =>
57
54
  validateData({
58
- slug: globalSlug,
59
- buildSchema: () => getGlobalInputSchema({ globalSlug, req }),
55
+ slug,
56
+ buildSchema: () => getGlobalInputSchema({ globalSlug: slug, req }) as JsonSchemaType | null,
60
57
  data,
61
58
  entity: 'global',
62
59
  partial: true,