Module: GroqRuby::MCP::ClaudeDesktopConfig

Defined in:
lib/groq_ruby/mcp/claude_desktop_config.rb

Overview

Loads MCP server configurations from the same JSON shape Claude Desktop uses (‘claude_desktop_config.json`’s ‘mcpServers` block) and returns a list of ServerConfig ready for Bridge.new.

Supports ‘$VAR` interpolation in `args` and `env` values. Lookup order: the server’s own ‘env` block first, then the process’s ‘ENV`. Unresolved references raise so silent misconfigurations don’t ship.

Examples:

Load from disk

configs = GroqRuby::MCP::ClaudeDesktopConfig.load("~/Library/Application Support/Claude/claude_desktop_config.json")
bridge = GroqRuby::MCP::Bridge.new(configs)

Parse an in-memory Hash

configs = GroqRuby::MCP::ClaudeDesktopConfig.parse({
  "mcpServers" => {
    "spectrum-ferret-staging" => {
      "command" => "npx",
      "args" => ["-y", "mcp-remote@latest", "https://...", "--header", "Authorization: Bearer ${SF_PAT}"],
      "env" => {"SF_PAT" => ENV.fetch("SF_PAT")}
    }
  }
})

Constant Summary collapse

VAR_PATTERN =
/\$\{([A-Z_][A-Z0-9_]*)\}/

Class Method Summary collapse

Class Method Details

.load(path) ⇒ Array<ServerConfig>

Load configurations from a JSON file path.

Parameters:

  • path (String)

    file path

Returns:

Raises:

  • (Errno::ENOENT)

    if the file is missing

  • (JSON::ParserError)

    if the file is not valid JSON

  • (ConfigurationError)

    if the structure is wrong or ‘$VAR` references are unresolvable



38
39
40
# File 'lib/groq_ruby/mcp/claude_desktop_config.rb', line 38

def self.load(path)
  parse(JSON.parse(File.read(File.expand_path(path))))
end

.parse(input) ⇒ Array<ServerConfig>

Parse configurations from an already-decoded Hash (or a JSON string).

Parameters:

  • input (Hash, String)

Returns:

Raises:



48
49
50
51
52
# File 'lib/groq_ruby/mcp/claude_desktop_config.rb', line 48

def self.parse(input)
  hash = input.is_a?(String) ? JSON.parse(input) : input
  servers = hash["mcpServers"] || hash[:mcpServers] || {}
  servers.map { |name, entry| build_server_config(name.to_s, entry) }
end