Documentation
¶
Overview ¶
Package config loads and validates the runtime configuration.
Environment variables (GITLAB_MCP_*) are the source of truth, because an MCP client passes only command, args and env to a stdio server. Most settings also have a flag bound to the same name; a flag given on the command line wins over the environment, and the environment over the default. Build validates once and reports every problem together, so a misconfigured server fails before it announces itself.
Vars lists every variable. Define binds from it, and the staleness gate holds docs/configuration.md (and, for the development override, docs/development.md) against it, so a setting cannot be added without being documented.
Index ¶
Constants ¶
const ( MinHTTPTimeout = time.Second MaxHTTPTimeout = 10 * time.Minute )
HTTP timeout bounds. Below a second nothing completes; above ten minutes a hung call holds the client longer than anyone waits.
const ( EnvProfile = EnvPrefix + "PROFILE" EnvClientID = EnvPrefix + "CLIENT_ID" EnvReadOnly = EnvPrefix + "READ_ONLY" EnvEnableShip = EnvPrefix + "ENABLE_SHIP" EnvEnableDestructive = EnvPrefix + "ENABLE_DESTRUCTIVE" EnvToolsets = EnvPrefix + "TOOLSETS" EnvWriteNamespaces = EnvPrefix + "WRITE_NAMESPACES" EnvLogLevel = EnvPrefix + "LOG_LEVEL" EnvLogFormat = EnvPrefix + "LOG_FORMAT" EnvHTTPTimeout = EnvPrefix + "HTTP_TIMEOUT" EnvConfigDir = EnvPrefix + "CONFIG_DIR" EnvConfigDirAllowOutsideHome = EnvPrefix + "CONFIG_DIR_ALLOW_OUTSIDE_HOME" // EnvRefreshToken is read by internal/credentials, never by Build, // and has no flag: a secret on a command line is visible to every // process on the machine. EnvRefreshToken = EnvPrefix + "REFRESH_TOKEN" // EnvTestInstance points the server at a loopback stand-in for // gitlab.com: the in-memory instance the tests, the evals and the // smoke gate run. It has no flag and is refused for any other host, // so it cannot send a token to a real one. EnvTestInstance = EnvPrefix + "TEST_INSTANCE" )
Variable names.
const DefaultHTTPTimeout = 60 * time.Second
DefaultHTTPTimeout bounds one attempt at an API call.
const EnvPrefix = "GITLAB_MCP_"
EnvPrefix is prepended to every environment variable name. Not GITLAB_: CI jobs already set GITLAB_CI, GITLAB_USER_LOGIN and more (§18 row 30).
const ToolsetAll = "all"
ToolsetAll names every toolset at once.
Variables ¶
var ErrInvalid = errors.New("config: invalid")
ErrInvalid wraps every validation failure.
var Toolsets = []string{"activity", "deployments", "planning", "releases", "snippets", "wiki"}
Toolsets are the optional toolsets, sorted, which are off unless named (§4.3).
var Vars = []Var{ {Name: EnvProfile, Flag: "profile", Doc: "named sign-in profile; unset means \"default\""}, {Name: EnvClientID, Flag: "client-id", Doc: "the OAuth application id (overrides the stored profile's)"}, {Name: EnvReadOnly, Flag: "read-only", Default: "false", Switch: true, Doc: "register only the read tools and request read_api"}, {Name: EnvEnableShip, Flag: "enable-ship", Default: "false", Switch: true, Doc: "register merging, approving, running CI and creating releases"}, {Name: EnvEnableDestructive, Flag: "enable-destructive", Default: "false", Switch: true, Doc: "register deletions, each of which also needs confirm: true"}, {Name: EnvToolsets, Flag: "toolsets", Doc: "comma-separated optional toolsets: " + strings.Join(Toolsets, ", ") + ", or all"}, {Name: EnvWriteNamespaces, Flag: "write-namespaces", Doc: "comma-separated groups or projects that writes are confined to; unset means anywhere"}, {Name: EnvLogLevel, Flag: "log-level", Default: string(LogInfo), Doc: "log level: debug, info, warn, error"}, {Name: EnvLogFormat, Flag: "log-format", Default: string(LogText), Doc: "log format: text, json"}, {Name: EnvHTTPTimeout, Flag: "http-timeout", Default: DefaultHTTPTimeout.String(), Doc: "deadline for one attempt at an API call, between 1s and 10m"}, {Name: EnvConfigDir, Flag: "config-dir", Doc: "directory for profiles; must be inside your home directory"}, {Name: EnvConfigDirAllowOutsideHome, Default: "false", Switch: true, Doc: "accept a config directory outside your home directory"}, {Name: EnvRefreshToken, Doc: "a refresh token to use instead of the stored one (CI, automation)"}, {Name: EnvTestInstance, Dev: true, Doc: "a loopback base URL that stands in for gitlab.com, for tests only"}, }
Vars is every variable this server reads, in documentation order.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Instance is gitlab.com, or the loopback stand-in of
// GITLAB_MCP_TEST_INSTANCE. Zero means gitlab.com; use Target.
Instance instance.Instance
// TestInstance says GITLAB_MCP_TEST_INSTANCE is set.
TestInstance bool
// Profile is the profile named, or empty for "default".
Profile string
// ClientID overrides the profile's stored OAuth application id.
ClientID string
// ReadOnly registers the Read kind only and requests read_api.
ReadOnly bool
// EnableShip registers the Ship kind. It changes no scope (§9.4).
EnableShip bool
// EnableDestructive registers the Destructive kind. It changes no
// scope either.
EnableDestructive bool
// Toolsets are the optional toolsets turned on, sorted, with "all"
// expanded.
Toolsets []string
// WriteNamespaces confine Write, Ship and Destructive (§4.7). Empty
// means no confinement.
WriteNamespaces []string
LogLevel LogLevel
LogFormat LogFormat
HTTPTimeout time.Duration
// ConfigDir is the resolved base directory for profiles.
ConfigDir userconfig.Dir
}
Config is the validated runtime configuration.
func (Config) Target ¶
Target is the instance this configuration talks to: gitlab.com unless the test override names another.
func (Config) ToolsetEnabled ¶
ToolsetEnabled reports whether an optional toolset is on.
type LogLevel ¶
type LogLevel string
LogLevel is a typed enum constrained at load time.
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
Settings holds the raw values before validation, keyed by variable.
type Var ¶
type Var struct {
// Name is the environment variable.
Name string
// Flag is the command-line flag bound to it, without dashes; empty
// for a variable read from the environment only.
Flag string
// Default is the value used when neither is given.
Default string
// Doc says what it does.
Doc string
// Switch marks a boolean: a bare --flag means true.
Switch bool
// Dev marks a development override: documented in
// docs/development.md rather than docs/configuration.md, and never
// offered to the people running the server.
Dev bool
}
Var is one configuration variable.