@payloadcms/plugin-mcp 4.0.0-internal.bc5cf8c → 4.0.0-internal.c7d5de4
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.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 +4 -11
- 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 +57 -17
- package/dist/endpoint/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- 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 +32 -10
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countTool.js +1 -2
- 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 +1 -2
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +14 -5
- 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 +1 -2
- 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 +1 -2
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
- 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.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.js +1 -2
- 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 +3 -4
- 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 +1 -2
- 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 +1 -2
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +44 -5
- 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 +1 -2
- 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 +23 -11
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.js +2 -5
- 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 +1 -2
- 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 +2 -2
- 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 +1 -2
- 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 +1 -2
- 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 +21 -3
- 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 +1 -2
- 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 +2 -2
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
- package/dist/mcp/builtin/validateEntityData.js +1 -1
- package/dist/mcp/builtin/validateEntityData.js.map +1 -1
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +1 -0
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts +3 -4
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +59 -41
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +57 -9
- 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/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 +5 -3
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +44 -12
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +5 -10
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +15 -95
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +15 -40
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
- package/dist/utils/toStandardSchema.d.ts.map +1 -1
- package/package.json +9 -11
- package/src/endpoint/access.ts +3 -10
- package/src/endpoint/index.ts +45 -16
- package/src/index.ts +4 -4
- package/src/mcp/buildMcpServer.ts +40 -20
- package/src/mcp/builtin/collections/countTool.ts +1 -2
- package/src/mcp/builtin/collections/countVersionsTool.ts +1 -2
- package/src/mcp/builtin/collections/createTool.ts +14 -5
- package/src/mcp/builtin/collections/deleteTool.ts +1 -2
- package/src/mcp/builtin/collections/duplicateTool.ts +1 -2
- 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 +1 -2
- package/src/mcp/builtin/collections/findTool.ts +3 -4
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +1 -2
- package/src/mcp/builtin/collections/findVersionsTool.ts +1 -2
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +39 -9
- package/src/mcp/builtin/collections/restoreVersionTool.ts +1 -2
- package/src/mcp/builtin/collections/updateTool.ts +25 -9
- package/src/mcp/builtin/getConfigInfoTool.ts +2 -4
- package/src/mcp/builtin/globals/countVersionsTool.ts +1 -2
- package/src/mcp/builtin/globals/findTool.ts +2 -2
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +1 -2
- package/src/mcp/builtin/globals/findVersionsTool.ts +1 -2
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +25 -3
- package/src/mcp/builtin/globals/restoreVersionTool.ts +1 -2
- package/src/mcp/builtin/globals/updateTool.ts +2 -2
- package/src/mcp/builtin/validateEntityData.ts +1 -1
- package/src/mcp/sanitizeMCPConfig.ts +1 -0
- package/src/stdio.ts +59 -42
- package/src/types.ts +57 -9
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +45 -27
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +12 -19
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +17 -114
- package/dist/@types/assets.d.js +0 -2
- package/dist/@types/assets.d.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/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/src/@types/assets.d.ts +0 -3
- package/src/utils/localAPIDefaults.ts +0 -22
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { CollectionSlug, File, FileData, PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { APIError } from 'payload'
|
|
4
|
+
import { getExternalFile, isURLAllowed } from 'payload/internal'
|
|
5
|
+
import { sanitizeFilename } from 'payload/shared'
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
|
|
8
|
+
const mimeTypeSchema = z
|
|
9
|
+
.string()
|
|
10
|
+
.regex(/^[!#$%&'*+.^`|~\w-]+\/[!#$%&'*+.^`|~\w-]+$/, 'MIME type must use the type/subtype format')
|
|
11
|
+
|
|
12
|
+
export const fileInputSchema = z
|
|
13
|
+
.discriminatedUnion('source', [
|
|
14
|
+
z.object({
|
|
15
|
+
name: z.string().min(1).describe('The file name, including its extension'),
|
|
16
|
+
data: z.string().describe('The base64-encoded file bytes, without a data URL prefix'),
|
|
17
|
+
mimeType: mimeTypeSchema.describe('The file MIME type, for example image/png'),
|
|
18
|
+
source: z.literal('base64'),
|
|
19
|
+
}),
|
|
20
|
+
z.object({
|
|
21
|
+
name: z.string().min(1).describe('Optional file name override').optional(),
|
|
22
|
+
source: z.literal('url'),
|
|
23
|
+
url: z.url().describe('The http or https URL to download'),
|
|
24
|
+
}),
|
|
25
|
+
])
|
|
26
|
+
.describe(
|
|
27
|
+
'A file for an upload collection. Use only a source listed by getCollectionSchema: url for an online file or base64 for a local file.',
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
type FileInput = z.infer<typeof fileInputSchema>
|
|
31
|
+
|
|
32
|
+
export async function resolveFileInput({
|
|
33
|
+
collectionSlug,
|
|
34
|
+
input,
|
|
35
|
+
req,
|
|
36
|
+
}: {
|
|
37
|
+
collectionSlug: CollectionSlug
|
|
38
|
+
input?: FileInput
|
|
39
|
+
req: PayloadRequest
|
|
40
|
+
}): Promise<File | undefined> {
|
|
41
|
+
if (!input) {
|
|
42
|
+
return undefined
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const uploadConfig = req.payload.collections[collectionSlug]?.config.upload
|
|
46
|
+
|
|
47
|
+
if (!uploadConfig) {
|
|
48
|
+
throw new APIError(`Collection "${collectionSlug}" does not support file uploads.`, 400)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const maxFileSize = req.payload.config.upload.limits?.fileSize
|
|
52
|
+
let file: File
|
|
53
|
+
|
|
54
|
+
if (input.source === 'base64') {
|
|
55
|
+
const data = decodeBase64({ maxFileSize, value: input.data })
|
|
56
|
+
|
|
57
|
+
file = {
|
|
58
|
+
name: sanitizeFilename(input.name),
|
|
59
|
+
data,
|
|
60
|
+
mimetype: input.mimeType,
|
|
61
|
+
size: data.length,
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
if (uploadConfig.pasteURL === false) {
|
|
65
|
+
throw new APIError(
|
|
66
|
+
`Uploading files from URLs is disabled for collection "${collectionSlug}".`,
|
|
67
|
+
400,
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const url = new URL(input.url)
|
|
72
|
+
|
|
73
|
+
if (!['http:', 'https:'].includes(url.protocol)) {
|
|
74
|
+
throw new APIError('File URLs must use http or https.', 400)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (
|
|
78
|
+
typeof uploadConfig.pasteURL === 'object' &&
|
|
79
|
+
!isURLAllowed(input.url, uploadConfig.pasteURL.allowList)
|
|
80
|
+
) {
|
|
81
|
+
throw new APIError('The provided file URL is not allowed.', 400)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
file = await getExternalFile({
|
|
85
|
+
data: {
|
|
86
|
+
filename: sanitizeFilename(input.name || getURLFilename(url)),
|
|
87
|
+
url: input.url,
|
|
88
|
+
} as FileData,
|
|
89
|
+
req,
|
|
90
|
+
uploadConfig: {
|
|
91
|
+
...uploadConfig,
|
|
92
|
+
externalFileHeaderFilter: uploadConfig.externalFileHeaderFilter ?? (() => ({})),
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
file.mimetype = file.mimetype?.split(';')[0] || 'application/octet-stream'
|
|
96
|
+
file.size = file.data.length
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (maxFileSize !== undefined && Number.isFinite(maxFileSize) && file.size > maxFileSize) {
|
|
100
|
+
throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return file
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function decodeBase64({ maxFileSize, value }: { maxFileSize?: number; value: string }): Buffer {
|
|
107
|
+
const normalized = value.replace(/\s/g, '')
|
|
108
|
+
|
|
109
|
+
if (!/^[a-z0-9+/]*={0,2}$/i.test(normalized) || normalized.length % 4 === 1) {
|
|
110
|
+
throw new APIError('File data must be valid base64.', 400)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (maxFileSize !== undefined && Number.isFinite(maxFileSize)) {
|
|
114
|
+
const paddingLength = normalized.endsWith('==') ? 2 : normalized.endsWith('=') ? 1 : 0
|
|
115
|
+
const decodedSize = Math.floor((normalized.length * 3) / 4) - paddingLength
|
|
116
|
+
|
|
117
|
+
if (decodedSize > maxFileSize) {
|
|
118
|
+
throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const data = Buffer.from(normalized, 'base64')
|
|
123
|
+
|
|
124
|
+
if (data.toString('base64').replace(/=+$/, '') !== normalized.replace(/=+$/, '')) {
|
|
125
|
+
throw new APIError('File data must be valid base64.', 400)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return data
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function getURLFilename(url: URL): string {
|
|
132
|
+
const pathSegment = url.pathname.split('/').pop() || 'upload'
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
return decodeURIComponent(pathSegment)
|
|
136
|
+
} catch {
|
|
137
|
+
return pathSegment
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
10
9
|
|
|
11
10
|
const DEFAULT_DESCRIPTION =
|
|
@@ -83,8 +82,8 @@ export const findDistinctTool = defineCollectionTool({
|
|
|
83
82
|
collection: collectionSlug,
|
|
84
83
|
depth,
|
|
85
84
|
field,
|
|
85
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
86
86
|
req,
|
|
87
|
-
...localAPIDefaults(authorizedMCP),
|
|
88
87
|
...(limit ? { limit } : {}),
|
|
89
88
|
...(locale ? { locale } : {}),
|
|
90
89
|
...(page ? { page } : {}),
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
10
9
|
|
|
11
10
|
const DEFAULT_DESCRIPTION =
|
|
@@ -40,7 +39,7 @@ export const findDocumentsTool = defineCollectionTool({
|
|
|
40
39
|
draft: z
|
|
41
40
|
.boolean()
|
|
42
41
|
.describe(
|
|
43
|
-
'
|
|
42
|
+
'For versioned collections, true returns the latest draft version when available. False reads the main document.',
|
|
44
43
|
)
|
|
45
44
|
.optional(),
|
|
46
45
|
fallbackLocale: z
|
|
@@ -134,8 +133,8 @@ export const findDocumentsTool = defineCollectionTool({
|
|
|
134
133
|
id,
|
|
135
134
|
collection: collectionSlug,
|
|
136
135
|
depth,
|
|
136
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
137
137
|
req,
|
|
138
|
-
...localAPIDefaults(authorizedMCP),
|
|
139
138
|
...(select && { select: select as SelectType }),
|
|
140
139
|
...(populate && { populate: populate as PopulateType }),
|
|
141
140
|
...(joins !== undefined && { joins: joins as JoinQuery }),
|
|
@@ -171,9 +170,9 @@ export const findDocumentsTool = defineCollectionTool({
|
|
|
171
170
|
collection: collectionSlug,
|
|
172
171
|
depth,
|
|
173
172
|
limit,
|
|
173
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
174
174
|
page,
|
|
175
175
|
req,
|
|
176
|
-
...localAPIDefaults(authorizedMCP),
|
|
177
176
|
...(select && { select: select as SelectType }),
|
|
178
177
|
...(populate && { populate: populate as PopulateType }),
|
|
179
178
|
...(joins !== undefined && { joins: joins as JoinQuery }),
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
|
|
10
9
|
const DEFAULT_DESCRIPTION =
|
|
11
10
|
'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.'
|
|
@@ -75,8 +74,8 @@ export const findVersionByIDTool = defineCollectionTool({
|
|
|
75
74
|
id,
|
|
76
75
|
collection: collectionSlug,
|
|
77
76
|
depth,
|
|
77
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
78
78
|
req,
|
|
79
|
-
...localAPIDefaults(authorizedMCP),
|
|
80
79
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
81
80
|
...(locale ? { locale } : {}),
|
|
82
81
|
...(populate ? { populate: populate as PopulateType } : {}),
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
10
9
|
|
|
11
10
|
const DEFAULT_DESCRIPTION =
|
|
@@ -116,9 +115,9 @@ export const findVersionsTool = defineCollectionTool({
|
|
|
116
115
|
collection: collectionSlug,
|
|
117
116
|
depth,
|
|
118
117
|
limit,
|
|
118
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
119
119
|
page,
|
|
120
120
|
req,
|
|
121
|
-
...localAPIDefaults(authorizedMCP),
|
|
122
121
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
123
122
|
...(locale ? { locale } : {}),
|
|
124
123
|
...(pagination !== undefined ? { pagination } : {}),
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getAccessResults } from 'payload'
|
|
2
|
+
|
|
1
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
2
4
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
3
5
|
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
@@ -6,12 +8,7 @@ export const getCollectionSchemaTool = defineCollectionTool({
|
|
|
6
8
|
access: (args) => {
|
|
7
9
|
const permissions = args.permissions?.collections?.[args.collectionSlug]
|
|
8
10
|
|
|
9
|
-
return (
|
|
10
|
-
defaultAccess(args) &&
|
|
11
|
-
Boolean(
|
|
12
|
-
permissions?.create || permissions?.delete || permissions?.read || permissions?.update,
|
|
13
|
-
)
|
|
14
|
-
)
|
|
11
|
+
return defaultAccess(args) && Boolean(permissions?.create || permissions?.update)
|
|
15
12
|
},
|
|
16
13
|
annotations: {
|
|
17
14
|
destructiveHint: false,
|
|
@@ -21,8 +18,28 @@ export const getCollectionSchemaTool = defineCollectionTool({
|
|
|
21
18
|
title: 'Get Collection Schema',
|
|
22
19
|
},
|
|
23
20
|
description: 'Get the input schema for creating or updating documents in a collection.',
|
|
24
|
-
}).handler(({ collectionSlug, req }) => {
|
|
25
|
-
const
|
|
21
|
+
}).handler(async ({ authorizedMCP, collectionSlug, req }) => {
|
|
22
|
+
const permissions = authorizedMCP.overrideAccess
|
|
23
|
+
? null
|
|
24
|
+
: (await getAccessResults({ req })).collections?.[collectionSlug]
|
|
25
|
+
|
|
26
|
+
if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {
|
|
27
|
+
return {
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: 'text',
|
|
31
|
+
text: `Error: MCP access to "getCollectionSchema" is not enabled for collection "${collectionSlug}"`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
isError: true,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const inputSchema = getCollectionInputSchema({
|
|
39
|
+
collectionSlug,
|
|
40
|
+
req,
|
|
41
|
+
...(permissions ? { permissions } : {}),
|
|
42
|
+
})
|
|
26
43
|
|
|
27
44
|
if (!inputSchema) {
|
|
28
45
|
return {
|
|
@@ -31,16 +48,29 @@ export const getCollectionSchemaTool = defineCollectionTool({
|
|
|
31
48
|
}
|
|
32
49
|
}
|
|
33
50
|
|
|
51
|
+
const uploadConfig = req.payload.collections[collectionSlug]?.config.upload
|
|
52
|
+
const maxFileSize = req.payload.config.upload.limits?.fileSize
|
|
53
|
+
const upload = uploadConfig
|
|
54
|
+
? {
|
|
55
|
+
enabled: true,
|
|
56
|
+
filesRequiredOnCreate: uploadConfig.filesRequiredOnCreate !== false,
|
|
57
|
+
mimeTypes: uploadConfig.mimeTypes ?? ['*/*'],
|
|
58
|
+
sources: [...(uploadConfig.pasteURL !== false ? ['url'] : []), 'base64'],
|
|
59
|
+
...(typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? { maxFileSize } : {}),
|
|
60
|
+
}
|
|
61
|
+
: { enabled: false }
|
|
62
|
+
|
|
34
63
|
return {
|
|
35
64
|
content: [
|
|
36
65
|
{
|
|
37
66
|
type: 'text',
|
|
38
|
-
text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``,
|
|
67
|
+
text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``,
|
|
39
68
|
},
|
|
40
69
|
],
|
|
41
70
|
structuredContent: {
|
|
42
71
|
collectionSlug,
|
|
43
72
|
schema: inputSchema,
|
|
73
|
+
upload,
|
|
44
74
|
},
|
|
45
75
|
}
|
|
46
76
|
})
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
|
|
10
9
|
const DEFAULT_DESCRIPTION =
|
|
11
10
|
'Restore a document from a previous version in any version-enabled collection.'
|
|
@@ -74,8 +73,8 @@ export const restoreVersionTool = defineCollectionTool({
|
|
|
74
73
|
collection: collectionSlug,
|
|
75
74
|
depth,
|
|
76
75
|
draft,
|
|
76
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
77
77
|
req,
|
|
78
|
-
...localAPIDefaults(authorizedMCP),
|
|
79
78
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
80
79
|
...(locale ? { locale } : {}),
|
|
81
80
|
...(populate ? { populate: populate as PopulateType } : {}),
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
getCollectionVirtualFieldNames,
|
|
10
10
|
stripVirtualFields,
|
|
11
11
|
} from '../../../utils/getVirtualFieldNames.js'
|
|
12
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
13
12
|
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
14
13
|
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
15
14
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
16
15
|
import { validateCollectionData } from '../validateEntityData.js'
|
|
16
|
+
import { fileInputSchema, resolveFileInput } from './fileInput.js'
|
|
17
17
|
import { formatCollectionError } from './formatCollectionError.js'
|
|
18
18
|
|
|
19
19
|
const DEFAULT_DESCRIPTION =
|
|
@@ -32,7 +32,11 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
32
32
|
description: DEFAULT_DESCRIPTION,
|
|
33
33
|
input: z.object({
|
|
34
34
|
id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),
|
|
35
|
-
data: z
|
|
35
|
+
data: z
|
|
36
|
+
.record(z.string(), z.unknown())
|
|
37
|
+
.describe(
|
|
38
|
+
'The fields to update. Only include fields permitted by the schema returned by getCollectionSchema.',
|
|
39
|
+
),
|
|
36
40
|
depth: z
|
|
37
41
|
.number()
|
|
38
42
|
.describe('How many levels deep to populate relationships')
|
|
@@ -40,14 +44,16 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
40
44
|
.default(0),
|
|
41
45
|
draft: z
|
|
42
46
|
.boolean()
|
|
43
|
-
.describe(
|
|
47
|
+
.describe(
|
|
48
|
+
'Only if getCollectionSchema includes _status; otherwise _status does not exist. true saves only a draft version; false updates main and versions. data._status: "published" overrides true.',
|
|
49
|
+
)
|
|
44
50
|
.optional()
|
|
45
51
|
.default(false),
|
|
46
52
|
fallbackLocale: z
|
|
47
53
|
.string()
|
|
48
54
|
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
49
55
|
.optional(),
|
|
50
|
-
|
|
56
|
+
file: fileInputSchema.optional(),
|
|
51
57
|
locale: z
|
|
52
58
|
.string()
|
|
53
59
|
.describe(
|
|
@@ -64,6 +70,12 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
64
70
|
.describe('Whether to overwrite existing files')
|
|
65
71
|
.optional()
|
|
66
72
|
.default(false),
|
|
73
|
+
publishAllLocales: z
|
|
74
|
+
.boolean()
|
|
75
|
+
.describe(
|
|
76
|
+
'For collections with localized publishing status, whether publishing should affect every locale. Set false with locale to publish only that locale.',
|
|
77
|
+
)
|
|
78
|
+
.optional(),
|
|
67
79
|
select: z
|
|
68
80
|
.record(z.string(), z.unknown())
|
|
69
81
|
.describe(
|
|
@@ -86,10 +98,11 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
86
98
|
depth,
|
|
87
99
|
draft,
|
|
88
100
|
fallbackLocale,
|
|
89
|
-
|
|
101
|
+
file: fileInput,
|
|
90
102
|
locale,
|
|
91
103
|
overrideLock,
|
|
92
104
|
overwriteExistingFiles,
|
|
105
|
+
publishAllLocales,
|
|
93
106
|
select,
|
|
94
107
|
where,
|
|
95
108
|
} = input
|
|
@@ -119,6 +132,7 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
119
132
|
}
|
|
120
133
|
|
|
121
134
|
const parsedData = transformPointDataToPayload(inputData)
|
|
135
|
+
const file = await resolveFileInput({ collectionSlug, input: fileInput, req })
|
|
122
136
|
|
|
123
137
|
const whereClause: Where = where ?? {}
|
|
124
138
|
|
|
@@ -129,11 +143,12 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
129
143
|
data: parsedData,
|
|
130
144
|
depth,
|
|
131
145
|
draft,
|
|
146
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
132
147
|
overrideLock,
|
|
133
148
|
req,
|
|
134
|
-
...
|
|
135
|
-
...(filePath ? { filePath } : {}),
|
|
149
|
+
...(file ? { file } : {}),
|
|
136
150
|
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
151
|
+
...(publishAllLocales !== undefined ? { publishAllLocales } : {}),
|
|
137
152
|
...(locale ? { locale } : {}),
|
|
138
153
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
139
154
|
...(select ? { select: select as SelectType } : {}),
|
|
@@ -155,12 +170,13 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
155
170
|
data: parsedData,
|
|
156
171
|
depth,
|
|
157
172
|
draft,
|
|
173
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
158
174
|
overrideLock,
|
|
159
175
|
req,
|
|
160
176
|
where: whereClause,
|
|
161
|
-
...
|
|
162
|
-
...(filePath ? { filePath } : {}),
|
|
177
|
+
...(file ? { file } : {}),
|
|
163
178
|
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
179
|
+
...(publishAllLocales !== undefined ? { publishAllLocales } : {}),
|
|
164
180
|
...(locale ? { locale } : {}),
|
|
165
181
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
166
182
|
...(select ? { select: select as SelectType } : {}),
|
|
@@ -12,10 +12,8 @@ export const getConfigInfoTool = defineTool({
|
|
|
12
12
|
},
|
|
13
13
|
description: 'List the Payload collection and global slugs visible to this MCP client.',
|
|
14
14
|
}).handler(async ({ authorizedMCP, req }) => {
|
|
15
|
-
const user =
|
|
16
|
-
const permissions = authorizedMCP.overrideAccess
|
|
17
|
-
? null
|
|
18
|
-
: await getAccessResults({ req: { ...req, user } })
|
|
15
|
+
const user = req.user
|
|
16
|
+
const permissions = authorizedMCP.overrideAccess ? null : await getAccessResults({ req })
|
|
19
17
|
const authorizedCollectionSlugs = new Set<string>()
|
|
20
18
|
const authorizedGlobalSlugs = new Set<string>()
|
|
21
19
|
|
|
@@ -3,7 +3,6 @@ import { z } from 'zod'
|
|
|
3
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
4
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
5
5
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
7
6
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
8
7
|
|
|
9
8
|
const DEFAULT_DESCRIPTION =
|
|
@@ -38,8 +37,8 @@ export const countGlobalVersionsTool = defineGlobalTool({
|
|
|
38
37
|
try {
|
|
39
38
|
const result = await payload.countGlobalVersions({
|
|
40
39
|
global: globalSlug,
|
|
40
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
41
41
|
req,
|
|
42
|
-
...localAPIDefaults(authorizedMCP),
|
|
43
42
|
...(locale ? { locale } : {}),
|
|
44
43
|
...(where ? { where } : {}),
|
|
45
44
|
})
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
|
|
10
9
|
const DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.'
|
|
11
10
|
|
|
@@ -66,7 +65,8 @@ export const findGlobalTool = defineGlobalTool({
|
|
|
66
65
|
const findOptions: Parameters<typeof payload.findGlobal>[0] = {
|
|
67
66
|
slug: globalSlug,
|
|
68
67
|
depth,
|
|
69
|
-
|
|
68
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
69
|
+
req,
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (locale) {
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
|
|
10
9
|
const DEFAULT_DESCRIPTION =
|
|
11
10
|
'Find a specific global version in any version-enabled global by passing the global slug and version ID.'
|
|
@@ -70,8 +69,8 @@ export const findGlobalVersionByIDTool = defineGlobalTool({
|
|
|
70
69
|
id,
|
|
71
70
|
slug: globalSlug,
|
|
72
71
|
depth,
|
|
72
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
73
73
|
req,
|
|
74
|
-
...localAPIDefaults(authorizedMCP),
|
|
75
74
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
76
75
|
...(locale ? { locale } : {}),
|
|
77
76
|
...(populate ? { populate: populate as PopulateType } : {}),
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
10
9
|
|
|
11
10
|
const DEFAULT_DESCRIPTION =
|
|
@@ -110,9 +109,9 @@ export const findGlobalVersionsTool = defineGlobalTool({
|
|
|
110
109
|
slug: globalSlug,
|
|
111
110
|
depth,
|
|
112
111
|
limit,
|
|
112
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
113
113
|
page,
|
|
114
114
|
req,
|
|
115
|
-
...localAPIDefaults(authorizedMCP),
|
|
116
115
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
117
116
|
...(locale ? { locale } : {}),
|
|
118
117
|
...(pagination !== undefined ? { pagination } : {}),
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getAccessResults } from 'payload'
|
|
2
|
+
|
|
1
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
2
4
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
3
5
|
import { getGlobalInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
@@ -6,7 +8,7 @@ export const getGlobalSchemaTool = defineGlobalTool({
|
|
|
6
8
|
access: (args) => {
|
|
7
9
|
const permissions = args.permissions?.globals?.[args.globalSlug]
|
|
8
10
|
|
|
9
|
-
return defaultAccess(args) && Boolean(permissions?.
|
|
11
|
+
return defaultAccess(args) && Boolean(permissions?.update)
|
|
10
12
|
},
|
|
11
13
|
annotations: {
|
|
12
14
|
destructiveHint: false,
|
|
@@ -16,8 +18,28 @@ export const getGlobalSchemaTool = defineGlobalTool({
|
|
|
16
18
|
title: 'Get Global Schema',
|
|
17
19
|
},
|
|
18
20
|
description: 'Get the input schema for updating a global.',
|
|
19
|
-
}).handler(({ globalSlug, req }) => {
|
|
20
|
-
const
|
|
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
|
+
})
|
|
21
43
|
|
|
22
44
|
if (!inputSchema) {
|
|
23
45
|
return {
|
|
@@ -5,7 +5,6 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
6
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
9
8
|
|
|
10
9
|
const DEFAULT_DESCRIPTION =
|
|
11
10
|
'Restore a global from a previous version in any version-enabled global.'
|
|
@@ -62,8 +61,8 @@ export const restoreGlobalVersionTool = defineGlobalTool({
|
|
|
62
61
|
id,
|
|
63
62
|
slug: globalSlug,
|
|
64
63
|
depth,
|
|
64
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
65
65
|
req,
|
|
66
|
-
...localAPIDefaults(authorizedMCP),
|
|
67
66
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
68
67
|
...(locale ? { locale } : {}),
|
|
69
68
|
...(populate ? { populate: populate as PopulateType } : {}),
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
getGlobalVirtualFieldNames,
|
|
10
10
|
stripVirtualFields,
|
|
11
11
|
} from '../../../utils/getVirtualFieldNames.js'
|
|
12
|
-
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
13
12
|
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
14
13
|
import { validateGlobalData } from '../validateEntityData.js'
|
|
15
14
|
|
|
@@ -81,7 +80,8 @@ export const updateGlobalTool = defineGlobalTool({
|
|
|
81
80
|
data: parsedData,
|
|
82
81
|
depth,
|
|
83
82
|
draft,
|
|
84
|
-
|
|
83
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
84
|
+
req,
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
if (locale) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CollectionSlug, GlobalSlug, PayloadRequest, SanitizedConfig } from 'payload'
|
|
2
2
|
|
|
3
|
-
import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server'
|
|
3
|
+
import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server/validators/cf-worker'
|
|
4
4
|
|
|
5
5
|
import type { JsonSchemaType, MCPToolResponse } from '../../types.js'
|
|
6
6
|
|