remove_issue_label
Removes a specified label from an issue in a GitHub repository. Requires repository owner, repository name, issue number, and label name as inputs.
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
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- MCP tool handler for 'remove_issue_label'. Validates parameters, checks if the label exists on the issue, calls the operations layer, and returns a 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 model RemoveIssueLabelParams defining input parameters: owner, repo (inherited), issue_number, label with validation.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
- src/pygithub_mcp_server/tools/issues/tools.py:439-463 (registration)Registration function for issue tools that includes 'remove_issue_label' in the list and registers all via register_tools with the MCP server.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")
- Low-level helper function implementing the GitHub API call to remove a label from an issue using PyGithub's remove_from_labels.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)