controller

package
v0.1.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package controller implements the stack lifecycle management for gridctl. It extracts orchestration logic from cmd/gridctl/deploy.go into testable, interface-backed components.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildWorkloadSummaries

func BuildWorkloadSummaries(stack *config.Stack, result *runtime.UpResult) []output.WorkloadSummary

BuildWorkloadSummaries creates summary data for the status table.

Types

type Config

type Config struct {
	StackPath   string
	Port        int
	BasePort    int
	Verbose     bool
	Quiet       bool
	NoCache     bool
	NoExpand    bool
	Foreground  bool
	Watch       bool
	DaemonChild bool
}

Config holds all deploy configuration, replacing package-level variables.

type DaemonManager

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

DaemonManager handles daemon lifecycle: forking child processes and waiting for readiness.

func NewDaemonManager

func NewDaemonManager(cfg Config) *DaemonManager

NewDaemonManager creates a DaemonManager.

func (*DaemonManager) Fork

func (d *DaemonManager) Fork(stack *config.Stack) (int, error)

Fork starts a daemon child process that runs the MCP gateway in the background. Returns the child PID.

func (*DaemonManager) WaitForReady

func (d *DaemonManager) WaitForReady(port int, timeout time.Duration) error

WaitForReady polls the /ready endpoint until it returns 200 or timeout. The /ready endpoint only succeeds when all MCP servers are initialized, unlike /health which succeeds immediately when the HTTP server starts.

type GatewayBuilder

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

GatewayBuilder constructs and runs the MCP gateway from a stack config.

func NewGatewayBuilder

func NewGatewayBuilder(cfg Config, stack *config.Stack, stackPath string, rt *runtime.Orchestrator, result *runtime.UpResult) *GatewayBuilder

NewGatewayBuilder creates a GatewayBuilder.

func (*GatewayBuilder) Build

func (b *GatewayBuilder) Build(verbose bool) (*GatewayInstance, error)

Build constructs all gateway components without starting the HTTP server.

func (*GatewayBuilder) BuildAndRun

func (b *GatewayBuilder) BuildAndRun(ctx context.Context, verbose bool) error

BuildAndRun constructs the gateway and runs it until shutdown. This is the main blocking call that replaces the old runGateway() function.

func (*GatewayBuilder) Run

func (b *GatewayBuilder) Run(ctx context.Context, inst *GatewayInstance, verbose bool) error

Run starts the HTTP server, registers MCP servers, and blocks until shutdown.

func (*GatewayBuilder) SetExistingLogInfra

func (b *GatewayBuilder) SetExistingLogInfra(buffer *logging.LogBuffer, handler slog.Handler)

SetExistingLogInfra allows reusing a log buffer/handler created earlier (e.g., in foreground mode where orchestrator events should also be captured).

func (*GatewayBuilder) SetVersion

func (b *GatewayBuilder) SetVersion(v string)

SetVersion sets the gateway version string.

func (*GatewayBuilder) SetWebFS

func (b *GatewayBuilder) SetWebFS(fn WebFSFunc)

SetWebFS sets the function for getting embedded web files.

type GatewayInstance

type GatewayInstance struct {
	Gateway    *mcp.Gateway
	APIServer  *api.Server
	HTTPServer *http.Server
	A2AGateway *a2a.Gateway
	LogBuffer  *logging.LogBuffer
	Handler    slog.Handler
}

GatewayInstance holds all components of a running gateway.

type ServerRegistrar

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

ServerRegistrar handles MCP server registration with the gateway. It provides a unified registration path for both bulk and single-server registration, eliminating the duplication between the former registerMCPServers() and registerSingleMCPServer() functions.

func NewServerRegistrar

func NewServerRegistrar(gateway *mcp.Gateway, noExpand bool) *ServerRegistrar

NewServerRegistrar creates a ServerRegistrar.

func (*ServerRegistrar) RegisterAll

func (r *ServerRegistrar) RegisterAll(ctx context.Context, result *runtime.UpResult, stack *config.Stack, stackPath string)

RegisterAll registers all MCP servers from the UpResult with the gateway.

func (*ServerRegistrar) RegisterOne

func (r *ServerRegistrar) RegisterOne(ctx context.Context, server config.MCPServer, hostPort int, stackPath string) error

RegisterOne registers a single MCP server with the gateway. Used by the reload handler to register newly added servers.

func (*ServerRegistrar) SetLogger

func (r *ServerRegistrar) SetLogger(logger *slog.Logger)

SetLogger sets the logger.

type StackController

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

StackController orchestrates the full deploy lifecycle.

func New

func New(cfg Config) *StackController

New creates a StackController.

func (*StackController) Deploy

func (sc *StackController) Deploy(ctx context.Context) error

Deploy orchestrates the full stack lifecycle.

func (*StackController) SetVersion

func (sc *StackController) SetVersion(v string)

SetVersion sets the version string for the gateway.

func (*StackController) SetWebFS

func (sc *StackController) SetWebFS(fn WebFSFunc)

SetWebFS sets the function for getting embedded web files.

type WebFSFunc

type WebFSFunc func() (fs.FS, error)

WebFSFunc is a function that returns embedded web UI files. This decouples the controller from the build-tag-conditional embed logic.

Jump to

Keyboard shortcuts

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