{"record":{"id":"fe2992bb8265f737","repo":"CherryHQ/cherry-studio","slug":"invalid-arguments-for-ls-parsed-error","errorCode":null,"errorMessage":"Invalid arguments for ls: ${parsed.error}","messagePattern":"Invalid arguments for ls: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/main/ai/mcp/servers/filesystem/tools/ls.ts","lineNumber":34,"sourceCode":"  description: `Lists files and directories in a specified path.\n\n- Returns a tree-like structure with icons (📁 directories, 📄 files)\n- Shows the absolute directory path in the header\n- Entries are sorted alphabetically with directories first\n- Can list recursively with recursive=true (up to 5 levels deep)\n- Common directories (node_modules, dist, .git) are excluded\n- Hidden files (starting with .) are excluded except .env.example\n- Results are limited to 100 entries\n- The path parameter must resolve within the configured workspace root if specified\n- If path is not specified, defaults to the base directory`,\n  inputSchema: z.toJSONSchema(LsToolSchema)\n}\n\n// Handler implementation\nexport async function handleLsTool(args: unknown, baseDir: string) {\n  const parsed = LsToolSchema.safeParse(args)\n  if (!parsed.success) {\n    throw new Error(`Invalid arguments for ls: ${parsed.error}`)\n  }\n\n  const targetPath = parsed.data.path || baseDir\n  const validPath = await validatePath(targetPath, baseDir)\n  const recursive = parsed.data.recursive || false\n\n  interface TreeNode {\n    name: string\n    type: 'file' | 'directory'\n    children?: TreeNode[]\n  }\n\n  let fileCount = 0\n  let truncated = false\n\n  async function buildTree(dirPath: string, depth: number = 0): Promise<TreeNode[]> {\n    if (fileCount >= MAX_FILES_LIMIT) {\n      truncated = true","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/servers/filesystem/tools/ls.ts#L16-L52","documentation":"Zod safeParse on the ls tool's arguments failed. LsToolSchema accepts an optional string `path` and an optional boolean `recursive`; both are optional, so this fires only on type errors — a non-string path or a non-boolean recursive. parsed.error identifies the offending field. Returned as an isError tool result.","triggerScenarios":"The caller sends path as a number/object/null or recursive as a non-boolean (e.g. the string 'true'). Because both fields are optional, omitting them entirely does not trigger this error.","commonSituations":"A client serializing recursive:true as the string 'true'; a model passing a number where a path is expected; schema drift where the client thinks path is required and sends path:null.","solutions":["Send path as an absolute string (or omit it) and recursive as a boolean (or omit it).","Read parsed.error to find which field has the wrong type.","Ensure the client does not stringify booleans when serializing the arguments object."],"exampleFix":"// before\nthrow new Error(`Invalid arguments for ls: ${parsed.error}`)\n\n// after — structured issues\nif (!parsed.success) {\n  const issues = parsed.error.issues.map(i => `${i.path.join('.') || '(root)'}: ${i.message}`).join('; ')\n  throw new Error(`Invalid arguments for ls: ${issues}`)\n}","handlingStrategy":"validation","validationCode":"// Validate ls args on the client (both fields optional).\nfunction isValidLsArgs(a: unknown): a is { path?: string; recursive?: boolean } {\n  if (typeof a !== 'object' || a === null) return true // both optional\n  const o = a as any\n  return (o.path === undefined || typeof o.path === 'string')\n    && (o.recursive === undefined || typeof o.recursive === 'boolean')\n}","typeGuard":"function isLsArgs(a: unknown): a is { path?: string; recursive?: boolean } {\n  if (typeof a !== 'object' || a === null) return true\n  const o = a as any\n  return (o.path === undefined || typeof o.path === 'string')\n    && (o.recursive === undefined || typeof o.recursive === 'boolean')\n}","tryCatchPattern":null,"preventionTips":["Send path as a string (or omit) and recursive as a boolean (or omit).","Never stringify booleans when serializing arguments.","Generate client types from z.toJSONSchema(LsToolSchema).","Run safeParse on the client before dispatching."],"tags":["zod","validation","ls","mcp-tool","filesystem"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}