Skip to main content
Glama

get_file_contents

Retrieve file or directory contents from a GitLab project by specifying the file path, project ID, and reference. Simplify access to project data within the GitLab MCP server.

Instructions

Get the contents of a file or directory from a GitLab project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathNo
project_idNo
refNo

Implementation Reference

  • MCP tool handler for 'get_file_contents' that parses arguments using the schema and delegates to GitLabApi.getFileContents
    case "get_file_contents": {
      const args = GetFileContentsSchema.parse(request.params.arguments);
      const contents = await gitlabApi.getFileContents(args.project_id, args.file_path, args.ref);
      return { content: [{ type: "text", text: JSON.stringify(contents, null, 2) }] };
    }
  • Core implementation of getFileContents that fetches file from GitLab API, decodes base64 content, and returns structured data
    async getFileContents(
      projectId: string,
      filePath: string,
      ref: string
    ): Promise<GitLabContent> {
      const encodedPath = encodeURIComponent(filePath);
      const url = `${this.apiUrl}/projects/${encodeURIComponent(projectId)}/repository/files/${encodedPath}?ref=${encodeURIComponent(ref)}`;
    
      const response = await fetch(url, {
        headers: {
          "Authorization": `Bearer ${this.token}`
        }
      });
    
      if (!response.ok) {
        throw new McpError(
          ErrorCode.InternalError,
          `GitLab API error: ${response.statusText}`
        );
      }
    
      const data = GitLabContentSchema.parse(await response.json());
    
      if (!Array.isArray(data) && data.content) {
        data.content = Buffer.from(data.content, 'base64').toString('utf8');
      }
    
      return data;
    }
  • Zod schema defining input parameters for get_file_contents tool: project_id, file_path, ref
    export const GetFileContentsSchema = z.object({
      project_id: z.string(),
      file_path: z.string(),
      ref: z.string()
    });
  • src/index.ts:127-131 (registration)
    Tool registration in ALL_TOOLS array, including name, description, input schema, and read-only flag used by listTools handler
      name: "get_file_contents",
      description: "Get the contents of a file or directory from a GitLab project",
      inputSchema: createJsonSchema(GetFileContentsSchema),
      readOnly: true
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action but lacks critical details: it doesn't specify if this is a read-only operation, what happens with invalid inputs (e.g., non-existent file), whether it returns raw content or metadata, or any rate limits. This leaves significant gaps for safe and effective use.

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, direct sentence with zero wasted words. It front-loads the core purpose efficiently, making it easy to parse quickly without unnecessary elaboration.

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

Completeness2/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 (3 parameters, no annotations, no output schema), the description is incomplete. It omits essential context: expected output format (e.g., file content, directory listing, error handling), authentication requirements, and how parameters interact. This inadequately supports an agent in invoking the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions 'file or directory' and 'GitLab project', which loosely relates to 'file_path' and 'project_id', but with 0% schema description coverage, it fails to explain the meaning of 'ref' (e.g., branch, tag, commit) or provide any format examples (e.g., path syntax, project ID format). It adds minimal value beyond the bare parameter names.

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 action ('Get the contents') and target resource ('a file or directory from a GitLab project'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_group_wiki_page' or 'get_project_wiki_page', which also retrieve content but from different sources.

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 doesn't mention prerequisites (e.g., authentication, project access), or clarify use cases like retrieving code vs. documentation, leaving the agent to infer usage from context alone.

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

Related 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/yoda-digital/mcp-gitlab-server'

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