framework

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

framework/color_helper.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintError added in v0.3.0

func PrintError(err error)

PrintError prints a colored error message

func PrintMetrics added in v0.3.0

func PrintMetrics(metrics map[string]interface{})

PrintMetrics prints metrics in a colored format

func PrintServerConfig added in v0.3.0

func PrintServerConfig(config map[string]string)

PrintServerConfig prints server configuration in a colorful table

func PrintShutdownMessage added in v0.3.0

func PrintShutdownMessage()

PrintShutdownMessage prints a shutdown message

func PrintStartupBanner added in v0.3.0

func PrintStartupBanner(name, version, description string)

PrintStartupBanner prints a colorful startup banner

func PrintStartupMessage added in v0.3.0

func PrintStartupMessage(transport, address string)

PrintStartupMessage prints a formatted startup message

func PrintToolsList added in v0.3.0

func PrintToolsList(tools []string)

PrintToolsList prints available tools in a colored format

Types

type BackendConfig

type BackendConfig struct {
	Type   string                 `yaml:"type"`
	Config map[string]interface{} `yaml:"config"`
}

BackendConfig configures the backend

type Config

type Config struct {
	Backend       BackendConfig       `yaml:"backend"`
	Transport     TransportConfig     `yaml:"transport"`
	Observability ObservabilityConfig `yaml:"observability"`
	Logging       LoggingConfig       `yaml:"logging"`
	Streaming     StreamingConfig     `yaml:"streaming"` // NEW
}

Config represents the complete server configuration

func DefaultConfig added in v0.2.0

func DefaultConfig() *Config

DefaultConfig returns the default configuration

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads configuration from a YAML file

func (*Config) Validate added in v0.2.0

func (c *Config) Validate() error

Validate validates the configuration

type HTTPConfig

type HTTPConfig struct {
	Address        string        `yaml:"address"`
	ReadTimeout    time.Duration `yaml:"read_timeout"`
	WriteTimeout   time.Duration `yaml:"write_timeout"`
	MaxRequestSize int64         `yaml:"max_request_size"`
	AllowedOrigins []string      `yaml:"allowed_origins"`
}

HTTPConfig configures HTTP transport

type LoggingConfig

type LoggingConfig struct {
	Level     string `yaml:"level"`
	Format    string `yaml:"format"`
	AddSource bool   `yaml:"add_source"`
}

LoggingConfig configures logging

type ObservabilityConfig

type ObservabilityConfig struct {
	Enabled        bool   `yaml:"enabled"`
	MetricsAddress string `yaml:"metrics_address"`
}

ObservabilityConfig configures observability features

type Option

type Option func(*Server)

Option configures the server

func WithAuth added in v0.3.0

func WithAuth(authType string, config interface{}) Option

WithAuth configures basic authentication

func WithAuthProvider added in v0.3.0

func WithAuthProvider(name string, provider auth.AuthProvider) Option

WithAuthProvider directly sets an auth provider

func WithAuthResource added in v0.3.0

func WithAuthResource(providerName string, resource auth.ResourceConfig) Option

WithAuthResource registers a resource with an auth provider

func WithAutoColors added in v0.3.0

func WithAutoColors() Option

WithAutoColors returns a function option to auto-detect color support

func WithBackend

func WithBackend(b backend.ServerBackend) Option

WithBackend sets a specific backend instance

func WithBackendType

func WithBackendType(backendType string) Option

WithBackendType sets the backend type

func WithCache added in v0.4.0

func WithCache(cacheType string, ttl int) Option

WithCache configures response caching

Example:

framework.NewServer(
    framework.WithCache("short", 60), // 60 seconds
)

func WithCacheConfig added in v0.4.0

func WithCacheConfig(config *cache.Config) Option

WithCacheConfig sets the complete cache configuration

func WithCacheDisabled added in v0.4.0

func WithCacheDisabled() Option

WithCacheDisabled explicitly disables caching

func WithCacheSize added in v0.4.0

func WithCacheSize(maxSize int) Option

WithCacheSize sets the maximum cache size (for memory cache)

func WithColors added in v0.3.0

func WithColors(enable bool) Option

WithColors returns a function option to enable colored output

func WithConfig

func WithConfig(config *Config) Option

WithConfig sets the complete configuration

func WithConfigFile

func WithConfigFile(path string) Option

WithConfigFile sets the config file path

func WithFacebook added in v0.3.0

func WithFacebook(clientID, clientSecret, redirectURL string, scopes []string) Option

WithFacebook is a convenience function for Facebook OAuth2

func WithGitHub added in v0.3.0

func WithGitHub(clientID, clientSecret, redirectURL string, scopes []string) Option

WithGitHub is a convenience function for GitHub OAuth2

func WithGoogle added in v0.3.0

func WithGoogle(clientID, clientSecret, redirectURL string, scopes []string) Option

WithGoogle is a convenience function for Google OAuth2

func WithHTTPAddress

func WithHTTPAddress(addr string) Option

WithHTTPAddress sets the HTTP server address

func WithLogLevel

func WithLogLevel(level string) Option

WithLogLevel sets the log level

func WithMaxConcurrent added in v0.2.0

func WithMaxConcurrent(max int) Option

WithMaxConcurrent sets maximum concurrent executions

func WithMaxEvents added in v0.2.0

func WithMaxEvents(max int64) Option

WithMaxEvents sets maximum events per execution

func WithMetricsAddress

func WithMetricsAddress(addr string) Option

WithMetricsAddress sets the metrics server address

func WithMicrosoft added in v0.3.0

func WithMicrosoft(clientID, clientSecret, redirectURL string, scopes []string) Option

WithMicrosoft is a convenience function for Microsoft OAuth2

func WithOAuth added in v0.3.0

func WithOAuth(providerName, clientID, clientSecret, redirectURL string, scopes []string) Option

WithOAuth configures OAuth2 authentication for popular providers

func WithOAuth2Token added in v0.3.0

func WithOAuth2Token(providerName string, token *auth.OAuth2Token) Option

WithOAuth2Token sets a pre-configured OAuth2 token

func WithObservability

func WithObservability(enabled bool) Option

WithObservability enables/disables observability

func WithSlack added in v0.3.0

func WithSlack(clientID, clientSecret, redirectURL string, scopes []string) Option

WithSlack is a convenience function for Slack OAuth2

func WithStreaming added in v0.2.0

func WithStreaming(enabled bool) Option

WithStreaming enables/disables streaming

func WithStreamingBufferSize added in v0.2.0

func WithStreamingBufferSize(size int) Option

WithStreamingBufferSize sets the event buffer size

func WithStreamingTimeout added in v0.2.0

func WithStreamingTimeout(timeout time.Duration) Option

WithStreamingTimeout sets the execution timeout

func WithToolCacheTTL added in v0.4.0

func WithToolCacheTTL(toolName string, ttl time.Duration) Option

WithToolCacheTTL sets per-tool TTL override

Example:

framework.NewServer(
    framework.WithCache("short", 60),
    framework.WithToolCacheTTL("search", 30*time.Second),
)

func WithTransport

func WithTransport(transport string) Option

WithTransport sets the transport type

type Server

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

Server is the main MCP server

func NewServer

func NewServer(opts ...Option) *Server

NewServer creates a new MCP server

func (*Server) GetAuthManager added in v0.3.0

func (s *Server) GetAuthManager() *auth.Manager

GetAuthManager returns the auth manager

func (*Server) GetBackend added in v0.2.0

func (s *Server) GetBackend() backend.ServerBackend

GetBackend returns the current backend

func (*Server) GetCache added in v0.4.0

func (s *Server) GetCache() cache.Cache

GetCache returns the cache instance

func (*Server) GetCacheConfig added in v0.4.0

func (s *Server) GetCacheConfig() *cache.Config

GetCacheConfig returns the cache configuration

func (*Server) GetExecutor added in v0.2.0

func (s *Server) GetExecutor() *engine.Executor

GetExecutor returns the streaming executor

func (*Server) GetKeyGenerator added in v0.4.0

func (s *Server) GetKeyGenerator() *cache.KeyGenerator

GetKeyGenerator returns the key generator

func (*Server) GetLogger added in v0.3.0

func (s *Server) GetLogger() *slog.Logger

GetLogger returns the logger

func (*Server) Initialize added in v0.2.0

func (s *Server) Initialize(ctx context.Context) error

Initialize initializes the server

func (*Server) RegisterBackend added in v0.2.0

func (s *Server) RegisterBackend(b backend.ServerBackend)

RegisterBackend registers a full backend

func (*Server) RegisterFunction added in v0.2.0

func (s *Server) RegisterFunction(name string, handler backend.StreamingHandler)

RegisterFunction registers a single streaming function as a tool

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts the server

type StreamingConfig added in v0.2.0

type StreamingConfig struct {
	Enabled       bool          `yaml:"enabled"`
	BufferSize    int           `yaml:"buffer_size"`
	Timeout       time.Duration `yaml:"timeout"`
	MaxEvents     int64         `yaml:"max_events"`
	MaxConcurrent int           `yaml:"max_concurrent"` // NEW: v2 semaphore
}

StreamingConfig configures streaming execution (NEW - v2 feature)

type TransportConfig

type TransportConfig struct {
	Type  string     `yaml:"type"`
	HTTP  HTTPConfig `yaml:"http"`
	Stdio struct{}   `yaml:"stdio"`
}

TransportConfig configures the transport layer

Jump to

Keyboard shortcuts

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