CherryHQ/cherry-studio · warning · Error
Invalid MCP package upload: file name cannot contain leading
Error message
Invalid MCP package upload: file name cannot contain leading or trailing whitespace
What it means
Thrown by validatePackageUploadPayload when fileName !== fileName.trim(), i.e. the value has leading or trailing whitespace. The service rejects this because (a) the temp-file path is built from the filename and surrounding whitespace causes confusing path errors, and (b) it almost always indicates a frontend string-handling bug rather than an intentional filename.
Source
Thrown at src/main/ai/mcp/McpPackageService.ts:291
return resolvedEnv
}
export function validatePackageUploadPayload(
fileBuffer: ArrayBuffer | NodeJS.ArrayBufferView,
fileName: string,
packageFormat: McpPackageFormat
): Buffer {
if (typeof fileName !== 'string') {
throw new Error('Invalid MCP package upload: file name must be a string')
}
const trimmedFileName = fileName.trim()
if (!trimmedFileName) {
throw new Error('Invalid MCP package upload: file name cannot be empty')
}
if (trimmedFileName !== fileName) {
throw new Error('Invalid MCP package upload: file name cannot contain leading or trailing whitespace')
}
if (trimmedFileName.includes('\0') || /[/\\]/.test(trimmedFileName)) {
throw new Error('Invalid MCP package upload: file name cannot contain path separators')
}
if (!/^[A-Za-z0-9._ ()@+-]+$/.test(trimmedFileName)) {
throw new Error('Invalid MCP package upload: file name contains unsupported characters')
}
if (path.extname(trimmedFileName).toLowerCase() !== `.${packageFormat}`) {
throw new Error(`Invalid MCP package upload: expected a .${packageFormat} file`)
}
let buffer: Buffer
if (fileBuffer instanceof ArrayBuffer) {
buffer = Buffer.from(fileBuffer)
} else if (ArrayBuffer.isView(fileBuffer)) {
buffer = Buffer.from(fileBuffer.buffer, fileBuffer.byteOffset, fileBuffer.byteLength)
} else {
throw new Error('Invalid MCP package upload: file buffer must be an ArrayBuffer')View on GitHub (pinned to 726446b54c)
Solutions
- On the renderer, pass file.name directly rather than a constructed or user-typed string; do not trim there because the service wants the raw value to detect the bug.
- Find the code path that added the whitespace (often a template literal or label concat) and remove it.
- Retry the upload once the frontend sends the verbatim File.name.
Example fix
// renderer - before
const fileName = `upload: ${file.name}`
// after
const fileName = file.name Defensive patterns
Strategy: validation
Validate before calling
function hasNoSurroundingWhitespace(s: string): boolean {
return s === s.trim()
} Type guard
function isTrimmedString(s: unknown): s is string {
return typeof s === 'string' && s.length > 0 && s === s.trim()
} Prevention
- Pass the verbatim File.name; do not construct filenames by concatenation with labels or prefixes.
- If the filename is user-typed, trim is the renderer's responsibility — but the service intentionally rejects pre-trimmed whitespace as a bug signal, so send a clean value.
- Add a renderer lint rule that flags template literals used to build filenames.
When it happens
Trigger: Renderer sent fileName = " pkg.mcpb" or "pkg.dxt\n". Common when the filename was concatenated with a separator and not trimmed, or when copy-pasted from a label that included padding spaces.
Common situations: The filename was read from a UI label or template literal that introduced spaces; a user typed the filename manually with stray spaces; the IPC payload builder did `somePrefix + ' ' + file.name`.
Related errors
- Invalid MCP package upload: file name must be a string
- Invalid MCP package upload: file name cannot be empty
- Invalid MCP package upload: file name cannot contain path se
- Invalid MCP package upload: file name contains unsupported c
- Invalid MCP package upload: expected a .${packageFormat} fil
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/769a5ff92d6b728b.
Report an issue: GitHub.