Skip to main content
Glama
AstroMined
by AstroMined

add_issue_labels

Add labels to a GitHub issue by specifying repository owner, repository name, issue number, and desired labels. Updates the issue with the new label set via the GitHub API.

Instructions

Add labels to an issue.

Args: params: Parameters for adding labels including: - owner: Repository owner (user or organization) - repo: Repository name - issue_number: Issue number - labels: Labels to add Returns: Updated list of labels from GitHub API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • MCP tool handler function for 'add_issue_labels'. Validates input using Pydantic model via type hints, calls the core operation, handles errors, and formats the JSON response.
    @tool() def add_issue_labels(params: AddIssueLabelsParams) -> dict: """Add labels to an issue. Args: params: Parameters for adding labels including: - owner: Repository owner (user or organization) - repo: Repository name - issue_number: Issue number - labels: Labels to add Returns: Updated list of labels from GitHub API """ try: logger.debug(f"add_issue_labels called with params: {params}") # Pass the Pydantic model directly to the operation result = issues.add_issue_labels(params) logger.debug(f"Got result: {result}") return {"content": [{"type": "text", "text": json.dumps(result, indent=2)}]} 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 AddIssueLabelsParams defining the parameters: owner, repo (inherited), issue_number, labels (non-empty list). Used for validation in the tool handler.
    class AddIssueLabelsParams(RepositoryRef): """Parameters for adding labels to an issue.""" model_config = ConfigDict(strict=True) issue_number: int = Field(..., description="Issue number") labels: List[str] = Field(..., description="Labels to add") @field_validator('labels') @classmethod def validate_labels(cls, v): """Validate that labels list is not empty.""" if not v: raise ValueError("labels list cannot be empty") return v
  • Registration function that adds the add_issue_labels tool (and other issue tools) to the MCP server via 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 helper function that executes the GitHub API logic: retrieves issue, adds labels using PyGithub, returns converted list of updated labels.
    def add_issue_labels(params: AddIssueLabelsParams) -> List[Dict[str, Any]]: """Add labels to an issue. Args: params: Validated parameters for adding labels to an issue Returns: Updated list of labels from GitHub API Raises: GitHubError: If the API request fails """ try: client = GitHubClient.get_instance() repository = client.get_repo(f"{params.owner}/{params.repo}") issue = repository.get_issue(params.issue_number) # Add labels to the issue issue.add_to_labels(*params.labels) # Get fresh issue data to get updated labels updated_issue = repository.get_issue(params.issue_number) return [convert_label(label) for label in updated_issue.labels] 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