Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package config reads and atomically edits tap's ordered server registry and its settings. It expands environment and home references only when a connection is opened.

Index

Constants

View Source
const (
	StartOnCall   = "call"   // only a call starts the server, once tap knows its tools
	StartOnSearch = "search" // a search starts it too, to check its tools again
	StartWithTap  = "start"  // it starts with tap and keeps running
)

Starts are the values of the start setting, from laziest to most eager.

Variables

View Source
var Settings = []Setting{
	{Name: "start", About: "when tap starts a server: call, search or start", Default: "call", PerServer: true, /* contains filtered or unexported fields */},
	{Name: "references", About: "let an agent keep large results as references: on or off", Default: "off", Env: "TAP_REFERENCES", /* contains filtered or unexported fields */},
	{Name: "searchLimit", About: "how many tools a search returns unless asked for more (1 to 25)", Default: "8", /* contains filtered or unexported fields */},
	{Name: "searchMaxBytes", About: "how much a search may return unless asked for more (1024 to 16777216)", Default: "32768", /* contains filtered or unexported fields */},
	{Name: "deadlineMs", About: "how long a server may take to connect and list its tools", Default: "5000", Env: "TAP_DEADLINE_MS", /* contains filtered or unexported fields */},
	{Name: "idleTimeoutMs", About: "how long an unused server keeps running", Default: "300000", Env: "TAP_IDLE_TTL_MS", PerServer: true, /* contains filtered or unexported fields */},
	{Name: "retryAfterMs", About: "how long tap waits before trying a failed server again", Default: "5000", Env: "TAP_FAIL_TTL_MS", /* contains filtered or unexported fields */},
}

Settings lists every setting, in the order tap shows them.

Functions

func Add

func Add(path, name string, def wire.Object) error

Add saves one server without losing concurrent edits or relay settings.

func Expand

func Expand(value any) string

Expand replaces ${NAME} in an arbitrary config value; unknown variables are empty.

func Home

func Home(value string) string

Home resolves only ~ and ~/ prefixes, matching the shared config's contract.

func JSONError

func JSONError(data []byte, fallback error) string

JSONError reports invalid JSON using the original CLI's JSON.parse diagnostics. Parsing valid values remains the standard library's job; this is only an error formatter.

func Load

func Load(path string) (wire.Object, error)

Load reads the local servers while validating the entire config.

func Loopback

func Loopback(host string) bool

Loopback accepts literal loopback addresses and localhost, without DNS resolution.

func NormalizeURL

func NormalizeURL(raw string, insecure bool) (string, error)

NormalizeURL accepts a remote base URL or its /mcp endpoint, without credentials.

func Path

func Path() string

Path returns TAP_CONFIG, or the default home-relative path when it is empty.

func Remove

func Remove(path, name string) (bool, error)

Remove deletes a named local server, reporting whether it existed.

func Save

func Save(path string, servers wire.Object) error

Save replaces local servers while preserving remote and other root settings.

func Set

func Set(path, server, name string, value any) error

Set keeps a value for a setting: in the settings block, or in one server's definition. A nil value removes it, so the default or the block applies again.

func SetRemote

func SetRemote(path string, r *Remote) error

SetRemote installs a validated relay block, or removes it when nil.

Types

type Own

type Own struct{ Server, Name, Text string }

Own is a setting a server has of its own.

func Owned

func Owned(path string) ([]Own, error)

Owned lists the settings servers have of their own, in the config's order.

type Remote

type Remote struct {
	URL           string `json:"url"`
	TokenEnv      string `json:"tokenEnv"`
	AllowInsecure bool   `json:"allowInsecure,omitempty"`
}

Remote selects the relay endpoint and the environment variable holding its token.

func LoadRemote

func LoadRemote(path string) (*Remote, error)

LoadRemote returns nil only when the remote block is absent.

type Setting

type Setting struct {
	Name, About, Default, Env string
	PerServer                 bool
	// contains filtered or unexported fields
}

Setting is one choice a person may make about how tap behaves. It is kept under its Name in the config's settings block, and PerServer ones also in a server's own definition, where they win over the block. Env, when set, names the environment variable that wins over both.

func Find

func Find(name string) (Setting, bool)

Find returns the setting with this name.

func (Setting) Parse

func (s Setting) Parse(text string) (any, error)

Parse turns text into the value the setting keeps, or says what it takes.

type Value

type Value struct {
	Setting
	Text, From string
}

Value is one setting as it stands: what it is, as text, and where it came from: "default", "config" or the environment variable's name.

func Current

func Current(path string) ([]Value, error)

Current reads every setting: its default, then the config's settings block, then its environment variable. A variable whose value the setting does not take is ignored.

type Values

type Values struct {
	Start                                   string
	References                              bool
	SearchLimit, SearchMaxBytes             int
	DeadlineMs, IdleTimeoutMs, RetryAfterMs int
}

Values are the settings a tap process runs with.

func LoadValues

func LoadValues(path string) Values

LoadValues reads the values a tap process runs with. A config that cannot be read gives the defaults and the environment, since whatever reads it next reports why.

Jump to

Keyboard shortcuts

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