Skip to content

Add pull request auto-merge tool - #3986

Open
timrogers wants to merge 3 commits into
mainfrom
copilot/enable-pull-request-auto-merge
Open

timrogers wants to merge 3 commits into
mainfrom
copilot/enable-pull-request-auto-merge

Conversation

@timrogers

@timrogers timrogers commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add a tool to enable auto-merge behind the pull_requests_granular feature flag and expose its state when reading a pull request.

Why

Agents currently have a tool to merge immediately but cannot schedule a merge after GitHub's requirements are met. No linked issue.

What changed

  • Add enable_pull_request_auto_merge, using GitHub's GraphQL mutation and matching merge_pull_request's input schema.
  • Add nullable auto_merge state, merge method, and enabler to pull_request_read's get response without changing list responses.
  • Cover feature gating, argument mapping, errors, MCP protocol output, and tool snapshots; update the pull-request-authoring skill and generated feature-flag documentation.

MCP impact

  • No tool or API changes
  • Tool schema or behavior changed
  • New tool added

The new write tool is available only when pull_requests_granular is enabled. GitHub defaults to the merge method if none is supplied. pull_request_read returns auto_merge: null when disabled or an object when enabled.

Prompts tested (tool changes only)

  • No natural-language prompts tested. Mocked MCP calls exercise enabling auto-merge with defaults and with a squash method, commit text, and expected head SHA.
  • Mocked MCP calls verify enabled and disabled pull_request_read results across supported protocol versions.
  • Also tested live MCP tools/call requests against GitHub from a locally built server at PR head 83d4823, with pull_requests_granular enabled:
    • On a review-blocked PR in a separate repository with auto-merge enabled, a call with merge_method: squash and the current expectedHeadSha succeeded. GitHub confirmed auto-merge was enabled; it was then disabled and confirmed off.
    • An incorrect expectedHeadSha was rejected and left auto-merge disabled.
    • Calls against this PR and a draft PR were rejected because the repository had auto-merge disabled and the PR was a draft, respectively; neither changed state.
    • The successful test repository uses a merge queue, so GitHub ignored the requested squash method and reported MERGE.

Security / limits

  • No security or limits impact
  • Auth / permissions considered
  • Data exposure, filtering, or token/size limits considered

The tool requires the repo scope; GitHub enforces repository permissions and auto-merge eligibility. An expected head SHA can guard against enabling auto-merge on a changed head.

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

No existing tools were renamed.

Note: if you're renaming tools, you must add the tool aliases. For more information on how to do so, please refer to the official docs.

Lint & tests

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

Also passed: UPDATE_TOOLSNAPS=true go test ./... and script/generate-docs.
go build -o /root/.copilot/session-state/bd4800d3bbe24f9d8fc6e277cef7753b/files/github-mcp-auto-merge ./cmd/github-mcp-server — passed for the live MCP tests above.

Docs

  • Not needed
  • Updated (README / docs / examples)

Regenerated docs/feature-flags.md with the new tool.

Skills

  • Updated relevant skills or confirmed no bundled skill applies

Updated the pull-request-authoring skill and its tool catalog.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@timrogers
timrogers requested a review from a team as a code owner November 30, 2026 03:12
Copilot AI adaptive review requested due to automatic review settings November 30, 2026 03:13
}
} `graphql:"enablePullRequestAutoMerge(input: $input)"`
}
if err := client.Mutate(ctx, &mutation, mutationInput, nil); err != nil {

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.

🔵 Needs a closer look

The new write tool authorizes future repository merges, extending effects beyond the current call and introducing authorization, branch-protection, and later-head-change interactions that warrant human review.

No open issues 🎉

What changed in this PR

Adds enable_pull_request_auto_merge behind the pull_requests_granular feature flag, letting agents schedule a merge once GitHub’s requirements are met rather than merge immediately.

Changes:

  • Implements the GraphQL mutation using the existing merge tool’s input schema.
  • Adds coverage for argument mapping, errors, feature gating, protocol output, and tool snapshots.
  • Updates the pull-request-authoring skill and generated feature-flag documentation.
File Description
pkg/​skills/​catalog/​tools.go Adds auto-merge to the authoring skill’s optional tools.
pkg/​skills/​catalog/​skills/​pull-request-authoring/​SKILL.md Explains auto-merge behavior and required user confirmation.
pkg/​github/​typed_granular_pull_request_outputs_test.go Covers typed protocol output and error handling.
pkg/​github/​tools.go Registers the new tool.
pkg/​github/​pullrequests.go Extracts the shared merge input schema.
pkg/​github/​pull_request_auto_merge.go Implements validation, GraphQL calls, and feature gating.
pkg/​github/​pull_request_auto_merge_test.go Tests defaults, options, failures, and feature gating.
pkg/​github/​granular_tools_test.go Updates expected granular tool availability.
pkg/​github/​__toolsnaps__/​enable_pull_request_auto_merge.snap Records the new tool’s schema and metadata.
docs/​feature-flags.md Documents the tool’s inputs and required scope.

Review effort: Balanced (adaptive)

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 auto-merge description can prompt unsupported calls on already mergeable PRs; it should clarify the pending-requirements use case and update the corresponding snapshot.

1 open issue

Review effort: Max

Comment thread pkg/github/pull_request_auto_merge.go Outdated
ToolsetMetadataPullRequests,
mcp.Tool{
Name: "enable_pull_request_auto_merge",
Description: t("TOOL_ENABLE_PULL_REQUEST_AUTO_MERGE_DESCRIPTION", "Enable auto-merge for a pull request when GitHub's merge requirements are met. If merge_method is omitted, GitHub defaults to merge."),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the tool description to say it is for pull requests that cannot be merged immediately because requirements are pending, and regenerated the snapshot (83d4823). script/test and snapshot regeneration passed; script/lint could not download its linter because DNS resolution failed, so hosted lint remains to be evaluated.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

// EnablePullRequestAutoMerge creates a tool to enable auto-merge for a pull request.
func EnablePullRequestAutoMerge(t translations.TranslationHelperFunc) inventory.ServerTool {
st := NewTool[MergePullRequestInput, *RepositoryMessageOutput](
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
)

// EnablePullRequestAutoMerge creates a tool to enable auto-merge for a pull request.
func EnablePullRequestAutoMerge(t translations.TranslationHelperFunc) inventory.ServerTool {
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.

4 participants