Skip to main content
Glama

gitlab_get_repository_file

Retrieve the content of a specific file from a GitLab repository. Provide the project ID, file path, and branch/tag/commit reference to access file data directly.

Instructions

Get content of a file in a repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath of the file in the repository
project_idYesThe ID or URL-encoded path of the project
refNoThe name of branch, tag or commit

Implementation Reference

  • The main handler function for 'gitlab_get_repository_file' that fetches the content of a specific file from a GitLab repository using the GitLab API.
    export const getRepositoryFile: ToolHandler = async (params, context) => {
      const { project_id, file_path, ref } = params.arguments || {};
      if (!project_id || !file_path) {
        throw new McpError(ErrorCode.InvalidParams, 'project_id and file_path are required');
      }
      
      const response = await context.axiosInstance.get(
        `/projects/${encodeURIComponent(String(project_id))}/repository/files/${encodeURIComponent(String(file_path))}`,
        { params: { ref: ref || 'main' } }
      );
      return formatResponse(response.data);
    };
  • The input schema definition for the 'gitlab_get_repository_file' tool, specifying parameters like project_id, file_path, and optional ref.
      name: 'gitlab_get_repository_file',
      description: 'Get content of a file in a repository',
      inputSchema: {
        type: 'object',
        properties: {
          project_id: {
            type: 'string',
            description: 'The ID or URL-encoded path of the project'
          },
          file_path: {
            type: 'string',
            description: 'Path of the file in the repository'
          },
          ref: {
            type: 'string',
            description: 'The name of branch, tag or commit'
          }
        },
        required: ['project_id', 'file_path']
      }
    },
  • Registration of the 'gitlab_get_repository_file' tool mapping to the repoHandlers.getRepositoryFile handler function.
    gitlab_get_repository_file: repoHandlers.getRepositoryFile,

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

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