Skip to main content
Glama
saidsef

GitHub PR Issue Analyser

by saidsef

get_latest_sha

Retrieve the SHA of the most recent commit from a GitHub repository by specifying the owner and repository name.

Instructions

Fetches the SHA of the latest commit in the specified GitHub repository. Args: repo_owner (str): The owner of the GitHub repository. repo_name (str): The name of the GitHub repository. Returns: Optional[str]: The SHA string of the latest commit if found, otherwise None. Error Handling: Logs errors and warnings if the request fails, the response is invalid, or no commits are found. Returns None in case of exceptions or if the repository has no commits.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_ownerYes
repo_nameYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler method `get_latest_sha` on the `GitHubIntegration` class. Fetches the SHA of the latest commit from a GitHub repository by calling the GitHub commits API endpoint `GET /repos/{owner}/{repo}/commits` and returning the SHA of the first (most recent) commit.
    def get_latest_sha(self, repo_owner: str, repo_name: str) -> str | None:
        """
        Fetches the SHA of the latest commit in the specified GitHub repository.
        Args:
            repo_owner (str): The owner of the GitHub repository.
            repo_name (str): The name of the GitHub repository.
        Returns:
            Optional[str]: The SHA string of the latest commit if found, otherwise None.
        Error Handling:
            Logs errors and warnings if the request fails, the response is invalid, or no commits are found.
            Returns None in case of exceptions or if the repository has no commits.
        """
        logger.info(f"Fetching latest commit SHA for {repo_owner}/{repo_name}")
    
        # Construct the commits URL
        commits_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/commits"
    
        try:
            # Fetch the latest commit
            response = httpx.get(commits_url, headers=self._get_headers(), timeout=TIMEOUT)
            self._raise_for_status(response, f"commits for {repo_owner}/{repo_name}")
            commits_data = response.json()
    
            if commits_data:
                latest_sha = commits_data[0]["sha"]
                logger.info(f"Latest commit SHA: {latest_sha}")
                return latest_sha
            else:
                logger.warning("No commits found in the repository")
                return "No commits found in the repository"
    
        except GitHubAuthError:
            raise
        except Exception as e:
            logger.error(f"Error fetching latest commit SHA: {str(e)}")
            traceback.print_exc()
            return str(e)
  • Registration: `register_tools(self.gi)` introspects all public methods of the `GitHubIntegration` instance (including `get_latest_sha`) and registers each as an MCP tool via `self.mcp.add_tool(method)`.
    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)
  • Helper usage: `create_tag` calls `self.get_latest_sha(repo_owner, repo_name)` to obtain the latest commit SHA before creating a new Git tag referencing that commit.
    def create_tag(self, repo_owner: str, repo_name: str, tag_name: str, message: str) -> dict[str, Any]:
        """
        Creates a new tag in the specified GitHub repository.
        Args:
            repo_owner (str): The owner of the repository.
            repo_name (str): The name of the repository.
            tag_name (str): The name of the tag to create.
            message (str): The message associated with the tag.
        Returns:
            Dict[str, Any]: The response data from the GitHub API if the tag is created successfully.
            None: If an error occurs during the tag creation process.
        Error Handling:
            Logs errors and prints the traceback if fetching the latest commit SHA fails or if the GitHub API request fails.
        """
        logger.info(f"Creating tag {tag_name} in {repo_owner}/{repo_name}")
        # Construct the tags URL
        tags_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/git/refs"
        try:
            # Fetch the latest commit SHA
            latest_sha = self.get_latest_sha(repo_owner, repo_name)
            if not latest_sha:
                raise ValueError("Failed to fetch the latest commit SHA")
    
            # Create the tag
            response = httpx.post(
                tags_url,
                headers=self._get_headers(),
                json={
                    "ref": f"refs/tags/{tag_name}",
                    "sha": latest_sha,
                    "message": message,
                },
                timeout=TIMEOUT,
            )
            self._raise_for_status(response, f"create tag {tag_name}")
            tag_data = response.json()
    
            logger.info("Tag created successfully")
            return tag_data
    
        except GitHubAuthError:
            raise
        except Exception as e:
            logger.error(f"Error creating tag: {str(e)}")
            traceback.print_exc()
            return {"status": "error", "message": str(e)}
Behavior4/5

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

With no annotations, the description fully discloses behavior: it returns Optional[str] and handles errors by logging and returning None. This covers what the agent needs to know about side effects and edge cases, though it lacks details on authentication or rate limits.

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 front-loaded with the main purpose, followed by parameter details and return/error info. It is slightly verbose due to docstring formatting, but every sentence adds value. Could be more concise, but it's well-organized.

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 tool's simplicity (two parameters, no annotations, output schema exists), the description covers all necessary aspects: purpose, parameters, return type, and error handling. It is complete for an agent to invoke the tool correctly.

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?

The input schema has 0% description coverage, so the description must add meaning. It lists 'repo_owner' and 'repo_name' with their types, which is clear but adds little beyond the schema. The parameter names are self-explanatory, so baseline 3 is appropriate.

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 'Fetches the SHA of the latest commit in the specified GitHub repository.' It uses a specific verb ('fetches') and resource ('SHA of latest commit'), which distinguishes it from sibling tools like get_pr_content or create_release.

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

Usage Guidelines3/5

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

The description explains the tool's purpose but does not provide explicit guidance on when to use it versus alternatives or mention any prerequisites. Usage is implied from the clear purpose, but no exclusions or alternative recommendations are given.

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