Skip to main content
Glama

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
NameRequiredDescriptionDefault
project_idYes
pathNo
refNo
recursiveNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • 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']}")
  • 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)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the tool 'browses' which implies read-only behavior, but doesn't explicitly state this. It doesn't disclose important behavioral traits like authentication requirements, rate limits, pagination behavior, error conditions, or what happens with invalid parameters. The parameter documentation is basic and doesn't explain behavioral implications.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with a clear purpose statement followed by parameter documentation. The structure is logical with purpose first, then parameters. While efficient, the parameter documentation could be more integrated with the purpose statement rather than appearing as a separate Args section.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that there's an output schema (which handles return values), no annotations, and 4 parameters with 0% schema coverage, the description provides basic purpose and parameter documentation but lacks important context. For a file browsing tool, it should explain what the output contains (files vs directories, metadata included), how recursion affects results, and error scenarios. The presence of an output schema reduces but doesn't eliminate the need for behavioral context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description provides basic parameter documentation in the Args section, explaining what each parameter represents (project ID, directory path, branch/tag reference, recursion flag). However, it doesn't add meaningful semantic context beyond what's obvious from parameter names - no format examples, constraints, or interaction effects. For 4 parameters with no schema descriptions, this provides minimal compensation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as '瀏覽 Repository 檔案結構' (browse repository file structure), which is a specific verb+resource combination. It distinguishes itself from siblings like list_branches or list_commits by focusing on the file tree structure rather than version control entities. However, it doesn't explicitly contrast with tools like get_commit which might also provide file information.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. While the purpose is clear, there's no mention of when this tool is appropriate compared to siblings like list_commits (which might show file changes) or get_commit (which might include file details). The description only documents parameters without usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/snowild/gitlab-mcp'

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