Skip to main content
Glama

checkout

Switch branches or restore working tree files in a Git repository by specifying a branch name, commit hash, or file path. Use with the Git MCP Server for enhanced Git operations.

Instructions

Switch branches or restore working tree files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNoPath to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)
targetYesBranch name, commit hash, or file path

Implementation Reference

  • Registers the 'checkout' MCP tool with name, description, and JSON input schema defining 'path' (optional) and 'target' (required).
    {
      name: 'checkout',
      description: 'Switch branches or restore working tree files',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: `Path to repository. ${PATH_DESCRIPTION}`,
          },
          target: {
            type: 'string',
            description: 'Branch name, commit hash, or file path',
          },
        },
        required: ['target'],
      },
  • Core handler function that executes 'git checkout {target}' after validating the repository path and ensuring a clean working tree. Returns formatted success message with output.
    static async checkout({ path, target }: CheckoutOptions, context: GitToolContext): Promise<GitToolResult> {
      const resolvedPath = this.getPath({ path });
      return await this.executeOperation(
        context.operation,
        resolvedPath,
        async () => {
          const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath);
          await RepositoryValidator.ensureClean(repoPath, context.operation);
          
          const result = await CommandExecutor.executeGitCommand(
            `checkout ${target}`,
            context.operation,
            repoPath
          );
    
          return {
            content: [{
              type: 'text',
              text: `Switched to '${target}' successfully\n${CommandExecutor.formatOutput(result)}`
            }]
          };
        },
        {
          command: 'checkout',
          invalidateCache: true, // Invalidate branch and status caches
          stateType: RepoStateType.BRANCH
        }
      );
  • TypeScript interface defining input parameters for checkout: optional path and required target.
    export interface CheckoutOptions extends GitOptions, BasePathOptions {
      target: string;
    }
  • Type guard function to validate if arguments match CheckoutOptions.
    export function isCheckoutOptions(obj: any): obj is CheckoutOptions {
      return obj && 
        validatePath(obj.path) && 
        typeof obj.target === 'string';
    }
  • Dispatch handler in MCP tool executor that validates arguments and delegates to GitOperations.checkout.
    case 'checkout': {
      const validArgs = this.validateArguments(operation, args, isCheckoutOptions);
      return await GitOperations.checkout(validArgs, context);
    }
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. It mentions the action ('switch' and 'restore') but doesn't clarify critical aspects like whether this is a destructive operation, what permissions are needed, how errors are handled, or what the output looks like. For a tool that modifies repository state, this is a significant gap.

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 extremely concise with a single, clear phrase that front-loads the core functionality. Every word earns its place, avoiding redundancy or unnecessary elaboration, 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 Git checkout operation (which can change branch state or overwrite files), the description is insufficient. With no annotations and no output schema, it fails to address safety concerns, error conditions, or return values. For a tool with potential destructive effects, more context is needed to ensure correct usage.

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 input schema fully documents both parameters ('path' and 'target'). The description adds no additional semantic context beyond what's in the schema, such as examples of valid 'target' values or interactions between parameters. This meets the baseline for high schema coverage.

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 branches' and 'restore working tree files'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'branch_create' or 'stash_pop' that might 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 like 'branch_create' for creating branches or 'stash_pop' for restoring files. It lacks context about prerequisites, typical scenarios, or exclusions, leaving the agent to infer usage from the purpose 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/Sheshiyer/git-mcp-v2'

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