Skip to content

Commit 1bb9ff8

Browse files
committed
feat: add update_issue_comment tool
- Add UpdateIssueComment in pkg/github/issues.go: new tool to update an existing issue or PR comment by comment_id (owner, repo, comment_id, body) - Register UpdateIssueComment in pkg/github/tools.go under issues toolset - Document update_issue_comment in README.md Issues section - Uses GitHub REST Issues.EditComment; comment_id from issue_read get_comments or add_issue_comment response
1 parent 48a2a05 commit 1bb9ff8

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,13 @@ The following sets of tools are available:
815815
- `owner`: Repository owner (string, required)
816816
- `repo`: Repository name (string, required)
817817

818+
- **update_issue_comment** - Update an existing issue or pull request comment
819+
- **Required OAuth Scopes**: `repo`
820+
- `body`: New comment content (string, required)
821+
- `comment_id`: ID of the comment to update, from issue_read get_comments or add_issue_comment response (number, required)
822+
- `owner`: Repository owner (string, required)
823+
- `repo`: Repository name (string, required)
824+
818825
- **get_label** - Get a specific label from a repository.
819826
- **Required OAuth Scopes**: `repo`
820827
- `name`: Label name. (string, required)
@@ -1093,8 +1100,8 @@ The following sets of tools are available:
10931100

10941101
- **pull_request_read** - Get details for a single pull request
10951102
- **Required OAuth Scopes**: `repo`
1096-
- `method`: Action to specify what pull request data needs to be retrieved from GitHub.
1097-
Possible options:
1103+
- `method`: Action to specify what pull request data needs to be retrieved from GitHub.
1104+
Possible options:
10981105
1. get - Get details of a specific pull request.
10991106
2. get_diff - Get the diff of a pull request.
11001107
3. get_status - Get status of a head commit in a pull request. This reflects status of builds and checks.

pkg/github/issues.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,90 @@ func AddIssueComment(t translations.TranslationHelperFunc) inventory.ServerTool
697697
})
698698
}
699699

700+
// UpdateIssueComment creates a tool to update an existing comment on an issue (or pull request).
701+
func UpdateIssueComment(t translations.TranslationHelperFunc) inventory.ServerTool {
702+
return NewTool(
703+
ToolsetMetadataIssues,
704+
mcp.Tool{
705+
Name: "update_issue_comment",
706+
Description: t("TOOL_UPDATE_ISSUE_COMMENT_DESCRIPTION", "Update an existing comment on an issue or pull request in a GitHub repository. Use the comment ID from issue_read with method get_comments, or from the comment object when adding a comment."),
707+
Annotations: &mcp.ToolAnnotations{
708+
Title: t("TOOL_UPDATE_ISSUE_COMMENT_USER_TITLE", "Update issue comment"),
709+
ReadOnlyHint: false,
710+
},
711+
InputSchema: &jsonschema.Schema{
712+
Type: "object",
713+
Properties: map[string]*jsonschema.Schema{
714+
"owner": {
715+
Type: "string",
716+
Description: "Repository owner",
717+
},
718+
"repo": {
719+
Type: "string",
720+
Description: "Repository name",
721+
},
722+
"comment_id": {
723+
Type: "number",
724+
Description: "ID of the comment to update (from issue_read get_comments or add_issue_comment response)",
725+
},
726+
"body": {
727+
Type: "string",
728+
Description: "New comment content",
729+
},
730+
},
731+
Required: []string{"owner", "repo", "comment_id", "body"},
732+
},
733+
},
734+
[]scopes.Scope{scopes.Repo},
735+
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
736+
owner, err := RequiredParam[string](args, "owner")
737+
if err != nil {
738+
return utils.NewToolResultError(err.Error()), nil, nil
739+
}
740+
repo, err := RequiredParam[string](args, "repo")
741+
if err != nil {
742+
return utils.NewToolResultError(err.Error()), nil, nil
743+
}
744+
commentID, err := RequiredBigInt(args, "comment_id")
745+
if err != nil {
746+
return utils.NewToolResultError(err.Error()), nil, nil
747+
}
748+
body, err := RequiredParam[string](args, "body")
749+
if err != nil {
750+
return utils.NewToolResultError(err.Error()), nil, nil
751+
}
752+
753+
comment := &github.IssueComment{
754+
Body: github.Ptr(body),
755+
}
756+
757+
client, err := deps.GetClient(ctx)
758+
if err != nil {
759+
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil
760+
}
761+
updatedComment, resp, err := client.Issues.EditComment(ctx, owner, repo, commentID, comment)
762+
if err != nil {
763+
return utils.NewToolResultErrorFromErr("failed to update comment", err), nil, nil
764+
}
765+
defer func() { _ = resp.Body.Close() }()
766+
767+
if resp.StatusCode != http.StatusOK {
768+
body, err := io.ReadAll(resp.Body)
769+
if err != nil {
770+
return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil
771+
}
772+
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to update comment", resp, body), nil, nil
773+
}
774+
775+
r, err := json.Marshal(updatedComment)
776+
if err != nil {
777+
return utils.NewToolResultErrorFromErr("failed to marshal response", err), nil, nil
778+
}
779+
780+
return utils.NewToolResultText(string(r)), nil, nil
781+
})
782+
}
783+
700784
// SubIssueWrite creates a tool to add a sub-issue to a parent issue.
701785
func SubIssueWrite(t translations.TranslationHelperFunc) inventory.ServerTool {
702786
return NewTool(

pkg/github/tools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func AllTools(t translations.TranslationHelperFunc) []inventory.ServerTool {
196196
ListIssueTypes(t),
197197
IssueWrite(t),
198198
AddIssueComment(t),
199+
UpdateIssueComment(t),
199200
SubIssueWrite(t),
200201

201202
// User tools

0 commit comments

Comments
 (0)