Skip to main content
Glama
nextDriveIoE

GitHub Action Trigger MCP Server

by nextDriveIoE

enable_pull_request_automerge

Automatically merge GitHub pull requests when all required checks pass, using specified merge methods like MERGE, SQUASH, or REBASE.

Instructions

Enable auto-merge for a specific pull request. This will automatically merge the PR when all required checks pass.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerYesOwner of the repository (username or organization)
repoYesName of the repository
pull_numberYesThe pull request number
merge_methodNoThe merge method to use when auto-merging (MERGE, SQUASH, or REBASE)
tokenNoGitHub personal access token (optional)

Implementation Reference

  • The core handler function that implements the enable_pull_request_automerge tool logic. It uses GitHub GraphQL API to first fetch the PR details, check status, and then enable auto-merge if not already enabled.
    async function enablePullRequestAutoMerge(owner: string, repo: string, pullNumber: number, mergeMethod: string = 'MERGE', token?: string) {
      // Use provided token or fall back to config token
      const authToken = token || config.githubToken;
      
      if (!authToken) {
        throw new Error('GitHub token is required to enable pull request auto-merge');
      }
      
      try {
        const headers: Record<string, string> = {
          'Accept': 'application/vnd.github+json',
          'Authorization': `Bearer ${authToken}`,
          'Content-Type': 'application/json'
        };
        
        // First, get the pull request ID using GraphQL
        const getPullRequestIdQuery = {
          query: `
            query GetPullRequestId($owner: String!, $repo: String!, $number: Int!) {
              repository(owner: $owner, name: $repo) {
                pullRequest(number: $number) {
                  id
                  title
                  state
                  autoMergeRequest {
                    enabledAt
                    mergeMethod
                  }
                }
              }
            }
          `,
          variables: {
            owner: owner,
            repo: repo,
            number: pullNumber
          }
        };
        
        const pullRequestResponse = await axios.post(
          'https://api.github.com/graphql',
          getPullRequestIdQuery,
          { headers }
        );
        
        if (pullRequestResponse.data.errors) {
          throw new Error(`GraphQL error: ${JSON.stringify(pullRequestResponse.data.errors)}`);
        }
        
        const pullRequest = pullRequestResponse.data.data?.repository?.pullRequest;
        if (!pullRequest) {
          throw new Error(`Pull request #${pullNumber} not found in ${owner}/${repo}`);
        }
        
        if (pullRequest.state !== 'OPEN') {
          throw new Error(`Pull request #${pullNumber} is not open (current state: ${pullRequest.state})`);
        }
        
        // Check if auto-merge is already enabled
        if (pullRequest.autoMergeRequest) {
          return {
            success: true,
            message: 'Auto-merge is already enabled for this pull request',
            pullRequest: {
              id: pullRequest.id,
              title: pullRequest.title,
              number: pullNumber,
              autoMergeEnabled: true,
              enabledAt: pullRequest.autoMergeRequest.enabledAt,
              mergeMethod: pullRequest.autoMergeRequest.mergeMethod
            }
          };
        }
        
        const pullRequestId = pullRequest.id;
        
        // Now enable auto-merge using the mutation
        const enableAutoMergeMutation = {
          query: `
            mutation EnablePullRequestAutoMerge($pullRequestId: ID!, $mergeMethod: PullRequestMergeMethod!) {
              enablePullRequestAutoMerge(input: {
                pullRequestId: $pullRequestId,
                mergeMethod: $mergeMethod
              }) {
                pullRequest {
                  id
                  title
                  number
                  autoMergeRequest {
                    enabledAt
                    mergeMethod
                  }
                }
              }
            }
          `,
          variables: {
            pullRequestId: pullRequestId,
            mergeMethod: mergeMethod
          }
        };
        
        const enableResponse = await axios.post(
          'https://api.github.com/graphql',
          enableAutoMergeMutation,
          { headers }
        );
        
        if (enableResponse.data.errors) {
          throw new Error(`Failed to enable auto-merge: ${JSON.stringify(enableResponse.data.errors)}`);
        }
        
        const result = enableResponse.data.data?.enablePullRequestAutoMerge?.pullRequest;
        if (!result) {
          throw new Error('Unexpected response from GitHub API');
        }
        
        return {
          success: true,
          message: 'Auto-merge enabled successfully',
          pullRequest: {
            id: result.id,
            title: result.title,
            number: result.number,
            autoMergeEnabled: true,
            enabledAt: result.autoMergeRequest.enabledAt,
            mergeMethod: result.autoMergeRequest.mergeMethod
          }
        };
        
      } catch (error) {
        if (axios.isAxiosError(error)) {
          const statusCode = error.response?.status;
          const errorMessage = error.response?.data?.message || error.message;
          
          if (statusCode === 401 || statusCode === 403) {
            throw new Error(`Authentication failed: ${errorMessage}. Make sure your token has the required permissions.`);
          } else if (statusCode === 404) {
            throw new Error(`Repository or pull request not found: ${errorMessage}`);
          }
          
          throw new Error(`GitHub API error: ${statusCode} - ${errorMessage}`);
        }
        throw error;
      }
    }
  • Input schema definition for the enable_pull_request_automerge tool, specifying parameters like owner, repo, pull_number, merge_method, and token.
    {
      name: "enable_pull_request_automerge",
      description: "Enable auto-merge for a specific pull request. This will automatically merge the PR when all required checks pass.",
      inputSchema: {
        type: "object",
        properties: {
          owner: {
            type: "string",
            description: "Owner of the repository (username or organization)"
          },
          repo: {
            type: "string",
            description: "Name of the repository"
          },
          pull_number: {
            type: "number",
            description: "The pull request number"
          },
          merge_method: {
            type: "string",
            description: "The merge method to use when auto-merging (MERGE, SQUASH, or REBASE)",
            enum: ["MERGE", "SQUASH", "REBASE"]
          },
          token: {
            type: "string",
            description: "GitHub personal access token (optional)"
          }
        },
        required: ["owner", "repo", "pull_number"]
      }
    }
  • src/index.ts:837-872 (registration)
    The registration and dispatching logic in the MCP CallToolRequestSchema handler that extracts arguments and calls the enablePullRequestAutoMerge function.
    case "enable_pull_request_automerge": {
      const owner = String(request.params.arguments?.owner);
      const repo = String(request.params.arguments?.repo);
      const pullNumber = Number(request.params.arguments?.pull_number);
      const mergeMethod = request.params.arguments?.merge_method ? String(request.params.arguments?.merge_method) : 'MERGE';
      const token = request.params.arguments?.token ? String(request.params.arguments?.token) : undefined;
      
      if (!owner || !repo || !pullNumber) {
        throw new Error("Owner, repo, and pull_number are required");
      }
      
      if (isNaN(pullNumber) || pullNumber <= 0) {
        throw new Error("pull_number must be a valid positive integer");
      }
      
      const validMergeMethods = ['MERGE', 'SQUASH', 'REBASE'];
      if (!validMergeMethods.includes(mergeMethod)) {
        throw new Error(`merge_method must be one of: ${validMergeMethods.join(', ')}`);
      }
    
      try {
        const result = await enablePullRequestAutoMerge(owner, repo, pullNumber, mergeMethod, token);
        
        return {
          content: [{
            type: "text",
            text: JSON.stringify(result, null, 2)
          }]
        };
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Failed to enable pull request auto-merge: ${error.message}`);
        }
        throw error;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While it states the tool enables auto-merge and describes the triggering condition, it lacks critical information about permissions needed, whether this is reversible, rate limits, error conditions, or what happens to existing auto-merge settings. For a mutation tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with two sentences that directly communicate the core functionality. Every word earns its place, and it's front-loaded with the main purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't address permissions, error handling, return values, or important behavioral details like whether this overrides existing settings or requires specific repository configurations. The context signals show this is a non-trivial operation (5 parameters, 3 required), warranting more comprehensive documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 5 parameters. The description doesn't add any parameter-specific information beyond what's in the schema, but it does provide context about the overall purpose that helps understand parameter usage. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Enable auto-merge') and the target resource ('for a specific pull request'), with additional detail about the automatic merging behavior when checks pass. It distinguishes itself from sibling tools (which are all read operations) by being a write/mutation tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or constraints. It mentions the condition 'when all required checks pass' but doesn't specify what happens if checks fail or if there are other requirements like permissions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/nextDriveIoE/github-action-trigger-mcp'

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