app

package
v0.0.0-...-f79cea0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 64 Imported by: 0

Documentation

Overview

Package app provides the main application logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HealthCheck

func HealthCheck(out io.Writer, addr string, timeout time.Duration) error

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

func HealthCheckWithContext(
	ctx context.Context,
	out io.Writer,
	addr string,
) error

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

	// 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
	// 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(ctx context.Context, 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,
	apiKey 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.

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

type AuthTestResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
}

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.

func (*GlobalSettingsManager) GetAPIKey

func (m *GlobalSettingsManager) GetAPIKey() string

GetAPIKey returns the current API key.

func (*GlobalSettingsManager) GetAllowedIPs

func (m *GlobalSettingsManager) GetAllowedIPs() []string

GetAllowedIPs returns the current allowed IPs.

func (*GlobalSettingsManager) GetAllowedOrigins

func (m *GlobalSettingsManager) GetAllowedOrigins() []string

GetAllowedOrigins returns the current allowed origins.

func (*GlobalSettingsManager) Update

func (m *GlobalSettingsManager) Update(settings *config_v1.GlobalSettings, explicitAPIKey string)

Update updates the settings from the provided GlobalSettings config.

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	// Run starts the application with the given configuration.
	Run(
		ctx context.Context,
		fs afero.Fs,
		stdio bool,
		jsonrpcPort, grpcPort string,
		configPaths []string,
		apiKey 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.
	//   - 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.

func (*SkillServiceServer) CreateSkill

CreateSkill creates a new skill.

func (*SkillServiceServer) DeleteSkill

DeleteSkill deletes a skill.

func (*SkillServiceServer) GetSkill

GetSkill retrieves a specific skill by name.

func (*SkillServiceServer) ListSkills

ListSkills lists all available skills.

func (*SkillServiceServer) UpdateSkill

UpdateSkill updates an existing skill.

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.

func (*TemplateManager) DeleteTemplate

func (tm *TemplateManager) DeleteTemplate(idOrName string) error

DeleteTemplate deletes a template by its ID or Name.

func (*TemplateManager) ListTemplates

func (tm *TemplateManager) ListTemplates() []*configv1.UpstreamServiceConfig

ListTemplates returns a list of all stored templates.

func (*TemplateManager) SaveTemplate

func (tm *TemplateManager) SaveTemplate(template *configv1.UpstreamServiceConfig) error

SaveTemplate saves or updates a template.

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.

Jump to

Keyboard shortcuts

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