Skip to main content
Glama
Arcia125

Git Workflow Automation MCP Server

by Arcia125

merge_pull_request

Merge GitHub pull requests using specified methods (merge, squash, rebase) with options to delete branches and preview changes before execution.

Instructions

Merge a GitHub pull request

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
prNumberYesPull request number
mergeMethodNoMerge methodmerge
deleteBranchNoDelete branch after merge
workingDirNoWorking directory path
dryRunNoPreview without executing

Implementation Reference

  • Core handler function that implements the merge_pull_request tool logic. Constructs and executes the 'gh pr merge' command with specified merge method, optional branch deletion, working directory, and dry-run support. Uses executeWithClearedTokens for secure execution with cleared GitHub tokens.
    async function mergePullRequest(
      prNumber: string,
      mergeMethod: 'merge' | 'squash' | 'rebase' = 'merge',
      deleteBranch: boolean = true,
      workingDir?: string,
      dryRun: boolean = false
    ): Promise<WorkflowResult> {
      try {
        if (dryRun) {
          return {
            success: true,
            message: "Dry run: Would merge pull request",
            details: {
              prNumber,
              mergeMethod,
              deleteBranch
            }
          };
        }
    
        // Merge PR using GitHub CLI with cleared tokens
        const mergeFlag = mergeMethod === 'squash' ? '--squash' : mergeMethod === 'rebase' ? '--rebase' : '--merge';
        const deleteFlag = deleteBranch ? '--delete-branch' : '';
        const command = `gh pr merge ${prNumber} ${mergeFlag} ${deleteFlag}`.trim();
    
        const result = await executeWithClearedTokens(command, workingDir);
    
        return {
          success: true,
          message: "Successfully merged pull request",
          details: {
            prNumber,
            mergeMethod,
            output: result.stdout
          }
        };
      } catch (error: any) {
        return {
          success: false,
          message: "Failed to merge pull request",
          error: `Failed to merge pull request: ${error.message}`
        };
      }
    }
  • Input schema defining the parameters for the merge_pull_request tool, including required prNumber and optional mergeMethod, deleteBranch, workingDir, dryRun.
      inputSchema: {
        type: "object",
        properties: {
          prNumber: {
            type: "string",
            description: "Pull request number"
          },
          mergeMethod: {
            type: "string",
            enum: ["merge", "squash", "rebase"],
            description: "Merge method",
            default: "merge"
          },
          deleteBranch: {
            type: "boolean",
            description: "Delete branch after merge",
            default: true
          },
          workingDir: {
            type: "string",
            description: "Working directory path"
          },
          dryRun: {
            type: "boolean",
            description: "Preview without executing",
            default: false
          }
        },
        required: ["prNumber"]
      }
    },
  • src/index.ts:487-520 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema for merge_pull_request.
    {
      name: "merge_pull_request",
      description: "Merge a GitHub pull request",
      inputSchema: {
        type: "object",
        properties: {
          prNumber: {
            type: "string",
            description: "Pull request number"
          },
          mergeMethod: {
            type: "string",
            enum: ["merge", "squash", "rebase"],
            description: "Merge method",
            default: "merge"
          },
          deleteBranch: {
            type: "boolean",
            description: "Delete branch after merge",
            default: true
          },
          workingDir: {
            type: "string",
            description: "Working directory path"
          },
          dryRun: {
            type: "boolean",
            description: "Preview without executing",
            default: false
          }
        },
        required: ["prNumber"]
      }
    },
  • src/index.ts:606-614 (registration)
    Dispatch logic in CallToolRequest handler that maps the tool name to the mergePullRequest function call with argument extraction and type casting.
    case "merge_pull_request":
      result = await mergePullRequest(
        args?.prNumber as string,
        (args?.mergeMethod as 'merge' | 'squash' | 'rebase') || 'merge',
        (args?.deleteBranch as boolean) ?? true,
        args?.workingDir as string,
        (args?.dryRun as boolean) || false
      );
      break;

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/Arcia125/git-workflow-mcp-server'

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