updatecheck

package
v0.47.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package updatecheck provides centralized version checking against GitHub releases.

Index

Constants

View Source
const (
	// DefaultCheckInterval is the default interval between update checks (4 hours).
	DefaultCheckInterval = 4 * time.Hour

	// EnvDisableAutoUpdate disables all update checks when set to "true".
	EnvDisableAutoUpdate = "MCPPROXY_DISABLE_AUTO_UPDATE"

	// EnvAllowPrereleaseUpdates enables prerelease version comparison when set to "true".
	EnvAllowPrereleaseUpdates = "MCPPROXY_ALLOW_PRERELEASE_UPDATES"
)
View Source
const (
	// GitHubRepo is the repository to check for releases
	GitHubRepo = "smart-mcp-proxy/mcpproxy-go"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	// Name is the asset filename (e.g., "mcpproxy-v1.2.3-darwin-arm64.tar.gz")
	Name string `json:"name"`

	// BrowserDownloadURL is the direct download URL
	BrowserDownloadURL string `json:"browser_download_url"`

	// ContentType is the MIME type of the asset
	ContentType string `json:"content_type"`

	// Size is the file size in bytes
	Size int64 `json:"size"`
}

Asset represents a downloadable file attached to a release.

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker performs background version checks against GitHub releases.

func New

func New(logger *zap.Logger, version string) *Checker

New creates a new update checker.

func (*Checker) CheckNow

func (c *Checker) CheckNow() *VersionInfo

CheckNow performs an immediate update check against GitHub. This bypasses the periodic check interval and updates the cached version info. Returns the updated VersionInfo after the check completes. When update checking is disabled (update_check.enabled=false or MCPPROXY_DISABLE_AUTO_UPDATE=true) no network check is performed and nil is returned (Spec 079 FR-015: disabled means no check and no nudge anywhere, including the manual /api/v1/info?refresh=true path).

func (*Checker) Enabled added in v0.47.0

func (c *Checker) Enabled() bool

Enabled reports whether update checking is effectively enabled: the MCPPROXY_DISABLE_AUTO_UPDATE environment kill-switch wins over the config value (Spec 079 FR-014 precedence: env > config).

func (*Checker) GetVersionInfo

func (c *Checker) GetVersionInfo() *VersionInfo

GetVersionInfo returns the current version information. Thread-safe. Returns nil when update checking is disabled (config or env): with no check running there is no meaningful update state, and FR-015 requires zero nudge on every surface — /api/v1/info then omits the update object entirely, so the Web UI banner/badge and CLI annotations naturally disappear.

func (*Checker) IncludePrereleases added in v0.47.0

func (c *Checker) IncludePrereleases() bool

IncludePrereleases reports whether prerelease versions are offered: MCPPROXY_ALLOW_PRERELEASE_UPDATES=true wins over the config channel (Spec 079 FR-014 precedence: env > config); otherwise channel=rc opts in.

func (*Checker) SetCheckFunc

func (c *Checker) SetCheckFunc(fn func() (*GitHubRelease, error))

SetCheckFunc sets a custom check function. Primarily for testing.

func (*Checker) SetCheckInterval

func (c *Checker) SetCheckInterval(interval time.Duration)

SetCheckInterval sets the interval between update checks. Primarily for testing.

func (*Checker) SetConfig added in v0.47.0

func (c *Checker) SetConfig(enabled, includePrereleases bool)

SetConfig applies the update_check config block (Spec 079 FR-012): enabled gates both the background poll and CheckNow; includePrereleases selects the release channel (stable vs rc).

Precedence (FR-014, documented in docs/features/version-updates.md): the environment switches win over config — MCPPROXY_DISABLE_AUTO_UPDATE=true force-disables even with enabled=true, and MCPPROXY_ALLOW_PRERELEASE_UPDATES=true force-includes prereleases even with channel=stable. The spec leaves precedence open; env-wins is the safe operator-override reading.

Safe to call at any time (config hot-reload). When the background loop is running, a change that leaves checking enabled (re-enable or channel switch) triggers a prompt background re-check instead of waiting up to a full checkInterval.

func (*Checker) Start

func (c *Checker) Start(ctx context.Context)

Start begins the background update checker. It performs an initial check immediately and then checks every checkInterval. The checker respects MCPPROXY_DISABLE_AUTO_UPDATE environment variable.

type GitHubClient

type GitHubClient struct {
	// contains filtered or unexported fields
}

GitHubClient handles communication with the GitHub Releases API.

func NewGitHubClient

func NewGitHubClient(logger *zap.Logger) *GitHubClient

NewGitHubClient creates a new GitHub API client.

func (*GitHubClient) GetLatestRelease

func (c *GitHubClient) GetLatestRelease() (*GitHubRelease, error)

GetLatestRelease fetches the latest stable release from GitHub.

func (*GitHubClient) GetLatestReleaseIncludingPrereleases

func (c *GitHubClient) GetLatestReleaseIncludingPrereleases() (*GitHubRelease, error)

GetLatestReleaseIncludingPrereleases fetches the latest release including prereleases.

func (*GitHubClient) GetRelease

func (c *GitHubClient) GetRelease(includePrereleases bool) (*GitHubRelease, error)

GetRelease fetches the appropriate release based on whether prereleases should be included.

type GitHubRelease

type GitHubRelease struct {
	// TagName is the git tag for this release (e.g., "v1.2.3")
	TagName string `json:"tag_name"`

	// Name is the release title
	Name string `json:"name"`

	// Body is the release notes in markdown format
	Body string `json:"body"`

	// Prerelease indicates if this is a prerelease
	Prerelease bool `json:"prerelease"`

	// HTMLURL is the URL to view the release on GitHub
	HTMLURL string `json:"html_url"`

	// PublishedAt is the publication timestamp
	PublishedAt string `json:"published_at"`

	// Assets is the list of downloadable files
	Assets []Asset `json:"assets"`
}

GitHubRelease represents a release from the GitHub Releases API. This matches the structure returned by: - GET /repos/{owner}/{repo}/releases/latest - GET /repos/{owner}/{repo}/releases

type InfoResponseUpdate

type InfoResponseUpdate struct {
	// Available indicates if an update is available
	Available bool `json:"available"`

	// LatestVersion is the latest version (empty if not checked)
	LatestVersion string `json:"latest_version,omitempty"`

	// ReleaseURL is the GitHub release page URL
	ReleaseURL string `json:"release_url,omitempty"`

	// CheckedAt is when the last check occurred
	CheckedAt *time.Time `json:"checked_at,omitempty"`

	// IsPrerelease indicates if latest is a prerelease
	IsPrerelease bool `json:"is_prerelease,omitempty"`

	// CheckError is set if the last check failed
	CheckError string `json:"check_error,omitempty"`
}

InfoResponseUpdate is the update field added to the /api/v1/info response. This structure is serialized to JSON for API responses.

type VersionInfo

type VersionInfo struct {
	// CurrentVersion is the version of the running MCPProxy instance.
	// Format: semver with "v" prefix (e.g., "v1.2.3") or "development"
	CurrentVersion string `json:"current_version"`

	// LatestVersion is the latest version available on GitHub releases.
	// Empty if update check has not completed yet.
	LatestVersion string `json:"latest_version,omitempty"`

	// UpdateAvailable is true if LatestVersion > CurrentVersion.
	// Computed via semver comparison.
	UpdateAvailable bool `json:"available"`

	// ReleaseURL is the URL to the GitHub release page for the latest version.
	ReleaseURL string `json:"release_url,omitempty"`

	// CheckedAt is the timestamp of the last successful update check.
	CheckedAt *time.Time `json:"checked_at,omitempty"`

	// IsPrerelease indicates if the latest version is a prerelease.
	IsPrerelease bool `json:"is_prerelease,omitempty"`

	// CheckError contains the error message if the last check failed.
	// Empty string if no error.
	CheckError string `json:"check_error,omitempty"`
}

VersionInfo represents the current version and update availability. This is stored in-memory only and refreshed on startup + every 4 hours.

func (*VersionInfo) ToAPIResponse

func (v *VersionInfo) ToAPIResponse() *InfoResponseUpdate

ToAPIResponse converts VersionInfo to the API response format.

Jump to

Keyboard shortcuts

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