Add a new "builder" capability to trigger Nix builds on a dedicated build host via NATS messaging. This allows pre-building NixOS configurations before deployment. New components: - Builder mode: subscribes to build.<repo>.* subjects, executes nix build - Build CLI command: triggers builds with progress tracking - MCP build tool: available with --enable-builds flag - Builder metrics: tracks build success/failure per repo and host - NixOS module: services.homelab-deploy.builder The builder uses a YAML config file to define allowed repositories with their URLs and default branches. Builds can target all hosts or specific hosts, with real-time progress updates. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package mcp
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/mark3labs/mcp-go/server"
|
|
)
|
|
|
|
// ServerConfig holds configuration for the MCP server.
|
|
type ServerConfig struct {
|
|
NATSUrl string
|
|
NKeyFile string
|
|
EnableAdmin bool
|
|
AdminNKeyFile string
|
|
EnableBuilds bool
|
|
DiscoverSubject string
|
|
Timeout time.Duration
|
|
}
|
|
|
|
// Server wraps the MCP server.
|
|
type Server struct {
|
|
cfg ServerConfig
|
|
server *server.MCPServer
|
|
}
|
|
|
|
// New creates a new MCP server.
|
|
func New(cfg ServerConfig) *Server {
|
|
s := server.NewMCPServer(
|
|
"homelab-deploy",
|
|
"0.1.0",
|
|
server.WithToolCapabilities(true),
|
|
)
|
|
|
|
handler := NewToolHandler(ToolConfig{
|
|
NATSUrl: cfg.NATSUrl,
|
|
NKeyFile: cfg.NKeyFile,
|
|
AdminNKeyFile: cfg.AdminNKeyFile,
|
|
DiscoverSubject: cfg.DiscoverSubject,
|
|
Timeout: cfg.Timeout,
|
|
})
|
|
|
|
// Register deploy tool (test-tier only)
|
|
s.AddTool(DeployTool(), handler.HandleDeploy)
|
|
|
|
// Register list_hosts tool
|
|
s.AddTool(ListHostsTool(), handler.HandleListHosts)
|
|
|
|
// Optionally register admin deploy tool
|
|
if cfg.EnableAdmin {
|
|
s.AddTool(DeployAdminTool(), handler.HandleDeployAdmin)
|
|
}
|
|
|
|
// Optionally register build tool
|
|
if cfg.EnableBuilds {
|
|
s.AddTool(BuildTool(), handler.HandleBuild)
|
|
}
|
|
|
|
return &Server{
|
|
cfg: cfg,
|
|
server: s,
|
|
}
|
|
}
|
|
|
|
// Run starts the MCP server and blocks until completed.
|
|
func (s *Server) Run() error {
|
|
return server.ServeStdio(s.server)
|
|
}
|