httpapi

package
v0.15.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBuildVersion

func GetBuildVersion() string

GetBuildVersion returns the build version from build-time variables. This should be set during build using -ldflags.

func GetLogger

func GetLogger(ctx context.Context) *zap.SugaredLogger

GetLogger retrieves the logger from context, or returns a nop logger if not found

func RequestIDLoggerMiddleware

func RequestIDLoggerMiddleware(logger *zap.SugaredLogger) func(http.Handler) http.Handler

RequestIDLoggerMiddleware creates a logger with the request ID field and adds it to context. This middleware should be registered AFTER RequestIDMiddleware.

func RequestIDMiddleware

func RequestIDMiddleware(next http.Handler) http.Handler

RequestIDMiddleware extracts or generates a request ID for each request. If the client provides a valid X-Request-Id header, it is used. Otherwise, a new UUID v4 is generated. The request ID is: - Added to the request context - Set in the response header (before calling next handler) - Available for logging via GetRequestID(ctx)

func SetupSwaggerHandler

func SetupSwaggerHandler(logger *zap.SugaredLogger) http.Handler

SetupSwaggerHandler returns a handler for Swagger UI This is exported so it can be mounted on the main mux

func WithLogger

func WithLogger(ctx context.Context, logger *zap.SugaredLogger) context.Context

WithLogger adds a logger to the context

Types

type AddServerRequest

type AddServerRequest struct {
	Name        string            `json:"name"`
	URL         string            `json:"url,omitempty"`
	Command     string            `json:"command,omitempty"`
	Args        []string          `json:"args,omitempty"`
	Env         map[string]string `json:"env,omitempty"`
	Headers     map[string]string `json:"headers,omitempty"`
	WorkingDir  string            `json:"working_dir,omitempty"`
	Protocol    string            `json:"protocol,omitempty"`
	Enabled     *bool             `json:"enabled,omitempty"`
	Quarantined *bool             `json:"quarantined,omitempty"`
}

AddServerRequest represents a request to add a new server

type CanonicalConfigPath added in v0.15.1

type CanonicalConfigPath struct {
	Name        string `json:"name"`        // Display name (e.g., "Claude Desktop")
	Format      string `json:"format"`      // Format identifier (e.g., "claude_desktop")
	Path        string `json:"path"`        // Full path to the config file
	Exists      bool   `json:"exists"`      // Whether the file exists
	OS          string `json:"os"`          // Operating system (darwin, windows, linux)
	Description string `json:"description"` // Brief description
}

CanonicalConfigPath represents a well-known config file path

type CanonicalConfigPathsResponse added in v0.15.1

type CanonicalConfigPathsResponse struct {
	OS    string                `json:"os"`    // Current operating system
	Paths []CanonicalConfigPath `json:"paths"` // List of canonical config paths
}

CanonicalConfigPathsResponse represents the response for canonical config paths

type CodeExecError

type CodeExecError struct {
	Message string `json:"message"`
	Code    string `json:"code"`
}

CodeExecError represents execution error details.

type CodeExecHandler

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

CodeExecHandler handles POST /api/v1/code/exec requests.

func NewCodeExecHandler

func NewCodeExecHandler(toolCaller ToolCaller, logger *zap.SugaredLogger) *CodeExecHandler

NewCodeExecHandler creates a new code execution handler.

func (*CodeExecHandler) ServeHTTP

func (h *CodeExecHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type CodeExecOptions

type CodeExecOptions struct {
	TimeoutMS      int      `json:"timeout_ms"`
	MaxToolCalls   int      `json:"max_tool_calls"`
	AllowedServers []string `json:"allowed_servers"`
}

CodeExecOptions represents execution options.

type CodeExecRequest

type CodeExecRequest struct {
	Code    string                 `json:"code"`
	Input   map[string]interface{} `json:"input"`
	Options CodeExecOptions        `json:"options"`
}

CodeExecRequest represents the request body for code execution.

type CodeExecResponse

type CodeExecResponse struct {
	OK        bool                   `json:"ok"`
	Result    interface{}            `json:"result,omitempty"`
	Error     *CodeExecError         `json:"error,omitempty"`
	Stats     map[string]interface{} `json:"stats,omitempty"`
	RequestID string                 `json:"request_id,omitempty"` // T016: Added for error correlation
}

CodeExecResponse represents the response format.

type ImportFromPathRequest added in v0.15.1

type ImportFromPathRequest struct {
	Path        string   `json:"path"`                   // File path to import from
	Format      string   `json:"format,omitempty"`       // Optional format hint
	ServerNames []string `json:"server_names,omitempty"` // Optional: import only these servers
}

ImportFromPathRequest represents a request to import from a file path

type ImportRequest added in v0.15.0

type ImportRequest struct {
	Content     string   `json:"content"`                // Raw JSON or TOML content
	Format      string   `json:"format,omitempty"`       // Optional format hint
	ServerNames []string `json:"server_names,omitempty"` // Optional: import only these servers
}

ImportRequest represents a request to import servers from JSON/TOML content

type ImportResponse added in v0.15.0

type ImportResponse struct {
	Format     string                       `json:"format"`
	FormatName string                       `json:"format_name"`
	Summary    configimport.ImportSummary   `json:"summary"`
	Imported   []ImportedServerResponse     `json:"imported"`
	Skipped    []configimport.SkippedServer `json:"skipped"`
	Failed     []configimport.FailedServer  `json:"failed"`
	Warnings   []string                     `json:"warnings"`
}

ImportResponse represents the response from an import operation

type ImportedServerResponse added in v0.15.0

type ImportedServerResponse struct {
	Name          string   `json:"name"`
	Protocol      string   `json:"protocol"`
	URL           string   `json:"url,omitempty"`
	Command       string   `json:"command,omitempty"`
	Args          []string `json:"args,omitempty"`
	SourceFormat  string   `json:"source_format"`
	OriginalName  string   `json:"original_name"`
	FieldsSkipped []string `json:"fields_skipped,omitempty"`
	Warnings      []string `json:"warnings,omitempty"`
}

ImportedServerResponse represents an imported server in the response

type Server

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

Server provides HTTP API endpoints with chi router

func NewServer

func NewServer(controller ServerController, logger *zap.SugaredLogger, obs *observability.Manager) *Server

NewServer creates a new HTTP API server

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler

type ServerController

type ServerController interface {
	IsRunning() bool
	IsReady() bool
	GetListenAddress() string
	GetUpstreamStats() map[string]interface{}
	StartServer(ctx context.Context) error
	StopServer() error
	GetStatus() interface{}
	StatusChannel() <-chan interface{}
	EventsChannel() <-chan internalRuntime.Event
	// SubscribeEvents creates a new per-client event subscription channel.
	// Each SSE client should get its own channel to avoid competing for events.
	SubscribeEvents() chan internalRuntime.Event
	// UnsubscribeEvents closes and removes the subscription channel.
	UnsubscribeEvents(chan internalRuntime.Event)

	// Server management
	GetAllServers() ([]map[string]interface{}, error)
	AddServer(ctx context.Context, serverConfig *config.ServerConfig) error // T001: Add server
	RemoveServer(ctx context.Context, serverName string) error              // T002: Remove server
	EnableServer(serverName string, enabled bool) error
	RestartServer(serverName string) error
	ForceReconnectAllServers(reason string) error
	GetDockerRecoveryStatus() *storage.DockerRecoveryState
	QuarantineServer(serverName string, quarantined bool) error
	GetQuarantinedServers() ([]map[string]interface{}, error)
	UnquarantineServer(serverName string) error
	GetManagementService() interface{} // Returns the management service for unified operations
	DiscoverServerTools(ctx context.Context, serverName string) error

	// Tools and search
	GetServerTools(serverName string) ([]map[string]interface{}, error)
	SearchTools(query string, limit int) ([]map[string]interface{}, error)

	// Logs
	GetServerLogs(serverName string, tail int) ([]contracts.LogEntry, error)

	// Config and OAuth
	ReloadConfiguration() error
	GetConfigPath() string
	GetLogDir() string
	TriggerOAuthLogin(serverName string) error

	// Secrets management
	GetSecretResolver() *secret.Resolver
	GetCurrentConfig() interface{}
	NotifySecretsChanged(ctx context.Context, operation, secretName string) error

	// Tool call history
	GetToolCalls(limit, offset int) ([]*contracts.ToolCallRecord, int, error)
	GetToolCallByID(id string) (*contracts.ToolCallRecord, error)
	GetServerToolCalls(serverName string, limit int) ([]*contracts.ToolCallRecord, error)
	ReplayToolCall(id string, arguments map[string]interface{}) (*contracts.ToolCallRecord, error)
	GetToolCallsBySession(sessionID string, limit, offset int) ([]*contracts.ToolCallRecord, int, error)

	// Session management
	GetRecentSessions(limit int) ([]*contracts.MCPSession, int, error)
	GetSessionByID(sessionID string) (*contracts.MCPSession, error)

	// Configuration management
	ValidateConfig(cfg *config.Config) ([]config.ValidationError, error)
	ApplyConfig(cfg *config.Config, cfgPath string) (*internalRuntime.ConfigApplyResult, error)
	GetConfig() (*config.Config, error)

	// Token statistics
	GetTokenSavings() (*contracts.ServerTokenMetrics, error)

	// Tool execution
	CallTool(ctx context.Context, toolName string, arguments map[string]interface{}) (interface{}, error)

	// Registry browsing (Phase 7)
	ListRegistries() ([]interface{}, error)
	SearchRegistryServers(registryID, tag, query string, limit int) ([]interface{}, error)

	// Version and updates
	GetVersionInfo() *updatecheck.VersionInfo
	RefreshVersionInfo() *updatecheck.VersionInfo

	// Activity logging (RFC-003)
	ListActivities(filter storage.ActivityFilter) ([]*storage.ActivityRecord, int, error)
	GetActivity(id string) (*storage.ActivityRecord, error)
	StreamActivities(filter storage.ActivityFilter) <-chan *storage.ActivityRecord
}

ServerController defines the interface for core server functionality

type ToolCaller

type ToolCaller interface {
	CallTool(ctx context.Context, toolName string, arguments map[string]interface{}) (interface{}, error)
}

ToolCaller interface for calling tools (subset of ServerController).

Jump to

Keyboard shortcuts

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