@payloadcms/plugin-mcp 4.0.0-internal.2fddfc0 → 4.0.0-internal.31ba7ee

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 (199) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/defaultAccess.d.ts.map +1 -1
  3. package/dist/defineTool.d.ts +8 -8
  4. package/dist/defineTool.d.ts.map +1 -1
  5. package/dist/endpoint/access.d.ts +2 -7
  6. package/dist/endpoint/access.d.ts.map +1 -1
  7. package/dist/endpoint/access.js +6 -13
  8. package/dist/endpoint/access.js.map +1 -1
  9. package/dist/endpoint/index.d.ts +1 -1
  10. package/dist/endpoint/index.d.ts.map +1 -1
  11. package/dist/endpoint/index.js +57 -17
  12. package/dist/endpoint/index.js.map +1 -1
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +2 -2
  16. package/dist/index.js.map +1 -1
  17. package/dist/mcp/buildMcpServer.d.ts +6 -6
  18. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  19. package/dist/mcp/buildMcpServer.js +68 -34
  20. package/dist/mcp/buildMcpServer.js.map +1 -1
  21. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  22. package/dist/mcp/builtin/collections/authTools.js +80 -56
  23. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  24. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
  25. package/dist/mcp/builtin/collections/countTool.js +10 -16
  26. package/dist/mcp/builtin/collections/countTool.js.map +1 -1
  27. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
  28. package/dist/mcp/builtin/collections/countVersionsTool.js +10 -15
  29. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
  30. package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
  31. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  32. package/dist/mcp/builtin/collections/createTool.js +104 -54
  33. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  34. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  35. package/dist/mcp/builtin/collections/deleteTool.js +45 -45
  36. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  37. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
  38. package/dist/mcp/builtin/collections/duplicateTool.js +32 -39
  39. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
  40. package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
  41. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  42. package/dist/mcp/builtin/collections/fileInput.js +88 -0
  43. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  44. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
  45. package/dist/mcp/builtin/collections/findDistinctTool.js +12 -28
  46. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
  47. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  48. package/dist/mcp/builtin/collections/findTool.js +29 -48
  49. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  50. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
  51. package/dist/mcp/builtin/collections/findVersionByIDTool.js +18 -28
  52. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
  53. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
  54. package/dist/mcp/builtin/collections/findVersionsTool.js +17 -32
  55. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
  56. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  57. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +51 -11
  58. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  59. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
  60. package/dist/mcp/builtin/collections/restoreVersionTool.js +15 -28
  61. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
  62. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  63. package/dist/mcp/builtin/collections/updateTool.js +67 -87
  64. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  65. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  66. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  67. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  68. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  69. package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
  70. package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
  71. package/dist/mcp/builtin/formatEntityError.js +55 -0
  72. package/dist/mcp/builtin/formatEntityError.js.map +1 -0
  73. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  74. package/dist/mcp/builtin/getConfigInfoTool.js +5 -7
  75. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  76. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
  77. package/dist/mcp/builtin/globals/countVersionsTool.js +10 -15
  78. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
  79. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  80. package/dist/mcp/builtin/globals/findTool.js +12 -18
  81. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  82. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
  83. package/dist/mcp/builtin/globals/findVersionByIDTool.js +14 -26
  84. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
  85. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
  86. package/dist/mcp/builtin/globals/findVersionsTool.js +14 -31
  87. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
  88. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  89. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +28 -10
  90. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  91. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
  92. package/dist/mcp/builtin/globals/restoreVersionTool.js +16 -24
  93. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
  94. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  95. package/dist/mcp/builtin/globals/updateTool.js +28 -37
  96. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  97. package/dist/mcp/builtinTools.d.ts +6 -0
  98. package/dist/mcp/builtinTools.d.ts.map +1 -1
  99. package/dist/mcp/builtinTools.js +9 -3
  100. package/dist/mcp/builtinTools.js.map +1 -1
  101. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  102. package/dist/mcp/sanitizeMCPConfig.js +5 -1
  103. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  104. package/dist/stdio.d.ts +3 -4
  105. package/dist/stdio.d.ts.map +1 -1
  106. package/dist/stdio.js +65 -45
  107. package/dist/stdio.js.map +1 -1
  108. package/dist/types.d.ts +61 -13
  109. package/dist/types.d.ts.map +1 -1
  110. package/dist/types.js +2 -4
  111. package/dist/types.js.map +1 -1
  112. package/dist/utils/camelCase.d.ts.map +1 -1
  113. package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
  114. package/dist/utils/toStandardSchema.d.ts.map +1 -1
  115. package/package.json +9 -13
  116. package/src/endpoint/access.ts +5 -13
  117. package/src/endpoint/index.ts +45 -16
  118. package/src/index.ts +4 -4
  119. package/src/mcp/buildMcpServer.ts +80 -50
  120. package/src/mcp/builtin/collections/authTools.ts +80 -69
  121. package/src/mcp/builtin/collections/countTool.ts +10 -23
  122. package/src/mcp/builtin/collections/countVersionsTool.ts +10 -20
  123. package/src/mcp/builtin/collections/createTool.ts +110 -77
  124. package/src/mcp/builtin/collections/deleteTool.ts +36 -65
  125. package/src/mcp/builtin/collections/duplicateTool.ts +36 -87
  126. package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
  127. package/src/mcp/builtin/collections/fileInput.ts +127 -0
  128. package/src/mcp/builtin/collections/findDistinctTool.ts +12 -65
  129. package/src/mcp/builtin/collections/findTool.ts +25 -108
  130. package/src/mcp/builtin/collections/findVersionByIDTool.ts +16 -60
  131. package/src/mcp/builtin/collections/findVersionsTool.ts +15 -87
  132. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +48 -14
  133. package/src/mcp/builtin/collections/restoreVersionTool.ts +15 -58
  134. package/src/mcp/builtin/collections/updateTool.ts +63 -101
  135. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  136. package/src/mcp/builtin/formatEntityError.ts +77 -0
  137. package/src/mcp/builtin/getConfigInfoTool.ts +4 -5
  138. package/src/mcp/builtin/globals/countVersionsTool.ts +10 -19
  139. package/src/mcp/builtin/globals/findTool.ts +14 -53
  140. package/src/mcp/builtin/globals/findVersionByIDTool.ts +14 -54
  141. package/src/mcp/builtin/globals/findVersionsTool.ts +15 -94
  142. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +30 -8
  143. package/src/mcp/builtin/globals/restoreVersionTool.ts +15 -47
  144. package/src/mcp/builtin/globals/updateTool.ts +39 -62
  145. package/src/mcp/builtinTools.ts +9 -2
  146. package/src/mcp/sanitizeMCPConfig.ts +5 -1
  147. package/src/stdio.ts +63 -45
  148. package/src/types.ts +61 -13
  149. package/dist/@types/assets.d.js +0 -2
  150. package/dist/@types/assets.d.js.map +0 -1
  151. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
  152. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
  153. package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
  154. package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
  155. package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
  156. package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
  157. package/dist/mcp/builtin/validateEntityData.js +0 -82
  158. package/dist/mcp/builtin/validateEntityData.js.map +0 -1
  159. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  160. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  161. package/dist/utils/getVirtualFieldNames.js +0 -35
  162. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  163. package/dist/utils/localAPIDefaults.d.ts +0 -20
  164. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  165. package/dist/utils/localAPIDefaults.js +0 -19
  166. package/dist/utils/localAPIDefaults.js.map +0 -1
  167. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -11
  168. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
  169. package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -34
  170. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
  171. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  172. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  173. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  174. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  175. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -15
  176. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
  177. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -464
  178. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
  179. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -158
  180. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
  181. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  182. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  183. package/dist/utils/transformPointDataToPayload.js +0 -28
  184. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  185. package/dist/utils/whereSchema.d.ts +0 -9
  186. package/dist/utils/whereSchema.d.ts.map +0 -1
  187. package/dist/utils/whereSchema.js +0 -13
  188. package/dist/utils/whereSchema.js.map +0 -1
  189. package/src/@types/assets.d.ts +0 -3
  190. package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
  191. package/src/mcp/builtin/validateEntityData.ts +0 -132
  192. package/src/utils/getVirtualFieldNames.ts +0 -53
  193. package/src/utils/localAPIDefaults.ts +0 -22
  194. package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -78
  195. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  196. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -103
  197. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -529
  198. package/src/utils/transformPointDataToPayload.ts +0 -40
  199. package/src/utils/whereSchema.ts +0 -24
package/src/types.ts CHANGED
@@ -15,7 +15,6 @@ import type {
15
15
  MaybePromise,
16
16
  PayloadRequest,
17
17
  SanitizedPermissions,
18
- TypedUser,
19
18
  } from 'payload'
20
19
 
21
20
  import type { GetAuthorizedMCPArgs } from './endpoint/access.js'
@@ -32,7 +31,8 @@ export type { JsonSchemaType, StandardSchemaWithJSON, ToolAnnotations }
32
31
 
33
32
  /**
34
33
  * What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw
35
- * JSON Schema literal, or a Standard Schema instance (Zod, Valibot, …).
34
+ * JSON Schema 2020-12 literal, or a Standard Schema instance (Zod, Valibot, …).
35
+ * Raw schemas may omit `$schema`; when present it must declare the 2020-12 dialect.
36
36
  */
37
37
  export type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON
38
38
 
@@ -52,6 +52,13 @@ export type MCPResponseOverride = (
52
52
  req: PayloadRequest,
53
53
  ) => MCPToolResponse
54
54
 
55
+ export type MCPAfterToolCallHook = (args: {
56
+ input: unknown
57
+ req: PayloadRequest
58
+ response: MCPToolResponse
59
+ toolName: string
60
+ }) => MaybePromise<MCPToolResponse>
61
+
55
62
  /**
56
63
  * The handler's `input` type. A specific Standard Schema (Zod, Valibot, …) gets
57
64
  * its inferred output; anything else falls back to `Record<string, unknown>`.
@@ -68,11 +75,11 @@ export type MCPAccessArgs = {
68
75
  }
69
76
 
70
77
  export type CollectionMCPAccessArgs = {
71
- collectionSlug: CollectionSlug
78
+ slug: CollectionSlug
72
79
  } & MCPAccessArgs
73
80
 
74
81
  export type GlobalMCPAccessArgs = {
75
- globalSlug: GlobalSlug
82
+ slug: GlobalSlug
76
83
  } & MCPAccessArgs
77
84
 
78
85
  export type ToolHandlerArgs<TSchema = undefined> = {
@@ -83,14 +90,19 @@ export type ToolHandlerArgs<TSchema = undefined> = {
83
90
  }
84
91
 
85
92
  export type CollectionToolHandlerArgs<TSchema = undefined> = {
86
- collectionSlug: CollectionSlug
93
+ slug: CollectionSlug
87
94
  } & ToolHandlerArgs<TSchema>
88
95
 
89
96
  export type GlobalToolHandlerArgs<TSchema = undefined> = {
90
- globalSlug: GlobalSlug
97
+ slug: GlobalSlug
91
98
  } & ToolHandlerArgs<TSchema>
92
99
 
93
100
  export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
101
+ /**
102
+ * Runs while authorizing each MCP request, before the tool is advertised or called. Return
103
+ * `false` to make the tool unavailable for that request. This is skipped when `overrideAccess`
104
+ * is enabled.
105
+ */
94
106
  access?: (args: MCPAccessArgs) => MaybePromise<boolean>
95
107
  annotations?: ToolAnnotations
96
108
  description: string
@@ -105,6 +117,12 @@ export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema |
105
117
  export type CollectionTool<
106
118
  TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,
107
119
  > = {
120
+ /**
121
+ * Runs while authorizing each MCP request for this collection. Return `false` to reject calls
122
+ * to this tool for the collection. The shared tool is not advertised when no collections allow
123
+ * it, but can remain advertised when it is available for another collection. This is skipped
124
+ * when `overrideAccess` is enabled.
125
+ */
108
126
  access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>
109
127
  handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
110
128
  input?: TSchema
@@ -112,6 +130,12 @@ export type CollectionTool<
112
130
 
113
131
  export type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> =
114
132
  {
133
+ /**
134
+ * Runs while authorizing each MCP request for this global. Return `false` to reject calls to
135
+ * this tool for the global. The shared tool is not advertised when no globals allow it, but
136
+ * can remain advertised when it is available for another global. This is skipped when
137
+ * `overrideAccess` is enabled.
138
+ */
115
139
  access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>
116
140
  handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
117
141
  input?: TSchema
@@ -123,6 +147,10 @@ export type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSc
123
147
  * required handler) from being silently accepted at a built-in key slot.
124
148
  */
125
149
  export type MCPBuiltInCollectionToolOverride = {
150
+ /**
151
+ * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
152
+ * this collection. This is skipped when `overrideAccess` is enabled.
153
+ */
126
154
  access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>
127
155
  annotations?: ToolAnnotations
128
156
  description?: string
@@ -131,6 +159,10 @@ export type MCPBuiltInCollectionToolOverride = {
131
159
  }
132
160
 
133
161
  export type MCPBuiltInGlobalToolOverride = {
162
+ /**
163
+ * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
164
+ * this global. This is skipped when `overrideAccess` is enabled.
165
+ */
134
166
  access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>
135
167
  annotations?: ToolAnnotations
136
168
  description?: string
@@ -175,6 +207,11 @@ export type PromptHandlerArgs<TSchema = undefined> = {
175
207
  }
176
208
 
177
209
  export type Prompt<TSchema extends ToolInputSchema = ToolInputSchema> = {
210
+ /**
211
+ * Runs while authorizing each MCP request, before the prompt is advertised or used. Return
212
+ * `false` to make the prompt unavailable for that request. This is skipped when
213
+ * `overrideAccess` is enabled.
214
+ */
178
215
  access?: (args: MCPAccessArgs) => MaybePromise<boolean>
179
216
  argsSchema: TSchema
180
217
  description: string
@@ -193,6 +230,11 @@ export type ResourceHandlerArgs = {
193
230
  }
194
231
 
195
232
  export type Resource = {
233
+ /**
234
+ * Runs while authorizing each MCP request, before the resource is advertised or read. Return
235
+ * `false` to make the resource unavailable for that request. This is skipped when
236
+ * `overrideAccess` is enabled.
237
+ */
196
238
  access?: (args: MCPAccessArgs) => MaybePromise<boolean>
197
239
  description: string
198
240
  handler: (args: ResourceHandlerArgs) => MaybePromise<{
@@ -232,11 +274,20 @@ export type MCPPluginConfig = {
232
274
  globals?: {
233
275
  [Slug in GlobalSlug]?: MCPPluginGlobalConfig
234
276
  }
277
+ hooks?: {
278
+ /** Transform a tool response after its handler returns */
279
+ afterToolCall?: MCPAfterToolCallHook[]
280
+ }
235
281
  mcp?: {
236
282
  serverOptions?: MCPServerOptions
237
283
  verboseLogs?: boolean
238
284
  }
239
- /** Replace the default MCP authorization resolver. */
285
+ /**
286
+ * Replace the default MCP authorization resolver.
287
+ *
288
+ * This hook replaces the default authentication flow. It must set `req.user` to the
289
+ * authenticated Payload user, or to `null` for an anonymous caller, before returning.
290
+ */
240
291
  overrideGetAuthorizedMCP?: (
241
292
  args: {
242
293
  pluginConfig: SanitizedMCPPluginConfig
@@ -250,7 +301,7 @@ export type MCPPluginConfig = {
250
301
 
251
302
  export type SanitizedMCPPluginConfig = {
252
303
  items: MCPItem[]
253
- } & Pick<MCPPluginConfig, 'disabled' | 'mcp' | 'overrideGetAuthorizedMCP'>
304
+ } & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>
254
305
 
255
306
  export type MCPServerOptions = {
256
307
  options?: ConstructorParameters<typeof McpServer>[1]
@@ -300,13 +351,10 @@ export type MCPItem =
300
351
  | GlobalMCPItem
301
352
 
302
353
  /**
303
- * The caller's identity + the MCP items authorized for this request. Disabled
304
- * items and items blocked by access callbacks or Payload operation access are
305
- * absent from `items`. Tool handlers receive this via `args.authorizedMCP` so
306
- * they can spread `localAPIDefaults(authorizedMCP)` into every local API call.
354
+ * The MCP items and access mode authorized for this request. The authenticated user is available
355
+ * as `req.user`.
307
356
  */
308
357
  export type AuthorizedMCP = {
309
358
  items: MCPItem[]
310
359
  overrideAccess: boolean
311
- user: null | TypedUser
312
360
  }
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=assets.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/@types/assets.d.ts"],"names":[],"mappings":""}
@@ -1,9 +0,0 @@
1
- import type { CollectionSlug, PayloadRequest } from 'payload';
2
- import type { MCPToolResponse } from '../../../types.js';
3
- export declare const formatCollectionError: ({ action, collectionSlug, error, req, }: {
4
- action: "creating" | "duplicating" | "updating";
5
- collectionSlug: CollectionSlug;
6
- error: unknown;
7
- req: PayloadRequest;
8
- }) => MCPToolResponse;
9
- //# sourceMappingURL=formatCollectionError.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatCollectionError.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/formatCollectionError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAgCxD,eAAO,MAAM,qBAAqB,GAAI,yCAKnC;IACD,MAAM,EAAE,UAAU,GAAG,aAAa,GAAG,UAAU,CAAA;IAC/C,cAAc,EAAE,cAAc,CAAA;IAC9B,KAAK,EAAE,OAAO,CAAA;IACd,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAuCH,CAAA"}
@@ -1,60 +0,0 @@
1
- import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
2
- const getValidationErrors = (error)=>{
3
- if (!error || typeof error !== 'object') {
4
- return undefined;
5
- }
6
- const data = 'data' in error ? error.data : undefined;
7
- if (!data || typeof data !== 'object' || !('errors' in data) || !Array.isArray(data.errors)) {
8
- return undefined;
9
- }
10
- return data.errors;
11
- };
12
- const isSchemaError = (error, message)=>{
13
- if (getValidationErrors(error)) {
14
- return true;
15
- }
16
- const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined;
17
- return name === 'CastError' || name === 'ValidationError' || message.includes('Cast to ') || message.includes('validation failed');
18
- };
19
- export const formatCollectionError = ({ action, collectionSlug, error, req })=>{
20
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
21
- const errors = getValidationErrors(error) ?? [
22
- {
23
- message: errorMessage
24
- }
25
- ];
26
- if (!isSchemaError(error, errorMessage)) {
27
- return {
28
- content: [
29
- {
30
- type: 'text',
31
- text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}`
32
- }
33
- ],
34
- isError: true
35
- };
36
- }
37
- const schema = getCollectionInputSchema({
38
- collectionSlug,
39
- req
40
- });
41
- const schemaText = schema ? `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\`` : '';
42
- return {
43
- content: [
44
- {
45
- type: 'text',
46
- text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}${schemaText}`
47
- }
48
- ],
49
- isError: true,
50
- ...schema ? {
51
- structuredContent: {
52
- collectionSlug,
53
- errors,
54
- schema
55
- }
56
- } : {}
57
- };
58
- };
59
-
60
- //# sourceMappingURL=formatCollectionError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/formatCollectionError.ts"],"sourcesContent":["import type { CollectionSlug, PayloadRequest } from 'payload'\n\nimport type { MCPToolResponse } from '../../../types.js'\n\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nconst getValidationErrors = (error: unknown): undefined | unknown[] => {\n if (!error || typeof error !== 'object') {\n return undefined\n }\n\n const data = 'data' in error ? error.data : undefined\n if (!data || typeof data !== 'object' || !('errors' in data) || !Array.isArray(data.errors)) {\n return undefined\n }\n\n return data.errors\n}\n\nconst isSchemaError = (error: unknown, message: string): boolean => {\n if (getValidationErrors(error)) {\n return true\n }\n\n const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined\n\n return (\n name === 'CastError' ||\n name === 'ValidationError' ||\n message.includes('Cast to ') ||\n message.includes('validation failed')\n )\n}\n\nexport const formatCollectionError = ({\n action,\n collectionSlug,\n error,\n req,\n}: {\n action: 'creating' | 'duplicating' | 'updating'\n collectionSlug: CollectionSlug\n error: unknown\n req: PayloadRequest\n}): MCPToolResponse => {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n const errors = getValidationErrors(error) ?? [{ message: errorMessage }]\n\n if (!isSchemaError(error, errorMessage)) {\n return {\n content: [\n {\n type: 'text',\n text: `Error ${action} document in collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n\n const schema = getCollectionInputSchema({ collectionSlug, req })\n const schemaText = schema\n ? `\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(schema)}\\n\\`\\`\\``\n : ''\n\n return {\n content: [\n {\n type: 'text',\n text: `Error ${action} document in collection \"${collectionSlug}\": ${errorMessage}${schemaText}`,\n },\n ],\n isError: true,\n ...(schema\n ? {\n structuredContent: {\n collectionSlug,\n errors,\n schema,\n },\n }\n : {}),\n }\n}\n"],"names":["getCollectionInputSchema","getValidationErrors","error","undefined","data","Array","isArray","errors","isSchemaError","message","name","includes","formatCollectionError","action","collectionSlug","req","errorMessage","Error","content","type","text","isError","schema","schemaText","JSON","stringify","structuredContent"],"mappings":"AAIA,SAASA,wBAAwB,QAAQ,0DAAyD;AAElG,MAAMC,sBAAsB,CAACC;IAC3B,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAOC;IACT;IAEA,MAAMC,OAAO,UAAUF,QAAQA,MAAME,IAAI,GAAGD;IAC5C,IAAI,CAACC,QAAQ,OAAOA,SAAS,YAAY,CAAE,CAAA,YAAYA,IAAG,KAAM,CAACC,MAAMC,OAAO,CAACF,KAAKG,MAAM,GAAG;QAC3F,OAAOJ;IACT;IAEA,OAAOC,KAAKG,MAAM;AACpB;AAEA,MAAMC,gBAAgB,CAACN,OAAgBO;IACrC,IAAIR,oBAAoBC,QAAQ;QAC9B,OAAO;IACT;IAEA,MAAMQ,OAAOR,SAAS,OAAOA,UAAU,YAAY,UAAUA,QAAQA,MAAMQ,IAAI,GAAGP;IAElF,OACEO,SAAS,eACTA,SAAS,qBACTD,QAAQE,QAAQ,CAAC,eACjBF,QAAQE,QAAQ,CAAC;AAErB;AAEA,OAAO,MAAMC,wBAAwB,CAAC,EACpCC,MAAM,EACNC,cAAc,EACdZ,KAAK,EACLa,GAAG,EAMJ;IACC,MAAMC,eAAed,iBAAiBe,QAAQf,MAAMO,OAAO,GAAG;IAC9D,MAAMF,SAASN,oBAAoBC,UAAU;QAAC;YAAEO,SAASO;QAAa;KAAE;IAExE,IAAI,CAACR,cAAcN,OAAOc,eAAe;QACvC,OAAO;YACLE,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,MAAM,EAAEP,OAAO,yBAAyB,EAAEC,eAAe,GAAG,EAAEE,cAAc;gBACrF;aACD;YACDK,SAAS;QACX;IACF;IAEA,MAAMC,SAAStB,yBAAyB;QAAEc;QAAgBC;IAAI;IAC9D,MAAMQ,aAAaD,SACf,CAAC,2CAA2C,EAAEE,KAAKC,SAAS,CAACH,QAAQ,QAAQ,CAAC,GAC9E;IAEJ,OAAO;QACLJ,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,MAAM,EAAEP,OAAO,yBAAyB,EAAEC,eAAe,GAAG,EAAEE,eAAeO,YAAY;YAClG;SACD;QACDF,SAAS;QACT,GAAIC,SACA;YACEI,mBAAmB;gBACjBZ;gBACAP;gBACAe;YACF;QACF,IACA,CAAC,CAAC;IACR;AACF,EAAC"}
@@ -1,14 +0,0 @@
1
- import type { CollectionSlug, GlobalSlug, PayloadRequest } from 'payload';
2
- import type { MCPToolResponse } from '../../types.js';
3
- export declare const validateCollectionData: ({ collectionSlug, data, partial, req, }: {
4
- collectionSlug: CollectionSlug;
5
- data: Record<string, unknown>;
6
- partial?: boolean;
7
- req: PayloadRequest;
8
- }) => MCPToolResponse | null;
9
- export declare const validateGlobalData: ({ data, globalSlug, req, }: {
10
- data: Record<string, unknown>;
11
- globalSlug: GlobalSlug;
12
- req: PayloadRequest;
13
- }) => MCPToolResponse | null;
14
- //# sourceMappingURL=validateEntityData.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validateEntityData.d.ts","sourceRoot":"","sources":["../../../src/mcp/builtin/validateEntityData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAmB,MAAM,SAAS,CAAA;AAI1F,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAuBrE,eAAO,MAAM,sBAAsB,GAAI,yCAKpC;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAAe,GAAG,IAQlB,CAAA;AAEJ,eAAO,MAAM,kBAAkB,GAAI,4BAIhC;IACD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,UAAU,EAAE,UAAU,CAAA;IACtB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAAe,GAAG,IAQlB,CAAA"}
@@ -1,82 +0,0 @@
1
- import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server';
2
- import { getCollectionInputSchema, getGlobalInputSchema } from '../../utils/schemaConversion/getEntityInputSchema.js';
3
- /**
4
- * Keep the default `shortcircuit: true` - `false` makes validating nested rich text exponentially slow.
5
- */ const validator = new CfWorkerJsonSchemaValidator({
6
- shortcircuit: true
7
- });
8
- /**
9
- * - Caches each entity's schema and validator, so both are only built on the first request.
10
- * - Keyed by payload config, then by entity type, slug, partial and language.
11
- */ const validatorCache = new WeakMap();
12
- export const validateCollectionData = ({ collectionSlug, data, partial, req })=>validateData({
13
- slug: collectionSlug,
14
- buildSchema: ()=>getCollectionInputSchema({
15
- collectionSlug,
16
- req
17
- }),
18
- data,
19
- entity: 'collection',
20
- partial,
21
- req
22
- });
23
- export const validateGlobalData = ({ data, globalSlug, req })=>validateData({
24
- slug: globalSlug,
25
- buildSchema: ()=>getGlobalInputSchema({
26
- globalSlug,
27
- req
28
- }),
29
- data,
30
- entity: 'global',
31
- partial: true,
32
- req
33
- });
34
- const validateData = ({ slug, buildSchema, data, entity, partial, req })=>{
35
- let cache = validatorCache.get(req.payload.config);
36
- if (!cache) {
37
- cache = new Map();
38
- validatorCache.set(req.payload.config, cache);
39
- }
40
- const cacheKey = `${entity}:${slug}:${partial ? 'partial' : 'full'}:${req.i18n.language}`;
41
- let entityValidator = cache.get(cacheKey);
42
- if (!entityValidator) {
43
- const schema = buildSchema();
44
- if (!schema) {
45
- return null;
46
- }
47
- entityValidator = {
48
- schema,
49
- validate: validator.getValidator(partial ? withoutRequired(schema) : schema)
50
- };
51
- cache.set(cacheKey, entityValidator);
52
- }
53
- const result = entityValidator.validate(data);
54
- if (result.valid) {
55
- return null;
56
- }
57
- const { schema } = entityValidator;
58
- return {
59
- content: [
60
- {
61
- type: 'text',
62
- text: `Invalid data for ${entity} "${slug}": ${result.errorMessage}\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\``
63
- }
64
- ],
65
- isError: true,
66
- structuredContent: {
67
- [`${entity}Slug`]: slug,
68
- errors: [
69
- {
70
- message: result.errorMessage
71
- }
72
- ],
73
- schema
74
- }
75
- };
76
- };
77
- /** Updates are partial — drop the schema's top-level `required` before validating. */ const withoutRequired = (schema)=>{
78
- const { required: _required, ...rest } = schema;
79
- return rest;
80
- };
81
-
82
- //# sourceMappingURL=validateEntityData.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/mcp/builtin/validateEntityData.ts"],"sourcesContent":["import type { CollectionSlug, GlobalSlug, PayloadRequest, SanitizedConfig } from 'payload'\n\nimport { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server'\n\nimport type { JsonSchemaType, MCPToolResponse } from '../../types.js'\n\nimport {\n getCollectionInputSchema,\n getGlobalInputSchema,\n} from '../../utils/schemaConversion/getEntityInputSchema.js'\n\n/**\n * Keep the default `shortcircuit: true` - `false` makes validating nested rich text exponentially slow.\n */\nconst validator = new CfWorkerJsonSchemaValidator({ shortcircuit: true })\n\ntype EntityValidator = {\n schema: JsonSchemaType\n validate: ReturnType<(typeof validator)['getValidator']>\n}\n\n/**\n * - Caches each entity's schema and validator, so both are only built on the first request.\n * - Keyed by payload config, then by entity type, slug, partial and language.\n */\nconst validatorCache = new WeakMap<SanitizedConfig, Map<string, EntityValidator>>()\n\nexport const validateCollectionData = ({\n collectionSlug,\n data,\n partial,\n req,\n}: {\n collectionSlug: CollectionSlug\n data: Record<string, unknown>\n partial?: boolean\n req: PayloadRequest\n}): MCPToolResponse | null =>\n validateData({\n slug: collectionSlug,\n buildSchema: () => getCollectionInputSchema({ collectionSlug, req }),\n data,\n entity: 'collection',\n partial,\n req,\n })\n\nexport const validateGlobalData = ({\n data,\n globalSlug,\n req,\n}: {\n data: Record<string, unknown>\n globalSlug: GlobalSlug\n req: PayloadRequest\n}): MCPToolResponse | null =>\n validateData({\n slug: globalSlug,\n buildSchema: () => getGlobalInputSchema({ globalSlug, req }),\n data,\n entity: 'global',\n partial: true,\n req,\n })\n\nconst validateData = ({\n slug,\n buildSchema,\n data,\n entity,\n partial,\n req,\n}: {\n buildSchema: () => JsonSchemaType | null\n data: Record<string, unknown>\n entity: 'collection' | 'global'\n partial?: boolean\n req: PayloadRequest\n slug: string\n}): MCPToolResponse | null => {\n let cache = validatorCache.get(req.payload.config)\n if (!cache) {\n cache = new Map()\n validatorCache.set(req.payload.config, cache)\n }\n\n const cacheKey = `${entity}:${slug}:${partial ? 'partial' : 'full'}:${req.i18n.language}`\n let entityValidator = cache.get(cacheKey)\n\n if (!entityValidator) {\n const schema = buildSchema()\n\n if (!schema) {\n return null\n }\n\n entityValidator = {\n schema,\n validate: validator.getValidator(partial ? withoutRequired(schema) : schema),\n }\n cache.set(cacheKey, entityValidator)\n }\n\n const result = entityValidator.validate(data)\n\n if (result.valid) {\n return null\n }\n\n const { schema } = entityValidator\n\n return {\n content: [\n {\n type: 'text',\n text: `Invalid data for ${entity} \"${slug}\": ${result.errorMessage}\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(schema)}\\n\\`\\`\\``,\n },\n ],\n isError: true,\n structuredContent: {\n [`${entity}Slug`]: slug,\n errors: [{ message: result.errorMessage }],\n schema,\n },\n }\n}\n\n/** Updates are partial — drop the schema's top-level `required` before validating. */\nconst withoutRequired = (schema: JsonSchemaType): JsonSchemaType => {\n const { required: _required, ...rest } = schema\n return rest\n}\n"],"names":["CfWorkerJsonSchemaValidator","getCollectionInputSchema","getGlobalInputSchema","validator","shortcircuit","validatorCache","WeakMap","validateCollectionData","collectionSlug","data","partial","req","validateData","slug","buildSchema","entity","validateGlobalData","globalSlug","cache","get","payload","config","Map","set","cacheKey","i18n","language","entityValidator","schema","validate","getValidator","withoutRequired","result","valid","content","type","text","errorMessage","JSON","stringify","isError","structuredContent","errors","message","required","_required","rest"],"mappings":"AAEA,SAASA,2BAA2B,QAAQ,+BAA8B;AAI1E,SACEC,wBAAwB,EACxBC,oBAAoB,QACf,uDAAsD;AAE7D;;CAEC,GACD,MAAMC,YAAY,IAAIH,4BAA4B;IAAEI,cAAc;AAAK;AAOvE;;;CAGC,GACD,MAAMC,iBAAiB,IAAIC;AAE3B,OAAO,MAAMC,yBAAyB,CAAC,EACrCC,cAAc,EACdC,IAAI,EACJC,OAAO,EACPC,GAAG,EAMJ,GACCC,aAAa;QACXC,MAAML;QACNM,aAAa,IAAMb,yBAAyB;gBAAEO;gBAAgBG;YAAI;QAClEF;QACAM,QAAQ;QACRL;QACAC;IACF,GAAE;AAEJ,OAAO,MAAMK,qBAAqB,CAAC,EACjCP,IAAI,EACJQ,UAAU,EACVN,GAAG,EAKJ,GACCC,aAAa;QACXC,MAAMI;QACNH,aAAa,IAAMZ,qBAAqB;gBAAEe;gBAAYN;YAAI;QAC1DF;QACAM,QAAQ;QACRL,SAAS;QACTC;IACF,GAAE;AAEJ,MAAMC,eAAe,CAAC,EACpBC,IAAI,EACJC,WAAW,EACXL,IAAI,EACJM,MAAM,EACNL,OAAO,EACPC,GAAG,EAQJ;IACC,IAAIO,QAAQb,eAAec,GAAG,CAACR,IAAIS,OAAO,CAACC,MAAM;IACjD,IAAI,CAACH,OAAO;QACVA,QAAQ,IAAII;QACZjB,eAAekB,GAAG,CAACZ,IAAIS,OAAO,CAACC,MAAM,EAAEH;IACzC;IAEA,MAAMM,WAAW,GAAGT,OAAO,CAAC,EAAEF,KAAK,CAAC,EAAEH,UAAU,YAAY,OAAO,CAAC,EAAEC,IAAIc,IAAI,CAACC,QAAQ,EAAE;IACzF,IAAIC,kBAAkBT,MAAMC,GAAG,CAACK;IAEhC,IAAI,CAACG,iBAAiB;QACpB,MAAMC,SAASd;QAEf,IAAI,CAACc,QAAQ;YACX,OAAO;QACT;QAEAD,kBAAkB;YAChBC;YACAC,UAAU1B,UAAU2B,YAAY,CAACpB,UAAUqB,gBAAgBH,UAAUA;QACvE;QACAV,MAAMK,GAAG,CAACC,UAAUG;IACtB;IAEA,MAAMK,SAASL,gBAAgBE,QAAQ,CAACpB;IAExC,IAAIuB,OAAOC,KAAK,EAAE;QAChB,OAAO;IACT;IAEA,MAAM,EAAEL,MAAM,EAAE,GAAGD;IAEnB,OAAO;QACLO,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,iBAAiB,EAAErB,OAAO,EAAE,EAAEF,KAAK,GAAG,EAAEmB,OAAOK,YAAY,CAAC,2CAA2C,EAAEC,KAAKC,SAAS,CAACX,QAAQ,QAAQ,CAAC;YAClJ;SACD;QACDY,SAAS;QACTC,mBAAmB;YACjB,CAAC,GAAG1B,OAAO,IAAI,CAAC,CAAC,EAAEF;YACnB6B,QAAQ;gBAAC;oBAAEC,SAASX,OAAOK,YAAY;gBAAC;aAAE;YAC1CT;QACF;IACF;AACF;AAEA,oFAAoF,GACpF,MAAMG,kBAAkB,CAACH;IACvB,MAAM,EAAEgB,UAAUC,SAAS,EAAE,GAAGC,MAAM,GAAGlB;IACzC,OAAOkB;AACT"}
@@ -1,14 +0,0 @@
1
- import type { SanitizedConfig } from 'payload';
2
- /**
3
- * Returns the names of all top-level virtual fields for a given collection slug.
4
- */
5
- export declare function getCollectionVirtualFieldNames(config: SanitizedConfig, slug: string): string[];
6
- /**
7
- * Returns the names of all top-level virtual fields for a given global slug.
8
- */
9
- export declare function getGlobalVirtualFieldNames(config: SanitizedConfig, slug: string): string[];
10
- /**
11
- * Strips virtual field values from a data object given a list of virtual field names.
12
- */
13
- export declare function stripVirtualFields(data: Record<string, unknown>, virtualFieldNames: string[]): Record<string, unknown>;
14
- //# sourceMappingURL=getVirtualFieldNames.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getVirtualFieldNames.d.ts","sourceRoot":"","sources":["../../src/utils/getVirtualFieldNames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAU9F;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAU1F;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,iBAAiB,EAAE,MAAM,EAAE,GAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB"}
@@ -1,35 +0,0 @@
1
- import { fieldIsVirtual } from 'payload/shared';
2
- /**
3
- * Returns the names of all top-level virtual fields for a given collection slug.
4
- */ export function getCollectionVirtualFieldNames(config, slug) {
5
- const collection = config.collections.find((c)=>c.slug === slug);
6
- if (!collection) {
7
- return [];
8
- }
9
- return collection.flattenedFields.filter((field)=>'name' in field && fieldIsVirtual(field)).map((field)=>field.name);
10
- }
11
- /**
12
- * Returns the names of all top-level virtual fields for a given global slug.
13
- */ export function getGlobalVirtualFieldNames(config, slug) {
14
- const global = config.globals.find((g)=>g.slug === slug);
15
- if (!global) {
16
- return [];
17
- }
18
- return global.flattenedFields.filter((field)=>'name' in field && fieldIsVirtual(field)).map((field)=>field.name);
19
- }
20
- /**
21
- * Strips virtual field values from a data object given a list of virtual field names.
22
- */ export function stripVirtualFields(data, virtualFieldNames) {
23
- if (virtualFieldNames.length === 0) {
24
- return data;
25
- }
26
- const stripped = {
27
- ...data
28
- };
29
- for (const name of virtualFieldNames){
30
- delete stripped[name];
31
- }
32
- return stripped;
33
- }
34
-
35
- //# sourceMappingURL=getVirtualFieldNames.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/getVirtualFieldNames.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport { fieldIsVirtual } from 'payload/shared'\n\n/**\n * Returns the names of all top-level virtual fields for a given collection slug.\n */\nexport function getCollectionVirtualFieldNames(config: SanitizedConfig, slug: string): string[] {\n const collection = config.collections.find((c) => c.slug === slug)\n\n if (!collection) {\n return []\n }\n\n return collection.flattenedFields\n .filter((field) => 'name' in field && fieldIsVirtual(field))\n .map((field) => (field as { name: string }).name)\n}\n\n/**\n * Returns the names of all top-level virtual fields for a given global slug.\n */\nexport function getGlobalVirtualFieldNames(config: SanitizedConfig, slug: string): string[] {\n const global = config.globals.find((g) => g.slug === slug)\n\n if (!global) {\n return []\n }\n\n return global.flattenedFields\n .filter((field) => 'name' in field && fieldIsVirtual(field))\n .map((field) => (field as { name: string }).name)\n}\n\n/**\n * Strips virtual field values from a data object given a list of virtual field names.\n */\nexport function stripVirtualFields(\n data: Record<string, unknown>,\n virtualFieldNames: string[],\n): Record<string, unknown> {\n if (virtualFieldNames.length === 0) {\n return data\n }\n\n const stripped = { ...data }\n\n for (const name of virtualFieldNames) {\n delete stripped[name]\n }\n\n return stripped\n}\n"],"names":["fieldIsVirtual","getCollectionVirtualFieldNames","config","slug","collection","collections","find","c","flattenedFields","filter","field","map","name","getGlobalVirtualFieldNames","global","globals","g","stripVirtualFields","data","virtualFieldNames","length","stripped"],"mappings":"AAEA,SAASA,cAAc,QAAQ,iBAAgB;AAE/C;;CAEC,GACD,OAAO,SAASC,+BAA+BC,MAAuB,EAAEC,IAAY;IAClF,MAAMC,aAAaF,OAAOG,WAAW,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEJ,IAAI,KAAKA;IAE7D,IAAI,CAACC,YAAY;QACf,OAAO,EAAE;IACX;IAEA,OAAOA,WAAWI,eAAe,CAC9BC,MAAM,CAAC,CAACC,QAAU,UAAUA,SAASV,eAAeU,QACpDC,GAAG,CAAC,CAACD,QAAU,AAACA,MAA2BE,IAAI;AACpD;AAEA;;CAEC,GACD,OAAO,SAASC,2BAA2BX,MAAuB,EAAEC,IAAY;IAC9E,MAAMW,SAASZ,OAAOa,OAAO,CAACT,IAAI,CAAC,CAACU,IAAMA,EAAEb,IAAI,KAAKA;IAErD,IAAI,CAACW,QAAQ;QACX,OAAO,EAAE;IACX;IAEA,OAAOA,OAAON,eAAe,CAC1BC,MAAM,CAAC,CAACC,QAAU,UAAUA,SAASV,eAAeU,QACpDC,GAAG,CAAC,CAACD,QAAU,AAACA,MAA2BE,IAAI;AACpD;AAEA;;CAEC,GACD,OAAO,SAASK,mBACdC,IAA6B,EAC7BC,iBAA2B;IAE3B,IAAIA,kBAAkBC,MAAM,KAAK,GAAG;QAClC,OAAOF;IACT;IAEA,MAAMG,WAAW;QAAE,GAAGH,IAAI;IAAC;IAE3B,KAAK,MAAMN,QAAQO,kBAAmB;QACpC,OAAOE,QAAQ,CAACT,KAAK;IACvB;IAEA,OAAOS;AACT"}
@@ -1,20 +0,0 @@
1
- import type { AuthorizedMCP } from '../types.js';
2
- /**
3
- * Returns the `user` and `overrideAccess` arguments every Payload local API call
4
- * should receive when initiated from an MCP request. Spread the result into the
5
- * call's arg object so the two pieces of caller state can't drift apart.
6
- *
7
- * @example
8
- * ```ts
9
- * await req.payload.create({
10
- * collection: 'posts',
11
- * data,
12
- * ...localAPIDefaults(authorizedMCP),
13
- * })
14
- * ```
15
- */
16
- export declare const localAPIDefaults: (authorizedMCP: AuthorizedMCP) => {
17
- overrideAccess: boolean;
18
- user: AuthorizedMCP["user"];
19
- };
20
- //# sourceMappingURL=localAPIDefaults.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"localAPIDefaults.d.ts","sourceRoot":"","sources":["../../src/utils/localAPIDefaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAC3B,eAAe,aAAa,KAC3B;IAAE,cAAc,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CAGvD,CAAA"}
@@ -1,19 +0,0 @@
1
- /**
2
- * Returns the `user` and `overrideAccess` arguments every Payload local API call
3
- * should receive when initiated from an MCP request. Spread the result into the
4
- * call's arg object so the two pieces of caller state can't drift apart.
5
- *
6
- * @example
7
- * ```ts
8
- * await req.payload.create({
9
- * collection: 'posts',
10
- * data,
11
- * ...localAPIDefaults(authorizedMCP),
12
- * })
13
- * ```
14
- */ export const localAPIDefaults = (authorizedMCP)=>({
15
- overrideAccess: authorizedMCP.overrideAccess,
16
- user: authorizedMCP.user
17
- });
18
-
19
- //# sourceMappingURL=localAPIDefaults.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/localAPIDefaults.ts"],"sourcesContent":["import type { AuthorizedMCP } from '../types.js'\n\n/**\n * Returns the `user` and `overrideAccess` arguments every Payload local API call\n * should receive when initiated from an MCP request. Spread the result into the\n * call's arg object so the two pieces of caller state can't drift apart.\n *\n * @example\n * ```ts\n * await req.payload.create({\n * collection: 'posts',\n * data,\n * ...localAPIDefaults(authorizedMCP),\n * })\n * ```\n */\nexport const localAPIDefaults = (\n authorizedMCP: AuthorizedMCP,\n): { overrideAccess: boolean; user: AuthorizedMCP['user'] } => ({\n overrideAccess: authorizedMCP.overrideAccess,\n user: authorizedMCP.user,\n})\n"],"names":["localAPIDefaults","authorizedMCP","overrideAccess","user"],"mappings":"AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMA,mBAAmB,CAC9BC,gBAC8D,CAAA;QAC9DC,gBAAgBD,cAAcC,cAAc;QAC5CC,MAAMF,cAAcE,IAAI;IAC1B,CAAA,EAAE"}
@@ -1,11 +0,0 @@
1
- import { type CollectionSlug, type GlobalSlug, type PayloadRequest } from 'payload';
2
- import type { JsonSchemaType } from '../../types.js';
3
- export declare const getCollectionInputSchema: ({ collectionSlug, req, }: {
4
- collectionSlug: CollectionSlug;
5
- req: PayloadRequest;
6
- }) => JsonSchemaType | null;
7
- export declare const getGlobalInputSchema: ({ globalSlug, req, }: {
8
- globalSlug: GlobalSlug;
9
- req: PayloadRequest;
10
- }) => JsonSchemaType | null;
11
- //# sourceMappingURL=getEntityInputSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getEntityInputSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,UAAU,EACf,KAAK,cAAc,EAGpB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AASpD,eAAO,MAAM,wBAAwB,GAAI,0BAGtC;IACD,cAAc,EAAE,cAAc,CAAA;IAC9B,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAYpB,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,sBAGlC;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,cAAc,GAAG,IAYpB,CAAA"}
@@ -1,34 +0,0 @@
1
- import { entityToStandaloneJSONSchema } from 'payload';
2
- import { getCollectionVirtualFieldNames, getGlobalVirtualFieldNames } from '../getVirtualFieldNames.js';
3
- import { removeVirtualFieldsFromSchema } from './removeVirtualFieldsFromSchema.js';
4
- import { sanitizeEntitySchema } from './sanitizeEntitySchema.js';
5
- export const getCollectionInputSchema = ({ collectionSlug, req })=>{
6
- const collection = req.payload.collections[collectionSlug]?.config;
7
- if (!collection) {
8
- return null;
9
- }
10
- return buildEntityInputSchema({
11
- entity: collection,
12
- req,
13
- virtualFieldNames: getCollectionVirtualFieldNames(req.payload.config, collectionSlug)
14
- });
15
- };
16
- export const getGlobalInputSchema = ({ globalSlug, req })=>{
17
- const global = req.payload.config.globals.find((globalConfig)=>globalConfig.slug === globalSlug);
18
- if (!global) {
19
- return null;
20
- }
21
- return buildEntityInputSchema({
22
- entity: global,
23
- req,
24
- virtualFieldNames: getGlobalVirtualFieldNames(req.payload.config, globalSlug)
25
- });
26
- };
27
- const buildEntityInputSchema = ({ entity, req, virtualFieldNames })=>sanitizeEntitySchema(removeVirtualFieldsFromSchema(entityToStandaloneJSONSchema({
28
- config: req.payload.config,
29
- defaultIDType: req.payload.db.defaultIDType,
30
- entity,
31
- i18n: req.i18n
32
- }), virtualFieldNames));
33
-
34
- //# sourceMappingURL=getEntityInputSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/schemaConversion/getEntityInputSchema.ts"],"sourcesContent":["import {\n type CollectionSlug,\n entityToStandaloneJSONSchema,\n type GlobalSlug,\n type PayloadRequest,\n type SanitizedCollectionConfig,\n type SanitizedGlobalConfig,\n} from 'payload'\n\nimport type { JsonSchemaType } from '../../types.js'\n\nimport {\n getCollectionVirtualFieldNames,\n getGlobalVirtualFieldNames,\n} from '../getVirtualFieldNames.js'\nimport { removeVirtualFieldsFromSchema } from './removeVirtualFieldsFromSchema.js'\nimport { sanitizeEntitySchema } from './sanitizeEntitySchema.js'\n\nexport const getCollectionInputSchema = ({\n collectionSlug,\n req,\n}: {\n collectionSlug: CollectionSlug\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const collection = req.payload.collections[collectionSlug]?.config\n\n if (!collection) {\n return null\n }\n\n return buildEntityInputSchema({\n entity: collection,\n req,\n virtualFieldNames: getCollectionVirtualFieldNames(req.payload.config, collectionSlug),\n })\n}\n\nexport const getGlobalInputSchema = ({\n globalSlug,\n req,\n}: {\n globalSlug: GlobalSlug\n req: PayloadRequest\n}): JsonSchemaType | null => {\n const global = req.payload.config.globals.find((globalConfig) => globalConfig.slug === globalSlug)\n\n if (!global) {\n return null\n }\n\n return buildEntityInputSchema({\n entity: global,\n req,\n virtualFieldNames: getGlobalVirtualFieldNames(req.payload.config, globalSlug),\n })\n}\n\nconst buildEntityInputSchema = ({\n entity,\n req,\n virtualFieldNames,\n}: {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n req: PayloadRequest\n virtualFieldNames: string[]\n}): JsonSchemaType =>\n sanitizeEntitySchema(\n removeVirtualFieldsFromSchema(\n entityToStandaloneJSONSchema({\n config: req.payload.config,\n defaultIDType: req.payload.db.defaultIDType,\n entity,\n i18n: req.i18n,\n }) as unknown as JsonSchemaType,\n virtualFieldNames,\n ),\n )\n"],"names":["entityToStandaloneJSONSchema","getCollectionVirtualFieldNames","getGlobalVirtualFieldNames","removeVirtualFieldsFromSchema","sanitizeEntitySchema","getCollectionInputSchema","collectionSlug","req","collection","payload","collections","config","buildEntityInputSchema","entity","virtualFieldNames","getGlobalInputSchema","globalSlug","global","globals","find","globalConfig","slug","defaultIDType","db","i18n"],"mappings":"AAAA,SAEEA,4BAA4B,QAKvB,UAAS;AAIhB,SACEC,8BAA8B,EAC9BC,0BAA0B,QACrB,6BAA4B;AACnC,SAASC,6BAA6B,QAAQ,qCAAoC;AAClF,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhE,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,cAAc,EACdC,GAAG,EAIJ;IACC,MAAMC,aAAaD,IAAIE,OAAO,CAACC,WAAW,CAACJ,eAAe,EAAEK;IAE5D,IAAI,CAACH,YAAY;QACf,OAAO;IACT;IAEA,OAAOI,uBAAuB;QAC5BC,QAAQL;QACRD;QACAO,mBAAmBb,+BAA+BM,IAAIE,OAAO,CAACE,MAAM,EAAEL;IACxE;AACF,EAAC;AAED,OAAO,MAAMS,uBAAuB,CAAC,EACnCC,UAAU,EACVT,GAAG,EAIJ;IACC,MAAMU,SAASV,IAAIE,OAAO,CAACE,MAAM,CAACO,OAAO,CAACC,IAAI,CAAC,CAACC,eAAiBA,aAAaC,IAAI,KAAKL;IAEvF,IAAI,CAACC,QAAQ;QACX,OAAO;IACT;IAEA,OAAOL,uBAAuB;QAC5BC,QAAQI;QACRV;QACAO,mBAAmBZ,2BAA2BK,IAAIE,OAAO,CAACE,MAAM,EAAEK;IACpE;AACF,EAAC;AAED,MAAMJ,yBAAyB,CAAC,EAC9BC,MAAM,EACNN,GAAG,EACHO,iBAAiB,EAKlB,GACCV,qBACED,8BACEH,6BAA6B;QAC3BW,QAAQJ,IAAIE,OAAO,CAACE,MAAM;QAC1BW,eAAef,IAAIE,OAAO,CAACc,EAAE,CAACD,aAAa;QAC3CT;QACAW,MAAMjB,IAAIiB,IAAI;IAChB,IACAV"}
@@ -1,7 +0,0 @@
1
- import type { JsonSchemaType } from '../../types.js';
2
- /**
3
- * Removes virtual fields from a JSON Schema by name so they don't appear
4
- * in the generated MCP tool input schema.
5
- */
6
- export declare function removeVirtualFieldsFromSchema(schema: JsonSchemaType, virtualFieldNames: string[]): JsonSchemaType;
7
- //# sourceMappingURL=removeVirtualFieldsFromSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"removeVirtualFieldsFromSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,cAAc,EACtB,iBAAiB,EAAE,MAAM,EAAE,GAC1B,cAAc,CAiBhB"}
@@ -1,20 +0,0 @@
1
- /**
2
- * Removes virtual fields from a JSON Schema by name so they don't appear
3
- * in the generated MCP tool input schema.
4
- */ export function removeVirtualFieldsFromSchema(schema, virtualFieldNames) {
5
- if (virtualFieldNames.length === 0) {
6
- return schema;
7
- }
8
- for (const name of virtualFieldNames){
9
- delete schema?.properties?.[name];
10
- }
11
- if (Array.isArray(schema.required)) {
12
- schema.required = schema.required.filter((field)=>!virtualFieldNames.includes(field));
13
- if (schema.required.length === 0) {
14
- delete schema.required;
15
- }
16
- }
17
- return schema;
18
- }
19
-
20
- //# sourceMappingURL=removeVirtualFieldsFromSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts"],"sourcesContent":["import type { JsonSchemaType } from '../../types.js'\n\n/**\n * Removes virtual fields from a JSON Schema by name so they don't appear\n * in the generated MCP tool input schema.\n */\nexport function removeVirtualFieldsFromSchema(\n schema: JsonSchemaType,\n virtualFieldNames: string[],\n): JsonSchemaType {\n if (virtualFieldNames.length === 0) {\n return schema\n }\n\n for (const name of virtualFieldNames) {\n delete schema?.properties?.[name]\n }\n\n if (Array.isArray(schema.required)) {\n schema.required = schema.required.filter((field) => !virtualFieldNames.includes(field))\n if (schema.required.length === 0) {\n delete schema.required\n }\n }\n\n return schema\n}\n"],"names":["removeVirtualFieldsFromSchema","schema","virtualFieldNames","length","name","properties","Array","isArray","required","filter","field","includes"],"mappings":"AAEA;;;CAGC,GACD,OAAO,SAASA,8BACdC,MAAsB,EACtBC,iBAA2B;IAE3B,IAAIA,kBAAkBC,MAAM,KAAK,GAAG;QAClC,OAAOF;IACT;IAEA,KAAK,MAAMG,QAAQF,kBAAmB;QACpC,OAAOD,QAAQI,YAAY,CAACD,KAAK;IACnC;IAEA,IAAIE,MAAMC,OAAO,CAACN,OAAOO,QAAQ,GAAG;QAClCP,OAAOO,QAAQ,GAAGP,OAAOO,QAAQ,CAACC,MAAM,CAAC,CAACC,QAAU,CAACR,kBAAkBS,QAAQ,CAACD;QAChF,IAAIT,OAAOO,QAAQ,CAACL,MAAM,KAAK,GAAG;YAChC,OAAOF,OAAOO,QAAQ;QACxB;IACF;IAEA,OAAOP;AACT"}
@@ -1,15 +0,0 @@
1
- import type { JsonSchemaType } from '../../types.js';
2
- /**
3
- * Turns the JSON Schema that Payload generates for a collection or global into the input schema for
4
- * an MCP create/update tool. In short, it:
5
- *
6
- * - drops fields a client can't set (`id`, `createdAt`, the draft `_status`, …),
7
- * - rewrites Payload-specific field shapes (points, relationships) into plain JSON the model can fill,
8
- * - and shrinks the result so it's cheaper for the model to read,
9
- *
10
- * while keeping every node valid JSON Schema draft 2020-12. Each step below is tagged with why it runs -
11
- * **Correctness** (valid input the API accepts), **Size** (equivalence-preserving shrink), or **LLM
12
- * ergonomics** (easier for the model to read/fill) - and carries a before/after example on its definition.
13
- */
14
- export declare const sanitizeEntitySchema: (schema: JsonSchemaType) => JsonSchemaType;
15
- //# sourceMappingURL=sanitizeEntitySchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sanitizeEntitySchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/sanitizeEntitySchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,cAAc,KAAG,cA6B7D,CAAA"}