Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1broseidon Ketch search NewFromConfig

From Leeroopedia
Knowledge Sources
Domains Search, Configuration
Last Updated 2026-10-27 00:00 GMT

Overview

Constructor that resolves a registered search backend (or the `auto` chain) from operator config, shared by the CLI and the MCP server.

Description

NewFromConfig is the single entry point both `cmd/search.go` and the MCP search tool call to turn a backend id string into a live `search.Searcher`. It looks up the provider in the ordered registry, applies the per-call SearXNG URL override to a copy of the config (so the shared config is never mutated), and calls `Provider.Build`, which checks `Usable` before constructing. The `auto` id is special-cased to `NewAutoFromConfig`. An unknown id wraps `ErrUnknownBackend`, which the surfaces map to a validation/precondition error.

Usage

Use this whenever you need a `Searcher` from a backend name and config — CLI commands, MCP tool handlers, and the multi/random resolvers all go through it. Never call a provider's `New` directly; `Build`'s `Usable` gate is the precondition check that keeps unconfigured backends from failing mid-query.

Code Reference

Source Location

  • Repository: ketch
  • File: search/config.go

Signature

// NewFromConfig constructs a registered search provider, or the auto fallback
// chain. The existing SearXNG per-call override is applied to a copy,
// preserving the shared configuration.
func NewFromConfig(cfg *config.Config, backend, searxngURL string) (Searcher, error)

Import

import (
	"github.com/1broseidon/ketch/search"
	config "github.com/1broseidon/ketch/internal/configbase"
)

I/O Contract

Inputs

Name Type Required Description
cfg *config.Config Yes Effective config with provider settings; never mutated
backend string Yes Provider id ("brave", "ddg", …) or "auto"
searxngURL string No Per-call SearXNG URL override applied to a config copy

Outputs

Name Type Description
return search.Searcher A single provider or the Auto chain
return error error Wraps ErrUnknownBackend for an unknown id; otherwise the provider's Setup precondition message

Usage Examples

CLI / MCP Backend Resolution

// "auto" returns the fallback chain; any other id returns one provider.
searcher, err := search.NewFromConfig(cfg, cfg.Backend, searxngURL)
if err != nil {
	// Map ErrUnknownBackend -> [validation]; anything else -> [precondition].
	return backendErrf(err, search.ErrUnknownBackend)
}
results, err := searcher.Search(ctx, query, limit)

Per-Call Override Without Mutation

// The SearXNG override is applied to a copy; the shared MCP config is untouched
// so a concurrent call sees the configured value.
searcher, err := search.NewFromConfig(cfg, "searxng", "http://localhost:8081")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment