Skip to main content
Glama

git_stash

Manage Git repository stashes by saving, applying, popping, listing, or dropping changes. Specify the repository path, action, and optional message or index for precise control.

Instructions

Create or apply a stash.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionNoStash action (save, pop, apply, list, drop)save
indexNoStash index (for pop, apply, drop actions)
messageNoStash message (for save action)
repo_pathYesThe path to the local Git repository

Implementation Reference

  • The core handler function implementing git stash operations: save, pop, apply, list, drop using simpleGit library.
    export async function handleGitStash({ repo_path, action = "save", message = "", index = 0, }) { try { const git = simpleGit(repo_path); let result; switch (action) { case "save": result = await git.stash(["save", message]); return { content: [ { type: "text", text: JSON.stringify( { success: true, message: "Changes stashed successfully", stash_message: message, }, null, 2 ), }, ], }; case "pop": result = await git.stash(["pop", index.toString()]); return { content: [ { type: "text", text: JSON.stringify( { success: true, message: `Applied and dropped stash@{${index}}`, }, null, 2 ), }, ], }; case "apply": result = await git.stash(["apply", index.toString()]); return { content: [ { type: "text", text: JSON.stringify( { success: true, message: `Applied stash@{${index}}`, }, null, 2 ), }, ], }; case "list": result = await git.stash(["list"]); // Parse the stash list const stashList = result .trim() .split("\n") .filter((line) => line.trim() !== "") .map((line) => { const match = line.match(/stash@\{(\d+)\}: (.*)/); if (match) { return { index: parseInt(match[1]), description: match[2], }; } return null; }) .filter((item) => item !== null); return { content: [ { type: "text", text: JSON.stringify( { success: true, stashes: stashList, }, null, 2 ), }, ], }; case "drop": result = await git.stash(["drop", index.toString()]); return { content: [ { type: "text", text: JSON.stringify( { success: true, message: `Dropped stash@{${index}}`, }, null, 2 ), }, ], }; default: return { content: [ { type: "text", text: JSON.stringify( { error: `Unknown stash action: ${action}` }, null, 2 ), }, ], isError: true, }; } } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to perform stash operation: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
  • Defines the MCP tool schema for 'git_stash' including name, description, and input validation schema.
    { name: "git_stash", description: "Create or apply a stash.", inputSchema: { type: "object", properties: { repo_path: { type: "string", description: "The path to the local Git repository", }, action: { type: "string", description: "Stash action (save, pop, apply, list, drop)", default: "save", enum: ["save", "pop", "apply", "list", "drop"], }, message: { type: "string", description: "Stash message (for save action)", default: "", }, index: { type: "integer", description: "Stash index (for pop, apply, drop actions)", default: 0, }, }, required: ["repo_path"], }, },
  • src/server.js:914-914 (registration)
    Registers the 'git_stash' tool name to the handleGitStash handler function in the handlersMap.
    git_stash: handleGitStash,
  • src/server.js:25-25 (registration)
    Imports the handleGitStash handler from the handlers index.
    handleGitStash,
  • Imports the handleGitStash from stash-operations.js for aggregation in handlers index.
    import { handleGitStash } from "./stash-operations.js";

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/bsreeram08/git-commands-mcp'

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