Skip to main content
Glama
saidsef

GitHub PR Issue Analyser

by saidsef

merge_pr

Merge GitHub pull requests using specified methods (merge, squash, or rebase) with customizable commit messages for repository integration.

Instructions

Merges a specific pull request in a GitHub repository using the specified merge method. Args: repo_owner (str): The owner of the repository. repo_name (str): The name of the repository. pr_number (int): The pull request number to merge. commit_title (str, optional): The title for the merge commit. Defaults to None. commit_message (str, optional): The message for the merge commit. Defaults to None. merge_method (Literal['merge', 'squash', 'rebase'], optional): The merge method to use ('merge', 'squash', or 'rebase'). Defaults to 'squash'. Returns: Dict[str, Any]: The JSON response from the GitHub API containing merge information if successful. Error Handling: Logs errors and prints the traceback if the merge fails, returning None.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_ownerYes
repo_nameYes
pr_numberYes
commit_titleNo
commit_messageNo
merge_methodNosquash

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The `merge_pr` method in the `GitHubIntegration` class implements the core logic for merging a GitHub pull request. It constructs the API URL, sends a PUT request with merge parameters, handles the response, and returns success or error details.
    def merge_pr(self, repo_owner: str, repo_name: str, pr_number: int, commit_title: Optional[str] = None, commit_message: Optional[str] = None, merge_method: Literal['merge', 'squash', 'rebase'] = 'squash') -> Dict[str, Any]:
        """
        Merges a specific pull request in a GitHub repository using the specified merge method.
        Args:
            repo_owner (str): The owner of the repository.
            repo_name (str): The name of the repository.
            pr_number (int): The pull request number to merge.
            commit_title (str, optional): The title for the merge commit. Defaults to None.
            commit_message (str, optional): The message for the merge commit. Defaults to None.
            merge_method (Literal['merge', 'squash', 'rebase'], optional): The merge method to use ('merge', 'squash', or 'rebase'). Defaults to 'squash'.
        Returns:
            Dict[str, Any]: The JSON response from the GitHub API containing merge information if successful.
        Error Handling:
            Logs errors and prints the traceback if the merge fails, returning None.
        """
        logging.info(f"Merging PR {repo_owner}/{repo_name}#{pr_number}")
    
        # Construct the merge URL
        merge_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls/{pr_number}/merge"
    
        try:
            response = requests.put(merge_url, headers=self._get_headers(), json={
                'commit_title': commit_title,
                'commit_message': commit_message,
                'merge_method': merge_method
            }, timeout=TIMEOUT)
            response.raise_for_status()
            merge_data = response.json()
    
            logging.info("PR merged successfully")
            return merge_data
    
        except Exception as e:
            logging.error({"status": "error", "message": str(e)})
            traceback.print_exc()
            return {"status": "error", "message": str(e)}
  • The `register_tools` method dynamically registers all non-private methods of the `GitHubIntegration` instance (including `merge_pr`) as MCP tools by calling `self.mcp.add_tool(method)` in a loop over inspect.getmembers.
    def register_tools(self, methods: Any = None) -> None:
        for name, method in inspect.getmembers(methods):
            if (inspect.isfunction(method) or inspect.ismethod(method)) and not name.startswith("_"):
                self.mcp.add_tool(method)
  • The `_register_tools` method calls `register_tools` on the `GitHubIntegration` instance (`self.gi`), which registers the `merge_pr` tool.
    self.register_tools(self.gi)
    self.register_tools(self.ip)
  • Instantiation of the `GitHubIntegration` class instance (`self.gi = GI()`), providing the `merge_pr` handler to the MCP server.
    self.gi = GI()
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses the merge action (a destructive write operation) and error handling (logs errors, returns None on failure), which are useful behavioral traits. However, it lacks details on permissions required, rate limits, or what happens to the PR post-merge (e.g., branch deletion).

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

Conciseness4/5

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

The description is well-structured with clear sections (Args, Returns, Error Handling) and front-loaded purpose. It's appropriately sized for a 6-parameter tool, though the error handling sentence could be more concise (e.g., 'Returns None on failure').

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

Completeness4/5

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

Given the tool's complexity (destructive merge operation, 6 parameters, no annotations) and the presence of an output schema (implied by 'Returns' section), the description is reasonably complete. It covers parameters, return values, and error handling, but lacks context on prerequisites or integration with sibling tools.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It adds meaningful context for all parameters: it explains what each arg represents (e.g., 'repo_owner' as 'The owner of the repository'), specifies optional parameters with defaults, and clarifies the merge_method enum values. This goes beyond the bare schema, though it doesn't detail format constraints (e.g., string length).

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 ('merges a specific pull request'), the resource ('in a GitHub repository'), and the mechanism ('using the specified merge method'). It distinguishes itself from sibling tools like 'create_pr', 'update_pr_description', and 'list_open_issues_prs' by focusing on the final merge operation rather than creation, modification, or listing.

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. It doesn't mention prerequisites (e.g., the PR must be mergeable, reviews approved), nor does it differentiate from sibling tools like 'update_reviews' or 'get_pr_content' that might be needed before merging. Usage is implied only by the action itself.

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/saidsef/mcp-github-pr-issue-analyser'

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