update_issue_comment
Modify GitHub issue comments by specifying repository details, issue number, comment ID, and updated text. Returns the revised comment for verification.
Instructions
Update an issue comment.
Args:
params: Parameters for updating a comment including:
- owner: Repository owner (user or organization)
- repo: Repository name
- issue_number: Issue number containing the comment
- comment_id: Comment ID to update
- body: New comment text
Returns:
Updated comment details from GitHub API
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Input Schema (JSON Schema)
{
"$defs": {
"UpdateIssueCommentParams": {
"description": "Parameters for updating an issue comment.",
"properties": {
"body": {
"description": "New comment text",
"title": "Body",
"type": "string"
},
"comment_id": {
"description": "Comment ID to update",
"title": "Comment Id",
"type": "integer"
},
"issue_number": {
"description": "Issue number containing the comment",
"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",
"comment_id",
"body"
],
"title": "UpdateIssueCommentParams",
"type": "object"
}
},
"properties": {
"params": {
"$ref": "#/$defs/UpdateIssueCommentParams"
}
},
"required": [
"params"
],
"title": "update_issue_commentArguments",
"type": "object"
}
Implementation Reference
- The main MCP tool handler decorated with @tool(). It receives parameters, validates them via Pydantic, delegates to operations layer, handles errors, and returns MCP-standard response.@tool() def update_issue_comment(params: UpdateIssueCommentParams) -> dict: """Update an issue comment. Args: params: Parameters for updating a comment including: - owner: Repository owner (user or organization) - repo: Repository name - issue_number: Issue number containing the comment - comment_id: Comment ID to update - body: New comment text Returns: Updated comment details from GitHub API """ try: logger.debug(f"update_issue_comment called with params: {params}") # Pass the Pydantic model directly to the operation result = issues.update_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 schema/model defining input parameters for the update_issue_comment tool, including validation for non-empty body.class UpdateIssueCommentParams(RepositoryRef): """Parameters for updating an issue comment.""" model_config = ConfigDict(strict=True) issue_number: int = Field(..., description="Issue number containing the comment") comment_id: int = Field(..., description="Comment ID to update") body: str = Field(..., description="New 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
- src/pygithub_mcp_server/tools/issues/tools.py:439-463 (registration)Registration function that adds the update_issue_comment tool (line 455 in the list) 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 implementation that performs the actual GitHub API calls using PyGithub to update the issue comment. Called by the tool handler.def update_issue_comment(params: UpdateIssueCommentParams) -> Dict[str, Any]: """Update an issue comment. Args: params: Validated parameters for updating a comment Returns: Updated 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.get_comment(params.comment_id) comment.edit(params.body) return convert_issue_comment(comment) except GithubException as e: raise GitHubClient.get_instance()._handle_github_exception(e)