Skip to content

fix(github-mcp): return the issue or PR together with its comments - #19

Merged
Martin Bens (SpiGAndromeda) merged 3 commits into
mainfrom
fix/view-with-comments
Oct 3, 2026
Merged

Martin Bens (SpiGAndromeda) merged 3 commits into
mainfrom
fix/view-with-comments

Conversation

@SpiGAndromeda

@SpiGAndromeda Martin Bens (SpiGAndromeda) commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #17.

Run without a terminal, gh issue view --comments and gh pr view --comments print only the comment list and return before the preview (pkg/cmd/issue/view/view.go, pkg/cmd/pr/view/view.go in cli/cli). issue_view with with_comments: true and pr_view with comments: true passed that flag, so they returned the comments without the title, body, or metadata, and nothing at all for an item without comments, although both schema descriptions promise the comments in addition to the item.

Changes

  • _gh_view_with_comments (lib/common.sh): runs the view once for the preview and once with --comments, then appends the comments after a --- comments --- line, or --- comments and reviews --- for a PR, because gh's PR list includes reviews. With no comments, the result is the preview alone. Both calls go through _gh_capture_split, so a gh warning on stderr never counts as a comment; a failed call reports its stderr. The --comments call is logged.
  • Always two calls: gh's raw PR preview prints no comment count, so there is nothing to skip the second call on. The cost is one extra gh call whenever the flag is set.
  • Failures: a failure of either call fails the tool call, or returns fallback. It never returns the item without its comments, which would read as an item that has none.
  • max_lines counts the item and its comments together, like on every other tool. Before, it applied to the comments alone, because the preview was missing.
  • Docs: the schema descriptions of with_comments and comments name the separator, the reviews, and the max_lines behavior. REFERENCE.md describes the same and lists the known limits.

Known limits

The item and its comments come from two gh calls, not one --json …,comments call rendered with jq. That keeps gh's own text format, and costs these:

  • A comment posted or deleted between the calls makes the issue's comments: count disagree with the list.
  • gh leaves hidden (minimized) comments out of the list, so an item whose only comments are hidden shows no separator.
  • The separator is plain text, so a body containing the same line reads as the start of the comments.

Run without a terminal, `gh issue view --comments` and `gh pr view --comments` print only the comment list and skip the preview. issue_view with with_comments and pr_view with comments passed that flag, so they returned the comments without the title, body, or metadata, and empty output for an item without comments, although both schema descriptions promise the comments in addition to the item.

A new _gh_view_with_comments helper runs the view once for the preview and once with `--comments`, then appends the comments after a `--- comments ---` line, or `--- comments and reviews ---` for a PR, because gh's PR list includes reviews. The second call always runs because gh's PR preview prints no comment count to decide on. A failure of either call fails the tool call or returns fallback, never the preview on its own. REFERENCE.md describes the separator lines for both tools.

Co-Authored-By: Claude <noreply@anthropic.com>
_gh_view_with_comments captured each call's stderr together with its stdout, so without suppress_errors a gh warning on an item without comments produced a `--- comments ---` line followed by the warning. Both calls now go through _gh_capture_split: the separator depends on the comments output alone, a warning on a successful call is dropped as in the other tools that capture stderr apart, and a failed call reports its stderr. The helper no longer takes suppress_errors, since the callers already decide whether to print a failure. It logs the --comments call, which the server log left out.

The schema descriptions of with_comments and comments now name the separator, the reviews in a PR's list, and that max_lines counts the item and its comments together. REFERENCE.md corrects the with_field_values case and lists the known limits of the two calls: a comment count that can disagree with the list, hidden comments gh leaves out, and a separator a body can contain.

New tests cover a warning on an item without comments, a failed first call that skips the comments call, fallback when the comments call fails, the number and --repo reaching the comments call, and fields turning the flag off.

Co-Authored-By: Claude <noreply@anthropic.com>
pi's tool_search adds each tool's parameter descriptions to its search text. The new description of pr_view's comments repeated "comments" and "reviews", so pr_comments ranked 6th and pr_reviews 4th, past the limits tool-search-ranking.test.ts allows (5th and 3rd). The description in tools-read.json now names those words once at most and leaves the separator text and the reviews to REFERENCE.md.

Co-Authored-By: Claude <noreply@anthropic.com>
@SpiGAndromeda
Martin Bens (SpiGAndromeda) merged commit 7c6cc92 into main Oct 3, 2026
1 check passed
@SpiGAndromeda
Martin Bens (SpiGAndromeda) deleted the fix/view-with-comments branch October 3, 2026 14:38
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.

issue_view with_comments and pr_view comments return only the comments, and nothing when there are none

1 participant