Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

git_branch

Manage Git branches by listing existing ones, creating new branches, deleting unwanted branches, or renaming branches to organize your repository workflow.

Instructions

List, create, delete, or rename branches

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdNoRepository directory
actionNoBranch actionlist
nameNoBranch name (required for create/delete/rename)
newNameNoNew branch name (required for rename)
forceNoForce delete or creation
remoteNoList remote branches

Implementation Reference

  • The main handler function that implements the git_branch tool logic. It handles list, create, delete, and rename actions for git branches using the executeGitCommand helper.
    export async function gitBranch(args: z.infer<typeof gitBranchSchema>): Promise<ToolResponse> { switch (args.action) { case 'list': const remoteFlag = args.remote ? '-r' : '-a'; return executeGitCommand(`git branch ${remoteFlag}`, args.cwd); case 'create': if (!args.name) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Branch name required for create action' }, null, 2) }], isError: true }; } return executeGitCommand(`git branch ${args.name}`, args.cwd); case 'delete': if (!args.name) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Branch name required for delete action' }, null, 2) }], isError: true }; } const deleteFlag = args.force ? '-D' : '-d'; return executeGitCommand(`git branch ${deleteFlag} ${args.name}`, args.cwd); case 'rename': if (!args.name || !args.newName) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Both name and newName required for rename action' }, null, 2) }], isError: true }; } return executeGitCommand(`git branch -m ${args.name} ${args.newName}`, args.cwd); default: return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Invalid branch action' }, null, 2) }], isError: true }; } }
  • Zod schema used for input validation of the git_branch tool parameters.
    export const gitBranchSchema = z.object({ cwd: z.string().optional().describe('Repository directory'), action: z.enum(['list', 'create', 'delete', 'rename']).optional().default('list').describe('Branch action'), name: z.string().optional().describe('Branch name (required for create/delete/rename)'), newName: z.string().optional().describe('New branch name (required for rename)'), force: z.boolean().optional().default(false).describe('Force delete or creation'), remote: z.boolean().optional().default(false).describe('List remote branches') });
  • MCP tool registration definition in the gitTools array, including the tool name, description, and input schema advertised to clients.
    { name: 'git_branch', description: 'List, create, delete, or rename branches', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Repository directory' }, action: { type: 'string', enum: ['list', 'create', 'delete', 'rename'], default: 'list', description: 'Branch action' }, name: { type: 'string', description: 'Branch name (required for create/delete/rename)' }, newName: { type: 'string', description: 'New branch name (required for rename)' }, force: { type: 'boolean', default: false, description: 'Force delete or creation' }, remote: { type: 'boolean', default: false, description: 'List remote branches' } } } },
  • src/index.ts:377-379 (registration)
    Dispatch/registration logic in the main MCP server handler that routes calls to the git_branch tool by name, validates input, and invokes the handler.
    if (name === 'git_branch') { const validated = gitBranchSchema.parse(args); return await gitBranch(validated);
  • Shared helper function used by gitBranch (and all git tools) to execute git commands and format responses.
    async function executeGitCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024 // 10MB buffer }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }

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/ConnorBoetig-dev/mcp2'

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