Documentation
¶
Index ¶
- func DefaultAPIShutdownTimeout() time.Duration
- func DefaultCORSAllowCredentials() bool
- func DefaultCORSAllowHeaders() []string
- func DefaultCORSAllowMethods() []string
- func DefaultCORSMaxAge() time.Duration
- func DefaultClientInitTimeout() time.Duration
- func DefaultClientShutdownTimeout() time.Duration
- func DefaultHealthCheckInterval() time.Duration
- func DefaultHealthCheckTimeout() time.Duration
- func DefaultMiddlewareProvider() func(context.Context) (func(http.Handler) http.Handler, error)
- func IsValidAddr(addr string) error
- type APIDependencies
- type APIOption
- func WithCORSAllowCredentials(allowed bool) APIOption
- func WithCORSAllowHeaders(headers []string) APIOption
- func WithCORSAllowMethods(methods []string) APIOption
- func WithCORSAllowOrigins(origins []string) APIOption
- func WithCORSEnabled(enabled bool) APIOption
- func WithCORSExposeHeaders(headers []string) APIOption
- func WithCORSMaxAge(maxAge time.Duration) APIOption
- func WithMiddlewareProvider(provider func(context.Context) (func(http.Handler) http.Handler, error)) APIOption
- func WithShutdownTimeout(timeout time.Duration) APIOption
- type APIOptions
- type APIServer
- type CORSConfig
- type ClientManager
- func (cm *ClientManager) Add(name string, c client.MCPClient, tools []string)
- func (cm *ClientManager) Client(name string) (client.MCPClient, bool)
- func (cm *ClientManager) List() []string
- func (cm *ClientManager) Remove(name string)
- func (cm *ClientManager) Tools(name string) ([]string, bool)
- func (cm *ClientManager) UpdateTools(name string, tools []string) error
- type Daemon
- type Dependencies
- type HealthTracker
- func (h *HealthTracker) Add(name string)
- func (h *HealthTracker) List() []domain.ServerHealth
- func (h *HealthTracker) Remove(name string)
- func (h *HealthTracker) Status(name string) (domain.ServerHealth, error)
- func (h *HealthTracker) Update(name string, status domain.HealthStatus, latency *time.Duration) error
- type Option
- func WithAPIOptions(apiOpts ...APIOption) Option
- func WithMCPServerHealthCheckInterval(interval time.Duration) Option
- func WithMCPServerHealthCheckTimeout(timeout time.Duration) Option
- func WithMCPServerInitTimeout(timeout time.Duration) Option
- func WithMCPServerShutdownTimeout(timeout time.Duration) Option
- func WithPluginConfig(cfg *config.PluginConfig) Option
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAPIShutdownTimeout ¶
DefaultAPIShutdownTimeout is the default time allowed for API server graceful shutdown.
func DefaultCORSAllowCredentials ¶
func DefaultCORSAllowCredentials() bool
DefaultCORSAllowCredentials returns the default CORS 'allow credentials' setting.
func DefaultCORSAllowHeaders ¶
func DefaultCORSAllowHeaders() []string
DefaultCORSAllowHeaders returns standard headers required for API interaction.
func DefaultCORSAllowMethods ¶
func DefaultCORSAllowMethods() []string
DefaultCORSAllowMethods returns standard HTTP methods for CORS.
func DefaultCORSMaxAge ¶
DefaultCORSMaxAge returns the default CORS max age duration. Max age is the default time browsers can cache preflight responses.
func DefaultClientInitTimeout ¶
DefaultClientInitTimeout is the default time to wait for MCP server initialization.
func DefaultClientShutdownTimeout ¶
DefaultClientShutdownTimeout is the default time to wait for MCP clients to close.
func DefaultHealthCheckInterval ¶
DefaultHealthCheckInterval is the default interval for health checks.
func DefaultHealthCheckTimeout ¶
DefaultHealthCheckTimeout is the default timeout for health check responses.
func DefaultMiddlewareProvider ¶
DefaultMiddlewareProvider returns a provider that supplies no-op middleware. The no-op middleware passes requests through unchanged.
func IsValidAddr ¶
IsValidAddr returns an error if the address is not a valid "host:port" string.
Types ¶
type APIDependencies ¶
type APIDependencies struct {
// Addr specifies the network address to bind (e.g., "0.0.0.0:8090").
Addr string
// ClientManager handles MCP client connections.
ClientManager contracts.MCPClientAccessor
// HealthTracker monitors server health status.
HealthTracker contracts.MCPHealthMonitor
// Logger for API server operations.
Logger hclog.Logger
}
APIDependencies contains the required external dependencies for the API server. NewAPIDependencies should be used to create instances of APIDependencies.
func NewAPIDependencies ¶
func NewAPIDependencies( logger hclog.Logger, clientManager contracts.MCPClientAccessor, healthTracker contracts.MCPHealthMonitor, addr string, ) (APIDependencies, error)
NewAPIDependencies creates and validates APIDependencies.
func (APIDependencies) Validate ¶
func (d APIDependencies) Validate() error
Validate ensures all required dependencies are provided and valid.
type APIOption ¶
type APIOption func(*APIOptions) error
APIOption defines a functional option for configuring APIOptions. Options are applied in order, with later options overriding earlier ones.
func WithCORSAllowCredentials ¶
WithCORSAllowCredentials sets whether credentials are allowed in CORS requests.
func WithCORSAllowHeaders ¶
WithCORSAllowHeaders sets which additional request headers are safe for the client to send. See: https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_request_header for information on safelisted-headers that don't required explicit configuration.
func WithCORSAllowMethods ¶
WithCORSAllowMethods sets the allowed HTTP methods for CORS requests.
func WithCORSAllowOrigins ¶
WithCORSAllowOrigins sets the allowed origins for CORS requests.
func WithCORSEnabled ¶
WithCORSEnabled enables or disables CORS support.
func WithCORSExposeHeaders ¶
WithCORSExposeHeaders sets which additional response headers are safe for the client to read. See: https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header for information on safelisted-headers that don't required explicit configuration.
func WithCORSMaxAge ¶
WithCORSMaxAge sets how long browsers can cache CORS preflight responses.
func WithMiddlewareProvider ¶
func WithMiddlewareProvider(provider func(context.Context) (func(http.Handler) http.Handler, error)) APIOption
WithMiddlewareProvider configures a provider function that returns HTTP middleware. The provider is called during API server startup to lazily initialize middleware.
func WithShutdownTimeout ¶
WithShutdownTimeout configures how long to wait for graceful shutdown.
type APIOptions ¶
type APIOptions struct {
// CORS configuration for cross-origin requests.
CORS CORSConfig
// ShutdownTimeout specifies how long to wait for graceful shutdown.
ShutdownTimeout time.Duration
// MiddlewareProvider lazily provides HTTP middleware when called during API server startup.
// This allows plugin initialization to be deferred until the server actually starts.
MiddlewareProvider func(context.Context) (func(http.Handler) http.Handler, error)
}
APIOptions contains optional configuration for the API server. NewAPIOptions should be used to create instances of APIOptions.
func NewAPIOptions ¶
func NewAPIOptions(opts ...APIOption) (APIOptions, error)
NewAPIOptions creates APIOptions with optional configurations applied. Starts with default values, then applies options in order with later options overriding earlier ones.
type APIServer ¶
type APIServer struct {
// contains filtered or unexported fields
}
APIServer manages the HTTP API for the daemon. NewAPIServer should be used to create instances of APIServer.
func NewAPIServer ¶
func NewAPIServer(deps APIDependencies, opt ...APIOption) (*APIServer, error)
NewAPIServer creates a new API server with the provided dependencies and options. Applies default options first, then user-provided options to ensure all fields have valid values.
type CORSConfig ¶
type CORSConfig struct {
// Enabled determines whether CORS headers are added to responses.
Enabled bool
// AllowCredentials indicates whether the request can include credentials.
// Must be false when AllowOrigins contains "*"
AllowCredentials bool
// AllowedHeaders specifies which headers the client can include in requests.
AllowedHeaders []string
// AllowMethods specifies which HTTP methods are permitted.
// Using strings to match the go-chi/cors library API.
AllowMethods []string
// AllowOrigins specifies which origins can access the API.
// Use ["*"] to allow all origins (not recommended for production).
AllowOrigins []string
// ExposedHeaders specifies which response headers are accessible to the client.
ExposedHeaders []string
// MaxAge specifies how long browsers can cache preflight responses.
MaxAge time.Duration
}
CORSConfig defines Cross-Origin Resource Sharing settings for the API server.
type ClientManager ¶
type ClientManager struct {
// contains filtered or unexported fields
}
ClientManager holds active client connections and their associated tool lists. It is safe for concurrent use by multiple goroutines. NewClientManager should be used to create instances of ClientManager.
func NewClientManager ¶
func NewClientManager() *ClientManager
NewClientManager creates an empty, concurrency-safe ClientManager.
func (*ClientManager) Add ¶
func (cm *ClientManager) Add(name string, c client.MCPClient, tools []string)
Add registers a client and its tools by server name. The server name and tool names are normalized (lowercase, trimmed) for consistent lookups. This method is safe for concurrent use.
func (*ClientManager) Client ¶
func (cm *ClientManager) Client(name string) (client.MCPClient, bool)
Client returns the client for the given server name. The server name is normalized for case-insensitive lookup. It returns a boolean to indicate whether the client was found. This method is safe for concurrent use.
func (*ClientManager) List ¶
func (cm *ClientManager) List() []string
List returns all known server names. This method is safe for concurrent use.
func (*ClientManager) Remove ¶
func (cm *ClientManager) Remove(name string)
Remove deletes the client and its tools by server name. The server name is normalized for case-insensitive lookup. This method is safe for concurrent use.
func (*ClientManager) Tools ¶
func (cm *ClientManager) Tools(name string) ([]string, bool)
Tools returns the tools for the given server name. The server name is normalized for case-insensitive lookup. It returns a boolean to indicate whether the tools were found. This method is safe for concurrent use.
func (*ClientManager) UpdateTools ¶
func (cm *ClientManager) UpdateTools(name string, tools []string) error
UpdateTools updates the tools list for an existing server without restarting the client. The server name and tool names are normalized for consistent lookups. Returns an error if the server is not found. This method is safe for concurrent use.
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon manages MCP server lifecycles, client connections, and health monitoring. It should only be created using NewDaemon to ensure proper initialization.
func NewDaemon ¶
func NewDaemon(deps Dependencies, opt ...Option) (*Daemon, error)
NewDaemon creates a new Daemon instance with proper initialization. Use this function instead of directly creating a Daemon struct.
func (*Daemon) ReloadServers ¶
ReloadServers reloads the daemon's MCP servers based on a new configuration. It compares the current servers with the new configuration and: - Stops servers that have been removed - Starts servers that have been added - Updates tools for servers where only tools changed - Restarts servers with other configuration changes - Preserves servers that remain unchanged (keeping their client connections, tools, and health history intact)
type Dependencies ¶
type Dependencies struct {
// APIAddr specifies the network address for the APIServer to bind (e.g., "0.0.0.0:8090").
APIAddr string
// Logger for daemon and subcomponent (API server) operations.
Logger hclog.Logger
// RuntimeServers contains the aggregated runtime servers (config + secrets).
RuntimeServers []runtime.Server
}
Dependencies contains required dependencies for the Daemon. NewDependencies should be used to create instances of Dependencies.
func NewDependencies ¶
func NewDependencies( logger hclog.Logger, apiAddr string, runtimeServers []runtime.Server, ) (Dependencies, error)
NewDependencies creates Dependencies with processed runtime servers.
func (Dependencies) Validate ¶
func (d Dependencies) Validate() error
Validate ensures all required dependencies are provided and valid.
type HealthTracker ¶
type HealthTracker struct {
// contains filtered or unexported fields
}
HealthTracker is used to track the health of registered MCP servers. NewHealthTracker should be used to initialize this type.
func NewHealthTracker ¶
func NewHealthTracker(serverNames []string) *HealthTracker
NewHealthTracker creates a HealthTracker which tracks the specified MCP server names.
func (*HealthTracker) Add ¶
func (h *HealthTracker) Add(name string)
Add registers a new server for health tracking. If the server is already being tracked, this is a no-op.
func (*HealthTracker) List ¶
func (h *HealthTracker) List() []domain.ServerHealth
List returns a copy of all known server health records.
func (*HealthTracker) Remove ¶
func (h *HealthTracker) Remove(name string)
Remove stops tracking health for a server and removes its health data.
func (*HealthTracker) Status ¶
func (h *HealthTracker) Status(name string) (domain.ServerHealth, error)
Status returns the health status for a single tracked server.
func (*HealthTracker) Update ¶
func (h *HealthTracker) Update(name string, status domain.HealthStatus, latency *time.Duration) error
Update records a health check for a tracked server. The current time is recorded as LastChecked, and LastSuccessful is updated only if status is HealthStatusOK. Latency can be nil if the ping failed or was not measured.
type Option ¶
Option defines a functional option for configuring Options. Options are applied in order, with later options overriding earlier ones.
func WithAPIOptions ¶
WithAPIOptions configures API server options. Replaces all previous API configuration including CORS settings.
func WithMCPServerHealthCheckInterval ¶
WithMCPServerHealthCheckInterval configures how often to ping MCP servers for health checks.
func WithMCPServerHealthCheckTimeout ¶
WithMCPServerHealthCheckTimeout configures maximum time to wait for MCP server health check responses.
func WithMCPServerInitTimeout ¶
WithMCPServerInitTimeout configures how long to wait for MCP servers to initialize.
func WithMCPServerShutdownTimeout ¶
WithMCPServerShutdownTimeout configures how long to wait for MCP servers to shut down.
func WithPluginConfig ¶
func WithPluginConfig(cfg *config.PluginConfig) Option
WithPluginConfig configures the plugin system with the specified configuration.
type Options ¶
type Options struct {
// APIOptions contains functional options for the API server.
APIOptions []APIOption
// ClientInitTimeout specifies how long to wait for MCP server initialization.
ClientInitTimeout time.Duration
// ClientHealthCheckInterval specifies how often to ping MCP servers for health checks.
ClientHealthCheckInterval time.Duration
// ClientHealthCheckTimeout specifies maximum time to wait for health check responses.
ClientHealthCheckTimeout time.Duration
// ClientShutdownTimeout specifies how long to wait for MCP clients to close.
ClientShutdownTimeout time.Duration
// PluginConfig specifies the configuration for plugins.
PluginConfig *config.PluginConfig
}
Options contains optional configuration for the daemon. NewOptions should be used to create instances of Options.
func NewOptions ¶
NewOptions creates Options with optional configurations applied. Starts with default values, then applies options in order with later options overriding earlier ones.