Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

git_stash

Save uncommitted changes temporarily to switch branches or tasks, then restore them later when needed. Manage stashed changes with push, pop, list, apply, drop, and clear operations.

Instructions

Stash changes in working directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdNoRepository directory
actionNoStash actionpush
messageNoStash message (for push)
indexNoStash index (for pop/apply/drop)

Implementation Reference

  • The main handler function that implements the git_stash tool logic, handling different stash actions like push, pop, list, apply, drop, and clear using git commands.
    export async function gitStash(args: z.infer<typeof gitStashSchema>): Promise<ToolResponse> { switch (args.action) { case 'push': const message = args.message ? `-m "${args.message}"` : ''; return executeGitCommand(`git stash push ${message}`.trim(), args.cwd); case 'pop': const popIndex = args.index !== undefined ? `stash@{${args.index}}` : ''; return executeGitCommand(`git stash pop ${popIndex}`.trim(), args.cwd); case 'list': return executeGitCommand('git stash list', args.cwd); case 'apply': const applyIndex = args.index !== undefined ? `stash@{${args.index}}` : ''; return executeGitCommand(`git stash apply ${applyIndex}`.trim(), args.cwd); case 'drop': const dropIndex = args.index !== undefined ? `stash@{${args.index}}` : ''; return executeGitCommand(`git stash drop ${dropIndex}`.trim(), args.cwd); case 'clear': return executeGitCommand('git stash clear', args.cwd); default: return { content: [{ type: "text", text: JSON.stringify({ success: false, error: 'Invalid stash action' }, null, 2) }], isError: true }; } }
  • Zod schema used for input validation of git_stash tool arguments in the dispatch handler.
    export const gitStashSchema = z.object({ cwd: z.string().optional().describe('Repository directory'), action: z.enum(['push', 'pop', 'list', 'apply', 'drop', 'clear']).optional().default('push').describe('Stash action'), message: z.string().optional().describe('Stash message (for push)'), index: z.number().optional().describe('Stash index (for pop/apply/drop)') });
  • src/index.ts:417-419 (registration)
    Dispatch logic in the main MCP server that registers and routes 'git_stash' tool calls to the handler function after validation.
    if (name === 'git_stash') { const validated = gitStashSchema.parse(args); return await gitStash(validated);
  • MCP tool definition including name, description, and input schema advertised in the listTools response.
    { name: 'git_stash', description: 'Stash changes in working directory', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Repository directory' }, action: { type: 'string', enum: ['push', 'pop', 'list', 'apply', 'drop', 'clear'], default: 'push', description: 'Stash action' }, message: { type: 'string', description: 'Stash message (for push)' }, index: { type: 'number', description: 'Stash index (for pop/apply/drop)' } } } },
  • Shared helper function that executes git commands via child_process.exec and formats the 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 }; } }

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