Class: RailsMarkup::McpConfig
- Inherits:
-
Object
- Object
- RailsMarkup::McpConfig
- Defined in:
- lib/rails_markup/mcp_config.rb
Overview
Reads and writes MCP configuration. Supports three scopes:
"local" → .mcp.json (project-level, Claude Code)
"global" → ~/.claude/settings.json (Claude Code global)
"codex" → ~/.codex/config.toml (OpenAI Codex CLI global)
Constant Summary collapse
- FILE_NAME =
".mcp.json"- GLOBAL_PATH =
File.join(Dir.home, ".claude", "settings.json")
- CODEX_PATH =
File.join(Dir.home, ".codex", "config.toml")
- SERVER_KEY =
"rails-markup"- SCOPES =
%w[local global codex].freeze
- ENV_KEYS =
{ "prod_url" => "RAILS_MARKUP_PROD_URL", "prod_token" => "RAILS_MARKUP_PROD_TOKEN", "dev_url" => "RAILS_MARKUP_DEV_URL", "mount_path" => "RAILS_MARKUP_MOUNT_PATH" }.freeze
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #display_env ⇒ Object
- #env ⇒ Object (also: #raw_env)
- #exist? ⇒ Boolean
- #global? ⇒ Boolean
-
#initialize(dir: Dir.pwd, scope: "local") ⇒ McpConfig
constructor
A new instance of McpConfig.
- #path ⇒ Object
- #read ⇒ Object
- #scope_label ⇒ Object
- #toml? ⇒ Boolean
- #update_env(new_vars) ⇒ Object
Constructor Details
#initialize(dir: Dir.pwd, scope: "local") ⇒ McpConfig
Returns a new instance of McpConfig.
28 29 30 31 32 |
# File 'lib/rails_markup/mcp_config.rb', line 28 def initialize(dir: Dir.pwd, scope: "local") @scope = scope @dir = dir @path = resolve_path(dir, scope) end |
Instance Attribute Details
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
26 27 28 |
# File 'lib/rails_markup/mcp_config.rb', line 26 def scope @scope end |
Instance Method Details
#display_env ⇒ Object
62 63 64 65 66 |
# File 'lib/rails_markup/mcp_config.rb', line 62 def display_env env.each_with_object({}) do |(k, v), hash| hash[k] = k.include?("TOKEN") ? mask(v) : v end end |
#env ⇒ Object Also known as: raw_env
48 49 50 |
# File 'lib/rails_markup/mcp_config.rb', line 48 def env read.dig(servers_key, SERVER_KEY, "env") || {} end |
#exist? ⇒ Boolean
34 35 36 |
# File 'lib/rails_markup/mcp_config.rb', line 34 def exist? File.exist?(@path) end |
#global? ⇒ Boolean
76 77 78 |
# File 'lib/rails_markup/mcp_config.rb', line 76 def global? @scope != "local" end |
#path ⇒ Object
38 39 40 |
# File 'lib/rails_markup/mcp_config.rb', line 38 def path @path end |
#read ⇒ Object
42 43 44 45 46 |
# File 'lib/rails_markup/mcp_config.rb', line 42 def read return {} unless exist? toml? ? read_toml : JSON.parse(File.read(@path)) end |
#scope_label ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/rails_markup/mcp_config.rb', line 68 def scope_label case @scope when "global" then "~/.claude/settings.json" when "codex" then "~/.codex/config.toml" else ".mcp.json" end end |
#toml? ⇒ Boolean
80 81 82 |
# File 'lib/rails_markup/mcp_config.rb', line 80 def toml? @scope == "codex" end |
#update_env(new_vars) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/rails_markup/mcp_config.rb', line 54 def update_env(new_vars) if toml? update_env_toml(new_vars) else update_env_json(new_vars) end end |