config

package
v1.232.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config parses `atmos mcp add` inputs into schema.MCPServerConfig values and reads/writes them under mcp.servers in atmos.yaml, backing the `atmos mcp add`/`remove` commands.

Index

Constants

View Source
const (
	PresetSelf     = "self"
	PresetAtmosPro = "atmos-pro"
)

PresetSelf and PresetAtmosPro are the built-in preset names recognized by `atmos mcp add`.

Variables

This section is empty.

Functions

func Exists

func Exists(file, name string) (bool, error)

Exists reports whether mcp.servers.<name> is already present in file.

func HasServerWithURL

func HasServerWithURL(servers map[string]schema.MCPServerConfig, url string) bool

HasServerWithURL reports whether any server in servers resolves to url -- used by the Atmos Pro nudge, matched by URL value rather than conventional key name so a renamed entry (via --name) doesn't trigger a false nudge.

func InferName

func InferName(target string) string

InferName derives a server name from a URL or command string, sanitized to the [A-Za-z0-9_-]+ charset atmos.yaml keys and MCP client configs expect.

func ParseHeaderPairs

func ParseHeaderPairs(pairs []string) (map[string]string, error)

ParseHeaderPairs parses repeatable "Key: Value" flags into a map.

func ParseKeyValuePairs

func ParseKeyValuePairs(pairs []string) (map[string]string, error)

ParseKeyValuePairs parses repeatable KEY=VALUE flags (env) into a map.

func ParseServerSpec

func ParseServerSpec(atmosConfig *schema.AtmosConfiguration, spec ServerSpec) (string, schema.MCPServerConfig, error)

ParseServerSpec builds a schema.MCPServerConfig from `atmos mcp add` inputs, inferring a name when spec.Name is empty. The spec.Target field may be a known preset name (see ResolvePreset), an http(s) URL, or a stdio command (optionally with arguments, e.g. "npx -y @org/mcp-server --flag value").

func Remove

func Remove(file, name string) error

Remove deletes mcp.servers.<name> from file.

func ResolveEnableFile added in v1.231.0

func ResolveEnableFile(cmd *cobra.Command, atmosConfig *schema.AtmosConfiguration) (string, error)

ResolveEnableFile picks the file to write mcp.enabled to. Because the root atmos.yaml is reapplied after its imports, an mcp.enabled written to a fragment is shadowed by an explicit root value; so this targets the highest-precedence file that already declares mcp.enabled, else the root atmos.yaml, which always takes effect (cloudposse/atmos#3269).

func ResolveServerFile added in v1.231.0

func ResolveServerFile(cmd *cobra.Command, atmosConfig *schema.AtmosConfiguration, name string) (file string, declared bool, err error)

ResolveServerFile picks the file that `add`/`remove` should edit for mcp.servers.<name>, honoring an explicit --config override the same way `atmos config set` does. Without an override it selects by the server's effective provenance so an edit is never silently shadowed by a higher-precedence file (cloudposse/atmos#3269). Precedence:

  1. an explicit --config override;
  2. the highest-precedence effective file that already declares the server (so an overwrite or remove targets the value that is actually in effect);
  3. for a new server, the highest-precedence effective file that already declares mcp.servers (joining existing servers, typically a .atmos.d fragment);
  4. the root atmos.yaml.

The declared return reports whether the server already exists in the chosen file (case 1 or 2), which `remove` uses to distinguish "edit here" from "not configured".

func Write

func Write(file, name string, cfg schema.MCPServerConfig) error

Write serializes cfg to a compact JSON literal (valid YAML flow syntax) and writes it at mcp.servers.<name> in file as a single atomic subtree replace -- avoids leaving stale fields behind if a server's shape changes (e.g. stdio to http) on overwrite, and preserves comments/formatting.

Types

type Preset

type Preset struct {
	Name string
	// DefaultServerName is the mcp.servers key used unless the user passes
	// --name explicitly.
	DefaultServerName string
	Description       string
	// RequiresMCPEnabled marks presets that only work when mcp.enabled is
	// true (i.e. Atmos itself needs to be able to run as an MCP server).
	RequiresMCPEnabled bool
	Resolve            func(atmosConfig *schema.AtmosConfiguration) schema.MCPServerConfig
}

Preset is a named, built-in server definition `atmos mcp add` can resolve without the user typing out a URL or command.

func Presets

func Presets() []Preset

Presets returns all built-in presets, for --help/listing.

func ResolvePreset

func ResolvePreset(name string) (Preset, bool)

ResolvePreset looks up a built-in preset by name.

type ServerSpec

type ServerSpec struct {
	Target      string
	Name        string
	Transport   string
	Description string
	Identity    string
	Timeout     string
	Env         []string
	Headers     []string
	AutoStart   bool
}

ServerSpec holds the `atmos mcp add` flag inputs used to build a schema.MCPServerConfig via ParseServerSpec. Grouped into a struct per the Options pattern rather than passed as positional parameters, since the full flag surface (name, transport, env, headers, description, identity, timeout, auto-start) is more than a handful of arguments.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL