api

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateHTTPClient

func CreateHTTPClient(endpoint string, timeout time.Duration, logger *zap.SugaredLogger) *http.Client

CreateHTTPClient creates an HTTP client with socket/pipe awareness and optional timeout. This is used by both the API client and health monitor to ensure consistent behavior.

Types

type Client

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

Client provides access to the mcpproxy API

func NewClient

func NewClient(endpoint string, logger *zap.SugaredLogger) *Client

NewClient creates a new API client with automatic socket/pipe support

func (*Client) ConnectionStateChannel

func (c *Client) ConnectionStateChannel() <-chan tray.ConnectionState

ConnectionStateChannel exposes connectivity updates for tray consumers.

func (*Client) EnableServer

func (c *Client) EnableServer(serverName string, enabled bool) error

EnableServer enables or disables a server

func (*Client) ForceReconnectAllServers

func (c *Client) ForceReconnectAllServers(reason string) error

ForceReconnectAllServers triggers reconnection attempts for all upstream servers

func (*Client) GetDockerStatus

func (c *Client) GetDockerStatus() (*DockerStatus, error)

GetDockerStatus retrieves the current Docker recovery status

func (*Client) GetInfo

func (c *Client) GetInfo() (map[string]interface{}, error)

SearchTools searches for tools GetInfo fetches server information from /api/v1/info endpoint

func (*Client) GetReady

func (c *Client) GetReady(ctx context.Context) error

GetReady checks if the core API is ready to serve requests

func (*Client) GetServerTools

func (c *Client) GetServerTools(serverName string) ([]Tool, error)

GetServerTools gets tools for a specific server

func (*Client) GetServers

func (c *Client) GetServers() ([]Server, error)

GetServers fetches the list of servers from the API

func (*Client) GetStatus

func (c *Client) GetStatus() (map[string]interface{}, error)

GetStatus fetches the current status snapshot from /api/v1/status

func (*Client) OpenWebUI

func (c *Client) OpenWebUI() error

OpenWebUI opens the web control panel in the default browser

func (*Client) RestartServer

func (c *Client) RestartServer(serverName string) error

RestartServer restarts a server

func (*Client) SearchTools

func (c *Client) SearchTools(query string, limit int) ([]SearchResult, error)

func (*Client) SetAPIKey

func (c *Client) SetAPIKey(apiKey string)

SetAPIKey sets the API key for authentication

func (*Client) StartSSE

func (c *Client) StartSSE(ctx context.Context) error

StartSSE starts the Server-Sent Events connection for real-time updates with enhanced retry logic

func (*Client) StatusChannel

func (c *Client) StatusChannel() <-chan StatusUpdate

StatusChannel returns the channel for status updates

func (*Client) StopSSE

func (c *Client) StopSSE()

StopSSE stops the SSE connection

func (*Client) TriggerOAuthLogin

func (c *Client) TriggerOAuthLogin(serverName string) error

TriggerOAuthLogin triggers OAuth login for a server

type ClientInterface

type ClientInterface interface {
	GetServers() ([]Server, error)
	GetInfo() (map[string]interface{}, error)
	EnableServer(serverName string, enabled bool) error
	TriggerOAuthLogin(serverName string) error
	StatusChannel() <-chan StatusUpdate
}

ClientInterface defines the methods required by ServerAdapter from the API client. This interface allows for testing with mock implementations.

type DockerStatus

type DockerStatus struct {
	DockerAvailable  bool   `json:"docker_available"`
	RecoveryMode     bool   `json:"recovery_mode"`
	FailureCount     int    `json:"failure_count"`
	AttemptsSinceUp  int    `json:"attempts_since_up"`
	LastAttempt      string `json:"last_attempt"`
	LastError        string `json:"last_error"`
	LastSuccessfulAt string `json:"last_successful_at"`
}

DockerStatus represents Docker recovery status from the API

type HealthStatus

type HealthStatus struct {
	Level      string `json:"level"`            // "healthy", "degraded", "unhealthy"
	AdminState string `json:"admin_state"`      // "enabled", "disabled", "quarantined"
	Summary    string `json:"summary"`          // e.g., "Connected (5 tools)"
	Detail     string `json:"detail,omitempty"` // Optional longer explanation
	Action     string `json:"action,omitempty"` // "login", "restart", "enable", "approve", "set_secret", "configure", "view_logs", ""
}

HealthStatus represents the unified health status of an upstream MCP server. This matches the contracts.HealthStatus struct from the core. Spec 013: Health is the single source of truth for server status.

type Response

type Response struct {
	Success bool                   `json:"success"`
	Data    map[string]interface{} `json:"data,omitempty"`
	Error   string                 `json:"error,omitempty"`
}

Response represents the standard API response format

type SearchResult

type SearchResult struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Server      string                 `json:"server"`
	Score       float64                `json:"score"`
	InputSchema map[string]interface{} `json:"input_schema,omitempty"`
}

SearchResult represents a search result from the API

type Server

type Server struct {
	Name        string        `json:"name"`
	Connected   bool          `json:"connected"`
	Connecting  bool          `json:"connecting"`
	Enabled     bool          `json:"enabled"`
	Quarantined bool          `json:"quarantined"`
	Protocol    string        `json:"protocol"`
	URL         string        `json:"url"`
	Command     string        `json:"command"`
	ToolCount   int           `json:"tool_count"`
	LastError   string        `json:"last_error"`
	Status      string        `json:"status"`
	ShouldRetry bool          `json:"should_retry"`
	RetryCount  int           `json:"retry_count"`
	LastRetry   string        `json:"last_retry_time"`
	Health      *HealthStatus `json:"health,omitempty"` // Spec 013: Health is source of truth
}

Server represents a server from the API

type ServerAdapter

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

ServerAdapter adapts the API client to the ServerInterface expected by the tray

func NewServerAdapter

func NewServerAdapter(client ClientInterface) *ServerAdapter

NewServerAdapter creates a new server adapter

func (*ServerAdapter) EnableServer

func (a *ServerAdapter) EnableServer(serverName string, enabled bool) error

EnableServer enables or disables a server

func (*ServerAdapter) EventsChannel

func (a *ServerAdapter) EventsChannel() <-chan internalRuntime.Event

EventsChannel returns nil as the remote API does not yet proxy runtime events.

func (*ServerAdapter) GetAllServers

func (a *ServerAdapter) GetAllServers() ([]map[string]interface{}, error)

GetAllServers returns all servers

func (*ServerAdapter) GetConfigPath

func (a *ServerAdapter) GetConfigPath() string

GetConfigPath returns the configuration file path

func (*ServerAdapter) GetListenAddress

func (a *ServerAdapter) GetListenAddress() string

GetListenAddress returns the listen address from the core's /api/v1/info endpoint

func (*ServerAdapter) GetLogDir

func (a *ServerAdapter) GetLogDir() string

GetLogDir returns the log directory path

func (*ServerAdapter) GetQuarantinedServers

func (a *ServerAdapter) GetQuarantinedServers() ([]map[string]interface{}, error)

GetQuarantinedServers returns quarantined servers

func (*ServerAdapter) GetStatus

func (a *ServerAdapter) GetStatus() interface{}

GetStatus returns the current server status

func (*ServerAdapter) GetUpstreamStats

func (a *ServerAdapter) GetUpstreamStats() map[string]interface{}

GetUpstreamStats returns upstream server statistics

func (*ServerAdapter) IsRunning

func (a *ServerAdapter) IsRunning() bool

IsRunning checks if the server is running via API

func (*ServerAdapter) QuarantineServer

func (a *ServerAdapter) QuarantineServer(serverName string, quarantined bool) error

QuarantineServer sets quarantine status for a server

func (*ServerAdapter) ReloadConfiguration

func (a *ServerAdapter) ReloadConfiguration() error

ReloadConfiguration reloads the configuration

func (*ServerAdapter) SetListenAddress

func (a *ServerAdapter) SetListenAddress(_ string, _ bool) error

SetListenAddress is not supported via API control surfaces.

func (*ServerAdapter) StartServer

func (a *ServerAdapter) StartServer(_ context.Context) error

StartServer is not supported via API (server is already running)

func (*ServerAdapter) StatusChannel

func (a *ServerAdapter) StatusChannel() <-chan interface{}

StatusChannel returns the channel for status updates from SSE

func (*ServerAdapter) StopServer

func (a *ServerAdapter) StopServer() error

StopServer is not supported via API (would break tray communication)

func (*ServerAdapter) SuggestAlternateListen

func (a *ServerAdapter) SuggestAlternateListen(baseAddr string) (string, error)

SuggestAlternateListen cannot operate through the remote API adapter.

func (*ServerAdapter) TriggerOAuthLogin

func (a *ServerAdapter) TriggerOAuthLogin(serverName string) error

TriggerOAuthLogin triggers OAuth login for a server

func (*ServerAdapter) UnquarantineServer

func (a *ServerAdapter) UnquarantineServer(serverName string) error

UnquarantineServer removes a server from quarantine

type StatusUpdate

type StatusUpdate struct {
	Running       bool                   `json:"running"`
	ListenAddr    string                 `json:"listen_addr"`
	UpstreamStats map[string]interface{} `json:"upstream_stats"`
	Status        map[string]interface{} `json:"status"`
	Timestamp     int64                  `json:"timestamp"`
}

StatusUpdate represents a status update from SSE

type Tool

type Tool struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Server      string                 `json:"server"`
	InputSchema map[string]interface{} `json:"input_schema,omitempty"`
}

Tool represents a tool from the API

Jump to

Keyboard shortcuts

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