Skip to main content
Glama
AstroMined
by AstroMined

create_issue

Automate GitHub issue creation by specifying repository details, title, description, assignees, labels, and milestones using the PyGithub MCP Server. Streamline project management workflows.

Instructions

Create a new issue in a GitHub repository.

Args: params_dict: Parameters for creating an issue including: - owner: Repository owner (user or organization) - repo: Repository name - title: Issue title - body: Issue description (optional) - assignees: List of usernames to assign - labels: List of labels to add - milestone: Milestone number (optional) Returns: Created issue details from GitHub API

Input Schema

NameRequiredDescriptionDefault
params_dictYes

Input Schema (JSON Schema)

{ "properties": { "params_dict": { "title": "Params Dict", "type": "object" } }, "required": [ "params_dict" ], "title": "create_issueArguments", "type": "object" }

Implementation Reference

  • MCP tool handler for create_issue that validates input using CreateIssueParams, calls the operations layer, handles errors, and formats the MCP response.
    @tool() def create_issue(params_dict: dict) -> dict: """Create a new issue in a GitHub repository. Args: params_dict: Parameters for creating an issue including: - owner: Repository owner (user or organization) - repo: Repository name - title: Issue title - body: Issue description (optional) - assignees: List of usernames to assign - labels: List of labels to add - milestone: Milestone number (optional) Returns: Created issue details from GitHub API """ try: # First validate the input params try: params = CreateIssueParams(**params_dict) logger.debug(f"create_issue called with validated params: {params}") except Exception as e: logger.error(f"Failed to convert dict to CreateIssueParams: {e}") return { "content": [{"type": "error", "text": f"Validation error: {str(e)}"}], "is_error": True } # Pass the Pydantic model directly to the operation result = issues.create_issue(params) logger.debug(f"Got result: {result}") response = {"content": [{"type": "text", "text": json.dumps(result, indent=2)}]} logger.debug(f"Returning response: {response}") return response except GitHubError as e: logger.error(f"GitHub error: {e}") return { "content": [{"type": "error", "text": format_github_error(e)}], "is_error": True } except Exception as e: logger.error(f"Unexpected error: {e}") logger.error(traceback.format_exc()) error_msg = str(e) if str(e) else "An unexpected error occurred" return { "content": [{"type": "error", "text": f"Internal server error: {error_msg}"}], "is_error": True }
  • Pydantic input schema model CreateIssueParams that validates parameters for the create_issue tool.
    class CreateIssueParams(RepositoryRef): """Parameters for creating an issue.""" model_config = ConfigDict(strict=True) title: str = Field(..., description="Issue title", strict=True) body: Optional[str] = Field(None, description="Issue description", strict=True) assignees: List[str] = Field(default_factory=list, description="Usernames to assign", strict=True) labels: List[str] = Field(default_factory=list, description="Labels to add", strict=True) milestone: Optional[int] = Field(None, description="Milestone number", strict=True) @field_validator('title') @classmethod def validate_title(cls, v): """Validate that title is not empty.""" if not v.strip(): raise ValueError("title cannot be empty") return v
  • Registration function that adds the create_issue tool (and other issue tools) to the MCP server instance.
    def register(mcp: FastMCP) -> None: """Register all issue tools with the MCP server. Args: mcp: The MCP server instance """ from pygithub_mcp_server.tools import register_tools # List of all issue tools to register issue_tools = [ create_issue, list_issues, get_issue, update_issue, add_issue_comment, list_issue_comments, update_issue_comment, delete_issue_comment, add_issue_labels, remove_issue_label, ] register_tools(mcp, issue_tools) logger.debug(f"Registered {len(issue_tools)} issue tools")
  • Helper function in operations layer that executes the actual GitHub API call via PyGithub's repository.create_issue.
    def create_issue(params: CreateIssueParams) -> Dict[str, Any]: """Create a new issue in a repository. Args: params: Validated parameters for creating an issue Returns: Created issue details from GitHub API Raises: GitHubError: If the API request fails """ try: client = GitHubClient.get_instance() repository = client.get_repo(f"{params.owner}/{params.repo}") # Build kwargs for create_issue using fields from the Pydantic model kwargs = {"title": params.title} # title is required # Add optional parameters only if provided if params.body is not None: kwargs["body"] = params.body if params.assignees: # Only add if non-empty list kwargs["assignees"] = params.assignees if params.labels: # Only add if non-empty list kwargs["labels"] = params.labels if params.milestone is not None: try: kwargs["milestone"] = repository.get_milestone(params.milestone) except Exception as e: logger.error(f"Failed to get milestone {params.milestone}: {e}") raise GitHubError(f"Invalid milestone number: {params.milestone}") # Create issue using PyGithub issue = repository.create_issue(**kwargs) # Convert to our schema return convert_issue(issue) except GithubException as e: raise GitHubClient.get_instance()._handle_github_exception(e)

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/AstroMined/pygithub-mcp-server'

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