Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
feat(ai): add Docker update management MCP tools
rcourtman432f13b6f586
diff --git a/internal/ai/mcp/adapters.go b/internal/ai/mcp/adapters.goindex 385cde9727..daaa9ab1b9 100644--- a/internal/ai/mcp/adapters.go+++ b/internal/ai/mcp/adapters.go@@ -599,3 +599,139 @@ func (a *MetadataUpdaterMCPAdapter) SetResourceURL(resourceType, resourceID, url}return a.source.SetResourceURL(resourceType, resourceID, url)}++// ========== Updates Provider Adapter ==========++// UpdatesMonitor is the subset of Monitor methods needed for update operations+type UpdatesMonitor interface {+ GetState() models.StateSnapshot+ QueueDockerCheckUpdatesCommand(hostID string) (models.DockerHostCommandStatus, error)+ QueueDockerContainerUpdateCommand(hostID, containerID, containerName string) (models.DockerHostCommandStatus, error)+}++// UpdatesConfig provides configuration for update operations+type UpdatesConfig interface {+ IsDockerUpdateActionsEnabled() bool+}++// UpdatesMCPAdapter adapts Monitor to MCP UpdatesProvider interface+type UpdatesMCPAdapter struct {+ monitor UpdatesMonitor+ config UpdatesConfig+}++// NewUpdatesMCPAdapter creates a new adapter for update operations+func NewUpdatesMCPAdapter(monitor UpdatesMonitor, config UpdatesConfig) *UpdatesMCPAdapter {+ if monitor == nil {+ return nil+ }+ return &UpdatesMCPAdapter{monitor: monitor, config: config}+}++// GetPendingUpdates implements mcp.UpdatesProvider+func (a *UpdatesMCPAdapter) GetPendingUpdates(hostID string) []ContainerUpdateInfo {+ if a.monitor == nil {+ return nil+ }++ state := a.monitor.GetState()+ var updates []ContainerUpdateInfo++ for _, host := range state.DockerHosts {+ // Filter by host ID if specified+ if hostID != "" && host.ID != hostID {+ continue+ }++ for _, container := range host.Containers {+ if container.UpdateStatus == nil {+ continue+ }++ // Only include containers with updates available or errors+ if !container.UpdateStatus.UpdateAvailable && container.UpdateStatus.Error == "" {+ continue+ }++ update := ContainerUpdateInfo{+ HostID: host.ID,+ HostName: host.DisplayName,+ ContainerID: container.ID,+ ContainerName: trimContainerName(container.Name),+ Image: container.Image,+ UpdateAvailable: container.UpdateStatus.UpdateAvailable,+ }++ if container.UpdateStatus.CurrentDigest != "" {+ update.CurrentDigest = container.UpdateStatus.CurrentDigest+ }+ if container.UpdateStatus.LatestDigest != "" {+ update.LatestDigest = container.UpdateStatus.LatestDigest+ }+ if !container.UpdateStatus.LastChecked.IsZero() {+ update.LastChecked = container.UpdateStatus.LastChecked.Unix()+ }+ if container.UpdateStatus.Error != "" {+ update.Error = container.UpdateStatus.Error+ }++ updates = append(updates, update)+ }+ }++ return updates+}++// TriggerUpdateCheck implements mcp.UpdatesProvider+func (a *UpdatesMCPAdapter) TriggerUpdateCheck(hostID string) (DockerCommandStatus, error) {+ if a.monitor == nil {+ return DockerCommandStatus{}, fmt.Errorf("monitor not available")+ }++ cmdStatus, err := a.monitor.QueueDockerCheckUpdatesCommand(hostID)+ if err != nil {+ return DockerCommandStatus{}, err+ }++ return DockerCommandStatus{+ ID: cmdStatus.ID,+ Type: cmdStatus.Type,+ Status: cmdStatus.Status,+ Message: cmdStatus.Message,+ }, nil+}++// UpdateContainer implements mcp.UpdatesProvider+func (a *UpdatesMCPAdapter) UpdateContainer(hostID, containerID, containerName string) (DockerCommandStatus, error) {+ if a.monitor == nil {+ return DockerCommandStatus{}, fmt.Errorf("monitor not available")+ }++ cmdStatus, err := a.monitor.QueueDockerContainerUpdateCommand(hostID, containerID, containerName)+ if err != nil {+ return DockerCommandStatus{}, err+ }++ return DockerCommandStatus{+ ID: cmdStatus.ID,+ Type: cmdStatus.Type,+ Status: cmdStatus.Status,+ Message: cmdStatus.Message,+ }, nil+}++// IsUpdateActionsEnabled implements mcp.UpdatesProvider+func (a *UpdatesMCPAdapter) IsUpdateActionsEnabled() bool {+ if a.config == nil {+ return true // Default to enabled if no config+ }+ return a.config.IsDockerUpdateActionsEnabled()+}++// trimContainerName removes the leading slash from container names+func trimContainerName(name string) string {+ if len(name) > 0 && name[0] == '/' {+ return name[1:]+ }+ return name+}diff --git a/internal/ai/mcp/data_types.go b/internal/ai/mcp/data_types.goindex 429ab41675..08a3afa93d 100644--- a/internal/ai/mcp/data_types.go+++ b/internal/ai/mcp/data_types.go@@ -566,3 +566,55 @@ type ControlActionResponse struct {Output string `json:"output,omitempty"`Error string `json:"error,omitempty"`}++// ========== Docker Updates Types ==========++// ContainerUpdateInfo represents a container with an available update+type ContainerUpdateInfo struct {+ HostID string `json:"host_id"`+ HostName string `json:"host_name"`+ ContainerID string `json:"container_id"`+ ContainerName string `json:"container_name"`+ Image string `json:"image"`+ CurrentDigest string `json:"current_digest,omitempty"`+ LatestDigest string `json:"latest_digest,omitempty"`+ UpdateAvailable bool `json:"update_available"`+ LastChecked int64 `json:"last_checked,omitempty"`+ Error string `json:"error,omitempty"`+}++// DockerCommandStatus represents the status of a queued Docker command+type DockerCommandStatus struct {+ ID string `json:"id"`+ Type string `json:"type"`+ Status string `json:"status"`+ Message string `json:"message"`+}++// DockerUpdatesResponse is returned by pulse_list_docker_updates+type DockerUpdatesResponse struct {+ Updates []ContainerUpdateInfo `json:"updates"`+ Total int `json:"total"`+ HostID string `json:"host_id,omitempty"`+}++// DockerCheckUpdatesResponse is returned by pulse_check_docker_updates+type DockerCheckUpdatesResponse struct {+ Success bool `json:"success"`+ HostID string `json:"host_id"`+ HostName string `json:"host_name"`+ CommandID string `json:"command_id"`+ Message string `json:"message"`+ Command DockerCommandStatus `json:"command"`+}++// DockerUpdateContainerResponse is returned by pulse_update_docker_container+type DockerUpdateContainerResponse struct {+ Success bool `json:"success"`+ HostID string `json:"host_id"`+ ContainerID string `json:"container_id"`+ ContainerName string `json:"container_name"`+ CommandID string `json:"command_id"`+ Message string `json:"message"`+ Command DockerCommandStatus `json:"command"`+}diff --git a/internal/ai/mcp/executor.go b/internal/ai/mcp/executor.goindex 3b21125390..e1df21c22c 100644--- a/internal/ai/mcp/executor.go+++ b/internal/ai/mcp/executor.go@@ -82,6 +82,14 @@ type DiskHealthProvider interface {GetHosts() []models.Host}+// UpdatesProvider provides Docker update operations for MCP tools+type UpdatesProvider interface {+ GetPendingUpdates(hostID string) []ContainerUpdateInfo+ TriggerUpdateCheck(hostID string) (DockerCommandStatus, error)+ UpdateContainer(hostID, containerID, containerName string) (DockerCommandStatus, error)+ IsUpdateActionsEnabled() bool+}+// ControlLevel represents the AI's permission level for infrastructure controltype ControlLevel string@@ -114,6 +122,7 @@ type ExecutorConfig struct {BackupProvider BackupProviderStorageProvider StorageProviderDiskHealthProvider DiskHealthProvider+ UpdatesProvider UpdatesProvider// Optional providers - managementMetadataUpdater MetadataUpdater@@ -143,6 +152,7 @@ type PulseToolExecutor struct {backupProvider BackupProviderstorageProvider StorageProviderdiskHealthProvider DiskHealthProvider+ updatesProvider UpdatesProvider// Management providersmetadataUpdater MetadataUpdater@@ -264,6 +274,11 @@ func (e *PulseToolExecutor) SetAgentProfileManager(manager AgentProfileManager)e.agentProfileManager = manager}+// SetUpdatesProvider sets the updates provider for Docker container updates+func (e *PulseToolExecutor) SetUpdatesProvider(provider UpdatesProvider) {+ e.updatesProvider = provider+}+// ListTools returns the list of available toolsfunc (e *PulseToolExecutor) ListTools() []Tool {return e.registry.ListTools(e.controlLevel)diff --git a/internal/ai/mcp/tools_infrastructure.go b/internal/ai/mcp/tools_infrastructure.goindex e81a1aac0b..ed832e7ecb 100644--- a/internal/ai/mcp/tools_infrastructure.go+++ b/internal/ai/mcp/tools_infrastructure.go@@ -2,6 +2,8 @@ package mcpimport ("context"+ "encoding/json"+ "fmt")// registerInfrastructureTools registers infrastructure context tools (backup, storage, disk health)@@ -73,6 +75,86 @@ func (e *PulseToolExecutor) registerInfrastructureTools() {return exec.executeGetDiskHealth(ctx, args)},})++ // Docker Updates Tools+ e.registry.Register(RegisteredTool{+ Definition: Tool{+ Name: "pulse_list_docker_updates",+ Description: `List Docker containers with pending image updates.++Returns: JSON with containers that have newer images available in their registry, including image names, current/latest digests, and any check errors.++Use when: User asks about available Docker updates, which containers need updating, or wants to see update status across Docker hosts.`,+ InputSchema: InputSchema{+ Type: "object",+ Properties: map[string]PropertySchema{+ "host": {+ Type: "string",+ Description: "Optional: filter by Docker host name or ID",+ },+ },+ },+ },+ Handler: func(ctx context.Context, exec *PulseToolExecutor, args map[string]interface{}) (CallToolResult, error) {+ return exec.executeListDockerUpdates(ctx, args)+ },+ })++ e.registry.Register(RegisteredTool{+ Definition: Tool{+ Name: "pulse_check_docker_updates",+ Description: `Trigger an update check for Docker containers on a host.++The Docker agent will check registries for newer images and report back. Results appear in pulse_list_docker_updates after the next agent report cycle (~30 seconds).++Use when: User wants to refresh/rescan for available Docker updates on a specific host.`,+ InputSchema: InputSchema{+ Type: "object",+ Properties: map[string]PropertySchema{+ "host": {+ Type: "string",+ Description: "Docker host name or ID to check for updates",+ },+ },+ Required: []string{"host"},+ },+ },+ Handler: func(ctx context.Context, exec *PulseToolExecutor, args map[string]interface{}) (CallToolResult, error) {+ return exec.executeCheckDockerUpdates(ctx, args)+ },+ RequireControl: true,+ })++ e.registry.Register(RegisteredTool{+ Definition: Tool{+ Name: "pulse_update_docker_container",+ Description: `Update a Docker container to its latest image.++This pulls the latest image, stops the container, recreates it with the same configuration, and starts it. The old container is kept as a backup and automatically cleaned up after 5 minutes if the new container is stable.++Use when: User explicitly asks to update a specific Docker container to its latest version.++Do NOT use for: Checking what updates are available (use pulse_list_docker_updates), or just restarting a container (use pulse_control_docker).`,+ InputSchema: InputSchema{+ Type: "object",+ Properties: map[string]PropertySchema{+ "container": {+ Type: "string",+ Description: "Container name or ID to update",+ },+ "host": {+ Type: "string",+ Description: "Docker host name or ID where the container runs",+ },+ },+ Required: []string{"container", "host"},+ },+ },+ Handler: func(ctx context.Context, exec *PulseToolExecutor, args map[string]interface{}) (CallToolResult, error) {+ return exec.executeUpdateDockerContainer(ctx, args)+ },+ RequireControl: true,+ })}func (e *PulseToolExecutor) executeListBackups(_ context.Context, args map[string]interface{}) (CallToolResult, error) {@@ -337,3 +419,197 @@ func (e *PulseToolExecutor) executeGetDiskHealth(_ context.Context, _ map[stringreturn NewJSONResult(response), nil}++// ========== Docker Updates Tool Implementations ==========++func (e *PulseToolExecutor) executeListDockerUpdates(_ context.Context, args map[string]interface{}) (CallToolResult, error) {+ if e.updatesProvider == nil {+ return NewTextResult("Docker update information not available. Ensure updates provider is configured."), nil+ }++ hostFilter, _ := args["host"].(string)++ // Resolve host name to ID if needed+ hostID := e.resolveDockerHostID(hostFilter)++ updates := e.updatesProvider.GetPendingUpdates(hostID)++ // Ensure non-nil slice+ if updates == nil {+ updates = []ContainerUpdateInfo{}+ }++ response := DockerUpdatesResponse{+ Updates: updates,+ Total: len(updates),+ HostID: hostID,+ }++ return NewJSONResult(response), nil+}++func (e *PulseToolExecutor) executeCheckDockerUpdates(_ context.Context, args map[string]interface{}) (CallToolResult, error) {+ if e.updatesProvider == nil {+ return NewTextResult("Docker update checking not available. Ensure updates provider is configured."), nil+ }++ hostArg, _ := args["host"].(string)+ if hostArg == "" {+ return NewErrorResult(fmt.Errorf("host is required")), nil+ }++ // Resolve host name to ID+ hostID := e.resolveDockerHostID(hostArg)+ if hostID == "" {+ return NewTextResult(fmt.Sprintf("Docker host '%s' not found.", hostArg)), nil+ }++ hostName := e.getDockerHostName(hostID)++ // Control level check - suggest mode just returns the suggestion+ if e.controlLevel == ControlLevelSuggest {+ return NewTextResult(fmt.Sprintf("To check for Docker updates on host '%s', use the UI or API:\n\nPOST /api/agents/docker/hosts/%s/check-updates", hostName, hostID)), nil+ }++ // Trigger the update check+ cmdStatus, err := e.updatesProvider.TriggerUpdateCheck(hostID)+ if err != nil {+ return NewTextResult(fmt.Sprintf("Failed to trigger update check: %v", err)), nil+ }++ response := DockerCheckUpdatesResponse{+ Success: true,+ HostID: hostID,+ HostName: hostName,+ CommandID: cmdStatus.ID,+ Message: "Update check command queued. Results will be available after the next agent report cycle (~30 seconds).",+ Command: cmdStatus,+ }++ return NewJSONResult(response), nil+}++func (e *PulseToolExecutor) executeUpdateDockerContainer(ctx context.Context, args map[string]interface{}) (CallToolResult, error) {+ if e.updatesProvider == nil {+ return NewTextResult("Docker update functionality not available. Ensure updates provider is configured."), nil+ }++ containerArg, _ := args["container"].(string)+ hostArg, _ := args["host"].(string)++ if containerArg == "" {+ return NewErrorResult(fmt.Errorf("container is required")), nil+ }+ if hostArg == "" {+ return NewErrorResult(fmt.Errorf("host is required")), nil+ }++ // Check if update actions are enabled+ if !e.updatesProvider.IsUpdateActionsEnabled() {+ return NewTextResult("Docker container updates are disabled by server configuration. Set PULSE_DISABLE_DOCKER_UPDATE_ACTIONS=false or enable in Settings to allow updates."), nil+ }++ // Resolve container and host+ container, dockerHost, err := e.resolveDockerContainer(containerArg, hostArg)+ if err != nil {+ return NewTextResult(fmt.Sprintf("Could not find container '%s' on host '%s': %v", containerArg, hostArg, err)), nil+ }++ containerName := trimContainerName(container.Name)++ // Control level handling+ if e.controlLevel == ControlLevelSuggest {+ return NewTextResult(fmt.Sprintf(`To update container '%s' on host '%s', use the UI or run:++POST /api/agents/docker/containers/update+{+ "hostId": "%s",+ "containerId": "%s",+ "containerName": "%s"+}`, containerName, dockerHost.Hostname, dockerHost.ID, container.ID, containerName)), nil+ }++ // Controlled mode - require approval+ if e.controlLevel == ControlLevelControlled {+ command := fmt.Sprintf("docker update %s", containerName)+ agentHostname := e.getAgentHostnameForDockerHost(dockerHost)+ approvalID := createApprovalRecord(command, "docker", container.ID, agentHostname, fmt.Sprintf("Update container %s to latest image", containerName))+ return NewTextResult(formatDockerUpdateApprovalNeeded(containerName, dockerHost.Hostname, approvalID)), nil+ }++ // Autonomous mode - execute directly+ cmdStatus, err := e.updatesProvider.UpdateContainer(dockerHost.ID, container.ID, containerName)+ if err != nil {+ return NewTextResult(fmt.Sprintf("Failed to queue update command: %v", err)), nil+ }++ response := DockerUpdateContainerResponse{+ Success: true,+ HostID: dockerHost.ID,+ ContainerID: container.ID,+ ContainerName: containerName,+ CommandID: cmdStatus.ID,+ Message: fmt.Sprintf("Update command queued for container '%s'. The agent will pull the latest image and recreate the container.", containerName),+ Command: cmdStatus,+ }++ return NewJSONResult(response), nil+}++// Helper methods for Docker updates++func (e *PulseToolExecutor) resolveDockerHostID(hostArg string) string {+ if hostArg == "" {+ return ""+ }+ if e.stateProvider == nil {+ return hostArg+ }++ state := e.stateProvider.GetState()+ for _, host := range state.DockerHosts {+ if host.ID == hostArg || host.Hostname == hostArg || host.DisplayName == hostArg {+ return host.ID+ }+ }+ return hostArg // Return as-is if not found (provider will handle error)+}++func (e *PulseToolExecutor) getDockerHostName(hostID string) string {+ if e.stateProvider == nil {+ return hostID+ }++ state := e.stateProvider.GetState()+ for _, host := range state.DockerHosts {+ if host.ID == hostID {+ if host.DisplayName != "" {+ return host.DisplayName+ }+ return host.Hostname+ }+ }+ return hostID+}++func formatDockerUpdateApprovalNeeded(containerName, hostName, approvalID string) string {+ payload := map[string]interface{}{+ "type": "approval_required",+ "approval_id": approvalID,+ "container_name": containerName,+ "docker_host": hostName,+ "action": "update",+ "command": fmt.Sprintf("docker update %s (pull latest + recreate)", containerName),+ "how_to_approve": "Click the approval button in the chat to execute this update.",+ "do_not_retry": true,+ }+ b, _ := json.Marshal(payload)+ return "APPROVAL_REQUIRED: " + string(b)+}++func trimLeadingSlash(name string) string {+ if len(name) > 0 && name[0] == '/' {+ return name[1:]+ }+ return name+}diff --git a/internal/ai/opencode/service.go b/internal/ai/opencode/service.goindex e90c37eef1..6256bc9fec 100644--- a/internal/ai/opencode/service.go+++ b/internal/ai/opencode/service.go@@ -753,6 +753,16 @@ func (s *Service) SetAgentProfileManager(manager mcp.AgentProfileManager) {}}+// SetUpdatesProvider sets the updates provider for Docker container updates+func (s *Service) SetUpdatesProvider(provider mcp.UpdatesProvider) {+ s.mu.Lock()+ defer s.mu.Unlock()++ if s.executor != nil {+ s.executor.SetUpdatesProvider(provider)+ }+}+// SetControlLevel sets the AI control level (read_only, suggest, controlled, autonomous)func (s *Service) SetControlLevel(level string) {s.mu.Lock()diff --git a/internal/api/router.go b/internal/api/router.goindex bc277ea9de..71a7525915 100644--- a/internal/api/router.go+++ b/internal/api/router.go@@ -2059,6 +2059,15 @@ func (r *Router) wireOpenCodeProviders() {}}+ // Wire updates provider for Docker container updates+ if r.monitor != nil {+ updatesAdapter := mcp.NewUpdatesMCPAdapter(r.monitor, &updatesConfigWrapper{cfg: r.config})+ if updatesAdapter != nil {+ service.SetUpdatesProvider(updatesAdapter)+ log.Debug().Msg("OpenCode: Updates provider wired")+ }+ }+// Wire metrics history providerif r.monitor != nil {if metricsHistory := r.monitor.GetMetricsHistory(); metricsHistory != nil {@@ -2260,6 +2269,18 @@ func (w *patternSourceWrapper) GetPredictions() []mcp.PredictionData {return result}+// updatesConfigWrapper wraps config.Config to implement mcp.UpdatesConfig+type updatesConfigWrapper struct {+ cfg *config.Config+}++func (w *updatesConfigWrapper) IsDockerUpdateActionsEnabled() bool {+ if w.cfg == nil {+ return true // Default to enabled+ }+ return !w.cfg.DisableDockerUpdateActions+}+// StopOpenCodeAI stops the OpenCode-based AI servicefunc (r *Router) StopOpenCodeAI(ctx context.Context) {if r.aiHandler != nil {