Skip to main content
Glama
saidsef

GitHub PR Issue Analyser

by saidsef

get_latest_sha

Fetch the SHA of the most recent commit in a GitHub repository to identify current code state for analysis or automation workflows.

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 core handler function for the 'get_latest_sha' tool. It queries the GitHub API to retrieve the SHA of the most recent commit in the specified repository's default branch.
    def get_latest_sha(self, repo_owner: str, repo_name: str) -> Optional[str]:
        """
        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.
        """
        logging.info({"status": "info", "message": 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 = requests.get(commits_url, headers=self._get_headers(), timeout=TIMEOUT)
            response.raise_for_status()
            commits_data = response.json()
    
            if commits_data:
                latest_sha = commits_data[0]['sha']
                logging.info({"status": "info", "message": f"Latest commit SHA: {latest_sha}"})
                return latest_sha
            else:
                logging.warning({"status": "warning", "message": "No commits found in the repository"})
                return "No commits found in the repository"
    
        except Exception as e:
            logging.error(f"Error fetching latest commit SHA: {str(e)}")
            traceback.print_exc()
            return str(e)
  • Registers all public methods (non-private, i.e., not starting with '_') from the GitHubIntegration instance as MCP tools, including 'get_latest_sha'.
    def _register_tools(self):
        self.register_tools(self.gi)
        self.register_tools(self.ip)
    
    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)
    
    def run(self):
  • Usage of get_latest_sha as a helper function within the create_tag method to obtain the latest commit SHA before creating a tag.
    # Fetch the latest commit SHA
    latest_sha = self.get_latest_sha(repo_owner, repo_name)
    if not latest_sha:
  • Instantiation of the GitHubIntegration class instance (self.gi) whose methods, including get_latest_sha, are later registered as tools.
    self.gi = GI()
    self.ip = IP()
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: it specifies the return type (Optional[str]), error handling behavior (logs errors/warnings, returns None on exceptions or no commits), and the conditional nature of the response (SHA if found, otherwise None). This goes beyond what the input schema provides.

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 efficiently structured with clear sections (Args, Returns, Error Handling), front-loading the core purpose, and every sentence adds value without redundancy. The four-sentence format is appropriately sized for this tool's complexity.

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 moderate complexity, no annotations, and the presence of an output schema (implied by 'Returns' section), the description is complete enough. It covers purpose, parameters, return behavior, and error handling, providing all necessary context for an agent to use the tool correctly.

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?

The description adds significant meaning beyond the input schema, which has 0% description coverage. It explicitly documents both parameters (repo_owner, repo_name) with their types and purposes, plus details about return values and error handling. This fully compensates for the schema's lack of descriptions.

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 ('Fetches the SHA of the latest commit') and resource ('GitHub repository'), distinguishing it from sibling tools like get_pr_content or get_pr_diff which focus on different GitHub resources. The verb 'fetches' is precise and the scope is well-defined.

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 implies usage context through the parameter names (repo_owner, repo_name) and mention of GitHub, but doesn't explicitly state when to use this tool versus alternatives like get_info or other GitHub-related siblings. No explicit when-not-to-use guidance or named alternatives are provided.

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