Class: TalkToYourApp::Plugins::Flipper::Tools::EnabledFlags

Inherits:
Tool
  • Object
show all
Defined in:
lib/talk_to_your_app/plugins/flipper/tools/enabled_flags.rb

Overview

Lists the currently-enabled feature flags (any active gate) with their per-gate configuration and last-change timestamps, for inspection. Flipper does not record full enable/disable history; ‘updated_at` is the last time the feature changed (ActiveRecord adapter only).

Instance Method Summary collapse

Methods inherited from Tool

argument, arguments, connection, default_arguments, description, dispatch, input_schema_hash, invoke, name, normalize_response, to_mcp_definition, to_mcp_tool

Instance Method Details

#call(_args, ctx) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/talk_to_your_app/plugins/flipper/tools/enabled_flags.rb', line 18

def call(_args, ctx)
  flags = ctx.connection do
    features = ::Flipper.features.to_a
    timestamps = Flipper.preload_timestamps(features.map(&:key))
    no_timestamps = { created_at: nil, updated_at: nil }
    features.filter_map do |feature|
      gates = Flipper.gate_values(feature.key)
      next unless Flipper.active?(gates)

      { name: feature.key, enabled: true, gates: gates }.merge(timestamps.fetch(feature.key, no_timestamps))
    end
  end
  json(
    enabled_flags: flags.sort_by { |f| f[:name] },
    note: "Flipper does not store enable/disable history; updated_at is the last feature change (ActiveRecord adapter only).",
  )
rescue StandardError => e
  error("Flipper storage unavailable: #{e.class}: #{e.message}")
end