{"record":{"id":"050fc43ba8d77c57","repo":"CherryHQ/cherry-studio","slug":"invalid-arguments-for-delete-parsed-error","errorCode":null,"errorMessage":"Invalid arguments for delete: ${parsed.error}","messagePattern":"Invalid arguments for delete: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/main/ai/mcp/servers/filesystem/tools/delete.ts","lineNumber":32,"sourceCode":"export const deleteToolDefinition = {\n  name: 'delete',\n  description: `Deletes a file or directory from the filesystem.\n\nCAUTION: This operation cannot be undone!\n\n- For files: simply provide the path\n- For empty directories: provide the path\n- For non-empty directories: set recursive=true\n- The path must resolve within the configured workspace root\n- Always verify the path before deleting to avoid data loss`,\n  inputSchema: z.toJSONSchema(DeleteToolSchema)\n}\n\n// Handler implementation\nexport async function handleDeleteTool(args: unknown, baseDir: string) {\n  const parsed = DeleteToolSchema.safeParse(args)\n  if (!parsed.success) {\n    throw new Error(`Invalid arguments for delete: ${parsed.error}`)\n  }\n\n  const targetPath = parsed.data.path\n  const validPath = await validatePath(targetPath, baseDir)\n  const recursive = parsed.data.recursive || false\n\n  // Check if path exists and get stats\n  let stats\n  try {\n    stats = await fs.stat(validPath)\n  } catch (error: any) {\n    if (error.code === 'ENOENT') {\n      throw new Error(`Path not found: ${targetPath}`)\n    }\n    throw error\n  }\n\n  const isDirectory = stats.isDirectory()","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/servers/filesystem/tools/delete.ts#L14-L50","documentation":"Zod safeParse on the delete tool's arguments failed. DeleteToolSchema requires a string `path` and accepts an optional boolean `recursive`. The throw embeds parsed.error, a ZodError whose message lists each failed field and the expected shape. Wrapped by the server-level catch into an isError tool result.","triggerScenarios":"The MCP client omitted `path`, sent a non-string path (number/object/null), sent a non-boolean recursive, or sent an unparseable JSON arguments object. Also fires if the model emits an empty arguments object.","commonSituations":"A model forgetting the required path field; a client serializing path as a number (e.g. a port-like path '8080' coerced to number); schema drift where the client was built against an older DeleteToolSchema.","solutions":["Ensure the arguments object includes path as a string and, if present, recursive as a boolean.","Read parsed.error in the returned message — it names the offending field and the constraint that failed.","Cross-check the arguments against z.toJSONSchema(DeleteToolSchema) published in the ListTools response."],"exampleFix":"// before\nconst parsed = DeleteToolSchema.safeParse(args)\nif (!parsed.success) {\n  throw new Error(`Invalid arguments for delete: ${parsed.error}`)\n}\n\n// after — emit a structured, field-level error for the client\nif (!parsed.success) {\n  const issues = parsed.error.issues.map(i => `${i.path.join('.')}: ${i.message}`).join('; ')\n  throw new Error(`Invalid arguments for delete: ${issues}`)\n}","handlingStrategy":"validation","validationCode":"// Validate delete args on the client before dispatching.\nfunction isValidDeleteArgs(args: unknown): args is { path: string; recursive?: boolean } {\n  if (typeof args !== 'object' || args === null) return false\n  const a = args as any\n  return typeof a.path === 'string' && (a.recursive === undefined || typeof a.recursive === 'boolean')\n}","typeGuard":"function isDeleteArgs(a: unknown): a is { path: string; recursive?: boolean } {\n  return typeof a === 'object' && a !== null && typeof (a as any).path === 'string'\n    && ((a as any).recursive === undefined || typeof (a as any).recursive === 'boolean')\n}","tryCatchPattern":null,"preventionTips":["Always send path as a string; omit recursive unless deleting a non-empty directory.","Generate client types from z.toJSONSchema(DeleteToolSchema) to avoid shape drift.","Read parsed.error in the returned message — it names the failing field.","Run a local safeParse on the client before sending the request."],"tags":["zod","validation","mcp-tool","filesystem"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}