Skip to main content
Glama
saidsef

GitHub PR Issue Analyser

by saidsef

add_inline_pr_comment

Add inline review comments to specific lines in GitHub pull request files for precise code feedback during collaborative development.

Instructions

Adds an inline review comment to a specific line in a file within a pull request on GitHub. Args: repo_owner (str): The owner of the repository. repo_name (str): The name of the repository. pr_number (int): The pull request number. path (str): The relative path to the file (e.g., 'src/main.py'). line (int): The line number in the file to comment on. comment_body (str): The content of the review comment. Returns: Dict[str, Any]: The JSON response from the GitHub API containing the comment data if successful. None: If an error occurs while adding the comment. Error Handling: Logs an error message and prints the traceback if the request fails or an exception is raised.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_ownerYes
repo_nameYes
pr_numberYes
pathYes
lineYes
comment_bodyYes

Implementation Reference

  • The core handler function that implements adding an inline PR comment using GitHub API, including fetching PR head commit and posting the review comment.
    def add_inline_pr_comment(self, repo_owner: str, repo_name: str, pr_number: int, path: str, line: int, comment_body: str) -> Dict[str, Any]:
        """
        Adds an inline review comment to a specific line in a file within a pull request on GitHub.
        Args:
            repo_owner (str): The owner of the repository.
            repo_name (str): The name of the repository.
            pr_number (int): The pull request number.
            path (str): The relative path to the file (e.g., 'src/main.py').
            line (int): The line number in the file to comment on.
            comment_body (str): The content of the review comment.
        Returns:
            Dict[str, Any]: The JSON response from the GitHub API containing the comment data if successful.
            None: If an error occurs while adding the comment.
        Error Handling:
            Logs an error message and prints the traceback if the request fails or an exception is raised.
        """
        logging.info(f"Adding inline review comment to PR {repo_owner}/{repo_name}#{pr_number} on {path}:{line}")
    
        # Construct the review comments URL
        review_comments_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls/{pr_number}/comments"
    
        try:
            pr_url = self._get_pr_url(repo_owner, repo_name, pr_number)
            pr_response = requests.get(pr_url, headers=self._get_headers(), timeout=TIMEOUT)
            pr_response.raise_for_status()
            pr_data = pr_response.json()
            commit_id = pr_data['head']['sha']
    
            payload = {
                "body": comment_body,
                "commit_id": commit_id,
                "path": path,
                "line": line,
                "side": "RIGHT"
            }
    
            response = requests.post(review_comments_url, headers=self._get_headers(), json=payload, timeout=TIMEOUT)
            response.raise_for_status()
            comment_data = response.json()
    
            logging.info("Inline review comment added successfully")
            return comment_data
    
        except Exception as e:
            logging.error(f"Error adding inline review comment: {str(e)}")
            traceback.print_exc()
            return {"status": "error", "message": str(e)}
  • Dynamically registers all public methods of GitHubIntegration (including add_inline_pr_comment) as MCP tools by inspecting and adding them to FastMCP.
    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)
  • Calls register_tools on the GitHubIntegration instance (self.gi), which triggers the registration of add_inline_pr_comment as an MCP tool.
    def _register_tools(self):
        self.register_tools(self.gi)
        self.register_tools(self.ip)

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