Documentation
¶
Overview ¶
Package app provides the main application logic.
Index ¶
- func HealthCheck(out io.Writer, addr string, timeout time.Duration) error
- func HealthCheckWithContext(ctx context.Context, out io.Writer, addr string) error
- type Application
- type AuthTestRequest
- type AuthTestResponse
- type GlobalSettingsManager
- type Metric
- type RunOptions
- type Runner
- type SkillServiceServer
- func (s *SkillServiceServer) CreateSkill(_ context.Context, req *pb.CreateSkillRequest) (*pb.CreateSkillResponse, error)
- func (s *SkillServiceServer) DeleteSkill(_ context.Context, req *pb.DeleteSkillRequest) (*pb.DeleteSkillResponse, error)
- func (s *SkillServiceServer) GetSkill(_ context.Context, req *pb.GetSkillRequest) (*pb.GetSkillResponse, error)
- func (s *SkillServiceServer) ListSkills(_ context.Context, _ *pb.ListSkillsRequest) (*pb.ListSkillsResponse, error)
- func (s *SkillServiceServer) UpdateSkill(_ context.Context, req *pb.UpdateSkillRequest) (*pb.UpdateSkillResponse, error)
- type SystemStatusResponse
- type TemplateManager
- type TestAuthRequest
- type TestAuthResponse
- type ToolUsageStats
- type ValidateRequest
- type ValidateResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HealthCheck ¶
HealthCheck performs a health check against a running server by sending an HTTP GET request to its /healthz endpoint. This is useful for monitoring and ensuring the server is operational.
The function constructs the health check URL from the provided address and sends an HTTP GET request. It expects a 200 OK status code for a successful health check.
Parameters:
- out: The writer to which the success message will be written.
- addr: The address (host:port) on which the server is running.
Returns nil if the server is healthy (i.e., responds with a 200 OK), or an error if the health check fails for any reason (e.g., connection error, non-200 status code).
func HealthCheckWithContext ¶
HealthCheckWithContext performs a health check against a running server by sending an HTTP GET request to its /healthz endpoint. This is useful for monitoring and ensuring the server is operational.
The function constructs the health check URL from the provided address and sends an HTTP GET request. It expects a 200 OK status code for a successful health check.
Parameters:
- ctx: The context for managing the health check's lifecycle.
- out: The writer to which the success message will be written.
- addr: The address (host:port) on which the server is running.
Returns nil if the server is healthy (i.e., responds with a 200 OK), or an error if the health check fails for any reason (e.g., connection error, non-200 status code).
Types ¶
type Application ¶
type Application struct {
PromptManager prompt.ManagerInterface
ToolManager tool.ManagerInterface
ResourceManager resource.ManagerInterface
ServiceRegistry serviceregistry.ServiceRegistryInterface
TopologyManager *topology.Manager
UpstreamFactory factory.Factory
Storage storage.Storage
TemplateManager *TemplateManager
// SkillManager manages agent skills
SkillManager *skill.Manager
// AlertsManager manages system alerts
AlertsManager *alerts.Manager
// Settings Manager for global settings (dynamic updates)
SettingsManager *GlobalSettingsManager
// Profile Manager for dynamic profile updates
ProfileManager *profile.Manager
// Auth Manager (stored here for access in runServerMode, though it is also passed to serviceregistry)
// We need to keep a reference to update it on reload.
AuthManager *auth.Manager
// BoundHTTPPort stores the actual port the HTTP server is listening on.
BoundHTTPPort atomic.Int32
// BoundGRPCPort stores the actual port the gRPC server is listening on.
BoundGRPCPort atomic.Int32
// RegistrationRetryDelay allows configuring the retry delay for service registration.
// If 0, it defaults to 5 seconds (in the worker).
RegistrationRetryDelay time.Duration
// contains filtered or unexported fields
}
Application is the main application struct, holding the dependencies and logic for the MCP Any server. It encapsulates the components required to run the server, such as the stdio mode handler, and provides the main `Run` method that starts the application.
func NewApplication ¶
func NewApplication() *Application
NewApplication creates a new Application with default dependencies. It initializes the application with the standard implementation of the stdio mode runner, making it ready to be configured and started.
Returns a new instance of the Application, ready to be run.
func (*Application) ReloadConfig ¶
ReloadConfig reloads the configuration from the given paths and updates the services.
func (*Application) Run ¶
func (a *Application) Run(opts RunOptions) error
Run starts the MCP Any server and all its components. It initializes the core services, loads configurations from the provided paths, starts background workers for handling service registration and upstream service communication, and launches the gRPC and JSON-RPC servers.
The server's lifecycle is managed by the provided context. A graceful shutdown is initiated when the context is canceled.
Parameters:
- ctx: The context for managing the application's lifecycle.
- fs: The filesystem interface for reading configuration files.
- stdio: A boolean indicating whether to run in standard I/O mode.
- jsonrpcPort: The port for the JSON-RPC server.
- grpcPort: The port for the gRPC registration server. An empty string disables the gRPC server.
- configPaths: A slice of paths to service configuration files.
- shutdownTimeout: The duration to wait for a graceful shutdown before forcing termination.
Returns an error if any part of the startup or execution fails.
func (*Application) WaitForStartup ¶
func (a *Application) WaitForStartup(ctx context.Context) error
WaitForStartup waits for the application to be fully initialized. It returns nil if startup completes, or context error if context is canceled.
type AuthTestRequest ¶
type AuthTestRequest struct {
CredentialID string `json:"credential_id"`
ServiceType string `json:"service_type"`
ServiceConfig map[string]any `json:"service_config"`
}
AuthTestRequest defines the structure for an authentication test request.
type AuthTestResponse ¶
AuthTestResponse defines the structure for an authentication test response.
type GlobalSettingsManager ¶
type GlobalSettingsManager struct {
// contains filtered or unexported fields
}
GlobalSettingsManager manages the global settings of the application in a thread-safe manner. It allows for dynamic updates to configuration values that are used across the application.
func NewGlobalSettingsManager ¶
func NewGlobalSettingsManager(apiKey string, allowedIPs []string, allowedOrigins []string) *GlobalSettingsManager
NewGlobalSettingsManager creates a new GlobalSettingsManager with initial values.
apiKey is the apiKey. allowedIPs is the allowedIPs. allowedOrigins is the allowedOrigins.
Returns the result.
func (*GlobalSettingsManager) GetAPIKey ¶
func (m *GlobalSettingsManager) GetAPIKey() string
GetAPIKey returns the current API key.
Returns the result.
func (*GlobalSettingsManager) GetAllowedIPs ¶
func (m *GlobalSettingsManager) GetAllowedIPs() []string
GetAllowedIPs returns the current allowed IPs.
Returns the result.
func (*GlobalSettingsManager) GetAllowedOrigins ¶
func (m *GlobalSettingsManager) GetAllowedOrigins() []string
GetAllowedOrigins returns the current allowed origins.
Returns the result.
func (*GlobalSettingsManager) Update ¶
func (m *GlobalSettingsManager) Update(settings *config_v1.GlobalSettings, explicitAPIKey string)
Update updates the settings from the provided GlobalSettings config.
settings is the settings. explicitAPIKey is the explicitAPIKey.
type Metric ¶
type Metric struct {
Label string `json:"label"`
Value string `json:"value"`
Change string `json:"change"`
Trend string `json:"trend"` // "up" | "down" | "neutral"
Icon string `json:"icon"`
SubLabel string `json:"subLabel"`
}
Metric matches the UI interface.
type RunOptions ¶
type RunOptions struct {
Ctx context.Context
Fs afero.Fs
Stdio bool
JSONRPCPort string
GRPCPort string
ConfigPaths []string
APIKey string
ShutdownTimeout time.Duration
TLSCert string
TLSKey string
TLSClientCA string
}
RunOptions defines the options for running the application.
type Runner ¶
type Runner interface {
// Run starts the application with the given options.
Run(opts RunOptions) error
// ReloadConfig reloads the application configuration from the provided file system
// and paths. It updates the internal state of the application, such as
// service registries and managers, to reflect changes in the configuration files.
//
// Parameters:
// - fs: The filesystem interface for reading configuration files.
// - configPaths: A slice of paths to configuration files to reload.
//
// Returns:
// - An error if the configuration reload fails.
// - ctx: The context for the reload operation.
// - fs: The filesystem interface for reading configuration files.
// - configPaths: A slice of paths to configuration files to reload.
//
// Returns:
// - An error if the configuration reload fails.
ReloadConfig(ctx context.Context, fs afero.Fs, configPaths []string) error
}
Runner defines the interface for running the MCP Any application. It abstracts the application's entry point, allowing for different implementations or mocks for testing purposes.
type SkillServiceServer ¶
type SkillServiceServer struct {
pb.UnimplementedSkillServiceServer
// contains filtered or unexported fields
}
SkillServiceServer implements the SkillService gRPC interface.
func NewSkillServiceServer ¶
func NewSkillServiceServer(manager *skill.Manager) *SkillServiceServer
NewSkillServiceServer creates a new SkillServiceServer.
manager handles the resource management.
Returns the result.
func (*SkillServiceServer) CreateSkill ¶
func (s *SkillServiceServer) CreateSkill(_ context.Context, req *pb.CreateSkillRequest) (*pb.CreateSkillResponse, error)
CreateSkill creates a new skill.
_ is an unused parameter. req is the request object.
Returns the response. Returns an error if the operation fails.
func (*SkillServiceServer) DeleteSkill ¶
func (s *SkillServiceServer) DeleteSkill(_ context.Context, req *pb.DeleteSkillRequest) (*pb.DeleteSkillResponse, error)
DeleteSkill deletes a skill.
_ is an unused parameter. req is the request object.
Returns the response. Returns an error if the operation fails.
func (*SkillServiceServer) GetSkill ¶
func (s *SkillServiceServer) GetSkill(_ context.Context, req *pb.GetSkillRequest) (*pb.GetSkillResponse, error)
GetSkill retrieves a specific skill by name.
_ is an unused parameter. req is the request object.
Returns the response. Returns an error if the operation fails.
func (*SkillServiceServer) ListSkills ¶
func (s *SkillServiceServer) ListSkills(_ context.Context, _ *pb.ListSkillsRequest) (*pb.ListSkillsResponse, error)
ListSkills lists all available skills.
_ is an unused parameter. _ is an unused parameter.
Returns the response. Returns an error if the operation fails.
func (*SkillServiceServer) UpdateSkill ¶
func (s *SkillServiceServer) UpdateSkill(_ context.Context, req *pb.UpdateSkillRequest) (*pb.UpdateSkillResponse, error)
UpdateSkill updates an existing skill.
_ is an unused parameter. req is the request object.
Returns the response. Returns an error if the operation fails.
type SystemStatusResponse ¶
type SystemStatusResponse struct {
UptimeSeconds int64 `json:"uptime_seconds"`
ActiveConnections int32 `json:"active_connections"`
BoundHTTPPort int `json:"bound_http_port"`
BoundGRPCPort int `json:"bound_grpc_port"`
Version string `json:"version"`
SecurityWarnings []string `json:"security_warnings"`
}
SystemStatusResponse represents the response from the system status API.
type TemplateManager ¶
type TemplateManager struct {
// contains filtered or unexported fields
}
TemplateManager manages the persistence and lifecycle of service templates.
func NewTemplateManager ¶
func NewTemplateManager(dataDir string) *TemplateManager
NewTemplateManager creates a new instance of TemplateManager.
dataDir is the dataDir.
Returns the result.
func (*TemplateManager) DeleteTemplate ¶
func (tm *TemplateManager) DeleteTemplate(idOrName string) error
DeleteTemplate deletes a template by its ID or Name.
idOrName is the idOrName.
Returns an error if the operation fails.
func (*TemplateManager) ListTemplates ¶
func (tm *TemplateManager) ListTemplates() []*configv1.UpstreamServiceConfig
ListTemplates returns a list of all stored templates.
Returns the result.
func (*TemplateManager) SaveTemplate ¶
func (tm *TemplateManager) SaveTemplate(template *configv1.UpstreamServiceConfig) error
SaveTemplate saves or updates a template.
template is the template.
Returns an error if the operation fails.
type TestAuthRequest ¶
type TestAuthRequest struct {
// The credential to use (can be a reference ID or inline Credential).
CredentialID string `json:"credential_id"`
// OR inline authentication config
Authentication *configv1.Authentication `json:"authentication"`
// OR inline user token (for ad-hoc testing)
UserToken *configv1.UserToken `json:"user_token"`
// The URL to test against.
TargetURL string `json:"target_url"`
// HTTP Method (GET, POST, etc.)
Method string `json:"method"`
}
TestAuthRequest defines the payload for testing authentication.
type TestAuthResponse ¶
type TestAuthResponse struct {
Status int `json:"status"`
StatusText string `json:"status_text"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
Error string `json:"error,omitempty"`
}
TestAuthResponse defines the response for testing authentication.
type ToolUsageStats ¶
type ToolUsageStats struct {
Name string `json:"name"`
ServiceID string `json:"serviceId"`
Count int64 `json:"count"`
}
ToolUsageStats represents usage statistics for a tool.
type ValidateRequest ¶
type ValidateRequest struct {
Content string `json:"content"`
Format string `json:"format"` // "json" or "yaml"
}
ValidateRequest represents the request body for the validation endpoint.
type ValidateResponse ¶
type ValidateResponse struct {
Valid bool `json:"valid"`
Error string `json:"error,omitempty"`
Message string `json:"message,omitempty"`
}
ValidateResponse represents the response body for the validation endpoint.