Skip to content

feat: Add tool for discussion comment write operations - #2427

Merged
kerobbi merged 12 commits into
mainfrom
rosstarrant/add-discussion-comment-write-ops
May 15, 2026
Merged

kerobbi merged 12 commits into
mainfrom
rosstarrant/add-discussion-comment-write-ops

Conversation

@RossTarrant

@RossTarrant RossTarrant commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a discussion_comment_write tool to the discussions toolset, enabling AI agents to add, reply to, update, delete, and mark/unmark comments as the answer on GitHub Discussions. Also enhances get_discussion_comments with an optional includeReplies parameter.

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

  • New discussion_comment_write tool in pkg/github/discussions.go consolidating 6 write operations (add, reply, update, delete, mark_answer, unmark_answer) into a single method-dispatching tool
  • Added includeReplies optional param to get_discussion_comments, returning nested replies (up to GitHub's 100-reply API limit per comment)
  • New MinimalDiscussionComment type in pkg/github/minimal_types.go with reply support
  • Updated README.md via script/generate-docs
  • Added tests related to changes in pkg/github/discussions_test.go

MCP impact

  • New tool added — discussion_comment_write
  • Tool schema or behavior changed — get_discussion_comments gains optional includeReplies parameter;

Prompts tested (tool changes only)

  • "Add a comment to discussion #XXX in the github-mcp-server repo saying 'Thanks for the update!'"
  • "Reply to comment node ID DC_xxx on discussion #XXX with 'Great point!'"
  • "Mark comment DC_xxx as the answer to discussion #XXX
  • "Delete my comment DC_xxx on discussion #XXX"
  • "Get all comments on discussion #XXX including replies"

Security / limits

  • Auth / permissions considered — write operations require a token with appropriate Discussion write scopes; the tool is not marked ReadOnlyHint
  • Data exposure, filtering, or token/size limits considered — includeReplies fetches up to 100 replies per comment (GitHub API maximum), documented in the parameter description

Tool renaming

  • I am not renaming tools as part of this PR

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Docs

  • Updated (README via script/generate-docs)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@RossTarrant
RossTarrant marked this pull request as ready for review May 5, 2026 12:26
@RossTarrant
RossTarrant requested a review from a team as a code owner May 5, 2026 12:26
Copilot AI review requested due to automatic review settings May 5, 2026 12:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/body is passed straight through to the mutation. That produces confusing GraphQL failures instead of the normal local missing required parameter error path used by the repo's other write tools.
			var params struct {
				CommentNodeID string
				Body          string
			}
			if err := mapstructure.WeakDecode(args, &params); err != nil {

pkg/github/discussions.go:820

  • This has the same required-parameter hole as the other new discussion write tools: commentNodeID is only weak-decoded, so missing or blank values are sent to GitHub instead of being rejected up front with a missing required parameter tool error.
			var params struct {
				CommentNodeID string
			}
			if err := mapstructure.WeakDecode(args, &params); err != nil {
				return utils.NewToolResultError(err.Error()), nil, nil
  • Files reviewed: 10/10 changed files
  • Comments generated: 6

Comment thread pkg/github/minimal_types.go
Comment thread pkg/github/discussions.go Outdated
Comment thread pkg/github/discussions.go Outdated
Comment thread pkg/github/discussions.go
Comment thread pkg/github/discussions.go Outdated
Comment thread README.md Outdated
@RossTarrant RossTarrant self-assigned this May 7, 2026
@RossTarrant RossTarrant changed the title feat: Add tools for discussion comment write operations feat: Add tool for discussion comment write operations May 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

Comments suppressed due to low confidence (3)

pkg/github/discussions.go:873

  • commentNodeID isn’t trimmed/validated for whitespace here, so a value like " " passes RequiredParam and produces a confusing backend GraphQL error. Consider applying the same strings.TrimSpace blank check used in replyToDiscussionComment.
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, commentNodeID is only checked for empty string. A whitespace-only value will pass and then fail at the GitHub API. Consider rejecting strings.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

  • commentNodeID should probably be validated for whitespace-only input (not just "") the same way it is for the reply method, 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

Comment thread pkg/github/discussions.go Outdated
Comment thread pkg/github/discussions.go
Comment thread pkg/github/discussions.go

@kerobbi kerobbi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me overall! Just a couple of comments 🙂

Comment thread pkg/github/discussions.go Outdated
Comment thread pkg/github/discussions_test.go
Comment thread pkg/github/discussions.go Outdated
Comment thread pkg/github/discussions_test.go Outdated
RossTarrant and others added 6 commits May 13, 2026 14:37
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
SamMorrowDrums pushed a commit that referenced this pull request Jun 8, 2026
* 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>
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
github-mcp-server 1.0.5

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* Add ifc label for list_issues tool by @gokhanarkan in github/github-mcp-server#2453
* Add ifc label for get_file_contents tool by @gokhanarkan in github/github-mcp-server#2454
* Add missing pagination on get_reviews by @RossTarrant in github/github-mcp-server#2367
* Add optional `rationale` parameter to `update_issue_type` tool by @alondahari in github/github-mcp-server#2458
* Add ifc label for search_issues tool by @gokhanarkan in github/github-mcp-server#2456
* Add ifc label for issue_read tool by @gokhanarkan in github/github-mcp-server#2457
* Add ifc label for search_repositories tool by @gokhanarkan in github/github-mcp-server#2459
* Return minimal code search results with text match snippets by @SamMorrowDrums in github/github-mcp-server#2476
* Replace ingress IFC reader list with private marker by @gokhanarkan in github/github-mcp-server#2478
* Document Copilot Spaces PAT requirements by @Bestra in github/github-mcp-server#2479
* Add tool to list repo collaborators by @JoannaaKL in github/github-mcp-server#2477
* Add tool for discussion comment write operations by @RossTarrant in github/github-mcp-server#2427
* Upgrade go-github to v 0.87 by @iulia-b in github/github-mcp-server#2452

## New Contributors
* @alondahari made their first contribution in github/github-mcp-server#2458
* @Bestra made their first contribution in github/github-mcp-server#2479

**Full Changelog**: https://github.com/github/github-mcp-server/compare/v1.0.4...v1.0.5</pre>
  <p>View the full release notes at <a href="https://github.com/github/github-mcp-server/releases/tag/v1.0.5">https://github.com/github/github-mcp-server/releases/tag/v1.0.5</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!3094
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add discussion comment write operations to discussions toolset

4 participants