Documentation
¶
Overview ¶
Package app provides the main application logic.
Index ¶
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
UpstreamFactory factory.Factory
// 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 ¶
func (a *Application) ReloadConfig(fs afero.Fs, configPaths []string) error
ReloadConfig reloads the configuration from the given paths and updates the services.
func (*Application) Run ¶
func (a *Application) Run( ctx context.Context, fs afero.Fs, stdio bool, jsonrpcPort, grpcPort string, configPaths []string, shutdownTimeout time.Duration, ) 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.
type Runner ¶
type Runner interface {
// Run starts the MCP Any application with the given context, filesystem, and
// configuration. It is the primary entry point for the server.
//
// ctx is the context that controls the application's lifecycle.
// fs is the filesystem interface for reading configurations.
// stdio specifies whether to run in standard I/O mode.
// jsonrpcPort is the port for the JSON-RPC server.
// grpcPort is the port for the gRPC registration server.
// configPaths is a slice of paths to configuration files.
//
// It returns an error if the application fails to start or run.
Run(
ctx context.Context,
fs afero.Fs,
stdio bool,
jsonrpcPort, grpcPort string,
configPaths []string,
shutdownTimeout time.Duration,
) 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.
ReloadConfig(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.