CherryHQ/cherry-studio · error · Error

Invalid command: command must be a non-empty string

Error message

Invalid command: command must be a non-empty string

What it means

Thrown by validateCommand() when the command field from an MCP package manifest is falsy (null, undefined, empty string, 0, false) or not of type string. This is the first validation gate: it rejects non-string values before any further processing. The function is called after variable substitution (performVariableSubstitution) has been applied to the manifest's command field.

Source

Thrown at src/main/ai/mcp/McpPackageService.ts:142

const MCP_PACKAGE_UPLOAD_MAX_BYTES = 100 * 1024 * 1024

/**
 * Validate and sanitize a command to prevent path traversal attacks.
 * Commands should be either:
 * 1. Simple command names (e.g., "node", "python", "npx") - looked up in PATH
 * 2. Absolute paths (e.g., "/usr/bin/node", "C:\\Program Files\\node\\node.exe")
 * 3. Relative paths starting with ./ or .\ (relative to extractDir)
 *
 * Rejects commands containing path traversal sequences (..)
 *
 * @param command - The command to validate
 * @returns The validated command
 * @throws Error if command contains path traversal or is invalid
 */
export function validateCommand(command: string): string {
  if (!command || typeof command !== 'string') {
    throw new Error('Invalid command: command must be a non-empty string')
  }

  const trimmed = command.trim()
  if (!trimmed) {
    throw new Error('Invalid command: command cannot be empty')
  }

  // Check for path traversal sequences
  // This catches: .., ../, ..\, /../, \..\, etc.
  if (/(?:^|[/\\])\.\.(?:[/\\]|$)/.test(trimmed) || trimmed === '..') {
    throw new Error(`Invalid command: path traversal detected in "${command}"`)
  }

  // Check for null bytes
  if (trimmed.includes('\0')) {
    throw new Error('Invalid command: null byte detected')
  }

View on GitHub (pinned to 726446b54c)

Solutions

  1. Inspect the package manifest's server.mcp_config.command field — ensure it is a non-empty string.
  2. If using platform_overrides, verify each override's command field is a valid string.
  3. Validate the manifest JSON against the DXT/MCPB schema before installing the package.
Defensive patterns

Strategy: type-guard

Validate before calling

// Validate command field type before calling validateCommand
if (typeof manifest.server.mcp_config.command !== 'string') {
  throw new Error('Manifest command field must be a string')
}
const command = validateCommand(manifest.server.mcp_config.command)

Type guard

function isNonEmptyString(value: unknown): value is string {
  return typeof value === 'string' && value.length > 0
}

Prevention

When it happens

Trigger: Called from resolveMcpConfig at line 351 after performVariableSubstitution runs on the manifest's server.mcp_config.command. Triggers when the manifest JSON has a missing, null, or non-string command field — e.g., { command: null }, { command: 123 }, or the field is absent entirely.

Common situations: A malformed DXT/MCPB manifest omitted the command field; the manifest used a platform_override that set command to null; variable substitution produced a non-string value from a user_config key; a manually-authored manifest had a typo in the field name.

Related errors


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/ae78386d3126698b. Report an issue: GitHub.