Skip to main content
Glama
AstroMined

PyGithub MCP Server

by AstroMined

create_issue

Create new issues in GitHub repositories by specifying owner, repo, title, body, assignees, labels, and milestones.

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

TableJSON Schema
NameRequiredDescriptionDefault
params_dictYes

Implementation Reference

  • MCP tool handler function decorated with @tool(). Validates input parameters using CreateIssueParams, delegates to operations.issues.create_issue, 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 model defining input parameters and validation 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
  • Core operation function that performs the actual GitHub API call to create the issue using PyGithub.
    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)
  • Registration function that registers the create_issue tool (and others) with the MCP server using register_tools.
    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")
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses that this is a creation/mutation operation ('Create a new issue') and mentions the GitHub API as the backend, but lacks details on permissions required, rate limits, error handling, or what 'Created issue details' includes. It provides basic behavioral context but misses critical operational traits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (Args, Returns) and uses bullet points for parameters, making it easy to scan. It's appropriately sized with no redundant information, though the 'Args' and 'Returns' headers could be more integrated into the flow.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a complex nested parameter structure, the description is moderately complete. It covers the purpose and parameters well but lacks details on return values (beyond a vague phrase), error conditions, authentication needs, or rate limits, which are crucial for a mutation tool in this context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It comprehensively lists 7 parameters within 'params_dict' with clear names and optionality notes, adding significant meaning beyond the generic schema. However, it doesn't specify data formats (e.g., string types for 'owner') or constraints, leaving some ambiguity.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Create a new issue') and resource ('in a GitHub repository'), distinguishing it from siblings like 'update_issue' or 'list_issues'. It uses precise language that leaves no ambiguity about the tool's function.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by specifying the resource (GitHub repository) but doesn't explicitly state when to use this tool versus alternatives like 'update_issue' or 'list_issues'. No guidance is provided on prerequisites, exclusions, or comparative contexts with sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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