1#!/usr/bin/env python3

2"""MCP tools to inspect feature flags and rollout guidance."""

3

4 from __future__ import annotations

5

6 from typing import TYPE_CHECKING, Any

7

8 from session_buddy.config.feature_flags import get_feature_flags

9

10 if TYPE_CHECKING:

11 from fastmcp import FastMCP

12

13

14 def register_feature_flags_tools(mcp: FastMCP) -> None:

15 @mcp.tool() # type: ignore[no-untyped-call]

16 async def feature_flags_status() -> dict[str, Any]:

17 """Return current feature flag values."""

18 flags = get_feature_flags()

19 return {

20 "use_schema_v2": flags.use_schema_v2,

21 "enable_llm_entity_extraction": flags.enable_llm_entity_extraction,

22 "enable_anthropic": flags.enable_anthropic,

23 "enable_ollama": flags.enable_ollama,

24 "enable_conscious_agent": flags.enable_conscious_agent,

25 "enable_filesystem_extraction": flags.enable_filesystem_extraction,

26 }

27

28 @mcp.tool() # type: ignore[no-untyped-call]

29 async def rollout_plan() -> dict[str, Any]:

30 """Return a staged enablement plan for features (read-only guidance)."""

31 return {

32 "day_1_2": [

33 "Enable SESSION_MGMT_USE_SCHEMA_V2=true (parallel with v1)",

34 "Verify migration: use migration_status tool",

35 ],

36 "day_3_4": [

37 "Enable SESSION_MGMT_ENABLE_LLM_ENTITY_EXTRACTION=true",

38 "Optionally set ANTHROPIC_API_KEY/OPENAI_API_KEY/GEMINI_API_KEY",

39 "Check provider distribution via access_log_stats (by_provider)",

40 ],

41 "day_5_6": [

42 "Enable SESSION_MGMT_ENABLE_CONSCIOUS_AGENT=true",

43 "Start agent with start_conscious_agent",

44 "Monitor promotions/demotions using access_log_stats",

45 ],

46 "day_7": [

47 "Enable SESSION_MGMT_ENABLE_FILESYSTEM_EXTRACTION=true",

48 "Tune filesystem settings (TTL, size, ignore dirs)",

49 ],

50 "rollback": [

51 "Use trigger_migration(dry_run=true) to preview",

52 "Create backup via trigger_migration(create_backup_first=true)",

53 "If needed, restore with rollback_migration(backup_path)",

54 ],

55 "notes": "All flags default to false; enable progressively. Monitor via access_log_stats.",

56 }