Documentation
¶
Overview ¶
Package config loads, defaults, and validates the gateway's declarative YAML configuration. Loading fails fast: a malformed file, an unknown field, a missing referenced secret, or a rule naming an unknown downstream or client is an error at startup rather than a surprise at request time (design §7, §8).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Audit ¶
type Audit struct {
// Sink is "stdout" or "file:/path/to/audit.jsonl".
Sink string `yaml:"sink"`
// Buffer is the bounded handoff buffer size.
Buffer int `yaml:"buffer"`
// HighWaterMark is the buffer fraction above which success records shed.
HighWaterMark float64 `yaml:"high_water_mark"`
// Flush controls batch flushing to the OS page cache.
Flush Flush `yaml:"flush"`
// FsyncInterval is the group-commit interval to disk.
FsyncInterval Duration `yaml:"fsync_interval"`
// Overflow is the success-record overflow policy: "shed" or "block".
Overflow OverflowPolicy `yaml:"overflow"`
// SecurityBlockTimeout bounds how long a security record blocks before the
// request is failed closed.
SecurityBlockTimeout Duration `yaml:"security_block_timeout"`
}
Audit configures the async audit write path.
type Config ¶
type Config struct {
// Listen is the host:port the client-facing server binds.
Listen string `yaml:"listen"`
// AllowedOrigins is the Origin allowlist for the DNS-rebinding guard.
AllowedOrigins []string `yaml:"allowed_origins"`
// Clients are the authenticated client identities.
Clients []Client `yaml:"clients"`
// Downstreams are the MCP servers the gateway proxies.
Downstreams []Downstream `yaml:"downstreams"`
// Policy is the deny-by-default access policy.
Policy Policy `yaml:"policy"`
// Redaction configures outbound secret and PII redaction.
Redaction Redaction `yaml:"redaction"`
// Audit configures the audit write path.
Audit Audit `yaml:"audit"`
}
Config is the gateway configuration.
func Load ¶
Load reads, defaults, and validates the configuration at path. Any failure — unreadable file, malformed YAML, unknown field, or a validation error — is returned, so a bad configuration stops startup rather than surfacing later.
func (*Config) Validate ¶
Validate checks the configuration and returns a combined error describing every problem found, or nil if the configuration is sound. It is the fail-fast gate: a missing referenced secret, an unknown transport or session_mode, a rule naming an unknown client or downstream, an uncompilable redaction pattern, or an out-of-range tuning value is reported here rather than at request time (design §7, §8).
type Downstream ¶
type Downstream struct {
Name string `yaml:"name"`
// Transport is "stdio" or "http".
Transport Transport `yaml:"transport"`
// Command is the stdio subprocess argv (stdio transport only).
Command []string `yaml:"command"`
// URL is the remote endpoint (http transport only).
URL string `yaml:"url"`
// SessionMode applies to stdio downstreams; it defaults to per_client.
SessionMode SessionMode `yaml:"session_mode"`
// Pool bounds the stdio subprocess pool (stdio transport only).
Pool Pool `yaml:"pool"`
// Secrets are connection-level credentials injected by the gateway, keyed by
// env var (stdio) or header name (http), each resolved from an env var.
Secrets map[string]SecretRef `yaml:"secrets"`
// Health configures the downstream health check.
Health Health `yaml:"health"`
}
Downstream is one downstream MCP server.
type Duration ¶
Duration is a time.Duration that unmarshals from a YAML string such as "2s" or "90s", so durations read naturally in the config file.
type Flush ¶
type Flush struct {
MaxRecords int `yaml:"max_records"`
MaxInterval Duration `yaml:"max_interval"`
}
Flush controls audit batch flushing.
type Health ¶
type Health struct {
Interval Duration `yaml:"interval"`
}
Health configures a downstream health check.
type OverflowPolicy ¶
type OverflowPolicy string
OverflowPolicy is the audit buffer's policy for success records under load.
const ( OverflowShed OverflowPolicy = "shed" OverflowBlock OverflowPolicy = "block" )
type Pattern ¶
type Pattern struct {
Name string `yaml:"name"`
Regex string `yaml:"regex"`
Anchor string `yaml:"anchor"`
}
Pattern is a literal-gated PII regex: the regex runs only when Anchor is present in the scanned text.
type Policy ¶
type Policy struct {
Default PolicyDefault `yaml:"default"`
Rules []Rule `yaml:"rules"`
}
Policy is the access policy.
type PolicyDefault ¶
type PolicyDefault string
PolicyDefault is the default access decision when no rule matches.
const ( DefaultDeny PolicyDefault = "deny" DefaultAllow PolicyDefault = "allow" )
type Pool ¶
type Pool struct {
Max int `yaml:"max"`
AcquireTimeout Duration `yaml:"acquire_timeout"`
IdleTTL Duration `yaml:"idle_ttl"`
}
Pool bounds an stdio subprocess pool.
type Redaction ¶
type Redaction struct {
Patterns []Pattern `yaml:"patterns"`
// MaxResultBytes caps a buffered tool result before scanning.
MaxResultBytes int `yaml:"max_result_bytes"`
}
Redaction configures outbound redaction.
type SecretRef ¶
type SecretRef struct {
Env string `yaml:"env"`
}
SecretRef names the environment variable holding a secret value.
type SessionMode ¶
type SessionMode string
SessionMode controls how stdio subprocesses are shared across client sessions.
const ( SessionPerClient SessionMode = "per_client" )