Skip to main content
Glama
ttpears

GitLab MCP Server

by ttpears

File Content

get_file_content
Read-onlyIdempotent

Retrieve file content from GitLab repositories to analyze code, review configurations, or extract data for development workflows.

Instructions

Get the content of a specific file from a GitLab repository - crucial for code analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathYesFull path of the project (e.g., "group/project-name")
filePathYesPath to the file within the repository (e.g., "src/main.js")
refNoGit reference (branch, tag, or commit SHA)HEAD
userCredentialsNoYour GitLab credentials (optional - uses shared token if not provided)

Implementation Reference

  • Tool definition for get_file_content including input schema (projectPath, filePath, ref), annotations, and handler that calls client.getFileContent and returns file metadata with content
    const getFileContentTool: Tool = {
      name: 'get_file_content',
      title: 'File Content',
      description: 'Get the content of a specific file from a GitLab repository - crucial for code analysis',
      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")'),
        filePath: z.string().describe('Path to the file within the repository (e.g., "src/main.js")'),
        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.getFileContent(input.projectPath, input.filePath, input.ref, credentials);
    
        if (result.project.repository.blobs.nodes.length === 0) {
          throw new Error(`File not found: ${input.filePath} in ${input.projectPath} at ${input.ref}`);
        }
    
        const file = result.project.repository.blobs.nodes[0];
        const projectWebUrl = result.project.webUrl;
        const refParam = input.ref || 'HEAD';
        const fileWebUrl = `${projectWebUrl}/-/blob/${refParam}/${file.path}`;
        
        return {
          project: input.projectPath,
          path: file.path,
          name: file.name,
          size: file.size,
          content: file.rawBlob,
          webUrl: fileWebUrl,
          ref: refParam,
          isLFS: !!file.lfsOid
        };
      },
    };
  • Client implementation that executes GraphQL query to fetch file content from GitLab repository using blobs API, returning file metadata including rawBlob content, size, and LFS information
    async getFileContent(
      projectPath: string, 
      filePath: string, 
      ref?: string, 
      userConfig?: UserConfig
    ): Promise<any> {
      const query = gql`
        query getFileContent($projectPath: ID!, $path: String!, $ref: String) {
          project(fullPath: $projectPath) {
            webUrl
            repository {
              blobs(paths: [$path], ref: $ref) {
                nodes {
                  name
                  path
                  rawBlob
                  size
                  lfsOid
                }
              }
            }
          }
        }
      `;
      
      return this.query(query, { 
        projectPath, 
        path: filePath, 
        ref: ref || "HEAD" 
      }, userConfig);
    }
  • Input schema definition using Zod validation for get_file_content tool, specifying projectPath (required), filePath (required), and ref (defaults to 'HEAD') parameters
    inputSchema: withUserAuth(z.object({
      projectPath: z.string().describe('Full path of the project (e.g., "group/project-name")'),
      filePath: z.string().describe('Path to the file within the repository (e.g., "src/main.js")'),
      ref: z.string().default('HEAD').describe('Git reference (branch, tag, or commit SHA)'),
    })),
  • src/tools.ts:1324-1337 (registration)
    Tool registration - getFileContentTool is exported as part of searchTools array which is then included in the main tools array for MCP registration
    export const searchTools: Tool[] = [
      globalSearchTool,
      searchProjectsTool,
      searchIssuesTool,
      searchMergeRequestsTool,
      getUserIssuesTool,
      getUserMergeRequestsTool,
      searchUsersTool,
      searchGroupsTool,
      searchLabelsTool,
      browseRepositoryTool,
      getFileContentTool,
      listGroupMembersTool,
    ];
  • src/index.ts:84-96 (registration)
    MCP tool registration handler that maps all tools from the tools array (including get_file_content) to MCP protocol format, exposing them to MCP clients through ListToolsRequest
    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 }),
        })),
      };
    });
Behavior4/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 valuable context about the tool's purpose ('crucial for code analysis'), which helps the agent understand its behavioral role beyond the annotations. No contradictions 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 and adds a brief contextual note. Every word earns its place with no redundancy or unnecessary elaboration.

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

Completeness4/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, 2 required), rich annotations, and 100% schema coverage, the description provides adequate context. However, without an output schema, it doesn't explain return values (e.g., file content format), leaving a minor gap in completeness.

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%, with all parameters well-documented in the schema itself. The description doesn't add any additional parameter semantics beyond what's already in the schema, so it meets the baseline of 3 for high coverage without extra value.

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

Purpose5/5

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

The description clearly states the action ('Get the content') and resource ('a specific file from a GitLab repository'), with the additional context 'crucial for code analysis' that distinguishes it from other file-related operations like browsing or searching. It's specific and immediately tells what the tool does.

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

Usage Guidelines3/5

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

The description implies usage for 'code analysis' but doesn't explicitly state when to use this tool versus alternatives like 'browse_repository' or 'resolve_path'. No guidance on prerequisites or exclusions is provided, leaving usage context somewhat vague.

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