Skip to main content
Glama
piyushgIITian

GitHub Enterprise MCP Server

create-or-update-file

Create or update files in GitHub repositories using the GitHub Enterprise MCP Server to manage repository content through direct file operations.

Instructions

Create or update a single file in a GitHub repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branchYesBranch to create/update the file in
contentYesContent of the file
messageYesCommit message
ownerYesRepository owner (username or organization)
pathYesPath where to create/update the file
repoYesRepository name
shaNoSHA of the file being replaced (required when updating existing files)

Implementation Reference

  • The core handler function for the 'create-or-update-file' tool. Validates input with Zod schema, ensures the branch exists, and uses the GitHub API to create or update the file content.
    export async function createOrUpdateFile(args: unknown): Promise<any> { const { owner, repo, path, content, message, branch, sha } = CreateOrUpdateFileSchema.parse(args); const github = getGitHubApi(); return tryCatchAsync(async () => { // Check if branch exists, create it if it doesn't const branchExists = await github.branchExists(owner, repo, branch); if (!branchExists) { await github.createBranch(owner, repo, branch); } // Create or update the file const { data } = await github.getOctokit().repos.createOrUpdateFileContents({ owner, repo, path, message, content: utf8ToBase64(content), branch, sha, }); return { content: { name: data.content?.name, path: data.content?.path, sha: data.content?.sha, size: data.content?.size, url: data.content?.html_url, }, commit: { sha: data.commit.sha, url: data.commit.html_url, message: data.commit.message, author: data.commit.author, committer: data.commit.committer, }, }; }, 'Failed to create or update file'); }
  • Zod schema used for input validation in the createOrUpdateFile handler, extending OwnerRepoSchema.
    export const CreateOrUpdateFileSchema = OwnerRepoSchema.extend({ path: z.string().min(1, 'File path is required'), content: z.string().min(1, 'File content is required'), message: z.string().min(1, 'Commit message is required'), branch: z.string().min(1, 'Branch name is required'), sha: z.string().optional(), });
  • src/server.ts:388-425 (registration)
    Registration of the 'create-or-update-file' tool in the server's ListToolsRequestHandler, including the MCP input schema definition.
    { name: 'create-or-update-file', description: 'Create or update a single file in 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 where to create/update the file', }, content: { type: 'string', description: 'Content of the file', }, message: { type: 'string', description: 'Commit message', }, branch: { type: 'string', description: 'Branch to create/update the file in', }, sha: { type: 'string', description: 'SHA of the file being replaced (required when updating existing files)', }, }, required: ['owner', 'repo', 'path', 'content', 'message', 'branch'], additionalProperties: false, },
  • Dispatch to the createOrUpdateFile handler in the CallToolRequestHandler switch statement.
    case 'create-or-update-file': result = await createOrUpdateFile(parsedArgs); break;

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