autoupdate

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 12 Imported by: 0

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

View Source
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

func HasPendingUpdate() (stagingPath string, ok bool)

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

func (c Config) GoString() string

GoString implements fmt.GoStringer to prevent token leakage via %#v formatting.

func (Config) String

func (c Config) String() string

String returns a redacted representation of Config to prevent accidental token leakage via fmt.Print, log, or %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

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

ListReleases returns the configured error.

type Mode

type Mode string

Mode controls auto-update behavior.

const (
	// ModeAuto downloads and applies updates automatically.
	ModeAuto Mode = "true"
	// ModeCheck only checks for updates and logs the result without applying.
	ModeCheck Mode = "check"
	// ModeDisabled disables all update checks.
	ModeDisabled Mode = "false"
)

func ParseMode

func ParseMode(s string) (Mode, error)

ParseMode parses a string into an update Mode. Accepted values: "true"/"1"/"yes" (auto), "check" (check-only), "false"/"0"/"no" (disabled). Empty defaults to DefaultMode.

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

func NewUpdater(cfg Config) (*Updater, error)

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

func (u *Updater) ApplyUpdate(ctx context.Context) (string, error)

ApplyUpdate downloads and applies the latest release, replacing the running binary. Returns the new version on success.

func (*Updater) CheckForUpdate

func (u *Updater) CheckForUpdate(ctx context.Context) (*UpdateInfo, bool, error)

CheckForUpdate checks the GitLab releases for a newer version. Returns update information and whether an update is available.

func (*Updater) CheckOnce

func (u *Updater) CheckOnce(ctx context.Context) (newVersion string, updated bool, err error)

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

func (u *Updater) DownloadAndReplace(ctx context.Context) (string, error)

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) GetConfig

func (u *Updater) GetConfig() Config

GetConfig returns the updater configuration.

func (*Updater) IsEnabled

func (u *Updater) IsEnabled() bool

IsEnabled reports whether auto-update checks are active (mode is not disabled).

func (*Updater) StartPeriodicCheck

func (u *Updater) StartPeriodicCheck(ctx context.Context)

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.

Jump to

Keyboard shortcuts

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