list_open_issues_prs
Retrieve open pull requests or issues from GitHub repositories to monitor development progress and manage contributions.
Instructions
Lists open pull requests or issues for a specified GitHub repository owner.
Args:
repo_owner (str): The owner of the repository.
issue (Literal['pr', 'issue']): The type of items to list, either 'pr' for pull requests or 'issue' for issues. Defaults to 'pr'.
filtering (Literal['user', 'owner', 'involves']): The filtering criteria for the search. Defaults to 'involves'.
per_page (Annotated[int, PerPage]): The number of results to return per page, range 1-100. Defaults to 50.
page (int): The page number to retrieve. Defaults to 1.
Returns:
Dict[str, Any]: A dictionary containing the list of open pull requests or issues, depending on the value of the issue parameter.
None: If an error occurs during the request.
Error Handling:
Logs an error message and prints the traceback if the request fails or an exception is raised.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_owner | Yes | ||
| issue | No | pr | |
| filtering | No | involves | |
| per_page | No | ||
| page | No |
Implementation Reference
- The core handler function implementing the 'list_open_issues_prs' tool logic. It queries GitHub's search API to retrieve open PRs or issues filtered by repo owner, with pagination and customizable filtering options.def list_open_issues_prs( self, repo_owner: str, issue: Literal['pr', 'issue'] = 'pr', filtering: Literal['user', 'owner', 'involves'] = 'involves', per_page: Annotated[PerPage, "Number of results per page (1-100)"] = 50, page: int = 1 ) -> Dict[str, Any]: """ Lists open pull requests or issues for a specified GitHub repository owner. Args: repo_owner (str): The owner of the repository. issue (Literal['pr', 'issue']): The type of items to list, either 'pr' for pull requests or 'issue' for issues. Defaults to 'pr'. filtering (Literal['user', 'owner', 'involves']): The filtering criteria for the search. Defaults to 'involves'. per_page (Annotated[int, PerPage]): The number of results to return per page, range 1-100. Defaults to 50. page (int): The page number to retrieve. Defaults to 1. Returns: Dict[str, Any]: A dictionary containing the list of open pull requests or issues, depending on the value of the `issue` parameter. None: If an error occurs during the request. Error Handling: Logs an error message and prints the traceback if the request fails or an exception is raised. """ logging.info(f"Listing open {issue}s for {repo_owner}") # Construct the search URL search_url = f"https://api.github.com/search/issues?q=is:{issue}+is:open+{filtering}:{repo_owner}&per_page={per_page}&page={page}" try: response = requests.get(search_url, headers=self._get_headers(), timeout=TIMEOUT) response.raise_for_status() pr_data = response.json() open_prs = { "total": pr_data['total_count'], f"open_{issue}s": [ { "url": item['html_url'], "title": item['title'], "number": item['number'], "state": item['state'], "created_at": item['created_at'], "updated_at": item['updated_at'], "author": item['user']['login'], "label_names": [label['name'] for label in item.get('labels', [])], "is_draft": item.get('draft', False), } for item in pr_data['items'] ] } logging.info(f"Open {issue}s listed successfully") return open_prs except Exception as e: logging.error(f"Error listing open {issue}s: {str(e)}") traceback.print_exc() return {"status": "error", "message": str(e)}
- src/mcp_github/issues_pr_analyser.py:105-113 (registration)Dynamic registration of all public methods from the GitHubIntegration instance (including list_open_issues_prs) as MCP tools via FastMCP.add_tool().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)
- Pydantic validator defining the schema constraint for the 'per_page' parameter (1-100). Used in the tool's Annotated type hint.PerPage = conint(ge=1, le=100)