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
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path of the file in the repository | |
| project_id | Yes | The ID or URL-encoded path of the project | |
| ref | No | The 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); };
- src/utils/tools-data.ts:222-242 (schema)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'] } },
- src/utils/tool-registry.ts:34-34 (registration)Registration of the 'gitlab_get_repository_file' tool mapping to the repoHandlers.getRepositoryFile handler function.gitlab_get_repository_file: repoHandlers.getRepositoryFile,