create_issue
Create a new GitHub issue in a repository with specified title, body, and labels. The issue link is automatically added to the related PR description.
Instructions
Creates a new issue in the specified GitHub repository. If the issue is created successfully, a link to the issue must be appended in the PR's description. Args: repo_owner (str): The owner of the repository. repo_name (str): The name of the repository. title (str): The title of the issue to be created. body (str): The body content of the issue. labels (list[str]): A list of labels to assign to the issue. The label 'mcp' will always be included. Returns: Dict[str, Any]: A dictionary containing the created issue's data if successful. None: If an error occurs during issue creation. Error Handling: Logs errors and prints the traceback if the issue creation fails, returning None.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_owner | Yes | ||
| repo_name | Yes | ||
| title | Yes | ||
| body | Yes | ||
| labels | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ||
| number | Yes | ||
| title | Yes | ||
| body | Yes | ||
| state | Yes | ||
| user | Yes | ||
| created_at | Yes | ||
| updated_at | Yes | ||
| labels | Yes |
Implementation Reference
- The `create_issue` method on `GitHubIntegration` class — the core handler logic. It POSTs to the GitHub Issues API and returns the created issue data. Always appends the 'mcp' label.
def create_issue(self, repo_owner: str, repo_name: str, title: str, body: str, labels: list[str]) -> IssueData: """ Creates a new issue in the specified GitHub repository. If the issue is created successfully, a link to the issue must be appended in the PR's description. Args: repo_owner (str): The owner of the repository. repo_name (str): The name of the repository. title (str): The title of the issue to be created. body (str): The body content of the issue. labels (list[str]): A list of labels to assign to the issue. The label 'mcp' will always be included. Returns: Dict[str, Any]: A dictionary containing the created issue's data if successful. None: If an error occurs during issue creation. Error Handling: Logs errors and prints the traceback if the issue creation fails, returning None. """ logger.info(f"Creating issue in {repo_owner}/{repo_name}") # Construct the issues URL issues_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues" try: # Create the issue issue_labels = ["mcp"] if not labels else labels + ["mcp"] response = httpx.post( issues_url, headers=self._get_headers(), json={"title": title, "body": body, "labels": issue_labels}, timeout=TIMEOUT, ) self._raise_for_status(response, f"create issue in {repo_owner}/{repo_name}") issue_data = response.json() logger.info("Issue created successfully") return issue_data except GitHubAuthError: raise except Exception as e: logger.error(f"Error creating issue: {str(e)}") traceback.print_exc() return {"status": "error", "message": str(e)} - The `IssueData` TypedDict defining the return type schema for `create_issue`.
type IssueData = TypedDict( "IssueData", { # pyright: ignore[reportInvalidTypeForm] "id": int, "number": int, "title": str, "body": str | None, "state": str, "user": dict[str, Any], "created_at": str, "updated_at": str, "labels": list[dict[str, Any]], }, ) - src/mcp_github/issues_pr_analyser.py:137-148 (registration)The `_register_tools` and `register_tools` methods that dynamically discover and register all public methods from `GitHubIntegration` (including `create_issue`) as MCP tools 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)