@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
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
|
+
import {
|
|
8
|
+
getCollectionVirtualFieldNames,
|
|
9
|
+
stripVirtualFields,
|
|
10
|
+
} from '../../../utils/getVirtualFieldNames.js'
|
|
11
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
12
|
+
import { prepareCollectionSchema } from '../../../utils/schemaConversion/prepareCollectionSchema.js'
|
|
13
|
+
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
14
|
+
|
|
15
|
+
const DEFAULT_DESCRIPTION = 'Update documents in a collection by ID or where clause.'
|
|
16
|
+
|
|
17
|
+
export const updateCollectionTool = defineCollectionTool({
|
|
18
|
+
description: DEFAULT_DESCRIPTION,
|
|
19
|
+
input: ({ collectionSchema }) => {
|
|
20
|
+
const partialSchema = prepareCollectionSchema(collectionSchema)
|
|
21
|
+
|
|
22
|
+
// Collection updates do not require all required fields to be passed => delete .required.
|
|
23
|
+
//
|
|
24
|
+
// Local API equivalent: packages/payload/src/collections/operations/local/update.ts#BaseOptions#data:
|
|
25
|
+
// data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>
|
|
26
|
+
delete partialSchema.required
|
|
27
|
+
|
|
28
|
+
return z.object({
|
|
29
|
+
id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),
|
|
30
|
+
data: z
|
|
31
|
+
.fromJSONSchema(partialSchema as unknown as z.core.JSONSchema.JSONSchema)
|
|
32
|
+
.describe('The fields to update'),
|
|
33
|
+
depth: z
|
|
34
|
+
.number()
|
|
35
|
+
.describe('How many levels deep to populate relationships')
|
|
36
|
+
.optional()
|
|
37
|
+
.default(0),
|
|
38
|
+
draft: z
|
|
39
|
+
.boolean()
|
|
40
|
+
.describe('Whether to update the document as a draft')
|
|
41
|
+
.optional()
|
|
42
|
+
.default(false),
|
|
43
|
+
fallbackLocale: z
|
|
44
|
+
.string()
|
|
45
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
46
|
+
.optional(),
|
|
47
|
+
filePath: z.string().describe('File path for file uploads').optional(),
|
|
48
|
+
locale: z
|
|
49
|
+
.string()
|
|
50
|
+
.describe(
|
|
51
|
+
'Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale',
|
|
52
|
+
)
|
|
53
|
+
.optional(),
|
|
54
|
+
overrideLock: z
|
|
55
|
+
.boolean()
|
|
56
|
+
.describe('Whether to override document locks')
|
|
57
|
+
.optional()
|
|
58
|
+
.default(true),
|
|
59
|
+
overwriteExistingFiles: z
|
|
60
|
+
.boolean()
|
|
61
|
+
.describe('Whether to overwrite existing files')
|
|
62
|
+
.optional()
|
|
63
|
+
.default(false),
|
|
64
|
+
select: z
|
|
65
|
+
.string()
|
|
66
|
+
.describe(
|
|
67
|
+
'Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"title": "My Post"}\'',
|
|
68
|
+
)
|
|
69
|
+
.optional(),
|
|
70
|
+
where: z
|
|
71
|
+
.string()
|
|
72
|
+
.describe('JSON string for where clause to update multiple documents')
|
|
73
|
+
.optional(),
|
|
74
|
+
})
|
|
75
|
+
},
|
|
76
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
77
|
+
const payload = req.payload
|
|
78
|
+
const logger = getLogger({ payload })
|
|
79
|
+
|
|
80
|
+
const {
|
|
81
|
+
id,
|
|
82
|
+
data,
|
|
83
|
+
depth,
|
|
84
|
+
draft,
|
|
85
|
+
fallbackLocale,
|
|
86
|
+
filePath,
|
|
87
|
+
locale,
|
|
88
|
+
overrideLock,
|
|
89
|
+
overwriteExistingFiles,
|
|
90
|
+
select,
|
|
91
|
+
where,
|
|
92
|
+
} = input
|
|
93
|
+
|
|
94
|
+
logger.info(
|
|
95
|
+
`Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
if (!id && !where) {
|
|
100
|
+
return {
|
|
101
|
+
content: [{ type: 'text', text: 'Error: Either id or where clause must be provided' }],
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let parsedData = transformPointDataToPayload(data as Record<string, unknown>)
|
|
106
|
+
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)
|
|
107
|
+
parsedData = stripVirtualFields(parsedData, virtualFieldNames)
|
|
108
|
+
|
|
109
|
+
let whereClause: Record<string, unknown> = {}
|
|
110
|
+
if (where) {
|
|
111
|
+
try {
|
|
112
|
+
whereClause = JSON.parse(where) as Record<string, unknown>
|
|
113
|
+
} catch {
|
|
114
|
+
logger.error(`Invalid where clause JSON: ${where}`)
|
|
115
|
+
return { content: [{ type: 'text', text: 'Error: Invalid JSON in where clause' }] }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let selectClause: SelectType | undefined
|
|
120
|
+
if (select) {
|
|
121
|
+
try {
|
|
122
|
+
selectClause = JSON.parse(select) as SelectType
|
|
123
|
+
} catch {
|
|
124
|
+
logger.warn(`Invalid select clause JSON: ${select}`)
|
|
125
|
+
return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (id) {
|
|
130
|
+
const updateOptions = {
|
|
131
|
+
id,
|
|
132
|
+
collection: collectionSlug,
|
|
133
|
+
data: parsedData,
|
|
134
|
+
depth,
|
|
135
|
+
draft,
|
|
136
|
+
overrideLock,
|
|
137
|
+
req,
|
|
138
|
+
...localAPIDefaults(authorizedMCP),
|
|
139
|
+
...(filePath ? { filePath } : {}),
|
|
140
|
+
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
141
|
+
...(locale ? { locale } : {}),
|
|
142
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
143
|
+
...(selectClause ? { select: selectClause } : {}),
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const result = await payload.update(updateOptions as any)
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
content: [
|
|
150
|
+
{
|
|
151
|
+
type: 'text',
|
|
152
|
+
text: `Document updated successfully in collection "${collectionSlug}"!\nUpdated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
doc: result as Record<string, unknown>,
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const updateOptions = {
|
|
160
|
+
collection: collectionSlug,
|
|
161
|
+
data: parsedData,
|
|
162
|
+
depth,
|
|
163
|
+
draft,
|
|
164
|
+
overrideLock,
|
|
165
|
+
req,
|
|
166
|
+
...localAPIDefaults(authorizedMCP),
|
|
167
|
+
where: whereClause,
|
|
168
|
+
...(filePath ? { filePath } : {}),
|
|
169
|
+
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
170
|
+
...(locale ? { locale } : {}),
|
|
171
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
172
|
+
...(selectClause ? { select: selectClause } : {}),
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const result = await payload.update(updateOptions as any)
|
|
176
|
+
|
|
177
|
+
const bulkResult = result as { docs?: unknown[]; errors?: unknown[] }
|
|
178
|
+
const docs = bulkResult.docs || []
|
|
179
|
+
const errors = bulkResult.errors || []
|
|
180
|
+
|
|
181
|
+
let responseText = `Multiple documents updated in collection "${collectionSlug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`
|
|
182
|
+
if (docs.length > 0) {
|
|
183
|
+
responseText += `\n\nUpdated documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``
|
|
184
|
+
}
|
|
185
|
+
if (errors.length > 0) {
|
|
186
|
+
responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
content: [{ type: 'text', text: responseText }],
|
|
191
|
+
doc: { docs, errors } as unknown as Record<string, unknown>,
|
|
192
|
+
}
|
|
193
|
+
} catch (error) {
|
|
194
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
195
|
+
logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`)
|
|
196
|
+
return {
|
|
197
|
+
content: [
|
|
198
|
+
{
|
|
199
|
+
type: 'text',
|
|
200
|
+
text: `Error updating document in collection "${collectionSlug}": ${errorMessage}`,
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
6
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
8
|
+
|
|
9
|
+
const DEFAULT_DESCRIPTION = 'Find a Payload global singleton configuration.'
|
|
10
|
+
|
|
11
|
+
export const findGlobalTool = defineGlobalTool({
|
|
12
|
+
description: DEFAULT_DESCRIPTION,
|
|
13
|
+
input: z.object({
|
|
14
|
+
depth: z
|
|
15
|
+
.number()
|
|
16
|
+
.int()
|
|
17
|
+
.min(0)
|
|
18
|
+
.max(10)
|
|
19
|
+
.describe('Depth of population for relationships')
|
|
20
|
+
.optional()
|
|
21
|
+
.default(0),
|
|
22
|
+
fallbackLocale: z
|
|
23
|
+
.string()
|
|
24
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
25
|
+
.optional(),
|
|
26
|
+
locale: z
|
|
27
|
+
.string()
|
|
28
|
+
.describe(
|
|
29
|
+
'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
|
|
30
|
+
)
|
|
31
|
+
.optional(),
|
|
32
|
+
select: z
|
|
33
|
+
.string()
|
|
34
|
+
.describe(
|
|
35
|
+
"Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'",
|
|
36
|
+
)
|
|
37
|
+
.optional(),
|
|
38
|
+
}),
|
|
39
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
40
|
+
const payload = req.payload
|
|
41
|
+
const logger = getLogger({ payload })
|
|
42
|
+
|
|
43
|
+
const { depth, fallbackLocale, locale, select } = input
|
|
44
|
+
|
|
45
|
+
logger.info(
|
|
46
|
+
`Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const findOptions: Parameters<typeof payload.findGlobal>[0] = {
|
|
51
|
+
slug: globalSlug,
|
|
52
|
+
depth,
|
|
53
|
+
...localAPIDefaults(authorizedMCP),
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let selectClause: SelectType | undefined
|
|
57
|
+
if (select) {
|
|
58
|
+
try {
|
|
59
|
+
selectClause = JSON.parse(select) as SelectType
|
|
60
|
+
} catch {
|
|
61
|
+
logger.warn(`Invalid select clause JSON for global: ${select}`)
|
|
62
|
+
return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (locale) {
|
|
67
|
+
findOptions.locale = locale
|
|
68
|
+
}
|
|
69
|
+
if (fallbackLocale) {
|
|
70
|
+
findOptions.fallbackLocale = fallbackLocale
|
|
71
|
+
}
|
|
72
|
+
if (selectClause) {
|
|
73
|
+
findOptions.select = selectClause
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const result = await payload.findGlobal(findOptions)
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
content: [
|
|
80
|
+
{
|
|
81
|
+
type: 'text',
|
|
82
|
+
text: `Global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
doc: result as Record<string, unknown>,
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
89
|
+
logger.error(`Error reading global ${globalSlug}: ${errorMessage}`)
|
|
90
|
+
return {
|
|
91
|
+
content: [
|
|
92
|
+
{ type: 'text', text: `❌ **Error reading global "${globalSlug}":** ${errorMessage}` },
|
|
93
|
+
],
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
})
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
6
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
|
+
import {
|
|
8
|
+
getGlobalVirtualFieldNames,
|
|
9
|
+
stripVirtualFields,
|
|
10
|
+
} from '../../../utils/getVirtualFieldNames.js'
|
|
11
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
12
|
+
import { prepareCollectionSchema } from '../../../utils/schemaConversion/prepareCollectionSchema.js'
|
|
13
|
+
|
|
14
|
+
const DEFAULT_DESCRIPTION = 'Update a Payload global singleton configuration.'
|
|
15
|
+
|
|
16
|
+
export const updateGlobalTool = defineGlobalTool({
|
|
17
|
+
description: DEFAULT_DESCRIPTION,
|
|
18
|
+
input: ({ globalSchema }) => {
|
|
19
|
+
const partialSchema = prepareCollectionSchema(globalSchema)
|
|
20
|
+
// Global updates do not require all required fields to be passed => delete .required.
|
|
21
|
+
//
|
|
22
|
+
// Local API equivalent: packages/payload/src/global/operations/local/update.ts#BaseOptions#data:
|
|
23
|
+
// data: DeepPartial<Omit<DataFromGlobalSlug<TSlug>, 'id'>>
|
|
24
|
+
delete partialSchema.required
|
|
25
|
+
|
|
26
|
+
return z.object({
|
|
27
|
+
data: z
|
|
28
|
+
.fromJSONSchema(partialSchema as unknown as z.core.JSONSchema.JSONSchema)
|
|
29
|
+
.describe('The fields to update'),
|
|
30
|
+
depth: z
|
|
31
|
+
.number()
|
|
32
|
+
.describe('Optional: Depth of relationships to populate')
|
|
33
|
+
.optional()
|
|
34
|
+
.default(0),
|
|
35
|
+
draft: z
|
|
36
|
+
.boolean()
|
|
37
|
+
.describe('Optional: Whether to save as draft (default: false)')
|
|
38
|
+
.optional()
|
|
39
|
+
.default(false),
|
|
40
|
+
fallbackLocale: z
|
|
41
|
+
.string()
|
|
42
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
43
|
+
.optional(),
|
|
44
|
+
locale: z
|
|
45
|
+
.string()
|
|
46
|
+
.describe(
|
|
47
|
+
'Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields',
|
|
48
|
+
)
|
|
49
|
+
.optional(),
|
|
50
|
+
select: z
|
|
51
|
+
.string()
|
|
52
|
+
.describe(
|
|
53
|
+
'Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"siteName": "My Site"}\'',
|
|
54
|
+
)
|
|
55
|
+
.optional(),
|
|
56
|
+
})
|
|
57
|
+
},
|
|
58
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
59
|
+
const payload = req.payload
|
|
60
|
+
const logger = getLogger({ payload })
|
|
61
|
+
|
|
62
|
+
const { data, depth, draft, fallbackLocale, locale, select } = input
|
|
63
|
+
|
|
64
|
+
logger.info(
|
|
65
|
+
`Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)
|
|
70
|
+
const parsedData = stripVirtualFields(data as Record<string, unknown>, virtualFieldNames)
|
|
71
|
+
|
|
72
|
+
let selectClause: SelectType | undefined
|
|
73
|
+
if (select) {
|
|
74
|
+
try {
|
|
75
|
+
selectClause = JSON.parse(select) as SelectType
|
|
76
|
+
} catch {
|
|
77
|
+
logger.warn(`Invalid select clause JSON for global: ${select}`)
|
|
78
|
+
return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {
|
|
83
|
+
slug: globalSlug,
|
|
84
|
+
data: parsedData,
|
|
85
|
+
depth,
|
|
86
|
+
draft,
|
|
87
|
+
...localAPIDefaults(authorizedMCP),
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (locale) {
|
|
91
|
+
updateOptions.locale = locale
|
|
92
|
+
}
|
|
93
|
+
if (fallbackLocale) {
|
|
94
|
+
updateOptions.fallbackLocale = fallbackLocale
|
|
95
|
+
}
|
|
96
|
+
if (selectClause) {
|
|
97
|
+
updateOptions.select = selectClause
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const result = await payload.updateGlobal(updateOptions)
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
content: [
|
|
104
|
+
{
|
|
105
|
+
type: 'text',
|
|
106
|
+
text: `Global "${globalSlug}" updated successfully!\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
doc: result as Record<string, unknown>,
|
|
110
|
+
}
|
|
111
|
+
} catch (error) {
|
|
112
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
113
|
+
logger.error(`Error updating global ${globalSlug}: ${errorMessage}`)
|
|
114
|
+
return {
|
|
115
|
+
content: [{ type: 'text', text: `Error updating global "${globalSlug}": ${errorMessage}` }],
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { CollectionTool, GlobalTool } from '../types.js'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
authCollectionTool,
|
|
5
|
+
forgotPasswordCollectionTool,
|
|
6
|
+
loginCollectionTool,
|
|
7
|
+
resetPasswordCollectionTool,
|
|
8
|
+
unlockCollectionTool,
|
|
9
|
+
verifyCollectionTool,
|
|
10
|
+
} from './builtin/collections/authTools.js'
|
|
11
|
+
import { createCollectionTool } from './builtin/collections/createTool.js'
|
|
12
|
+
import { deleteCollectionTool } from './builtin/collections/deleteTool.js'
|
|
13
|
+
import { findCollectionTool } from './builtin/collections/findTool.js'
|
|
14
|
+
import { updateCollectionTool } from './builtin/collections/updateTool.js'
|
|
15
|
+
import { findGlobalTool } from './builtin/globals/findTool.js'
|
|
16
|
+
import { updateGlobalTool } from './builtin/globals/updateTool.js'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The static built-in collection CRUD tools. Keys here are the source of truth
|
|
20
|
+
* for `MCPCollectionBuiltinName` — adding/removing an entry updates the type
|
|
21
|
+
* automatically.
|
|
22
|
+
*/
|
|
23
|
+
export const COLLECTION_BUILTINS: Record<MCPCollectionBuiltinName, CollectionTool> = {
|
|
24
|
+
create: createCollectionTool,
|
|
25
|
+
delete: deleteCollectionTool,
|
|
26
|
+
find: findCollectionTool,
|
|
27
|
+
update: updateCollectionTool,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The static auth tools surfaced under auth-enabled collections. Each entry
|
|
32
|
+
* carries the admin-UI label alongside the tool. Keys are the source of truth
|
|
33
|
+
* for `MCPCollectionAuthToolName`.
|
|
34
|
+
*/
|
|
35
|
+
export const COLLECTION_AUTH_BUILTINS: Record<
|
|
36
|
+
MCPCollectionAuthToolName,
|
|
37
|
+
{ label: string; tool: CollectionTool }
|
|
38
|
+
> = {
|
|
39
|
+
auth: { label: 'Check Auth Status', tool: authCollectionTool },
|
|
40
|
+
forgotPassword: { label: 'Forgot Password', tool: forgotPasswordCollectionTool },
|
|
41
|
+
login: { label: 'User Login', tool: loginCollectionTool },
|
|
42
|
+
resetPassword: { label: 'Reset Password', tool: resetPasswordCollectionTool },
|
|
43
|
+
unlock: { label: 'Unlock Account', tool: unlockCollectionTool },
|
|
44
|
+
verify: { label: 'Email Verification', tool: verifyCollectionTool },
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The static built-in global tools. Keys are the source of truth for
|
|
49
|
+
* `MCPGlobalBuiltinName`.
|
|
50
|
+
*/
|
|
51
|
+
export const GLOBAL_BUILTINS: Record<MCPGlobalBuiltinName, GlobalTool> = {
|
|
52
|
+
find: findGlobalTool,
|
|
53
|
+
update: updateGlobalTool,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type MCPCollectionBuiltinName = 'create' | 'delete' | 'find' | 'update'
|
|
57
|
+
|
|
58
|
+
export type MCPCollectionAuthToolName =
|
|
59
|
+
| 'auth'
|
|
60
|
+
| 'forgotPassword'
|
|
61
|
+
| 'login'
|
|
62
|
+
| 'resetPassword'
|
|
63
|
+
| 'unlock'
|
|
64
|
+
| 'verify'
|
|
65
|
+
|
|
66
|
+
export type MCPGlobalBuiltinName = 'find' | 'update'
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Pre-typed `Object.entries` for each registry. The cast from `string` to the
|
|
70
|
+
* literal key union lives here once so consumers can iterate without their own
|
|
71
|
+
* cast — TypeScript's `Object.entries` always widens keys to `string`, which
|
|
72
|
+
* defeats the narrow type lookups on `MCPCollectionToolsMap`.
|
|
73
|
+
*/
|
|
74
|
+
export const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS) as Array<
|
|
75
|
+
[MCPCollectionBuiltinName, CollectionTool]
|
|
76
|
+
>
|
|
77
|
+
|
|
78
|
+
export const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS) as Array<
|
|
79
|
+
[MCPCollectionAuthToolName, { label: string; tool: CollectionTool }]
|
|
80
|
+
>
|
|
81
|
+
|
|
82
|
+
export const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS) as Array<
|
|
83
|
+
[MCPGlobalBuiltinName, GlobalTool]
|
|
84
|
+
>
|