runner

package
v0.0.43 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: Apache-2.0 Imports: 30 Imported by: 1

Documentation

Overview

Package runner provides functionality for running MCP servers

Package runner provides functionality for running MCP servers

Package runner provides functionality for running MCP servers

Index

Constants

View Source
const (
	UVXScheme = "uvx://"
	NPXScheme = "npx://"
	GOScheme  = "go://"
)

Protocol schemes

View Source
const DefaultAppName = "toolhive"

DefaultAppName is the default application name used for state storage

Variables

This section is empty.

Functions

func DeleteSavedConfig

func DeleteSavedConfig(ctx context.Context, name string) error

DeleteSavedConfig deletes a saved run configuration

func HandleProtocolScheme added in v0.0.33

func HandleProtocolScheme(
	ctx context.Context,
	runtime rt.Runtime,
	serverOrImage string,
	caCertPath string,
) (string, error)

HandleProtocolScheme checks if the serverOrImage string contains a protocol scheme (uvx://, npx://, or go://) and builds a Docker image for it if needed. Returns the Docker image name to use and any error encountered.

func IsImageProtocolScheme added in v0.0.35

func IsImageProtocolScheme(serverOrImage string) bool

IsImageProtocolScheme checks if the serverOrImage string contains a protocol scheme (uvx://, npx://, or go://)

func ListSavedConfigs

func ListSavedConfigs(ctx context.Context) ([]string, error)

ListSavedConfigs lists all saved run configurations

Types

type RunConfig

type RunConfig struct {
	// Image is the Docker image to run
	Image string `json:"image" yaml:"image"`

	// CmdArgs are the arguments to pass to the container
	CmdArgs []string `json:"cmd_args,omitempty" yaml:"cmd_args,omitempty"`

	// Name is the name of the MCP server
	Name string `json:"name" yaml:"name"`

	// ContainerName is the name of the container
	ContainerName string `json:"container_name" yaml:"container_name"`

	// BaseName is the base name used for the container (without prefixes)
	BaseName string `json:"base_name" yaml:"base_name"`

	// Transport is the transport mode (sse or stdio)
	Transport types.TransportType `json:"transport" yaml:"transport"`

	// Host is the host for the HTTP proxy
	Host string `json:"host" yaml:"host"`

	// Port is the port for the HTTP proxy to listen on (host port)
	Port int `json:"port" yaml:"port"`

	// TargetPort is the port for the container to expose (only applicable to SSE transport)
	TargetPort int `json:"target_port,omitempty" yaml:"target_port,omitempty"`

	// TargetHost is the host to forward traffic to (only applicable to SSE transport)
	TargetHost string `json:"target_host,omitempty" yaml:"target_host,omitempty"`

	// PermissionProfileNameOrPath is the name or path of the permission profile
	PermissionProfileNameOrPath string `json:"permission_profile_name_or_path,omitempty" yaml:"permission_profile_name_or_path,omitempty"` //nolint:lll

	// PermissionProfile is the permission profile to use
	PermissionProfile *permissions.Profile `json:"permission_profile" yaml:"permission_profile"`

	// EnvVars are the parsed environment variables as key-value pairs
	EnvVars map[string]string `json:"env_vars,omitempty" yaml:"env_vars,omitempty"`

	// Debug indicates whether debug mode is enabled
	Debug bool `json:"debug,omitempty" yaml:"debug,omitempty"`

	// Volumes are the directory mounts to pass to the container
	// Format: "host-path:container-path[:ro]"
	Volumes []string `json:"volumes,omitempty" yaml:"volumes,omitempty"`

	// ContainerLabels are the labels to apply to the container
	ContainerLabels map[string]string `json:"container_labels,omitempty" yaml:"container_labels,omitempty"`

	// OIDCConfig contains OIDC configuration
	OIDCConfig *auth.JWTValidatorConfig `json:"oidc_config,omitempty" yaml:"oidc_config,omitempty"`

	// AuthzConfig contains the authorization configuration
	AuthzConfig *authz.Config `json:"authz_config,omitempty" yaml:"authz_config,omitempty"`

	// AuthzConfigPath is the path to the authorization configuration file
	AuthzConfigPath string `json:"authz_config_path,omitempty" yaml:"authz_config_path,omitempty"`

	// AuditConfig contains the audit logging configuration
	AuditConfig *audit.Config `json:"audit_config,omitempty" yaml:"audit_config,omitempty"`

	// AuditConfigPath is the path to the audit configuration file
	AuditConfigPath string `json:"audit_config_path,omitempty" yaml:"audit_config_path,omitempty"`

	// Secrets are the secret parameters to pass to the container
	// Format: "<secret name>,target=<target environment variable>"
	Secrets []string `json:"secrets,omitempty" yaml:"secrets,omitempty"`

	// K8sPodTemplatePatch is a JSON string to patch the Kubernetes pod template
	// Only applicable when using Kubernetes runtime
	K8sPodTemplatePatch string `json:"k8s_pod_template_patch,omitempty" yaml:"k8s_pod_template_patch,omitempty"`

	// Runtime is the container runtime to use (not serialized)
	Runtime rt.Runtime `json:"-" yaml:"-"`
}

RunConfig contains all the configuration needed to run an MCP server It is serializable to JSON and YAML

func NewRunConfig

func NewRunConfig() *RunConfig

NewRunConfig creates a new RunConfig with default values

func NewRunConfigFromFlags

func NewRunConfigFromFlags(
	runtime rt.Runtime,
	cmdArgs []string,
	name string,
	host string,
	debug bool,
	volumes []string,
	secretsList []string,
	authzConfigPath string,
	auditConfigPath string,
	enableAudit bool,
	permissionProfile string,
	targetHost string,
	oidcIssuer string,
	oidcAudience string,
	oidcJwksURL string,
	oidcClientID string,
) *RunConfig

NewRunConfigFromFlags creates a new RunConfig with values from command-line flags

func ReadJSON

func ReadJSON(r io.Reader) (*RunConfig, error)

ReadJSON deserializes the RunConfig from JSON read from the provided reader

func (*RunConfig) ParsePermissionProfile

func (c *RunConfig) ParsePermissionProfile() (*RunConfig, error)

ParsePermissionProfile loads and sets the permission profile

func (*RunConfig) ProcessVolumeMounts

func (c *RunConfig) ProcessVolumeMounts() error

ProcessVolumeMounts processes volume mounts and adds them to the permission profile

func (*RunConfig) WithAudit added in v0.0.40

func (c *RunConfig) WithAudit(config *audit.Config) *RunConfig

WithAudit adds audit configuration to the RunConfig

func (*RunConfig) WithAuthz

func (c *RunConfig) WithAuthz(config *authz.Config) *RunConfig

WithAuthz adds authorization configuration to the RunConfig

func (*RunConfig) WithContainerName

func (c *RunConfig) WithContainerName() *RunConfig

WithContainerName generates container name if not already set

func (*RunConfig) WithEnvironmentVariables

func (c *RunConfig) WithEnvironmentVariables(envVarStrings []string) (*RunConfig, error)

WithEnvironmentVariables parses and sets environment variables

func (*RunConfig) WithPorts

func (c *RunConfig) WithPorts(port, targetPort int) (*RunConfig, error)

WithPorts configures the host and target ports

func (*RunConfig) WithSecrets

func (c *RunConfig) WithSecrets(ctx context.Context, secretManager secrets.Provider) (*RunConfig, error)

WithSecrets processes secrets and adds them to environment variables

func (*RunConfig) WithStandardLabels

func (c *RunConfig) WithStandardLabels() *RunConfig

WithStandardLabels adds standard labels to the container

func (*RunConfig) WithTransport

func (c *RunConfig) WithTransport(t string) (*RunConfig, error)

WithTransport parses and sets the transport type

func (*RunConfig) WriteJSON

func (c *RunConfig) WriteJSON(w io.Writer) error

WriteJSON serializes the RunConfig to JSON and writes it to the provided writer

type Runner

type Runner struct {
	// Config is the configuration for the runner
	Config *RunConfig
}

Runner is responsible for running an MCP server with the provided configuration

func LoadState

func LoadState(ctx context.Context, name string) (*Runner, error)

LoadState loads the runner configuration from the state store This is a static method that returns a new Runner instance

func NewRunner

func NewRunner(runConfig *RunConfig) *Runner

NewRunner creates a new Runner with the provided configuration

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run runs the MCP server with the provided configuration

func (*Runner) SaveState

func (r *Runner) SaveState(ctx context.Context) error

SaveState saves the runner configuration to the state store

Jump to

Keyboard shortcuts

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