config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: GPL-3.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config loads and validates agentgate.yaml.

Index

Constants

View Source
const (
	DefaultPrefixSeparator = "__"
	DefaultCallTimeout     = 120 * time.Second
	DefaultApprovalTimeout = 60 * time.Second
	DefaultRetention       = 30 * 24 * time.Hour
	DefaultMaxResultBytes  = 256 * 1024
	DefaultAuditPath       = "~/.agentgate/audit.db"
	DefaultUIAddr          = "127.0.0.1:7777"
)

Defaults that apply when the config file leaves a field out.

View Source
const (
	EventDeny     = "deny"
	EventAsk      = "ask"
	EventHoneypot = "honeypot"
	EventFreeze   = "freeze"
	EventError    = "error"
	EventShadow   = "shadow"
)

Event names a webhook can subscribe to.

Variables

View Source
var DefaultWebhookEvents = []string{EventDeny, EventAsk, EventHoneypot, EventFreeze}

DefaultWebhookEvents are sent when a webhook does not say which it wants.

Functions

func BuiltinRedactionPatterns

func BuiltinRedactionPatterns() []string

BuiltinRedactionPatterns returns the source of the built-in patterns, for documentation and for the web UI.

func BuiltinRedactors

func BuiltinRedactors() []*regexp.Regexp

BuiltinRedactors returns the patterns agentgate redacts out of the box.

func ExpandEnv

func ExpandEnv(s string) string

ExpandEnv replaces ${VAR} and $VAR with the value from the environment. Unset variables expand to the empty string, matching how MCP host configs behave.

func ExpandPath

func ExpandPath(p string) (string, error)

ExpandPath expands ${ENV} and a leading ~ in a filesystem path.

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses "30d", "2w", "90m", "1h30m" and everything else time.ParseDuration accepts.

Types

type Approval

type Approval struct {
	// Mode is auto, tty, ui or deny.
	//
	//	auto  use the web UI when it is running, else the TTY, else deny
	//	tty   prompt on the agentgate terminal only
	//	ui    wait for an approval in the web UI only
	//	deny  never ask, deny every "ask" decision
	Mode    string   `yaml:"mode"`
	Timeout Duration `yaml:"timeout"`
}

Approval configures what happens to calls a rule marked "ask".

type Audit

type Audit struct {
	// Enabled defaults to true; set it to false to run without an audit trail.
	Enabled   *bool    `yaml:"enabled"`
	Path      string   `yaml:"path"`
	Retention Duration `yaml:"retention"`
	// Redact holds regexes applied to arguments and results before they are
	// written. They are added to the built-in patterns unless BuiltinRedaction
	// is false.
	Redact           []string `yaml:"redact"`
	BuiltinRedaction *bool    `yaml:"builtin_redaction"`
	// MaxResultBytes caps how much of a result is stored. Larger results are
	// truncated and flagged.
	MaxResultBytes int `yaml:"max_result_bytes"`
	// contains filtered or unexported fields
}

Audit configures the SQLite audit store.

func (*Audit) Redactors

func (a *Audit) Redactors() []*regexp.Regexp

Redactors returns the compiled redaction patterns.

type Config

type Config struct {
	Version int `yaml:"version"`
	// PrefixSeparator joins the upstream name and the tool name. It defaults to
	// "__" because some MCP hosts reject dots in tool names; policy rules may
	// still be written with a dot either way.
	PrefixSeparator string        `yaml:"prefix_separator"`
	CallTimeout     Duration      `yaml:"call_timeout"`
	Approval        Approval      `yaml:"approval"`
	Audit           Audit         `yaml:"audit"`
	Upstreams       []Upstream    `yaml:"upstreams"`
	Policy          policy.Policy `yaml:"policy"`
	Honeypots       Honeypots     `yaml:"honeypots"`
	Notify          Notify        `yaml:"notify"`

	// Path is the file the config was read from. It is not part of the file.
	Path string `yaml:"-"`
}

Config is the whole of agentgate.yaml.

func Load

func Load(path string) (*Config, error)

Load reads, expands and validates a config file.

func Parse

func Parse(raw []byte) (*Config, error)

Parse decodes and validates config bytes. Unknown fields are an error, so a misspelled key is caught by "agentgate policy validate" rather than silently ignored at run time.

func (*Config) AuditEnabled

func (c *Config) AuditEnabled() bool

AuditEnabled reports whether calls should be recorded.

func (*Config) FreezeFile

func (c *Config) FreezeFile() string

FreezeFile is the path of the kill-switch marker. It sits next to the audit database so that every agentgate process reading the same config agrees on it, and so that `agentgate freeze` works with no proxy running at all.

func (*Config) Prefixed

func (c *Config) Prefixed(u *Upstream, tool string) string

Prefixed returns the name a tool of upstream u is exposed under.

func (*Config) SplitTool

func (c *Config) SplitTool(exposed string) (upstream string, tool string, ok bool)

SplitTool resolves an exposed tool name back to an upstream and the name the upstream uses. It reports false when no configured upstream can own the name.

func (*Config) Timeout

func (c *Config) Timeout(u *Upstream) time.Duration

Timeout returns the per-call timeout for an upstream.

type Duration

type Duration time.Duration

Duration is a time.Duration that also understands the day and week suffixes used in the config file ("30d", "2w"), which time.ParseDuration rejects.

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration returns the value as a time.Duration.

func (Duration) Or

func (d Duration) Or(fallback time.Duration) time.Duration

Or returns d, or fallback when d is zero.

func (Duration) String

func (d Duration) String() string

String prints whole days and weeks the way they were written in the config, so "retention 30d" does not read back as "720h0m0s".

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML accepts both "30d" and a plain number of seconds.

type Honeypot

type Honeypot struct {
	// Name is the exact name the host sees. Give it a prefix that matches a
	// real upstream if you want it to blend in ("fs__delete_everything").
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
}

Honeypot is one decoy tool.

type Honeypots

type Honeypots struct {
	// Action is what tripping a honeypot does beyond denying the call:
	// "deny" (the default) or "freeze", which also throws the kill switch.
	Action string `yaml:"action"`
	// Tools are the decoys. Each needs a name; a description makes it more
	// convincing, and the whole point is to be convincing.
	Tools []Honeypot `yaml:"tools"`
}

Honeypots are tools that do not exist. They are advertised to the host like any other tool, and a call to one is proof that the agent is acting on instructions you did not give it — a prompt injection, a hallucinated capability, or a model that has decided to be creative. Nothing is ever forwarded; the call is denied, recorded and, if you say so, freezes the gateway.

type Notify

type Notify struct {
	Webhooks []Webhook `yaml:"webhooks"`
}

Notify sends events to the outside world.

type Upstream

type Upstream struct {
	Name string `yaml:"name"`
	// Stdio is the command and arguments to run, for a stdio server.
	Stdio []string `yaml:"stdio"`
	// HTTP is the endpoint of a Streamable HTTP server.
	HTTP string `yaml:"http"`
	// Env is added to the environment of a stdio server. Values may reference
	// the agentgate process environment with ${VAR}.
	Env map[string]string `yaml:"env"`
	// Cwd is the working directory of a stdio server.
	Cwd string `yaml:"cwd"`
	// Headers are sent with every request to an HTTP server.
	Headers map[string]string `yaml:"headers"`
	// Prefix controls whether this upstream's tools are exposed with a
	// "<name><sep>" prefix. It defaults to true when more than one upstream is
	// configured and to false for a single upstream.
	Prefix  *bool    `yaml:"prefix"`
	Timeout Duration `yaml:"timeout"`
}

Upstream is one real MCP server agentgate connects to.

func (*Upstream) Transport

func (u *Upstream) Transport() string

Transport reports how the upstream is reached.

type Webhook

type Webhook struct {
	URL string `yaml:"url"`
	// Events is the subset to send: deny, ask, honeypot, freeze, error,
	// shadow. Empty means deny, ask, honeypot and freeze.
	Events []string `yaml:"events"`
	// Format shapes the body: "json" (the default, agentgate's own event
	// object), "slack", "discord" or "ntfy". The named ones post a message
	// the service renders as-is, so a webhook URL from any of them works
	// with no glue in between.
	Format  string            `yaml:"format"`
	Headers map[string]string `yaml:"headers"`
}

Webhook is one HTTP endpoint that wants to hear about events.

func (*Webhook) Wants

func (w *Webhook) Wants(event string) bool

Wants reports whether the webhook subscribed to an event.

Jump to

Keyboard shortcuts

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