Skip to content

Add granular Agent Merge enrollment tool - #3987

Open
timrogers wants to merge 3 commits into
mainfrom
timrogers/agent-merge-granular-tool
Open

timrogers wants to merge 3 commits into
mainfrom
timrogers/agent-merge-granular-tool

Conversation

@timrogers

@timrogers timrogers commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add granular tools to read, enable, update, and disable Agent Merge for a pull request.

Why

Clients need to delegate CI fixes and merge conflict resolution to Copilot from the pull request workflow. No linked issue.

What changed

  • Add update_pull_request_agent_merge_enrollment using the Agent Merge REST API.
  • Add get_pull_request_agent_merge_enrollment to read enabled enrollment and allowed actions.
  • Register the tools behind the granular pull request feature flag and update schema snapshots, documentation, skill, and tests.

MCP impact

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

The read tool takes repository and PR coordinates. The write tool also takes an action array: an empty array disables enrollment; nonempty arrays enable or replace the allowed actions. A read 404 is ambiguous and is returned as an error rather than definitively reporting disabled enrollment.

Prompts tested (tool changes only)

  • Natural-language prompts were not tested. Automated MCP calls cover enabling, updating, disabling, validation, and API errors with a mocked GitHub API.

Security / limits

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

Both tools use the repo OAuth challenge and the API enforces repository write access. Enabling permits asynchronous Copilot actions; it does not merge the PR immediately. The read result is labeled private when IFC labels are enabled because enrollment requires write access even on public repositories.

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

This adds new tools without renaming existing tools.

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.
  • UPDATE_TOOLSNAPS=true go test ./... — passed.
  • go test ./pkg/github -run 'TestUpdatePullRequestAgentMergeEnrollment|TestGranularToolSnaps|TestPullRequestsGranularToolset' -count=1 — passed.
  • go test ./pkg/skills/catalog -run TestCatalogToolRequirementsAreRegistered -count=1 — passed.

Live end-to-end testing on this PR using the locally built server (f4d20848), stdio MCP calls, and the session network/authentication setup — passed:

  • Discovered the tool via tools/list with --features=pull_requests_granular --toolsets=pull_requests.
  • Updated enrollment to ["fix_ci"], disabled it with [], and re-enabled it with ["fix_ci","resolve_merge_conflicts"].
  • Independently verified every transition using the Agent Merge GET API, including 404 after disabling.
  • Verified legacy text output and modern structured output using per-request protocol metadata; stdio initialization negotiates 2025-11-25.
  • Restored and verified the original actions and enrollment owner after testing. The enrollment update timestamp changed as expected.

The original enrollment includes respond_to_copilot_code_reviews, an additional API action the tool's input does not yet accept. Restoring that three-action selection required a direct REST call; the output schema can represent the additional action.

This validates enrollment management, not Copilot execution of CI fixes/conflict resolution or eventual merging.

Live read-tool testing: built the local server with go build -o /root/.copilot/session-state/e21bcb87be2a497fb56b6ded36fd0cb1/files/agent-merge-read-server ./cmd/github-mcp-server and called get_pull_request_agent_merge_enrollment over stdio with --features=pull_requests_granular --toolsets=pull_requests using gh auth token. The call for this PR returned its enabled enrollment and all three existing actions; a call for a nonexistent PR returned a 404 tool error explaining its ambiguity. Both passed without modifying enrollment.

Docs

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

script/generate-docs passed and updated the feature-flag documentation.

Skills

  • Updated relevant skills or confirmed no bundled skill applies

Updated the pull-request-authoring skill to describe enrollment and the authorization boundary.

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:26
Copilot AI adaptive review requested due to automatic review settings November 30, 2026 03:26
if output.Enabled {
target = &output.Enrollment
}
resp, err := client.Do(request, target)

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 enrollment tool grants and revokes persistent permissions for asynchronous repository writes, requiring human review of its authorization lifecycle, ownership, and eligibility boundaries.

No open issues 🎉

What changed in this PR

Adds a granular tool for managing Agent Merge enrollment, allowing clients to delegate CI fixes and merge conflict resolution to Copilot within pull request workflows.

Changes:

  • Supports enabling or replacing allowed actions, and disabling enrollment with an empty array.
  • Registers the tool behind the granular pull request feature flag.
  • Adds validation, API-response and feature-gate tests, schema coverage, documentation, and skill guidance.
File Description
pkg/​skills/​catalog/​tools.go Adds the tool to the pull-request-authoring skill’s optional tools.
pkg/​skills/​catalog/​skills/​pull-request-authoring/​SKILL.md Documents enrollment, authorization, and eligibility requirements.
pkg/​github/​tools.go Registers the new tool.
pkg/​github/​pull_request_agent_merge.go Implements enrollment updates, validation, and API error handling.
pkg/​github/​pull_request_agent_merge_test.go Tests enrollment operations, validation, API responses, and feature gating.
pkg/​github/​granular_tools_test.go Includes the tool in snapshot and toolset checks.
pkg/​github/​__toolsnaps__/​update_pull_request_agent_merge_enrollment.snap Records the tool’s schema and annotations.
docs/​feature-flags.md Documents the feature-gated tool and its parameters.

Review effort: Balanced (adaptive)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Required: []string{"owner", "repo", "pullNumber", "allowedActions"},
},
},
scopes.RequireAll(scopes.Repo),
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
if err != nil {
return utils.NewToolResultErrorFromErr("failed to marshal Agent Merge enrollment", err), nil, nil
}
return utils.NewToolResultText(string(text)), output, nil

// GranularUpdatePullRequestAgentMergeEnrollment creates a tool to enable, update, or disable Agent Merge.
func GranularUpdatePullRequestAgentMergeEnrollment(t translations.TranslationHelperFunc) inventory.ServerTool {
tool := NewTool[UpdatePullRequestAgentMergeEnrollmentInput, *UpdatePullRequestAgentMergeEnrollmentOutput](
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