Skip to main content
Glama

github_get_pull_requests

Retrieve pull requests from GitHub repositories to monitor code changes, review contributions, and track development progress. Filter by open, closed, or all states with customizable result limits.

Instructions

Get pull requests for a GitHub repository.

Args: repo_name: Full repository name (e.g., "owner/repo") state: PR state: "open", "closed", or "all" (default: "open") limit: Maximum number of PRs to return (default: 20)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
repo_nameYes
stateNoopen

Implementation Reference

  • MCP tool handler for 'github_get_pull_requests', registered with @mcp.tool() decorator and delegates execution to GitHubTools.get_pull_requests
    @mcp.tool()
    async def github_get_pull_requests(
        repo_name: str, state: str = "open", limit: int = 20
    ) -> list:
        """Get pull requests for a GitHub repository.
    
        Args:
            repo_name: Full repository name (e.g., "owner/repo")
            state: PR state: "open", "closed", or "all" (default: "open")
            limit: Maximum number of PRs to return (default: 20)
        """
        return await github_tools.get_pull_requests(
            repo_name=repo_name, state=state, limit=limit
        )
  • Core helper function in GitHubTools class that implements the pull requests fetching logic using PyGithub library
    async def get_pull_requests(
        self, repo_name: str, state: str = "open", limit: int = 20
    ) -> List[Dict[str, Any]]:
        """
        Get pull requests for a repository.
    
        Args:
            repo_name: Full repository name (e.g., "owner/repo")
            state: PR state ("open", "closed", or "all")
            limit: Maximum number of PRs to return
    
        Returns:
            List of pull request information
        """
        self._check_client()
    
        try:
            repo = self.client.get_repo(repo_name)
            pulls = repo.get_pulls(state=state)
    
            results = []
            for i, pr in enumerate(pulls):
                if i >= limit:
                    break
                results.append(
                    {
                        "number": pr.number,
                        "title": pr.title,
                        "state": pr.state,
                        "user": pr.user.login,
                        "created_at": (
                            pr.created_at.isoformat() if pr.created_at else None
                        ),
                        "updated_at": (
                            pr.updated_at.isoformat() if pr.updated_at else None
                        ),
                        "url": pr.html_url,
                        "head": pr.head.ref,
                        "base": pr.base.ref,
                    }
                )
    
            return results
    
        except GithubException as e:
            logger.error(f"GitHub API error: {e}")
            raise ValueError(f"Failed to get pull requests: {str(e)}")
  • JSON schema definition for the tool input used in the LLM assistant integration
    {
        "name": "github_get_pull_requests",
        "description": "Get pull requests for a GitHub repository",
        "input_schema": {
            "type": "object",
            "properties": {
                "repo_name": {
                    "type": "string",
                    "description": "Full repository name",
                },
                "state": {
                    "type": "string",
                    "enum": ["open", "closed", "all"],
                    "default": "open",
                },
                "limit": {
                    "type": "integer",
                    "description": "Maximum PRs",
                    "default": 20,
                },
            },
            "required": ["repo_name"],
        },
    },

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/bsangars/mcp'

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