Skip to main content
Glama
ttpears

GitLab MCP Server

by ttpears

Browse Repository

browse_repository
Read-onlyIdempotent

Explore GitLab repository files and folders to navigate codebase structure, view directories, and examine project contents using branch, tag, or commit references.

Instructions

Browse repository files and folders - essential for exploring codebase structure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathYesFull path of the project (e.g., "group/project-name")
pathNoDirectory path to browse (empty for root)
refNoGit reference (branch, tag, or commit SHA)HEAD
userCredentialsNoYour GitLab credentials (optional - uses shared token if not provided)

Implementation Reference

  • Complete browse_repository tool definition including handler function that processes input, calls client.searchRepositoryFiles(), and formats the response with files and directories with web URLs
    const browseRepositoryTool: Tool = {
      name: 'browse_repository',
      title: 'Browse Repository',
      description: 'Browse repository files and folders - essential for exploring codebase structure',
      requiresAuth: false,
      requiresWrite: false,
      annotations: {
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
      },
      inputSchema: withUserAuth(z.object({
        projectPath: z.string().describe('Full path of the project (e.g., "group/project-name")'),
        path: z.string().default('').describe('Directory path to browse (empty for root)'),
        ref: z.string().default('HEAD').describe('Git reference (branch, tag, or commit SHA)'),
      })),
      handler: async (input, client, userConfig) => {
        const credentials = input.userCredentials ? validateUserConfig(input.userCredentials) : userConfig;
        const result = await client.searchRepositoryFiles(input.projectPath, input.path, input.ref, credentials);
        const projectWebUrl = result.project.webUrl;
        const refParam = input.ref || 'HEAD';
        
        const files = result.project.repository.tree.blobs.nodes.map((f: any) => ({
          ...f,
          webUrl: `${projectWebUrl}/-/blob/${refParam}/${f.path}`
        }));
        const directories = result.project.repository.tree.trees.nodes.map((d: any) => ({
          ...d,
          webUrl: `${projectWebUrl}/-/tree/${refParam}/${d.path}`
        }));
        
        return {
          project: input.projectPath,
          path: input.path,
          ref: refParam,
          files,
          directories
        };
      },
    };
  • Input schema definition using Zod with user authentication wrapper. Defines projectPath, path (directory), and ref (git reference) parameters with defaults and descriptions
    inputSchema: withUserAuth(z.object({
      projectPath: z.string().describe('Full path of the project (e.g., "group/project-name")'),
      path: z.string().default('').describe('Directory path to browse (empty for root)'),
      ref: z.string().default('HEAD').describe('Git reference (branch, tag, or commit SHA)'),
    })),
  • Client-side implementation that executes the GraphQL query to fetch repository tree structure. Queries project.repository.tree with blobs (files) and trees (directories), using path and ref parameters
    async searchRepositoryFiles(
      projectPath: string, 
      path: string, 
      ref?: string, 
      userConfig?: UserConfig
    ): Promise<any> {
      const query = gql`
        query searchRepositoryFiles($projectPath: ID!, $path: String, $ref: String) {
          project(fullPath: $projectPath) {
            webUrl
            repository {
              tree(path: $path, ref: $ref, recursive: true) {
                blobs {
                  nodes {
                    name
                    path
                    type
                    mode
                  }
                }
                trees {
                  nodes {
                    name
                    path
                    type
                  }
                }
              }
            }
          }
        }
      `;
      
      return this.query(query, { 
        projectPath, 
        path: path || "", 
        ref: ref || "HEAD" 
      }, userConfig);
    }
  • src/tools.ts:1324-1349 (registration)
    Tool registration - browseRepositoryTool is included in searchTools array (line 1334) which is then exported as part of the main tools array that gets registered with the MCP server
    export const searchTools: Tool[] = [
      globalSearchTool,
      searchProjectsTool,
      searchIssuesTool,
      searchMergeRequestsTool,
      getUserIssuesTool,
      getUserMergeRequestsTool,
      searchUsersTool,
      searchGroupsTool,
      searchLabelsTool,
      browseRepositoryTool,
      getFileContentTool,
      listGroupMembersTool,
    ];
    
    export const tools: Tool[] = [
      ...readOnlyTools,
      ...userAuthTools,
      ...writeTools,
      updateIssueTool,
      updateMergeRequestTool,
      resolvePathTool,
      getGroupProjectsTool,
      getTypeFieldsTool,
      ...searchTools,
    ];
  • src/index.ts:83-96 (registration)
    MCP server registration handler that lists all available tools including browse_repository. The tools array is imported and mapped to the MCP tool format with schemas converted to JSON Schema
    private setupToolHandlers(server: Server): void {
      server.setRequestHandler(ListToolsRequestSchema, async () => {
        return {
          tools: tools.map(tool => ({
            name: tool.name,
            ...(tool.title && { title: tool.title }),
            description: tool.description,
            inputSchema: toJsonSchema(tool.inputSchema),
            ...(tool.outputSchema && { outputSchema: toJsonSchema(tool.outputSchema) }),
            ...(tool.annotations && { annotations: tool.annotations }),
            ...(tool.icon && { icon: tool.icon }),
          })),
        };
      });
Behavior3/5

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

Annotations already declare readOnlyHint=true, idempotentHint=true, and destructiveHint=false, covering safety and idempotency. The description adds minimal behavioral context by implying it's for exploration, but doesn't disclose details like pagination, rate limits, or authentication requirements beyond what's in the schema. No contradiction with annotations.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core purpose ('browse repository files and folders') and adds value with the explanatory clause ('essential for exploring codebase structure'). There is no wasted text or redundancy.

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 the tool's moderate complexity (4 parameters, no output schema) and rich annotations, the description is adequate but incomplete. It lacks guidance on usage scenarios, output format, or error handling, which would help an agent use it effectively despite the good schema coverage.

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?

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds no parameter-specific semantics beyond the general 'browse repository files and folders' context. This meets the baseline of 3 when schema coverage is high.

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 with a specific verb ('browse') and resource ('repository files and folders'), and it adds context about exploring codebase structure. However, it doesn't explicitly differentiate from sibling tools like 'get_file_content' or 'resolve_path', which also involve repository exploration.

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. It mentions it's 'essential for exploring codebase structure,' but doesn't specify scenarios, prerequisites, or exclusions compared to siblings like 'get_file_content' (for file details) or 'search_gitlab' (for broader searches).

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

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