Skip to main content
Glama
by AstroMined

add_issue_comment

Add comments to GitHub issues by specifying repository owner, repository name, issue number, and comment text. Returns details of the created comment using the GitHub API.

Instructions

Add a comment to an issue.

Args: params: Parameters for adding a comment including: - owner: Repository owner (user or organization) - repo: Repository name - issue_number: Issue number to comment on - body: Comment text Returns: Created comment details from GitHub API

Input Schema

NameRequiredDescriptionDefault
paramsYes

Input Schema (JSON Schema)

{ "$defs": { "IssueCommentParams": { "description": "Parameters for adding a comment to an issue.", "properties": { "body": { "description": "Comment text", "title": "Body", "type": "string" }, "issue_number": { "description": "Issue number to comment on", "title": "Issue Number", "type": "integer" }, "owner": { "description": "Repository owner (username or organization)", "title": "Owner", "type": "string" }, "repo": { "description": "Repository name", "title": "Repo", "type": "string" } }, "required": [ "owner", "repo", "issue_number", "body" ], "title": "IssueCommentParams", "type": "object" } }, "properties": { "params": { "$ref": "#/$defs/IssueCommentParams" } }, "required": [ "params" ], "title": "add_issue_commentArguments", "type": "object" }

Implementation Reference

  • MCP tool handler for 'add_issue_comment'. Validates input using IssueCommentParams, delegates to operations.issues.add_issue_comment(), handles errors, and returns formatted MCP response with JSON content.
    @tool() def add_issue_comment(params: IssueCommentParams) -> dict: """Add a comment to an issue. Args: params: Parameters for adding a comment including: - owner: Repository owner (user or organization) - repo: Repository name - issue_number: Issue number to comment on - body: Comment text Returns: Created comment details from GitHub API """ try: logger.debug(f"add_issue_comment called with params: {params}") # Pass the Pydantic model directly to the operation result = issues.add_issue_comment(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 model defining input schema for add_issue_comment tool, including repo reference (owner/repo), issue_number, body with validation ensuring non-empty body.
    class IssueCommentParams(RepositoryRef): """Parameters for adding a comment to an issue.""" model_config = ConfigDict(strict=True) issue_number: int = Field(..., description="Issue number to comment on") body: str = Field(..., description="Comment text") @field_validator('body') @classmethod def validate_body(cls, v): """Validate that body is not empty.""" if not v.strip(): raise ValueError("body cannot be empty") return v
  • Registration function that collects all issue tools including add_issue_comment and registers them 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")
  • Core implementation of adding an issue comment using PyGithub client: retrieves repo and issue, calls create_comment, converts result using convert_issue_comment.
    def add_issue_comment(params: IssueCommentParams) -> Dict[str, Any]: """Add a comment to an issue. Args: params: Validated parameters for adding a comment Returns: Created comment 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}") issue = repository.get_issue(params.issue_number) comment = issue.create_comment(params.body) return convert_issue_comment(comment) 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