Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

git_checkout

Switch between Git branches, restore files to specific versions, or create new branches to manage your code changes and repository state.

Instructions

Switch branches or restore files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetYesBranch name, commit hash, or file path to checkout
cwdNoRepository directory
createBranchNoCreate new branch
forceNoForce checkout, discarding local changes

Implementation Reference

  • The main handler function that constructs and executes the 'git checkout' command using the shared executeGitCommand helper, handling branch creation and force flags.
    export async function gitCheckout(args: z.infer<typeof gitCheckoutSchema>): Promise<ToolResponse> {
      const createFlag = args.createBranch ? '-b' : '';
      const forceFlag = args.force ? '-f' : '';
      return executeGitCommand(`git checkout ${createFlag} ${forceFlag} ${args.target}`.trim(), args.cwd);
    }
  • Zod schema defining the input parameters and validation for the git_checkout tool.
    export const gitCheckoutSchema = z.object({
      target: z.string().describe('Branch name, commit hash, or file path to checkout'),
      cwd: z.string().optional().describe('Repository directory'),
      createBranch: z.boolean().optional().default(false).describe('Create new branch'),
      force: z.boolean().optional().default(false).describe('Force checkout, discarding local changes')
    });
  • MCP tool registration entry in gitTools array, defining the tool name, description, and JSON input schema for protocol listing.
    {
      name: 'git_checkout',
      description: 'Switch branches or restore files',
      inputSchema: {
        type: 'object',
        properties: {
          target: { type: 'string', description: 'Branch name, commit hash, or file path to checkout' },
          cwd: { type: 'string', description: 'Repository directory' },
          createBranch: { type: 'boolean', default: false, description: 'Create new branch' },
          force: { type: 'boolean', default: false, description: 'Force checkout, discarding local changes' }
        },
        required: ['target']
      }
    },
  • src/index.ts:381-384 (registration)
    Server request handler dispatcher that matches tool name 'git_checkout', validates arguments, and invokes the gitCheckout handler.
    if (name === 'git_checkout') {
      const validated = gitCheckoutSchema.parse(args);
      return await gitCheckout(validated);
    }
  • Shared helper utility that executes git shell commands asynchronously, handles output/error formatting, and returns standardized ToolResponse.
    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
        };
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'switch branches or restore files' implies mutation, it doesn't address critical behaviors like: whether this discards uncommitted changes by default, requires a clean working directory, creates new branches only with specific parameters, or has side effects on the repository state.

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 perfectly concise at just 4 words, front-loading the core functionality with zero wasted words. Every word earns its place by communicating essential information about the tool's purpose.

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 Git operation tool with 4 parameters, no annotations, and no output schema, the description is insufficient. It doesn't address the tool's complexity, potential destructive behaviors, error conditions, or what happens after execution. Users need more context about this being a fundamental Git command with significant repository implications.

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 fully documents all parameters. The description doesn't add any parameter semantics beyond what's in the schema - it doesn't explain how 'target' interprets different inputs, when 'createBranch' should be used, or the implications of 'force'. Baseline 3 is appropriate when schema does all the work.

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 tool's purpose with specific verbs ('switch', 'restore') and resources ('branches', 'files'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling git tools like 'git_branch' or 'git_reset', which could also involve branch or file operations.

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. With many sibling git tools available (e.g., git_branch, git_reset, git_revert), there's no indication of when checkout is appropriate versus other branching or file restoration methods.

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

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