Documentation
¶
Overview ¶
Package config loads, normalizes, and validates runtime configuration for the GitLab MCP server.
Configuration comes from environment variables, .env files, and CLI flags in cmd/server. The package centralizes defaults and bounds for stdio mode, HTTP mode, OAuth token verification, auto-update behavior, upload limits, safe mode, read-only mode, rate limiting, tool surfaces, capability surfaces, and meta-tool schema detail.
Validation Model ¶
Loaders keep user-facing configuration forgiving while preserving hard bounds that protect runtime behavior: URL values are parsed and normalized, duration and size fields are clamped to documented limits, and invalid enum values are reported before server registration begins.
http_overlay.go layers environment variables underneath the HTTP-mode CLI flags.
HTTP mode used to build its whole configuration from flags and never consult the environment, so every documented HTTP environment variable was inert: the flag default won even when the operator had exported a value and passed no flag. This file supplies the middle layer of the intended precedence — an explicitly passed flag, then the environment, then the built-in default.
Only values actually present in the environment are reported. That distinction is the whole point: the existing loaders substitute defaults for absent variables, which would make "exported the default" indistinguishable from "exported nothing" and let the overlay overwrite a flag default with an identical value for the wrong reason.
Index ¶
- Constants
- func EffectiveCapabilitySurface(capabilitySurface string) string
- func EffectiveToolSurface(metaTools bool, toolSurface string) string
- func LegacyEnterpriseEnvInUse(tierValue, enterpriseValue string) bool
- func LegacyMetaToolsReplacement(metaToolsValue string) string
- func LegacyMetaToolsSelectorInUse(toolSurfaceValue, metaToolsValue string) bool
- func ParseCSV(s string) []string
- func ParseTierFlag(value string) (tier edition.Tier, explicit bool, err error)
- func ParseToolSurface(toolSurfaceValue, metaToolsValue string) (mode string, metaTools bool, err error)
- func ValidateOAuthGitLabURL(raw string) error
- func ValidatePublicURL(raw string) error
- type Config
- type HTTPEnvOverlay
- type ServerConfig
Constants ¶
const ( DefaultMaxFileSize = 2 * 1024 * 1024 * 1024 // 2 GB MaxFileSize = 1024 * 1024 * 1024 * 1024 // 1 TB upper bound )
DefaultMaxFileSize and MaxFileSize define the default and upper bound for GitLab upload payload sizes.
const ( DefaultMaxHTTPClients = 100 DefaultSessionTimeout = 30 * time.Minute DefaultRevalidateInterval = 15 * time.Minute DefaultPoolIdleTimeout = 1 * time.Hour MaxHTTPClients = 10000 MaxSessionTimeout = 24 * time.Hour MaxRevalidateInterval = 24 * time.Hour MaxPoolIdleTimeout = 24 * time.Hour )
HTTP pool defaults.
const ( DefaultOAuthCacheTTL = 15 * time.Minute MinOAuthCacheTTL = 1 * time.Minute MaxOAuthCacheTTL = 2 * time.Hour )
OAuth defaults.
const ( DefaultAutoUpdateRepo = "jmrplens/gitlab-mcp-server" DefaultAutoUpdateInterval = 1 * time.Hour DefaultAutoUpdateTimeout = 60 * time.Second MinAutoUpdateTimeout = 5 * time.Second MaxAutoUpdateTimeout = 10 * time.Minute )
Auto-update defaults.
const ( DefaultRateLimitBurst = 40 MaxRateLimitRPS = 1000 MaxRateLimitBurst = 10000 )
DefaultRateLimitBurst is the bucket size used when rps > 0 and the operator did not set RATE_LIMIT_BURST explicitly.
const ( // MetaParamSchemaOpaque keeps the legacy `params: object` envelope. // This is the default and produces the smallest tools/list payload. MetaParamSchemaOpaque = "opaque" // MetaParamSchemaCompact emits a discriminated `oneOf` per action with // descriptions and $defs stripped to reduce size. MetaParamSchemaCompact = "compact" // MetaParamSchemaFull emits a discriminated `oneOf` per action with the // complete reflected JSON Schema for each action's params. MetaParamSchemaFull = "full" // DefaultMetaParamSchema is the default mode applied when neither the // META_PARAM_SCHEMA env var nor the --meta-param-schema flag is set. DefaultMetaParamSchema = MetaParamSchemaOpaque )
Meta-tool param schema modes.
const ( // ToolSurfaceMeta exposes the current domain meta-tool catalog. ToolSurfaceMeta = "meta" // ToolSurfaceIndividual exposes the full individual tool catalog. ToolSurfaceIndividual = "individual" // ToolSurfaceDynamic exposes the default low-token find/execute catalog. ToolSurfaceDynamic = "dynamic" // DefaultToolSurface selects the low-token find/execute catalog by default. DefaultToolSurface = ToolSurfaceDynamic )
Tool surface modes select which tool catalog is exposed by the server.
const ( // CapabilitySurfaceFull exposes the current resource and prompt catalog. CapabilitySurfaceFull = "full" // CapabilitySurfaceMinimal exposes only capabilities required for dynamic use. CapabilitySurfaceMinimal = "minimal" // DefaultCapabilitySurface preserves the existing resource and prompt catalog. DefaultCapabilitySurface = CapabilitySurfaceFull )
Capability surface modes select which non-tool MCP capabilities are exposed.
const DefaultGitLabURL = "https://gitlab.com"
DefaultGitLabURL is the GitLab instance used when GITLAB_URL is unset.
const EnvFileName = ".gitlab-mcp-server.env"
EnvFileName is the name of the env file where the setup wizard stores secrets.
Variables ¶
This section is empty.
Functions ¶
func EffectiveCapabilitySurface ¶
EffectiveCapabilitySurface returns the canonical capability surface.
func EffectiveToolSurface ¶
EffectiveToolSurface returns the canonical tool surface for legacy and new configuration snapshots. Empty ToolSurface values are derived from MetaTools so older tests and callers keep their current behavior.
func LegacyEnterpriseEnvInUse ¶ added in v2.3.0
LegacyEnterpriseEnvInUse reports whether the DEPRECATED GITLAB_ENTERPRISE env var is the active tier source (GITLAB_TIER unset, GITLAB_ENTERPRISE set), so the caller can emit a one-time deprecation warning pointing users to GITLAB_TIER.
func LegacyMetaToolsReplacement ¶
LegacyMetaToolsReplacement returns the canonical TOOL_SURFACE value that corresponds to a legacy META_TOOLS value. It returns an empty string when the legacy value is invalid.
func LegacyMetaToolsSelectorInUse ¶
LegacyMetaToolsSelectorInUse reports whether a configuration relies on the deprecated META_TOOLS selector instead of the canonical TOOL_SURFACE selector.
func ParseTierFlag ¶ added in v2.3.0
ParseTierFlag resolves a CLI --tier flag value into a tier and an "explicit" flag, mirroring [parseTierEnv]. It is exported for cmd/server HTTP-mode flag handling.
func ParseToolSurface ¶
func ParseToolSurface(toolSurfaceValue, metaToolsValue string) (mode string, metaTools bool, err error)
ParseToolSurface resolves the explicit TOOL_SURFACE value and legacy META_TOOLS value into a canonical tool surface and compatible MetaTools bool.
func ValidateOAuthGitLabURL ¶ added in v2.7.4
ValidateOAuthGitLabURL requires the GitLab instance URL to use https in oauth mode. Bearer tokens are forwarded upstream on every call, so a cleartext instance URL would put a live credential on the wire (CWE-319). http is tolerated only for loopback hosts, matching the exemption ValidatePublicURL makes for local development.
func ValidatePublicURL ¶ added in v2.7.1
ValidatePublicURL enforces the RFC 9728 constraints on the advertised protected-resource identifier. Exported for the HTTP flag path, which assembles its Config directly instead of going through Load.
Types ¶
type Config ¶
type Config struct {
GitLabURL string
GitLabToken string
SkipTLSVerify bool
DisableRetries bool // Disable GitLab client retries for unit tests.
MetaTools bool
ToolSurface string
CapabilitySurface string
// Tier is the resolved GitLab licensing tier for this configuration.
// When TierExplicit is false it holds the conservative default
// (edition.Free); callers detect the real tier from the instance license.
Tier edition.Tier
// TierExplicit reports whether the tier was set explicitly via GITLAB_TIER
// (stdio) or --tier (HTTP). When true, no instance license check is
// performed and Tier is used verbatim. When false, the tier is detected
// per instance, falling back to edition.Free.
TierExplicit bool
ReadOnly bool
SafeMode bool
EmbeddedResources bool // Append EmbeddedResource content blocks to get_* tool results (default true)
UploadMaxFileSize int64
MaxHTTPClients int // Maximum unique tokens in the server pool (HTTP mode only)
SessionTimeout time.Duration // Idle MCP session timeout (HTTP mode only)
RevalidateInterval time.Duration // Token re-validation interval (HTTP mode only)
// PoolIdleTimeout is how long a pooled per-token-and-URL server entry may go unused
// before it is reclaimed; 0 keeps entries until the pool's size bound
// evicts them (HTTP mode only).
PoolIdleTimeout time.Duration
// Stateless enables sessionless streamable HTTP (SEP-2567, protocol
// 2026-07-28): the server neither reads nor sets Mcp-Session-Id, every
// POST is self-contained, and GET/DELETE return 405 (HTTP mode only).
Stateless bool
// JSONResponse returns application/json bodies instead of
// text/event-stream (SSE) for streamable responses (HTTP mode only).
JSONResponse bool
// MaxRequestBodyBytes caps the size of incoming streamable HTTP request
// bodies. 0 uses the SDK default (4 MiB); negatives are rejected at
// validation (HTTP mode only).
MaxRequestBodyBytes int64
AutoUpdate string // Auto-update mode: "true" (auto), "check" (log-only), "false" (disabled)
AutoUpdateRepo string // GitLab project path for update checks
AutoUpdateInterval time.Duration // How often to check for updates (HTTP mode)
AutoUpdateTimeout time.Duration // Timeout for startup/background update checks
AuthMode string // Auth mode for HTTP: "legacy" (default) or "oauth"
OAuthCacheTTL time.Duration // OAuth token cache TTL (HTTP mode, oauth auth mode)
// PublicURL is the externally reachable origin of this deployment
// (scheme://host[:port][/path], no trailing slash). Required in oauth
// mode: RFC 9728 defines the protected-resource identifier as an https
// URL, and deriving it from the bind address produces host-less or
// wrong-origin identifiers behind any TLS-terminating proxy.
PublicURL string
TrustedProxyHeader string // HTTP header with real client IP (e.g. X-Forwarded-For, X-Real-IP)
// TrustedOrigins are absolute origins (scheme://host[:port]) allowed to
// make cross-origin browser requests. Empty by default: the server
// refuses every cross-origin browser POST, and only a listed origin (or
// the PublicURL origin, seeded automatically) is exempted. A trusted
// origin is validation, not a bypass — the DNS-rebinding MUST is still
// met for every origin not on the list.
TrustedOrigins []string
ExcludeTools []string // Tool names to exclude from registration (comma-separated via EXCLUDE_TOOLS)
IgnoreScopes bool // When true, skip PAT scope detection and register all tools
RateLimitRPS float64 // Per-server tools/call rate limit in requests/second (0 = disabled)
RateLimitBurst int // Token-bucket burst size when RateLimitRPS > 0
// MetaParamSchema controls how meta-tool input schemas advertise the
// shape of the `params` object. Allowed values: "opaque" (default),
// "compact", "full". See [DefaultMetaParamSchema] and constants.
MetaParamSchema string
}
Config holds all configuration values for the MCP server.
func Load ¶
Load reads configuration from environment variables. It attempts to load a .env file from the current directory first, then falls back to ~/.gitlab-mcp-server.env (written by the setup wizard) for secrets not provided via the environment or CWD .env.
func (*Config) Enterprise ¶
Enterprise reports whether the resolved tier is an Enterprise (Premium or Ultimate) tier. It derives the legacy binary "enterprise" notion from the 3-tier model so positional gating continues to behave identically.
func (*Config) ServerConfig ¶
func (c *Config) ServerConfig() *ServerConfig
ServerConfig returns the server-scoped subset of Config. Callers may enrich the returned snapshot with detected per-principal data before creating a concrete MCP server instance.
type HTTPEnvOverlay ¶ added in v2.7.0
type HTTPEnvOverlay struct {
GitLabURL *string
SkipTLSVerify *bool
ToolSurface *string
MetaTools *bool
CapabilitySurface *string
MetaParamSchema *string
Tier *edition.Tier
TierExplicit bool
ReadOnly *bool
SafeMode *bool
EmbeddedResources *bool
IgnoreScopes *bool
ExcludeTools *string
MaxHTTPClients *int
SessionTimeout *time.Duration
PoolIdleTimeout *time.Duration
RevalidateInterval *time.Duration
AuthMode *string
PublicURL *string
TrustedOrigins *string
OAuthCacheTTL *time.Duration
RateLimitRPS *float64
RateLimitBurst *int
AutoUpdate *string
AutoUpdateRepo *string
AutoUpdateInterval *time.Duration
AutoUpdateTimeout *time.Duration
}
HTTPEnvOverlay holds the HTTP-relevant settings found in the environment. A nil field means the variable was absent or empty, and the caller keeps whatever the flag layer resolved.
func LoadHTTPEnvOverlay ¶ added in v2.7.0
func LoadHTTPEnvOverlay() (*HTTPEnvOverlay, error)
LoadHTTPEnvOverlay reads the environment variables that have an HTTP flag counterpart, validating each with the same parser and bounds the stdio path applies. An invalid value is an error rather than a silent fallback, so a typo in a deployment manifest fails at startup instead of quietly running with a default the operator did not choose.
type ServerConfig ¶
type ServerConfig struct {
GitLabURL string
MetaTools bool
ToolSurface string
CapabilitySurface string
// Tier is the resolved GitLab licensing tier for this pool entry. When the
// owning Config did not set the tier explicitly, the pool detects it per
// instance before building the server.
Tier edition.Tier
// TierExplicit mirrors Config.TierExplicit: when true the tier is used
// verbatim and the pool performs no per-instance license detection.
TierExplicit bool
ReadOnly bool
SafeMode bool
ExcludeTools []string
TokenScopes []string
RateLimitRPS float64
RateLimitBurst int
MetaParamSchema string
// Stateless mirrors Config.Stateless. It reaches the server because a
// sessionless transport cannot carry a server-initiated notification
// outside an open request, which decides whether the legacy
// resources/subscribe path can be honored at all.
Stateless bool
}
ServerConfig is an immutable configuration snapshot used to build one MCP server instance for a specific GitLab URL and credential principal.
func (*ServerConfig) Enterprise ¶
func (s *ServerConfig) Enterprise() bool
Enterprise reports whether this server's resolved tier is an Enterprise (Premium or Ultimate) tier, deriving the legacy binary notion from the tier.