Skip to main content
Glama

get_file_contents

Retrieve the contents of a file or directory from a GitHub repository by specifying the owner, repository name, and path. Access specific branches for precise file operations.

Instructions

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

Input Schema

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

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "branch": { "description": "Branch to get contents from", "type": "string" }, "owner": { "description": "Repository owner (username or organization)", "type": "string" }, "path": { "description": "Path to the file or directory", "type": "string" }, "repo": { "description": "Repository name", "type": "string" } }, "required": [ "owner", "repo", "path" ], "type": "object" }

Implementation Reference

  • The core handler function that fetches the file or directory contents from the GitHub API, parses the response, and decodes base64 content for files.
    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:84-87 (registration)
    Tool registration in the list of tools returned by ListToolsRequestHandler, including name, description, and input schema.
    name: "get_file_contents", description: "Get the contents of a file or directory from a GitHub repository", inputSchema: zodToJsonSchema(files.GetFileContentsSchema), },
  • index.ts:210-221 (registration)
    Dispatch handler in the CallToolRequestHandler switch statement that parses arguments and calls the getFileContents function.
    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) }], }; }

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/PhialsBasement/mcp-github-server-plus'

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