config

package
v0.1.0-beta.12 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandStackVarsWithEnv

func ExpandStackVarsWithEnv(s *Stack)

ExpandStackVarsWithEnv expands environment variable references in stack fields.

func ExpandString

func ExpandString(s string, resolve Resolver) (expanded string, unresolvedVault []string, emptyEnvVars []string)

ExpandString expands variable references in a string using the given resolver. All patterns are matched in a single pass to prevent double-expansion of values that contain dollar signs.

Returns the expanded string, any unresolved vault references, and env vars that resolved to empty.

func ExpandStringRefs

func ExpandStringRefs(s string, resolve Resolver) (expanded string, storeRefs []string, unresolvedVault []string, emptyEnvVars []string)

ExpandStringRefs is ExpandString plus storeRefs: the variable-store keys (the KEY in ${var:KEY} / ${vault:KEY}) referenced by s, in first-seen order.

storeRefs is captured from the parsed grammar *before* resolution, so it records what s references regardless of whether each key resolves — this is the basis for usage tracing and is why the index can never drift from what expansion actually recognizes. Bare $VAR / ${VAR} env-style references are NOT store references and are deliberately excluded.

func NormalizedClientModelKeyForTest

func NormalizedClientModelKeyForTest(raw string) string

NormalizedClientModelKeyForTest exposes normalizedClientModelKey to the external parity test (clientmodels_parity_test.go), which asserts this package's copy of the normalization logic matches mcp.NormalizeClientID. Not for production use — the cost path never re-normalizes keys.

func Validate

func Validate(s *Stack) error

Validate checks the stack configuration for errors.

func ValidateStackFile

func ValidateStackFile(path string) (*Stack, *ValidationResult, error)

ValidateStackFile loads a stack file and validates it without deploying. Returns the parsed stack (for further use) and the validation result.

Types

type AuthConfig

type AuthConfig struct {
	// Type is the auth mechanism: "bearer" or "api_key".
	Type string `yaml:"type"`
	// Token is the expected token value (supports env var references via $VAR or ${VAR}).
	Token string `yaml:"token"`
	// Header is the header name for api_key auth (default: "Authorization").
	Header string `yaml:"header,omitempty"`
}

AuthConfig configures gateway authentication. When configured, all requests (except /health and /ready) must include a valid token.

type AutoscaleConfig

type AutoscaleConfig struct {
	// Min is the minimum number of healthy replicas to maintain.
	// >= 0. Must be >= 1 when IdleToZero is false.
	Min int `yaml:"min" json:"min"`
	// Max is the upper bound on replica count. >= 1, >= Min, <= 32.
	Max int `yaml:"max" json:"max"`
	// TargetInFlight is the per-replica in-flight request count the scaler
	// tries to hold the median at or below. >= 1.
	TargetInFlight int `yaml:"target_in_flight" json:"target_in_flight"`
	// ScaleUpAfter is how long the window median must exceed the target
	// before spawning a replica. Default 30s. Minimum 10s.
	ScaleUpAfter string `yaml:"scale_up_after,omitempty" json:"scale_up_after,omitempty"`
	// ScaleDownAfter is how long the window median must be below the target
	// before reaping a replica. Default 5m. Minimum 1m.
	ScaleDownAfter string `yaml:"scale_down_after,omitempty" json:"scale_down_after,omitempty"`
	// WarmPool keeps this many extra idle-ready replicas above the load-derived
	// target at all times. Default 0. Must satisfy Min + WarmPool <= Max.
	WarmPool int `yaml:"warm_pool,omitempty" json:"warm_pool,omitempty"`
	// IdleToZero allows the scaler to reap every replica after a sustained
	// idle. Min may be 0 only when IdleToZero is true. Default false.
	IdleToZero bool `yaml:"idle_to_zero,omitempty" json:"idle_to_zero,omitempty"`
}

AutoscaleConfig controls reactive autoscaling of a ReplicaSet. All fields are optional at the YAML layer only in the sense that SetDefaults fills missing timings; Min, Max, and TargetInFlight are required for the block to validate.

func (*AutoscaleConfig) ResolvedScaleDownAfter

func (a *AutoscaleConfig) ResolvedScaleDownAfter() time.Duration

ResolvedScaleDownAfter parses ScaleDownAfter; returns 5m when unset or invalid.

func (*AutoscaleConfig) ResolvedScaleUpAfter

func (a *AutoscaleConfig) ResolvedScaleUpAfter() time.Duration

ResolvedScaleUpAfter parses ScaleUpAfter; returns 30s when unset or invalid.

type ClientProfile

type ClientProfile struct {
	// Aliases are raw clientInfo.name values that should resolve to this
	// profile, for reconciling a wire identity that differs from the profile
	// key without relying on the built-in normalization heuristic.
	Aliases []string `yaml:"aliases,omitempty"`
	// Servers is an allow-list of MCP server names. Empty means all servers.
	Servers []string `yaml:"servers,omitempty"`
	// Tools is an allow-list of prefixed tool names. Empty means all tools
	// within the allowed servers.
	Tools []string `yaml:"tools,omitempty"`
}

ClientProfile is one client's tool access allow-list. Servers and Tools are both allow-lists; an empty Servers list means "all servers" and an empty Tools list means "all tools within the allowed servers". Tools are matched against the router's prefixed names (e.g. "github__search-repos").

type ClientsConfig

type ClientsConfig struct {
	// Default is the policy for clients that match no profile: "deny" (the
	// default when empty) or "allow".
	Default string `yaml:"default,omitempty"`
	// Profiles maps a stable client identifier to its access allow-list.
	Profiles map[string]ClientProfile `yaml:"profiles,omitempty"`
}

ClientsConfig is the optional top-level per-client access scoping block. Its presence opts a stack into NetworkPolicy semantics:

  • Omitting the entire `clients:` block preserves legacy behavior — every connecting client sees every tool (Article IX back-compat).
  • With the block present, a connecting client that matches a profile is restricted to that profile's allow-list; a client matching no profile is governed by Default ("deny" unless set to "allow").

The map key in Profiles is the stable client identifier assigned at `gridctl link` time, which is also the identifier shown in the UI and carried on the wire (the `client` query parameter / X-Gridctl-Client-Id header). It is reconciled with the connecting client's normalized identity, so the same string keys configuration, enforcement, and the topology view.

Scope coverage for v1 is tools only: skills (served as MCP prompts) and resources remain globally visible. This is an explicit, documented decision; extending scope to prompts/resources is deferred.

type Consumer

type Consumer struct {
	Kind  ReferenceKind `json:"kind"`
	Name  string        `json:"name,omitempty"`
	Field string        `json:"field"`
}

Consumer is a single site that references a variable: the kind of stack element, its name (server/resource/network name; empty for stack- and gateway-level sites), and the field where the reference appears.

Field mirrors the YAML key path the user actually wrote (e.g. "env.GITHUB_TOKEN", "image", "command[2]", "ssh.identityFile", "openapi.baseUrl") so it can be used verbatim to locate the reference in the stack file. Casing therefore tracks the schema's own YAML tags, which mix camelCase (identityFile, baseUrl) and snake_case (build_args, ssh_key_path).

type DependencyStatus

type DependencyStatus struct {
	Status  string   `json:"status"` // "resolved", "missing"
	Missing []string `json:"missing,omitempty"`
}

DependencyStatus summarizes skill dependency resolution.

type DiffAction

type DiffAction string

DiffAction describes what changed.

const (
	DiffAdd    DiffAction = "add"
	DiffRemove DiffAction = "remove"
	DiffChange DiffAction = "change"
)

type DiffItem

type DiffItem struct {
	Action  DiffAction `json:"action"`
	Kind    string     `json:"kind"` // "mcp-server", "agent", "resource", "a2a-agent", "gateway", "network"
	Name    string     `json:"name"`
	Details []string   `json:"details,omitempty"` // human-readable change descriptions
}

DiffItem represents a single change in the plan.

type DriftStatus

type DriftStatus struct {
	Status  string   `json:"status"` // "in-sync", "drifted", "unknown"
	Added   []string `json:"added,omitempty"`
	Removed []string `json:"removed,omitempty"`
	Changed []string `json:"changed,omitempty"`
}

DriftStatus summarizes drift between spec and running state.

type GatewayConfig

type GatewayConfig struct {
	// AllowedOrigins lists origins for CORS.
	// When not set, defaults to ["*"] (allow all) for backward compatibility.
	// Set explicit origins to restrict cross-origin access.
	AllowedOrigins []string    `yaml:"allowed_origins,omitempty"`
	Auth           *AuthConfig `yaml:"auth,omitempty"`

	// CodeMode controls whether the gateway replaces individual tool definitions
	// with two meta-tools (search + execute). Values: "off" (default), "on".
	// Experimental: may change without notice.
	CodeMode string `yaml:"code_mode,omitempty"`
	// CodeModeTimeout is the execution timeout in seconds (default: 30).
	// Experimental: may change without notice.
	CodeModeTimeout int `yaml:"code_mode_timeout,omitempty"`

	// OutputFormat sets the default output format for tool call results.
	// Values: "json" (default), "toon", "csv", "text".
	// Per-server output_format overrides this value.
	OutputFormat string `yaml:"output_format,omitempty"`

	// MaxToolResultBytes sets the maximum size of a tool result in bytes before truncation.
	// Results exceeding this limit are truncated with a suffix indicating the original size.
	// Default: 65536 (64KB). Set to 0 to use the default.
	MaxToolResultBytes int `yaml:"maxToolResultBytes,omitempty" json:"maxToolResultBytes,omitempty"`

	// Tracing configures distributed tracing. When nil, tracing is enabled with defaults.
	Tracing *TracingConfig `yaml:"tracing,omitempty" json:"tracing,omitempty"`

	// Security configures security features such as schema pinning. When nil, defaults apply.
	Security *GatewaySecurityConfig `yaml:"security,omitempty" json:"security,omitempty"`

	// DefaultModel is the model ID used to price tool calls for servers that
	// do not set their own model field (e.g. "claude-opus-4-7"). Rates come
	// from the embedded LiteLLM pricing snapshot; resulting figures are
	// estimates, not billing truth. Empty (the default) disables cost
	// attribution for servers without a per-server model.
	DefaultModel string `yaml:"default_model,omitempty" json:"default_model,omitempty"`

	// Tokenizer selects the token counting strategy.
	// Values: "embedded" (default) uses the cl100k_base BPE vocabulary (pure Go, no network).
	// "api" uses Anthropic's count_tokens endpoint for exact counts — Anthropic-specific,
	// requires network access and an API key, wrong for non-Anthropic model routing.
	Tokenizer string `yaml:"tokenizer,omitempty"`
	// TokenizerAPIKey overrides ANTHROPIC_API_KEY for the api tokenizer mode.
	// When unset, the api tokenizer falls back to the ANTHROPIC_API_KEY environment variable.
	TokenizerAPIKey string `yaml:"tokenizer_api_key,omitempty"`
}

GatewayConfig holds optional gateway-level configuration.

type GatewaySecurityConfig

type GatewaySecurityConfig struct {
	// SchemaPinning configures TOFU schema pinning for MCP tool definitions.
	SchemaPinning *SchemaPinningConfig `yaml:"schema_pinning,omitempty" json:"schema_pinning,omitempty"`
}

GatewaySecurityConfig holds gateway-level security settings.

type IssueSeverity

type IssueSeverity string

IssueSeverity represents the severity level of a validation issue.

const (
	SeverityError   IssueSeverity = "error"
	SeverityWarning IssueSeverity = "warning"
	SeverityInfo    IssueSeverity = "info"
)

type LoadOption

type LoadOption func(*loadConfig)

LoadOption configures LoadStack behavior.

func WithVault

func WithVault(v VaultLookup) LoadOption

WithVault enables ${vault:KEY} resolution during stack loading.

func WithVaultSets

func WithVaultSets(v VaultSetLookup) LoadOption

WithVaultSets enables secrets.sets injection during stack loading.

type LoggingConfig

type LoggingConfig struct {
	// File is the path to the log file. When set, logs are written to both the
	// in-memory ring buffer (web UI) and this file simultaneously.
	File string `yaml:"file,omitempty" json:"file,omitempty"`
	// MaxSizeMB is the maximum log file size in megabytes before rotation (default: 100).
	MaxSizeMB int `yaml:"maxSizeMB,omitempty" json:"maxSizeMB,omitempty"`
	// MaxAgeDays is the maximum number of days to retain old log files (default: 7).
	MaxAgeDays int `yaml:"maxAgeDays,omitempty" json:"maxAgeDays,omitempty"`
	// MaxBackups is the maximum number of compressed old log files to keep (default: 3).
	MaxBackups int `yaml:"maxBackups,omitempty" json:"maxBackups,omitempty"`
}

LoggingConfig configures log file output with automatic rotation.

type MCPServer

type MCPServer struct {
	Name         string            `yaml:"name"`
	Image        string            `yaml:"image,omitempty"`
	Source       *Source           `yaml:"source,omitempty"`
	URL          string            `yaml:"url,omitempty"`       // External server URL (no container)
	Port         int               `yaml:"port,omitempty"`      // For HTTP transport (container-based)
	Transport    string            `yaml:"transport,omitempty"` // "http" (default), "stdio", or "sse"
	Command      []string          `yaml:"command,omitempty"`   // Override container command or remote command for SSH
	Env          map[string]string `yaml:"env,omitempty"`
	BuildArgs    map[string]string `yaml:"build_args,omitempty"`
	Network      string            `yaml:"network,omitempty"`       // Network to join (for multi-network mode)
	SSH          *SSHConfig        `yaml:"ssh,omitempty"`           // SSH connection config for remote servers
	OpenAPI      *OpenAPIConfig    `yaml:"openapi,omitempty"`       // OpenAPI spec config for API-backed servers
	Tools        []string          `yaml:"tools,omitempty"`         // Tool whitelist (empty = all tools exposed)
	OutputFormat string            `yaml:"output_format,omitempty"` // Output format override: "json", "toon", "csv", "text"
	PinSchemas   *bool             `yaml:"pin_schemas,omitempty"`   // Override gateway schema pinning for this server (nil = inherit)
	// ReadyTimeout overrides the HTTP/SSE readiness wait for container-based servers.
	// Accepts any time.Duration string (e.g. "60s", "2m"). Empty/"0" inherits the gateway default (30s).
	// Ignored for stdio, local process, SSH, OpenAPI, and external transports.
	ReadyTimeout string `yaml:"ready_timeout,omitempty"`

	// PingTimeout overrides the per-ping deadline used by the gateway health monitor.
	// Accepts any time.Duration string (e.g. "10s"). Empty/"0" inherits DefaultPingTimeout (5s).
	// Tune this for slow upstreams (e.g. HTTP servers with many tools) where the
	// 5s default can flake under autoscale spawn load.
	PingTimeout string `yaml:"ping_timeout,omitempty"`

	// Replicas is the number of independent processes to spawn for this server.
	// Defaults to 1. Values >1 load-balance JSON-RPC tool calls across replicas
	// using ReplicaPolicy. Not supported for external URL or OpenAPI transports.
	Replicas int `yaml:"replicas,omitempty" json:"replicas,omitempty"`

	// ReplicaPolicy selects the dispatch policy when Replicas > 1.
	// Valid values: "round-robin" (default), "least-connections".
	ReplicaPolicy string `yaml:"replica_policy,omitempty" json:"replica_policy,omitempty"`

	// Autoscale, when set, replaces the static Replicas count with reactive
	// autoscaling bounded by Min and Max. Mutually exclusive with Replicas.
	// Not supported on external URL or OpenAPI transports.
	Autoscale *AutoscaleConfig `yaml:"autoscale,omitempty" json:"autoscale,omitempty"`

	// Telemetry, when set, overrides stack-global telemetry persistence for
	// this server. nil fields inherit; *bool fields explicitly opt in or out.
	Telemetry *MCPServerTelemetry `yaml:"telemetry,omitempty" json:"telemetry,omitempty"`

	// Model is the model ID used to price this server's tool calls against
	// the embedded LiteLLM pricing snapshot (e.g. "claude-opus-4-7").
	// Overrides gateway.default_model for this server. Empty (the default)
	// means no cost attribution: tokens are still recorded but cost stays
	// zero. Unknown model IDs are best-effort — they log a single WARN and
	// price as zero rather than failing validation.
	Model string `yaml:"model,omitempty" json:"model,omitempty"`
}

MCPServer defines an MCP server (container-based or external).

func (*MCPServer) IsContainerBased

func (s *MCPServer) IsContainerBased() bool

IsContainerBased returns true if this MCP server requires a container runtime.

func (*MCPServer) IsExternal

func (s *MCPServer) IsExternal() bool

IsExternal returns true if this is an external MCP server (URL-only, no container).

func (*MCPServer) IsLocalProcess

func (s *MCPServer) IsLocalProcess() bool

IsLocalProcess returns true if this is a local process MCP server (command-only, no container).

func (*MCPServer) IsOpenAPI

func (s *MCPServer) IsOpenAPI() bool

IsOpenAPI returns true if this is an OpenAPI-based MCP server.

func (*MCPServer) IsSSH

func (s *MCPServer) IsSSH() bool

IsSSH returns true if this is an SSH-based MCP server (ssh config with command).

func (*MCPServer) PersistLogs

func (s *MCPServer) PersistLogs(stack *Stack) bool

PersistLogs reports whether log persistence is effectively enabled for this server. An explicit per-server *bool override wins; otherwise the stack- global default is returned. Returns false when both stack and server are nil.

func (*MCPServer) PersistMetrics

func (s *MCPServer) PersistMetrics(stack *Stack) bool

PersistMetrics — see PersistLogs for inheritance semantics.

func (*MCPServer) PersistTraces

func (s *MCPServer) PersistTraces(stack *Stack) bool

PersistTraces — see PersistLogs for inheritance semantics.

func (*MCPServer) ResolvedPingTimeout

func (s *MCPServer) ResolvedPingTimeout() time.Duration

ResolvedPingTimeout parses PingTimeout; returns 0 when unset or invalid so the gateway falls back to DefaultPingTimeout (5s).

func (*MCPServer) ResolvedReadyTimeout

func (s *MCPServer) ResolvedReadyTimeout() time.Duration

ResolvedReadyTimeout parses ReadyTimeout; returns 0 when unset or invalid so the gateway falls back to its default.

type MCPServerPersistence

type MCPServerPersistence struct {
	Logs    *bool `yaml:"logs,omitempty" json:"logs,omitempty"`
	Metrics *bool `yaml:"metrics,omitempty" json:"metrics,omitempty"`
	Traces  *bool `yaml:"traces,omitempty" json:"traces,omitempty"`
}

MCPServerPersistence is the *bool tri-state mirror of TelemetryPersistence.

type MCPServerTelemetry

type MCPServerTelemetry struct {
	Persist MCPServerPersistence `yaml:"persist,omitempty" json:"persist,omitempty"`
}

MCPServerTelemetry holds per-server telemetry persistence overrides. Each *bool field uses tri-state semantics: nil = inherit stack-global, &true = explicitly persist, &false = explicitly do not persist (overrides stack global). Never default these to &false in SetDefaults — that would collapse inherit and explicit-off into the same value.

type Network

type Network struct {
	Name   string `yaml:"name"`
	Driver string `yaml:"driver"`
}

Network defines the Docker network configuration.

type OpenAPIAuth

type OpenAPIAuth struct {
	Type     string `yaml:"type"`               // "bearer", "header", "query", "oauth2", or "basic"
	TokenEnv string `yaml:"tokenEnv,omitempty"` // Env var name containing bearer token (for type: bearer)
	Header   string `yaml:"header,omitempty"`   // Header name (for type: header, e.g., "X-API-Key")
	ValueEnv string `yaml:"valueEnv,omitempty"` // Env var name containing header value (for type: header or query)

	// Query param auth (type: query)
	ParamName string `yaml:"paramName,omitempty"` // Query parameter name (for type: query)

	// OAuth2 client credentials (type: oauth2)
	ClientIdEnv     string   `yaml:"clientIdEnv,omitempty"`     // Env var name containing OAuth2 client ID
	ClientSecretEnv string   `yaml:"clientSecretEnv,omitempty"` // Env var name containing OAuth2 client secret
	TokenUrl        string   `yaml:"tokenUrl,omitempty"`        // OAuth2 token endpoint URL
	Scopes          []string `yaml:"scopes,omitempty"`          // OAuth2 scopes to request

	// Basic auth (type: basic)
	UsernameEnv string `yaml:"usernameEnv,omitempty"` // Env var name containing username
	PasswordEnv string `yaml:"passwordEnv,omitempty"` // Env var name containing password
}

OpenAPIAuth defines authentication for OpenAPI HTTP requests.

type OpenAPIConfig

type OpenAPIConfig struct {
	Spec       string            `yaml:"spec"`                 // URL or local file path to OpenAPI spec (JSON or YAML)
	BaseURL    string            `yaml:"baseUrl,omitempty"`    // Override the server URL from the spec
	Auth       *OpenAPIAuth      `yaml:"auth,omitempty"`       // Authentication configuration
	TLS        *OpenAPITLS       `yaml:"tls,omitempty"`        // TLS/mTLS configuration (transport-layer)
	Operations *OperationsFilter `yaml:"operations,omitempty"` // Filter which operations become tools
}

OpenAPIConfig defines an MCP server backed by an OpenAPI specification. The spec is parsed and each operation becomes an MCP tool.

type OpenAPITLS

type OpenAPITLS struct {
	CertFile           string `yaml:"certFile,omitempty"`           // Client certificate file path (required for mTLS)
	KeyFile            string `yaml:"keyFile,omitempty"`            // Client private key file path (required for mTLS)
	CaFile             string `yaml:"caFile,omitempty"`             // Custom CA certificate file path
	InsecureSkipVerify bool   `yaml:"insecureSkipVerify,omitempty"` // Skip server certificate verification (dangerous)
}

OpenAPITLS defines TLS/mTLS configuration for OpenAPI HTTP connections. This is transport-layer config and can be combined with any auth type.

type OperationsFilter

type OperationsFilter struct {
	Include []string `yaml:"include,omitempty"` // Operation IDs to include (whitelist)
	Exclude []string `yaml:"exclude,omitempty"` // Operation IDs to exclude (blacklist)
}

OperationsFilter defines which OpenAPI operations to include or exclude. Only one of Include or Exclude should be specified.

type PlanDiff

type PlanDiff struct {
	HasChanges bool       `json:"hasChanges"`
	Items      []DiffItem `json:"items"`
	Summary    string     `json:"summary"`
}

PlanDiff is the complete diff between two stack specs.

func ComputePlan

func ComputePlan(proposed, current *Stack) *PlanDiff

ComputePlan compares a new spec against the currently running spec and returns a structured diff.

type ReferenceIndex

type ReferenceIndex map[string][]Consumer

ReferenceIndex maps a variable-store key to the consumers that reference it.

It is built by expandStackVars from the same grammar used for expansion (ExpandStringRefs), so it can never drift from what gridctl actually recognizes as a ${var:KEY}/${vault:KEY} reference. It carries only keys and reference-site metadata — never variable values — so it is safe to expose even while the vault is locked.

Scope:

  • One-hop only: a variable referenced inside another variable's *value* is not followed. This is intentional — values live in the vault, outside the static stack, so resolving transitive references would require reading secrets at index time. v1 indexes only references written in the stack.
  • Known gap: secrets injected via secrets.sets (see injectSetSecrets) are added to server env *after* expansion without ${var:KEY} syntax, so they are not recorded here. v1 indexes explicit references only.

type ReferenceKind

type ReferenceKind string

ReferenceKind identifies what kind of stack element references a variable.

const (
	RefKindMCPServer ReferenceKind = "mcp-server"
	RefKindResource  ReferenceKind = "resource"
	RefKindGateway   ReferenceKind = "gateway"
	RefKindNetwork   ReferenceKind = "network"
	RefKindStack     ReferenceKind = "stack"
)

type ReplicaHealth

type ReplicaHealth struct {
	ReplicaID        int    `json:"replicaId"`
	State            string `json:"state"` // "healthy" | "unhealthy" | "restarting"
	InFlight         int64  `json:"inFlight"`
	UptimeSeconds    int64  `json:"uptimeSeconds,omitempty"`
	LastError        string `json:"lastError,omitempty"`
	NextRetrySeconds int64  `json:"nextRetrySeconds,omitempty"`
	RestartAttempts  uint32 `json:"restartAttempts,omitempty"`
	PID              int    `json:"pid,omitempty"`
	ContainerID      string `json:"containerId,omitempty"`
}

ReplicaHealth describes the live state of one replica in a server's ReplicaSet. Durations use seconds so the JSON representation does not depend on Go's time formatting.

type Resolver

type Resolver func(name string) (string, bool)

Resolver looks up a variable by name. Returns value and whether it exists.

func EnvResolver

func EnvResolver() Resolver

EnvResolver returns a resolver that checks os.LookupEnv.

func VaultResolver

func VaultResolver(vault VaultLookup) Resolver

VaultResolver returns a resolver that checks vault first, then env.

type Resource

type Resource struct {
	Name    string            `yaml:"name"`
	Image   string            `yaml:"image"`
	Env     map[string]string `yaml:"env,omitempty"`
	Ports   []string          `yaml:"ports,omitempty"`
	Volumes []string          `yaml:"volumes,omitempty"`
	Network string            `yaml:"network,omitempty"` // Network to join (for multi-network mode)
}

Resource defines a supporting container (database, cache, etc).

type RetentionConfig

type RetentionConfig struct {
	MaxSizeMB  int `yaml:"max_size_mb,omitempty" json:"max_size_mb,omitempty"`
	MaxBackups int `yaml:"max_backups,omitempty" json:"max_backups,omitempty"`
	MaxAgeDays int `yaml:"max_age_days,omitempty" json:"max_age_days,omitempty"`
}

RetentionConfig controls lumberjack rotation for persisted telemetry files. One block per stack — per-signal retention is intentionally out of scope at MVP. Defaults: 100MB / 5 backups / 7d. YAML tags use snake_case to match the AutoscaleConfig precedent for control-plane structs (LoggingConfig uses camelCase, but is closer to a runtime-rotation knob than a control-plane resource).

type SSHConfig

type SSHConfig struct {
	Host           string `yaml:"host"`                     // Required: hostname or IP address
	User           string `yaml:"user"`                     // Required: SSH username
	Port           int    `yaml:"port,omitempty"`           // Optional: SSH port (default 22)
	IdentityFile   string `yaml:"identityFile,omitempty"`   // Optional: path to SSH private key
	KnownHostsFile string `yaml:"knownHostsFile,omitempty"` // Optional: path to known_hosts file; enables StrictHostKeyChecking=yes
	JumpHost       string `yaml:"jumpHost,omitempty"`       // Optional: bastion/jump host ([user@]host[:port])
}

SSHConfig defines SSH connection parameters for remote MCP servers.

type SchemaPinningConfig

type SchemaPinningConfig struct {
	// Enabled controls whether schema pinning is active. Default: true.
	// A pointer so an omitted `enabled:` inherits the default-on behavior
	// rather than YAML's zero value (false); set it explicitly to false to
	// disable pinning for the whole stack.
	Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
	// Action is the response when drift is detected: "warn" (default) or "block".
	// warn: log a structured diff and continue serving.
	// block: reject all tool calls from the drifted server until approved.
	Action string `yaml:"action,omitempty" json:"action,omitempty"`
}

SchemaPinningConfig controls the schema pinning feature.

type Secrets

type Secrets struct {
	Sets []string `yaml:"sets,omitempty" json:"sets,omitempty"`
}

Secrets configures automatic secret injection from variable sets.

type Source

type Source struct {
	Type       string      `yaml:"type"` // "git" or "local"
	URL        string      `yaml:"url,omitempty"`
	Ref        string      `yaml:"ref,omitempty"`
	Path       string      `yaml:"path,omitempty"`
	Dockerfile string      `yaml:"dockerfile,omitempty"`
	Auth       *SourceAuth `yaml:"auth,omitempty"`
}

Source defines how to build an MCP server from source code.

type SourceAuth

type SourceAuth struct {
	Method        string `yaml:"method,omitempty"`         // "", "none", "token", "ssh-agent", "ssh-key"
	CredentialRef string `yaml:"credential_ref,omitempty"` // e.g. "${vault:GIT_TOKEN}" — resolved on every clone/fetch
	SSHUser       string `yaml:"ssh_user,omitempty"`       // defaults to "git" when empty
	SSHKeyPath    string `yaml:"ssh_key_path,omitempty"`   // required for method "ssh-key"
}

SourceAuth is the declarative auth block on an MCP server git source. Raw tokens must NOT appear here — use CredentialRef (e.g. "${vault:GIT_TOKEN}") which is resolved against the live vault at clone time. Never add a Token field to this struct: anything with a yaml tag here gets persisted to disk.

type SpecHealth

type SpecHealth struct {
	Validation   ValidationStatus `json:"validation"`
	Drift        DriftStatus      `json:"drift"`
	Dependencies DependencyStatus `json:"dependencies"`

	// Replicas reports live per-replica health for every server that has
	// more than one replica registered. Servers with replicas <= 1 are
	// omitted so the shape is backward compatible with single-replica
	// deployments. Keyed by server name.
	Replicas map[string][]ReplicaHealth `json:"replicas,omitempty"`
}

SpecHealth aggregates validation, drift, and dependency status.

type Stack

type Stack struct {
	Version    string           `yaml:"version"`
	Name       string           `yaml:"name"`
	Extends    string           `yaml:"extends,omitempty"` // Path to a parent stack file for composition
	Gateway    *GatewayConfig   `yaml:"gateway,omitempty"`
	Logging    *LoggingConfig   `yaml:"logging,omitempty"`
	Telemetry  *TelemetryConfig `yaml:"telemetry,omitempty"` // Opt-in disk persistence for logs/metrics/traces
	Secrets    *Secrets         `yaml:"secrets,omitempty"`   // Variable set references
	Network    Network          `yaml:"network"`             // Single network (simple mode)
	Networks   []Network        `yaml:"networks,omitempty"`  // Multiple networks (advanced mode)
	MCPServers []MCPServer      `yaml:"mcp-servers"`
	Resources  []Resource       `yaml:"resources,omitempty"`
	Clients    *ClientsConfig   `yaml:"clients,omitempty"` // Optional per-client access scoping (NetworkPolicy semantics)

	// ClientModels declares which model each connecting client runs, purely
	// for cost attribution: tool calls from a declared client are priced at
	// that model's rates ahead of any per-server model or gateway
	// default_model. Keys are stable client identifiers (the same form used
	// by clients.profiles and shown on the topology — e.g. "claude-code").
	// The map has zero effect on access policy: declaring a model never
	// requires a clients: block and never restricts an unlisted client.
	// Empty (the default) disables the client pricing tier.
	ClientModels map[string]string `yaml:"client_models,omitempty" json:"client_models,omitempty"`

	// References is the variable-usage index, derived during expandStackVars:
	// which consumers reference each ${var:KEY}/${vault:KEY} key. It is computed
	// from the stack, not persisted with it — the yaml/json "-" tags keep it out
	// of every existing serialization path. Nil until a stack is loaded/expanded.
	References ReferenceIndex `yaml:"-" json:"-"`
}

Stack represents the complete gridctl configuration.

func LoadStack

func LoadStack(path string, opts ...LoadOption) (*Stack, error)

LoadStack reads and parses a stack file.

func (*Stack) ClientModelAttribution

func (s *Stack) ClientModelAttribution() map[string]string

ClientModelAttribution returns the client ID -> model mapping used to price tool calls by calling client, the highest-precedence configured tier (a call-level model reported by the server still wins over it). Entries with empty values are skipped. Returns nil when nothing is configured, which keeps the client pricing tier inert. Keys are NOT re-normalized: they must already be canonical client IDs (see NormalizeClientID in pkg/mcp/clientid.go); ValidateWithIssues warns on keys that are not.

func (*Stack) ContainerWorkloads

func (s *Stack) ContainerWorkloads() []string

ContainerWorkloads returns human-readable descriptions of workloads that require a container runtime.

func (*Stack) ModelAttribution

func (s *Stack) ModelAttribution() map[string]string

ModelAttribution builds the server name -> effective model mapping used to price tool calls: a server's own Model field wins, then the gateway-level DefaultModel. Servers with no effective model are omitted. Returns nil when no attribution is configured anywhere, which keeps the cost path inert.

func (*Stack) NeedsContainerRuntime

func (s *Stack) NeedsContainerRuntime() bool

NeedsContainerRuntime returns true if the stack has workloads requiring a container runtime.

func (*Stack) NonContainerWorkloads

func (s *Stack) NonContainerWorkloads() []string

NonContainerWorkloads returns human-readable descriptions of workloads that work without a container runtime.

func (*Stack) SetDefaults

func (s *Stack) SetDefaults()

SetDefaults applies default values to the stack.

type TelemetryConfig

type TelemetryConfig struct {
	// Persist names which signals are written to disk by default. Per-server
	// blocks can override individual signals.
	Persist TelemetryPersistence `yaml:"persist,omitempty" json:"persist,omitempty"`
	// Retention controls lumberjack rotation for every persisted signal file.
	// SetDefaults fills sensible defaults when this block is omitted.
	Retention *RetentionConfig `yaml:"retention,omitempty" json:"retention,omitempty"`
}

TelemetryConfig configures opt-in disk persistence for the three signals gridctl already captures (logs, metrics, traces). All fields are optional; when the block is omitted entirely, every signal stays ephemeral (today's behavior). Per-server overrides on MCPServer.Telemetry can flip individual signals on or off relative to these defaults.

Stack-global Persist fields are plain bool (binary on/off). Per-server MCPServerPersistence fields are *bool to express tri-state inheritance — see MCPServerTelemetry.

type TelemetryPersistence

type TelemetryPersistence struct {
	Logs    bool `yaml:"logs,omitempty" json:"logs,omitempty"`
	Metrics bool `yaml:"metrics,omitempty" json:"metrics,omitempty"`
	Traces  bool `yaml:"traces,omitempty" json:"traces,omitempty"`
}

TelemetryPersistence is the stack-global signal toggle. Stack-global is binary (a bool) — the per-server override carries the tri-state.

type TracingConfig

type TracingConfig struct {
	// Enabled controls whether tracing is active. Default: true.
	// A pointer so an omitted `enabled:` inherits the default-on behavior
	// rather than YAML's zero value (false); set it explicitly to false to
	// disable tracing.
	Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
	// Sampling is the head-based sampling rate [0.0, 1.0]. Default: 1.0.
	Sampling float64 `yaml:"sampling,omitempty" json:"sampling,omitempty"`
	// Retention is how long completed traces are kept in memory (e.g. "24h"). Default: "24h".
	Retention string `yaml:"retention,omitempty" json:"retention,omitempty"`
	// Export selects an exporter: "otlp" or "" (none).
	Export string `yaml:"export,omitempty" json:"export,omitempty"`
	// Endpoint is the OTLP endpoint URL (e.g. "http://localhost:4318").
	Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"`
	// MaxTraces is the in-memory ring buffer capacity (number of traces). Default: 1000.
	MaxTraces int `yaml:"max_traces,omitempty" json:"max_traces,omitempty"`
}

TracingConfig configures distributed tracing for the gateway.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a configuration validation error.

func (ValidationError) Error

func (e ValidationError) Error() string

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is a collection of validation errors.

func (ValidationErrors) Error

func (e ValidationErrors) Error() string

type ValidationIssue

type ValidationIssue struct {
	Field    string        `json:"field"`
	Message  string        `json:"message"`
	Severity IssueSeverity `json:"severity"`
}

ValidationIssue is a validation finding with severity level.

type ValidationResult

type ValidationResult struct {
	Valid        bool              `json:"valid"`
	ErrorCount   int               `json:"errorCount"`
	WarningCount int               `json:"warningCount"`
	Issues       []ValidationIssue `json:"issues"`
}

ValidationResult holds the complete output of spec validation.

func ValidateWithIssues

func ValidateWithIssues(s *Stack) *ValidationResult

ValidateWithIssues runs full validation and returns structured issues with severity. This wraps the existing Validate() and adds warning-level checks.

type ValidationStatus

type ValidationStatus struct {
	Status       string `json:"status"` // "valid", "warnings", "errors"
	ErrorCount   int    `json:"errorCount"`
	WarningCount int    `json:"warningCount"`
}

ValidationStatus summarizes the spec validation state.

type VaultLookup

type VaultLookup interface {
	Get(key string) (string, bool)
}

VaultLookup is the interface the vault store must satisfy.

type VaultSecret

type VaultSecret struct {
	Key   string
	Value string
}

VaultSecret is a minimal secret view for set lookups.

type VaultSetLookup

type VaultSetLookup interface {
	VaultLookup
	GetSetSecrets(setName string) []VaultSecret
}

VaultSetLookup extends VaultLookup with set operations for secrets.sets support.

Jump to

Keyboard shortcuts

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