Skip to main content
Glama
piyushgIITian

GitHub Enterprise MCP Server

get-file-contents

Retrieve file or directory contents from GitHub repositories using owner, repo, and path parameters to access code and project files.

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

  • The core handler function that implements the 'get-file-contents' tool logic. It validates input using GetFileContentsSchema, fetches content using GitHub API, handles files, directories, and other types, and decodes base64 content.
    export async function getFileContents(args: unknown): Promise<any> {
      const { owner, repo, path, branch } = GetFileContentsSchema.parse(args);
      const github = getGitHubApi();
    
      return tryCatchAsync(async () => {
        const { data } = await github.getOctokit().repos.getContent({
          owner,
          repo,
          path,
          ref: branch,
        });
    
        // Handle directory listing
        if (Array.isArray(data)) {
          return data.map((item) => ({
            name: item.name,
            path: item.path,
            sha: item.sha,
            size: item.size,
            type: item.type,
            url: item.html_url,
            download_url: item.download_url,
          }));
        }
    
        // Handle file content
        if (data.type === 'file') {
          return {
            name: data.name,
            path: data.path,
            sha: data.sha,
            size: data.size,
            type: data.type,
            url: data.html_url,
            content: data.content ? base64ToUtf8(data.content) : null,
            encoding: data.encoding,
          };
        }
    
        // Handle submodule or symlink
        return {
          name: data.name,
          path: data.path,
          sha: data.sha,
          size: data.size,
          type: data.type,
          url: data.html_url,
        };
      }, 'Failed to get file contents');
    }
  • Zod schema used for input validation inside the handler function. Extends OwnerRepoSchema with path (required) and optional branch.
    export const GetFileContentsSchema = OwnerRepoSchema.extend({
      path: z.string().min(1, 'File path is required'),
      branch: z.string().optional(),
    });
  • src/server.ts:471-497 (registration)
    Tool registration in the ListTools response, including name, description, and input schema definition.
    {
      name: 'get-file-contents',
      description: 'Get the contents of a file or directory from a GitHub repository',
      inputSchema: {
        type: 'object',
        properties: {
          owner: {
            type: 'string',
            description: 'Repository owner (username or organization)',
          },
          repo: {
            type: 'string',
            description: 'Repository name',
          },
          path: {
            type: 'string',
            description: 'Path to the file or directory',
          },
          branch: {
            type: 'string',
            description: 'Branch to get contents from',
          },
        },
        required: ['owner', 'repo', 'path'],
        additionalProperties: false,
      },
    },
  • Dispatch case in the CallToolRequest handler switch statement that invokes the getFileContents function.
    case 'get-file-contents':
      result = await getFileContents(parsedArgs);
      break;
  • Import statement that brings the getFileContents handler into the server module.
    import {
      createOrUpdateFile,
      pushFiles,
      getFileContents,
      forkRepository,
      getPullRequestFiles,
    } from './tools/files.js';
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 does not cover critical aspects like authentication needs, rate limits, error handling, or whether it returns raw content, metadata, or both. This leaves significant gaps for an agent to understand operational traits.

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 directly states the tool's function without unnecessary words. It is front-loaded and wastes no space, making it easy to parse quickly.

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 lack of annotations and output schema, the description is incomplete. It does not explain return values (e.g., file content vs. directory listing), error conditions, or behavioral constraints like GitHub API limits. For a tool with 4 parameters and no structured output info, more context is needed.

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?

The input schema has 100% description coverage, clearly documenting all four parameters (owner, repo, path, branch). The description adds no additional semantic details beyond what the schema provides, such as path format examples or branch defaults. 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 ('a file or directory from a GitHub repository'), making the purpose understandable. However, it does not explicitly differentiate from sibling tools like 'search-code' or 'get-pull-request-files', which might also retrieve content in different contexts, so it misses full sibling distinction.

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, such as 'search-code' for broader searches or 'get-pull-request-files' for PR-specific content. It lacks explicit context, prerequisites, or exclusions, offering minimal usage direction.

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

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/piyushgIITian/github-enterprice-mcp'

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