Skip to content

feat(pull_requests): add MCP tools for GitHub Stacked PRs (#2905) - #2908

Open
ruhaanpathan wants to merge 3 commits into
github:mainfrom
ruhaanpathan:feat/stacked-pr-tools
Open

feat(pull_requests): add MCP tools for GitHub Stacked PRs (#2905)#2908
ruhaanpathan wants to merge 3 commits into
github:mainfrom
ruhaanpathan:feat/stacked-pr-tools

Conversation

@ruhaanpathan

Copy link
Copy Markdown

Summary

Adds 5 new MCP tools (get_stack, list_stacks, link_stack, update_stack, dissolve_stack) to the pull_requests toolset to support native GitHub Stacked PRs.

Why

Agents managing stacked/dependent PRs currently lack a first-class way to discover, create, update, and dissolve native GitHub Stacked PR objects via MCP without needing host gh CLI access.
Fixes #2905

What changed

  • Added pkg/github/pullrequests_stacks.go implementing get_stack, list_stacks, link_stack, update_stack, and dissolve_stack.
  • Registered all 5 Stacked PR tools in pkg/github/tools.go under ToolsetMetadataPullRequests.
  • Updated generatePullRequestsToolsetInstructions in pkg/github/toolset_instructions.go with stacked PR guidance.
  • Added unit test suite in pkg/github/pullrequests_stacks_test.go.

MCP impact

  • New tool added
    Added get_stack, list_stacks, link_stack, update_stack, and dissolve_stack tools under the pull_requests toolset.

Prompts tested (tool changes only)

Security / limits

  • Auth / permissions considered
    Requires standard repo OAuth scope matching other pull request management tools.

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
    • I have added the new tool aliases in deprecated_tool_aliases.go
  • I am not renaming tools as part of this PR

Lint & tests

  • Tested locally with ./script/test
    Added unit tests covering tool definitions, input schemas, and HTTP API execution handlers.

Docs

  • Updated (README / docs / examples)
    Updated toolset instructions for pull_requests.

@ruhaanpathan
ruhaanpathan requested a review from a team as a code owner July 19, 2026 11:28
Copilot AI review requested due to automatic review settings July 19, 2026 11:28

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@jdpt0

jdpt0 commented Aug 25, 2026

Copy link
Copy Markdown

Thanks for working on this — native stacked-PR support would be genuinely useful for us. We use agents to maintain dependent, reviewable PRs in a monorepo and currently have to mark and resynchronise GitHub stacks manually.

I tested this branch against current main and compared it with GitHub’s published Stacked Pull Requests REST API. It looks like it now needs rebasing and some API updates:

  • It no longer compiles against the current go-github/v89 request signatures.
  • GitHub documents the request field as pull_requests, rather than pull_numbers.
  • The documented mutations are POST /stacks/{stack_number}/add and POST /stacks/{stack_number}/unstack; the current PATCH and DELETE calls don’t appear to exist.
  • The response model differs from the documented schema, including number, base.ref, and nested pull-request refs.
  • The implementation should confirm support for API version 2026-03-10.

I’d be happy to help rebase and update this. Would the author and maintainers prefer contributions to this branch, or a replacement PR preserving attribution?

ruhaanpathan and others added 2 commits September 3, 2026 16:04
Use the 2026-03-10 native stack endpoints, consolidate the tool surface, and cover pagination, validation, scopes, and unstack outcomes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@leuasseurfarrelds247-arch

Copy link
Copy Markdown

Summary

Adds 5 new MCP tools (get_stack, list_stacks, link_stack, update_stack, dissolve_stack) to the pull_requests toolset to support native GitHub Stacked PRs.

Why

Agents managing stacked/dependent PRs currently lack a first-class way to discover, create, update, and dissolve native GitHub Stacked PR objects via MCP without needing host gh CLI access.
Fixes #2905

What changed

  • Added pkg/github/pullrequests_stacks.go implementing get_stack, list_stacks, link_stack, update_stack, and dissolve_stack.
  • Registered all 5 Stacked PR tools in pkg/github/tools.go under ToolsetMetadataPullRequests.
  • Updated generatePullRequestsToolsetInstructions in pkg/github/toolset_instructions.go with stacked PR guidance.
  • Added unit test suite in pkg/github/pullrequests_stacks_test.go.

MCP impact

  • New tool added
    Added get_stack, list_stacks, link_stack, update_stack, and dissolve_stack tools under the pull_requests toolset.

Prompts tested (tool changes only)

Security / limits

  • Auth / permissions considered
    Requires standard repo OAuth scope matching other pull request management tools.

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
    • I have added the new tool aliases in deprecated_tool_aliases.go
  • I am not renaming tools as part of this PR

Lint & tests

  • Tested locally with ./script/test
    Added unit tests covering tool definitions, input schemas, and HTTP API execution handlers.

Docs

  • Updated (README / docs / examples)
    Updated toolset instructions for pull_requests.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pkg/github/toolset_instructions.go

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.

🟡 Changes recommended

The documented tool contract does not match the implementation, and unsupported GHES hosts expose unusable tools.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (3)

pkg/github/pullrequests_stacks.go:198

  • The documented exception is inaccurate: the native API leaves pull requests that are merged, currently merging, or queued for merge; a locked conversation is not the condition. This wording can make agents misinterpret a successful partial unstack, so please update it here and regenerate the matching toolsnap/README artifacts.
					"`unstack` removes every removable unmerged pull request and may leave locked or queued pull requests in the stack. "+

pkg/github/pullrequests_stacks_test.go:154

  • The fixture represents a merged pull request (state: closed with merged_at set), not a locked pull request. Rename this subtest to remaining merged pull requests so it documents the actual unstack behavior being tested.
	t.Run("remaining locked pull requests", func(t *testing.T) {

pkg/github/toolset_instructions.go:23

  • This instruction gives agents the wrong postcondition: merged, merging, or merge-queued pull requests can remain after unstack, not locked pull requests. Please use the API's actual categories so agents correctly interpret and report the returned stack.
Stacked PRs workflow: Use 'pull_request_stack_read' to inspect native stack metadata. Use 'pull_request_stack_write' with method 'create' for 2-100 repository pull requests ordered bottom-to-top, 'add' only to append new pull requests above the current top, and 'unstack' to remove every removable unmerged pull request. Native stack operations require same-repository branches in an existing linear base/head chain; they do not create pull requests, retarget bases, rebase commits, push branches, or merge. After 'unstack', inspect the result because locked or queued pull requests can remain.`
  • Files reviewed: 7/7 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment on lines +210 to +213
"method": {
Type: "string",
Description: "The write operation: `create`, `add`, or `unstack`.",
Enum: []any{"create", "add", "unstack"},
Comment thread pkg/github/tools.go Outdated
Comment on lines +291 to +292
PullRequestStackRead(t),
PullRequestStackWrite(t),
Comment thread pkg/github/tools.go Outdated
Comment on lines +291 to +292
PullRequestStackRead(t),
PullRequestStackWrite(t),

@leuasseurfarrelds247-arch leuasseurfarrelds247-arch left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hide native stack tools and instructions on GHES, and conservatively label stack responses as repository user content.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f37b1980-3ec0-4b4e-9795-c9d8b448555e

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.

🟡 Changes recommended

Resolve the API contract mismatch and prevent read-only instructions from naming an unavailable write tool.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

pkg/github/tools.go:292

  • The registered MCP surface does not match this PR's stated contract: the description and tested prompts promise five tools named get_stack, list_stacks, link_stack, update_stack, and dissolve_stack, but these lines expose only two grouped tools whose write methods are create, add, and unstack; there is no update/reorder/drop operation. Clients following the documented names and prompts cannot invoke this implementation. Either expose the promised names and semantics or revise the PR contract and prompts to the consolidated API before merge.
		PullRequestStackRead(t, opts...),
		PullRequestStackWrite(t, opts...),
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread README.md
- `repo`: Repository name (string, required)
- `threadId`: The node ID of the review thread (e.g., PRRT_kwDOxxx). Required for resolve_thread and unresolve_thread methods. Get thread IDs from pull_request_read with method get_review_comments. (string, optional)

- **pull_request_stack_read** - Read pull request stacks
Comment on lines +27 to +31
if inventoryHasAvailableTool(inv, "pull_request_stack_read") {
instructions += `

Stacked PRs workflow: Use 'pull_request_stack_read' to inspect native stack metadata. Use 'pull_request_stack_write' with method 'create' for 2-100 repository pull requests ordered bottom-to-top, 'add' only to append new pull requests above the current top, and 'unstack' to remove every removable unmerged pull request. Native stack operations require same-repository branches in an existing linear base/head chain; they do not create pull requests, retarget bases, rebase commits, push branches, or merge. After 'unstack', inspect the result because locked or queued pull requests can remain.`
}
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 MCP tools for GitHub Stacked PRs (gh stack link / sync / view)

5 participants