@payloadcms/plugin-mcp 4.0.0-internal.40de3ec → 4.0.0-internal.41055b1

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 (247) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +15 -6
  3. package/dist/bin/index.d.ts +2 -0
  4. package/dist/bin/index.d.ts.map +1 -0
  5. package/dist/bin/index.js +12 -0
  6. package/dist/bin/index.js.map +1 -0
  7. package/dist/bin/initializeViteHMR.d.ts +8 -0
  8. package/dist/bin/initializeViteHMR.d.ts.map +1 -0
  9. package/dist/bin/initializeViteHMR.js +75 -0
  10. package/dist/bin/initializeViteHMR.js.map +1 -0
  11. package/dist/bin/viteConfigBoundary.d.ts +6 -0
  12. package/dist/bin/viteConfigBoundary.d.ts.map +1 -0
  13. package/dist/bin/viteConfigBoundary.js +25 -0
  14. package/dist/bin/viteConfigBoundary.js.map +1 -0
  15. package/dist/defaultAccess.d.ts +3 -0
  16. package/dist/defaultAccess.d.ts.map +1 -0
  17. package/dist/defaultAccess.js +3 -0
  18. package/dist/defaultAccess.js.map +1 -0
  19. package/dist/endpoint/access.d.ts +12 -5
  20. package/dist/endpoint/access.d.ts.map +1 -1
  21. package/dist/endpoint/access.js +75 -88
  22. package/dist/endpoint/access.js.map +1 -1
  23. package/dist/endpoint/index.d.ts +1 -1
  24. package/dist/endpoint/index.d.ts.map +1 -1
  25. package/dist/endpoint/index.js +68 -17
  26. package/dist/endpoint/index.js.map +1 -1
  27. package/dist/exports/client.d.ts +1 -1
  28. package/dist/exports/client.d.ts.map +1 -1
  29. package/dist/exports/client.js +1 -1
  30. package/dist/exports/client.js.map +1 -1
  31. package/dist/exports/internal.d.ts +2 -0
  32. package/dist/exports/internal.d.ts.map +1 -0
  33. package/dist/exports/internal.js +3 -0
  34. package/dist/exports/internal.js.map +1 -0
  35. package/dist/index.d.ts +2 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +15 -20
  38. package/dist/index.js.map +1 -1
  39. package/dist/mcp/buildMcpServer.d.ts +4 -4
  40. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  41. package/dist/mcp/buildMcpServer.js +133 -80
  42. package/dist/mcp/buildMcpServer.js.map +1 -1
  43. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  44. package/dist/mcp/builtin/collections/authTools.js +44 -6
  45. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  46. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  47. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  48. package/dist/mcp/builtin/collections/countTool.js +68 -0
  49. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  50. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  51. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  52. package/dist/mcp/builtin/collections/countVersionsTool.js +64 -0
  53. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  54. package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
  55. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  56. package/dist/mcp/builtin/collections/createTool.js +39 -44
  57. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  58. package/dist/mcp/builtin/collections/deleteTool.d.ts +1 -1
  59. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  60. package/dist/mcp/builtin/collections/deleteTool.js +15 -22
  61. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  62. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  63. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  64. package/dist/mcp/builtin/collections/duplicateTool.js +96 -0
  65. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  66. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  67. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  68. package/dist/mcp/builtin/collections/findDistinctTool.js +92 -0
  69. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  70. package/dist/mcp/builtin/collections/findTool.d.ts +1 -1
  71. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  72. package/dist/mcp/builtin/collections/findTool.js +52 -47
  73. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  74. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  75. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  76. package/dist/mcp/builtin/collections/findVersionByIDTool.js +83 -0
  77. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  78. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  79. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  80. package/dist/mcp/builtin/collections/findVersionsTool.js +98 -0
  81. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  82. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
  83. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
  84. package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
  85. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
  86. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
  87. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
  88. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +65 -0
  89. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
  90. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  91. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  92. package/dist/mcp/builtin/collections/restoreVersionTool.js +81 -0
  93. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  94. package/dist/mcp/builtin/collections/updateTool.d.ts +1 -1
  95. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  96. package/dist/mcp/builtin/collections/updateTool.js +96 -89
  97. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  98. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  99. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  100. package/dist/mcp/builtin/getConfigInfoTool.js +68 -0
  101. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  102. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  103. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  104. package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
  105. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  106. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  107. package/dist/mcp/builtin/globals/findTool.js +20 -23
  108. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  109. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  110. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  111. package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
  112. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  113. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  114. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  115. package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
  116. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  117. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  118. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  119. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +65 -0
  120. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  121. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  122. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  123. package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
  124. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  125. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  126. package/dist/mcp/builtin/globals/updateTool.js +33 -42
  127. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  128. package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
  129. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
  130. package/dist/mcp/builtin/validateEntityData.js +82 -0
  131. package/dist/mcp/builtin/validateEntityData.js.map +1 -0
  132. package/dist/mcp/builtinTools.d.ts +144 -19
  133. package/dist/mcp/builtinTools.d.ts.map +1 -1
  134. package/dist/mcp/builtinTools.js +119 -20
  135. package/dist/mcp/builtinTools.js.map +1 -1
  136. package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
  137. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  138. package/dist/mcp/sanitizeMCPConfig.js +121 -58
  139. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  140. package/dist/stdio.d.ts +5 -4
  141. package/dist/stdio.d.ts.map +1 -1
  142. package/dist/stdio.js +88 -49
  143. package/dist/stdio.js.map +1 -1
  144. package/dist/types.d.ts +112 -110
  145. package/dist/types.d.ts.map +1 -1
  146. package/dist/types.js +2 -4
  147. package/dist/types.js.map +1 -1
  148. package/dist/utils/getPluginConfig.d.ts +1 -1
  149. package/dist/utils/getPluginConfig.js +1 -1
  150. package/dist/utils/getPluginConfig.js.map +1 -1
  151. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
  152. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  153. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  154. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  155. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +13 -0
  156. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
  157. package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
  158. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
  159. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +5 -10
  160. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
  161. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +15 -95
  162. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -1
  163. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +15 -40
  164. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
  165. package/dist/utils/whereSchema.d.ts +9 -0
  166. package/dist/utils/whereSchema.d.ts.map +1 -0
  167. package/dist/utils/whereSchema.js +13 -0
  168. package/dist/utils/whereSchema.js.map +1 -0
  169. package/package.json +25 -17
  170. package/src/bin/index.ts +16 -0
  171. package/src/bin/initializeViteHMR.ts +76 -0
  172. package/src/bin/viteConfigBoundary.ts +39 -0
  173. package/src/defaultAccess.ts +3 -0
  174. package/src/endpoint/access.ts +81 -101
  175. package/src/endpoint/index.ts +58 -16
  176. package/src/exports/client.ts +2 -1
  177. package/src/exports/internal.ts +1 -0
  178. package/src/index.ts +12 -20
  179. package/src/mcp/buildMcpServer.ts +170 -115
  180. package/src/mcp/builtin/collections/authTools.ts +45 -9
  181. package/src/mcp/builtin/collections/countTool.ts +73 -0
  182. package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
  183. package/src/mcp/builtin/collections/createTool.ts +62 -61
  184. package/src/mcp/builtin/collections/deleteTool.ts +20 -18
  185. package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
  186. package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
  187. package/src/mcp/builtin/collections/findTool.ts +66 -37
  188. package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
  189. package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
  190. package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
  191. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +63 -0
  192. package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
  193. package/src/mcp/builtin/collections/updateTool.ts +127 -112
  194. package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
  195. package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
  196. package/src/mcp/builtin/globals/findTool.ts +28 -19
  197. package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
  198. package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
  199. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
  200. package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
  201. package/src/mcp/builtin/globals/updateTool.ts +52 -57
  202. package/src/mcp/builtin/validateEntityData.ts +132 -0
  203. package/src/mcp/builtinTools.ts +111 -41
  204. package/src/mcp/sanitizeMCPConfig.ts +117 -78
  205. package/src/stdio.ts +82 -48
  206. package/src/types.ts +128 -115
  207. package/src/utils/getPluginConfig.ts +1 -1
  208. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  209. package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
  210. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +12 -19
  211. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +17 -114
  212. package/src/utils/whereSchema.ts +24 -0
  213. package/dist/@types/assets.d.js +0 -2
  214. package/dist/@types/assets.d.js.map +0 -1
  215. package/dist/collection/getAccessField.d.ts +0 -12
  216. package/dist/collection/getAccessField.d.ts.map +0 -1
  217. package/dist/collection/getAccessField.js +0 -57
  218. package/dist/collection/getAccessField.js.map +0 -1
  219. package/dist/collection/index.d.ts +0 -6
  220. package/dist/collection/index.d.ts.map +0 -1
  221. package/dist/collection/index.js +0 -60
  222. package/dist/collection/index.js.map +0 -1
  223. package/dist/components/AccessField/index.client.d.ts +0 -10
  224. package/dist/components/AccessField/index.client.d.ts.map +0 -1
  225. package/dist/components/AccessField/index.client.js +0 -305
  226. package/dist/components/AccessField/index.client.js.map +0 -1
  227. package/dist/components/AccessField/index.css +0 -93
  228. package/dist/utils/localAPIDefaults.d.ts +0 -20
  229. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  230. package/dist/utils/localAPIDefaults.js +0 -19
  231. package/dist/utils/localAPIDefaults.js.map +0 -1
  232. package/dist/utils/schemaConversion/buildToolInput.d.ts +0 -29
  233. package/dist/utils/schemaConversion/buildToolInput.d.ts.map +0 -1
  234. package/dist/utils/schemaConversion/buildToolInput.js +0 -51
  235. package/dist/utils/schemaConversion/buildToolInput.js.map +0 -1
  236. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  237. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  238. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  239. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  240. package/src/@types/assets.d.ts +0 -3
  241. package/src/collection/getAccessField.ts +0 -64
  242. package/src/collection/index.ts +0 -64
  243. package/src/components/AccessField/index.client.tsx +0 -344
  244. package/src/components/AccessField/index.css +0 -93
  245. package/src/utils/localAPIDefaults.ts +0 -22
  246. package/src/utils/schemaConversion/buildToolInput.ts +0 -68
  247. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
@@ -0,0 +1,123 @@
1
+ import type {
2
+ FlattenedBlock,
3
+ FlattenedField,
4
+ Operation,
5
+ SanitizedDocumentPermissions,
6
+ SanitizedFieldsPermissions,
7
+ } from 'payload'
8
+
9
+ type FieldOperation = Exclude<Operation, 'delete'>
10
+ type AllowedFieldOperations = Record<FieldOperation, boolean>
11
+
12
+ /**
13
+ * Filters fields using the access results in `permissions`. `shouldExcludeField` receives the
14
+ * operations allowed by the entity, field, and its parents and decides whether to remove the
15
+ * field.
16
+ *
17
+ * Arrays, groups, named tabs, and blocks are filtered recursively. Rows and unnamed tabs are
18
+ * flattened by Payload, so their children are filtered at the containing level.
19
+ *
20
+ * @example Include fields writable through any collection operation the user can perform.
21
+ * ```ts
22
+ * filterFieldsByAccess({
23
+ * fields,
24
+ * permissions: collectionPermissions,
25
+ * shouldExcludeField: ({ create, update }) => !create && !update,
26
+ * })
27
+ * ```
28
+ */
29
+ export const filterFieldsByAccess = ({
30
+ blocks,
31
+ fields,
32
+ permissions,
33
+ shouldExcludeField,
34
+ }: {
35
+ blocks?: FlattenedBlock[]
36
+ fields: FlattenedField[]
37
+ permissions: SanitizedDocumentPermissions
38
+ shouldExcludeField: (allowedOperations: AllowedFieldOperations) => boolean
39
+ }): FlattenedField[] => {
40
+ const filterFields = (
41
+ nestedFields: FlattenedField[],
42
+ nestedPermissions: SanitizedFieldsPermissions | undefined,
43
+ parentAllowedOperations: AllowedFieldOperations,
44
+ ): FlattenedField[] => {
45
+ const accessibleFields: FlattenedField[] = []
46
+
47
+ for (const field of nestedFields) {
48
+ const fieldPermissions = nestedPermissions === true ? true : nestedPermissions?.[field.name]
49
+ const isOperationAllowed = (operation: FieldOperation): boolean =>
50
+ parentAllowedOperations[operation] &&
51
+ (fieldPermissions === true || fieldPermissions?.[operation] === true)
52
+ const allowedOperations: AllowedFieldOperations = {
53
+ create: isOperationAllowed('create'),
54
+ read: isOperationAllowed('read'),
55
+ update: isOperationAllowed('update'),
56
+ }
57
+
58
+ if (shouldExcludeField(allowedOperations)) {
59
+ continue
60
+ }
61
+
62
+ if (field.type === 'blocks') {
63
+ const accessibleBlocks: (FlattenedBlock | string)[] = []
64
+
65
+ for (const blockOrReference of field.blocks) {
66
+ const block =
67
+ typeof blockOrReference === 'string'
68
+ ? blocks?.find(({ slug }) => slug === blockOrReference)
69
+ : blockOrReference
70
+
71
+ if (!block) {
72
+ continue
73
+ }
74
+
75
+ const blockPermissions =
76
+ fieldPermissions === true
77
+ ? true
78
+ : fieldPermissions?.blocks === true
79
+ ? true
80
+ : fieldPermissions?.blocks?.[block.slug]
81
+
82
+ accessibleBlocks.push({
83
+ ...block,
84
+ flattenedFields: filterFields(
85
+ block.flattenedFields,
86
+ blockPermissions === true ? true : blockPermissions?.fields,
87
+ allowedOperations,
88
+ ),
89
+ })
90
+ }
91
+
92
+ if (accessibleBlocks.length === 0) {
93
+ continue
94
+ }
95
+
96
+ accessibleFields.push({ ...field, blocks: accessibleBlocks })
97
+ continue
98
+ }
99
+
100
+ if (field.type === 'array' || field.type === 'group' || field.type === 'tab') {
101
+ accessibleFields.push({
102
+ ...field,
103
+ flattenedFields: filterFields(
104
+ field.flattenedFields,
105
+ fieldPermissions === true ? true : fieldPermissions?.fields,
106
+ allowedOperations,
107
+ ),
108
+ })
109
+ continue
110
+ }
111
+
112
+ accessibleFields.push(field)
113
+ }
114
+
115
+ return accessibleFields
116
+ }
117
+
118
+ return filterFields(fields, permissions.fields, {
119
+ create: 'create' in permissions && permissions.create === true,
120
+ read: permissions.read === true,
121
+ update: permissions.update === true,
122
+ })
123
+ }
@@ -0,0 +1,96 @@
1
+ import {
2
+ type CollectionSlug,
3
+ entityToStandaloneJSONSchema,
4
+ type FlattenedField,
5
+ type GlobalSlug,
6
+ type PayloadRequest,
7
+ type SanitizedCollectionConfig,
8
+ type SanitizedCollectionPermission,
9
+ type SanitizedGlobalConfig,
10
+ type SanitizedGlobalPermission,
11
+ } from 'payload'
12
+
13
+ import type { JsonSchemaType } from '../../types.js'
14
+
15
+ import { filterFieldsByAccess } from './filterFieldsByAccess.js'
16
+ import { sanitizeEntitySchema } from './sanitizeEntitySchema.js'
17
+
18
+ export const getCollectionInputSchema = ({
19
+ collectionSlug,
20
+ permissions,
21
+ req,
22
+ }: {
23
+ collectionSlug: CollectionSlug
24
+ permissions?: SanitizedCollectionPermission
25
+ req: PayloadRequest
26
+ }): JsonSchemaType | null => {
27
+ const collection = req.payload.collections[collectionSlug]?.config
28
+
29
+ if (!collection) {
30
+ return null
31
+ }
32
+
33
+ if (!permissions) {
34
+ return buildEntityInputSchema({ entity: collection, req })
35
+ }
36
+
37
+ const fieldsAllowedByAccess = filterFieldsByAccess({
38
+ blocks: req.payload.config.blocks,
39
+ fields: collection.flattenedFields,
40
+ permissions,
41
+ shouldExcludeField: ({ create, update }) => !create && !update,
42
+ })
43
+
44
+ return buildEntityInputSchema({ entity: collection, fields: fieldsAllowedByAccess, req })
45
+ }
46
+
47
+ export const getGlobalInputSchema = ({
48
+ globalSlug,
49
+ permissions,
50
+ req,
51
+ }: {
52
+ globalSlug: GlobalSlug
53
+ permissions?: SanitizedGlobalPermission
54
+ req: PayloadRequest
55
+ }): JsonSchemaType | null => {
56
+ const global = req.payload.config.globals.find((globalConfig) => globalConfig.slug === globalSlug)
57
+
58
+ if (!global) {
59
+ return null
60
+ }
61
+
62
+ if (!permissions) {
63
+ return buildEntityInputSchema({ entity: global, req })
64
+ }
65
+
66
+ const fieldsAllowedByAccess = filterFieldsByAccess({
67
+ blocks: req.payload.config.blocks,
68
+ fields: global.flattenedFields,
69
+ permissions,
70
+ shouldExcludeField: ({ create, update }) => !create && !update,
71
+ })
72
+
73
+ return buildEntityInputSchema({ entity: global, fields: fieldsAllowedByAccess, req })
74
+ }
75
+
76
+ const buildEntityInputSchema = ({
77
+ entity,
78
+ fields = entity.flattenedFields,
79
+ req,
80
+ }: {
81
+ entity: SanitizedCollectionConfig | SanitizedGlobalConfig
82
+ fields?: FlattenedField[]
83
+ req: PayloadRequest
84
+ }): JsonSchemaType => {
85
+ // The core schema generator reads flattenedFields from the entity and has no fields argument.
86
+ const entityForSchema = { ...entity, flattenedFields: fields }
87
+ const schema = entityToStandaloneJSONSchema({
88
+ config: req.payload.config,
89
+ defaultIDType: req.payload.db.defaultIDType,
90
+ entity: entityForSchema,
91
+ i18n: req.i18n,
92
+ variant: 'input',
93
+ }) as unknown as JsonSchemaType
94
+
95
+ return sanitizeEntitySchema(schema)
96
+ }
@@ -5,10 +5,11 @@ import type { JsonSchemaType } from '../../types.js'
5
5
  import { sanitizeEntitySchema } from './sanitizeEntitySchema.js'
6
6
 
7
7
  describe('sanitizeEntitySchema', () => {
8
- it('keeps a Lexical node union strict (oneOf) while simplifying relationship values to IDs', () => {
9
- // Shaped like the schema the MCP server prepares for a collection with a Lexical richText field:
10
- // a `$defs` node union (a `oneOf` of node shapes) where a relationship node's `value` is either
11
- // an ID or a `$ref` to the populated related collection.
8
+ it('renames the Lexical node-union definition to a short name and keeps it a strict oneOf', () => {
9
+ // Shaped like the schema the MCP server prepares for a collection with a Lexical richText field
10
+ // (Payload's `input` variant): a `$defs` node union (a `oneOf` of node shapes). The input variant
11
+ // already types the relationship node's `value` as a bare ID - there is no populated-doc `$ref` to
12
+ // reduce here (the variant did that upstream), so sanitize leaves the value untouched.
12
13
  const standalone: JsonSchemaType = {
13
14
  type: 'object',
14
15
  $defs: {
@@ -25,17 +26,12 @@ describe('sanitizeEntitySchema', () => {
25
26
  additionalProperties: false,
26
27
  properties: {
27
28
  type: { const: 'relationship' },
28
- value: { oneOf: [{ type: 'string' }, { $ref: '#/$defs/posts' }] },
29
+ value: { type: 'string', description: 'The related document ID.' },
29
30
  },
30
31
  required: ['type'],
31
32
  },
32
33
  ],
33
34
  },
34
- posts: {
35
- type: 'object',
36
- additionalProperties: false,
37
- properties: { id: { type: 'string' }, title: { type: 'string' } },
38
- },
39
35
  },
40
36
  properties: {
41
37
  id: { type: 'string' },
@@ -57,7 +53,7 @@ describe('sanitizeEntitySchema', () => {
57
53
  type: 'object',
58
54
  $defs: {
59
55
  // The node union is renamed to a short, readable `node`, and stays a strict discriminated
60
- // `oneOf` - not loosened to `anyOf`...
56
+ // `oneOf` - not loosened to `anyOf`.
61
57
  node: {
62
58
  oneOf: [
63
59
  {
@@ -71,21 +67,18 @@ describe('sanitizeEntitySchema', () => {
71
67
  additionalProperties: false,
72
68
  properties: {
73
69
  type: { const: 'relationship' },
74
- // ...while the relationship `value` is simplified to a bare ID (the populated-doc `$ref` is dropped).
75
- value: { type: 'string', description: 'The ID of the related "posts" document.' },
70
+ // The value is already ID-only from the input variant - left as-is.
71
+ value: { type: 'string', description: 'The related document ID.' },
76
72
  },
77
73
  required: ['type'],
78
74
  },
79
75
  ],
80
76
  },
81
- posts: {
82
- type: 'object',
83
- additionalProperties: false,
84
- properties: { id: { type: 'string' }, title: { type: 'string' } },
85
- },
86
77
  },
87
78
  properties: {
88
- // `id` is dropped - it's a Payload-managed field MCP clients never set.
79
+ // Managed timestamps are excluded upstream by the `input` variant. `id` stays because it's
80
+ // a valid optional input (a client may supply a custom ID).
81
+ id: { type: 'string' },
89
82
  content: {
90
83
  type: 'object',
91
84
  properties: {
@@ -1,30 +1,22 @@
1
1
  import type { JsonSchemaType } from '../../types.js'
2
2
 
3
3
  /**
4
- * Turns the JSON Schema that Payload generates for a collection or global into the input schema for
5
- * an MCP create/update tool. In short, it:
6
- *
7
- * - drops fields a client can't set (`id`, `createdAt`, the draft `_status`, …),
8
- * - rewrites Payload-specific field shapes (points, relationships) into plain JSON the model can fill,
9
- * - and shrinks the result so it's cheaper for the model to read,
10
- *
11
- * while keeping every node valid JSON Schema draft 2020-12. Each step below is tagged with why it runs -
12
- * **Correctness** (valid input the API accepts), **Size** (equivalence-preserving shrink), or **LLM
13
- * ergonomics** (easier for the model to read/fill) - and carries a before/after example on its definition.
4
+ * Refines Payload's `input`-variant JSON Schema into an MCP create/update tool's input schema. The
5
+ * variant already covers correctness (ID-only relationships, no managed/virtual/join fields); the
6
+ * passes here are MCP-specific - reshaping fields for the model and shrinking the result - and keep
7
+ * every node valid JSON Schema draft 2020-12. Each is tagged **Correctness**, **Size**, or **LLM
8
+ * ergonomics**, with a before/after example on its definition.
14
9
  */
15
10
  export const sanitizeEntitySchema = (schema: JsonSchemaType): JsonSchemaType => {
16
11
  // Work on a copy — the caller reuses the original schema elsewhere (e.g. when listing tools).
17
12
  let result = structuredClone(schema)
18
13
 
19
- // Correctness — drop the fields a client can't set (id, createdAt, updatedAt, draft _status) + collapse nullable types.
20
- result = removeManagedFields(result)
14
+ // LLM ergonomics — drop the redundant `'null'` from optional arrays/objects (`['array','null']` `'array'`).
15
+ result = collapseOptionalContainerTypes(result)
21
16
 
22
17
  // LLM ergonomics — rewrite point fields from a `[number, number]` tuple into a `{ longitude, latitude }` object.
23
18
  result = pointFieldsToObjects(result)
24
19
 
25
- // Correctness — a relationship value can be an ID or a populated doc; on input only the ID is valid, so keep that.
26
- result = relationshipsToIds(result)
27
-
28
20
  // Size — strip inert type-gen leftovers that only bloat the schema (`tsType`, block-collision notes).
29
21
  result = removeTypeGenArtifacts(result)
30
22
 
@@ -58,26 +50,20 @@ const mapNodes = (node: unknown, visit: (node: JsonSchemaType) => JsonSchemaType
58
50
  for (const [key, value] of Object.entries(node)) {
59
51
  out[key] = mapNodes(value, visit)
60
52
  }
61
- return visit(out as JsonSchemaType)
53
+ return visit(out)
62
54
  }
63
55
 
64
- // Payload sets these on every document, so an MCP client never provides them when creating/updating.
65
- const PAYLOAD_MANAGED_FIELDS = new Set(['_status', 'createdAt', 'id', 'updatedAt'])
66
-
67
56
  /**
68
- * **Correctness.** Removes the fields a client can't set on create/update - `id`, `createdAt`, `updatedAt`, and the draft
69
- * `_status` - from every field object's `properties` and `required` (recursing into nested objects and
70
- * array items). Along the way it also collapses optional array/object types via {@link collapseNullableType}.
57
+ * **LLM ergonomics.** Collapses optional array/object types (`['array', 'null']` `'array'`) via
58
+ * {@link collapseNullableType}, recursing through `properties` and array items. The `required` list
59
+ * already conveys optionality, so the `'null'` is redundant noise for the model.
71
60
  *
72
61
  * @example
73
- * { properties: { id: { type: 'string' }, tags: { type: ['array', 'null'], items: {} } }, required: ['id', 'tags'] }
74
- * → { properties: { tags: { type: 'array', items: {} } }, required: ['tags'] }
62
+ * { properties: { tags: { type: ['array', 'null'], items: {} } }, required: [] }
63
+ * → { properties: { tags: { type: 'array', items: {} } }, required: [] }
75
64
  */
76
- const removeManagedFields = (schema: JsonSchemaType): JsonSchemaType => {
65
+ const collapseOptionalContainerTypes = (schema: JsonSchemaType): JsonSchemaType => {
77
66
  if (schema.properties && typeof schema.properties === 'object') {
78
- for (const field of PAYLOAD_MANAGED_FIELDS) {
79
- delete schema.properties[field]
80
- }
81
67
  for (const key of Object.keys(schema.properties)) {
82
68
  const prop = schema.properties[key] as JsonSchemaType
83
69
  if (!prop || typeof prop !== 'object') {
@@ -86,21 +72,14 @@ const removeManagedFields = (schema: JsonSchemaType): JsonSchemaType => {
86
72
  const isRequired = Array.isArray(schema.required) && schema.required.includes(key)
87
73
  collapseNullableType(prop, isRequired)
88
74
  if (prop.properties) {
89
- removeManagedFields(prop)
75
+ collapseOptionalContainerTypes(prop)
90
76
  }
91
77
  if (prop.items && typeof prop.items === 'object' && !Array.isArray(prop.items)) {
92
- removeManagedFields(prop.items)
78
+ collapseOptionalContainerTypes(prop.items)
93
79
  }
94
80
  }
95
81
  }
96
82
 
97
- if (Array.isArray(schema.required)) {
98
- schema.required = schema.required.filter((name) => !PAYLOAD_MANAGED_FIELDS.has(name))
99
- if (schema.required.length === 0) {
100
- delete schema.required
101
- }
102
- }
103
-
104
83
  return schema
105
84
  }
106
85
 
@@ -193,82 +172,6 @@ const pointFieldsToObjects = (schema: JsonSchemaType): JsonSchemaType => {
193
172
  return transformed
194
173
  }
195
174
 
196
- /**
197
- * **Correctness.** Reduces relationship/upload fields to the IDs a client actually sends. Payload types the value as
198
- * "an ID or the full related document" - but the populated-document form only appears in read responses;
199
- * on create/update you always reference a relationship by its ID. So we drop that `$ref` option, leaving
200
- * the bare ID. A single remaining target collapses inline (with a description naming the target
201
- * collection); several targets become an `anyOf` of IDs.
202
- *
203
- * @example
204
- * { oneOf: [{ type: 'string' }, { $ref: '#/$defs/posts' }] }
205
- * → { type: 'string', description: 'The ID of the related "posts" document.' }
206
- */
207
- const relationshipsToIds = (schema: JsonSchemaType): JsonSchemaType => {
208
- if (!schema || typeof schema !== 'object') {
209
- return schema
210
- }
211
-
212
- const processed = { ...schema }
213
-
214
- if (Array.isArray(processed.oneOf)) {
215
- const isRelatedDocRef = (option: unknown): option is { $ref: string } =>
216
- !!option && typeof option === 'object' && '$ref' in option
217
-
218
- if (processed.oneOf.some(isRelatedDocRef)) {
219
- // A relationship value is "an ID, or the populated related document". Keep the ID option(s) and
220
- // drop the `$ref`s to the related collections, since a client only ever sends the ID.
221
- const idOptions = processed.oneOf
222
- .filter((option) => !isRelatedDocRef(option))
223
- .map((option) => (typeof option === 'object' ? relationshipsToIds(option) : option))
224
- const targetCollections = processed.oneOf
225
- .filter(isRelatedDocRef)
226
- .map((option) => option.$ref.replace('#/$defs/', ''))
227
-
228
- if (idOptions.length === 1) {
229
- delete processed.oneOf
230
- Object.assign(processed, idOptions[0])
231
- if (targetCollections.length > 0 && !processed.description) {
232
- processed.description = `The ID of the related "${targetCollections.join('" or "')}" document.`
233
- }
234
- } else if (idOptions.length > 1) {
235
- delete processed.oneOf
236
- processed.anyOf = idOptions
237
- }
238
- } else {
239
- processed.oneOf = processed.oneOf.map((option) =>
240
- typeof option === 'object' ? relationshipsToIds(option) : option,
241
- )
242
- }
243
- }
244
-
245
- if (processed.properties && typeof processed.properties === 'object') {
246
- processed.properties = Object.fromEntries(
247
- Object.entries(processed.properties).map(([key, value]) => [
248
- key,
249
- typeof value === 'object' ? relationshipsToIds(value) : value,
250
- ]),
251
- )
252
- }
253
-
254
- if (processed.items && typeof processed.items === 'object' && !Array.isArray(processed.items)) {
255
- processed.items = relationshipsToIds(processed.items)
256
- }
257
-
258
- // Lexical node unions and blocks live under `$defs` and have their own relationship fields, so walk
259
- // those too — otherwise their `$ref`s would dangle once we don't bundle the related collections.
260
- if (processed.$defs && typeof processed.$defs === 'object') {
261
- processed.$defs = Object.fromEntries(
262
- Object.entries(processed.$defs).map(([key, value]) => [
263
- key,
264
- typeof value === 'object' ? relationshipsToIds(value) : value,
265
- ]),
266
- )
267
- }
268
-
269
- return processed
270
- }
271
-
272
175
  /**
273
176
  * **Size.** Strips type-generation leftovers that bloat the schema without helping the model: the `tsType`
274
177
  * hint (a `json-schema-to-typescript` extension; JSON Schema validators just ignore it, they don't reject it)
@@ -448,7 +351,7 @@ const deduplicateIntoDefinitions = (schema: JsonSchemaType): JsonSchemaType => {
448
351
  if (!name) {
449
352
  name = `shared_${nameByKey.size}`
450
353
  nameByKey.set(key, name)
451
- sharedEntries[name] = node as JsonSchemaType
354
+ sharedEntries[name] = node
452
355
  }
453
356
  return { $ref: `#/$defs/${name}` }
454
357
  }
@@ -0,0 +1,24 @@
1
+ import type { Where } from 'payload'
2
+
3
+ import { validOperators } from 'payload/shared'
4
+ import { z } from 'zod'
5
+
6
+ const whereFieldSchema = z
7
+ .partialRecord(z.enum(validOperators), z.unknown())
8
+ .describe('Field query operators')
9
+
10
+ /**
11
+ * - Validates the `where` input of collection tools against Payload's `Where` shape
12
+ * - Field keys map to operator objects restricted to `validOperators`
13
+ * - `and` / `or` nest recursively
14
+ */
15
+ export const whereSchema: z.ZodType<Where> = z
16
+ .lazy(() =>
17
+ z
18
+ .object({
19
+ and: z.array(whereSchema).optional(),
20
+ or: z.array(whereSchema).optional(),
21
+ })
22
+ .catchall(whereFieldSchema),
23
+ )
24
+ .describe('Where clause using field names with Payload query operators, plus and/or groups')
@@ -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,12 +0,0 @@
1
- import type { JSONField } from 'payload';
2
- import type { SanitizedMCPPluginConfig } from '../types.js';
3
- /**
4
- * Returns the API key collection's `access` field — a JSON field whose value
5
- * is the `MCPAPIKeysDocAccessTree` the endpoint consults. The actual UI is
6
- * a custom client component (`AccessField`) which renders a permissions
7
- * matrix; the field's stored shape is just the runtime access tree.
8
- */
9
- export declare const getAccessField: ({ pluginConfig, }: {
10
- pluginConfig: SanitizedMCPPluginConfig;
11
- }) => JSONField;
12
- //# sourceMappingURL=getAccessField.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getAccessField.d.ts","sourceRoot":"","sources":["../../src/collection/getAccessField.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,OAAO,KAAK,EAAkC,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAE3F;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,mBAE5B;IACD,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,SAqBH,CAAA"}
@@ -1,57 +0,0 @@
1
- /**
2
- * Returns the API key collection's `access` field — a JSON field whose value
3
- * is the `MCPAPIKeysDocAccessTree` the endpoint consults. The actual UI is
4
- * a custom client component (`AccessField`) which renders a permissions
5
- * matrix; the field's stored shape is just the runtime access tree.
6
- */ export const getAccessField = ({ pluginConfig })=>{
7
- const clientPluginConfig = sanitizeClientPluginConfig(pluginConfig);
8
- return {
9
- name: 'access',
10
- type: 'json',
11
- admin: {
12
- components: {
13
- Field: {
14
- clientProps: {
15
- pluginConfig: clientPluginConfig
16
- },
17
- path: '@payloadcms/plugin-mcp/client#AccessField'
18
- }
19
- },
20
- // TODO: needs i18n once design is finalized
21
- description: 'Access for this API key — uncheck to revoke individual tools.',
22
- position: 'sidebar'
23
- },
24
- defaultValue: {},
25
- // TODO: needs i18n once design is finalized
26
- label: 'Access'
27
- };
28
- };
29
- /**
30
- * Strips the non-serializable parts of `SanitizedMCPPluginConfig` (handlers,
31
- * input/argsSchema functions, etc.) so the result is safe to thread to a
32
- * client component via `clientProps`.
33
- */ const sanitizeClientPluginConfig = (pluginConfig)=>({
34
- items: pluginConfig.items.map((item)=>({
35
- ...item.type === 'collectionTool' ? {
36
- collectionSlug: item.collectionSlug
37
- } : {},
38
- ...item.type === 'globalTool' ? {
39
- globalSlug: item.globalSlug
40
- } : {},
41
- type: item.type,
42
- description: itemDescription(item),
43
- key: item.key,
44
- label: item.label
45
- }))
46
- });
47
- const itemDescription = (item)=>{
48
- if (item.type === 'prompt') {
49
- return item.prompt.description;
50
- }
51
- if (item.type === 'resource') {
52
- return item.resource.description;
53
- }
54
- return item.tool.description;
55
- };
56
-
57
- //# sourceMappingURL=getAccessField.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/collection/getAccessField.ts"],"sourcesContent":["import type { JSONField } from 'payload'\n\nimport type { ClientMCPPluginConfig, MCPItem, SanitizedMCPPluginConfig } from '../types.js'\n\n/**\n * Returns the API key collection's `access` field — a JSON field whose value\n * is the `MCPAPIKeysDocAccessTree` the endpoint consults. The actual UI is\n * a custom client component (`AccessField`) which renders a permissions\n * matrix; the field's stored shape is just the runtime access tree.\n */\nexport const getAccessField = ({\n pluginConfig,\n}: {\n pluginConfig: SanitizedMCPPluginConfig\n}): JSONField => {\n const clientPluginConfig = sanitizeClientPluginConfig(pluginConfig)\n\n return {\n name: 'access',\n type: 'json',\n admin: {\n components: {\n Field: {\n clientProps: { pluginConfig: clientPluginConfig },\n path: '@payloadcms/plugin-mcp/client#AccessField',\n },\n },\n // TODO: needs i18n once design is finalized\n description: 'Access for this API key — uncheck to revoke individual tools.',\n position: 'sidebar',\n },\n defaultValue: {},\n // TODO: needs i18n once design is finalized\n label: 'Access',\n }\n}\n\n/**\n * Strips the non-serializable parts of `SanitizedMCPPluginConfig` (handlers,\n * input/argsSchema functions, etc.) so the result is safe to thread to a\n * client component via `clientProps`.\n */\nconst sanitizeClientPluginConfig = (\n pluginConfig: SanitizedMCPPluginConfig,\n): ClientMCPPluginConfig => ({\n items: pluginConfig.items.map((item) => ({\n ...(item.type === 'collectionTool' ? { collectionSlug: item.collectionSlug } : {}),\n ...(item.type === 'globalTool' ? { globalSlug: item.globalSlug } : {}),\n type: item.type,\n description: itemDescription(item),\n key: item.key,\n label: item.label,\n })),\n})\n\nconst itemDescription = (item: MCPItem): string => {\n if (item.type === 'prompt') {\n return item.prompt.description\n }\n if (item.type === 'resource') {\n return item.resource.description\n }\n return item.tool.description\n}\n"],"names":["getAccessField","pluginConfig","clientPluginConfig","sanitizeClientPluginConfig","name","type","admin","components","Field","clientProps","path","description","position","defaultValue","label","items","map","item","collectionSlug","globalSlug","itemDescription","key","prompt","resource","tool"],"mappings":"AAIA;;;;;CAKC,GACD,OAAO,MAAMA,iBAAiB,CAAC,EAC7BC,YAAY,EAGb;IACC,MAAMC,qBAAqBC,2BAA2BF;IAEtD,OAAO;QACLG,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBAAER,cAAcC;oBAAmB;oBAChDQ,MAAM;gBACR;YACF;YACA,4CAA4C;YAC5CC,aAAa;YACbC,UAAU;QACZ;QACAC,cAAc,CAAC;QACf,4CAA4C;QAC5CC,OAAO;IACT;AACF,EAAC;AAED;;;;CAIC,GACD,MAAMX,6BAA6B,CACjCF,eAC2B,CAAA;QAC3Bc,OAAOd,aAAac,KAAK,CAACC,GAAG,CAAC,CAACC,OAAU,CAAA;gBACvC,GAAIA,KAAKZ,IAAI,KAAK,mBAAmB;oBAAEa,gBAAgBD,KAAKC,cAAc;gBAAC,IAAI,CAAC,CAAC;gBACjF,GAAID,KAAKZ,IAAI,KAAK,eAAe;oBAAEc,YAAYF,KAAKE,UAAU;gBAAC,IAAI,CAAC,CAAC;gBACrEd,MAAMY,KAAKZ,IAAI;gBACfM,aAAaS,gBAAgBH;gBAC7BI,KAAKJ,KAAKI,GAAG;gBACbP,OAAOG,KAAKH,KAAK;YACnB,CAAA;IACF,CAAA;AAEA,MAAMM,kBAAkB,CAACH;IACvB,IAAIA,KAAKZ,IAAI,KAAK,UAAU;QAC1B,OAAOY,KAAKK,MAAM,CAACX,WAAW;IAChC;IACA,IAAIM,KAAKZ,IAAI,KAAK,YAAY;QAC5B,OAAOY,KAAKM,QAAQ,CAACZ,WAAW;IAClC;IACA,OAAOM,KAAKO,IAAI,CAACb,WAAW;AAC9B"}
@@ -1,6 +0,0 @@
1
- import type { CollectionConfig } from 'payload';
2
- import type { SanitizedMCPPluginConfig } from '../types.js';
3
- export declare const getAPIKeysCollection: ({ pluginConfig, }: {
4
- pluginConfig: SanitizedMCPPluginConfig;
5
- }) => CollectionConfig;
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collection/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAI3D,eAAO,MAAM,oBAAoB,GAAI,mBAElC;IACD,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBAqDH,CAAA"}
@@ -1,60 +0,0 @@
1
- import { getAccessField } from './getAccessField.js';
2
- export const getAPIKeysCollection = ({ pluginConfig })=>{
3
- const collection = {
4
- slug: 'payload-mcp-api-keys',
5
- admin: {
6
- description: 'API keys control which collections, resources, tools, and prompts MCP clients can access',
7
- group: 'MCP',
8
- useAsTitle: 'label'
9
- },
10
- auth: {
11
- disableLocalStrategy: true,
12
- useAPIKey: true
13
- },
14
- fields: [
15
- {
16
- name: 'user',
17
- type: 'relationship',
18
- admin: {
19
- description: 'The user that the API key is associated with.'
20
- },
21
- relationTo: pluginConfig.userCollection,
22
- required: true
23
- },
24
- {
25
- name: 'label',
26
- type: 'text',
27
- admin: {
28
- description: 'A useful label for the API key.'
29
- }
30
- },
31
- {
32
- name: 'description',
33
- type: 'text',
34
- admin: {
35
- description: 'The purpose of the API key.'
36
- }
37
- },
38
- {
39
- name: 'overrideAccess',
40
- type: 'checkbox',
41
- admin: {
42
- description: 'When checked, this key bypasses Payload access control on every operation it performs. Leave unchecked unless you have a specific reason.'
43
- },
44
- defaultValue: false,
45
- label: 'Override access control'
46
- },
47
- getAccessField({
48
- pluginConfig
49
- })
50
- ],
51
- labels: {
52
- plural: 'API Keys',
53
- singular: 'API Key'
54
- },
55
- versions: false
56
- };
57
- return pluginConfig.overrideApiKeyCollection ? pluginConfig.overrideApiKeyCollection(collection) : collection;
58
- };
59
-
60
- //# sourceMappingURL=index.js.map