Skip to main content
Glama
shanksxz

GitHub Repository MCP Server

get-file-content

Retrieve specific file content from GitHub repositories by providing owner, repository name, and file path to access code, documentation, or configuration files.

Instructions

Get content of a specific file from a GitHub repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerYesGitHub repository owner/organization name
repoYesGitHub repository name
pathYesPath to the file in the repository

Implementation Reference

  • Handler function that fetches the content of a specific file from a GitHub repository using the getFileContent helper and returns it formatted as text content block or an error message.
    async ({ owner, repo, path }) => {
      try {
        const content = await getFileContent(owner, repo, path);
    
        if (!content) {
          return {
            content: [
              {
                type: "text",
                text: `Could not retrieve content for ${path} in ${owner}/${repo}`,
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: "text",
              text: `File: ${path}\n\n\`\`\`\n${content}\n\`\`\``,
            },
          ],
        };
      } catch (error) {
        console.error(`Error fetching file content for ${path}:`, error);
        return {
          content: [
            {
              type: "text",
              text: `Error fetching file content: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
    },
  • Input schema defined using Zod for the parameters: owner, repo, and path.
    {
      owner: z.string().describe("GitHub repository owner/organization name"),
      repo: z.string().describe("GitHub repository name"),
      path: z.string().describe("Path to the file in the repository"),
    },
  • src/index.ts:155-198 (registration)
    Registration of the 'get-file-content' tool on the MCP server using server.tool method, including name, description, input schema, and handler.
    server.tool(
      "get-file-content",
      "Get content of a specific file from a GitHub repository",
      {
        owner: z.string().describe("GitHub repository owner/organization name"),
        repo: z.string().describe("GitHub repository name"),
        path: z.string().describe("Path to the file in the repository"),
      },
      async ({ owner, repo, path }) => {
        try {
          const content = await getFileContent(owner, repo, path);
    
          if (!content) {
            return {
              content: [
                {
                  type: "text",
                  text: `Could not retrieve content for ${path} in ${owner}/${repo}`,
                },
              ],
            };
          }
    
          return {
            content: [
              {
                type: "text",
                text: `File: ${path}\n\n\`\`\`\n${content}\n\`\`\``,
              },
            ],
          };
        } catch (error) {
          console.error(`Error fetching file content for ${path}:`, error);
          return {
            content: [
              {
                type: "text",
                text: `Error fetching file content: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      },
    );
  • Helper function that retrieves the raw content of a file from a GitHub repository using the Octokit API, decoding base64 content to UTF-8 string.
    async function getFileContent(owner: string, repo: string, path: string): Promise<string | null> {
      try {
        const response = await octokit.repos.getContent({
          owner,
          repo,
          path,
        });
    
        if ('content' in response.data && 'encoding' in response.data) {
          if (response.data.encoding === 'base64') {
            return Buffer.from(response.data.content, 'base64').toString('utf-8');
          }
        }
    
        return null;
      } catch (error) {
        console.error(`Error getting file content for ${owner}/${repo}/${path}:`, error);
        return null;
      }
    }
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 tool retrieves file content but omits critical details: it doesn't specify whether this is a read-only operation (implied but not explicit), mention authentication requirements, rate limits, error handling for missing files, or the format of returned content. For a tool with zero annotation coverage, this is a significant gap in transparency.

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 purpose without any fluff or redundancy. It is appropriately sized and front-loaded, making it easy for an agent to parse quickly. Every word earns its place, contributing to clarity 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 complexity (a read operation with 3 required parameters) and the absence of both annotations and an output schema, the description is incomplete. It doesn't explain what the return value looks like (e.g., file content as text or binary), error conditions, or behavioral traits like authentication needs. For a tool with no structured data to rely on, the description should provide more comprehensive context to guide the agent effectively.

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, with clear documentation for 'owner', 'repo', and 'path' parameters. The description adds no additional semantic context beyond what the schema provides, such as examples or constraints on path formatting. According to the rules, when schema coverage is high (>80%), the baseline score is 3, which applies here as the description doesn't compensate with extra parameter insights.

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 content') and resource ('specific file from a GitHub repository'), making the tool's purpose immediately understandable. It distinguishes from sibling tools like 'get-repo-context' and 'get-repo-structure' by focusing on file content retrieval rather than repository metadata or structure. However, it doesn't explicitly mention the verb 'read' or specify that it's for a single file, which would make it a perfect 5.

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 its siblings. It doesn't mention alternatives like 'get-repo-context' for repository information or 'get-repo-structure' for directory listings, nor does it specify prerequisites such as needing a valid file path. This lack of context leaves the agent to infer usage scenarios without explicit 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/shanksxz/gh-mcp-server'

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