@payloadcms/plugin-mcp 4.0.0-internal.c2b57ce → 4.0.0-internal.cd69eef
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 +1 -1
- package/bin.js +7 -0
- package/dist/defaultAccess.d.ts +3 -0
- package/dist/defaultAccess.d.ts.map +1 -0
- package/dist/defaultAccess.js +3 -0
- package/dist/defaultAccess.js.map +1 -0
- package/dist/defineTool.d.ts +8 -8
- package/dist/defineTool.d.ts.map +1 -1
- package/dist/endpoint/access.d.ts +12 -5
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +75 -88
- package/dist/endpoint/access.js.map +1 -1
- package/dist/endpoint/index.d.ts +1 -1
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +70 -19
- package/dist/endpoint/index.js.map +1 -1
- package/dist/exports/client.d.ts +1 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -20
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +4 -4
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +133 -73
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/authTools.js +44 -6
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countTool.js +68 -0
- package/dist/mcp/builtin/collections/countTool.js.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js +64 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +50 -41
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +15 -22
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.js +96 -0
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts +20 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.js +100 -0
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.spec.js +72 -0
- package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js +92 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +52 -47
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +83 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js +98 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +86 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js +81 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +106 -89
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.js +68 -0
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +20 -23
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +65 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +33 -38
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
- package/dist/mcp/builtin/validateEntityData.js +82 -0
- package/dist/mcp/builtin/validateEntityData.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +144 -19
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +119 -20
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +121 -58
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts +3 -3
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +82 -45
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +112 -110
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -4
- package/dist/types.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/getPluginConfig.d.ts +1 -1
- package/dist/utils/getPluginConfig.js +1 -1
- package/dist/utils/getPluginConfig.js.map +1 -1
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +13 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +10 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +384 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +133 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
- package/dist/utils/toStandardSchema.d.ts.map +1 -1
- package/dist/utils/whereSchema.d.ts +9 -0
- package/dist/utils/whereSchema.d.ts.map +1 -0
- package/dist/utils/whereSchema.js +13 -0
- package/dist/utils/whereSchema.js.map +1 -0
- package/package.json +16 -21
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +81 -101
- package/src/endpoint/index.ts +59 -17
- package/src/exports/client.ts +2 -1
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +12 -20
- package/src/mcp/buildMcpServer.ts +169 -109
- package/src/mcp/builtin/collections/authTools.ts +45 -9
- package/src/mcp/builtin/collections/countTool.ts +73 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
- package/src/mcp/builtin/collections/createTool.ts +67 -62
- package/src/mcp/builtin/collections/deleteTool.ts +20 -18
- package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
- package/src/mcp/builtin/collections/fileInput.spec.ts +79 -0
- package/src/mcp/builtin/collections/fileInput.ts +139 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
- package/src/mcp/builtin/collections/findTool.ts +66 -37
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
- package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +76 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
- package/src/mcp/builtin/collections/updateTool.ts +132 -110
- package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
- package/src/mcp/builtin/globals/findTool.ts +28 -19
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
- package/src/mcp/builtin/globals/updateTool.ts +52 -55
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +111 -41
- package/src/mcp/sanitizeMCPConfig.ts +117 -78
- package/src/stdio.ts +77 -45
- package/src/types.ts +128 -115
- package/src/utils/getPluginConfig.ts +1 -1
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +96 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +432 -0
- package/src/utils/whereSchema.ts +24 -0
- package/dist/collection/getAccessField.d.ts +0 -12
- package/dist/collection/getAccessField.d.ts.map +0 -1
- package/dist/collection/getAccessField.js +0 -57
- package/dist/collection/getAccessField.js.map +0 -1
- package/dist/collection/index.d.ts +0 -6
- package/dist/collection/index.d.ts.map +0 -1
- package/dist/collection/index.js +0 -59
- package/dist/collection/index.js.map +0 -1
- package/dist/components/AccessField/index.client.d.ts +0 -10
- package/dist/components/AccessField/index.client.d.ts.map +0 -1
- package/dist/components/AccessField/index.client.js +0 -305
- package/dist/components/AccessField/index.client.js.map +0 -1
- package/dist/components/AccessField/index.css +0 -93
- package/dist/utils/localAPIDefaults.d.ts +0 -20
- package/dist/utils/localAPIDefaults.d.ts.map +0 -1
- package/dist/utils/localAPIDefaults.js +0 -19
- package/dist/utils/localAPIDefaults.js.map +0 -1
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/prepareCollectionSchema.js +0 -37
- package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -56
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
- package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.js +0 -57
- package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
- package/src/collection/getAccessField.ts +0 -64
- package/src/collection/index.ts +0 -63
- package/src/components/AccessField/index.client.tsx +0 -344
- package/src/components/AccessField/index.css +0 -93
- package/src/utils/localAPIDefaults.ts +0 -22
- package/src/utils/schemaConversion/prepareCollectionSchema.ts +0 -39
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -70
- package/src/utils/schemaConversion/transformPointFields.ts +0 -56
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import type { SelectType } from 'payload'
|
|
1
|
+
import type { PopulateType, SelectType } from 'payload'
|
|
2
2
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
5
6
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
6
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
8
8
|
|
|
9
|
-
const DEFAULT_DESCRIPTION = 'Find
|
|
9
|
+
const DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.'
|
|
10
10
|
|
|
11
11
|
export const findGlobalTool = defineGlobalTool({
|
|
12
|
+
access: (args) =>
|
|
13
|
+
defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.read),
|
|
14
|
+
annotations: {
|
|
15
|
+
destructiveHint: false,
|
|
16
|
+
idempotentHint: true,
|
|
17
|
+
openWorldHint: false,
|
|
18
|
+
readOnlyHint: true,
|
|
19
|
+
title: 'Find Global',
|
|
20
|
+
},
|
|
12
21
|
description: DEFAULT_DESCRIPTION,
|
|
13
22
|
input: z.object({
|
|
14
23
|
depth: z
|
|
@@ -29,10 +38,16 @@ export const findGlobalTool = defineGlobalTool({
|
|
|
29
38
|
'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
|
|
30
39
|
)
|
|
31
40
|
.optional(),
|
|
41
|
+
populate: z
|
|
42
|
+
.record(z.string(), z.unknown())
|
|
43
|
+
.describe(
|
|
44
|
+
'Optional: control which fields to include from populated relationship or upload documents.',
|
|
45
|
+
)
|
|
46
|
+
.optional(),
|
|
32
47
|
select: z
|
|
33
|
-
.string()
|
|
48
|
+
.record(z.string(), z.unknown())
|
|
34
49
|
.describe(
|
|
35
|
-
|
|
50
|
+
'Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}',
|
|
36
51
|
)
|
|
37
52
|
.optional(),
|
|
38
53
|
}),
|
|
@@ -40,7 +55,7 @@ export const findGlobalTool = defineGlobalTool({
|
|
|
40
55
|
const payload = req.payload
|
|
41
56
|
const logger = getLogger({ payload })
|
|
42
57
|
|
|
43
|
-
const { depth, fallbackLocale, locale, select } = input
|
|
58
|
+
const { depth, fallbackLocale, locale, populate, select } = input
|
|
44
59
|
|
|
45
60
|
logger.info(
|
|
46
61
|
`Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,
|
|
@@ -50,17 +65,8 @@ export const findGlobalTool = defineGlobalTool({
|
|
|
50
65
|
const findOptions: Parameters<typeof payload.findGlobal>[0] = {
|
|
51
66
|
slug: globalSlug,
|
|
52
67
|
depth,
|
|
53
|
-
|
|
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
|
-
}
|
|
68
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
69
|
+
req,
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
if (locale) {
|
|
@@ -69,8 +75,11 @@ export const findGlobalTool = defineGlobalTool({
|
|
|
69
75
|
if (fallbackLocale) {
|
|
70
76
|
findOptions.fallbackLocale = fallbackLocale
|
|
71
77
|
}
|
|
72
|
-
if (
|
|
73
|
-
findOptions.select =
|
|
78
|
+
if (select) {
|
|
79
|
+
findOptions.select = select as SelectType
|
|
80
|
+
}
|
|
81
|
+
if (populate) {
|
|
82
|
+
findOptions.populate = populate as PopulateType
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
const result = await payload.findGlobal(findOptions)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { PopulateType, SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
+
|
|
9
|
+
const DEFAULT_DESCRIPTION =
|
|
10
|
+
'Find a specific global version in any version-enabled global by passing the global slug and version ID.'
|
|
11
|
+
|
|
12
|
+
export const findGlobalVersionByIDTool = defineGlobalTool({
|
|
13
|
+
access: (args) =>
|
|
14
|
+
defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
|
|
15
|
+
annotations: {
|
|
16
|
+
destructiveHint: false,
|
|
17
|
+
idempotentHint: true,
|
|
18
|
+
openWorldHint: false,
|
|
19
|
+
readOnlyHint: true,
|
|
20
|
+
title: 'Find Global Version By ID',
|
|
21
|
+
},
|
|
22
|
+
description: DEFAULT_DESCRIPTION,
|
|
23
|
+
input: z.object({
|
|
24
|
+
id: z.string().describe('The ID of the global version to retrieve'),
|
|
25
|
+
depth: z
|
|
26
|
+
.number()
|
|
27
|
+
.int()
|
|
28
|
+
.min(0)
|
|
29
|
+
.max(10)
|
|
30
|
+
.describe('How many levels deep to populate relationships in the global version document')
|
|
31
|
+
.optional()
|
|
32
|
+
.default(0),
|
|
33
|
+
fallbackLocale: z
|
|
34
|
+
.string()
|
|
35
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
36
|
+
.optional(),
|
|
37
|
+
locale: z
|
|
38
|
+
.string()
|
|
39
|
+
.describe(
|
|
40
|
+
'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
|
|
41
|
+
)
|
|
42
|
+
.optional(),
|
|
43
|
+
populate: z
|
|
44
|
+
.record(z.string(), z.unknown())
|
|
45
|
+
.describe(
|
|
46
|
+
'Optional: control which fields to include from populated relationship or upload documents.',
|
|
47
|
+
)
|
|
48
|
+
.optional(),
|
|
49
|
+
select: z
|
|
50
|
+
.record(z.string(), z.unknown())
|
|
51
|
+
.describe(
|
|
52
|
+
'Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.siteName": true}',
|
|
53
|
+
)
|
|
54
|
+
.optional(),
|
|
55
|
+
showHiddenFields: z
|
|
56
|
+
.boolean()
|
|
57
|
+
.describe('Optional: include hidden fields in the returned global version document')
|
|
58
|
+
.optional(),
|
|
59
|
+
}),
|
|
60
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
61
|
+
const payload = req.payload
|
|
62
|
+
const logger = getLogger({ payload })
|
|
63
|
+
const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields } = input
|
|
64
|
+
|
|
65
|
+
logger.info(`Finding version for global: ${globalSlug} with ID: ${id}`)
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const result = await payload.findGlobalVersionByID({
|
|
69
|
+
id,
|
|
70
|
+
slug: globalSlug,
|
|
71
|
+
depth,
|
|
72
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
73
|
+
req,
|
|
74
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
75
|
+
...(locale ? { locale } : {}),
|
|
76
|
+
...(populate ? { populate: populate as PopulateType } : {}),
|
|
77
|
+
...(select ? { select: select as SelectType } : {}),
|
|
78
|
+
...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
content: [
|
|
83
|
+
{
|
|
84
|
+
type: 'text',
|
|
85
|
+
text: `Version "${id}" from global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
doc: result as unknown as Record<string, unknown>,
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
92
|
+
logger.error(`Error finding version ${id} for global ${globalSlug}: ${errorMessage}`)
|
|
93
|
+
return {
|
|
94
|
+
content: [
|
|
95
|
+
{
|
|
96
|
+
type: 'text',
|
|
97
|
+
text: `❌ **Error finding version "${id}" for global "${globalSlug}":** ${errorMessage}`,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
isError: true,
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
})
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { PopulateType, SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
+
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
9
|
+
|
|
10
|
+
const DEFAULT_DESCRIPTION =
|
|
11
|
+
'Find global versions in any version-enabled global by passing the global slug and optional where clause.'
|
|
12
|
+
|
|
13
|
+
export const findGlobalVersionsTool = defineGlobalTool({
|
|
14
|
+
access: (args) =>
|
|
15
|
+
defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
|
|
16
|
+
annotations: {
|
|
17
|
+
destructiveHint: false,
|
|
18
|
+
idempotentHint: true,
|
|
19
|
+
openWorldHint: false,
|
|
20
|
+
readOnlyHint: true,
|
|
21
|
+
title: 'Find Global Versions',
|
|
22
|
+
},
|
|
23
|
+
description: DEFAULT_DESCRIPTION,
|
|
24
|
+
input: z.object({
|
|
25
|
+
depth: z
|
|
26
|
+
.number()
|
|
27
|
+
.int()
|
|
28
|
+
.min(0)
|
|
29
|
+
.max(10)
|
|
30
|
+
.describe('How many levels deep to populate relationships in global version documents')
|
|
31
|
+
.optional()
|
|
32
|
+
.default(0),
|
|
33
|
+
fallbackLocale: z
|
|
34
|
+
.string()
|
|
35
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
36
|
+
.optional(),
|
|
37
|
+
limit: z
|
|
38
|
+
.number()
|
|
39
|
+
.int()
|
|
40
|
+
.min(1)
|
|
41
|
+
.max(100)
|
|
42
|
+
.describe('Maximum number of versions to return (default: 10, max: 100)')
|
|
43
|
+
.optional()
|
|
44
|
+
.default(10),
|
|
45
|
+
locale: z
|
|
46
|
+
.string()
|
|
47
|
+
.describe(
|
|
48
|
+
'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
|
|
49
|
+
)
|
|
50
|
+
.optional(),
|
|
51
|
+
page: z
|
|
52
|
+
.number()
|
|
53
|
+
.int()
|
|
54
|
+
.min(1)
|
|
55
|
+
.describe('Page number for pagination (default: 1)')
|
|
56
|
+
.optional()
|
|
57
|
+
.default(1),
|
|
58
|
+
pagination: z
|
|
59
|
+
.boolean()
|
|
60
|
+
.describe('Optional: set to false to skip the count query overhead')
|
|
61
|
+
.optional(),
|
|
62
|
+
populate: z
|
|
63
|
+
.record(z.string(), z.unknown())
|
|
64
|
+
.describe(
|
|
65
|
+
'Optional: control which fields to include from populated relationship or upload documents.',
|
|
66
|
+
)
|
|
67
|
+
.optional(),
|
|
68
|
+
select: z
|
|
69
|
+
.record(z.string(), z.unknown())
|
|
70
|
+
.describe(
|
|
71
|
+
'Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.siteName": true}',
|
|
72
|
+
)
|
|
73
|
+
.optional(),
|
|
74
|
+
showHiddenFields: z
|
|
75
|
+
.boolean()
|
|
76
|
+
.describe('Optional: include hidden fields in returned global version documents')
|
|
77
|
+
.optional(),
|
|
78
|
+
sort: z
|
|
79
|
+
.string()
|
|
80
|
+
.describe('Field to sort by (e.g., "-updatedAt", "-version.updatedAt" for descending)')
|
|
81
|
+
.optional(),
|
|
82
|
+
where: whereSchema
|
|
83
|
+
.describe(
|
|
84
|
+
'Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.siteName":{"contains":"test"}}',
|
|
85
|
+
)
|
|
86
|
+
.optional(),
|
|
87
|
+
}),
|
|
88
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
89
|
+
const payload = req.payload
|
|
90
|
+
const logger = getLogger({ payload })
|
|
91
|
+
const {
|
|
92
|
+
depth,
|
|
93
|
+
fallbackLocale,
|
|
94
|
+
limit,
|
|
95
|
+
locale,
|
|
96
|
+
page,
|
|
97
|
+
pagination,
|
|
98
|
+
populate,
|
|
99
|
+
select,
|
|
100
|
+
showHiddenFields,
|
|
101
|
+
sort,
|
|
102
|
+
where,
|
|
103
|
+
} = input
|
|
104
|
+
|
|
105
|
+
logger.info(`Finding versions for global: ${globalSlug}, limit: ${limit}, page: ${page}`)
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const result = await payload.findGlobalVersions({
|
|
109
|
+
slug: globalSlug,
|
|
110
|
+
depth,
|
|
111
|
+
limit,
|
|
112
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
113
|
+
page,
|
|
114
|
+
req,
|
|
115
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
116
|
+
...(locale ? { locale } : {}),
|
|
117
|
+
...(pagination !== undefined ? { pagination } : {}),
|
|
118
|
+
...(populate ? { populate: populate as PopulateType } : {}),
|
|
119
|
+
...(select ? { select: select as SelectType } : {}),
|
|
120
|
+
...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
|
|
121
|
+
...(sort ? { sort } : {}),
|
|
122
|
+
...(where ? { where } : {}),
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
content: [
|
|
127
|
+
{
|
|
128
|
+
type: 'text',
|
|
129
|
+
text: `Versions for global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
doc: result as unknown as Record<string, unknown>,
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
136
|
+
logger.error(`Error finding versions for global ${globalSlug}: ${errorMessage}`)
|
|
137
|
+
return {
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
type: 'text',
|
|
141
|
+
text: `❌ **Error finding versions for global "${globalSlug}":** ${errorMessage}`,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
isError: true,
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { getAccessResults } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
5
|
+
import { getGlobalInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
6
|
+
|
|
7
|
+
export const getGlobalSchemaTool = defineGlobalTool({
|
|
8
|
+
access: (args) => {
|
|
9
|
+
const permissions = args.permissions?.globals?.[args.globalSlug]
|
|
10
|
+
|
|
11
|
+
return defaultAccess(args) && Boolean(permissions?.update)
|
|
12
|
+
},
|
|
13
|
+
annotations: {
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: true,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
title: 'Get Global Schema',
|
|
19
|
+
},
|
|
20
|
+
description: 'Get the input schema for updating a global.',
|
|
21
|
+
}).handler(async ({ authorizedMCP, globalSlug, req }) => {
|
|
22
|
+
const permissions = authorizedMCP.overrideAccess
|
|
23
|
+
? null
|
|
24
|
+
: (await getAccessResults({ req })).globals?.[globalSlug]
|
|
25
|
+
|
|
26
|
+
if (!authorizedMCP.overrideAccess && !permissions?.update) {
|
|
27
|
+
return {
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: 'text',
|
|
31
|
+
text: `Error: MCP access to "getGlobalSchema" is not enabled for global "${globalSlug}"`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
isError: true,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const inputSchema = getGlobalInputSchema({
|
|
39
|
+
globalSlug,
|
|
40
|
+
req,
|
|
41
|
+
...(permissions ? { permissions } : {}),
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
if (!inputSchema) {
|
|
45
|
+
return {
|
|
46
|
+
content: [{ type: 'text', text: `Error: Global "${globalSlug}" not found` }],
|
|
47
|
+
isError: true,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: 'text',
|
|
55
|
+
text: `Schema for global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
structuredContent: {
|
|
59
|
+
globalSlug,
|
|
60
|
+
schema: inputSchema,
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
})
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { PopulateType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
+
|
|
9
|
+
const DEFAULT_DESCRIPTION =
|
|
10
|
+
'Restore a global from a previous version in any version-enabled global.'
|
|
11
|
+
|
|
12
|
+
export const restoreGlobalVersionTool = defineGlobalTool({
|
|
13
|
+
access: (args) =>
|
|
14
|
+
defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),
|
|
15
|
+
annotations: {
|
|
16
|
+
destructiveHint: true,
|
|
17
|
+
idempotentHint: false,
|
|
18
|
+
openWorldHint: false,
|
|
19
|
+
readOnlyHint: false,
|
|
20
|
+
title: 'Restore Global Version',
|
|
21
|
+
},
|
|
22
|
+
description: DEFAULT_DESCRIPTION,
|
|
23
|
+
input: z.object({
|
|
24
|
+
id: z.string().describe('The ID of the global version to restore'),
|
|
25
|
+
depth: z
|
|
26
|
+
.number()
|
|
27
|
+
.int()
|
|
28
|
+
.min(0)
|
|
29
|
+
.max(10)
|
|
30
|
+
.describe('How many levels deep to populate relationships in response')
|
|
31
|
+
.optional()
|
|
32
|
+
.default(0),
|
|
33
|
+
fallbackLocale: z
|
|
34
|
+
.string()
|
|
35
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
36
|
+
.optional(),
|
|
37
|
+
locale: z
|
|
38
|
+
.string()
|
|
39
|
+
.describe('Optional: locale code to restore in (e.g., "en", "es")')
|
|
40
|
+
.optional(),
|
|
41
|
+
populate: z
|
|
42
|
+
.record(z.string(), z.unknown())
|
|
43
|
+
.describe(
|
|
44
|
+
'Optional: control which fields to include from populated relationship or upload documents.',
|
|
45
|
+
)
|
|
46
|
+
.optional(),
|
|
47
|
+
showHiddenFields: z
|
|
48
|
+
.boolean()
|
|
49
|
+
.describe('Optional: include hidden fields in the restored global response')
|
|
50
|
+
.optional(),
|
|
51
|
+
}),
|
|
52
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
53
|
+
const payload = req.payload
|
|
54
|
+
const logger = getLogger({ payload })
|
|
55
|
+
const { id, depth, fallbackLocale, locale, populate, showHiddenFields } = input
|
|
56
|
+
|
|
57
|
+
logger.info(`Restoring version for global: ${globalSlug} with ID: ${id}`)
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const result = await payload.restoreGlobalVersion({
|
|
61
|
+
id,
|
|
62
|
+
slug: globalSlug,
|
|
63
|
+
depth,
|
|
64
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
65
|
+
req,
|
|
66
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
67
|
+
...(locale ? { locale } : {}),
|
|
68
|
+
...(populate ? { populate: populate as PopulateType } : {}),
|
|
69
|
+
...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
|
|
70
|
+
})
|
|
71
|
+
const resultObject = result as Record<string, unknown>
|
|
72
|
+
const restoredGlobal =
|
|
73
|
+
resultObject.version && typeof resultObject.version === 'object'
|
|
74
|
+
? (resultObject.version as Record<string, unknown>)
|
|
75
|
+
: resultObject
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
content: [
|
|
79
|
+
{
|
|
80
|
+
type: 'text',
|
|
81
|
+
text: `Version "${id}" restored successfully for global "${globalSlug}"!\nRestored global:\n\`\`\`json\n${JSON.stringify(restoredGlobal)}\n\`\`\``,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
doc: restoredGlobal,
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
88
|
+
logger.error(`Error restoring version ${id} for global ${globalSlug}: ${errorMessage}`)
|
|
89
|
+
return {
|
|
90
|
+
content: [
|
|
91
|
+
{
|
|
92
|
+
type: 'text',
|
|
93
|
+
text: `❌ **Error restoring version "${id}" for global "${globalSlug}":** ${errorMessage}`,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
isError: true,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
})
|
|
@@ -2,59 +2,58 @@ import type { SelectType } from 'payload'
|
|
|
2
2
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
5
6
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
6
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
8
|
import {
|
|
8
9
|
getGlobalVirtualFieldNames,
|
|
9
10
|
stripVirtualFields,
|
|
10
11
|
} from '../../../utils/getVirtualFieldNames.js'
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
12
|
+
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
13
|
+
import { validateGlobalData } from '../validateEntityData.js'
|
|
13
14
|
|
|
14
|
-
const DEFAULT_DESCRIPTION = 'Update
|
|
15
|
+
const DEFAULT_DESCRIPTION = 'Update any Payload global by passing the global slug and data.'
|
|
15
16
|
|
|
16
17
|
export const updateGlobalTool = defineGlobalTool({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
})
|
|
18
|
+
access: (args) =>
|
|
19
|
+
defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),
|
|
20
|
+
annotations: {
|
|
21
|
+
destructiveHint: true,
|
|
22
|
+
idempotentHint: false,
|
|
23
|
+
openWorldHint: false,
|
|
24
|
+
readOnlyHint: false,
|
|
25
|
+
title: 'Update Global',
|
|
57
26
|
},
|
|
27
|
+
description: DEFAULT_DESCRIPTION,
|
|
28
|
+
input: z.object({
|
|
29
|
+
data: z.record(z.string(), z.unknown()).describe('The global 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
|
+
.record(z.string(), z.unknown())
|
|
52
|
+
.describe(
|
|
53
|
+
'Optional: define exactly which fields you\'d like to return in the response, e.g., {"siteName": true}',
|
|
54
|
+
)
|
|
55
|
+
.optional(),
|
|
56
|
+
}),
|
|
58
57
|
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
59
58
|
const payload = req.payload
|
|
60
59
|
const logger = getLogger({ payload })
|
|
@@ -67,24 +66,22 @@ export const updateGlobalTool = defineGlobalTool({
|
|
|
67
66
|
|
|
68
67
|
try {
|
|
69
68
|
const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)
|
|
70
|
-
const
|
|
69
|
+
const inputData = stripVirtualFields(data, virtualFieldNames)
|
|
70
|
+
const validationError = validateGlobalData({ data: inputData, globalSlug, req })
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
}
|
|
72
|
+
if (validationError) {
|
|
73
|
+
return validationError
|
|
80
74
|
}
|
|
81
75
|
|
|
76
|
+
const parsedData = transformPointDataToPayload(inputData)
|
|
77
|
+
|
|
82
78
|
const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {
|
|
83
79
|
slug: globalSlug,
|
|
84
80
|
data: parsedData,
|
|
85
81
|
depth,
|
|
86
82
|
draft,
|
|
87
|
-
|
|
83
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
84
|
+
req,
|
|
88
85
|
}
|
|
89
86
|
|
|
90
87
|
if (locale) {
|
|
@@ -93,8 +90,8 @@ export const updateGlobalTool = defineGlobalTool({
|
|
|
93
90
|
if (fallbackLocale) {
|
|
94
91
|
updateOptions.fallbackLocale = fallbackLocale
|
|
95
92
|
}
|
|
96
|
-
if (
|
|
97
|
-
updateOptions.select =
|
|
93
|
+
if (select) {
|
|
94
|
+
updateOptions.select = select as SelectType
|
|
98
95
|
}
|
|
99
96
|
|
|
100
97
|
const result = await payload.updateGlobal(updateOptions)
|