@payloadcms/plugin-mcp 3.85.0 → 4.0.0-canary.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/README.md +2 -2
- package/bin.js +39 -0
- package/dist/collection/getAccessField.d.ts +12 -0
- package/dist/collection/getAccessField.d.ts.map +1 -0
- package/dist/collection/getAccessField.js +57 -0
- package/dist/collection/getAccessField.js.map +1 -0
- package/dist/collection/index.d.ts +6 -0
- package/dist/collection/index.d.ts.map +1 -0
- package/dist/collection/index.js +59 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/components/AccessField/index.client.d.ts +10 -0
- package/dist/components/AccessField/index.client.d.ts.map +1 -0
- package/dist/components/AccessField/index.client.js +305 -0
- package/dist/components/AccessField/index.client.js.map +1 -0
- package/dist/components/AccessField/index.css +93 -0
- package/dist/defineTool.d.ts +26 -0
- package/dist/defineTool.d.ts.map +1 -0
- package/dist/defineTool.js +37 -0
- package/dist/defineTool.js.map +1 -0
- package/dist/endpoint/access.d.ts +10 -0
- package/dist/endpoint/access.d.ts.map +1 -0
- package/dist/endpoint/access.js +106 -0
- package/dist/endpoint/access.js.map +1 -0
- package/dist/endpoint/index.d.ts +3 -0
- package/dist/endpoint/index.d.ts.map +1 -0
- package/dist/endpoint/index.js +36 -0
- package/dist/endpoint/index.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/index.d.ts +4 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -67
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +19 -0
- package/dist/mcp/buildMcpServer.d.ts.map +1 -0
- package/dist/mcp/buildMcpServer.js +163 -0
- package/dist/mcp/buildMcpServer.js.map +1 -0
- package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/authTools.js +250 -0
- package/dist/mcp/builtin/collections/authTools.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/createTool.js +87 -0
- package/dist/mcp/builtin/collections/createTool.js.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.js +117 -0
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findTool.js +159 -0
- package/dist/mcp/builtin/collections/findTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.js +187 -0
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findTool.js +76 -0
- package/dist/mcp/builtin/globals/findTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.js +92 -0
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +37 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -0
- package/dist/mcp/builtinTools.js +64 -0
- package/dist/mcp/builtinTools.js.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts +17 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.js +167 -0
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
- package/dist/stdio.d.ts +8 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +89 -0
- package/dist/stdio.js.map +1 -0
- package/dist/types.d.ts +262 -455
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/getLogger.d.ts +10 -0
- package/dist/utils/getLogger.d.ts.map +1 -0
- package/dist/utils/getLogger.js +22 -0
- package/dist/utils/getLogger.js.map +1 -0
- package/dist/utils/getPluginConfig.d.ts +12 -0
- package/dist/utils/getPluginConfig.d.ts.map +1 -0
- package/dist/utils/getPluginConfig.js +15 -0
- package/dist/utils/getPluginConfig.js.map +1 -0
- package/dist/utils/localAPIDefaults.d.ts +20 -0
- package/dist/utils/localAPIDefaults.d.ts.map +1 -0
- package/dist/utils/localAPIDefaults.js +19 -0
- package/dist/utils/localAPIDefaults.js.map +1 -0
- package/dist/utils/resolveProjectRoot.d.ts +7 -0
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
- package/dist/utils/resolveProjectRoot.js +15 -0
- package/dist/utils/resolveProjectRoot.js.map +1 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +7 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.js +37 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +1 -0
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +2 -2
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +1 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +2 -2
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +1 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +2 -2
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +1 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js +7 -4
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +1 -1
- package/dist/utils/schemaConversion/transformPointFields.d.ts +2 -2
- package/dist/utils/schemaConversion/transformPointFields.d.ts.map +1 -1
- package/dist/utils/schemaConversion/transformPointFields.js +7 -1
- package/dist/utils/schemaConversion/transformPointFields.js.map +1 -1
- package/dist/utils/toStandardSchema.d.ts +5 -0
- package/dist/utils/toStandardSchema.d.ts.map +1 -0
- package/dist/utils/toStandardSchema.js +4 -0
- package/dist/utils/toStandardSchema.js.map +1 -0
- package/package.json +35 -10
- package/src/collection/getAccessField.ts +64 -0
- package/src/collection/index.ts +63 -0
- package/src/components/AccessField/index.client.tsx +344 -0
- package/src/components/AccessField/index.css +93 -0
- package/src/defineTool.ts +44 -0
- package/src/endpoint/access.ts +132 -0
- package/src/endpoint/index.ts +35 -0
- package/src/exports/client.ts +2 -0
- package/src/index.ts +35 -85
- package/src/mcp/buildMcpServer.ts +224 -0
- package/src/mcp/builtin/collections/authTools.ts +233 -0
- package/src/mcp/builtin/collections/createTool.ts +116 -0
- package/src/mcp/builtin/collections/deleteTool.ts +123 -0
- package/src/mcp/builtin/collections/findTool.ts +187 -0
- package/src/mcp/builtin/collections/updateTool.ts +205 -0
- package/src/mcp/builtin/globals/findTool.ts +96 -0
- package/src/mcp/builtin/globals/updateTool.ts +118 -0
- package/src/mcp/builtinTools.ts +84 -0
- package/src/mcp/sanitizeMCPConfig.ts +239 -0
- package/src/stdio.ts +98 -0
- package/src/types.ts +295 -490
- package/src/utils/getLogger.ts +22 -0
- package/src/utils/getPluginConfig.ts +24 -0
- package/src/utils/localAPIDefaults.ts +22 -0
- package/src/utils/resolveProjectRoot.ts +17 -0
- package/src/utils/schemaConversion/prepareCollectionSchema.ts +39 -0
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +3 -3
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +4 -4
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +11 -6
- package/src/utils/schemaConversion/transformPointFields.ts +6 -5
- package/src/utils/toStandardSchema.ts +9 -0
- package/dist/collections/createApiKeysCollection.d.ts +0 -7
- package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
- package/dist/collections/createApiKeysCollection.js +0 -317
- package/dist/collections/createApiKeysCollection.js.map +0 -1
- package/dist/defaults.d.ts +0 -4
- package/dist/defaults.d.ts.map +0 -1
- package/dist/defaults.js +0 -5
- package/dist/defaults.js.map +0 -1
- package/dist/endpoints/mcp.d.ts +0 -4
- package/dist/endpoints/mcp.d.ts.map +0 -1
- package/dist/endpoints/mcp.js +0 -71
- package/dist/endpoints/mcp.js.map +0 -1
- package/dist/mcp/createRequest.d.ts +0 -3
- package/dist/mcp/createRequest.d.ts.map +0 -1
- package/dist/mcp/createRequest.js +0 -14
- package/dist/mcp/createRequest.js.map +0 -1
- package/dist/mcp/getMcpHandler.d.ts +0 -4
- package/dist/mcp/getMcpHandler.d.ts.map +0 -1
- package/dist/mcp/getMcpHandler.js +0 -231
- package/dist/mcp/getMcpHandler.js.map +0 -1
- package/dist/mcp/helpers/config.d.ts +0 -22
- package/dist/mcp/helpers/config.d.ts.map +0 -1
- package/dist/mcp/helpers/config.js +0 -153
- package/dist/mcp/helpers/config.js.map +0 -1
- package/dist/mcp/helpers/fields.d.ts +0 -19
- package/dist/mcp/helpers/fields.d.ts.map +0 -1
- package/dist/mcp/helpers/fields.js +0 -102
- package/dist/mcp/helpers/fields.js.map +0 -1
- package/dist/mcp/helpers/fileValidation.d.ts +0 -67
- package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
- package/dist/mcp/helpers/fileValidation.js +0 -267
- package/dist/mcp/helpers/fileValidation.js.map +0 -1
- package/dist/mcp/registerTool.d.ts +0 -6
- package/dist/mcp/registerTool.d.ts.map +0 -1
- package/dist/mcp/registerTool.js +0 -18
- package/dist/mcp/registerTool.js.map +0 -1
- package/dist/mcp/tools/auth/auth.d.ts +0 -4
- package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
- package/dist/mcp/tools/auth/auth.js +0 -57
- package/dist/mcp/tools/auth/auth.js.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.js +0 -48
- package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
- package/dist/mcp/tools/auth/login.d.ts +0 -4
- package/dist/mcp/tools/auth/login.d.ts.map +0 -1
- package/dist/mcp/tools/auth/login.js +0 -51
- package/dist/mcp/tools/auth/login.js.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.js +0 -49
- package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
- package/dist/mcp/tools/auth/unlock.d.ts +0 -4
- package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
- package/dist/mcp/tools/auth/unlock.js +0 -48
- package/dist/mcp/tools/auth/unlock.js.map +0 -1
- package/dist/mcp/tools/auth/verify.d.ts +0 -4
- package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
- package/dist/mcp/tools/auth/verify.js +0 -45
- package/dist/mcp/tools/auth/verify.js.map +0 -1
- package/dist/mcp/tools/collection/create.d.ts +0 -10
- package/dist/mcp/tools/collection/create.d.ts.map +0 -1
- package/dist/mcp/tools/collection/create.js +0 -139
- package/dist/mcp/tools/collection/create.js.map +0 -1
- package/dist/mcp/tools/collection/delete.d.ts +0 -10
- package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
- package/dist/mcp/tools/collection/delete.js +0 -154
- package/dist/mcp/tools/collection/delete.js.map +0 -1
- package/dist/mcp/tools/collection/find.d.ts +0 -10
- package/dist/mcp/tools/collection/find.d.ts.map +0 -1
- package/dist/mcp/tools/collection/find.js +0 -165
- package/dist/mcp/tools/collection/find.js.map +0 -1
- package/dist/mcp/tools/collection/update.d.ts +0 -10
- package/dist/mcp/tools/collection/update.d.ts.map +0 -1
- package/dist/mcp/tools/collection/update.js +0 -209
- package/dist/mcp/tools/collection/update.js.map +0 -1
- package/dist/mcp/tools/config/find.d.ts +0 -10
- package/dist/mcp/tools/config/find.d.ts.map +0 -1
- package/dist/mcp/tools/config/find.js +0 -97
- package/dist/mcp/tools/config/find.js.map +0 -1
- package/dist/mcp/tools/config/update.d.ts +0 -10
- package/dist/mcp/tools/config/update.d.ts.map +0 -1
- package/dist/mcp/tools/config/update.js +0 -215
- package/dist/mcp/tools/config/update.js.map +0 -1
- package/dist/mcp/tools/global/find.d.ts +0 -5
- package/dist/mcp/tools/global/find.d.ts.map +0 -1
- package/dist/mcp/tools/global/find.js +0 -82
- package/dist/mcp/tools/global/find.js.map +0 -1
- package/dist/mcp/tools/global/update.d.ts +0 -6
- package/dist/mcp/tools/global/update.d.ts.map +0 -1
- package/dist/mcp/tools/global/update.js +0 -124
- package/dist/mcp/tools/global/update.js.map +0 -1
- package/dist/mcp/tools/job/create.d.ts +0 -10
- package/dist/mcp/tools/job/create.d.ts.map +0 -1
- package/dist/mcp/tools/job/create.js +0 -293
- package/dist/mcp/tools/job/create.js.map +0 -1
- package/dist/mcp/tools/job/run.d.ts +0 -10
- package/dist/mcp/tools/job/run.d.ts.map +0 -1
- package/dist/mcp/tools/job/run.js +0 -129
- package/dist/mcp/tools/job/run.js.map +0 -1
- package/dist/mcp/tools/job/update.d.ts +0 -11
- package/dist/mcp/tools/job/update.d.ts.map +0 -1
- package/dist/mcp/tools/job/update.js +0 -186
- package/dist/mcp/tools/job/update.js.map +0 -1
- package/dist/mcp/tools/resource/create.d.ts +0 -6
- package/dist/mcp/tools/resource/create.d.ts.map +0 -1
- package/dist/mcp/tools/resource/create.js +0 -124
- package/dist/mcp/tools/resource/create.js.map +0 -1
- package/dist/mcp/tools/resource/delete.d.ts +0 -5
- package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
- package/dist/mcp/tools/resource/delete.js +0 -151
- package/dist/mcp/tools/resource/delete.js.map +0 -1
- package/dist/mcp/tools/resource/find.d.ts +0 -5
- package/dist/mcp/tools/resource/find.d.ts.map +0 -1
- package/dist/mcp/tools/resource/find.js +0 -170
- package/dist/mcp/tools/resource/find.js.map +0 -1
- package/dist/mcp/tools/resource/update.d.ts +0 -6
- package/dist/mcp/tools/resource/update.d.ts.map +0 -1
- package/dist/mcp/tools/resource/update.js +0 -256
- package/dist/mcp/tools/resource/update.js.map +0 -1
- package/dist/mcp/tools/schemas.d.ts +0 -457
- package/dist/mcp/tools/schemas.d.ts.map +0 -1
- package/dist/mcp/tools/schemas.js +0 -243
- package/dist/mcp/tools/schemas.js.map +0 -1
- package/dist/utils/adminEntitySettings.d.ts +0 -17
- package/dist/utils/adminEntitySettings.d.ts.map +0 -1
- package/dist/utils/adminEntitySettings.js +0 -41
- package/dist/utils/adminEntitySettings.js.map +0 -1
- package/dist/utils/createApiKeyFields.d.ts +0 -15
- package/dist/utils/createApiKeyFields.d.ts.map +0 -1
- package/dist/utils/createApiKeyFields.js +0 -57
- package/dist/utils/createApiKeyFields.js.map +0 -1
- package/dist/utils/getEnabledSlugs.d.ts +0 -13
- package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
- package/dist/utils/getEnabledSlugs.js +0 -32
- package/dist/utils/getEnabledSlugs.js.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
- package/src/collections/createApiKeysCollection.ts +0 -373
- package/src/defaults.ts +0 -3
- package/src/endpoints/mcp.ts +0 -91
- package/src/mcp/createRequest.ts +0 -13
- package/src/mcp/getMcpHandler.ts +0 -545
- package/src/mcp/helpers/config.ts +0 -213
- package/src/mcp/helpers/fields.ts +0 -154
- package/src/mcp/helpers/fileValidation.ts +0 -362
- package/src/mcp/registerTool.ts +0 -22
- package/src/mcp/tools/auth/auth.ts +0 -71
- package/src/mcp/tools/auth/forgotPassword.ts +0 -70
- package/src/mcp/tools/auth/login.ts +0 -72
- package/src/mcp/tools/auth/resetPassword.ts +0 -61
- package/src/mcp/tools/auth/unlock.ts +0 -64
- package/src/mcp/tools/auth/verify.ts +0 -57
- package/src/mcp/tools/collection/create.ts +0 -210
- package/src/mcp/tools/collection/delete.ts +0 -211
- package/src/mcp/tools/collection/find.ts +0 -224
- package/src/mcp/tools/collection/update.ts +0 -290
- package/src/mcp/tools/config/find.ts +0 -128
- package/src/mcp/tools/config/update.ts +0 -280
- package/src/mcp/tools/global/find.ts +0 -128
- package/src/mcp/tools/global/update.ts +0 -207
- package/src/mcp/tools/job/create.ts +0 -416
- package/src/mcp/tools/job/run.ts +0 -167
- package/src/mcp/tools/job/update.ts +0 -274
- package/src/mcp/tools/resource/create.ts +0 -211
- package/src/mcp/tools/resource/delete.ts +0 -218
- package/src/mcp/tools/resource/find.ts +0 -246
- package/src/mcp/tools/resource/update.ts +0 -383
- package/src/mcp/tools/schemas.ts +0 -520
- package/src/utils/adminEntitySettings.ts +0 -40
- package/src/utils/createApiKeyFields.ts +0 -72
- package/src/utils/getEnabledSlugs.ts +0 -42
- package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
-
import type { PayloadRequest, SelectType, TypedUser } from 'payload'
|
|
3
|
-
|
|
4
|
-
import type { MCPPluginConfig } from '../../../types.js'
|
|
5
|
-
|
|
6
|
-
import { toCamelCase } from '../../../utils/camelCase.js'
|
|
7
|
-
import { toolSchemas } from '../schemas.js'
|
|
8
|
-
|
|
9
|
-
export const findResourceTool = (
|
|
10
|
-
server: McpServer,
|
|
11
|
-
req: PayloadRequest,
|
|
12
|
-
user: TypedUser,
|
|
13
|
-
verboseLogs: boolean,
|
|
14
|
-
collectionSlug: string,
|
|
15
|
-
collections: MCPPluginConfig['collections'],
|
|
16
|
-
) => {
|
|
17
|
-
const tool = async (
|
|
18
|
-
id?: number | string,
|
|
19
|
-
limit: number = 10,
|
|
20
|
-
page: number = 1,
|
|
21
|
-
sort?: string,
|
|
22
|
-
where?: string,
|
|
23
|
-
select?: string,
|
|
24
|
-
depth: number = 0,
|
|
25
|
-
locale?: string,
|
|
26
|
-
fallbackLocale?: string,
|
|
27
|
-
draft?: boolean,
|
|
28
|
-
): Promise<{
|
|
29
|
-
content: Array<{
|
|
30
|
-
text: string
|
|
31
|
-
type: 'text'
|
|
32
|
-
}>
|
|
33
|
-
}> => {
|
|
34
|
-
const payload = req.payload
|
|
35
|
-
|
|
36
|
-
if (verboseLogs) {
|
|
37
|
-
payload.logger.info(
|
|
38
|
-
`[payload-mcp] Reading resource from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
// Parse where clause if provided
|
|
44
|
-
let whereClause = {}
|
|
45
|
-
if (where) {
|
|
46
|
-
try {
|
|
47
|
-
whereClause = JSON.parse(where)
|
|
48
|
-
if (verboseLogs) {
|
|
49
|
-
payload.logger.info(`[payload-mcp] Using where clause: ${where}`)
|
|
50
|
-
}
|
|
51
|
-
} catch (_parseError) {
|
|
52
|
-
payload.logger.warn(`[payload-mcp] Invalid where clause JSON: ${where}`)
|
|
53
|
-
const response = {
|
|
54
|
-
content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],
|
|
55
|
-
}
|
|
56
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||
|
|
57
|
-
response) as {
|
|
58
|
-
content: Array<{
|
|
59
|
-
text: string
|
|
60
|
-
type: 'text'
|
|
61
|
-
}>
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Parse select clause if provided
|
|
67
|
-
let selectClause: SelectType | undefined
|
|
68
|
-
if (select) {
|
|
69
|
-
try {
|
|
70
|
-
selectClause = JSON.parse(select) as SelectType
|
|
71
|
-
} catch (_parseError) {
|
|
72
|
-
payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)
|
|
73
|
-
const response = {
|
|
74
|
-
content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],
|
|
75
|
-
}
|
|
76
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||
|
|
77
|
-
response) as {
|
|
78
|
-
content: Array<{
|
|
79
|
-
text: string
|
|
80
|
-
type: 'text'
|
|
81
|
-
}>
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// If ID is provided, use findByID
|
|
87
|
-
if (id) {
|
|
88
|
-
try {
|
|
89
|
-
const doc = await payload.findByID({
|
|
90
|
-
id,
|
|
91
|
-
collection: collectionSlug,
|
|
92
|
-
depth,
|
|
93
|
-
...(selectClause && { select: selectClause }),
|
|
94
|
-
overrideAccess: false,
|
|
95
|
-
req,
|
|
96
|
-
user,
|
|
97
|
-
...(locale && { locale }),
|
|
98
|
-
...(fallbackLocale && { fallbackLocale }),
|
|
99
|
-
...(draft !== undefined && { draft }),
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
if (verboseLogs) {
|
|
103
|
-
payload.logger.info(`[payload-mcp] Found document with ID: ${id}`)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const response = {
|
|
107
|
-
content: [
|
|
108
|
-
{
|
|
109
|
-
type: 'text' as const,
|
|
110
|
-
text: `Resource from collection "${collectionSlug}":
|
|
111
|
-
${JSON.stringify(doc)}`,
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, doc, req) ||
|
|
117
|
-
response) as {
|
|
118
|
-
content: Array<{
|
|
119
|
-
text: string
|
|
120
|
-
type: 'text'
|
|
121
|
-
}>
|
|
122
|
-
}
|
|
123
|
-
} catch (_findError) {
|
|
124
|
-
payload.logger.warn(
|
|
125
|
-
`[payload-mcp] Document not found with ID: ${id} in collection: ${collectionSlug}`,
|
|
126
|
-
)
|
|
127
|
-
const response = {
|
|
128
|
-
content: [
|
|
129
|
-
{
|
|
130
|
-
type: 'text' as const,
|
|
131
|
-
text: `Error: Document with ID "${id}" not found in collection "${collectionSlug}"`,
|
|
132
|
-
},
|
|
133
|
-
],
|
|
134
|
-
}
|
|
135
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||
|
|
136
|
-
response) as {
|
|
137
|
-
content: Array<{
|
|
138
|
-
text: string
|
|
139
|
-
type: 'text'
|
|
140
|
-
}>
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Otherwise, use find to get multiple documents
|
|
146
|
-
const findOptions: Parameters<typeof payload.find>[0] = {
|
|
147
|
-
collection: collectionSlug,
|
|
148
|
-
depth,
|
|
149
|
-
limit,
|
|
150
|
-
overrideAccess: false,
|
|
151
|
-
page,
|
|
152
|
-
req,
|
|
153
|
-
user,
|
|
154
|
-
...(selectClause && { select: selectClause }),
|
|
155
|
-
...(locale && { locale }),
|
|
156
|
-
...(fallbackLocale && { fallbackLocale }),
|
|
157
|
-
...(draft !== undefined && { draft }),
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (sort) {
|
|
161
|
-
findOptions.sort = sort
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (Object.keys(whereClause).length > 0) {
|
|
165
|
-
findOptions.where = whereClause
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const result = await payload.find(findOptions)
|
|
169
|
-
|
|
170
|
-
if (verboseLogs) {
|
|
171
|
-
payload.logger.info(
|
|
172
|
-
`[payload-mcp] Found ${result.docs.length} documents in collection: ${collectionSlug}`,
|
|
173
|
-
)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
let responseText = `Collection: "${collectionSlug}"
|
|
177
|
-
Total: ${result.totalDocs} documents
|
|
178
|
-
Page: ${result.page} of ${result.totalPages}
|
|
179
|
-
`
|
|
180
|
-
|
|
181
|
-
for (const doc of result.docs) {
|
|
182
|
-
responseText += `\n\`\`\`json\n${JSON.stringify(doc)}\n\`\`\``
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const response = {
|
|
186
|
-
content: [
|
|
187
|
-
{
|
|
188
|
-
type: 'text' as const,
|
|
189
|
-
text: responseText,
|
|
190
|
-
},
|
|
191
|
-
],
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||
|
|
195
|
-
response) as {
|
|
196
|
-
content: Array<{
|
|
197
|
-
text: string
|
|
198
|
-
type: 'text'
|
|
199
|
-
}>
|
|
200
|
-
}
|
|
201
|
-
} catch (error) {
|
|
202
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
203
|
-
payload.logger.error(
|
|
204
|
-
`[payload-mcp] Error reading resources from collection ${collectionSlug}: ${errorMessage}`,
|
|
205
|
-
)
|
|
206
|
-
const response = {
|
|
207
|
-
content: [
|
|
208
|
-
{
|
|
209
|
-
type: 'text' as const,
|
|
210
|
-
text: `❌ **Error reading resources from collection "${collectionSlug}":** ${errorMessage}`,
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
}
|
|
214
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {
|
|
215
|
-
content: Array<{
|
|
216
|
-
text: string
|
|
217
|
-
type: 'text'
|
|
218
|
-
}>
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (collections?.[collectionSlug]?.enabled) {
|
|
224
|
-
server.registerTool(
|
|
225
|
-
`find${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,
|
|
226
|
-
{
|
|
227
|
-
description: `${collections?.[collectionSlug]?.description || toolSchemas.findResources.description.trim()}`,
|
|
228
|
-
inputSchema: toolSchemas.findResources.parameters.shape,
|
|
229
|
-
},
|
|
230
|
-
async ({ id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where }) => {
|
|
231
|
-
return await tool(
|
|
232
|
-
id,
|
|
233
|
-
limit,
|
|
234
|
-
page,
|
|
235
|
-
sort,
|
|
236
|
-
where,
|
|
237
|
-
select,
|
|
238
|
-
depth,
|
|
239
|
-
locale,
|
|
240
|
-
fallbackLocale,
|
|
241
|
-
draft,
|
|
242
|
-
)
|
|
243
|
-
},
|
|
244
|
-
)
|
|
245
|
-
}
|
|
246
|
-
}
|
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
-
import type { JSONSchema4 } from 'json-schema'
|
|
3
|
-
import type { PayloadRequest, SelectType, TypedUser } from 'payload'
|
|
4
|
-
|
|
5
|
-
import { z } from 'zod'
|
|
6
|
-
|
|
7
|
-
import type { MCPPluginConfig } from '../../../types.js'
|
|
8
|
-
|
|
9
|
-
import { toCamelCase } from '../../../utils/camelCase.js'
|
|
10
|
-
import {
|
|
11
|
-
getCollectionVirtualFieldNames,
|
|
12
|
-
stripVirtualFields,
|
|
13
|
-
} from '../../../utils/getVirtualFieldNames.js'
|
|
14
|
-
import { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/convertCollectionSchemaToZod.js'
|
|
15
|
-
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
16
|
-
import { toolSchemas } from '../schemas.js'
|
|
17
|
-
export const updateResourceTool = (
|
|
18
|
-
server: McpServer,
|
|
19
|
-
req: PayloadRequest,
|
|
20
|
-
user: TypedUser,
|
|
21
|
-
verboseLogs: boolean,
|
|
22
|
-
collectionSlug: string,
|
|
23
|
-
collections: MCPPluginConfig['collections'],
|
|
24
|
-
schema: JSONSchema4,
|
|
25
|
-
) => {
|
|
26
|
-
const tool = async (
|
|
27
|
-
data: string,
|
|
28
|
-
id?: number | string,
|
|
29
|
-
where?: string,
|
|
30
|
-
draft: boolean = false,
|
|
31
|
-
depth: number = 0,
|
|
32
|
-
overrideLock: boolean = true,
|
|
33
|
-
filePath?: string,
|
|
34
|
-
overwriteExistingFiles: boolean = false,
|
|
35
|
-
locale?: string,
|
|
36
|
-
fallbackLocale?: string,
|
|
37
|
-
select?: string,
|
|
38
|
-
): Promise<{
|
|
39
|
-
content: Array<{
|
|
40
|
-
text: string
|
|
41
|
-
type: 'text'
|
|
42
|
-
}>
|
|
43
|
-
}> => {
|
|
44
|
-
const payload = req.payload
|
|
45
|
-
|
|
46
|
-
if (verboseLogs) {
|
|
47
|
-
payload.logger.info(
|
|
48
|
-
`[payload-mcp] Updating resource in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
// Parse the data JSON
|
|
54
|
-
let parsedData: Record<string, unknown>
|
|
55
|
-
try {
|
|
56
|
-
parsedData = JSON.parse(data)
|
|
57
|
-
|
|
58
|
-
// Transform point fields from object format to tuple array
|
|
59
|
-
parsedData = transformPointDataToPayload(parsedData)
|
|
60
|
-
|
|
61
|
-
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)
|
|
62
|
-
parsedData = stripVirtualFields(parsedData, virtualFieldNames)
|
|
63
|
-
|
|
64
|
-
if (verboseLogs) {
|
|
65
|
-
payload.logger.info(
|
|
66
|
-
`[payload-mcp] Parsed data for ${collectionSlug}: ${JSON.stringify(parsedData)}`,
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
} catch (_parseError) {
|
|
70
|
-
payload.logger.error(`[payload-mcp] Invalid JSON data provided: ${data}`)
|
|
71
|
-
const response = {
|
|
72
|
-
content: [{ type: 'text' as const, text: 'Error: Invalid JSON data provided' }],
|
|
73
|
-
}
|
|
74
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||
|
|
75
|
-
response) as {
|
|
76
|
-
content: Array<{
|
|
77
|
-
text: string
|
|
78
|
-
type: 'text'
|
|
79
|
-
}>
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Validate that either id or where is provided
|
|
84
|
-
if (!id && !where) {
|
|
85
|
-
payload.logger.error('[payload-mcp] Either id or where clause must be provided')
|
|
86
|
-
const response = {
|
|
87
|
-
content: [
|
|
88
|
-
{ type: 'text' as const, text: 'Error: Either id or where clause must be provided' },
|
|
89
|
-
],
|
|
90
|
-
}
|
|
91
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||
|
|
92
|
-
response) as {
|
|
93
|
-
content: Array<{
|
|
94
|
-
text: string
|
|
95
|
-
type: 'text'
|
|
96
|
-
}>
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Parse where clause if provided
|
|
101
|
-
let whereClause = {}
|
|
102
|
-
if (where) {
|
|
103
|
-
try {
|
|
104
|
-
whereClause = JSON.parse(where)
|
|
105
|
-
if (verboseLogs) {
|
|
106
|
-
payload.logger.info(`[payload-mcp] Using where clause: ${where}`)
|
|
107
|
-
}
|
|
108
|
-
} catch (_parseError) {
|
|
109
|
-
payload.logger.error(`[payload-mcp] Invalid where clause JSON: ${where}`)
|
|
110
|
-
const response = {
|
|
111
|
-
content: [{ type: 'text' as const, text: 'Error: Invalid JSON in where clause' }],
|
|
112
|
-
}
|
|
113
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||
|
|
114
|
-
response) as {
|
|
115
|
-
content: Array<{
|
|
116
|
-
text: string
|
|
117
|
-
type: 'text'
|
|
118
|
-
}>
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
let selectClause: SelectType | undefined
|
|
124
|
-
if (select) {
|
|
125
|
-
try {
|
|
126
|
-
selectClause = JSON.parse(select) as SelectType
|
|
127
|
-
} catch (_parseError) {
|
|
128
|
-
payload.logger.warn(`[payload-mcp] Invalid select clause JSON: ${select}`)
|
|
129
|
-
const response = {
|
|
130
|
-
content: [{ type: 'text' as const, text: 'Error: Invalid JSON in select clause' }],
|
|
131
|
-
}
|
|
132
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) ||
|
|
133
|
-
response) as {
|
|
134
|
-
content: Array<{
|
|
135
|
-
text: string
|
|
136
|
-
type: 'text'
|
|
137
|
-
}>
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Update by ID or where clause
|
|
143
|
-
if (id) {
|
|
144
|
-
// Single document update
|
|
145
|
-
const updateOptions = {
|
|
146
|
-
id,
|
|
147
|
-
collection: collectionSlug,
|
|
148
|
-
data: parsedData,
|
|
149
|
-
depth,
|
|
150
|
-
draft,
|
|
151
|
-
overrideAccess: false,
|
|
152
|
-
overrideLock,
|
|
153
|
-
req,
|
|
154
|
-
user,
|
|
155
|
-
...(filePath && { filePath }),
|
|
156
|
-
...(overwriteExistingFiles && { overwriteExistingFiles }),
|
|
157
|
-
...(locale && { locale }),
|
|
158
|
-
...(fallbackLocale && { fallbackLocale }),
|
|
159
|
-
...(selectClause && { select: selectClause }),
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (verboseLogs) {
|
|
163
|
-
payload.logger.info(`[payload-mcp] Updating single document with ID: ${id}`)
|
|
164
|
-
}
|
|
165
|
-
const result = await payload.update({
|
|
166
|
-
...updateOptions,
|
|
167
|
-
data: parsedData,
|
|
168
|
-
} as any)
|
|
169
|
-
|
|
170
|
-
if (verboseLogs) {
|
|
171
|
-
payload.logger.info(`[payload-mcp] Successfully updated document with ID: ${id}`)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const response = {
|
|
175
|
-
content: [
|
|
176
|
-
{
|
|
177
|
-
type: 'text' as const,
|
|
178
|
-
text: `Document updated successfully in collection "${collectionSlug}"!
|
|
179
|
-
Updated document:
|
|
180
|
-
\`\`\`json
|
|
181
|
-
${JSON.stringify(result)}
|
|
182
|
-
\`\`\``,
|
|
183
|
-
},
|
|
184
|
-
],
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||
|
|
188
|
-
response) as {
|
|
189
|
-
content: Array<{
|
|
190
|
-
text: string
|
|
191
|
-
type: 'text'
|
|
192
|
-
}>
|
|
193
|
-
}
|
|
194
|
-
} else {
|
|
195
|
-
// Multiple documents update
|
|
196
|
-
const updateOptions = {
|
|
197
|
-
collection: collectionSlug,
|
|
198
|
-
data: parsedData,
|
|
199
|
-
depth,
|
|
200
|
-
draft,
|
|
201
|
-
overrideAccess: false,
|
|
202
|
-
overrideLock,
|
|
203
|
-
req,
|
|
204
|
-
user,
|
|
205
|
-
where: whereClause,
|
|
206
|
-
...(filePath && { filePath }),
|
|
207
|
-
...(overwriteExistingFiles && { overwriteExistingFiles }),
|
|
208
|
-
...(locale && { locale }),
|
|
209
|
-
...(fallbackLocale && { fallbackLocale }),
|
|
210
|
-
...(selectClause && { select: selectClause }),
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (verboseLogs) {
|
|
214
|
-
payload.logger.info(`[payload-mcp] Updating multiple documents with where clause`)
|
|
215
|
-
}
|
|
216
|
-
const result = await payload.update({
|
|
217
|
-
...updateOptions,
|
|
218
|
-
data: parsedData,
|
|
219
|
-
} as any)
|
|
220
|
-
|
|
221
|
-
const bulkResult = result as { docs?: unknown[]; errors?: unknown[] }
|
|
222
|
-
const docs = bulkResult.docs || []
|
|
223
|
-
const errors = bulkResult.errors || []
|
|
224
|
-
|
|
225
|
-
if (verboseLogs) {
|
|
226
|
-
payload.logger.info(
|
|
227
|
-
`[payload-mcp] Successfully updated ${docs.length} documents, ${errors.length} errors`,
|
|
228
|
-
)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
let responseText = `Multiple documents updated in collection "${collectionSlug}"!
|
|
232
|
-
Updated: ${docs.length} documents
|
|
233
|
-
Errors: ${errors.length}
|
|
234
|
-
---`
|
|
235
|
-
|
|
236
|
-
if (docs.length > 0) {
|
|
237
|
-
responseText += `\n\nUpdated documents:
|
|
238
|
-
\`\`\`json
|
|
239
|
-
${JSON.stringify(docs)}
|
|
240
|
-
\`\`\``
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (errors.length > 0) {
|
|
244
|
-
responseText += `\n\nErrors:
|
|
245
|
-
\`\`\`json
|
|
246
|
-
${JSON.stringify(errors)}
|
|
247
|
-
\`\`\``
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const response = {
|
|
251
|
-
content: [
|
|
252
|
-
{
|
|
253
|
-
type: 'text' as const,
|
|
254
|
-
text: responseText,
|
|
255
|
-
},
|
|
256
|
-
],
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(
|
|
260
|
-
response,
|
|
261
|
-
{ docs, errors },
|
|
262
|
-
req,
|
|
263
|
-
) || response) as {
|
|
264
|
-
content: Array<{
|
|
265
|
-
text: string
|
|
266
|
-
type: 'text'
|
|
267
|
-
}>
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
} catch (error) {
|
|
271
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
272
|
-
payload.logger.error(
|
|
273
|
-
`[payload-mcp] Error updating resource in ${collectionSlug}: ${errorMessage}`,
|
|
274
|
-
)
|
|
275
|
-
|
|
276
|
-
const response = {
|
|
277
|
-
content: [
|
|
278
|
-
{
|
|
279
|
-
type: 'text' as const,
|
|
280
|
-
text: `Error updating resource in collection "${collectionSlug}": ${errorMessage}`,
|
|
281
|
-
},
|
|
282
|
-
],
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {
|
|
286
|
-
content: Array<{
|
|
287
|
-
text: string
|
|
288
|
-
type: 'text'
|
|
289
|
-
}>
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (collections?.[collectionSlug]?.enabled) {
|
|
295
|
-
const convertedFields = convertCollectionSchemaToZod(schema)
|
|
296
|
-
|
|
297
|
-
// Create a new schema that combines the converted fields with update-specific parameters
|
|
298
|
-
// Use .partial() to make all fields optional for partial updates
|
|
299
|
-
const updateResourceSchema = z.object({
|
|
300
|
-
...convertedFields.partial().shape,
|
|
301
|
-
id: z.union([z.string(), z.number()]).optional().describe('The ID of the document to update'),
|
|
302
|
-
depth: z
|
|
303
|
-
.number()
|
|
304
|
-
.optional()
|
|
305
|
-
.default(0)
|
|
306
|
-
.describe('How many levels deep to populate relationships'),
|
|
307
|
-
draft: z
|
|
308
|
-
.boolean()
|
|
309
|
-
.optional()
|
|
310
|
-
.default(false)
|
|
311
|
-
.describe('Whether to update the document as a draft'),
|
|
312
|
-
fallbackLocale: z
|
|
313
|
-
.string()
|
|
314
|
-
.optional()
|
|
315
|
-
.describe('Optional: fallback locale code to use when requested locale is not available'),
|
|
316
|
-
filePath: z.string().optional().describe('File path for file uploads'),
|
|
317
|
-
locale: z
|
|
318
|
-
.string()
|
|
319
|
-
.optional()
|
|
320
|
-
.describe(
|
|
321
|
-
'Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale',
|
|
322
|
-
),
|
|
323
|
-
overrideLock: z
|
|
324
|
-
.boolean()
|
|
325
|
-
.optional()
|
|
326
|
-
.default(true)
|
|
327
|
-
.describe('Whether to override document locks'),
|
|
328
|
-
overwriteExistingFiles: z
|
|
329
|
-
.boolean()
|
|
330
|
-
.optional()
|
|
331
|
-
.default(false)
|
|
332
|
-
.describe('Whether to overwrite existing files'),
|
|
333
|
-
select: z
|
|
334
|
-
.string()
|
|
335
|
-
.optional()
|
|
336
|
-
.describe(
|
|
337
|
-
'Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"title": "My Post"}\'',
|
|
338
|
-
),
|
|
339
|
-
where: z
|
|
340
|
-
.string()
|
|
341
|
-
.optional()
|
|
342
|
-
.describe('JSON string for where clause to update multiple documents'),
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
server.registerTool(
|
|
346
|
-
`update${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,
|
|
347
|
-
{
|
|
348
|
-
description: `${collections?.[collectionSlug]?.description || toolSchemas.updateResource.description.trim()}`,
|
|
349
|
-
inputSchema: updateResourceSchema.shape,
|
|
350
|
-
},
|
|
351
|
-
async (params: Record<string, unknown>) => {
|
|
352
|
-
const {
|
|
353
|
-
id,
|
|
354
|
-
depth,
|
|
355
|
-
draft,
|
|
356
|
-
fallbackLocale,
|
|
357
|
-
filePath,
|
|
358
|
-
locale,
|
|
359
|
-
overrideLock,
|
|
360
|
-
overwriteExistingFiles,
|
|
361
|
-
select,
|
|
362
|
-
where,
|
|
363
|
-
...fieldData
|
|
364
|
-
} = params
|
|
365
|
-
// Convert field data back to JSON string format expected by the tool
|
|
366
|
-
const data = JSON.stringify(fieldData)
|
|
367
|
-
return await tool(
|
|
368
|
-
data,
|
|
369
|
-
id as number | string | undefined,
|
|
370
|
-
where as string | undefined,
|
|
371
|
-
draft as boolean,
|
|
372
|
-
depth as number,
|
|
373
|
-
overrideLock as boolean,
|
|
374
|
-
filePath as string | undefined,
|
|
375
|
-
overwriteExistingFiles as boolean,
|
|
376
|
-
locale as string | undefined,
|
|
377
|
-
fallbackLocale as string | undefined,
|
|
378
|
-
select as string | undefined,
|
|
379
|
-
)
|
|
380
|
-
},
|
|
381
|
-
)
|
|
382
|
-
}
|
|
383
|
-
}
|