get_file_content
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
| Name | Required | Description | Default |
|---|---|---|---|
| projectPath | Yes | Full path of the project (e.g., "group/project-name") | |
| filePath | Yes | Path to the file within the repository (e.g., "src/main.js") | |
| ref | No | Git reference (branch, tag, or commit SHA) | HEAD |
| userCredentials | No | Your GitLab credentials (optional - uses shared token if not provided) |
Implementation Reference
- src/tools.ts:696-736 (handler)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 }; }, }; - src/gitlab-client.ts:1176-1206 (handler)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); } - src/tools.ts:707-711 (schema)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 }), })), }; });