Skip to main content
Glama

create_or_update_file

Create or update a file in a GitHub repository by specifying the owner, repo, path, content, commit message, and branch. Includes optional SHA for updating existing files.

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

  • Core implementation of the create_or_update_file tool. Encodes content, fetches existing SHA if not provided, and makes a PUT request to GitHub API to create or update the file.
    export async function createOrUpdateFile(
      owner: string,
      repo: string,
      path: string,
      content: string,
      message: string,
      branch: string,
      sha?: string
    ) {
      const encodedContent = Buffer.from(content).toString("base64");
    
      let currentSha = sha;
      if (!currentSha) {
        try {
          const existingFile = await getFileContents(owner, repo, path, branch);
          if (!Array.isArray(existingFile)) {
            currentSha = existingFile.sha;
          }
        } catch (error) {
          console.error("Note: File does not exist in branch, will create new file");
        }
      }
    
      const url = `https://api.github.com/repos/${owner}/${repo}/contents/${path}`;
      const body = {
        message,
        content: encodedContent,
        branch,
        ...(currentSha ? { sha: currentSha } : {}),
      };
    
      const response = await githubRequest(url, {
        method: "PUT",
        body,
      });
    
      return GitHubCreateUpdateFileResponseSchema.parse(response);
    }
  • Zod schema defining the input parameters for the create_or_update_file tool.
    export const CreateOrUpdateFileSchema = z.object({
      owner: z.string().describe("Repository owner (username or organization)"),
      repo: z.string().describe("Repository name"),
      path: z.string().describe("Path where to create/update the file"),
      content: z.string().describe("Content of the file"),
      message: z.string().describe("Commit message"),
      branch: z.string().describe("Branch to create/update the file in"),
      sha: z.string().optional().describe("SHA of the file being replaced (required when updating existing files)"),
    });
  • index.ts:70-74 (registration)
    Tool registration in the MCP server's ListTools response, including name, description, and input schema reference.
    {
      name: "create_or_update_file",
      description: "Create or update a single file in a GitHub repository",
      inputSchema: zodToJsonSchema(files.CreateOrUpdateFileSchema),
    },
  • Dispatcher handler in the main CallToolRequestSchema switch statement that parses arguments and delegates to the core createOrUpdateFile function.
    case "create_or_update_file": {
      const args = files.CreateOrUpdateFileSchema.parse(request.params.arguments);
      const result = await files.createOrUpdateFile(
        args.owner,
        args.repo,
        args.path,
        args.content,
        args.message,
        args.branch,
        args.sha
      );
      return {
        content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action but doesn't mention critical details like required permissions (e.g., write access to the repo), whether it's idempotent, potential side effects (e.g., creating commits), or error handling. This is a significant gap for a mutation tool with zero annotation coverage.

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. It's front-loaded and wastes no words, making it easy for an agent 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 complexity of a file mutation tool with 7 parameters, no annotations, and no output schema, the description is inadequate. It lacks details on behavior, usage context, and output format, leaving the agent with insufficient information to use the tool effectively beyond basic parameter passing.

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 schema already documents all parameters thoroughly. The description adds no additional meaning beyond what's in the schema, such as explaining parameter interactions or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.

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 ('create or update') and resource ('a single file in a GitHub repository'), making the purpose unambiguous. However, it doesn't distinguish this tool from sibling tools like 'push_files' or 'get_file_contents', which might handle similar file operations, so it doesn't reach the highest score.

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. For example, it doesn't clarify if this is preferred over 'push_files' for single-file operations or when to use 'get_file_contents' for reading instead. This lack of context leaves the agent to guess based on tool names 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