@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
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import type { JSONSchema4 } from 'json-schema'
|
|
2
|
+
|
|
3
|
+
import { createMcpHandler } from '@vercel/mcp-adapter'
|
|
4
|
+
import { join } from 'path'
|
|
5
|
+
import { APIError, configToJSONSchema, type PayloadRequest, type TypedUser } from 'payload'
|
|
6
|
+
|
|
7
|
+
import type { PluginMCPServerConfig, ToolSettings } from '../types.js'
|
|
8
|
+
|
|
9
|
+
import { toCamelCase } from '../utils/camelCase.js'
|
|
10
|
+
import { registerTool } from './registerTool.js'
|
|
11
|
+
|
|
12
|
+
// Tools
|
|
13
|
+
import { createResourceTool } from './tools/resource/create.js'
|
|
14
|
+
import { deleteResourceTool } from './tools/resource/delete.js'
|
|
15
|
+
import { findResourceTool } from './tools/resource/find.js'
|
|
16
|
+
import { updateResourceTool } from './tools/resource/update.js'
|
|
17
|
+
|
|
18
|
+
// Experimental Tools
|
|
19
|
+
import { authTool } from './tools/auth/auth.js'
|
|
20
|
+
import { forgotPasswordTool } from './tools/auth/forgotPassword.js'
|
|
21
|
+
import { loginTool } from './tools/auth/login.js'
|
|
22
|
+
import { resetPasswordTool } from './tools/auth/resetPassword.js'
|
|
23
|
+
import { unlockTool } from './tools/auth/unlock.js'
|
|
24
|
+
import { verifyTool } from './tools/auth/verify.js'
|
|
25
|
+
import { createCollectionTool } from './tools/collection/create.js'
|
|
26
|
+
import { deleteCollectionTool } from './tools/collection/delete.js'
|
|
27
|
+
import { findCollectionTool } from './tools/collection/find.js'
|
|
28
|
+
import { updateCollectionTool } from './tools/collection/update.js'
|
|
29
|
+
import { findConfigTool } from './tools/config/find.js'
|
|
30
|
+
import { updateConfigTool } from './tools/config/update.js'
|
|
31
|
+
import { createJobTool } from './tools/job/create.js'
|
|
32
|
+
import { runJobTool } from './tools/job/run.js'
|
|
33
|
+
import { updateJobTool } from './tools/job/update.js'
|
|
34
|
+
|
|
35
|
+
export const getMCPHandler = (
|
|
36
|
+
pluginOptions: PluginMCPServerConfig,
|
|
37
|
+
toolSettings: ToolSettings,
|
|
38
|
+
req: PayloadRequest,
|
|
39
|
+
) => {
|
|
40
|
+
const { payload } = req
|
|
41
|
+
const configSchema = configToJSONSchema(payload.config)
|
|
42
|
+
|
|
43
|
+
// User
|
|
44
|
+
const user = toolSettings.user as TypedUser
|
|
45
|
+
|
|
46
|
+
// MCP Server and Handler Options
|
|
47
|
+
const MCPOptions = pluginOptions.mcp || {}
|
|
48
|
+
const customMCPTools = MCPOptions.tools || []
|
|
49
|
+
const customMCPPrompts = MCPOptions.prompts || []
|
|
50
|
+
const customMCPResources = MCPOptions.resources || []
|
|
51
|
+
const MCPHandlerOptions = MCPOptions.handlerOptions || {}
|
|
52
|
+
const serverOptions = MCPOptions.serverOptions || {}
|
|
53
|
+
const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false
|
|
54
|
+
|
|
55
|
+
// Experimental MCP Tool Requirements
|
|
56
|
+
const isDevelopment = process.env.NODE_ENV === 'development'
|
|
57
|
+
const experimentalTools: NonNullable<PluginMCPServerConfig['experimental']>['tools'] =
|
|
58
|
+
pluginOptions?.experimental?.tools || {}
|
|
59
|
+
const collectionsPluginConfig = pluginOptions.collections || {}
|
|
60
|
+
const collectionsDirPath =
|
|
61
|
+
experimentalTools && experimentalTools.collections?.collectionsDirPath
|
|
62
|
+
? experimentalTools.collections.collectionsDirPath
|
|
63
|
+
: join(process.cwd(), 'src/collections')
|
|
64
|
+
const configFilePath =
|
|
65
|
+
experimentalTools && experimentalTools.config?.configFilePath
|
|
66
|
+
? experimentalTools.config.configFilePath
|
|
67
|
+
: join(process.cwd(), 'src/payload.config.ts')
|
|
68
|
+
const jobsDirPath =
|
|
69
|
+
experimentalTools && experimentalTools.jobs?.jobsDirPath
|
|
70
|
+
? experimentalTools.jobs.jobsDirPath
|
|
71
|
+
: join(process.cwd(), 'src/jobs')
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
return createMcpHandler(
|
|
75
|
+
(server) => {
|
|
76
|
+
const enabledCollectionSlugs = Object.keys(collectionsPluginConfig || {}).filter(
|
|
77
|
+
(collection) => {
|
|
78
|
+
const fullyEnabled =
|
|
79
|
+
typeof collectionsPluginConfig?.[collection]?.enabled === 'boolean' &&
|
|
80
|
+
collectionsPluginConfig?.[collection]?.enabled
|
|
81
|
+
|
|
82
|
+
if (fullyEnabled) {
|
|
83
|
+
return true
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const partiallyEnabled =
|
|
87
|
+
typeof collectionsPluginConfig?.[collection]?.enabled !== 'boolean' &&
|
|
88
|
+
((typeof collectionsPluginConfig?.[collection]?.enabled?.find === 'boolean' &&
|
|
89
|
+
collectionsPluginConfig?.[collection]?.enabled?.find === true) ||
|
|
90
|
+
(typeof collectionsPluginConfig?.[collection]?.enabled?.create === 'boolean' &&
|
|
91
|
+
collectionsPluginConfig?.[collection]?.enabled?.create === true) ||
|
|
92
|
+
(typeof collectionsPluginConfig?.[collection]?.enabled?.update === 'boolean' &&
|
|
93
|
+
collectionsPluginConfig?.[collection]?.enabled?.update === true) ||
|
|
94
|
+
(typeof collectionsPluginConfig?.[collection]?.enabled?.delete === 'boolean' &&
|
|
95
|
+
collectionsPluginConfig?.[collection]?.enabled?.delete === true))
|
|
96
|
+
|
|
97
|
+
if (partiallyEnabled) {
|
|
98
|
+
return true
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
// Collection Operation Tools
|
|
104
|
+
enabledCollectionSlugs.forEach((enabledCollectionSlug) => {
|
|
105
|
+
try {
|
|
106
|
+
const schema = configSchema.definitions?.[enabledCollectionSlug] as JSONSchema4
|
|
107
|
+
|
|
108
|
+
const toolCapabilities = toolSettings?.[
|
|
109
|
+
`${toCamelCase(enabledCollectionSlug)}`
|
|
110
|
+
] as Record<string, unknown>
|
|
111
|
+
const allowCreate: boolean | undefined = toolCapabilities['create'] as boolean
|
|
112
|
+
const allowUpdate: boolean | undefined = toolCapabilities['update'] as boolean
|
|
113
|
+
const allowFind: boolean | undefined = toolCapabilities['find'] as boolean
|
|
114
|
+
const allowDelete: boolean | undefined = toolCapabilities['delete'] as boolean
|
|
115
|
+
|
|
116
|
+
if (allowCreate) {
|
|
117
|
+
registerTool(
|
|
118
|
+
allowCreate,
|
|
119
|
+
`Create ${enabledCollectionSlug}`,
|
|
120
|
+
() =>
|
|
121
|
+
createResourceTool(
|
|
122
|
+
server,
|
|
123
|
+
req,
|
|
124
|
+
user,
|
|
125
|
+
useVerboseLogs,
|
|
126
|
+
enabledCollectionSlug,
|
|
127
|
+
collectionsPluginConfig,
|
|
128
|
+
schema,
|
|
129
|
+
),
|
|
130
|
+
payload,
|
|
131
|
+
useVerboseLogs,
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
if (allowUpdate) {
|
|
135
|
+
registerTool(
|
|
136
|
+
allowUpdate,
|
|
137
|
+
`Update ${enabledCollectionSlug}`,
|
|
138
|
+
() =>
|
|
139
|
+
updateResourceTool(
|
|
140
|
+
server,
|
|
141
|
+
req,
|
|
142
|
+
user,
|
|
143
|
+
useVerboseLogs,
|
|
144
|
+
enabledCollectionSlug,
|
|
145
|
+
collectionsPluginConfig,
|
|
146
|
+
schema,
|
|
147
|
+
),
|
|
148
|
+
payload,
|
|
149
|
+
useVerboseLogs,
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
if (allowFind) {
|
|
153
|
+
registerTool(
|
|
154
|
+
allowFind,
|
|
155
|
+
`Find ${enabledCollectionSlug}`,
|
|
156
|
+
() =>
|
|
157
|
+
findResourceTool(
|
|
158
|
+
server,
|
|
159
|
+
req,
|
|
160
|
+
user,
|
|
161
|
+
useVerboseLogs,
|
|
162
|
+
enabledCollectionSlug,
|
|
163
|
+
collectionsPluginConfig,
|
|
164
|
+
),
|
|
165
|
+
payload,
|
|
166
|
+
useVerboseLogs,
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
if (allowDelete) {
|
|
170
|
+
registerTool(
|
|
171
|
+
allowDelete,
|
|
172
|
+
`Delete ${enabledCollectionSlug}`,
|
|
173
|
+
() =>
|
|
174
|
+
deleteResourceTool(
|
|
175
|
+
server,
|
|
176
|
+
req,
|
|
177
|
+
user,
|
|
178
|
+
useVerboseLogs,
|
|
179
|
+
enabledCollectionSlug,
|
|
180
|
+
collectionsPluginConfig,
|
|
181
|
+
),
|
|
182
|
+
payload,
|
|
183
|
+
useVerboseLogs,
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
} catch (error) {
|
|
187
|
+
throw new APIError(
|
|
188
|
+
`Error registering tools for collection ${enabledCollectionSlug}: ${String(error)}`,
|
|
189
|
+
500,
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
// Custom tools
|
|
195
|
+
customMCPTools.forEach((tool) => {
|
|
196
|
+
const camelCasedToolName = toCamelCase(tool.name)
|
|
197
|
+
const isToolEnabled = toolSettings.custom?.[camelCasedToolName] ?? true
|
|
198
|
+
|
|
199
|
+
registerTool(
|
|
200
|
+
isToolEnabled,
|
|
201
|
+
tool.name,
|
|
202
|
+
() => server.tool(tool.name, tool.description, tool.parameters, tool.handler),
|
|
203
|
+
payload,
|
|
204
|
+
useVerboseLogs,
|
|
205
|
+
)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
// Custom prompts
|
|
209
|
+
customMCPPrompts.forEach((prompt) => {
|
|
210
|
+
server.registerPrompt(
|
|
211
|
+
prompt.name,
|
|
212
|
+
{
|
|
213
|
+
argsSchema: prompt.argsSchema,
|
|
214
|
+
description: prompt.description,
|
|
215
|
+
title: prompt.title,
|
|
216
|
+
},
|
|
217
|
+
prompt.handler,
|
|
218
|
+
)
|
|
219
|
+
if (useVerboseLogs) {
|
|
220
|
+
payload.logger.info(`[payload-mcp] ✅ Prompt: ${prompt.title} Registered.`)
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
// Custom resources
|
|
225
|
+
customMCPResources.forEach((resource) => {
|
|
226
|
+
server.registerResource(
|
|
227
|
+
resource.name,
|
|
228
|
+
// @ts-expect-error - Overload type is not working however -- ResourceTemplate OR String is a valid type
|
|
229
|
+
resource.uri,
|
|
230
|
+
{
|
|
231
|
+
description: resource.description,
|
|
232
|
+
mimeType: resource.mimeType,
|
|
233
|
+
title: resource.title,
|
|
234
|
+
},
|
|
235
|
+
resource.handler,
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
if (useVerboseLogs) {
|
|
239
|
+
payload.logger.info(`[payload-mcp] ✅ Resource: ${resource.title} Registered.`)
|
|
240
|
+
}
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
// Experimental - Collection Schema Modfication Tools
|
|
244
|
+
if (
|
|
245
|
+
toolSettings.collections?.create &&
|
|
246
|
+
experimentalTools.collections?.enabled &&
|
|
247
|
+
isDevelopment
|
|
248
|
+
) {
|
|
249
|
+
registerTool(
|
|
250
|
+
toolSettings.collections.create,
|
|
251
|
+
'Create Collection',
|
|
252
|
+
() =>
|
|
253
|
+
createCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),
|
|
254
|
+
payload,
|
|
255
|
+
useVerboseLogs,
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
if (
|
|
259
|
+
toolSettings.collections?.delete &&
|
|
260
|
+
experimentalTools.collections?.enabled &&
|
|
261
|
+
isDevelopment
|
|
262
|
+
) {
|
|
263
|
+
registerTool(
|
|
264
|
+
toolSettings.collections.delete,
|
|
265
|
+
'Delete Collection',
|
|
266
|
+
() =>
|
|
267
|
+
deleteCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),
|
|
268
|
+
payload,
|
|
269
|
+
useVerboseLogs,
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (
|
|
274
|
+
toolSettings.collections?.find &&
|
|
275
|
+
experimentalTools.collections?.enabled &&
|
|
276
|
+
isDevelopment
|
|
277
|
+
) {
|
|
278
|
+
registerTool(
|
|
279
|
+
toolSettings.collections.find,
|
|
280
|
+
'Find Collection',
|
|
281
|
+
() => findCollectionTool(server, req, useVerboseLogs, collectionsDirPath),
|
|
282
|
+
payload,
|
|
283
|
+
useVerboseLogs,
|
|
284
|
+
)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (
|
|
288
|
+
toolSettings.collections?.update &&
|
|
289
|
+
experimentalTools.collections?.enabled &&
|
|
290
|
+
isDevelopment
|
|
291
|
+
) {
|
|
292
|
+
registerTool(
|
|
293
|
+
toolSettings.collections.update,
|
|
294
|
+
'Update Collection',
|
|
295
|
+
() =>
|
|
296
|
+
updateCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),
|
|
297
|
+
payload,
|
|
298
|
+
useVerboseLogs,
|
|
299
|
+
)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Experimental - Payload Config Modification Tools
|
|
303
|
+
if (toolSettings.config?.find && experimentalTools.config?.enabled && isDevelopment) {
|
|
304
|
+
registerTool(
|
|
305
|
+
toolSettings.config.find,
|
|
306
|
+
'Find Config',
|
|
307
|
+
() => findConfigTool(server, req, useVerboseLogs, configFilePath),
|
|
308
|
+
payload,
|
|
309
|
+
useVerboseLogs,
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (toolSettings.config?.update && experimentalTools.config?.enabled && isDevelopment) {
|
|
314
|
+
registerTool(
|
|
315
|
+
toolSettings.config.update,
|
|
316
|
+
'Update Config',
|
|
317
|
+
() => updateConfigTool(server, req, useVerboseLogs, configFilePath),
|
|
318
|
+
payload,
|
|
319
|
+
useVerboseLogs,
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Experimental - Job Modification Tools
|
|
324
|
+
if (toolSettings.jobs?.create && experimentalTools.jobs?.enabled && isDevelopment) {
|
|
325
|
+
registerTool(
|
|
326
|
+
toolSettings.jobs.create,
|
|
327
|
+
'Create Job',
|
|
328
|
+
() => createJobTool(server, req, useVerboseLogs, jobsDirPath),
|
|
329
|
+
payload,
|
|
330
|
+
useVerboseLogs,
|
|
331
|
+
)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (toolSettings.jobs?.update && experimentalTools.jobs?.enabled && isDevelopment) {
|
|
335
|
+
registerTool(
|
|
336
|
+
toolSettings.jobs.update,
|
|
337
|
+
'Update Job',
|
|
338
|
+
() => updateJobTool(server, req, useVerboseLogs, jobsDirPath),
|
|
339
|
+
payload,
|
|
340
|
+
useVerboseLogs,
|
|
341
|
+
)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (toolSettings.jobs?.run && experimentalTools.jobs?.enabled && isDevelopment) {
|
|
345
|
+
registerTool(
|
|
346
|
+
toolSettings.jobs.run,
|
|
347
|
+
'Run Job',
|
|
348
|
+
() => runJobTool(server, req, useVerboseLogs),
|
|
349
|
+
payload,
|
|
350
|
+
useVerboseLogs,
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Experimental - Auth Modification Tools
|
|
355
|
+
if (toolSettings.auth?.auth && experimentalTools.auth?.enabled && isDevelopment) {
|
|
356
|
+
registerTool(
|
|
357
|
+
toolSettings.auth.auth,
|
|
358
|
+
'Auth',
|
|
359
|
+
() => authTool(server, req, useVerboseLogs),
|
|
360
|
+
payload,
|
|
361
|
+
useVerboseLogs,
|
|
362
|
+
)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (toolSettings.auth?.login && experimentalTools.auth?.enabled && isDevelopment) {
|
|
366
|
+
registerTool(
|
|
367
|
+
toolSettings.auth.login,
|
|
368
|
+
'Login',
|
|
369
|
+
() => loginTool(server, req, useVerboseLogs),
|
|
370
|
+
payload,
|
|
371
|
+
useVerboseLogs,
|
|
372
|
+
)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (toolSettings.auth?.verify && experimentalTools.auth?.enabled && isDevelopment) {
|
|
376
|
+
registerTool(
|
|
377
|
+
toolSettings.auth.verify,
|
|
378
|
+
'Verify',
|
|
379
|
+
() => verifyTool(server, req, useVerboseLogs),
|
|
380
|
+
payload,
|
|
381
|
+
useVerboseLogs,
|
|
382
|
+
)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (toolSettings.auth?.resetPassword && experimentalTools.auth?.enabled) {
|
|
386
|
+
registerTool(
|
|
387
|
+
toolSettings.auth.resetPassword,
|
|
388
|
+
'Reset Password',
|
|
389
|
+
() => resetPasswordTool(server, req, useVerboseLogs),
|
|
390
|
+
payload,
|
|
391
|
+
useVerboseLogs,
|
|
392
|
+
)
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (toolSettings.auth?.forgotPassword && experimentalTools.auth?.enabled) {
|
|
396
|
+
registerTool(
|
|
397
|
+
toolSettings.auth.forgotPassword,
|
|
398
|
+
'Forgot Password',
|
|
399
|
+
() => forgotPasswordTool(server, req, useVerboseLogs),
|
|
400
|
+
payload,
|
|
401
|
+
useVerboseLogs,
|
|
402
|
+
)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (toolSettings.auth?.unlock && experimentalTools.auth?.enabled) {
|
|
406
|
+
registerTool(
|
|
407
|
+
toolSettings.auth.unlock,
|
|
408
|
+
'Unlock',
|
|
409
|
+
() => unlockTool(server, req, useVerboseLogs),
|
|
410
|
+
payload,
|
|
411
|
+
useVerboseLogs,
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (useVerboseLogs) {
|
|
416
|
+
payload.logger.info('[payload-mcp] 🚀 MCP Server Ready.')
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
serverInfo: serverOptions.serverInfo,
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
basePath: MCPHandlerOptions.basePath || '/api',
|
|
424
|
+
maxDuration: MCPHandlerOptions.maxDuration || 60,
|
|
425
|
+
// INFO: Disabled until developer clarity is reached for server side streaming and we have an auth pattern for all SSE patterns
|
|
426
|
+
// redisUrl: MCPHandlerOptions.redisUrl || process.env.REDIS_URL,
|
|
427
|
+
verboseLogs: useVerboseLogs,
|
|
428
|
+
},
|
|
429
|
+
)
|
|
430
|
+
} catch (error) {
|
|
431
|
+
throw new APIError(`Error initializing MCP handler: ${String(error)}`, 500)
|
|
432
|
+
}
|
|
433
|
+
}
|