Uh oh!
There was an error while loading. Please reload this page.
feat: Add tool for discussion comment write operations - #2427
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (3)
pkg/github/discussions.go:873
commentNodeIDisn’t trimmed/validated for whitespace here, so a value like " " passesRequiredParamand produces a confusing backend GraphQL error. Consider applying the samestrings.TrimSpaceblank check used inreplyToDiscussionComment.
func deleteDiscussionComment(ctx context.Context, client *githubv4.Client, args map[string]any) (*mcp.CallToolResult, any, error) {
commentNodeID, err := RequiredParam[string](args, "commentNodeID")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
pkg/github/discussions.go:908
- As with the other methods,
commentNodeIDis only checked for empty string. A whitespace-only value will pass and then fail at the GitHub API. Consider rejectingstrings.TrimSpace(commentNodeID) == ""to give callers a consistent tool-level error.
func markDiscussionCommentAsAnswer(ctx context.Context, client *githubv4.Client, args map[string]any) (*mcp.CallToolResult, any, error) {
commentNodeID, err := RequiredParam[string](args, "commentNodeID")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
pkg/github/discussions.go:943
commentNodeIDshould probably be validated for whitespace-only input (not just"") the same way it is for thereplymethod, otherwise callers can get opaque GraphQL errors for what is effectively a missing ID.
func unmarkDiscussionCommentAsAnswer(ctx context.Context, client *githubv4.Client, args map[string]any) (*mcp.CallToolResult, any, error) {
commentNodeID, err := RequiredParam[string](args, "commentNodeID")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
- Files reviewed: 7/7 changed files
- Comments generated: 3
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
kerobbi
left a comment
There was a problem hiding this comment.
Looks good to me overall! Just a couple of comments 🙂
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Roberto Nacu <kerobbi@github.com>
Co-authored-by: Roberto Nacu <kerobbi@github.com>
….com:github/github-mcp-server into rosstarrant/add-discussion-comment-write-ops
* Add discussion comment write operation tools Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address comments from Copilot review * Update includeReplies description to specify GitHub API maximum replies limit * Consolidate into single tool * add tests cases for checking param presence * Enhance validation on discussion comment operations * Enhance discussion_write tool description Co-authored-by: Roberto Nacu <kerobbi@github.com> * Remove redundant param Co-authored-by: Roberto Nacu <kerobbi@github.com> * Refactor tests * Fix failing build --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Roberto Nacu <kerobbi@github.com>
Summary
Adds a
discussion_comment_writetool to the discussions toolset, enabling AI agents to add, reply to, update, delete, and mark/unmark comments as the answer on GitHub Discussions. Also enhancesget_discussion_commentswith an optionalincludeRepliesparameter.Why
Closes#1908
The discussions toolset previously only supported read operations. AI agents could read discussions but couldn't participate - posting comments, replying, or marking answers - because Discussions use GraphQL mutations, not the REST Issues API. This change brings write operations to GitHub Discussions, enabling AI agents to fully participate in discussion threads.
What changed
discussion_comment_writetool inpkg/github/discussions.goconsolidating 6 write operations (add,reply,update,delete,mark_answer,unmark_answer) into a single method-dispatching toolincludeRepliesoptional param toget_discussion_comments, returning nested replies (up to GitHub's 100-reply API limit per comment)MinimalDiscussionCommenttype inpkg/github/minimal_types.gowith reply supportREADME.mdviascript/generate-docspkg/github/discussions_test.goMCP impact
discussion_comment_writeget_discussion_commentsgains optionalincludeRepliesparameter;Prompts tested (tool changes only)
DC_xxxon discussion #XXX with 'Great point!'"DC_xxxas the answer to discussion #XXXDC_xxxon discussion #XXX"Security / limits
ReadOnlyHintincludeRepliesfetches up to 100 replies per comment (GitHub API maximum), documented in the parameter descriptionTool renaming
Lint & tests
./script/lint./script/testDocs
script/generate-docs)