list_repository_tree
Browse and list files and directories in a GitLab repository to explore project structure, with options for specific paths, branches, and recursive viewing.
Instructions
瀏覽 Repository 檔案結構
Args: project_id: 專案 ID 或路徑 path: 目錄路徑(預設為根目錄) ref: 分支或標籤(預設為預設分支) recursive: 是否遞迴列出子目錄
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| path | No | ||
| ref | No | ||
| recursive | No |
Implementation Reference
- src/gitlab_mcp/server.py:931-960 (handler)The MCP tool registration and handler function for `list_repository_tree`.
@mcp.tool() def list_repository_tree(project_id: int | str, path: str = "", ref: str = None, recursive: bool = False) -> str: """瀏覽 Repository 檔案結構 Args: project_id: 專案 ID 或路徑 path: 目錄路徑(預設為根目錄) ref: 分支或標籤(預設為預設分支) recursive: 是否遞迴列出子目錄 """ try: client = get_client() items = client.list_repository_tree(project_id, path=path, ref=ref, recursive=recursive, per_page=100) if not items: return "此路徑下沒有檔案" path_display = path or "/" lines = [f"Repository 檔案結構({path_display}):\n"] # 排序:目錄在前,檔案在後 dirs = [i for i in items if i.get("type") == "tree"] files = [i for i in items if i.get("type") == "blob"] for d in dirs: lines.append(f"📁 {d['name']}/") for f in files: lines.append(f"📄 {f['name']}") - src/gitlab_mcp/gitlab_client.py:424-442 (handler)The actual GitLab API client implementation of `list_repository_tree` called by the MCP tool.
def list_repository_tree( self, project_id: int | str, path: str = "", ref: str = None, recursive: bool = False, page: int = 1, per_page: int = 20, ) -> list[dict]: """GET /projects/:id/repository/tree""" pid = self._resolve_project_id(project_id) params = {"page": page, "per_page": per_page} if path: params["path"] = path if ref: params["ref"] = ref if recursive: params["recursive"] = True return self._get_json(f"/projects/{pid}/repository/tree", params=params)