Class: McpInspector::Data::ConfigManager

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_inspector/data/config_manager.rb

Defined Under Namespace

Classes: ConfigError

Constant Summary collapse

DEFAULT_USER_CONFIG_PATH =
File.expand_path("~/.mcp-inspector.json")
DEFAULT_PROJECT_CONFIG_PATH =
"./.mcp-inspector.json"

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (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

#defaultsObject



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_formatObject



37
38
39
# File 'lib/mcp_inspector/data/config_manager.rb', line 37

def output_format
  defaults["output"] || "json"
end

#pretty_print?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/mcp_inspector/data/config_manager.rb', line 41

def pretty_print?
  defaults.fetch("pretty", true)
end

#server_namesObject



25
26
27
# File 'lib/mcp_inspector/data/config_manager.rb', line 25

def server_names
  servers.keys
end

#serversObject



21
22
23
# File 'lib/mcp_inspector/data/config_manager.rb', line 21

def servers
  @servers ||= build_server_configs
end

#to_hObject



45
46
47
# File 'lib/mcp_inspector/data/config_manager.rb', line 45

def to_h
  @config
end