feat: Add tools for discussion comment write operations#2427
Open
RossTarrant wants to merge 3 commits intomainfrom
Open
feat: Add tools for discussion comment write operations#2427RossTarrant wants to merge 3 commits intomainfrom
RossTarrant wants to merge 3 commits intomainfrom
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands the Discussions toolset so the MCP server can write discussion comments, edit/delete them, mark answers, and optionally return nested replies from get_discussion_comments.
Changes:
- Added four new discussion comment write tools and registered them in the global tool inventory.
- Extended discussion comment responses with IDs, answer state, and optional nested replies.
- Updated tests, toolsnaps, and generated README documentation to reflect the new Discussions API surface.
Show a summary per file
| File | Description |
|---|---|
README.md |
Documents the new discussion comment tools and includeReplies option. |
pkg/github/tools.go |
Registers the new Discussions tools in AllTools. |
pkg/github/minimal_types.go |
Adds the minimal response type for discussion comments. |
pkg/github/discussions.go |
Implements new discussion comment mutations and reply-aware comment fetching. |
pkg/github/discussions_test.go |
Adds/updates unit tests for the new discussion comment behavior. |
pkg/github/__toolsnaps__/add_discussion_comment.snap |
Snapshot for the add-comment tool schema. |
pkg/github/__toolsnaps__/delete_discussion_comment.snap |
Snapshot for the delete-comment tool schema. |
pkg/github/__toolsnaps__/get_discussion_comments.snap |
Snapshot update for the new includeReplies input. |
pkg/github/__toolsnaps__/set_discussion_comment_answer.snap |
Snapshot for the answer-toggle tool schema. |
pkg/github/__toolsnaps__/update_discussion_comment.snap |
Snapshot for the update-comment tool schema. |
Copilot's findings
Comments suppressed due to low confidence (2)
pkg/github/discussions.go:752
- This handler never validates its required fields after weak-decoding, so an omitted or empty
commentNodeID/bodyis passed straight through to the mutation. That produces confusing GraphQL failures instead of the normal localmissing required parametererror path used by the repo's other write tools.
var params struct {
CommentNodeID string
Body string
}
if err := mapstructure.WeakDecode(args, ¶ms); err != nil {
pkg/github/discussions.go:820
- This has the same required-parameter hole as the other new discussion write tools:
commentNodeIDis only weak-decoded, so missing or blank values are sent to GitHub instead of being rejected up front with amissing required parametertool error.
var params struct {
CommentNodeID string
}
if err := mapstructure.WeakDecode(args, ¶ms); err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
- Files reviewed: 10/10 changed files
- Comments generated: 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds four write operation tools to the
discussionstoolset:add_discussion_commentupdate_discussion_commentdelete_discussion_commentset_discussion_comment_answerenabling AI agents to participate in GitHub Discussions, not just read them. Also enhances
get_discussion_commentsto optionally include nested replies.Why
The
discussionstoolset previously only supported read operations. AI agents could read discussion threads but had no way to post, edit, or delete comments, or mark an answer. Theadd_issue_commenttool returns 404 for Discussions because they use GraphQL, not the REST Issues API.Fixes #1908
What changed
AddDiscussionCommenttool inpkg/github/discussions.goUpdateDiscussionCommenttool inpkg/github/discussions.goDeleteDiscussionCommenttool inpkg/github/discussions.goSetDiscussionCommentAnswertool inpkg/github/discussions.goGetDiscussionCommentswith optionalincludeRepliesparameter and richer response shape (ID,isAnswer, nested replies)MinimalDiscussionCommenttype inpkg/github/minimal_types.gopkg/github/tools.gopkg/github/__toolsnaps__/README.mdviascript/generate-docsMCP impact
New tool added
Four new write tools added:
add_discussion_comment,update_discussion_comment,delete_discussion_comment,set_discussion_comment_answer. The existingget_discussion_commentstool schema was also extended with theincludeRepliesparameter and now returns richer comment objects (ID,isAnswer, optional replies). Toolsnaps updated withUPDATE_TOOLSNAPS=true go test ./....Prompts tested (tool changes only)
Security / limits
Write operations require a token with
write:discussionscope. The tools use the existinggithubv4GraphQL client and follow the same auth patterns as other write tools in the codebase.Tool renaming
Lint & tests
./script/lint./script/testDocs