Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

git_revert

Revert a Git commit by creating a new commit that undoes the changes. Apply changes without committing when needed to manage repository history effectively.

Instructions

Revert a commit by creating a new commit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commitYesCommit hash to revert
cwdNoRepository directory
noCommitNoApply changes without committing

Implementation Reference

  • The git_revert tool handler function that executes the git revert command using the shared executeGitCommand helper.
    export async function gitRevert(args: z.infer<typeof gitRevertSchema>): Promise<ToolResponse> { const noCommitFlag = args.noCommit ? '--no-commit' : ''; return executeGitCommand(`git revert ${noCommitFlag} ${args.commit}`.trim(), args.cwd); }
  • Zod schema used for input validation in the git_revert handler.
    export const gitRevertSchema = z.object({ commit: z.string().describe('Commit hash to revert'), cwd: z.string().optional().describe('Repository directory'), noCommit: z.boolean().optional().default(false).describe('Apply changes without committing') });
  • MCP tool registration definition in the gitTools array, including name, description, and JSON input schema.
    { name: 'git_revert', description: 'Revert a commit by creating a new commit', inputSchema: { type: 'object', properties: { commit: { type: 'string', description: 'Commit hash to revert' }, cwd: { type: 'string', description: 'Repository directory' }, noCommit: { type: 'boolean', default: false, description: 'Apply changes without committing' } }, required: ['commit'] } },
  • src/index.ts:425-428 (registration)
    Dispatch handler in the main MCP server that routes git_revert calls to the handler function after validation.
    if (name === 'git_revert') { const validated = gitRevertSchema.parse(args); return await gitRevert(validated); }
  • Shared helper function used by all git tools, including git_revert, to execute git commands and format responses.
    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