@payloadcms/plugin-mcp 4.0.0-internal.293e026 → 4.0.0-internal.2a3c3bc

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 (242) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/defaultAccess.d.ts +3 -0
  3. package/dist/defaultAccess.d.ts.map +1 -0
  4. package/dist/defaultAccess.js +3 -0
  5. package/dist/defaultAccess.js.map +1 -0
  6. package/dist/defineTool.d.ts +8 -8
  7. package/dist/defineTool.d.ts.map +1 -1
  8. package/dist/endpoint/access.d.ts +12 -5
  9. package/dist/endpoint/access.d.ts.map +1 -1
  10. package/dist/endpoint/access.js +76 -88
  11. package/dist/endpoint/access.js.map +1 -1
  12. package/dist/endpoint/index.d.ts +1 -1
  13. package/dist/endpoint/index.d.ts.map +1 -1
  14. package/dist/endpoint/index.js +102 -16
  15. package/dist/endpoint/index.js.map +1 -1
  16. package/dist/endpoint/oauth.d.ts +27 -0
  17. package/dist/endpoint/oauth.d.ts.map +1 -0
  18. package/dist/endpoint/oauth.js +61 -0
  19. package/dist/endpoint/oauth.js.map +1 -0
  20. package/dist/exports/client.d.ts +1 -1
  21. package/dist/exports/client.d.ts.map +1 -1
  22. package/dist/exports/client.js +1 -1
  23. package/dist/exports/client.js.map +1 -1
  24. package/dist/exports/internal.d.ts +2 -0
  25. package/dist/exports/internal.d.ts.map +1 -0
  26. package/dist/exports/internal.js +3 -0
  27. package/dist/exports/internal.js.map +1 -0
  28. package/dist/index.d.ts +3 -2
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +22 -20
  31. package/dist/index.js.map +1 -1
  32. package/dist/mcp/buildMcpServer.d.ts +6 -6
  33. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  34. package/dist/mcp/buildMcpServer.js +146 -81
  35. package/dist/mcp/buildMcpServer.js.map +1 -1
  36. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  37. package/dist/mcp/builtin/collections/authTools.js +123 -61
  38. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  39. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  40. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  41. package/dist/mcp/builtin/collections/countTool.js +63 -0
  42. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  43. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  44. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  45. package/dist/mcp/builtin/collections/countVersionsTool.js +60 -0
  46. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  47. package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
  48. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  49. package/dist/mcp/builtin/collections/createTool.js +114 -68
  50. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  51. package/dist/mcp/builtin/collections/deleteTool.d.ts +1 -1
  52. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  53. package/dist/mcp/builtin/collections/deleteTool.js +55 -61
  54. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  55. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  56. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  57. package/dist/mcp/builtin/collections/duplicateTool.js +90 -0
  58. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  59. package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
  60. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  61. package/dist/mcp/builtin/collections/fileInput.js +88 -0
  62. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  63. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  64. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  65. package/dist/mcp/builtin/collections/findDistinctTool.js +77 -0
  66. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  67. package/dist/mcp/builtin/collections/findTool.d.ts +1 -1
  68. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  69. package/dist/mcp/builtin/collections/findTool.js +61 -74
  70. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  71. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  72. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  73. package/dist/mcp/builtin/collections/findVersionByIDTool.js +74 -0
  74. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  75. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  76. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  77. package/dist/mcp/builtin/collections/findVersionsTool.js +84 -0
  78. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  79. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
  80. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
  81. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +103 -0
  82. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
  83. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  84. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  85. package/dist/mcp/builtin/collections/restoreVersionTool.js +69 -0
  86. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  87. package/dist/mcp/builtin/collections/updateTool.d.ts +1 -1
  88. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  89. package/dist/mcp/builtin/collections/updateTool.js +118 -137
  90. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  91. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  92. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  93. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  94. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  95. package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
  96. package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
  97. package/dist/mcp/builtin/formatEntityError.js +55 -0
  98. package/dist/mcp/builtin/formatEntityError.js.map +1 -0
  99. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  100. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  101. package/dist/mcp/builtin/getConfigInfoTool.js +69 -0
  102. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  103. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  104. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  105. package/dist/mcp/builtin/globals/countVersionsTool.js +60 -0
  106. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  107. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  108. package/dist/mcp/builtin/globals/findTool.js +27 -36
  109. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  110. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  111. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  112. package/dist/mcp/builtin/globals/findVersionByIDTool.js +68 -0
  113. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  114. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  115. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  116. package/dist/mcp/builtin/globals/findVersionsTool.js +78 -0
  117. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  118. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  119. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  120. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +81 -0
  121. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  122. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  123. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  124. package/dist/mcp/builtin/globals/restoreVersionTool.js +70 -0
  125. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  126. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  127. package/dist/mcp/builtin/globals/updateTool.js +44 -62
  128. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  129. package/dist/mcp/builtinTools.d.ts +150 -19
  130. package/dist/mcp/builtinTools.d.ts.map +1 -1
  131. package/dist/mcp/builtinTools.js +125 -20
  132. package/dist/mcp/builtinTools.js.map +1 -1
  133. package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
  134. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  135. package/dist/mcp/sanitizeMCPConfig.js +125 -58
  136. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  137. package/dist/stdio.d.ts +3 -3
  138. package/dist/stdio.d.ts.map +1 -1
  139. package/dist/stdio.js +86 -47
  140. package/dist/stdio.js.map +1 -1
  141. package/dist/types.d.ts +138 -114
  142. package/dist/types.d.ts.map +1 -1
  143. package/dist/types.js +2 -4
  144. package/dist/types.js.map +1 -1
  145. package/dist/utils/camelCase.d.ts.map +1 -1
  146. package/dist/utils/getPluginConfig.d.ts +1 -1
  147. package/dist/utils/getPluginConfig.js +1 -1
  148. package/dist/utils/getPluginConfig.js.map +1 -1
  149. package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
  150. package/dist/utils/toStandardSchema.d.ts.map +1 -1
  151. package/package.json +11 -18
  152. package/src/defaultAccess.ts +3 -0
  153. package/src/endpoint/access.ts +81 -101
  154. package/src/endpoint/index.ts +93 -15
  155. package/src/endpoint/oauth.ts +72 -0
  156. package/src/exports/client.ts +2 -1
  157. package/src/exports/internal.ts +1 -0
  158. package/src/index.ts +19 -20
  159. package/src/mcp/buildMcpServer.ts +181 -116
  160. package/src/mcp/builtin/collections/authTools.ts +122 -75
  161. package/src/mcp/builtin/collections/countTool.ts +61 -0
  162. package/src/mcp/builtin/collections/countVersionsTool.ts +60 -0
  163. package/src/mcp/builtin/collections/createTool.ts +117 -88
  164. package/src/mcp/builtin/collections/deleteTool.ts +48 -74
  165. package/src/mcp/builtin/collections/duplicateTool.ts +84 -0
  166. package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
  167. package/src/mcp/builtin/collections/fileInput.ts +127 -0
  168. package/src/mcp/builtin/collections/findDistinctTool.ts +67 -0
  169. package/src/mcp/builtin/collections/findTool.ts +57 -110
  170. package/src/mcp/builtin/collections/findVersionByIDTool.ts +66 -0
  171. package/src/mcp/builtin/collections/findVersionsTool.ts +83 -0
  172. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +91 -0
  173. package/src/mcp/builtin/collections/restoreVersionTool.ts +65 -0
  174. package/src/mcp/builtin/collections/updateTool.ts +106 -143
  175. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  176. package/src/mcp/builtin/formatEntityError.ts +77 -0
  177. package/src/mcp/builtin/getConfigInfoTool.ts +68 -0
  178. package/src/mcp/builtin/globals/countVersionsTool.ts +60 -0
  179. package/src/mcp/builtin/globals/findTool.ts +27 -57
  180. package/src/mcp/builtin/globals/findVersionByIDTool.ts +64 -0
  181. package/src/mcp/builtin/globals/findVersionsTool.ts +69 -0
  182. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +73 -0
  183. package/src/mcp/builtin/globals/restoreVersionTool.ts +68 -0
  184. package/src/mcp/builtin/globals/updateTool.ts +51 -79
  185. package/src/mcp/builtinTools.ts +118 -41
  186. package/src/mcp/sanitizeMCPConfig.ts +121 -78
  187. package/src/stdio.ts +80 -47
  188. package/src/types.ts +156 -120
  189. package/src/utils/getPluginConfig.ts +1 -1
  190. package/dist/@types/assets.d.js +0 -2
  191. package/dist/@types/assets.d.js.map +0 -1
  192. package/dist/collection/getAccessField.d.ts +0 -12
  193. package/dist/collection/getAccessField.d.ts.map +0 -1
  194. package/dist/collection/getAccessField.js +0 -57
  195. package/dist/collection/getAccessField.js.map +0 -1
  196. package/dist/collection/index.d.ts +0 -6
  197. package/dist/collection/index.d.ts.map +0 -1
  198. package/dist/collection/index.js +0 -60
  199. package/dist/collection/index.js.map +0 -1
  200. package/dist/components/AccessField/index.client.d.ts +0 -10
  201. package/dist/components/AccessField/index.client.d.ts.map +0 -1
  202. package/dist/components/AccessField/index.client.js +0 -305
  203. package/dist/components/AccessField/index.client.js.map +0 -1
  204. package/dist/components/AccessField/index.css +0 -93
  205. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  206. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  207. package/dist/utils/getVirtualFieldNames.js +0 -35
  208. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  209. package/dist/utils/localAPIDefaults.d.ts +0 -20
  210. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  211. package/dist/utils/localAPIDefaults.js +0 -19
  212. package/dist/utils/localAPIDefaults.js.map +0 -1
  213. package/dist/utils/schemaConversion/buildToolInput.d.ts +0 -29
  214. package/dist/utils/schemaConversion/buildToolInput.d.ts.map +0 -1
  215. package/dist/utils/schemaConversion/buildToolInput.js +0 -51
  216. package/dist/utils/schemaConversion/buildToolInput.js.map +0 -1
  217. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  218. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  219. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  220. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  221. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -15
  222. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
  223. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -464
  224. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
  225. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -158
  226. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
  227. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  228. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  229. package/dist/utils/transformPointDataToPayload.js +0 -28
  230. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  231. package/src/@types/assets.d.ts +0 -3
  232. package/src/collection/getAccessField.ts +0 -64
  233. package/src/collection/index.ts +0 -64
  234. package/src/components/AccessField/index.client.tsx +0 -344
  235. package/src/components/AccessField/index.css +0 -93
  236. package/src/utils/getVirtualFieldNames.ts +0 -53
  237. package/src/utils/localAPIDefaults.ts +0 -22
  238. package/src/utils/schemaConversion/buildToolInput.ts +0 -68
  239. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  240. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -103
  241. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -529
  242. package/src/utils/transformPointDataToPayload.ts +0 -40
@@ -1,4 +1,4 @@
1
- import type { CollectionTool, GlobalTool } from '../types.js'
1
+ import type { CollectionTool, GlobalTool, Tool } from '../types.js'
2
2
 
3
3
  import {
4
4
  authCollectionTool,
@@ -8,62 +8,135 @@ import {
8
8
  unlockCollectionTool,
9
9
  verifyCollectionTool,
10
10
  } from './builtin/collections/authTools.js'
11
- import { createCollectionTool } from './builtin/collections/createTool.js'
12
- import { deleteCollectionTool } from './builtin/collections/deleteTool.js'
13
- import { findCollectionTool } from './builtin/collections/findTool.js'
14
- import { updateCollectionTool } from './builtin/collections/updateTool.js'
11
+ import { countDocumentsTool } from './builtin/collections/countTool.js'
12
+ import { countVersionsTool } from './builtin/collections/countVersionsTool.js'
13
+ import { createDocumentsTool } from './builtin/collections/createTool.js'
14
+ import { deleteDocumentsTool } from './builtin/collections/deleteTool.js'
15
+ import { duplicateDocumentTool } from './builtin/collections/duplicateTool.js'
16
+ import { findDistinctTool } from './builtin/collections/findDistinctTool.js'
17
+ import { findDocumentsTool } from './builtin/collections/findTool.js'
18
+ import { findVersionByIDTool } from './builtin/collections/findVersionByIDTool.js'
19
+ import { findVersionsTool } from './builtin/collections/findVersionsTool.js'
20
+ import { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js'
21
+ import { restoreVersionTool } from './builtin/collections/restoreVersionTool.js'
22
+ import { updateDocumentTool } from './builtin/collections/updateTool.js'
23
+ import { getUploadInstructionsTool } from './builtin/collections/uploadInstructionsTool.js'
24
+ import { getConfigInfoTool } from './builtin/getConfigInfoTool.js'
25
+ import { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js'
15
26
  import { findGlobalTool } from './builtin/globals/findTool.js'
27
+ import { findGlobalVersionByIDTool } from './builtin/globals/findVersionByIDTool.js'
28
+ import { findGlobalVersionsTool } from './builtin/globals/findVersionsTool.js'
29
+ import { getGlobalSchemaTool } from './builtin/globals/getGlobalSchemaTool.js'
30
+ import { restoreGlobalVersionTool } from './builtin/globals/restoreVersionTool.js'
16
31
  import { updateGlobalTool } from './builtin/globals/updateTool.js'
17
32
 
33
+ type CollectionBuiltin = {
34
+ mcpName: string
35
+ requiresDuplicateEnabled?: boolean
36
+ requiresUpload?: boolean
37
+ requiresVersions?: boolean
38
+ tool: CollectionTool
39
+ }
40
+
41
+ type GlobalBuiltin = {
42
+ mcpName: string
43
+ requiresVersions?: boolean
44
+ tool: GlobalTool
45
+ }
46
+
47
+ export const TOOL_BUILTINS = {
48
+ getConfigInfo: { mcpName: 'getConfigInfo', tool: getConfigInfoTool },
49
+ } satisfies Record<string, { mcpName: string; tool: Tool }>
50
+
18
51
  /**
19
52
  * The static built-in collection CRUD tools. Keys here are the source of truth
20
53
  * for `MCPCollectionBuiltinName` — adding/removing an entry updates the type
21
54
  * automatically.
22
55
  */
23
- export const COLLECTION_BUILTINS: Record<MCPCollectionBuiltinName, CollectionTool> = {
24
- create: createCollectionTool,
25
- delete: deleteCollectionTool,
26
- find: findCollectionTool,
27
- update: updateCollectionTool,
28
- }
56
+ export const COLLECTION_BUILTINS = {
57
+ count: { mcpName: 'countDocuments', tool: countDocumentsTool },
58
+ countVersions: { mcpName: 'countVersions', requiresVersions: true, tool: countVersionsTool },
59
+ create: { mcpName: 'createDocuments', tool: createDocumentsTool },
60
+ delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },
61
+ duplicate: {
62
+ mcpName: 'duplicateDocument',
63
+ requiresDuplicateEnabled: true,
64
+ tool: duplicateDocumentTool,
65
+ },
66
+ find: { mcpName: 'findDocuments', tool: findDocumentsTool },
67
+ findDistinct: { mcpName: 'findDistinct', tool: findDistinctTool },
68
+ findVersionByID: {
69
+ mcpName: 'findVersionByID',
70
+ requiresVersions: true,
71
+ tool: findVersionByIDTool,
72
+ },
73
+ findVersions: { mcpName: 'findVersions', requiresVersions: true, tool: findVersionsTool },
74
+ getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },
75
+ getUploadInstructions: {
76
+ mcpName: 'getUploadInstructions',
77
+ requiresUpload: true,
78
+ tool: getUploadInstructionsTool,
79
+ },
80
+ restoreVersion: { mcpName: 'restoreVersion', requiresVersions: true, tool: restoreVersionTool },
81
+ update: { mcpName: 'updateDocument', tool: updateDocumentTool },
82
+ } satisfies Record<string, CollectionBuiltin>
29
83
 
30
84
  /**
31
- * The static auth tools surfaced under auth-enabled collections. Each entry
32
- * carries the admin-UI label alongside the tool. Keys are the source of truth
33
- * for `MCPCollectionAuthToolName`.
85
+ * The static auth tools surfaced under auth-enabled collections. Keys are the
86
+ * source of truth for `MCPCollectionAuthToolName`.
34
87
  */
35
- export const COLLECTION_AUTH_BUILTINS: Record<
36
- MCPCollectionAuthToolName,
37
- { label: string; tool: CollectionTool }
38
- > = {
39
- auth: { label: 'Check Auth Status', tool: authCollectionTool },
40
- forgotPassword: { label: 'Forgot Password', tool: forgotPasswordCollectionTool },
41
- login: { label: 'User Login', tool: loginCollectionTool },
42
- resetPassword: { label: 'Reset Password', tool: resetPasswordCollectionTool },
43
- unlock: { label: 'Unlock Account', tool: unlockCollectionTool },
44
- verify: { label: 'Email Verification', tool: verifyCollectionTool },
45
- }
88
+ export const COLLECTION_AUTH_BUILTINS = {
89
+ auth: { mcpName: 'auth', tool: authCollectionTool },
90
+ forgotPassword: {
91
+ mcpName: 'forgotPassword',
92
+ tool: forgotPasswordCollectionTool,
93
+ },
94
+ login: { mcpName: 'login', tool: loginCollectionTool },
95
+ resetPassword: {
96
+ mcpName: 'resetPassword',
97
+ tool: resetPasswordCollectionTool,
98
+ },
99
+ unlock: { mcpName: 'unlock', tool: unlockCollectionTool },
100
+ verify: { mcpName: 'verify', tool: verifyCollectionTool },
101
+ } satisfies Record<string, { mcpName: string; tool: CollectionTool }>
46
102
 
47
103
  /**
48
104
  * The static built-in global tools. Keys are the source of truth for
49
105
  * `MCPGlobalBuiltinName`.
50
106
  */
51
- export const GLOBAL_BUILTINS: Record<MCPGlobalBuiltinName, GlobalTool> = {
52
- find: findGlobalTool,
53
- update: updateGlobalTool,
54
- }
107
+ export const GLOBAL_BUILTINS = {
108
+ countGlobalVersions: {
109
+ mcpName: 'countGlobalVersions',
110
+ requiresVersions: true,
111
+ tool: countGlobalVersionsTool,
112
+ },
113
+ find: { mcpName: 'findGlobal', tool: findGlobalTool },
114
+ findGlobalVersionByID: {
115
+ mcpName: 'findGlobalVersionByID',
116
+ requiresVersions: true,
117
+ tool: findGlobalVersionByIDTool,
118
+ },
119
+ findGlobalVersions: {
120
+ mcpName: 'findGlobalVersions',
121
+ requiresVersions: true,
122
+ tool: findGlobalVersionsTool,
123
+ },
124
+ getGlobalSchema: { mcpName: 'getGlobalSchema', tool: getGlobalSchemaTool },
125
+ restoreGlobalVersion: {
126
+ mcpName: 'restoreGlobalVersion',
127
+ requiresVersions: true,
128
+ tool: restoreGlobalVersionTool,
129
+ },
130
+ update: { mcpName: 'updateGlobal', tool: updateGlobalTool },
131
+ } satisfies Record<string, GlobalBuiltin>
132
+
133
+ export type MCPCollectionBuiltinName = keyof typeof COLLECTION_BUILTINS
55
134
 
56
- export type MCPCollectionBuiltinName = 'create' | 'delete' | 'find' | 'update'
135
+ export type MCPCollectionAuthToolName = keyof typeof COLLECTION_AUTH_BUILTINS
57
136
 
58
- export type MCPCollectionAuthToolName =
59
- | 'auth'
60
- | 'forgotPassword'
61
- | 'login'
62
- | 'resetPassword'
63
- | 'unlock'
64
- | 'verify'
137
+ export type MCPGlobalBuiltinName = keyof typeof GLOBAL_BUILTINS
65
138
 
66
- export type MCPGlobalBuiltinName = 'find' | 'update'
139
+ export type MCPTopLevelBuiltinName = keyof typeof TOOL_BUILTINS
67
140
 
68
141
  /**
69
142
  * Pre-typed `Object.entries` for each registry. The cast from `string` to the
@@ -71,14 +144,18 @@ export type MCPGlobalBuiltinName = 'find' | 'update'
71
144
  * cast — TypeScript's `Object.entries` always widens keys to `string`, which
72
145
  * defeats the narrow type lookups on `MCPCollectionToolsMap`.
73
146
  */
147
+ export const TOOL_BUILTIN_ENTRIES = Object.entries(TOOL_BUILTINS) as Array<
148
+ [MCPTopLevelBuiltinName, (typeof TOOL_BUILTINS)[MCPTopLevelBuiltinName]]
149
+ >
150
+
74
151
  export const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS) as Array<
75
- [MCPCollectionBuiltinName, CollectionTool]
152
+ [MCPCollectionBuiltinName, CollectionBuiltin]
76
153
  >
77
154
 
78
155
  export const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS) as Array<
79
- [MCPCollectionAuthToolName, { label: string; tool: CollectionTool }]
156
+ [MCPCollectionAuthToolName, (typeof COLLECTION_AUTH_BUILTINS)[MCPCollectionAuthToolName]]
80
157
  >
81
158
 
82
159
  export const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS) as Array<
83
- [MCPGlobalBuiltinName, GlobalTool]
160
+ [MCPGlobalBuiltinName, GlobalBuiltin]
84
161
  >
@@ -8,16 +8,16 @@ import type {
8
8
  } from 'payload'
9
9
 
10
10
  import type {
11
+ CollectionMCPItem,
11
12
  CollectionTool,
13
+ GlobalMCPItem,
12
14
  GlobalTool,
13
- MCPBuiltInToolOverride,
14
15
  MCPItem,
15
- MCPPluginCollectionConfig,
16
16
  MCPPluginConfig,
17
- MCPPluginGlobalConfig,
18
17
  SanitizedMCPPluginConfig,
19
18
  } from '../types.js'
20
19
 
20
+ import { defaultAccess } from '../defaultAccess.js'
21
21
  import {
22
22
  COLLECTION_AUTH_BUILTIN_ENTRIES,
23
23
  COLLECTION_AUTH_BUILTINS,
@@ -25,6 +25,8 @@ import {
25
25
  COLLECTION_BUILTINS,
26
26
  GLOBAL_BUILTIN_ENTRIES,
27
27
  GLOBAL_BUILTINS,
28
+ TOOL_BUILTIN_ENTRIES,
29
+ TOOL_BUILTINS,
28
30
  } from './builtinTools.js'
29
31
 
30
32
  /**
@@ -32,7 +34,6 @@ import {
32
34
  * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global
33
35
  * tool maps into a single `items` array.
34
36
  * - Applies built-in tools for collections and globals, respecting opt-out user overrides.
35
- * - Applies the `userCollection` default
36
37
  *
37
38
  * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']
38
39
  * ?.options` holds the sanitized result
@@ -54,44 +55,56 @@ export const sanitizeMCPConfig = ({
54
55
  items.push(...sanitizeGlobalConfig({ global, pluginConfig }))
55
56
  }
56
57
 
57
- for (const [key, tool] of Object.entries(pluginConfig.tools ?? {})) {
58
+ for (const [configKey, { mcpName, tool }] of TOOL_BUILTIN_ENTRIES) {
58
59
  items.push({
59
60
  type: 'tool',
60
- key,
61
- label: key,
62
- tool,
61
+ configKey,
62
+ label: tool.annotations?.title ?? configKey,
63
+ mcpName,
64
+ tool: { ...tool, access: tool.access ?? defaultAccess },
63
65
  })
64
66
  }
65
67
 
66
- for (const [key, prompt] of Object.entries(pluginConfig.prompts ?? {})) {
68
+ for (const [configKey, tool] of Object.entries(pluginConfig.tools ?? {})) {
69
+ if (configKey in TOOL_BUILTINS) {
70
+ continue
71
+ }
72
+ items.push({
73
+ type: 'tool',
74
+ configKey,
75
+ label: tool.annotations?.title ?? configKey,
76
+ mcpName: configKey,
77
+ tool: { ...tool, access: tool.access ?? defaultAccess },
78
+ })
79
+ }
80
+
81
+ for (const [configKey, prompt] of Object.entries(pluginConfig.prompts ?? {})) {
67
82
  items.push({
68
83
  type: 'prompt',
69
- key,
70
- label: prompt.title ?? key,
71
- prompt,
84
+ configKey,
85
+ label: prompt.title ?? configKey,
86
+ mcpName: configKey,
87
+ prompt: { ...prompt, access: prompt.access ?? defaultAccess },
72
88
  })
73
89
  }
74
90
 
75
- for (const [key, resource] of Object.entries(pluginConfig.resources ?? {})) {
91
+ for (const [configKey, resource] of Object.entries(pluginConfig.resources ?? {})) {
76
92
  items.push({
77
93
  type: 'resource',
78
- key,
79
- label: resource.title ?? key,
80
- resource,
94
+ configKey,
95
+ label: resource.title ?? configKey,
96
+ mcpName: configKey,
97
+ resource: { ...resource, access: resource.access ?? defaultAccess },
81
98
  })
82
99
  }
83
100
 
84
- // Mirror Payload's own admin.user detection (sanitize.ts) since plugins run first.
85
- const firstCollectionWithAuth = config.collections!.find(({ auth }) => Boolean(auth))
86
-
87
101
  return {
88
102
  disabled: pluginConfig.disabled,
103
+ hooks: pluginConfig.hooks,
89
104
  items,
90
105
  mcp: pluginConfig.mcp,
91
- overrideApiKeyCollection: pluginConfig.overrideApiKeyCollection,
92
- overrideAuth: pluginConfig.overrideAuth,
93
- userCollection:
94
- pluginConfig.userCollection ?? config.admin?.user ?? firstCollectionWithAuth?.slug ?? 'users',
106
+ oauth: pluginConfig.oauth,
107
+ overrideGetAuthorizedMCP: pluginConfig.overrideGetAuthorizedMCP,
95
108
  }
96
109
  }
97
110
 
@@ -101,42 +114,81 @@ const sanitizeCollectionConfig = ({
101
114
  }: {
102
115
  collection: CollectionConfig | SanitizedCollectionConfig
103
116
  pluginConfig: MCPPluginConfig
104
- }): MCPItem[] => {
105
- if (collection.slug === 'payload-mcp-api-keys') {
106
- return []
107
- }
117
+ }): CollectionMCPItem[] => {
108
118
  const slug = collection.slug
109
119
  const collectionPluginConfig = pluginConfig.collections?.[slug]
110
- const items: MCPItem[] = []
120
+ const items: CollectionMCPItem[] = []
121
+ /**
122
+ * Payload disables duplicate for auth collections by default unless the
123
+ * collection explicitly opts back in with `disableDuplicate: false`.
124
+ */
125
+ const isDuplicateDisabled =
126
+ collection.disableDuplicate === true ||
127
+ (Boolean(collection.auth) && collection.disableDuplicate !== false)
111
128
 
112
- for (const [toolKey, tool] of COLLECTION_BUILTIN_ENTRIES) {
129
+ for (const [
130
+ toolKey,
131
+ { mcpName, requiresDuplicateEnabled, requiresUpload, requiresVersions, tool },
132
+ ] of COLLECTION_BUILTIN_ENTRIES) {
133
+ if (requiresVersions && !collection.versions) {
134
+ continue
135
+ }
136
+ if (requiresDuplicateEnabled && isDuplicateDisabled) {
137
+ continue
138
+ }
139
+ if (requiresUpload && !collection.upload) {
140
+ continue
141
+ }
113
142
  const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]
114
143
  if (matchedConfigEntry === false) {
115
144
  continue
116
145
  }
146
+ const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
147
+ const annotations = { ...tool.annotations, ...override?.annotations }
117
148
  items.push({
118
149
  type: 'collectionTool',
119
150
  collectionSlug: slug,
120
- key: toolKey,
121
- label: capitalize(toolKey),
122
- tool: overrideBuiltinTool(tool, matchedConfigEntry, collectionPluginConfig),
151
+ configKey: toolKey,
152
+ label: annotations.title ?? toolKey,
153
+ mcpName,
154
+ tool: {
155
+ ...tool,
156
+ access: override?.access ?? tool.access ?? defaultAccess,
157
+ annotations,
158
+ description: override?.description ?? tool.description,
159
+ overrideResponse:
160
+ override?.overrideResponse ??
161
+ collectionPluginConfig?.overrideResponse ??
162
+ tool.overrideResponse,
163
+ },
123
164
  })
124
165
  }
125
166
 
126
167
  if (collection.auth) {
127
- for (const [authToolKey, { label, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {
168
+ for (const [authToolKey, { mcpName, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {
128
169
  const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey]
129
170
  if (!matchedConfigEntry) {
130
171
  continue
131
172
  }
132
173
  // `true` means "enable, no override"; only the object form carries fields.
133
174
  const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
175
+ const annotations = { ...tool.annotations, ...override?.annotations }
134
176
  items.push({
135
177
  type: 'collectionTool',
136
178
  collectionSlug: slug,
137
- key: authToolKey,
138
- label,
139
- tool: overrideBuiltinTool(tool, override, collectionPluginConfig),
179
+ configKey: authToolKey,
180
+ label: annotations.title ?? authToolKey,
181
+ mcpName,
182
+ tool: {
183
+ ...tool,
184
+ access: override?.access ?? tool.access ?? defaultAccess,
185
+ annotations,
186
+ description: override?.description ?? tool.description,
187
+ overrideResponse:
188
+ override?.overrideResponse ??
189
+ collectionPluginConfig?.overrideResponse ??
190
+ tool.overrideResponse,
191
+ },
140
192
  })
141
193
  }
142
194
  }
@@ -146,8 +198,8 @@ const sanitizeCollectionConfig = ({
146
198
  const customEntries = Object.entries(collectionPluginConfig?.tools ?? {}) as Array<
147
199
  [string, CollectionTool | undefined]
148
200
  >
149
- for (const [key, customTool] of customEntries) {
150
- if (key in COLLECTION_BUILTINS || key in COLLECTION_AUTH_BUILTINS) {
201
+ for (const [configKey, customTool] of customEntries) {
202
+ if (configKey in COLLECTION_BUILTINS || configKey in COLLECTION_AUTH_BUILTINS) {
151
203
  continue
152
204
  }
153
205
  if (!customTool) {
@@ -156,9 +208,10 @@ const sanitizeCollectionConfig = ({
156
208
  items.push({
157
209
  type: 'collectionTool',
158
210
  collectionSlug: slug,
159
- key,
160
- label: key,
161
- tool: customTool,
211
+ configKey,
212
+ label: customTool.annotations?.title ?? configKey,
213
+ mcpName: configKey,
214
+ tool: { ...customTool, access: customTool.access ?? defaultAccess },
162
215
  })
163
216
  }
164
217
 
@@ -171,30 +224,45 @@ const sanitizeGlobalConfig = ({
171
224
  }: {
172
225
  global: GlobalConfig | SanitizedGlobalConfig
173
226
  pluginConfig: MCPPluginConfig
174
- }): MCPItem[] => {
227
+ }): GlobalMCPItem[] => {
175
228
  const slug = global.slug
176
229
  const globalPluginConfig = pluginConfig.globals?.[slug]
177
- const items: MCPItem[] = []
230
+ const items: GlobalMCPItem[] = []
178
231
 
179
- for (const [toolKey, baseTool] of GLOBAL_BUILTIN_ENTRIES) {
232
+ for (const [toolKey, { mcpName, requiresVersions, tool }] of GLOBAL_BUILTIN_ENTRIES) {
233
+ if (requiresVersions && !global.versions) {
234
+ continue
235
+ }
180
236
  const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]
181
237
  if (matchedConfigEntry === false) {
182
238
  continue
183
239
  }
240
+ const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
241
+ const annotations = { ...tool.annotations, ...override?.annotations }
184
242
  items.push({
185
243
  type: 'globalTool',
244
+ configKey: toolKey,
186
245
  globalSlug: slug,
187
- key: toolKey,
188
- label: capitalize(toolKey),
189
- tool: overrideBuiltinTool(baseTool, matchedConfigEntry, globalPluginConfig),
246
+ label: annotations.title ?? toolKey,
247
+ mcpName,
248
+ tool: {
249
+ ...tool,
250
+ access: override?.access ?? tool.access ?? defaultAccess,
251
+ annotations,
252
+ description: override?.description ?? tool.description,
253
+ overrideResponse:
254
+ override?.overrideResponse ??
255
+ globalPluginConfig?.overrideResponse ??
256
+ tool.overrideResponse,
257
+ },
190
258
  })
191
259
  }
192
260
 
193
261
  const customEntries = Object.entries(globalPluginConfig?.tools ?? {}) as Array<
194
262
  [string, GlobalTool | undefined]
195
263
  >
196
- for (const [key, customTool] of customEntries) {
197
- if (key in GLOBAL_BUILTINS) {
264
+ for (const [configKey, customTool] of customEntries) {
265
+ if (configKey in GLOBAL_BUILTINS) {
198
266
  continue
199
267
  }
200
268
  if (!customTool) {
@@ -202,38 +270,13 @@ const sanitizeGlobalConfig = ({
202
270
  }
203
271
  items.push({
204
272
  type: 'globalTool',
273
+ configKey,
205
274
  globalSlug: slug,
206
- key,
207
- label: key,
208
- tool: customTool,
275
+ label: customTool.annotations?.title ?? configKey,
276
+ mcpName: configKey,
277
+ tool: { ...customTool, access: customTool.access ?? defaultAccess },
209
278
  })
210
279
  }
211
280
 
212
281
  return items
213
282
  }
214
-
215
- const capitalize = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1)
216
-
217
- /**
218
- * Spread the static built-in tool and apply consumer-side overrides.
219
- * Precedence: per-tool override > scope-level (collection/global) override >
220
- * the static tool's defaults. `toolEntry` is whatever the user put under
221
- * `tools: { find: ... }` — could be `true`, `false`, or an override object —
222
- * so it's narrowed internally.
223
- */
224
- const overrideBuiltinTool = <TTool extends CollectionTool | GlobalTool>(
225
- tool: TTool,
226
- toolOverride?: MCPBuiltInToolOverride,
227
- entityPluginConfig?: TTool extends CollectionTool
228
- ? MCPPluginCollectionConfig<any>
229
- : MCPPluginGlobalConfig,
230
- ): TTool => {
231
- return {
232
- ...tool,
233
- description: toolOverride?.description ?? entityPluginConfig?.description ?? tool.description,
234
- overrideResponse:
235
- toolOverride?.overrideResponse ??
236
- entityPluginConfig?.overrideResponse ??
237
- tool.overrideResponse,
238
- }
239
- }