cli

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 53 Imported by: 0

Documentation

Overview

Package cli provides the business logic for the vMCP serve, validate, and init commands. It is designed to be imported by both the standalone vmcp binary (cmd/vmcp/app) and the thv vmcp subcommand (cmd/thv/app).

Package cli provides the business logic for the vMCP serve and validate commands. It is designed to be imported by both the standalone vmcp binary (cmd/vmcp/app) and the thv vmcp subcommand (cmd/thv/app), keeping all server-initialization logic in one importable place.

Index

Constants

View Source
const (
	// DefaultEmbeddingImage is the default HuggingFace Text Embeddings
	// Inference image used when ServeConfig.EmbeddingImage is empty.
	DefaultEmbeddingImage = "ghcr.io/huggingface/text-embeddings-inference:cpu-latest"

	// DefaultEmbeddingModel is the HuggingFace model used when EmbeddingModel is empty.
	DefaultEmbeddingModel = "BAAI/bge-small-en-v1.5"
)

Variables

This section is empty.

Functions

func Init

func Init(ctx context.Context, cfg InitConfig) error

Init discovers workloads in cfg.GroupName, renders a starter vMCP YAML config file with one backend entry per accessible workload, and writes the result to cfg.OutputPath or cfg.Writer.

func Serve

func Serve(ctx context.Context, cfg ServeConfig) error

Serve loads configuration, initializes all subsystems, and starts the vMCP server. It blocks until the context is cancelled or the server stops.

func Validate

func Validate(_ context.Context, cfg ValidateConfig) error

Validate loads and validates a vMCP configuration file, printing a summary on success. Returns a descriptive error if the file is missing, malformed, or fails semantic validation.

Types

type ContainerFactory

type ContainerFactory interface {
	// Create initialises a container runtime backed by the host daemon.
	Create(ctx context.Context) (runtime.Runtime, error)
}

ContainerFactory is the minimal interface over *container.Factory that EmbeddingServiceManager requires. Defined here to allow mock injection in unit tests; in production callers pass container.NewFactory().

type EmbeddingServiceManager

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

EmbeddingServiceManager manages the lifecycle of a TEI container used by the Tier 2 semantic optimizer. It creates or reuses a container deterministically named after the model, health-polls with exponential backoff, and only stops the container if this instance started it.

On Docker the container is bound to a localhost port and the model cache is bind-mounted from the host. On Kubernetes the TEI pod is exposed via a ClusterIP Service named "mcp-<containerName>" and reached at http://mcp-<containerName>:<teiContainerPort>; the host bind-mount is skipped because Kubernetes ignores Docker permission profiles.

func NewEmbeddingServiceManager

func NewEmbeddingServiceManager(factory ContainerFactory, cfg EmbeddingServiceManagerConfig) (*EmbeddingServiceManager, error)

NewEmbeddingServiceManager constructs an EmbeddingServiceManager from the given factory and config. Returns an error when factory is nil or cfg.Model is empty.

func (*EmbeddingServiceManager) Start

Start ensures the TEI container is running and returns its HTTP base URL. On Docker this is http://localhost:<port>; on Kubernetes it is http://<containerName>:<teiContainerPort>.

On first call it checks for an existing running container with the same name; if found, it returns that container's URL without starting a new one (idempotent reuse). If no container is running, Start deploys a new one, then polls its /health endpoint with exponential backoff until it responds 200 or ctx is cancelled.

Returns a non-nil error if the container cannot be started or the health check never succeeds within the context deadline.

func (*EmbeddingServiceManager) Stop

Stop stops the TEI container if this EmbeddingServiceManager instance started it. If the container was already running when Start was called (reuse case), Stop is a no-op — the container belongs to whichever process created it.

type EmbeddingServiceManagerConfig

type EmbeddingServiceManagerConfig struct {
	// Model is the HuggingFace model name (e.g. "BAAI/bge-small-en-v1.5").
	// Required; must be non-empty.
	Model string

	// Image is the TEI container image to run.
	// Defaults to DefaultEmbeddingImage when empty.
	Image string
}

EmbeddingServiceManagerConfig holds the parameters for constructing an EmbeddingServiceManager.

type InitConfig

type InitConfig struct {
	// GroupName is the ToolHive group whose workloads are enumerated.
	GroupName string

	// OutputPath is the file path to write the generated config.
	// If empty or "-", content is written to Writer.
	OutputPath string

	// Writer is used when OutputPath is empty or "-".
	// Defaults to os.Stdout when nil.
	Writer io.Writer

	// Discoverer resolves running workloads in the group.
	// In production, callers pass a *pkg/workloads.DiscovererAdapter (CLI) or
	// the Kubernetes discoverer from pkg/vmcp/workloads/k8s.go.
	Discoverer workloads.Discoverer
}

InitConfig holds all parameters for the Init command. Discoverer is injected rather than constructed internally to enable unit testing.

type ServeConfig

type ServeConfig struct {
	// ConfigPath is the path to the vMCP YAML configuration file.
	// When set, takes precedence over GroupRef.
	ConfigPath string
	// GroupRef is a ToolHive group name used for zero-config quick mode when
	// ConfigPath is empty. A minimal in-memory config is generated from this value.
	GroupRef string
	// Host is the address the server binds to (e.g. "127.0.0.1").
	Host string
	// Port is the TCP port the server listens on.
	Port int
	// EnableAudit enables audit logging with default configuration when
	// the loaded config does not already define an audit section.
	EnableAudit bool

	// Optimizer tier selection (Phase 4 — flag-driven).
	// EnableOptimizer enables Tier 1 FTS5 keyword search (find_tool / call_tool).
	EnableOptimizer bool
	// EnableEmbedding enables Tier 2 TEI semantic search; implies EnableOptimizer.
	EnableEmbedding bool
	// EmbeddingModel is the HuggingFace model name for the managed TEI container.
	// Defaults to "BAAI/bge-small-en-v1.5" when empty.
	EmbeddingModel string
	// EmbeddingImage is the TEI container image.
	// Defaults to the CPU TEI image when empty.
	EmbeddingImage string
}

ServeConfig holds all parameters needed to start the vMCP server. Populated by the caller from Cobra flag values or equivalent. At least one of ConfigPath or GroupRef must be non-empty; ConfigPath takes precedence when both are provided.

type ValidateConfig

type ValidateConfig struct {
	// ConfigPath is the path to the vMCP YAML configuration file to validate.
	ConfigPath string
}

ValidateConfig holds parameters for the validate command.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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