Class: McpInspector::Data::ConfigManager
- Inherits:
-
Object
- Object
- McpInspector::Data::ConfigManager
- Defined in:
- lib/mcp_inspector/data/config_manager.rb
Defined Under Namespace
Classes: ConfigError
Constant Summary collapse
- DEFAULT_USER_CONFIG_PATH =
File.("~/.mcp-inspector.json")
- DEFAULT_PROJECT_CONFIG_PATH =
"./.mcp-inspector.json"
Class Method Summary collapse
- .config_file_exists?(path = nil) ⇒ Boolean
- .create_example_config(path = DEFAULT_USER_CONFIG_PATH) ⇒ Object
Instance Method Summary collapse
- #defaults ⇒ Object
- #find_server(name) ⇒ Object
-
#initialize(config_path: nil) ⇒ ConfigManager
constructor
A new instance of ConfigManager.
- #output_format ⇒ Object
- #pretty_print? ⇒ Boolean
- #server_names ⇒ Object
- #servers ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(config_path: nil) ⇒ ConfigManager
Returns a new instance of ConfigManager.
15 16 17 18 19 |
# File 'lib/mcp_inspector/data/config_manager.rb', line 15 def initialize(config_path: nil) @config_path = config_path @config = load_merged_config validate_config! end |
Class Method Details
.config_file_exists?(path = nil) ⇒ Boolean
49 50 51 52 53 54 55 56 57 |
# File 'lib/mcp_inspector/data/config_manager.rb', line 49 def self.config_file_exists?(path = nil) paths_to_check = if path [path] else [DEFAULT_PROJECT_CONFIG_PATH, DEFAULT_USER_CONFIG_PATH] end paths_to_check.any? { |p| File.exist?(p) } end |
.create_example_config(path = DEFAULT_USER_CONFIG_PATH) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mcp_inspector/data/config_manager.rb', line 59 def self.create_example_config(path = DEFAULT_USER_CONFIG_PATH) example_config = { "servers" => [ { "name" => "filesystem-server", "transport" => "stdio", "command" => ["npx", "-y", "@modelcontextprotocol/server-filesystem"], "args" => ["/tmp"], "env" => {} }, { "name" => "github-server", "transport" => "stdio", "command" => ["npx", "-y", "@modelcontextprotocol/server-github"], "env" => { "GITHUB_TOKEN" => "${GITHUB_TOKEN}" } } ], "defaults" => { "output" => "json", "pretty" => true } } File.write(path, JSON.pretty_generate(example_config)) path end |
Instance Method Details
#defaults ⇒ Object
33 34 35 |
# File 'lib/mcp_inspector/data/config_manager.rb', line 33 def defaults @config["defaults"] || {} end |
#find_server(name) ⇒ Object
29 30 31 |
# File 'lib/mcp_inspector/data/config_manager.rb', line 29 def find_server(name) servers[name] or raise ConfigError, "Server '#{name}' not found" end |
#output_format ⇒ Object
37 38 39 |
# File 'lib/mcp_inspector/data/config_manager.rb', line 37 def output_format defaults["output"] || "json" end |
#pretty_print? ⇒ Boolean
41 42 43 |
# File 'lib/mcp_inspector/data/config_manager.rb', line 41 def pretty_print? defaults.fetch("pretty", true) end |
#server_names ⇒ Object
25 26 27 |
# File 'lib/mcp_inspector/data/config_manager.rb', line 25 def server_names servers.keys end |
#servers ⇒ Object
21 22 23 |
# File 'lib/mcp_inspector/data/config_manager.rb', line 21 def servers @servers ||= build_server_configs end |
#to_h ⇒ Object
45 46 47 |
# File 'lib/mcp_inspector/data/config_manager.rb', line 45 def to_h @config end |