Skip to main content
Glama

get_file_contents

Extract and retrieve contents of a specific file or directory from a GitHub repository by specifying the owner, repository name, path, and branch.

Instructions

Get the contents of a file or directory from a GitHub repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branchNoBranch to get contents from
ownerYesRepository owner (username or organization)
pathYesPath to the file or directory
repoYesRepository name

Implementation Reference

  • Core handler function that fetches file or directory contents from GitHub API, decodes base64 content for files, and returns parsed data.
    export async function getFileContents(
      owner: string,
      repo: string,
      path: string,
      branch?: string
    ) {
      let url = `https://api.github.com/repos/${owner}/${repo}/contents/${path}`;
      if (branch) {
        url += `?ref=${branch}`;
      }
    
      const response = await githubRequest(url);
      const data = GitHubContentSchema.parse(response);
    
      // If it's a file, decode the content
      if (!Array.isArray(data) && data.content) {
        data.content = Buffer.from(data.content, "base64").toString("utf8");
      }
    
      return data;
    }
  • Zod schema defining the input parameters for the get_file_contents tool: owner, repo, path, and optional branch.
    export const GetFileContentsSchema = z.object({
      owner: z.string().describe("Repository owner (username or organization)"),
      repo: z.string().describe("Repository name"),
      path: z.string().describe("Path to the file or directory"),
      branch: z.string().optional().describe("Branch to get contents from"),
    });
  • index.ts:86-88 (registration)
    Tool registration in the MCP server's listTools response, including name, description, and input schema reference.
    name: "get_file_contents",
    description: "Get the contents of a file or directory from a GitHub repository",
    inputSchema: zodToJsonSchema(files.GetFileContentsSchema),
  • MCP server dispatcher handler that parses arguments, invokes the getFileContents function, and formats the response.
    case "get_file_contents": {
      const args = files.GetFileContentsSchema.parse(request.params.arguments);
      const contents = await files.getFileContents(
        args.owner,
        args.repo,
        args.path,
        args.branch
      );
      return {
        content: [{ type: "text", text: JSON.stringify(contents, null, 2) }],
      };
    }
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 but offers minimal information. It mentions reading ('Get') but doesn't specify whether this requires authentication, rate limits, what happens with non-existent paths, or if it returns raw content vs. metadata. For a tool with 4 parameters and no annotation coverage, this is insufficient.

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 functionality without unnecessary words. Every part of the sentence ('Get the contents of a file or directory from a GitHub repository') directly contributes to understanding the tool's purpose.

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 complexity (4 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain return values (e.g., file content vs. directory listing), error conditions, or authentication requirements. For a read operation in a GitHub context with many sibling tools, more contextual information is needed to guide effective use.

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%, so the input schema already documents all parameters (owner, repo, path, branch) with clear descriptions. The description adds no additional meaning beyond implying the tool operates on GitHub repositories, which is redundant with the schema. This meets the baseline for high schema coverage.

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 resource ('file or directory from a GitHub repository'), making the purpose immediately understandable. However, it doesn't differentiate from similar sibling tools like 'search_code' or 'get_pull_request_files', which could also retrieve file-related information in different contexts.

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 like 'search_code' for broader searches or 'get_pull_request_files' for PR-specific content. It lacks context about prerequisites (e.g., needing repository access) or typical use cases, leaving the agent to infer usage from the tool name 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/tuanle96/mcp-github'

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