Skip to main content
Glama
saidsef

GitHub PR Issue Analyser

by saidsef

merge_pr

Merges a pull request in a GitHub repository using your choice of merge, squash, or rebase methods.

Instructions

Merges a specific pull request in a GitHub repository using the specified merge method. If merge pr is fails use update_pr_branch to update the branch with the latest changes from the base branch and try merging again after CI finishes. 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

No arguments

Implementation Reference

  • The merge_pr method on GitHubIntegration class - the core implementation that merges a pull request via PUT to GitHub's /pulls/{pr_number}/merge endpoint. Supports merge, squash, and rebase methods. Handles GitHubAPIError and httpx.HTTPError with error logging.
    def merge_pr(
        self,
        repo_owner: str,
        repo_name: str,
        pr_number: int,
        commit_title: str | None = None,
        commit_message: str | None = 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.
        If merge pr is fails use update_pr_branch to update the branch with the latest changes from the base branch and try merging again after CI finishes.
        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.
        """
        logger.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:
            payload: dict[str, Any] = {"merge_method": merge_method}
            if commit_title is not None:
                payload["commit_title"] = commit_title
            if commit_message is not None:
                payload["commit_message"] = commit_message
    
            response = httpx.put(
                merge_url,
                headers=self._get_headers(),
                json=payload,
                timeout=TIMEOUT,
            )
            if not response.is_success:
                self._handle_response_error(
                    response,
                    f"PR #{pr_number} merge in {repo_owner}/{repo_name}",
                )
            merge_data = response.json()
    
            logger.info("PR merged successfully")
            return merge_data
    
        except GitHubAPIError as e:
            if isinstance(e, GitHubAuthError):
                detail = e.message
            else:
                github_msg = (e.response_body or {}).get("message", "") if e.response_body else ""
                detail = github_msg or e.message
            logger.error(f"Error merging PR: {detail}")
            return {"status": "error", "message": detail, "details": e.response_body}
        except httpx.HTTPError as e:
            logger.error(f"Error merging PR: {str(e)}")
            traceback.print_exc()
            return {"status": "error", "message": str(e)}
  • Dynamic registration of all public methods of GitHubIntegration as MCP tools via introspection. register_tools iterates over the object's public methods (including merge_pr) and calls self.mcp.add_tool(method) on each.
    def _register_tools(self):
        self.register_tools(self.gi)
        self.register_tools(self.ip)
        self.mcp.add_provider(SkillsDirectoryProvider(Path(__file__).parent / "skills"))
    
    def register_tools(self, methods: Any = None) -> None:
        for name in dir(methods):
            if name.startswith("_"):
                continue
            method = getattr(methods, name)
            if inspect.isroutine(method):
                self.mcp.add_tool(method)
Behavior5/5

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

Despite no annotations, the description discloses error handling behavior (log errors, return None) and the fallback process. This gives the AI agent a clear understanding of outcomes and edge cases.

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). It is slightly verbose but each sentence adds value; could be trimmed slightly without losing clarity.

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

Completeness5/5

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

Given the complexity (6 parameters, no annotations, no schema descriptions), the description is highly complete. It covers parameter semantics, error handling, and a fallback strategy, making the tool fully understandable for selection and invocation.

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

Parameters5/5

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

With 0% schema description coverage, the description compensates fully by explaining each parameter (repo_owner, repo_name, pr_number, commit_title, commit_message, merge_method) including defaults and constraints like the merge_method enum. The output schema exists but the description adds the return type and error case.

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 it merges a pull request using a specified merge method, and distinguishes itself from sibling tool update_pr_branch by providing a fallback strategy. The verb 'merge' and resource 'pull request' are specific and unambiguous.

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

Usage Guidelines5/5

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

Explicitly advises to use update_pr_branch if merging fails, and to try again after CI finishes. This provides clear when-to-use and when-not-to-use guidance, referencing sibling tools and context.

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