Skip to main content
Glama
piyushgIITian

GitHub Enterprise MCP Server

create-branch

Create a new branch in a GitHub repository by specifying the owner, repository name, and branch name, with optional source branch selection.

Instructions

Create a new branch in a GitHub repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branchYesName for the new branch
from_branchNoSource branch to create from (defaults to the repository's default branch)
ownerYesRepository owner
repoYesRepository name

Implementation Reference

  • The core handler function that executes the create-branch tool. Validates inputs using CreateBranchSchema, checks if the branch exists, determines the source branch, fetches its SHA, and creates the new branch ref via GitHub API.
    export async function createBranch(args: unknown): Promise<any> {
      const { owner, repo, branch, from_branch } = CreateBranchSchema.parse(args);
      const github = getGitHubApi();
    
      return tryCatchAsync(async () => {
        // Check if branch already exists
        try {
          await github.getOctokit().git.getRef({
            owner,
            repo,
            ref: `heads/${branch}`,
          });
          
          return {
            success: false,
            message: `Branch '${branch}' already exists in ${owner}/${repo}`,
          };
        } catch (error: any) {
          // If error is not 404 (not found), rethrow it
          if (error.status !== 404) {
            throw error;
          }
        }
    
        // Get the SHA of the latest commit on the source branch
        const sourceBranch = from_branch || await github.getDefaultBranch(owner, repo);
        const { data: refData } = await github.getOctokit().git.getRef({
          owner,
          repo,
          ref: `heads/${sourceBranch}`,
        });
    
        // Create a new branch from the source branch
        const { data } = await github.getOctokit().git.createRef({
          owner,
          repo,
          ref: `refs/heads/${branch}`,
          sha: refData.object.sha,
        });
    
        return {
          success: true,
          ref: data.ref,
          url: data.url,
          object: {
            sha: data.object.sha,
            type: data.object.type,
            url: data.object.url,
          },
          message: `Branch '${branch}' created from '${sourceBranch}' in ${owner}/${repo}`,
        };
      }, 'Failed to create branch');
    }
  • Zod validation schema used in the handler to parse and validate the input arguments for create-branch.
    export const CreateBranchSchema = OwnerRepoSchema.extend({
      branch: z.string().min(1, 'Branch name is required'),
      from_branch: z.string().optional(),
    });
  • Switch case in the MCP tool call handler that routes 'create-branch' invocations to the createBranch function.
    case 'create-branch':
      result = await createBranch(parsedArgs);
      break;
  • Input schema definition for the create-branch tool in the MCP server's listTools response.
    {
      name: 'create-branch',
      description: 'Create a new branch in a GitHub repository',
      inputSchema: {
        type: 'object',
        properties: {
          owner: {
            type: 'string',
            description: 'Repository owner',
          },
          repo: {
            type: 'string',
            description: 'Repository name',
          },
          branch: {
            type: 'string',
            description: 'Name for the new branch',
          },
          from_branch: {
            type: 'string',
            description: 'Source branch to create from (defaults to the repository\'s default branch)',
          },
        },
        required: ['owner', 'repo', 'branch'],
        additionalProperties: false,
      },
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action ('Create') but doesn't mention permissions required, whether it's idempotent, error conditions, or what happens if the branch already exists. This is inadequate 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 states the core purpose without any wasted words. It's appropriately sized and front-loaded, 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?

For a mutation tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the tool returns, error conditions, or behavioral nuances. Given the complexity of GitHub operations, more context about permissions, conflicts, or typical workflows would be 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?

Schema description coverage is 100%, so the schema already documents all 4 parameters thoroughly. The description adds no additional parameter information beyond what's in the schema, meeting the baseline expectation but not providing extra value.

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') and resource ('new branch in a GitHub repository'), making the purpose immediately understandable. However, it doesn't differentiate this tool from sibling tools like 'create-repository' or 'create-pull-request' beyond the obvious resource difference, missing explicit 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. There's no mention of prerequisites, when not to use it, or how it relates to sibling tools like 'update-pull-request-branch' or 'fork-repository', leaving usage context entirely implicit.

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