Documentation
¶
Overview ¶
Package autoupdate provides self-update capability for the gitlab-mcp-server MCP server. It uses the creativeprojects/go-selfupdate library with a GitLab source to detect, download, validate, and apply new releases.
Two operational modes are supported:
Stdio mode: a single update check runs at startup with a short timeout. If a newer version is found and auto-update is enabled, the binary is replaced and the process re-executes itself.
HTTP mode: a background goroutine periodically checks for updates at a configurable interval. When a new version is detected it is downloaded and applied; the operator is advised to restart the server.
Configuration is provided through the Config struct, typically populated from environment variables (stdio) or CLI flags (HTTP).
Index ¶
- Constants
- func CleanupOldBinary()
- func ClearJustUpdated()
- func ExecSelf() error
- func HasPendingUpdate() (stagingPath string, ok bool)
- func JustUpdated() bool
- func SetJustUpdated() error
- type Config
- type EmptySource
- type ErrorSource
- type Mode
- type PreStartResult
- type UpdateInfo
- type Updater
- func (u *Updater) ApplyUpdate(ctx context.Context) (string, error)
- func (u *Updater) CheckForUpdate(ctx context.Context) (*UpdateInfo, bool, error)
- func (u *Updater) CheckOnce(ctx context.Context) (newVersion string, updated bool, err error)
- func (u *Updater) DownloadAndReplace(ctx context.Context) (string, error)
- func (u *Updater) GetConfig() Config
- func (u *Updater) IsEnabled() bool
- func (u *Updater) StartPeriodicCheck(ctx context.Context)
Constants ¶
const ( DefaultEnabled = true DefaultRepository = "mcp/gitlab-mcp-server" DefaultInterval = 1 * time.Hour DefaultMode = ModeAuto )
Default configuration values.
Variables ¶
This section is empty.
Functions ¶
func CleanupOldBinary ¶
func CleanupOldBinary()
CleanupOldBinary removes leftover .old files from a previous rename-based update. Safe to call unconditionally at startup; errors are logged and do not prevent the server from starting.
func ClearJustUpdated ¶
func ClearJustUpdated()
ClearJustUpdated removes the re-exec guard variable.
func ExecSelf ¶
func ExecSelf() error
ExecSelf replaces the current process with a new instance of the same binary. On Unix, this uses syscall.Exec which preserves the PID and all open file descriptors, making it transparent to the MCP client. This function does not return on success.
func HasPendingUpdate ¶
HasPendingUpdate reports whether a previous update left a staged binary (.tmp or .new) waiting to be applied.
func JustUpdated ¶
func JustUpdated() bool
JustUpdated reports whether the process was re-executed after an update.
func SetJustUpdated ¶
func SetJustUpdated() error
SetJustUpdated sets the environment variable that prevents re-exec loops.
Types ¶
type Config ¶
type Config struct {
Mode Mode // Update behavior (auto, check, disabled)
Repository string // GitHub repository slug (e.g. "jmrplens/gitlab-mcp-server")
Interval time.Duration // Check interval for HTTP mode periodic checks
CurrentVersion string // Running binary version (semver without "v" prefix)
}
Config holds auto-update configuration.
func (Config) GoString ¶
GoString implements fmt.GoStringer to prevent token leakage via %#v formatting.
type EmptySource ¶
type EmptySource struct{}
EmptySource is a selfupdate.Source that returns no releases. Used for testing when a valid Updater is needed but no real update server.
func (EmptySource) DownloadReleaseAsset ¶
func (EmptySource) DownloadReleaseAsset(_ context.Context, _ *selfupdate.Release, _ int64) (io.ReadCloser, error)
DownloadReleaseAsset returns nil.
func (EmptySource) ListReleases ¶
func (EmptySource) ListReleases(_ context.Context, _ selfupdate.Repository) ([]selfupdate.SourceRelease, error)
ListReleases returns no releases.
type ErrorSource ¶
type ErrorSource struct{ Err error }
ErrorSource is a selfupdate.Source that returns an error on every operation. Used for testing error handling paths.
func (ErrorSource) DownloadReleaseAsset ¶
func (e ErrorSource) DownloadReleaseAsset(_ context.Context, _ *selfupdate.Release, _ int64) (io.ReadCloser, error)
DownloadReleaseAsset returns the configured error.
func (ErrorSource) ListReleases ¶
func (e ErrorSource) ListReleases(_ context.Context, _ selfupdate.Repository) ([]selfupdate.SourceRelease, error)
ListReleases returns the configured error.
type PreStartResult ¶
type PreStartResult struct {
Updated bool // Whether a new binary was placed on disk
NewVersion string // Version of the downloaded update (empty if none)
ExecFailed bool // True if exec was attempted but failed (Unix only)
}
PreStartResult describes what happened during the pre-start update check.
func PreStartUpdate ¶
func PreStartUpdate(ctx context.Context, cfg Config) (result *PreStartResult)
PreStartUpdate checks for an update and, if available, downloads the new binary and replaces the current executable using the rename trick.
On Unix, if the replacement succeeds, it calls ExecSelf to re-exec the process with the new binary. ExecSelf does not return on success; if it fails, ExecFailed is set and the server continues with the old code.
On Windows, the rename trick places the new binary at the original path. ExecSelf is not supported, so the new version takes effect on next restart.
The function is guarded by [envJustUpdated] to prevent infinite re-exec loops.
type UpdateInfo ¶
type UpdateInfo struct {
CurrentVersion string `json:"current_version"`
LatestVersion string `json:"latest_version"`
ReleaseURL string `json:"release_url,omitempty"`
ReleaseNotes string `json:"release_notes,omitempty"`
PublishedAt string `json:"published_at,omitempty"`
}
UpdateInfo describes an available release.
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater manages update detection and application.
func NewUpdater ¶
NewUpdater creates an Updater for the given configuration. Returns an error if required fields are missing or a GitHub source cannot be created.
func NewUpdaterWithSource ¶
func NewUpdaterWithSource(cfg Config, src selfupdate.Source) *Updater
NewUpdaterWithSource creates an Updater with an injected source (for testing).
func (*Updater) ApplyUpdate ¶
ApplyUpdate downloads and applies the latest release, replacing the running binary. Returns the new version on success.
func (*Updater) CheckForUpdate ¶
CheckForUpdate checks the GitLab releases for a newer version. Returns update information and whether an update is available.
func (*Updater) CheckOnce ¶
CheckOnce runs a single update check (for stdio mode startup). In ModeAuto, if an update is found it is applied and the function returns the new version (the caller should re-exec the process). In ModeCheck, only a log message is emitted.
func (*Updater) DownloadAndReplace ¶
DownloadAndReplace downloads the latest release and replaces the current binary using the rename trick. Returns the new version. This is the public entry point for MCP tools that need to trigger an update.
func (*Updater) IsEnabled ¶
IsEnabled reports whether auto-update checks are active (mode is not disabled).
func (*Updater) StartPeriodicCheck ¶
StartPeriodicCheck launches a background goroutine that checks for updates at the configured interval. Cancel the context to stop. In ModeAuto, detected updates are applied automatically. In ModeCheck, updates are only logged.