Files
github--github-mcp-server/pkg/github/feature_flags.go
Sam Morrow f5e26a8540 feat(issues): gate issue-fields features behind remote_mcp_issue_fields flag (#2520)
* feat(issues): gate issue-fields features behind remote_mcp_issue_fields flag

Gates the recently merged issue-fields work (list_issue_fields tool,
field_values enrichment on list_issues/search_issues, and field_filters
input on list_issues) behind a new feature flag, also enabled in
insiders mode.

- list_issues splits into two same-named registrations: the field-aware
  variant requires the flag, while LegacyListIssues (FeatureFlagDisable)
  preserves the prior schema and GraphQL selection set so disabled
  callers don't pay the extra wire/server cost.
- search_issues skips the field-values lookup when the flag is off.
- list_issue_fields requires the flag to be registered at all.
- Adopts <tool>_ff_<flag>.snap naming for flagged toolsnap variants so
  same-named duplicates each get a distinct snapshot.

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

* fix: address PR review on issue-fields gating

- docs generator: install a no-flags feature checker so README reflects
  the default user experience (tools enabled with no special flags),
  fixing duplicate `list_issues` and removing granular/flagged-only
  tools that were never meant to appear in the default docs.
- csv_output: drop the FeatureFlagEnable/Disable exclusion in
  isCSVOutputTool. Wrapping happens before the per-request flag filter
  picks the live variant, so flag-gated list_* tools wrap safely; this
  restores CSV conversion for `list_issues` and enables it for
  `list_issue_fields` when both flags are on.

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

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-21 23:01:19 +02:00

76 lines
2.9 KiB
Go

package github
import "slices"
// MCPAppsFeatureFlag is the feature flag name for MCP Apps (interactive UI forms).
const MCPAppsFeatureFlag = "remote_mcp_ui_apps"
// FeatureFlagCSVOutput is the feature flag name for CSV output on list tools.
const FeatureFlagCSVOutput = "csv_output"
// FeatureFlagIFCLabels is the feature flag name for IFC security labels in tool results.
const FeatureFlagIFCLabels = "ifc_labels"
// FeatureFlagIssueFields is the feature flag name for Issues 2.0 custom field
// support: the list_issue_fields tool, the field_filters input on list_issues,
// and field_values enrichment in list_issues / search_issues output.
const FeatureFlagIssueFields = "remote_mcp_issue_fields"
// AllowedFeatureFlags is the allowlist of feature flags that can be enabled
// by users via --features CLI flag or X-MCP-Features HTTP header.
// Only flags in this list are accepted; unknown flags are silently ignored.
// This is the single source of truth for which flags are user-controllable.
var AllowedFeatureFlags = []string{
MCPAppsFeatureFlag,
FeatureFlagCSVOutput,
FeatureFlagIssueFields,
FeatureFlagIssuesGranular,
FeatureFlagPullRequestsGranular,
}
// InsidersFeatureFlags is the list of feature flags that insiders mode enables.
// When insiders mode is active, all flags in this list are treated as enabled.
// This is the single source of truth for what "insiders" means in terms of
// feature flag expansion.
var InsidersFeatureFlags = []string{
MCPAppsFeatureFlag,
FeatureFlagCSVOutput,
FeatureFlagIFCLabels,
FeatureFlagIssueFields,
}
// FeatureFlags defines runtime feature toggles that adjust tool behavior.
type FeatureFlags struct {
LockdownMode bool
}
// ResolveFeatureFlags computes the effective set of enabled feature flags by:
// 1. Taking the user-supplied flags (from --features or X-MCP-Features) and
// keeping only those present in AllowedFeatureFlags. Unknown or unsafe
// flags from request input are silently dropped here.
// 2. If insiders mode is on, unioning in every flag from InsidersFeatureFlags.
// Insiders is a server-controlled meta switch, so its expansion is NOT
// re-validated against AllowedFeatureFlags.
//
// AllowedFeatureFlags and InsidersFeatureFlags are independent sets:
// - A flag in AllowedFeatureFlags but not InsidersFeatureFlags is a regular
// opt-in flag that insiders mode does not turn on automatically.
// - A flag in InsidersFeatureFlags but not AllowedFeatureFlags is reachable
// only through insiders mode and cannot be enabled by user input.
//
// Returns a set (map) for O(1) lookup by the feature checker.
func ResolveFeatureFlags(enabledFeatures []string, insidersMode bool) map[string]bool {
effective := make(map[string]bool)
for _, f := range enabledFeatures {
if slices.Contains(AllowedFeatureFlags, f) {
effective[f] = true
}
}
if insidersMode {
for _, f := range InsidersFeatureFlags {
effective[f] = true
}
}
return effective
}