CherryHQ/cherry-studio · warning · Error

Invalid arguments for glob: ${parsed.error}

Error message

Invalid arguments for glob: ${parsed.error}

What it means

Zod safeParse on the glob tool's arguments failed. GlobToolSchema requires a string `pattern` and accepts an optional string `path`. parsed.error is a ZodError describing which field failed. Returned as an isError tool result by the server-level catch.

Source

Thrown at src/main/ai/mcp/servers/filesystem/tools/glob.ts:39

- Supports glob patterns like "**/*.js" or "src/**/*.ts"
- Returns matching absolute file paths sorted by modification time (newest first)
- Use this when you need to find files by name patterns
- Patterns without "/" (e.g., "*.txt") match files at ANY depth in the directory tree
- Patterns with "/" (e.g., "src/*.ts") match relative to the search path
- Pattern syntax: * (any chars), ** (any path), {a,b} (alternatives), ? (single char)
- Results are limited to 100 files
- The path parameter must resolve within the configured workspace root if specified
- If path is not specified, defaults to the base directory
- IMPORTANT: Omit the path field for the default directory (don't use "undefined" or "null")`,
  inputSchema: z.toJSONSchema(GlobToolSchema)
}

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

  const searchPath = parsed.data.path || baseDir
  const validPath = await validatePath(searchPath, baseDir)

  // Verify the search directory exists
  try {
    const stats = await fs.stat(validPath)
    if (!stats.isDirectory()) {
      throw new Error(`Path is not a directory: ${validPath}`)
    }
  } catch (error: unknown) {
    if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
      throw new Error(`Directory not found: ${validPath}`)
    }
    throw error
  }

View on GitHub (pinned to 726446b54c)

Solutions

  1. Provide pattern as a non-empty glob string (e.g. '**/*.ts').
  2. If passing path, ensure it is an absolute string resolving inside the workspace root.
  3. Read parsed.error to identify the failing field.

Example fix

// before
throw new Error(`Invalid arguments for glob: ${parsed.error}`)

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

Strategy: validation

Validate before calling

// Validate glob args on the client.
function isValidGlobArgs(a: unknown): a is { pattern: string; path?: string } {
  if (typeof a !== 'object' || a === null) return false
  const o = a as any
  return typeof o.pattern === 'string' && (o.path === undefined || typeof o.path === 'string')
}

Type guard

function isGlobArgs(a: unknown): a is { pattern: string; path?: string } {
  return typeof a === 'object' && a !== null && typeof (a as any).pattern === 'string'
}

Prevention

When it happens

Trigger: The arguments object omits pattern, sends pattern as a non-string, or sends path as a non-string. An empty-string pattern passes zod (the empty check happens later at error 314).

Common situations: A model calling glob with only a path and no pattern; a client sending pattern:null; schema drift between the advertised inputSchema and the client's expectations.

Related errors


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