create_pr
Create a new pull request in a GitHub repository by specifying the owner, repo, title, body, head branch, base branch, and optional draft status.
Instructions
Creates a new pull request in the specified GitHub repository. Args: repo_owner (str): The owner of the repository. repo_name (str): The name of the repository. title (str): The title of the pull request. body (str): The body content of the pull request. head (str): The name of the branch where your changes are implemented. base (str): The name of the branch you want the changes pulled into. draft (bool, optional): Whether the pull request is a draft. Defaults to False. Returns: Dict[str, Any]: The JSON response from the GitHub API containing pull request information if successful. Error Handling: Logs errors and prints the traceback if the pull request creation fails, returning None.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_owner | Yes | ||
| repo_name | Yes | ||
| title | Yes | ||
| body | Yes | ||
| head | Yes | ||
| base | Yes | ||
| draft | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | ||
| description | Yes | ||
| author | Yes | ||
| created_at | Yes | ||
| updated_at | Yes | ||
| state | Yes |
Implementation Reference
- The create_pr method on GitHubIntegration class - sends POST to /repos/{owner}/{repo}/pulls to create a pull request with title, body, head, base, draft params. Returns PR url, number, status, and title.
def create_pr( self, repo_owner: str, repo_name: str, title: str, body: str, head: str, base: str, draft: bool = False, ) -> PRContent: """ Creates a new pull request in the specified GitHub repository. Args: repo_owner (str): The owner of the repository. repo_name (str): The name of the repository. title (str): The title of the pull request. body (str): The body content of the pull request. head (str): The name of the branch where your changes are implemented. base (str): The name of the branch you want the changes pulled into. draft (bool, optional): Whether the pull request is a draft. Defaults to False. Returns: Dict[str, Any]: The JSON response from the GitHub API containing pull request information if successful. Error Handling: Logs errors and prints the traceback if the pull request creation fails, returning None. """ logger.info(f"Creating PR in {repo_owner}/{repo_name}") pr_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls" try: response = httpx.post( pr_url, headers=self._get_headers(), json={ "title": title, "body": body, "head": head, "base": base, "draft": draft, }, timeout=TIMEOUT, ) self._raise_for_status(response, f"create PR {head} -> {base}") pr_data = response.json() logger.info("PR created successfully") return { "pr_url": pr_data.get("html_url"), "pr_number": pr_data.get("number"), "status": pr_data.get("state"), "title": pr_data.get("title"), } except GitHubAuthError: raise except Exception as e: logger.error(f"Error creating PR: {str(e)}") traceback.print_exc() return {"status": "error", "message": str(e)} - PRContent TypedDict - defines the return type shape for PR operations including title, description, author, created_at, updated_at, state.
type PRContent = TypedDict( "PRContent", { # pyright: ignore[reportInvalidTypeForm] "title": str, "description": str | None, "author": str, "created_at": str, "updated_at": str, "state": str, }, ) - src/mcp_github/issues_pr_analyser.py:137-148 (registration)Registration mechanism: _register_tools() calls register_tools(self.gi) which iterates all non-underscore methods of GitHubIntegration and registers them as MCP tools via self.mcp.add_tool(method). This is how create_pr gets registered as an MCP tool.
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)