@payloadcms/plugin-mcp 4.0.0-internal.fa183d3 → 4.0.0-internal.fec2230

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 (171) 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 +104 -63
  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 +44 -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 +31 -37
  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 +52 -64
  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 +27 -45
  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/getCollectionSchemaTool.d.ts.map +1 -1
  45. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +15 -14
  46. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  47. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
  48. package/dist/mcp/builtin/collections/restoreVersionTool.js +14 -26
  49. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  50. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  51. package/dist/mcp/builtin/collections/updateTool.js +58 -90
  52. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  53. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  54. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  55. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  56. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  57. package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
  58. package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
  59. package/dist/mcp/builtin/formatEntityError.js +55 -0
  60. package/dist/mcp/builtin/formatEntityError.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 +27 -36
  84. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  85. package/dist/mcp/builtinTools.d.ts +6 -0
  86. package/dist/mcp/builtinTools.d.ts.map +1 -1
  87. package/dist/mcp/builtinTools.js +9 -3
  88. package/dist/mcp/builtinTools.js.map +1 -1
  89. package/dist/mcp/sanitizeMCPConfig.js +4 -1
  90. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  91. package/dist/stdio.d.ts.map +1 -1
  92. package/dist/stdio.js +2 -1
  93. package/dist/stdio.js.map +1 -1
  94. package/dist/types.d.ts +4 -4
  95. package/dist/types.d.ts.map +1 -1
  96. package/dist/types.js.map +1 -1
  97. package/package.json +5 -7
  98. package/src/endpoint/access.ts +2 -3
  99. package/src/mcp/buildMcpServer.ts +39 -29
  100. package/src/mcp/builtin/collections/authTools.ts +77 -69
  101. package/src/mcp/builtin/collections/countTool.ts +9 -21
  102. package/src/mcp/builtin/collections/countVersionsTool.ts +9 -18
  103. package/src/mcp/builtin/collections/createTool.ts +110 -86
  104. package/src/mcp/builtin/collections/deleteTool.ts +36 -64
  105. package/src/mcp/builtin/collections/duplicateTool.ts +35 -85
  106. package/src/mcp/builtin/collections/fileInput.spec.ts +20 -6
  107. package/src/mcp/builtin/collections/fileInput.ts +64 -76
  108. package/src/mcp/builtin/collections/findDistinctTool.ts +11 -63
  109. package/src/mcp/builtin/collections/findTool.ts +23 -105
  110. package/src/mcp/builtin/collections/findVersionByIDTool.ts +15 -58
  111. package/src/mcp/builtin/collections/findVersionsTool.ts +14 -85
  112. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +16 -12
  113. package/src/mcp/builtin/collections/restoreVersionTool.ts +14 -56
  114. package/src/mcp/builtin/collections/updateTool.ts +57 -111
  115. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  116. package/src/mcp/builtin/formatEntityError.ts +77 -0
  117. package/src/mcp/builtin/getConfigInfoTool.ts +2 -1
  118. package/src/mcp/builtin/globals/countVersionsTool.ts +9 -17
  119. package/src/mcp/builtin/globals/findTool.ts +12 -51
  120. package/src/mcp/builtin/globals/findVersionByIDTool.ts +13 -52
  121. package/src/mcp/builtin/globals/findVersionsTool.ts +14 -92
  122. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +10 -10
  123. package/src/mcp/builtin/globals/restoreVersionTool.ts +14 -45
  124. package/src/mcp/builtin/globals/updateTool.ts +37 -60
  125. package/src/mcp/builtinTools.ts +9 -2
  126. package/src/mcp/sanitizeMCPConfig.ts +4 -1
  127. package/src/stdio.ts +2 -1
  128. package/src/types.ts +4 -4
  129. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
  130. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
  131. package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
  132. package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
  133. package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
  134. package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
  135. package/dist/mcp/builtin/validateEntityData.js +0 -82
  136. package/dist/mcp/builtin/validateEntityData.js.map +0 -1
  137. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  138. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  139. package/dist/utils/getVirtualFieldNames.js +0 -35
  140. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  141. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +0 -28
  142. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +0 -1
  143. package/dist/utils/schemaConversion/filterFieldsByAccess.js +0 -71
  144. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +0 -1
  145. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -13
  146. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
  147. package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -66
  148. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
  149. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -10
  150. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
  151. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -384
  152. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
  153. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -133
  154. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
  155. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  156. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  157. package/dist/utils/transformPointDataToPayload.js +0 -28
  158. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  159. package/dist/utils/whereSchema.d.ts +0 -9
  160. package/dist/utils/whereSchema.d.ts.map +0 -1
  161. package/dist/utils/whereSchema.js +0 -13
  162. package/dist/utils/whereSchema.js.map +0 -1
  163. package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
  164. package/src/mcp/builtin/validateEntityData.ts +0 -132
  165. package/src/utils/getVirtualFieldNames.ts +0 -53
  166. package/src/utils/schemaConversion/filterFieldsByAccess.ts +0 -123
  167. package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -96
  168. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -96
  169. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -432
  170. package/src/utils/transformPointDataToPayload.ts +0 -40
  171. package/src/utils/whereSchema.ts +0 -24
@@ -0,0 +1,64 @@
1
+ import { strictObject, z } from 'payload'
2
+ import { getUploadInstructions as getPayloadUploadInstructions } from 'payload/internal'
3
+
4
+ import { defaultAccess } from '../../../defaultAccess.js'
5
+ import { defineCollectionTool } from '../../../defineTool.js'
6
+
7
+ export const getUploadInstructionsTool = defineCollectionTool({
8
+ access: (args) =>
9
+ defaultAccess(args) &&
10
+ Boolean(
11
+ args.permissions?.collections?.[args.slug]?.create ||
12
+ args.permissions?.collections?.[args.slug]?.update,
13
+ ),
14
+ annotations: {
15
+ destructiveHint: false,
16
+ idempotentHint: false,
17
+ openWorldHint: true,
18
+ readOnlyHint: false,
19
+ title: 'Get Upload Instructions',
20
+ },
21
+ description:
22
+ 'Prepare uploads for createDocuments or updateDocument. This does not upload bytes; finish the returned action before use.',
23
+ input: strictObject({
24
+ docPrefix: z.optional(z.string()).check(z.describe('Document folder or prefix.')),
25
+ filename: z.string().check(z.describe('The original file name.')),
26
+ filesize: z.int().check(z.nonnegative(), z.describe('The file size in bytes.')),
27
+ mimeType: z.string().check(z.describe('The file MIME type.')),
28
+ }),
29
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
30
+ try {
31
+ const instructions = await getPayloadUploadInstructions({
32
+ ...input,
33
+ collectionSlug: slug,
34
+ overrideAccess: authorizedMCP.overrideAccess,
35
+ req,
36
+ })
37
+
38
+ const nextStep =
39
+ instructions.type === 'http'
40
+ ? 'Upload bytes with instructions.request. After success, pass { source: "uploadReference", file: instructions.file }.'
41
+ : `Call "${instructions.name}" with file and data. After success, pass { source: "uploadReference", file: instructions.file }.`
42
+
43
+ return {
44
+ content: [
45
+ {
46
+ type: 'text',
47
+ text: `Upload instructions for collection "${slug}":\n\`\`\`json\n${JSON.stringify(instructions)}\n\`\`\`\n${nextStep}`,
48
+ },
49
+ ],
50
+ structuredContent: { instructions },
51
+ }
52
+ } catch (error) {
53
+ const message = error instanceof Error ? error.message : 'Unknown error'
54
+ return {
55
+ content: [
56
+ {
57
+ type: 'text',
58
+ text: `Error getting upload instructions for collection "${slug}": ${message}`,
59
+ },
60
+ ],
61
+ isError: true,
62
+ }
63
+ }
64
+ })
@@ -0,0 +1,77 @@
1
+ import type { CollectionSlug, GlobalSlug, PayloadRequest } from 'payload'
2
+
3
+ import { getCollectionInputSchema, getGlobalInputSchema, ValidationError } from 'payload'
4
+
5
+ import type { MCPToolResponse } from '../../types.js'
6
+
7
+ export const formatEntityError = ({
8
+ slug,
9
+ action,
10
+ entity,
11
+ error,
12
+ req,
13
+ }:
14
+ | {
15
+ action: 'creating' | 'duplicating' | 'updating'
16
+ entity: 'collection'
17
+ error: unknown
18
+ req: PayloadRequest
19
+ slug: CollectionSlug
20
+ }
21
+ | {
22
+ action: 'updating'
23
+ entity: 'global'
24
+ error: unknown
25
+ req: PayloadRequest
26
+ slug: GlobalSlug
27
+ }): MCPToolResponse => {
28
+ const message = error instanceof Error ? error.message : 'Unknown error'
29
+ const target = entity === 'collection' ? `document in collection "${slug}"` : `global "${slug}"`
30
+
31
+ if (!isValidationError(error, message)) {
32
+ return {
33
+ content: [{ type: 'text', text: `Error ${action} ${target}: ${message}` }],
34
+ isError: true,
35
+ }
36
+ }
37
+
38
+ const schema =
39
+ entity === 'collection'
40
+ ? getCollectionInputSchema({ collectionSlug: slug, req })
41
+ : getGlobalInputSchema({ globalSlug: slug, req })
42
+ const errors = error instanceof ValidationError ? error.data.errors : [{ message }]
43
+ const validationMessage = errors
44
+ .map((issue) => `${'path' in issue ? `${issue.path}: ` : ''}${issue.message}`)
45
+ .join('\n')
46
+ const schemaText = schema
47
+ ? `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\``
48
+ : ''
49
+
50
+ return {
51
+ content: [
52
+ { type: 'text', text: `Error ${action} ${target}: ${validationMessage}${schemaText}` },
53
+ ],
54
+ isError: true,
55
+ ...(schema
56
+ ? {
57
+ structuredContent: {
58
+ slug,
59
+ errors,
60
+ schema,
61
+ },
62
+ }
63
+ : {}),
64
+ }
65
+ }
66
+
67
+ const isValidationError = (error: unknown, message: string): boolean => {
68
+ if (error instanceof ValidationError) {
69
+ return true
70
+ }
71
+
72
+ const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined
73
+
74
+ return (
75
+ name === 'CastError' || message.includes('Cast to ') || message.includes('validation failed')
76
+ )
77
+ }
@@ -1,4 +1,4 @@
1
- import { getAccessResults, isEntityHidden } from 'payload'
1
+ import { getAccessResults, getConfigInfoInputSchema, isEntityHidden } from 'payload'
2
2
 
3
3
  import { defineTool } from '../../defineTool.js'
4
4
 
@@ -11,6 +11,7 @@ export const getConfigInfoTool = defineTool({
11
11
  title: 'Config Info',
12
12
  },
13
13
  description: 'List the Payload collection and global slugs visible to this MCP client.',
14
+ input: getConfigInfoInputSchema,
14
15
  }).handler(async ({ authorizedMCP, req }) => {
15
16
  const user = req.user
16
17
  const permissions = authorizedMCP.overrideAccess ? null : await getAccessResults({ req })
@@ -1,16 +1,15 @@
1
- import { z } from 'zod'
1
+ import { countGlobalVersionsInputSchema } from 'payload'
2
2
 
3
3
  import { defaultAccess } from '../../../defaultAccess.js'
4
4
  import { defineGlobalTool } from '../../../defineTool.js'
5
5
  import { getLogger } from '../../../utils/getLogger.js'
6
- import { whereSchema } from '../../../utils/whereSchema.js'
7
6
 
8
7
  const DEFAULT_DESCRIPTION =
9
8
  'Count global versions in any version-enabled global by passing the global slug and optional where clause.'
10
9
 
11
10
  export const countGlobalVersionsTool = defineGlobalTool({
12
11
  access: (args) =>
13
- defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
12
+ defaultAccess(args) && Boolean(args.permissions?.globals?.[args.slug]?.readVersions),
14
13
  annotations: {
15
14
  destructiveHint: false,
16
15
  idempotentHint: true,
@@ -19,24 +18,17 @@ export const countGlobalVersionsTool = defineGlobalTool({
19
18
  title: 'Count Global Versions',
20
19
  },
21
20
  description: DEFAULT_DESCRIPTION,
22
- input: z.object({
23
- locale: z.string().describe('Optional: locale code to count versions in').optional(),
24
- where: whereSchema
25
- .describe(
26
- 'Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.siteName":{"contains":"test"}}',
27
- )
28
- .optional(),
29
- }),
30
- }).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
21
+ input: countGlobalVersionsInputSchema,
22
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
31
23
  const payload = req.payload
32
24
  const logger = getLogger({ payload })
33
25
  const { locale, where } = input
34
26
 
35
- logger.info(`Counting versions for global: ${globalSlug}`)
27
+ logger.info(`Counting versions for global: ${slug}`)
36
28
 
37
29
  try {
38
30
  const result = await payload.countGlobalVersions({
39
- global: globalSlug,
31
+ global: slug,
40
32
  overrideAccess: authorizedMCP.overrideAccess,
41
33
  req,
42
34
  ...(locale ? { locale } : {}),
@@ -47,19 +39,19 @@ export const countGlobalVersionsTool = defineGlobalTool({
47
39
  content: [
48
40
  {
49
41
  type: 'text',
50
- text: `Global "${globalSlug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
42
+ text: `Global "${slug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
51
43
  },
52
44
  ],
53
45
  doc: result,
54
46
  }
55
47
  } catch (error) {
56
48
  const errorMessage = error instanceof Error ? error.message : 'Unknown error'
57
- logger.error(`Error counting versions for global ${globalSlug}: ${errorMessage}`)
49
+ logger.error(`Error counting versions for global ${slug}: ${errorMessage}`)
58
50
  return {
59
51
  content: [
60
52
  {
61
53
  type: 'text',
62
- text: `❌ **Error counting versions for global "${globalSlug}":** ${errorMessage}`,
54
+ text: `❌ **Error counting versions for global "${slug}":** ${errorMessage}`,
63
55
  },
64
56
  ],
65
57
  isError: true,
@@ -1,6 +1,4 @@
1
- import type { PopulateType, SelectType } from 'payload'
2
-
3
- import { z } from 'zod'
1
+ import { findGlobalInputSchema } from 'payload'
4
2
 
5
3
  import { defaultAccess } from '../../../defaultAccess.js'
6
4
  import { defineGlobalTool } from '../../../defineTool.js'
@@ -9,8 +7,7 @@ import { getLogger } from '../../../utils/getLogger.js'
9
7
  const DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.'
10
8
 
11
9
  export const findGlobalTool = defineGlobalTool({
12
- access: (args) =>
13
- defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.read),
10
+ access: (args) => defaultAccess(args) && Boolean(args.permissions?.globals?.[args.slug]?.read),
14
11
  annotations: {
15
12
  destructiveHint: false,
16
13
  idempotentHint: true,
@@ -19,51 +16,18 @@ export const findGlobalTool = defineGlobalTool({
19
16
  title: 'Find Global',
20
17
  },
21
18
  description: DEFAULT_DESCRIPTION,
22
- input: z.object({
23
- depth: z
24
- .number()
25
- .int()
26
- .min(0)
27
- .max(10)
28
- .describe('Depth of population for relationships')
29
- .optional()
30
- .default(0),
31
- fallbackLocale: z
32
- .string()
33
- .describe('Optional: fallback locale code to use when requested locale is not available')
34
- .optional(),
35
- locale: z
36
- .string()
37
- .describe(
38
- 'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
39
- )
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
- select: z
48
- .record(z.string(), z.unknown())
49
- .describe(
50
- 'Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}',
51
- )
52
- .optional(),
53
- }),
54
- }).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
19
+ input: findGlobalInputSchema,
20
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
55
21
  const payload = req.payload
56
22
  const logger = getLogger({ payload })
57
23
 
58
24
  const { depth, fallbackLocale, locale, populate, select } = input
59
25
 
60
- logger.info(
61
- `Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,
62
- )
26
+ logger.info(`Reading global: ${slug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`)
63
27
 
64
28
  try {
65
29
  const findOptions: Parameters<typeof payload.findGlobal>[0] = {
66
- slug: globalSlug,
30
+ slug,
67
31
  depth,
68
32
  overrideAccess: authorizedMCP.overrideAccess,
69
33
  req,
@@ -72,34 +36,31 @@ export const findGlobalTool = defineGlobalTool({
72
36
  if (locale) {
73
37
  findOptions.locale = locale
74
38
  }
75
- if (fallbackLocale) {
39
+ if (fallbackLocale !== undefined) {
76
40
  findOptions.fallbackLocale = fallbackLocale
77
41
  }
78
42
  if (select) {
79
- findOptions.select = select as SelectType
43
+ findOptions.select = select
80
44
  }
81
45
  if (populate) {
82
- findOptions.populate = populate as PopulateType
46
+ findOptions.populate = populate
83
47
  }
84
-
85
48
  const result = await payload.findGlobal(findOptions)
86
49
 
87
50
  return {
88
51
  content: [
89
52
  {
90
53
  type: 'text',
91
- text: `Global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
54
+ text: `Global "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
92
55
  },
93
56
  ],
94
57
  doc: result as Record<string, unknown>,
95
58
  }
96
59
  } catch (error) {
97
60
  const errorMessage = error instanceof Error ? error.message : 'Unknown error'
98
- logger.error(`Error reading global ${globalSlug}: ${errorMessage}`)
61
+ logger.error(`Error reading global ${slug}: ${errorMessage}`)
99
62
  return {
100
- content: [
101
- { type: 'text', text: `❌ **Error reading global "${globalSlug}":** ${errorMessage}` },
102
- ],
63
+ content: [{ type: 'text', text: `❌ **Error reading global "${slug}":** ${errorMessage}` }],
103
64
  }
104
65
  }
105
66
  })
@@ -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
  }