Skip to main content
Glama
AstroMined

PyGithub MCP Server

by AstroMined

remove_issue_label

Remove a label from a GitHub issue by specifying repository details, issue number, and label name.

Instructions

Remove a label from an issue.

Args:
    params: Parameters for removing a label including:
        - owner: Repository owner (user or organization)
        - repo: Repository name
        - issue_number: Issue number
        - label: Label to remove

Returns:
    Empty response on success or error if label doesn't exist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • MCP tool handler for remove_issue_label: validates params with RemoveIssueLabelParams, checks if label exists on issue, calls the underlying operation if present, handles errors and returns MCP-formatted response.
    @tool()
    def remove_issue_label(params: RemoveIssueLabelParams) -> dict:
        """Remove a label from an issue.
        
        Args:
            params: Parameters for removing a label including:
                - owner: Repository owner (user or organization)
                - repo: Repository name
                - issue_number: Issue number
                - label: Label to remove
        
        Returns:
            Empty response on success or error if label doesn't exist
        """
        try:
            logger.debug(f"remove_issue_label called with params: {params}")
            
            # First check if the issue exists and has the label
            client = GitHubClient.get_instance()
            repository = client.get_repo(f"{params.owner}/{params.repo}")
            issue = repository.get_issue(params.issue_number)
            
            # Get current labels
            label_names = [label.name for label in issue.labels]
            
            if params.label not in label_names:
                # Label doesn't exist on this issue, return an error
                error_msg = f"Label '{params.label}' does not exist on issue #{params.issue_number}"
                logger.warning(error_msg)
                return {
                    "content": [{"type": "error", "text": error_msg}],
                    "is_error": True
                }
            
            # Now try to remove the label
            issues.remove_issue_label(params)
            logger.debug("Label removed successfully")
            return {"content": [{"type": "text", "text": "Label removed successfully"}]}
        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 RemoveIssueLabelParams defining parameters: owner/repo (inherited), issue_number (int), label (str non-empty). Used for validation in the tool handler.
    class RemoveIssueLabelParams(RepositoryRef):
        """Parameters for removing a label from an issue."""
    
        model_config = ConfigDict(strict=True)
        
        issue_number: int = Field(..., description="Issue number")
        label: str = Field(..., description="Label to remove")
        
        @field_validator('label')
        @classmethod
        def validate_label(cls, v):
            """Validate that label is not empty."""
            if not v.strip():
                raise ValueError("label cannot be empty")
            return v
  • Registration function that adds remove_issue_label (and other issue tools) to 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")
  • Core operation function called by the tool handler: uses PyGithub to remove the label from the issue, handles non-existent label gracefully.
    def remove_issue_label(params: RemoveIssueLabelParams) -> None:
        """Remove a label from an issue.
    
        Args:
            params: Validated parameters for removing a label from an issue
    
        Raises:
            GitHubError: If the API request fails or label doesn't exist
        """
        try:
            client = GitHubClient.get_instance()
            repository = client.get_repo(f"{params.owner}/{params.repo}")
            issue = repository.get_issue(params.issue_number)
            try:
                issue.remove_from_labels(params.label)
            except GithubException as label_e:
                # Handle specific case for non-existent labels
                if label_e.status == 404 and "Label does not exist" in str(label_e):
                    logger.warning(f"Label '{params.label}' does not exist on issue #{params.issue_number}")
                    # Not raising an error since removing a non-existent label is not a failure
                    return
                # Re-raise if it's a different error
                raise label_e
        except GithubException as e:
            raise client._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