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