Skip to content

enhance update_issue_labels tool with method options - #2742

Open
MayorFaj wants to merge 1 commit into
github:mainfrom
MayorFaj:feat/2724-improve-issue-label
Open

MayorFaj wants to merge 1 commit into
github:mainfrom
MayorFaj:feat/2724-improve-issue-label

Conversation

@MayorFaj

@MayorFaj MayorFaj commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a method option to the feature-flagged update_issue_labels tool so one tool can replace (default), add, or remove an issue's labels.

Why

Fixes #2724

The tool can only replace an issue's whole label set, so adding or removing one label means reading the current labels and sending back the full list. If that read is stale, labels are silently dropped. #2724 has a live repro: two agents each add a different label, and the first add is lost every time. add and remove call GitHub's add/remove label endpoints, so there is no read-modify-write and no lost labels.

What changed

  • New method input: replace (default), add, remove.
    • replace: unchanged PATCH, including per-label rationale / confidence / is_suggestion.
    • add: POST /issues/{n}/labels, keeping existing labels.
    • remove: one DELETE /issues/{n}/labels/{name} per label. Names are URL-escaped, because go-github's RemoveLabelForIssue does not escape names like status/blocked. If a removal fails part-way, the error lists the labels already removed.
  • Label names are trimmed and validated for every method. add and remove also de-duplicate names.
  • Output is now {id, url, labels}: the previous MinimalResponse fields plus the issue's labels after the update. Existing consumers of id/url are unaffected.
  • destructiveHint set to true, since both replace and remove can delete labels.

MCP impact

  • Tool schema or behavior changed
    • Adds the method input, adds labels to the output schema, and changes destructiveHint to true. Only applies behind the issues_granular feature flag. Calls without method behave as before.

Prompts tested (tool changes only)

Tested live against a private test repo with --features=issues_granular, checking every step with gh:

  • "Add the label enhancement to issue 1": method: add, existing labels kept.
  • "Remove good first issue and status/blocked from issue 1": method: remove. Names with a space and a slash work.
  • Two separate adds of different labels: both labels kept (the Add granular add_label_to_issue / remove_label_from_issue tools #2724 scenario).
  • Removing a label not on the issue: error that names the labels already removed.
  • Invalid method: rejected, labels unchanged.
  • Replace with []: clears all labels.

Security / limits

  • Auth / permissions considered
    • Still requires repo. The response now includes label names, so it is tagged with the repo-visibility IFC label (LabelRepoMetadata), the same as other tools that return labels.

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: regenerated docs/feature-flags.md and the tool snapshot.

Note: the default issue_write tool also replaces the full label set when labels is passed (see the repro in #2724). That is out of scope here and can be a follow-up.

Copilot AI review requested due to automatic review settings June 21, 2026 08:35
@MayorFaj
MayorFaj requested a review from a team as a code owner June 21, 2026 08:35

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 enhances the feature-flagged update_issue_labels MCP tool to support granular label operations via a new method parameter, enabling atomic add/remove behavior without requiring a read-modify-write cycle.

Changes:

  • Added method to update_issue_labels with replace (default), add, and remove behaviors, including URL-escaped label removal for names containing spaces/slashes.
  • Refactored label handling into helpers (issueLabelNames, replaceIssueLabels, addIssueLabels, removeIssueLabels) and attached repo-visibility IFC labeling for label results.
  • Added unit tests and updated the tool snapshot and feature-flag docs to reflect the new input schema/behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/github/issues_granular.go Adds method support and implements add/remove/replace label operations with validation and URL-escaped deletes.
pkg/github/helper_test.go Adds mock endpoint patterns for the new labels POST and label DELETE routes used by tests.
pkg/github/granular_tools_test.go Adds coverage for add/remove behaviors, trimming/dedup validation, escaping, and method normalization.
pkg/github/toolsnaps/update_issue_labels.snap Updates the toolsnap to include the new method parameter and updated labels description.
docs/feature-flags.md Updates feature-flag tool documentation to include the new method parameter and revised labels description.

Comment thread pkg/github/issues_granular.go Outdated
Comment on lines +536 to +545
r, err := json.Marshal(issue.Labels)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to marshal response", err), nil, nil
}

result := utils.NewToolResultText(string(r))
// Labels are structural repo metadata defined by collaborators
// (trusted); confidentiality follows repo visibility.
result = attachRepoVisibilityIFCLabelLazy(ctx, deps, owner, repo, result, ifc.LabelRepoMetadata)
return result, nil, nil

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.

The shape change is intentional and not a GA break, this tool is behind the issues_granular feature flag, so there's no stable response contract yet. All three methods (replace/add/remove) return the resulting label set on purpose: add/remove are backed by the labels endpoints, which return []Label and never expose the issue's ID/URL, so emitting MinimalResponse would force an extra GET per call to return less useful data, and reverting only replace would make the tool inconsistent with itself. Returning the labels gives one consistent, useful response across all methods (see

Add a `method` parameter to the granular update_issue_labels tool so a
single tool can replace (default), add, or remove issue labels without
a read-modify-write cycle that can silently drop labels.

- add: POST /issues/{n}/labels, keeping existing labels
- remove: one DELETE /issues/{n}/labels/{name} per label, with the name
  URL-escaped so names containing spaces or slashes stay one segment;
  on failure the error lists labels already removed
- replace: unchanged PATCH behaviour, including per-label rationale,
  confidence and is_suggestion intent
- label names are trimmed and validated for every method; add and
  remove also de-duplicate names

The output keeps `id` and `url` and adds `labels`, the issue's labels
after the update, so callers see the resulting set without another read.

Mark the tool destructiveHint: true, since both replace and remove can
delete existing labels (github#3760).

Fixes github#2724
@MayorFaj
MayorFaj force-pushed the feat/2724-improve-issue-label branch from 095bb42 to 11728ad Compare November 15, 2026 07:07
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 granular add_label_to_issue / remove_label_from_issue tools

2 participants