@payloadcms/plugin-mcp 0.0.1-alpha.0
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.
- package/LICENSE.md +22 -0
- package/README.md +7 -0
- package/dist/collections/createApiKeysCollection.d.ts +7 -0
- package/dist/collections/createApiKeysCollection.d.ts.map +1 -0
- package/dist/collections/createApiKeysCollection.js +315 -0
- package/dist/collections/createApiKeysCollection.js.map +1 -0
- package/dist/endpoints/mcp.d.ts +4 -0
- package/dist/endpoints/mcp.d.ts.map +1 -0
- package/dist/endpoints/mcp.js +44 -0
- package/dist/endpoints/mcp.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/createRequest.d.ts +3 -0
- package/dist/mcp/createRequest.d.ts.map +1 -0
- package/dist/mcp/createRequest.js +14 -0
- package/dist/mcp/createRequest.js.map +1 -0
- package/dist/mcp/getMcpHandler.d.ts +4 -0
- package/dist/mcp/getMcpHandler.d.ts.map +1 -0
- package/dist/mcp/getMcpHandler.js +179 -0
- package/dist/mcp/getMcpHandler.js.map +1 -0
- package/dist/mcp/helpers/config.d.ts +30 -0
- package/dist/mcp/helpers/config.d.ts.map +1 -0
- package/dist/mcp/helpers/config.js +217 -0
- package/dist/mcp/helpers/config.js.map +1 -0
- package/dist/mcp/helpers/conversion.d.ts +2 -0
- package/dist/mcp/helpers/conversion.d.ts.map +1 -0
- package/dist/mcp/helpers/conversion.js +5 -0
- package/dist/mcp/helpers/conversion.js.map +1 -0
- package/dist/mcp/helpers/fields.d.ts +38 -0
- package/dist/mcp/helpers/fields.d.ts.map +1 -0
- package/dist/mcp/helpers/fields.js +96 -0
- package/dist/mcp/helpers/fields.js.map +1 -0
- package/dist/mcp/helpers/fileValidation.d.ts +69 -0
- package/dist/mcp/helpers/fileValidation.d.ts.map +1 -0
- package/dist/mcp/helpers/fileValidation.js +305 -0
- package/dist/mcp/helpers/fileValidation.js.map +1 -0
- package/dist/mcp/helpers/validation.d.ts +9 -0
- package/dist/mcp/helpers/validation.d.ts.map +1 -0
- package/dist/mcp/helpers/validation.js +22 -0
- package/dist/mcp/helpers/validation.js.map +1 -0
- package/dist/mcp/registerTool.d.ts +6 -0
- package/dist/mcp/registerTool.d.ts.map +1 -0
- package/dist/mcp/registerTool.js +18 -0
- package/dist/mcp/registerTool.js.map +1 -0
- package/dist/mcp/tools/auth/auth.d.ts +4 -0
- package/dist/mcp/tools/auth/auth.d.ts.map +1 -0
- package/dist/mcp/tools/auth/auth.js +54 -0
- package/dist/mcp/tools/auth/auth.js.map +1 -0
- package/dist/mcp/tools/auth/forgotPassword.d.ts +4 -0
- package/dist/mcp/tools/auth/forgotPassword.d.ts.map +1 -0
- package/dist/mcp/tools/auth/forgotPassword.js +45 -0
- package/dist/mcp/tools/auth/forgotPassword.js.map +1 -0
- package/dist/mcp/tools/auth/login.d.ts +4 -0
- package/dist/mcp/tools/auth/login.d.ts.map +1 -0
- package/dist/mcp/tools/auth/login.js +48 -0
- package/dist/mcp/tools/auth/login.js.map +1 -0
- package/dist/mcp/tools/auth/resetPassword.d.ts +4 -0
- package/dist/mcp/tools/auth/resetPassword.d.ts.map +1 -0
- package/dist/mcp/tools/auth/resetPassword.js +46 -0
- package/dist/mcp/tools/auth/resetPassword.js.map +1 -0
- package/dist/mcp/tools/auth/unlock.d.ts +4 -0
- package/dist/mcp/tools/auth/unlock.d.ts.map +1 -0
- package/dist/mcp/tools/auth/unlock.js +45 -0
- package/dist/mcp/tools/auth/unlock.js.map +1 -0
- package/dist/mcp/tools/auth/verify.d.ts +4 -0
- package/dist/mcp/tools/auth/verify.d.ts.map +1 -0
- package/dist/mcp/tools/auth/verify.js +42 -0
- package/dist/mcp/tools/auth/verify.js.map +1 -0
- package/dist/mcp/tools/collection/create.d.ts +10 -0
- package/dist/mcp/tools/collection/create.d.ts.map +1 -0
- package/dist/mcp/tools/collection/create.js +159 -0
- package/dist/mcp/tools/collection/create.js.map +1 -0
- package/dist/mcp/tools/collection/delete.d.ts +10 -0
- package/dist/mcp/tools/collection/delete.d.ts.map +1 -0
- package/dist/mcp/tools/collection/delete.js +162 -0
- package/dist/mcp/tools/collection/delete.js.map +1 -0
- package/dist/mcp/tools/collection/find.d.ts +10 -0
- package/dist/mcp/tools/collection/find.d.ts.map +1 -0
- package/dist/mcp/tools/collection/find.js +162 -0
- package/dist/mcp/tools/collection/find.js.map +1 -0
- package/dist/mcp/tools/collection/update.d.ts +10 -0
- package/dist/mcp/tools/collection/update.d.ts.map +1 -0
- package/dist/mcp/tools/collection/update.js +206 -0
- package/dist/mcp/tools/collection/update.js.map +1 -0
- package/dist/mcp/tools/config/find.d.ts +10 -0
- package/dist/mcp/tools/config/find.d.ts.map +1 -0
- package/dist/mcp/tools/config/find.js +94 -0
- package/dist/mcp/tools/config/find.js.map +1 -0
- package/dist/mcp/tools/config/update.d.ts +10 -0
- package/dist/mcp/tools/config/update.d.ts.map +1 -0
- package/dist/mcp/tools/config/update.js +212 -0
- package/dist/mcp/tools/config/update.js.map +1 -0
- package/dist/mcp/tools/job/create.d.ts +10 -0
- package/dist/mcp/tools/job/create.d.ts.map +1 -0
- package/dist/mcp/tools/job/create.js +293 -0
- package/dist/mcp/tools/job/create.js.map +1 -0
- package/dist/mcp/tools/job/run.d.ts +10 -0
- package/dist/mcp/tools/job/run.d.ts.map +1 -0
- package/dist/mcp/tools/job/run.js +147 -0
- package/dist/mcp/tools/job/run.js.map +1 -0
- package/dist/mcp/tools/job/update.d.ts +11 -0
- package/dist/mcp/tools/job/update.d.ts.map +1 -0
- package/dist/mcp/tools/job/update.js +211 -0
- package/dist/mcp/tools/job/update.js.map +1 -0
- package/dist/mcp/tools/resource/create.d.ts +6 -0
- package/dist/mcp/tools/resource/create.d.ts.map +1 -0
- package/dist/mcp/tools/resource/create.js +75 -0
- package/dist/mcp/tools/resource/create.js.map +1 -0
- package/dist/mcp/tools/resource/delete.d.ts +5 -0
- package/dist/mcp/tools/resource/delete.d.ts.map +1 -0
- package/dist/mcp/tools/resource/delete.js +140 -0
- package/dist/mcp/tools/resource/delete.js.map +1 -0
- package/dist/mcp/tools/resource/find.d.ts +5 -0
- package/dist/mcp/tools/resource/find.d.ts.map +1 -0
- package/dist/mcp/tools/resource/find.js +119 -0
- package/dist/mcp/tools/resource/find.js.map +1 -0
- package/dist/mcp/tools/resource/update.d.ts +6 -0
- package/dist/mcp/tools/resource/update.d.ts.map +1 -0
- package/dist/mcp/tools/resource/update.js +201 -0
- package/dist/mcp/tools/resource/update.js.map +1 -0
- package/dist/mcp/tools/schemas.d.ts +374 -0
- package/dist/mcp/tools/schemas.d.ts.map +1 -0
- package/dist/mcp/tools/schemas.js +201 -0
- package/dist/mcp/tools/schemas.js.map +1 -0
- package/dist/types.d.ts +379 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/camelCase.d.ts +9 -0
- package/dist/utils/camelCase.d.ts.map +1 -0
- package/dist/utils/camelCase.js +11 -0
- package/dist/utils/camelCase.js.map +1 -0
- package/dist/utils/convertCollectionSchemaToZod.d.ts +3 -0
- package/dist/utils/convertCollectionSchemaToZod.d.ts.map +1 -0
- package/dist/utils/convertCollectionSchemaToZod.js +30 -0
- package/dist/utils/convertCollectionSchemaToZod.js.map +1 -0
- package/package.json +64 -0
- package/src/collections/createApiKeysCollection.ts +393 -0
- package/src/endpoints/mcp.ts +60 -0
- package/src/index.ts +86 -0
- package/src/mcp/createRequest.ts +13 -0
- package/src/mcp/getMcpHandler.ts +433 -0
- package/src/mcp/helpers/config.ts +326 -0
- package/src/mcp/helpers/conversion.ts +3 -0
- package/src/mcp/helpers/fields.ts +158 -0
- package/src/mcp/helpers/fileValidation.ts +417 -0
- package/src/mcp/helpers/validation.ts +32 -0
- package/src/mcp/registerTool.ts +22 -0
- package/src/mcp/tools/auth/auth.ts +69 -0
- package/src/mcp/tools/auth/forgotPassword.ts +68 -0
- package/src/mcp/tools/auth/login.ts +70 -0
- package/src/mcp/tools/auth/resetPassword.ts +59 -0
- package/src/mcp/tools/auth/unlock.ts +62 -0
- package/src/mcp/tools/auth/verify.ts +55 -0
- package/src/mcp/tools/collection/create.ts +236 -0
- package/src/mcp/tools/collection/delete.ts +227 -0
- package/src/mcp/tools/collection/find.ts +222 -0
- package/src/mcp/tools/collection/update.ts +288 -0
- package/src/mcp/tools/config/find.ts +126 -0
- package/src/mcp/tools/config/update.ts +282 -0
- package/src/mcp/tools/job/create.ts +420 -0
- package/src/mcp/tools/job/run.ts +189 -0
- package/src/mcp/tools/job/update.ts +319 -0
- package/src/mcp/tools/resource/create.ts +121 -0
- package/src/mcp/tools/resource/delete.ts +210 -0
- package/src/mcp/tools/resource/find.ts +194 -0
- package/src/mcp/tools/resource/update.ts +314 -0
- package/src/mcp/tools/schemas.ts +373 -0
- package/src/types.ts +405 -0
- package/src/utils/camelCase.ts +12 -0
- package/src/utils/convertCollectionSchemaToZod.ts +35 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import type { CollectionConfig, CollectionSlug, PayloadRequest } from 'payload'
|
|
2
|
+
import type { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { type ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
5
|
+
|
|
6
|
+
export type PluginMCPServerConfig = {
|
|
7
|
+
/**
|
|
8
|
+
* Set the collections that should be available as resources via MCP.
|
|
9
|
+
*/
|
|
10
|
+
collections?: Partial<
|
|
11
|
+
Record<
|
|
12
|
+
CollectionSlug,
|
|
13
|
+
{
|
|
14
|
+
/**
|
|
15
|
+
* Set the description of the collection. This is used by MCP clients to determine when to use the collecton as a resource.
|
|
16
|
+
*/
|
|
17
|
+
description: string
|
|
18
|
+
/**
|
|
19
|
+
* Set the enabled capabilities of the collection. Admins can then allow or disallow the use of the capability by MCP clients.
|
|
20
|
+
*/
|
|
21
|
+
enabled:
|
|
22
|
+
| {
|
|
23
|
+
create?: boolean
|
|
24
|
+
delete?: boolean
|
|
25
|
+
find?: boolean
|
|
26
|
+
update?: boolean
|
|
27
|
+
}
|
|
28
|
+
| boolean
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Override the data generated by the MCP client. This allows you to modify the data that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.
|
|
32
|
+
*/
|
|
33
|
+
override?: (
|
|
34
|
+
original: Record<string, unknown>,
|
|
35
|
+
req: PayloadRequest,
|
|
36
|
+
) => Record<string, unknown>
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Override the response generated by the MCP client. This allows you to modify the response that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.
|
|
40
|
+
*/
|
|
41
|
+
overrideResponse?: (
|
|
42
|
+
response: {
|
|
43
|
+
content: Array<{
|
|
44
|
+
text: string
|
|
45
|
+
type: string
|
|
46
|
+
}>
|
|
47
|
+
},
|
|
48
|
+
doc: Record<string, unknown>,
|
|
49
|
+
req: PayloadRequest,
|
|
50
|
+
) => {
|
|
51
|
+
content: Array<{
|
|
52
|
+
text: string
|
|
53
|
+
type: string
|
|
54
|
+
}>
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
>
|
|
58
|
+
>
|
|
59
|
+
/**
|
|
60
|
+
* Disable the MCP plugin.
|
|
61
|
+
*/
|
|
62
|
+
disabled?: boolean
|
|
63
|
+
/**
|
|
64
|
+
* Experimental features
|
|
65
|
+
* **These features are for experimental purposes -- They are Disabled in Production by Default**
|
|
66
|
+
*/
|
|
67
|
+
experimental?: {
|
|
68
|
+
/**
|
|
69
|
+
* These are MCP tools that can be used by a client to modify Payload.
|
|
70
|
+
*/
|
|
71
|
+
tools: {
|
|
72
|
+
/**
|
|
73
|
+
* **Experimental** -- Auth MCP tools allow a client to change authentication priviliages for users. This is for developing ideas that help Admins with authentication tasks.
|
|
74
|
+
*/
|
|
75
|
+
auth?: {
|
|
76
|
+
/**
|
|
77
|
+
* Enable the auth MCP tools. This allows Admins to enable or disable the auth capabilities.
|
|
78
|
+
* @default false
|
|
79
|
+
*/
|
|
80
|
+
enabled: boolean
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* **Experimental** -- Collection MCP tools allow for the creation, modification, and deletion of Payload collections. This is for developing ideas that help Developers with collection tasks.
|
|
84
|
+
*/
|
|
85
|
+
collections?: {
|
|
86
|
+
/**
|
|
87
|
+
* Set the directory path to the collections directory. This can be a directory outside of your default directory, or another Payload project.
|
|
88
|
+
*/
|
|
89
|
+
collectionsDirPath: string
|
|
90
|
+
/**
|
|
91
|
+
* Enable the collection MCP tools. This allows Admins to enable or disable the Collection modification capabilities.
|
|
92
|
+
* @default false
|
|
93
|
+
*/
|
|
94
|
+
enabled: boolean
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* **Experimental** -- Config MCP tools allow for the modification of a Payload Config. This is for developing ideas that help Developers with config tasks.
|
|
98
|
+
*/
|
|
99
|
+
config?: {
|
|
100
|
+
/**
|
|
101
|
+
* Set the directory path to the config directory. This can be a directory outside of your default directory, or another Payload project.
|
|
102
|
+
*/
|
|
103
|
+
configFilePath: string
|
|
104
|
+
/**
|
|
105
|
+
* Enable the config MCP tools. This allows Admins to enable or disable the Payload Config modification capabilities.
|
|
106
|
+
* @default false
|
|
107
|
+
*/
|
|
108
|
+
enabled: boolean
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* **Experimental** -- Jobs MCP tools allow for the modification of Payload jobs. This is for developing ideas that help Developers with job tasks.
|
|
112
|
+
*/
|
|
113
|
+
jobs?: {
|
|
114
|
+
/**
|
|
115
|
+
* Enable the jobs MCP tools. This allows Admins to enable or disable the Job modification capabilities.
|
|
116
|
+
* @default false
|
|
117
|
+
*/
|
|
118
|
+
enabled: boolean
|
|
119
|
+
/**
|
|
120
|
+
* Set the directory path to the jobs directory. This can be a directory outside of your default directory, or another Payload project.
|
|
121
|
+
*/
|
|
122
|
+
jobsDirPath: string
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* MCP Server options.
|
|
128
|
+
*/
|
|
129
|
+
mcp?: {
|
|
130
|
+
handlerOptions?: MCPHandlerOptions
|
|
131
|
+
/**
|
|
132
|
+
* Add custom MCP Prompts.
|
|
133
|
+
*/
|
|
134
|
+
prompts?: {
|
|
135
|
+
/**
|
|
136
|
+
* Set the args schema of the prompt. This is the args schema that will be passed to the prompt. This is used by MCP clients to determine the arguments that will be passed to the prompt.
|
|
137
|
+
*/
|
|
138
|
+
argsSchema: z.ZodRawShape
|
|
139
|
+
/**
|
|
140
|
+
* Set the description of the prompt. This is used by MCP clients to determine when to use the prompt.
|
|
141
|
+
*/
|
|
142
|
+
description: string
|
|
143
|
+
/**
|
|
144
|
+
* Set the handler of the prompt. This is the function that will be called when the prompt is used.
|
|
145
|
+
*/
|
|
146
|
+
handler: (...args: any) => any
|
|
147
|
+
/**
|
|
148
|
+
* Set the function name of the prompt.
|
|
149
|
+
*/
|
|
150
|
+
name: string
|
|
151
|
+
/**
|
|
152
|
+
* Set the title of the prompt. LLMs will interperate the title to determine when to use the prompt.
|
|
153
|
+
*/
|
|
154
|
+
title: string
|
|
155
|
+
}[]
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Add custom MCP Resource.
|
|
159
|
+
*/
|
|
160
|
+
resources?: {
|
|
161
|
+
/**
|
|
162
|
+
* Set the description of the resource. This is used by MCP clients to determine when to use the resource.
|
|
163
|
+
* example: 'Data is a resource that contains special data.'
|
|
164
|
+
*/
|
|
165
|
+
description: string
|
|
166
|
+
/**
|
|
167
|
+
* Set the handler of the resource. This is the function that will be called when the resource is used.
|
|
168
|
+
*/
|
|
169
|
+
handler: (...args: any) => any
|
|
170
|
+
/**
|
|
171
|
+
* Set the mime type of the resource.
|
|
172
|
+
* example: 'text/plain'
|
|
173
|
+
*/
|
|
174
|
+
mimeType: string
|
|
175
|
+
/**
|
|
176
|
+
* Set the function name of the resource.
|
|
177
|
+
* example: 'data'
|
|
178
|
+
*/
|
|
179
|
+
name: string
|
|
180
|
+
/**
|
|
181
|
+
* Set the title of the resource. LLMs will interperate the title to determine when to use the resource.
|
|
182
|
+
* example: 'Data'
|
|
183
|
+
*/
|
|
184
|
+
title: string
|
|
185
|
+
/**
|
|
186
|
+
* Set the uri of the resource.
|
|
187
|
+
* example: 'data://app'
|
|
188
|
+
*/
|
|
189
|
+
uri: ResourceTemplate | string
|
|
190
|
+
}[]
|
|
191
|
+
serverOptions?: MCPServerOptions
|
|
192
|
+
/**
|
|
193
|
+
* Add custom MCP Tools.
|
|
194
|
+
*/
|
|
195
|
+
tools?: {
|
|
196
|
+
/**
|
|
197
|
+
* Set the description of the tool. This is used by MCP clients to determine when to use the tool.
|
|
198
|
+
*/
|
|
199
|
+
description: string
|
|
200
|
+
/**
|
|
201
|
+
* Set the handler of the tool. This is the function that will be called when the tool is used.
|
|
202
|
+
*/
|
|
203
|
+
handler: (args: Record<string, unknown>) => Promise<{
|
|
204
|
+
content: Array<{
|
|
205
|
+
text: string
|
|
206
|
+
type: 'text'
|
|
207
|
+
}>
|
|
208
|
+
}>
|
|
209
|
+
/**
|
|
210
|
+
* Set the name of the tool. This is the name that will be used to identify the tool. LLMs will interperate the name to determine when to use the tool.
|
|
211
|
+
*/
|
|
212
|
+
name: string
|
|
213
|
+
/**
|
|
214
|
+
* Set the parameters of the tool. This is the parameters that will be passed to the tool.
|
|
215
|
+
*/
|
|
216
|
+
parameters: z.ZodRawShape
|
|
217
|
+
}[]
|
|
218
|
+
}
|
|
219
|
+
overrideApiKeyCollection?: (collection: CollectionConfig) => CollectionConfig
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* MCP Handler options.
|
|
224
|
+
*/
|
|
225
|
+
export type MCPHandlerOptions = {
|
|
226
|
+
/**
|
|
227
|
+
* Set the base path of the MCP handler. This is the path that will be used to access the MCP handler.
|
|
228
|
+
* @default /api
|
|
229
|
+
*/
|
|
230
|
+
basePath?: string
|
|
231
|
+
/**
|
|
232
|
+
* Set the maximum duration of the MCP handler. This is the maximum duration that the MCP handler will run for.
|
|
233
|
+
* @default 60
|
|
234
|
+
*/
|
|
235
|
+
maxDuration?: number
|
|
236
|
+
/**
|
|
237
|
+
* Set the Redis URL for the MCP handler. This is the URL that will be used to access the Redis server.
|
|
238
|
+
* @default process.env.REDIS_URL
|
|
239
|
+
* INFO: Disabled until developer clarity is reached for server side streaming and we have an auth pattern for all SSE patterns
|
|
240
|
+
*/
|
|
241
|
+
// redisUrl?: string
|
|
242
|
+
/**
|
|
243
|
+
* Set verbose logging.
|
|
244
|
+
* @default false
|
|
245
|
+
*/
|
|
246
|
+
verboseLogs?: boolean
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* MCP Server options.
|
|
251
|
+
*/
|
|
252
|
+
export type MCPServerOptions = {
|
|
253
|
+
/**
|
|
254
|
+
* Set the server info of the MCP server.
|
|
255
|
+
*/
|
|
256
|
+
serverInfo?: {
|
|
257
|
+
/**
|
|
258
|
+
* Set the name of the MCP server.
|
|
259
|
+
* @default 'Payload MCP Server'
|
|
260
|
+
*/
|
|
261
|
+
name: string
|
|
262
|
+
/**
|
|
263
|
+
* Set the version of the MCP server.
|
|
264
|
+
* @default '1.0.0'
|
|
265
|
+
*/
|
|
266
|
+
version: string
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export type ToolSettings = {
|
|
271
|
+
auth?: {
|
|
272
|
+
auth?: boolean
|
|
273
|
+
forgotPassword?: boolean
|
|
274
|
+
login?: boolean
|
|
275
|
+
resetPassword?: boolean
|
|
276
|
+
unlock?: boolean
|
|
277
|
+
verify?: boolean
|
|
278
|
+
}
|
|
279
|
+
collections?: {
|
|
280
|
+
create?: boolean
|
|
281
|
+
delete?: boolean
|
|
282
|
+
find?: boolean
|
|
283
|
+
update?: boolean
|
|
284
|
+
}
|
|
285
|
+
config?: {
|
|
286
|
+
find?: boolean
|
|
287
|
+
update?: boolean
|
|
288
|
+
}
|
|
289
|
+
custom?: Record<string, boolean>
|
|
290
|
+
jobs?: {
|
|
291
|
+
create?: boolean
|
|
292
|
+
run?: boolean
|
|
293
|
+
update?: boolean
|
|
294
|
+
}
|
|
295
|
+
} & Record<string, unknown>
|
|
296
|
+
|
|
297
|
+
export type FieldDefinition = {
|
|
298
|
+
description?: string
|
|
299
|
+
name: string
|
|
300
|
+
options?: { label: string; value: string }[]
|
|
301
|
+
position?: 'main' | 'sidebar'
|
|
302
|
+
required?: boolean
|
|
303
|
+
type: string
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export type FieldModification = {
|
|
307
|
+
changes: {
|
|
308
|
+
description?: string
|
|
309
|
+
options?: { label: string; value: string }[]
|
|
310
|
+
position?: 'main' | 'sidebar'
|
|
311
|
+
required?: boolean
|
|
312
|
+
type?: string
|
|
313
|
+
}
|
|
314
|
+
fieldName: string
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export type CollectionConfigUpdates = {
|
|
318
|
+
access?: {
|
|
319
|
+
create?: string
|
|
320
|
+
delete?: string
|
|
321
|
+
read?: string
|
|
322
|
+
update?: string
|
|
323
|
+
}
|
|
324
|
+
description?: string
|
|
325
|
+
slug?: string
|
|
326
|
+
timestamps?: boolean
|
|
327
|
+
versioning?: boolean
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export type AdminConfig = {
|
|
331
|
+
avatar?: string
|
|
332
|
+
css?: string
|
|
333
|
+
dateFormat?: string
|
|
334
|
+
inactivityRoute?: string
|
|
335
|
+
livePreview?: {
|
|
336
|
+
breakpoints?: Array<{
|
|
337
|
+
height: number
|
|
338
|
+
label: string
|
|
339
|
+
name: string
|
|
340
|
+
width: number
|
|
341
|
+
}>
|
|
342
|
+
}
|
|
343
|
+
logoutRoute?: string
|
|
344
|
+
meta?: {
|
|
345
|
+
favicon?: string
|
|
346
|
+
ogImage?: string
|
|
347
|
+
titleSuffix?: string
|
|
348
|
+
}
|
|
349
|
+
user?: string
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export type DatabaseConfig = {
|
|
353
|
+
connectOptions?: string
|
|
354
|
+
type?: 'mongodb' | 'postgres'
|
|
355
|
+
url?: string
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export type PluginUpdates = {
|
|
359
|
+
add?: string[]
|
|
360
|
+
remove?: string[]
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export type GeneralConfig = {
|
|
364
|
+
cookiePrefix?: string
|
|
365
|
+
cors?: string
|
|
366
|
+
csrf?: string
|
|
367
|
+
graphQL?: {
|
|
368
|
+
disable?: boolean
|
|
369
|
+
schemaOutputFile?: string
|
|
370
|
+
}
|
|
371
|
+
rateLimit?: {
|
|
372
|
+
max?: number
|
|
373
|
+
skip?: string
|
|
374
|
+
window?: number
|
|
375
|
+
}
|
|
376
|
+
secret?: string
|
|
377
|
+
serverURL?: string
|
|
378
|
+
typescript?: {
|
|
379
|
+
declare?: boolean
|
|
380
|
+
outputFile?: string
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export interface SchemaField {
|
|
385
|
+
description?: string
|
|
386
|
+
name: string
|
|
387
|
+
options?: string[]
|
|
388
|
+
required?: boolean
|
|
389
|
+
type: string
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface TaskSequenceItem {
|
|
393
|
+
description?: string
|
|
394
|
+
retries?: number
|
|
395
|
+
taskId: string
|
|
396
|
+
taskSlug: string
|
|
397
|
+
timeout?: number
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export interface JobConfigUpdate {
|
|
401
|
+
description?: string
|
|
402
|
+
queue?: string
|
|
403
|
+
retries?: number
|
|
404
|
+
timeout?: number
|
|
405
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to camel case by replacing dashes, underscores, and spaces
|
|
3
|
+
* with camel case formatting.
|
|
4
|
+
*
|
|
5
|
+
* @param str - The string to convert to camel case
|
|
6
|
+
* @returns The camel cased string
|
|
7
|
+
*/
|
|
8
|
+
export const toCamelCase = (str: string): string => {
|
|
9
|
+
return str
|
|
10
|
+
.replace(/[-_\s]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : ''))
|
|
11
|
+
.replace(/^(.)/, (_, chr) => chr.toLowerCase())
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { JSONSchema4 } from 'json-schema'
|
|
2
|
+
|
|
3
|
+
import { jsonSchemaToZod } from 'json-schema-to-zod'
|
|
4
|
+
import * as ts from 'typescript'
|
|
5
|
+
import { z } from 'zod'
|
|
6
|
+
|
|
7
|
+
export const convertCollectionSchemaToZod = (schema: JSONSchema4) => {
|
|
8
|
+
// Remove properties that should not be included in the Zod schema
|
|
9
|
+
delete schema?.properties?.createdAt
|
|
10
|
+
delete schema?.properties?.updatedAt
|
|
11
|
+
|
|
12
|
+
const zodSchemaAsString = jsonSchemaToZod(schema)
|
|
13
|
+
|
|
14
|
+
// Transpile TypeScript to JavaScript
|
|
15
|
+
const transpileResult = ts.transpileModule(zodSchemaAsString, {
|
|
16
|
+
compilerOptions: {
|
|
17
|
+
module: ts.ModuleKind.CommonJS,
|
|
18
|
+
removeComments: true,
|
|
19
|
+
strict: false,
|
|
20
|
+
target: ts.ScriptTarget.ES2018,
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This Function evaluation is safe because:
|
|
26
|
+
* 1. The input schema comes from Payload's collection configuration, which is controlled by the application developer
|
|
27
|
+
* 2. The jsonSchemaToZod library converts JSON Schema to Zod schema definitions, producing only type validation code
|
|
28
|
+
* 3. The transpiled output contains only Zod schema definitions (z.string(), z.number(), etc.) - no executable logic
|
|
29
|
+
* 4. The resulting Zod schema is used only for parameter validation in MCP tools, not for data processing
|
|
30
|
+
* 5. No user input or external data is involved in the schema generation process
|
|
31
|
+
*/
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
33
|
+
const zodSchema = new Function('z', `return ${transpileResult.outputText}`)(z)
|
|
34
|
+
return zodSchema
|
|
35
|
+
}
|