Module: Woods::MCP::ConfigResolver
- Defined in:
- lib/woods/mcp/config_resolver.rb
Overview
Resolves the embedding configuration that the MCP server should use.
Reads woods.json (the resolved config snapshot written at embed time), applies environment-variable overrides, validates, and returns either a populated Configuration or raises a typed BootstrapError subclass that the caller can present to an operator.
This class is extracted from Bootstrapper to isolate the config-resolution concern from network probing and store construction. Bootstrapper delegates to ConfigResolver.resolve as its first step.
Resolution order (highest priority first):
-
Host Rails initializer (Woods.configuration already has embedding_provider). When
woods.jsonis also present the stored config is loaded and asserted compatible via ResolvedConfig#assert_compatible!. -
woods.jsonsnapshot alone (MCP server running without a host initializer). The stored config is used to populateconfigin place. -
Environment-variable auto-detect (the default when
woods.jsonis absent and no host provider is set). Wires semantic search ifOPENAI_API_KEYor a reachable Ollama is found; otherwise leaves the provider nil so the server boots in pattern/structural-only mode. -
WOODS_REQUIRE_INDEX=1 overrides (3) to fail closed, raising MissingArtifact when
woods.jsonis absent.
Class Method Summary collapse
-
.resolve(config, artifact:, env: ENV, ollama_probe: nil) ⇒ Array(Woods::Configuration, Symbol)
Resolve and validate the embedding configuration.
Class Method Details
.resolve(config, artifact:, env: ENV, ollama_probe: nil) ⇒ Array(Woods::Configuration, Symbol)
Resolve and validate the embedding configuration.
When woods.json is present in the artifact directory it is parsed into a ResolvedConfig and, if the host already has a provider configured, validated for compatibility (dimension + provider class/model must agree). If the host has no provider configured the stored config is applied to config so Builder can construct the correct provider.
When woods.json is absent and the host already has a provider configured, the host config is trusted and used as-is.
When woods.json is absent and the host has no provider configured, auto-detect runs by default: pattern/structural tools always work, and semantic search wires up only if OPENAI_API_KEY or a reachable Ollama is found. Set WOODS_REQUIRE_INDEX=1 to fail closed and raise MissingArtifact instead.
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/woods/mcp/config_resolver.rb', line 75 def self.resolve(config, artifact:, env: ENV, ollama_probe: nil) stored = read_stored_config(artifact) if stored [apply_stored_config(config, stored, artifact: artifact, env: env), :snapshot] elsif config. # Host initializer configured a provider; no woods.json to validate # against. Trust the host config and proceed. [config, :host_config] else resolve_without_artifact(config, artifact: artifact, env: env, ollama_probe: ollama_probe) end end |