CherryHQ/cherry-studio · warning · Error

Invalid arguments for edit: ${parsed.error}

Error message

Invalid arguments for edit: ${parsed.error}

What it means

Zod safeParse on the edit tool's arguments failed. EditToolSchema requires file_path, old_string, new_string as strings and accepts an optional replace_all boolean (default false). parsed.error is a ZodError enumerating each failing field. Returned to the MCP client as an isError tool result via the server-level catch.

Source

Thrown at src/main/ai/mcp/servers/filesystem/tools/edit.ts:36

  description: `Performs exact string replacements in files.

- You must use the 'read' tool at least once before editing
- The file_path must resolve within the configured workspace root
- Preserve exact indentation from read output (after the line number prefix)
- Never include line number prefixes in old_string or new_string
- ALWAYS prefer editing existing files over creating new ones
- The edit will FAIL if old_string is not found in the file
- The edit will FAIL if old_string appears multiple times (provide more context or use replace_all)
- The edit will FAIL if old_string equals new_string
- Use replace_all to rename variables or replace all occurrences`,
  inputSchema: z.toJSONSchema(EditToolSchema)
}

// Handler implementation
export async function handleEditTool(args: unknown, baseDir: string) {
  const parsed = EditToolSchema.safeParse(args)
  if (!parsed.success) {
    throw new Error(`Invalid arguments for edit: ${parsed.error}`)
  }

  const { file_path: filePath, old_string: oldString, new_string: newString, replace_all: replaceAll } = parsed.data

  // Validate path
  const validPath = await validatePath(filePath, baseDir)

  // Check if file exists
  try {
    const stats = await fs.stat(validPath)
    if (!stats.isFile()) {
      throw new Error(`Path is not a file: ${filePath}`)
    }
  } catch (error: any) {
    if (error.code === 'ENOENT') {
      // If old_string is empty, this is a create new file operation
      if (oldString === '') {
        // Create parent directory if needed

View on GitHub (pinned to 726446b54c)

Solutions

  1. Provide all three required fields as strings: file_path, old_string, new_string.
  2. For file creation, send old_string as the empty string '' explicitly rather than omitting it.
  3. Read parsed.error in the returned message — it identifies the missing or mistyped field.

Example fix

// before
if (!parsed.success) {
  throw new Error(`Invalid arguments for edit: ${parsed.error}`)
}

// after — name the failing fields explicitly
if (!parsed.success) {
  const issues = parsed.error.issues.map(i => `${i.path.join('.') || '(root)'}: ${i.message}`).join('; ')
  throw new Error(`Invalid arguments for edit: ${issues}`)
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate edit args client-side before dispatching.
function isValidEditArgs(a: unknown): a is { file_path: string; old_string: string; new_string: string; replace_all?: boolean } {
  if (typeof a !== 'object' || a === null) return false
  const o = a as any
  return typeof o.file_path === 'string' && typeof o.old_string === 'string' && typeof o.new_string === 'string'
    && (o.replace_all === undefined || typeof o.replace_all === 'boolean')
}

Type guard

function isEditArgs(a: unknown): a is { file_path: string; old_string: string; new_string: string } {
  return typeof a === 'object' && a !== null && typeof (a as any).file_path === 'string'
    && typeof (a as any).old_string === 'string' && typeof (a as any).new_string === 'string'
}

Prevention

When it happens

Trigger: The arguments object is missing any of the three required strings, has a non-string value, or is not a parseable object. A common case is the model sending old_string and new_string but forgetting file_path.

Common situations: A model attempting a 'create file' edit by sending only new_string (the empty-old_string create path still requires the field to be present); schema drift between client and server; a client sending arguments as a JSON string instead of a parsed object.

Related errors


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