@payloadcms/plugin-mcp 4.0.0-internal.543da65 → 4.0.0-internal.567a487
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.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts.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 +91 -39
- package/dist/mcp/builtin/collections/createTool.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 +124 -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/findTool.js +1 -1
- package/dist/mcp/builtin/collections/findTool.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 +24 -2
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +22 -9
- 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/validateEntityData.d.ts.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/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +2 -2
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
- package/dist/utils/toStandardSchema.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/mcp/builtin/collections/createTool.ts +90 -33
- package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
- package/src/mcp/builtin/collections/fileInput.ts +164 -0
- package/src/mcp/builtin/collections/findTool.ts +1 -1
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +18 -1
- package/src/mcp/builtin/collections/updateTool.ts +24 -7
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtinTools.ts +9 -2
- package/src/mcp/sanitizeMCPConfig.ts +4 -1
- package/src/stdio.ts +2 -1
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +2 -2
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { CollectionSlug, File, FileData, PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { APIError } from 'payload'
|
|
4
|
+
import { getExternalFile, getFileFromUploadInstructions, 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
|
+
const uploadFileSchema = z.object({
|
|
13
|
+
filename: z.string(),
|
|
14
|
+
mimeType: z.string(),
|
|
15
|
+
size: z.number().int().nonnegative(),
|
|
16
|
+
uploadReference: z.record(z.string(), z.unknown()),
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const fileInputSchema = z
|
|
20
|
+
.discriminatedUnion('source', [
|
|
21
|
+
z.object({
|
|
22
|
+
name: z.string().min(1).describe('The file name, including its extension'),
|
|
23
|
+
data: z.string().describe('The base64-encoded file bytes, without a data URL prefix'),
|
|
24
|
+
mimeType: mimeTypeSchema.describe('The file MIME type, for example image/png'),
|
|
25
|
+
source: z.literal('base64'),
|
|
26
|
+
}),
|
|
27
|
+
z.object({
|
|
28
|
+
name: z.string().min(1).describe('Optional file name override').optional(),
|
|
29
|
+
source: z.literal('externalURL'),
|
|
30
|
+
url: z.url().describe('The http or https URL to download'),
|
|
31
|
+
}),
|
|
32
|
+
z.object({
|
|
33
|
+
file: uploadFileSchema.describe('getUploadInstructions file field post-upload'),
|
|
34
|
+
source: z.literal('uploadReference'),
|
|
35
|
+
}),
|
|
36
|
+
])
|
|
37
|
+
.describe(
|
|
38
|
+
'A file for an upload collection. Prefer uploadReference after its upload succeeds; use base64 only for small local files or externalURL for an online file.',
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
type FileInput = z.infer<typeof fileInputSchema>
|
|
42
|
+
|
|
43
|
+
export async function resolveFile({
|
|
44
|
+
collectionSlug,
|
|
45
|
+
input,
|
|
46
|
+
req,
|
|
47
|
+
}: {
|
|
48
|
+
collectionSlug: CollectionSlug
|
|
49
|
+
input?: FileInput
|
|
50
|
+
req: PayloadRequest
|
|
51
|
+
}): Promise<File | undefined> {
|
|
52
|
+
if (!input) {
|
|
53
|
+
return undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (input.source === 'uploadReference') {
|
|
57
|
+
try {
|
|
58
|
+
return await getFileFromUploadInstructions({ collectionSlug, file: input.file, req })
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error instanceof Error && error.message === 'Staged upload was not found.') {
|
|
61
|
+
throw new APIError(
|
|
62
|
+
'Staged upload not found. Complete the upload action first, or use base64 for small local files.',
|
|
63
|
+
400,
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
throw error
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const uploadConfig = req.payload.collections[collectionSlug]?.config.upload
|
|
71
|
+
|
|
72
|
+
if (!uploadConfig) {
|
|
73
|
+
throw new APIError(`Collection "${collectionSlug}" does not support file uploads.`, 400)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const maxFileSize = req.payload.config.upload.limits?.fileSize
|
|
77
|
+
let file: File
|
|
78
|
+
|
|
79
|
+
if (input.source === 'base64') {
|
|
80
|
+
const data = decodeBase64({ maxFileSize, value: input.data })
|
|
81
|
+
|
|
82
|
+
file = {
|
|
83
|
+
name: sanitizeFilename(input.name),
|
|
84
|
+
data,
|
|
85
|
+
mimetype: input.mimeType,
|
|
86
|
+
size: data.length,
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
if (uploadConfig.pasteURL === false) {
|
|
90
|
+
throw new APIError(
|
|
91
|
+
`Uploading files from URLs is disabled for collection "${collectionSlug}".`,
|
|
92
|
+
400,
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const url = new URL(input.url)
|
|
97
|
+
|
|
98
|
+
if (!['http:', 'https:'].includes(url.protocol)) {
|
|
99
|
+
throw new APIError('File URLs must use http or https.', 400)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (
|
|
103
|
+
typeof uploadConfig.pasteURL === 'object' &&
|
|
104
|
+
!isURLAllowed(input.url, uploadConfig.pasteURL.allowList)
|
|
105
|
+
) {
|
|
106
|
+
throw new APIError('The provided file URL is not allowed.', 400)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
file = await getExternalFile({
|
|
110
|
+
data: {
|
|
111
|
+
filename: sanitizeFilename(input.name || getURLFilename(url)),
|
|
112
|
+
url: input.url,
|
|
113
|
+
} as FileData,
|
|
114
|
+
req,
|
|
115
|
+
uploadConfig: {
|
|
116
|
+
...uploadConfig,
|
|
117
|
+
externalFileHeaderFilter: uploadConfig.externalFileHeaderFilter ?? (() => ({})),
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
file.mimetype = file.mimetype?.split(';')[0] || 'application/octet-stream'
|
|
121
|
+
file.size = file.data.length
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (maxFileSize !== undefined && Number.isFinite(maxFileSize) && file.size > maxFileSize) {
|
|
125
|
+
throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return file
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function decodeBase64({ maxFileSize, value }: { maxFileSize?: number; value: string }): Buffer {
|
|
132
|
+
const normalized = value.replace(/\s/g, '')
|
|
133
|
+
|
|
134
|
+
if (!/^[a-z0-9+/]*={0,2}$/i.test(normalized) || normalized.length % 4 === 1) {
|
|
135
|
+
throw new APIError('File data must be valid base64.', 400)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (maxFileSize !== undefined && Number.isFinite(maxFileSize)) {
|
|
139
|
+
const paddingLength = normalized.endsWith('==') ? 2 : normalized.endsWith('=') ? 1 : 0
|
|
140
|
+
const decodedSize = Math.floor((normalized.length * 3) / 4) - paddingLength
|
|
141
|
+
|
|
142
|
+
if (decodedSize > maxFileSize) {
|
|
143
|
+
throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const data = Buffer.from(normalized, 'base64')
|
|
148
|
+
|
|
149
|
+
if (data.toString('base64').replace(/=+$/, '') !== normalized.replace(/=+$/, '')) {
|
|
150
|
+
throw new APIError('File data must be valid base64.', 400)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return data
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getURLFilename(url: URL): string {
|
|
157
|
+
const pathSegment = url.pathname.split('/').pop() || 'upload'
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
return decodeURIComponent(pathSegment)
|
|
161
|
+
} catch {
|
|
162
|
+
return pathSegment
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -39,7 +39,7 @@ export const findDocumentsTool = defineCollectionTool({
|
|
|
39
39
|
draft: z
|
|
40
40
|
.boolean()
|
|
41
41
|
.describe(
|
|
42
|
-
'
|
|
42
|
+
'For versioned collections, true returns the latest draft version when available. False reads the main document.',
|
|
43
43
|
)
|
|
44
44
|
.optional(),
|
|
45
45
|
fallbackLocale: z
|
|
@@ -48,16 +48,33 @@ export const getCollectionSchemaTool = defineCollectionTool({
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
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: [
|
|
59
|
+
...(uploadConfig.pasteURL !== false ? ['externalURL'] : []),
|
|
60
|
+
'base64',
|
|
61
|
+
'uploadReference',
|
|
62
|
+
],
|
|
63
|
+
...(typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? { maxFileSize } : {}),
|
|
64
|
+
}
|
|
65
|
+
: { enabled: false }
|
|
66
|
+
|
|
51
67
|
return {
|
|
52
68
|
content: [
|
|
53
69
|
{
|
|
54
70
|
type: 'text',
|
|
55
|
-
text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``,
|
|
71
|
+
text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``,
|
|
56
72
|
},
|
|
57
73
|
],
|
|
58
74
|
structuredContent: {
|
|
59
75
|
collectionSlug,
|
|
60
76
|
schema: inputSchema,
|
|
77
|
+
upload,
|
|
61
78
|
},
|
|
62
79
|
}
|
|
63
80
|
})
|
|
@@ -13,10 +13,11 @@ import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEnt
|
|
|
13
13
|
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
14
14
|
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
15
15
|
import { validateCollectionData } from '../validateEntityData.js'
|
|
16
|
+
import { fileInputSchema, resolveFile } from './fileInput.js'
|
|
16
17
|
import { formatCollectionError } from './formatCollectionError.js'
|
|
17
18
|
|
|
18
19
|
const DEFAULT_DESCRIPTION =
|
|
19
|
-
'Update documents
|
|
20
|
+
'Update documents. Prefer uploadReference after upload, externalURL for URLs, or base64 for small local files.'
|
|
20
21
|
|
|
21
22
|
export const updateDocumentTool = defineCollectionTool({
|
|
22
23
|
access: (args) =>
|
|
@@ -31,7 +32,11 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
31
32
|
description: DEFAULT_DESCRIPTION,
|
|
32
33
|
input: z.object({
|
|
33
34
|
id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),
|
|
34
|
-
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
|
+
),
|
|
35
40
|
depth: z
|
|
36
41
|
.number()
|
|
37
42
|
.describe('How many levels deep to populate relationships')
|
|
@@ -39,14 +44,16 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
39
44
|
.default(0),
|
|
40
45
|
draft: z
|
|
41
46
|
.boolean()
|
|
42
|
-
.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
|
+
)
|
|
43
50
|
.optional()
|
|
44
51
|
.default(false),
|
|
45
52
|
fallbackLocale: z
|
|
46
53
|
.string()
|
|
47
54
|
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
48
55
|
.optional(),
|
|
49
|
-
|
|
56
|
+
file: fileInputSchema.optional(),
|
|
50
57
|
locale: z
|
|
51
58
|
.string()
|
|
52
59
|
.describe(
|
|
@@ -63,6 +70,12 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
63
70
|
.describe('Whether to overwrite existing files')
|
|
64
71
|
.optional()
|
|
65
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(),
|
|
66
79
|
select: z
|
|
67
80
|
.record(z.string(), z.unknown())
|
|
68
81
|
.describe(
|
|
@@ -85,10 +98,11 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
85
98
|
depth,
|
|
86
99
|
draft,
|
|
87
100
|
fallbackLocale,
|
|
88
|
-
|
|
101
|
+
file: fileInput,
|
|
89
102
|
locale,
|
|
90
103
|
overrideLock,
|
|
91
104
|
overwriteExistingFiles,
|
|
105
|
+
publishAllLocales,
|
|
92
106
|
select,
|
|
93
107
|
where,
|
|
94
108
|
} = input
|
|
@@ -118,6 +132,7 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
118
132
|
}
|
|
119
133
|
|
|
120
134
|
const parsedData = transformPointDataToPayload(inputData)
|
|
135
|
+
const file = await resolveFile({ collectionSlug, input: fileInput, req })
|
|
121
136
|
|
|
122
137
|
const whereClause: Where = where ?? {}
|
|
123
138
|
|
|
@@ -131,8 +146,9 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
131
146
|
overrideAccess: authorizedMCP.overrideAccess,
|
|
132
147
|
overrideLock,
|
|
133
148
|
req,
|
|
134
|
-
...(
|
|
149
|
+
...(file ? { file } : {}),
|
|
135
150
|
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
151
|
+
...(publishAllLocales !== undefined ? { publishAllLocales } : {}),
|
|
136
152
|
...(locale ? { locale } : {}),
|
|
137
153
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
138
154
|
...(select ? { select: select as SelectType } : {}),
|
|
@@ -158,8 +174,9 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
158
174
|
overrideLock,
|
|
159
175
|
req,
|
|
160
176
|
where: whereClause,
|
|
161
|
-
...(
|
|
177
|
+
...(file ? { file } : {}),
|
|
162
178
|
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
179
|
+
...(publishAllLocales !== undefined ? { publishAllLocales } : {}),
|
|
163
180
|
...(locale ? { locale } : {}),
|
|
164
181
|
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
165
182
|
...(select ? { select: select as SelectType } : {}),
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getUploadInstructions as getPayloadUploadInstructions } from 'payload/internal'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
5
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
|
+
|
|
7
|
+
export const getUploadInstructionsTool = defineCollectionTool({
|
|
8
|
+
access: (args) =>
|
|
9
|
+
defaultAccess(args) &&
|
|
10
|
+
Boolean(
|
|
11
|
+
args.permissions?.collections?.[args.collectionSlug]?.create ||
|
|
12
|
+
args.permissions?.collections?.[args.collectionSlug]?.update,
|
|
13
|
+
),
|
|
14
|
+
annotations: {
|
|
15
|
+
destructiveHint: false,
|
|
16
|
+
idempotentHint: false,
|
|
17
|
+
openWorldHint: true,
|
|
18
|
+
readOnlyHint: false,
|
|
19
|
+
title: 'Get Upload Instructions',
|
|
20
|
+
},
|
|
21
|
+
description:
|
|
22
|
+
'Prepare uploads for createDocuments or updateDocument. This does not upload bytes; finish the returned action before use.',
|
|
23
|
+
input: z.object({
|
|
24
|
+
docPrefix: z.string().describe('Optional document folder or prefix').optional(),
|
|
25
|
+
filename: z.string().describe('The original file name'),
|
|
26
|
+
filesize: z.number().int().nonnegative().describe('The file size in bytes'),
|
|
27
|
+
mimeType: z.string().describe('The file MIME type'),
|
|
28
|
+
}),
|
|
29
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
30
|
+
try {
|
|
31
|
+
const instructions = await getPayloadUploadInstructions({
|
|
32
|
+
...input,
|
|
33
|
+
collectionSlug,
|
|
34
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
35
|
+
req,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const nextStep =
|
|
39
|
+
instructions.type === 'http'
|
|
40
|
+
? 'Upload bytes with instructions.request. After success, pass { source: "uploadReference", file: instructions.file }.'
|
|
41
|
+
: `Call "${instructions.name}" with file and data. After success, pass { source: "uploadReference", file: instructions.file }.`
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: `Upload instructions for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(instructions)}\n\`\`\`\n${nextStep}`,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
structuredContent: { instructions },
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const message = error instanceof Error ? error.message : 'Unknown error'
|
|
54
|
+
return {
|
|
55
|
+
content: [
|
|
56
|
+
{
|
|
57
|
+
type: 'text',
|
|
58
|
+
text: `Error getting upload instructions for collection "${collectionSlug}": ${message}`,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
isError: true,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
package/src/mcp/builtinTools.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from './builtin/collections/authTools.js'
|
|
11
11
|
import { countDocumentsTool } from './builtin/collections/countTool.js'
|
|
12
12
|
import { countVersionsTool } from './builtin/collections/countVersionsTool.js'
|
|
13
|
-
import {
|
|
13
|
+
import { createDocumentsTool } from './builtin/collections/createTool.js'
|
|
14
14
|
import { deleteDocumentsTool } from './builtin/collections/deleteTool.js'
|
|
15
15
|
import { duplicateDocumentTool } from './builtin/collections/duplicateTool.js'
|
|
16
16
|
import { findDistinctTool } from './builtin/collections/findDistinctTool.js'
|
|
@@ -20,6 +20,7 @@ import { findVersionsTool } from './builtin/collections/findVersionsTool.js'
|
|
|
20
20
|
import { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js'
|
|
21
21
|
import { restoreVersionTool } from './builtin/collections/restoreVersionTool.js'
|
|
22
22
|
import { updateDocumentTool } from './builtin/collections/updateTool.js'
|
|
23
|
+
import { getUploadInstructionsTool } from './builtin/collections/uploadInstructionsTool.js'
|
|
23
24
|
import { getConfigInfoTool } from './builtin/getConfigInfoTool.js'
|
|
24
25
|
import { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js'
|
|
25
26
|
import { findGlobalTool } from './builtin/globals/findTool.js'
|
|
@@ -32,6 +33,7 @@ import { updateGlobalTool } from './builtin/globals/updateTool.js'
|
|
|
32
33
|
type CollectionBuiltin = {
|
|
33
34
|
mcpName: string
|
|
34
35
|
requiresDuplicateEnabled?: boolean
|
|
36
|
+
requiresUpload?: boolean
|
|
35
37
|
requiresVersions?: boolean
|
|
36
38
|
tool: CollectionTool
|
|
37
39
|
}
|
|
@@ -54,7 +56,7 @@ export const TOOL_BUILTINS = {
|
|
|
54
56
|
export const COLLECTION_BUILTINS = {
|
|
55
57
|
count: { mcpName: 'countDocuments', tool: countDocumentsTool },
|
|
56
58
|
countVersions: { mcpName: 'countVersions', requiresVersions: true, tool: countVersionsTool },
|
|
57
|
-
create: { mcpName: '
|
|
59
|
+
create: { mcpName: 'createDocuments', tool: createDocumentsTool },
|
|
58
60
|
delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },
|
|
59
61
|
duplicate: {
|
|
60
62
|
mcpName: 'duplicateDocument',
|
|
@@ -70,6 +72,11 @@ export const COLLECTION_BUILTINS = {
|
|
|
70
72
|
},
|
|
71
73
|
findVersions: { mcpName: 'findVersions', requiresVersions: true, tool: findVersionsTool },
|
|
72
74
|
getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },
|
|
75
|
+
getUploadInstructions: {
|
|
76
|
+
mcpName: 'getUploadInstructions',
|
|
77
|
+
requiresUpload: true,
|
|
78
|
+
tool: getUploadInstructionsTool,
|
|
79
|
+
},
|
|
73
80
|
restoreVersion: { mcpName: 'restoreVersion', requiresVersions: true, tool: restoreVersionTool },
|
|
74
81
|
update: { mcpName: 'updateDocument', tool: updateDocumentTool },
|
|
75
82
|
} satisfies Record<string, CollectionBuiltin>
|
|
@@ -127,7 +127,7 @@ const sanitizeCollectionConfig = ({
|
|
|
127
127
|
|
|
128
128
|
for (const [
|
|
129
129
|
toolKey,
|
|
130
|
-
{ mcpName, requiresDuplicateEnabled, requiresVersions, tool },
|
|
130
|
+
{ mcpName, requiresDuplicateEnabled, requiresUpload, requiresVersions, tool },
|
|
131
131
|
] of COLLECTION_BUILTIN_ENTRIES) {
|
|
132
132
|
if (requiresVersions && !collection.versions) {
|
|
133
133
|
continue
|
|
@@ -135,6 +135,9 @@ const sanitizeCollectionConfig = ({
|
|
|
135
135
|
if (requiresDuplicateEnabled && isDuplicateDisabled) {
|
|
136
136
|
continue
|
|
137
137
|
}
|
|
138
|
+
if (requiresUpload && !collection.upload) {
|
|
139
|
+
continue
|
|
140
|
+
}
|
|
138
141
|
const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]
|
|
139
142
|
if (matchedConfigEntry === false) {
|
|
140
143
|
continue
|
package/src/stdio.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Config, Plugin, SanitizedConfig } from 'payload'
|
|
|
4
4
|
import { serveStdio } from '@modelcontextprotocol/server/stdio'
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
6
6
|
import { createLocalReq, getPayload } from 'payload'
|
|
7
|
-
import { findConfig } from 'payload/node'
|
|
7
|
+
import { findConfig, loadEnv } from 'payload/node'
|
|
8
8
|
|
|
9
9
|
import type { SanitizedMCPPluginConfig } from './types.js'
|
|
10
10
|
|
|
@@ -28,6 +28,7 @@ export const runMcpStdio = async (): Promise<void> => {
|
|
|
28
28
|
process.chdir(projectRoot)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
loadEnv()
|
|
31
32
|
const configPath = findConfig()
|
|
32
33
|
const configModule = await import(pathToFileURL(configPath).toString())
|
|
33
34
|
const config = (await (configModule.default ?? configModule)) as SanitizedConfig
|
|
@@ -76,8 +76,8 @@ describe('sanitizeEntitySchema', () => {
|
|
|
76
76
|
},
|
|
77
77
|
},
|
|
78
78
|
properties: {
|
|
79
|
-
// Managed
|
|
80
|
-
//
|
|
79
|
+
// Managed timestamps are excluded upstream by the `input` variant. `id` stays because it's
|
|
80
|
+
// a valid optional input (a client may supply a custom ID).
|
|
81
81
|
id: { type: 'string' },
|
|
82
82
|
content: {
|
|
83
83
|
type: 'object',
|