Back to MCP directory
publicPublicdnsLocal runtime

Source Tree Generator

一个生成目录文件树结构的MCP服务器,支持.gitignore规则过滤

article

README

🚀 MCP 源代码树服务器

MCP 源代码树服务器可根据指定目录下的文件生成文件树,同时会自动排除以 . 开头的目录以及 .gitignore 文件中指定的文件或目录。集成 Claude 后,能让你快速确认项目结构,精准定位需要编辑的文件。

Source Tree Server MCP 服务器

🚀 快速开始

MCP 源代码树服务器能为你提供指定目录的文件树,并以 JSON 格式呈现,同时依据 .gitignore 规则排除特定文件和目录。集成 Claude 后,可助力你快速掌握项目结构。

✨ 主要特性

  • 文件树生成:获取指定目录下的文件树,并以 JSON 格式返回。
  • 文件过滤:依据 .gitignore 中的条件,自动排除指定的文件和目录。
  • 层次结构展示:采用层次结构式的 JSON 表示目录结构,清晰明了。

📦 安装指南

先决条件

  • Python 3.10 及以上版本。
  • 已安装 uv。

安装步骤

# 安装uv
$ curl -LsSf https://astral.sh/uv/install.sh | sh

$ cd /path/to/mcp-src-tree
# 安装依赖库
$ uv sync

📚 详细文档

在Claude Desktop中的配置

claude_desktop_config.json 中添加以下配置:

{
    "mcpServers": {
        "src-tree": {
            "command": "uv",
            "args": [
                "--directory",
                "/path/to/mcp-src-tree",  # 替换为你的项目目录的绝对路径
                "run",
                "tree.py"
            ]
        }
    }
}

💻 使用示例

基础用法

指示时请指定 src 的上层根目录。假设 .gitignore 文件存在于根目录下,且包含以下内容:

__pycache__
node_modules/
*.log

当用户指示“请确认/GitHub/xxx/ 的源代码树”时,Claude 会响应如下:

是的,请让我确认一下源代码树。
我已经确认了项目的结构,以下是其构成:
src/
└── xxxx/
    ├── __init__.py
    ├── converter.py
    ├── html_converter.py
    ├── image_processor.py
    ├── toc_analyzer.py
    └── utils.py

通过上述操作,Claude 可以快速了解项目结构。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client