googleapis/mcp-toolbox · error

error finding YAML files in %q: %w

Error message

error finding YAML files in %q: %w

What it means

GetPathsFromConfigFolder uses filepath.Glob to discover *.yaml files in the configured tools config directory. If Glob itself fails (it only fails on malformed patterns, e.g. ErrBadPattern), the function wraps the error and returns no paths. This is a wrapper around Go's standard library glob matching, not a 'no files found' condition.

Source

Thrown at cmd/internal/config.go:549

	return configs[0], nil
}

// GetPathsFromConfigFolder loads all YAML files from a directory and merges them
func GetPathsFromConfigFolder(ctx context.Context, folderPath string) ([]string, error) {
	// Check if directory exists
	info, err := os.Stat(folderPath)
	if err != nil {
		return nil, fmt.Errorf("unable to access config folder at %q: %w", folderPath, err)
	}
	if !info.IsDir() {
		return nil, fmt.Errorf("path %q is not a directory", folderPath)
	}

	// Find all YAML files in the directory
	pattern := filepath.Join(folderPath, "*.yaml")
	yamlFiles, err := filepath.Glob(pattern)
	if err != nil {
		return nil, fmt.Errorf("error finding YAML files in %q: %w", folderPath, err)
	}

	// Also find .yml files
	ymlPattern := filepath.Join(folderPath, "*.yml")
	ymlFiles, err := filepath.Glob(ymlPattern)
	if err != nil {
		return nil, fmt.Errorf("error finding YML files in %q: %w", folderPath, err)
	}

	// Combine both file lists
	allFiles := append(yamlFiles, ymlFiles...)
	return allFiles, nil
}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Check the folderPath string for glob metacharacters ([, ], *, ?) and escape them with filepath.Escape or by fixing the path
  2. Verify the path passed to --prebuilt/--tools-file config flags is a plain directory path, not a partial glob
  3. Use filepath.Match error output (errors.Is(err, filepath.ErrBadPattern)) to confirm the pattern is malformed
  4. Update the toolbox binary if the directory name is legitimate and the pattern joining is at fault

Example fix

// before
folderPath := "configs/[drafts" // unbalanced bracket -> ErrBadPattern
paths, err := GetPathsFromConfigFolder(ctx, folderPath)
// after
folderPath := filepath.Escape("configs/[drafts")
paths, err := GetPathsFromConfigFolder(ctx, folderPath)
Defensive patterns

Strategy: validation

Validate before calling

for _, c := range folderPath {
    if c == '[' || c == ']' {
        return nil, fmt.Errorf("config folder path %q contains glob metacharacters", folderPath)
    }
}
paths, err := GetPathsFromConfigFolder(ctx, folderPath)

Type guard

func badGlobPath(p string) bool {
    _, err := filepath.Match(p, "")
    return errors.Is(err, filepath.ErrBadPattern)
}

Prevention

When it happens

Trigger: Calling GetPathsFromConfigFolder (via GetCustomConfigFiles) where filepath.Glob(filepath.Join(folderPath, "*.yaml")) returns a non-nil err — practically only when the joined pattern is malformed (e.g. folderPath contains an invalid glob escape like an unbalanced '[').

Common situations: A config folder path set via --tools-file/--prebuilt flags or env var containing glob metacharacters (brackets from oddly named directories), or programmatically constructed paths with unescaped pattern characters.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/30e909018717d7c2. Report an issue: GitHub.