Repository navigation
Conversation
There was a problem hiding this comment.
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
methodtoupdate_issue_labelswithreplace(default),add, andremovebehaviors, 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. |
| 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 |
There was a problem hiding this comment.
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
095bb42 to
11728ad
Compare
Summary
Adds a
methodoption to the feature-flaggedupdate_issue_labelstool 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.
addandremovecall GitHub's add/remove label endpoints, so there is no read-modify-write and no lost labels.What changed
methodinput:replace(default),add,remove.replace: unchanged PATCH, including per-labelrationale/confidence/is_suggestion.add:POST /issues/{n}/labels, keeping existing labels.remove: oneDELETE /issues/{n}/labels/{name}per label. Names are URL-escaped, because go-github'sRemoveLabelForIssuedoes not escape names likestatus/blocked. If a removal fails part-way, the error lists the labels already removed.addandremovealso de-duplicate names.{id, url, labels}: the previousMinimalResponsefields plus the issue's labels after the update. Existing consumers ofid/urlare unaffected.destructiveHintset totrue, since bothreplaceandremovecan delete labels.MCP impact
methodinput, addslabelsto the output schema, and changesdestructiveHinttotrue. Only applies behind theissues_granularfeature flag. Calls withoutmethodbehave as before.Prompts tested (tool changes only)
Tested live against a private test repo with
--features=issues_granular, checking every step withgh:enhancementto issue 1":method: add, existing labels kept.good first issueandstatus/blockedfrom issue 1":method: remove. Names with a space and a slash work.add_label_to_issue/remove_label_from_issuetools #2724 scenario).[]: clears all labels.Security / limits
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
Lint & tests
./script/lint./script/testDocs
docs/feature-flags.mdand the tool snapshot.Note: the default
issue_writetool also replaces the full label set whenlabelsis passed (see the repro in #2724). That is out of scope here and can be a follow-up.