Skip to main content
Glama
utils.py1.36 kB
import os from pathlib import Path # 强制过滤的黑名单 IGNORED_DIRS = { ".git", ".svn", ".hg", ".idea", ".vscode", ".venv", "venv", "env", "node_modules", "__pycache__", "dist", "build", "target", "bin", "obj" } IGNORED_FILES = { ".DS_Store", "Thumbs.db" } IGNORED_EXTENSIONS = { ".pyc", ".pyo", ".pyd", ".so", ".dll", ".dylib", ".exe", ".class" } def generate_tree(root_path: Path) -> str: """Generates a visual file tree string, filtering out noise.""" output = [] # Walk the directory for dirpath, dirnames, filenames in os.walk(root_path): # 1. In-place filtering of directories to prevent recursion into ignored dirs dirnames[:] = [d for d in dirnames if d not in IGNORED_DIRS and not d.startswith(".")] rel_path = Path(dirpath).relative_to(root_path) if rel_path == Path("."): level = 0 else: level = len(rel_path.parts) indent = " " * (level - 1) output.append(f"{indent}- {rel_path.name}/") sub_indent = " " * level for f in sorted(filenames): if f in IGNORED_FILES or f.startswith("."): continue if any(f.endswith(ext) for ext in IGNORED_EXTENSIONS): continue output.append(f"{sub_indent}- {f}") return "\n".join(output)

Implementation Reference

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/leezhuuuuu/skills-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server