@payloadcms/plugin-mcp 4.0.0-internal.40de3ec → 4.0.0-internal.4cbdd50
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/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/endpoint/access.d.ts +17 -5
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +82 -88
- package/dist/endpoint/access.js.map +1 -1
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +11 -0
- 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.map +1 -1
- package/dist/index.js +13 -18
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +102 -71
- 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 +69 -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 +65 -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 +38 -42
- 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 +14 -20
- 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 +97 -0
- package/dist/mcp/builtin/collections/duplicateTool.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 +93 -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 +49 -43
- 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 +84 -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 +99 -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 +47 -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 +82 -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 +87 -86
- 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 +71 -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 +65 -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 +18 -21
- 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 +80 -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 +95 -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 +47 -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 +78 -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 +31 -40
- 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 +120 -58
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts +3 -2
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +27 -8
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +62 -108
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -4
- package/dist/types.js.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/schemaConversion/getEntityInputSchema.d.ts +11 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js +34 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
- 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 +8 -11
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +88 -101
- package/src/endpoint/index.ts +14 -1
- package/src/exports/client.ts +2 -1
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +8 -16
- package/src/mcp/buildMcpServer.ts +131 -96
- package/src/mcp/builtin/collections/authTools.ts +45 -9
- package/src/mcp/builtin/collections/countTool.ts +74 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +70 -0
- package/src/mcp/builtin/collections/createTool.ts +55 -59
- package/src/mcp/builtin/collections/deleteTool.ts +19 -16
- package/src/mcp/builtin/collections/duplicateTool.ts +135 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +120 -0
- package/src/mcp/builtin/collections/findTool.ts +63 -33
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +110 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +155 -0
- package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +46 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +108 -0
- package/src/mcp/builtin/collections/updateTool.ts +111 -110
- package/src/mcp/builtin/getConfigInfoTool.ts +69 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +69 -0
- package/src/mcp/builtin/globals/findTool.ts +26 -17
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +104 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +148 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +41 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +100 -0
- package/src/mcp/builtin/globals/updateTool.ts +50 -55
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +111 -41
- package/src/mcp/sanitizeMCPConfig.ts +116 -78
- package/src/stdio.ts +23 -8
- package/src/types.ts +77 -112
- package/src/utils/getPluginConfig.ts +1 -1
- package/src/utils/schemaConversion/getEntityInputSchema.ts +78 -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 -60
- 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/schemaConversion/buildToolInput.d.ts +0 -29
- package/dist/utils/schemaConversion/buildToolInput.d.ts.map +0 -1
- package/dist/utils/schemaConversion/buildToolInput.js +0 -51
- package/dist/utils/schemaConversion/buildToolInput.js.map +0 -1
- package/src/collection/getAccessField.ts +0 -64
- package/src/collection/index.ts +0 -64
- package/src/components/AccessField/index.client.tsx +0 -344
- package/src/components/AccessField/index.css +0 -93
- package/src/utils/schemaConversion/buildToolInput.ts +0 -68
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { PopulateType, SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
|
+
|
|
10
|
+
const DEFAULT_DESCRIPTION =
|
|
11
|
+
'Restore a document from a previous version in any version-enabled collection.'
|
|
12
|
+
|
|
13
|
+
export const restoreVersionTool = defineCollectionTool({
|
|
14
|
+
access: (args) =>
|
|
15
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),
|
|
16
|
+
annotations: {
|
|
17
|
+
destructiveHint: true,
|
|
18
|
+
idempotentHint: false,
|
|
19
|
+
openWorldHint: false,
|
|
20
|
+
readOnlyHint: false,
|
|
21
|
+
title: 'Restore Version',
|
|
22
|
+
},
|
|
23
|
+
description: DEFAULT_DESCRIPTION,
|
|
24
|
+
input: z.object({
|
|
25
|
+
id: z.string().describe('The ID of the version to restore'),
|
|
26
|
+
depth: z
|
|
27
|
+
.number()
|
|
28
|
+
.int()
|
|
29
|
+
.min(0)
|
|
30
|
+
.max(10)
|
|
31
|
+
.describe('How many levels deep to populate relationships in response')
|
|
32
|
+
.optional()
|
|
33
|
+
.default(0),
|
|
34
|
+
draft: z
|
|
35
|
+
.boolean()
|
|
36
|
+
.describe('Whether to restore the version as a draft')
|
|
37
|
+
.optional()
|
|
38
|
+
.default(false),
|
|
39
|
+
fallbackLocale: z
|
|
40
|
+
.string()
|
|
41
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
42
|
+
.optional(),
|
|
43
|
+
locale: z
|
|
44
|
+
.string()
|
|
45
|
+
.describe('Optional: locale code to restore in (e.g., "en", "es")')
|
|
46
|
+
.optional(),
|
|
47
|
+
populate: z
|
|
48
|
+
.record(z.string(), z.unknown())
|
|
49
|
+
.describe(
|
|
50
|
+
'Optional: control which fields to include from populated relationship or upload documents.',
|
|
51
|
+
)
|
|
52
|
+
.optional(),
|
|
53
|
+
select: z
|
|
54
|
+
.record(z.string(), z.unknown())
|
|
55
|
+
.describe(
|
|
56
|
+
'Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}',
|
|
57
|
+
)
|
|
58
|
+
.optional(),
|
|
59
|
+
showHiddenFields: z
|
|
60
|
+
.boolean()
|
|
61
|
+
.describe('Optional: include hidden fields in the restored document response')
|
|
62
|
+
.optional(),
|
|
63
|
+
}),
|
|
64
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
65
|
+
const payload = req.payload
|
|
66
|
+
const logger = getLogger({ payload })
|
|
67
|
+
const { id, depth, draft, fallbackLocale, locale, populate, select, showHiddenFields } = input
|
|
68
|
+
|
|
69
|
+
logger.info(`Restoring version in collection: ${collectionSlug} with ID: ${id}`)
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const result = await payload.restoreVersion({
|
|
73
|
+
id,
|
|
74
|
+
collection: collectionSlug,
|
|
75
|
+
depth,
|
|
76
|
+
draft,
|
|
77
|
+
req,
|
|
78
|
+
...localAPIDefaults(authorizedMCP),
|
|
79
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
80
|
+
...(locale ? { locale } : {}),
|
|
81
|
+
...(populate ? { populate: populate as PopulateType } : {}),
|
|
82
|
+
...(select ? { select: select as SelectType } : {}),
|
|
83
|
+
...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
content: [
|
|
88
|
+
{
|
|
89
|
+
type: 'text',
|
|
90
|
+
text: `Version "${id}" restored successfully in collection "${collectionSlug}"!\nRestored document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
doc: result as Record<string, unknown>,
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
97
|
+
logger.error(`Error restoring version ${id} in ${collectionSlug}: ${errorMessage}`)
|
|
98
|
+
return {
|
|
99
|
+
content: [
|
|
100
|
+
{
|
|
101
|
+
type: 'text',
|
|
102
|
+
text: `❌ **Error restoring version "${id}" in collection "${collectionSlug}":** ${errorMessage}`,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
isError: true,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { SelectType } from 'payload'
|
|
1
|
+
import type { SelectType, Where } from 'payload'
|
|
2
2
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
5
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
8
|
import {
|
|
@@ -9,75 +10,72 @@ import {
|
|
|
9
10
|
stripVirtualFields,
|
|
10
11
|
} from '../../../utils/getVirtualFieldNames.js'
|
|
11
12
|
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
12
|
-
import {
|
|
13
|
-
import { sanitizeEntitySchema } from '../../../utils/schemaConversion/sanitizeEntitySchema.js'
|
|
13
|
+
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
14
14
|
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
id: z
|
|
32
|
-
.union([z.string(), z.number()])
|
|
33
|
-
.describe('The ID of the document to update')
|
|
34
|
-
.optional(),
|
|
35
|
-
depth: z
|
|
36
|
-
.number()
|
|
37
|
-
.describe('How many levels deep to populate relationships')
|
|
38
|
-
.optional()
|
|
39
|
-
.default(0),
|
|
40
|
-
draft: z
|
|
41
|
-
.boolean()
|
|
42
|
-
.describe('Whether to update the document as a draft')
|
|
43
|
-
.optional()
|
|
44
|
-
.default(false),
|
|
45
|
-
fallbackLocale: z
|
|
46
|
-
.string()
|
|
47
|
-
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
48
|
-
.optional(),
|
|
49
|
-
filePath: z.string().describe('File path for file uploads').optional(),
|
|
50
|
-
locale: z
|
|
51
|
-
.string()
|
|
52
|
-
.describe(
|
|
53
|
-
'Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale',
|
|
54
|
-
)
|
|
55
|
-
.optional(),
|
|
56
|
-
overrideLock: z
|
|
57
|
-
.boolean()
|
|
58
|
-
.describe('Whether to override document locks')
|
|
59
|
-
.optional()
|
|
60
|
-
.default(true),
|
|
61
|
-
overwriteExistingFiles: z
|
|
62
|
-
.boolean()
|
|
63
|
-
.describe('Whether to overwrite existing files')
|
|
64
|
-
.optional()
|
|
65
|
-
.default(false),
|
|
66
|
-
select: z
|
|
67
|
-
.string()
|
|
68
|
-
.describe(
|
|
69
|
-
'Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"title": "My Post"}\'',
|
|
70
|
-
)
|
|
71
|
-
.optional(),
|
|
72
|
-
where: z
|
|
73
|
-
.string()
|
|
74
|
-
.describe('JSON string for where clause to update multiple documents')
|
|
75
|
-
.optional(),
|
|
76
|
-
},
|
|
77
|
-
dataDescription: 'The fields to update',
|
|
78
|
-
dataSchema: partialSchema,
|
|
79
|
-
})
|
|
15
|
+
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
16
|
+
import { validateCollectionData } from '../validateEntityData.js'
|
|
17
|
+
import { formatCollectionError } from './formatCollectionError.js'
|
|
18
|
+
|
|
19
|
+
const DEFAULT_DESCRIPTION =
|
|
20
|
+
'Update documents in any collection by passing the collection slug and data.'
|
|
21
|
+
|
|
22
|
+
export const updateDocumentTool = defineCollectionTool({
|
|
23
|
+
access: (args) =>
|
|
24
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),
|
|
25
|
+
annotations: {
|
|
26
|
+
destructiveHint: true,
|
|
27
|
+
idempotentHint: false,
|
|
28
|
+
openWorldHint: false,
|
|
29
|
+
readOnlyHint: false,
|
|
30
|
+
title: 'Update Document',
|
|
80
31
|
},
|
|
32
|
+
description: DEFAULT_DESCRIPTION,
|
|
33
|
+
input: z.object({
|
|
34
|
+
id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),
|
|
35
|
+
data: z.record(z.string(), z.unknown()).describe('The fields to update'),
|
|
36
|
+
depth: z
|
|
37
|
+
.number()
|
|
38
|
+
.describe('How many levels deep to populate relationships')
|
|
39
|
+
.optional()
|
|
40
|
+
.default(0),
|
|
41
|
+
draft: z
|
|
42
|
+
.boolean()
|
|
43
|
+
.describe('Whether to update the document as a draft')
|
|
44
|
+
.optional()
|
|
45
|
+
.default(false),
|
|
46
|
+
fallbackLocale: z
|
|
47
|
+
.string()
|
|
48
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
49
|
+
.optional(),
|
|
50
|
+
filePath: z.string().describe('File path for file uploads').optional(),
|
|
51
|
+
locale: z
|
|
52
|
+
.string()
|
|
53
|
+
.describe(
|
|
54
|
+
'Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale',
|
|
55
|
+
)
|
|
56
|
+
.optional(),
|
|
57
|
+
overrideLock: z
|
|
58
|
+
.boolean()
|
|
59
|
+
.describe('Whether to override document locks')
|
|
60
|
+
.optional()
|
|
61
|
+
.default(true),
|
|
62
|
+
overwriteExistingFiles: z
|
|
63
|
+
.boolean()
|
|
64
|
+
.describe('Whether to overwrite existing files')
|
|
65
|
+
.optional()
|
|
66
|
+
.default(false),
|
|
67
|
+
select: z
|
|
68
|
+
.record(z.string(), z.unknown())
|
|
69
|
+
.describe(
|
|
70
|
+
'Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}',
|
|
71
|
+
)
|
|
72
|
+
.optional(),
|
|
73
|
+
where: whereSchema
|
|
74
|
+
.describe(
|
|
75
|
+
'Where clause to update multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}',
|
|
76
|
+
)
|
|
77
|
+
.optional(),
|
|
78
|
+
}),
|
|
81
79
|
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
82
80
|
const payload = req.payload
|
|
83
81
|
const logger = getLogger({ payload })
|
|
@@ -107,32 +105,25 @@ export const updateCollectionTool = defineCollectionTool({
|
|
|
107
105
|
}
|
|
108
106
|
}
|
|
109
107
|
|
|
110
|
-
let parsedData = transformPointDataToPayload(data)
|
|
111
108
|
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
logger.error(`Invalid where clause JSON: ${where}`)
|
|
120
|
-
return { content: [{ type: 'text', text: 'Error: Invalid JSON in where clause' }] }
|
|
121
|
-
}
|
|
122
|
-
}
|
|
109
|
+
const inputData = stripVirtualFields(data, virtualFieldNames)
|
|
110
|
+
const validationError = validateCollectionData({
|
|
111
|
+
collectionSlug,
|
|
112
|
+
data: inputData,
|
|
113
|
+
partial: true,
|
|
114
|
+
req,
|
|
115
|
+
})
|
|
123
116
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
selectClause = JSON.parse(select) as SelectType
|
|
128
|
-
} catch {
|
|
129
|
-
logger.warn(`Invalid select clause JSON: ${select}`)
|
|
130
|
-
return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }
|
|
131
|
-
}
|
|
117
|
+
if (validationError) {
|
|
118
|
+
return validationError
|
|
132
119
|
}
|
|
133
120
|
|
|
121
|
+
const parsedData = transformPointDataToPayload(inputData)
|
|
122
|
+
|
|
123
|
+
const whereClause: Where = where ?? {}
|
|
124
|
+
|
|
134
125
|
if (id) {
|
|
135
|
-
const
|
|
126
|
+
const result = await payload.update({
|
|
136
127
|
id,
|
|
137
128
|
collection: collectionSlug,
|
|
138
129
|
data: parsedData,
|
|
@@ -145,10 +136,8 @@ export const updateCollectionTool = defineCollectionTool({
|
|
|
145
136
|
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
146
137
|
...(locale ? { locale } : {}),
|
|
147
138
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
148
|
-
...(
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const result = await payload.update(updateOptions as any)
|
|
139
|
+
...(select ? { select: select as SelectType } : {}),
|
|
140
|
+
})
|
|
152
141
|
|
|
153
142
|
return {
|
|
154
143
|
content: [
|
|
@@ -161,27 +150,24 @@ export const updateCollectionTool = defineCollectionTool({
|
|
|
161
150
|
}
|
|
162
151
|
}
|
|
163
152
|
|
|
164
|
-
const
|
|
153
|
+
const result = await payload.update({
|
|
165
154
|
collection: collectionSlug,
|
|
166
155
|
data: parsedData,
|
|
167
156
|
depth,
|
|
168
157
|
draft,
|
|
169
158
|
overrideLock,
|
|
170
159
|
req,
|
|
171
|
-
...localAPIDefaults(authorizedMCP),
|
|
172
160
|
where: whereClause,
|
|
161
|
+
...localAPIDefaults(authorizedMCP),
|
|
173
162
|
...(filePath ? { filePath } : {}),
|
|
174
163
|
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
175
164
|
...(locale ? { locale } : {}),
|
|
176
165
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
177
|
-
...(
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const result = await payload.update(updateOptions as any)
|
|
166
|
+
...(select ? { select: select as SelectType } : {}),
|
|
167
|
+
})
|
|
181
168
|
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
const errors = bulkResult.errors || []
|
|
169
|
+
const docs = result.docs || []
|
|
170
|
+
const errors = result.errors || []
|
|
185
171
|
|
|
186
172
|
let responseText = `Multiple documents updated in collection "${collectionSlug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`
|
|
187
173
|
if (docs.length > 0) {
|
|
@@ -189,6 +175,28 @@ export const updateCollectionTool = defineCollectionTool({
|
|
|
189
175
|
}
|
|
190
176
|
if (errors.length > 0) {
|
|
191
177
|
responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``
|
|
178
|
+
|
|
179
|
+
const errorSchema = getCollectionInputSchema({ collectionSlug, req })
|
|
180
|
+
|
|
181
|
+
if (errorSchema) {
|
|
182
|
+
responseText += `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(errorSchema)}\n\`\`\``
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
content: [{ type: 'text', text: responseText }],
|
|
187
|
+
doc: { docs, errors } as unknown as Record<string, unknown>,
|
|
188
|
+
isError: true,
|
|
189
|
+
...(errorSchema
|
|
190
|
+
? {
|
|
191
|
+
structuredContent: {
|
|
192
|
+
collectionSlug,
|
|
193
|
+
docs,
|
|
194
|
+
errors,
|
|
195
|
+
schema: errorSchema,
|
|
196
|
+
},
|
|
197
|
+
}
|
|
198
|
+
: {}),
|
|
199
|
+
}
|
|
192
200
|
}
|
|
193
201
|
|
|
194
202
|
return {
|
|
@@ -198,13 +206,6 @@ export const updateCollectionTool = defineCollectionTool({
|
|
|
198
206
|
} catch (error) {
|
|
199
207
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
200
208
|
logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`)
|
|
201
|
-
return {
|
|
202
|
-
content: [
|
|
203
|
-
{
|
|
204
|
-
type: 'text',
|
|
205
|
-
text: `Error updating document in collection "${collectionSlug}": ${errorMessage}`,
|
|
206
|
-
},
|
|
207
|
-
],
|
|
208
|
-
}
|
|
209
|
+
return formatCollectionError({ action: 'updating', collectionSlug, error, req })
|
|
209
210
|
}
|
|
210
211
|
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { getAccessResults, isEntityHidden } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { defineTool } from '../../defineTool.js'
|
|
4
|
+
|
|
5
|
+
export const getConfigInfoTool = defineTool({
|
|
6
|
+
annotations: {
|
|
7
|
+
destructiveHint: false,
|
|
8
|
+
idempotentHint: true,
|
|
9
|
+
openWorldHint: false,
|
|
10
|
+
readOnlyHint: true,
|
|
11
|
+
title: 'Config Info',
|
|
12
|
+
},
|
|
13
|
+
description: 'List the Payload collection and global slugs visible to this MCP client.',
|
|
14
|
+
}).handler(async ({ authorizedMCP, req }) => {
|
|
15
|
+
const user = authorizedMCP.user
|
|
16
|
+
const permissions = authorizedMCP.overrideAccess
|
|
17
|
+
? null
|
|
18
|
+
: await getAccessResults({ req: { ...req, user } })
|
|
19
|
+
const authorizedCollectionSlugs = new Set<string>()
|
|
20
|
+
const authorizedGlobalSlugs = new Set<string>()
|
|
21
|
+
|
|
22
|
+
for (const item of authorizedMCP.items) {
|
|
23
|
+
if (item.type === 'collectionTool') {
|
|
24
|
+
authorizedCollectionSlugs.add(item.collectionSlug)
|
|
25
|
+
} else if (item.type === 'globalTool') {
|
|
26
|
+
authorizedGlobalSlugs.add(item.globalSlug)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const collections: string[] = []
|
|
31
|
+
const globals: string[] = []
|
|
32
|
+
|
|
33
|
+
for (const collection of req.payload.config.collections) {
|
|
34
|
+
if (!authorizedCollectionSlugs.has(collection.slug)) {
|
|
35
|
+
continue
|
|
36
|
+
}
|
|
37
|
+
if (user && isEntityHidden({ hidden: collection.admin.hidden, user })) {
|
|
38
|
+
continue
|
|
39
|
+
}
|
|
40
|
+
if (!authorizedMCP.overrideAccess && !permissions?.collections?.[collection.slug]?.read) {
|
|
41
|
+
continue
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
collections.push(collection.slug)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (const global of req.payload.config.globals) {
|
|
48
|
+
if (!authorizedGlobalSlugs.has(global.slug)) {
|
|
49
|
+
continue
|
|
50
|
+
}
|
|
51
|
+
if (user && isEntityHidden({ hidden: global.admin.hidden, user })) {
|
|
52
|
+
continue
|
|
53
|
+
}
|
|
54
|
+
if (!authorizedMCP.overrideAccess && !permissions?.globals?.[global.slug]?.read) {
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
globals.push(global.slug)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
type: 'text',
|
|
65
|
+
text: `Collections: ${collections.join(', ') || 'none'}\nGlobals: ${globals.join(', ') || 'none'}`,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
}
|
|
69
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
5
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
7
|
+
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
8
|
+
|
|
9
|
+
const DEFAULT_DESCRIPTION =
|
|
10
|
+
'Count global versions in any version-enabled global by passing the global slug and optional where clause.'
|
|
11
|
+
|
|
12
|
+
export const countGlobalVersionsTool = 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: 'Count Global Versions',
|
|
21
|
+
},
|
|
22
|
+
description: DEFAULT_DESCRIPTION,
|
|
23
|
+
input: z.object({
|
|
24
|
+
locale: z.string().describe('Optional: locale code to count versions in').optional(),
|
|
25
|
+
where: whereSchema
|
|
26
|
+
.describe(
|
|
27
|
+
'Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.siteName":{"contains":"test"}}',
|
|
28
|
+
)
|
|
29
|
+
.optional(),
|
|
30
|
+
}),
|
|
31
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
32
|
+
const payload = req.payload
|
|
33
|
+
const logger = getLogger({ payload })
|
|
34
|
+
const { locale, where } = input
|
|
35
|
+
|
|
36
|
+
logger.info(`Counting versions for global: ${globalSlug}`)
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const result = await payload.countGlobalVersions({
|
|
40
|
+
global: globalSlug,
|
|
41
|
+
req,
|
|
42
|
+
...localAPIDefaults(authorizedMCP),
|
|
43
|
+
...(locale ? { locale } : {}),
|
|
44
|
+
...(where ? { where } : {}),
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
content: [
|
|
49
|
+
{
|
|
50
|
+
type: 'text',
|
|
51
|
+
text: `Global "${globalSlug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
doc: result,
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
58
|
+
logger.error(`Error counting versions for global ${globalSlug}: ${errorMessage}`)
|
|
59
|
+
return {
|
|
60
|
+
content: [
|
|
61
|
+
{
|
|
62
|
+
type: 'text',
|
|
63
|
+
text: `❌ **Error counting versions for global "${globalSlug}":** ${errorMessage}`,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
isError: true,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
})
|
|
@@ -1,14 +1,24 @@
|
|
|
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
8
|
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
8
9
|
|
|
9
|
-
const DEFAULT_DESCRIPTION = 'Find
|
|
10
|
+
const DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.'
|
|
10
11
|
|
|
11
12
|
export const findGlobalTool = defineGlobalTool({
|
|
13
|
+
access: (args) =>
|
|
14
|
+
defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.read),
|
|
15
|
+
annotations: {
|
|
16
|
+
destructiveHint: false,
|
|
17
|
+
idempotentHint: true,
|
|
18
|
+
openWorldHint: false,
|
|
19
|
+
readOnlyHint: true,
|
|
20
|
+
title: 'Find Global',
|
|
21
|
+
},
|
|
12
22
|
description: DEFAULT_DESCRIPTION,
|
|
13
23
|
input: z.object({
|
|
14
24
|
depth: z
|
|
@@ -29,10 +39,16 @@ export const findGlobalTool = defineGlobalTool({
|
|
|
29
39
|
'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
|
|
30
40
|
)
|
|
31
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(),
|
|
32
48
|
select: z
|
|
33
|
-
.string()
|
|
49
|
+
.record(z.string(), z.unknown())
|
|
34
50
|
.describe(
|
|
35
|
-
|
|
51
|
+
'Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}',
|
|
36
52
|
)
|
|
37
53
|
.optional(),
|
|
38
54
|
}),
|
|
@@ -40,7 +56,7 @@ export const findGlobalTool = defineGlobalTool({
|
|
|
40
56
|
const payload = req.payload
|
|
41
57
|
const logger = getLogger({ payload })
|
|
42
58
|
|
|
43
|
-
const { depth, fallbackLocale, locale, select } = input
|
|
59
|
+
const { depth, fallbackLocale, locale, populate, select } = input
|
|
44
60
|
|
|
45
61
|
logger.info(
|
|
46
62
|
`Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,
|
|
@@ -53,24 +69,17 @@ export const findGlobalTool = defineGlobalTool({
|
|
|
53
69
|
...localAPIDefaults(authorizedMCP),
|
|
54
70
|
}
|
|
55
71
|
|
|
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
72
|
if (locale) {
|
|
67
73
|
findOptions.locale = locale
|
|
68
74
|
}
|
|
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)
|