Skip to content

Commit d0f8aaf

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 b222072 commit d0f8aaf

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 combined commit status of a head commit in a pull request.

pkg/github/issues.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,90 @@ func AddIssueComment(t translations.TranslationHelperFunc) inventory.ServerTool
702702
})
703703
}
704704

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