@payloadcms/plugin-mcp 4.0.0-internal.656159a → 4.0.0-internal.697830c
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 +0 -7
- 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.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +3 -13
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- 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 +2 -23
- 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 +8 -21
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.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 +3 -13
- package/src/mcp/builtin/collections/findTool.ts +1 -1
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +1 -14
- package/src/mcp/builtin/collections/updateTool.ts +6 -23
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +2 -2
- package/dist/mcp/builtin/collections/fileInput.d.ts +0 -20
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +0 -1
- package/dist/mcp/builtin/collections/fileInput.js +0 -100
- package/dist/mcp/builtin/collections/fileInput.js.map +0 -1
- package/dist/mcp/builtin/collections/fileInput.spec.js +0 -72
- package/dist/mcp/builtin/collections/fileInput.spec.js.map +0 -1
- package/src/mcp/builtin/collections/fileInput.spec.ts +0 -79
- package/src/mcp/builtin/collections/fileInput.ts +0 -139
|
@@ -1,139 +0,0 @@
|
|
|
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
|
-
}
|