Skip to main content
Glama

stash_pop

Apply and remove a Git stash from a specified repository path using the stash index. Part of the Git MCP Server, enabling enhanced Git operations for efficient repository management.

Instructions

Apply and remove a stash

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexNoStash index
pathNoPath to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)

Implementation Reference

  • The primary handler function that executes the 'git stash pop' command, validates the repository, handles caching invalidation, and formats the response.
    static async stashPop({ path, index = 0 }: StashOptions, context: GitToolContext): Promise<GitToolResult> {
      const resolvedPath = this.getPath({ path });
      return await this.executeOperation(
        context.operation,
        resolvedPath,
        async () => {
          const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath);
          const result = await CommandExecutor.executeGitCommand(
            `stash pop stash@{${index}}`,
            context.operation,
            repoPath
          );
    
          return {
            content: [{
              type: 'text',
              text: `Stash applied successfully\n${CommandExecutor.formatOutput(result)}`
            }]
          };
        },
        {
          command: 'stash_pop',
          invalidateCache: true, // Invalidate stash and status caches
          stateType: RepoStateType.STASH
        }
      );
    }
  • The input schema definition for the stash_pop tool, registered in the ListTools handler, defining parameters path and index.
    {
      name: 'stash_pop',
      description: 'Apply and remove a stash',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: `Path to repository. ${PATH_DESCRIPTION}`,
          },
          index: {
            type: 'number',
            description: 'Stash index',
            default: 0,
          },
        },
        required: [],
      },
    },
  • The switch case in the CallToolRequest handler that validates arguments using isStashOptions and dispatches to GitOperations.stashPop.
    case 'stash_pop': {
      const validArgs = this.validateArguments(operation, args, isStashOptions);
      return await GitOperations.stashPop(validArgs, context);
    }
  • TypeScript interface StashOptions defining the input parameters for stash operations, used for type checking and validation.
    export interface StashOptions extends GitOptions, BasePathOptions {
      message?: string;
      index?: number;
      includeUntracked?: boolean;  // Include untracked files
      keepIndex?: boolean;  // Keep staged changes
      all?: boolean;  // Include ignored files
    }
  • Type guard function isStashOptions used to validate input arguments before calling the handler.
    export function isStashOptions(obj: any): obj is StashOptions {
      return obj && validatePath(obj.path);
    }

Tool Definition Quality

Score is being calculated. Check back soon.

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