config

package
v0.0.1 Latest Latest
Warning

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

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

Documentation

Overview

Package config provides configuration management and MCP proxy functionality for the Centian tool.

Index

Constants

View Source
const DefaultAuthHeader = "X-Centian-Auth"

DefaultAuthHeader represents the default header for authentication at the Centian server.

View Source
const DefaultProxyHost = "127.0.0.1"

DefaultProxyHost represents the default bind address for the Centian server.

Variables

View Source
var ConfigCommand = &cli.Command{
	Name:        "config",
	Usage:       "Manage centian configuration",
	Description: "Commands to manage the global centian configuration at ~/.centian/config.json",
	Commands: []*cli.Command{
		configInitCommand,
		configShowCommand,
		configValidateCommand,
		configRemoveCommand,
		configServerCommand,
	},
}

ConfigCommand provides configuration management subcommands for the centian CLI. This is the main entry point for all config-related operations including initialization, validation, and server management.

Functions

func EnsureConfigDir

func EnsureConfigDir() error

EnsureConfigDir creates the config directory if it doesn't exist.

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the centian config directory path.

func GetConfigPath

func GetConfigPath() (string, error)

GetConfigPath returns the full path to config.json.

func SaveConfig

func SaveConfig(config *GlobalConfig) error

SaveConfig saves the configuration to ~/.centian/config.json. Creates the ~/.centian directory if it doesn't exist and writes the configuration as formatted JSON with proper indentation.

func ValidateConfig

func ValidateConfig(config *GlobalConfig) error

ValidateConfig performs full validation including operational requirements. This requires at least one gateway to be configured.

func ValidateConfigForServer

func ValidateConfigForServer(config *GlobalConfig) error

ValidateConfigForServer validates the config is ready for server operation. This checks operational requirements like having at least one gateway configured.

func ValidateConfigSchema

func ValidateConfigSchema(config *GlobalConfig) error

ValidateConfigSchema performs basic schema validation on the configuration. This validates required fields and structure but allows empty gateways. Use ValidateConfigForServer for operational validation before starting a server.

Types

type ConnectionContext

type ConnectionContext struct {
	ServerName string `json:"server_name"` // Name of the MCP server
	Transport  string `json:"transport"`   // Transport type: stdio, http, websocket
	SessionID  string `json:"session_id"`  // Unique session identifier

}

ConnectionContext provides connection-level metadata for processors.

type GatewayConfig

type GatewayConfig struct {
	AllowDynamic         bool                        `json:"allowDynamic,omitempty"` // Allow dynamic proxy endpoints
	AllowGatewayEndpoint bool                        `json:"setupGateway,omitempty"` // Setup gateway endpoint with namespacing
	MCPServers           map[string]*MCPServerConfig `json:"mcpServers"`             // HTTP MCP servers in this gateway
	Processors           []*ProcessorConfig          `json:"processors,omitempty"`
}

GatewayConfig represents a logical grouping of HTTP MCP servers.

func (*GatewayConfig) AddServer

func (g *GatewayConfig) AddServer(name string, server *MCPServerConfig)

AddServer adds a the provided server to the gateways MCP servers using name as key.

func (*GatewayConfig) HasServer

func (g *GatewayConfig) HasServer(name string) bool

HasServer returns true if a server with the provided name exists in this gateway.

func (*GatewayConfig) ListServers

func (g *GatewayConfig) ListServers() []*MCPServerConfig

ListServers returns a slice of all available MCPServerConfigs for this GatewayConfig.

func (*GatewayConfig) RemoveServer

func (g *GatewayConfig) RemoveServer(name string)

RemoveServer removes server identified via name.

type GlobalConfig

type GlobalConfig struct {
	Name        string                    `json:"name"`                 // Name of the server - simplifies server identification
	Version     string                    `json:"version"`              // Config schema version
	AuthEnabled *bool                     `json:"auth,omitempty"`       // Enable or disable proxy auth
	AuthHeader  string                    `json:"authHeader,omitempty"` // Header name for proxy auth
	Proxy       *ProxySettings            `json:"proxy,omitempty"`      // Proxy-level settings
	Gateways    map[string]*GatewayConfig `json:"gateways,omitempty"`   // HTTP proxy gateways
	Processors  []*ProcessorConfig        `json:"processors,omitempty"` // Processor chain
	Metadata    map[string]interface{}    `json:"metadata,omitempty"`   // Additional metadata
}

GlobalConfig represents the main configuration structure stored at ~/.centian/config.json. This is the root configuration object that contains all settings for MCP servers, proxy behavior, processors, and additional metadata.

func DefaultConfig

func DefaultConfig() *GlobalConfig

DefaultConfig returns a default configuration.

func LoadConfig

func LoadConfig() (*GlobalConfig, error)

LoadConfig loads the global configuration from ~/.centian/config.json. If the config file doesn't exist, it creates a new one with default settings. The configuration is validated after loading to ensure it's properly formatted.

func LoadConfigFromPath

func LoadConfigFromPath(path string) (*GlobalConfig, error)

LoadConfigFromPath loads configuration from a custom file path. The configuration is validated after loading.

func (*GlobalConfig) GetAuthHeader

func (g *GlobalConfig) GetAuthHeader() string

GetAuthHeader returns the configured auth header name or the default.

func (*GlobalConfig) IsAuthEnabled

func (g *GlobalConfig) IsAuthEnabled() bool

IsAuthEnabled returns true when auth is enabled or unset.

func (*GlobalConfig) SearchServerByName

func (g *GlobalConfig) SearchServerByName(name string) []ServerSearchResult

SearchServerByName searches for a server given a name, can return multiple results for different gateways.

type MCPServerConfig

type MCPServerConfig struct {
	Name        string                 `json:"name"`                  // Display name
	Command     string                 `json:"command,omitempty"`     // Executable command (for stdio/process transport)
	Args        []string               `json:"args,omitempty"`        // Command arguments
	Env         map[string]string      `json:"env,omitempty"`         // Environment variables
	URL         string                 `json:"url,omitempty"`         // HTTP/WebSocket URL (for http/sse transport)
	Headers     map[string]string      `json:"headers,omitempty"`     // HTTP headers (supports ${ENV_VAR} substitution)
	Enabled     *bool                  `json:"enabled,omitempty"`     // Whether server is active
	Description string                 `json:"description,omitempty"` // Human readable description
	Source      string                 `json:"source,omitempty"`      // Source file path for auto-discovered servers
	Config      map[string]interface{} `json:"config,omitempty"`      // Server-specific config
}

MCPServerConfig represents a single MCP server configuration. Each server defines how to start and connect to an MCP server process, including all necessary arguments, e.g. command, arguments, environment variables, and metadata.

func (*MCPServerConfig) GetSubstitutedHeaders

func (s *MCPServerConfig) GetSubstitutedHeaders() map[string]string

GetSubstitutedHeaders returns headers with environment variables substituted. Supports both ${VAR_NAME} and $VAR_NAME syntax. Example: "Bearer ${GITHUB_TOKEN}" -> "Bearer ghp_abc123...".

func (*MCPServerConfig) IsEnabled

func (s *MCPServerConfig) IsEnabled() bool

IsEnabled returns true if the MCP server is either explicitly enabled or the flag is unset (nil).

type ProcessorConfig

type ProcessorConfig struct {
	Name    string                 `json:"name"`              // Unique processor name
	Type    string                 `json:"type"`              // Processor type: "cli" (future: "http", "builtin")
	Enabled bool                   `json:"enabled"`           // Whether processor is active
	Timeout int                    `json:"timeout,omitempty"` // Timeout in seconds (default: 15)
	Config  map[string]interface{} `json:"config"`            // Type-specific configuration
}

ProcessorConfig defines a single processor that executes during MCP request/response flow. Processors are composable units that can inspect, modify, or reject MCP messages.

TODO: move below documentation into a better place Type-specific configuration (Config field):

For CLIProcessor processors:

  • "command" (string, required): Executable command to run (e.g., "python", "bash", "node").
  • "args" (array of strings, optional): Command-line arguments (e.g., ["script.py", "--flag"]).

Example CLI processor:

{.
  "name": "security-validator",
  "type": "cli",
  "enabled": true,
  "timeout": 20,
  "config": {
    "command": "python",
    "args": ["~/processors/security.py", "--strict"]
  }
}.

type ProcessorInput

type ProcessorInput struct {
	Type       string                 `json:"type"`       // "request" or "response"
	Timestamp  string                 `json:"timestamp"`  // ISO 8601 timestamp
	Connection ConnectionContext      `json:"connection"` // Connection metadata
	Payload    map[string]interface{} `json:"payload"`    // MCP message payload
	Metadata   ProcessorMetadata      `json:"metadata"`   // Additional context
}

ProcessorInput represents the JSON input passed to processors via stdin. This structure provides all context needed for the processor to make decisions.

type ProcessorMetadata

type ProcessorMetadata struct {
	ProcessorChain  []string               `json:"processor_chain"`  // Names of processors already executed
	OriginalPayload map[string]interface{} `json:"original_payload"` // Original unmodified payload
}

ProcessorMetadata contains additional context for processor execution.

type ProcessorOutput

type ProcessorOutput struct {
	Status   int                    `json:"status"`             // HTTP-style status: 200, 40x, 50x
	Payload  map[string]interface{} `json:"payload"`            // Modified or original payload
	Error    *string                `json:"error"`              // Error message if status >= 400, otherwise null
	Metadata map[string]interface{} `json:"metadata,omitempty"` // Processor-specific metadata
}

ProcessorOutput represents the JSON output expected from processors via stdout. Processors must return this structure to indicate their decision and any modifications.

type ProcessorType

type ProcessorType string

ProcessorType defines the type of processor, e.g. cli, webhook, internal, etc.

const (
	// CLIProcessor represents the type of a CLI-based processor -> "cli".
	CLIProcessor ProcessorType = "cli"
)

type ProxySettings

type ProxySettings struct {
	Host     string `json:"host,omitempty"`     // Bind address for the proxy
	Port     string `json:"port,omitempty"`     // HTTP proxy port (if enabled)
	LogLevel string `json:"logLevel,omitempty"` // debug, info, warn, error
	LogFile  string `json:"logFile,omitempty"`  // Log file path
	Timeout  int    `json:"timeout,omitempty"`  // Request timeout in seconds
}

ProxySettings contains proxy-level configuration that affects how the centian proxy operates, including transport method, logging, and timeouts.

func NewDefaultProxySettings

func NewDefaultProxySettings() ProxySettings

NewDefaultProxySettings creates a new ProxySettings with default values.

type ServerSearchResult

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

ServerSearchResult captures data and references when searching for a specific server in the config.

Jump to

Keyboard shortcuts

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