Documentation
¶
Index ¶
- Constants
- func ConvertArgs(args map[string]any) map[string]any
- func ConvertValue(paramName string, value any) any
- func DefaultConfigPath() (string, error)
- func GroupToolsByServer(tools map[string][]Tool) map[string]int
- func IsBoolParam(name string) bool
- func IsNumberParam(name string) bool
- func RetryOperation(ctx context.Context, config RetryConfig, operation func() error) error
- func SanitizeServerName(name string) string
- func SnakeToCamel(s string) string
- func ValidateServerConfig(config ServerConfig) error
- type AuthConfig
- type Client
- type ClientConfig
- type Config
- type FunctionDefinition
- type MCPClient
- type MCPStatus
- type Manager
- func (m *Manager) Close() error
- func (m *Manager) ConnectAll(ctx context.Context) error
- func (m *Manager) DiscoverAndConnectServers(ctx context.Context) error
- func (m *Manager) GetClient(name string) (*Client, bool)
- func (m *Manager) GetStatus(ctx context.Context, mcpClientEnabled bool) (*MCPStatus, error)
- func (m *Manager) ListAvailableTools(ctx context.Context) (map[string][]Tool, error)
- func (m *Manager) ListClients() []*Client
- func (m *Manager) LogConfig(mcpConfigPath string) error
- func (m *Manager) RefreshToolDiscovery(ctx context.Context) (map[string][]Tool, error)
- func (m *Manager) RegisterTools(ctx context.Context, registerCallback func(serverName string, tool Tool) error) error
- func (m *Manager) RegisterWithToolSystem(ctx context.Context, registerCallback func(serverName string, tool Tool) error) error
- type OAuthConfig
- type RetryConfig
- type SchemaBuilder
- type SchemaProperty
- type ServerConfig
- type ServerConnectionInfo
- type Tool
Constants ¶
const ( // DefaultConnectionTimeout is the timeout for establishing connections to MCP servers DefaultConnectionTimeout = 30 * time.Second // DefaultVerificationTimeout is the timeout for verifying server connections DefaultVerificationTimeout = 10 * time.Second // DefaultPingTimeout is the timeout for ping operations DefaultPingTimeout = 5 * time.Second // DefaultStabilizationDelay is the delay to allow servers to stabilize after connection DefaultStabilizationDelay = 2 * time.Second )
Timeout constants for MCP operations
const ( ErrServerConnectionFmt = "connecting to MCP server %q: %w" ErrServerCloseFmt = "closing MCP client %q: %w" ErrToolCallFmt = "calling tool %q: %w" ErrPathCheckFmt = "checking path %q: %w" )
Error message templates
const ( ClientName = "kubectl-qyai-mcp-client" ClientVersion = "1.0.0" )
Client constants
const ( ConfigFilePermissions = 0600 ConfigDirPermissions = 0755 )
File permissions
const (
// EnvMCPServerPrefix is the prefix for MCP server environment variables
EnvMCPServerPrefix = "MCP_"
)
Constants for environment variables
Variables ¶
This section is empty.
Functions ¶
func ConvertArgs ¶
ConvertArgs handles all argument conversions for MCP tools. It transforms keys from snake_case to camelCase and converts values to appropriate types.
func ConvertValue ¶
ConvertValue infers and converts a value to an appropriate type based on the parameter name.
func DefaultConfigPath ¶
DefaultConfigPath returns the default path to the MCP config file
func GroupToolsByServer ¶
GroupToolsByServer groups tools by their server name for easier display
func IsBoolParam ¶
IsBoolParam checks if a parameter name suggests a boolean value.
func IsNumberParam ¶
IsNumberParam checks if a parameter name suggests a numeric value.
func RetryOperation ¶
func RetryOperation(ctx context.Context, config RetryConfig, operation func() error) error
RetryOperation executes an operation with exponential backoff retry
func SanitizeServerName ¶
SanitizeServerName ensures server names are valid identifiers
func SnakeToCamel ¶
SnakeToCamel converts a snake_case string to camelCase.
func ValidateServerConfig ¶
func ValidateServerConfig(config ServerConfig) error
ValidateServerConfig validates a single server configuration
Types ¶
type AuthConfig ¶
type AuthConfig struct {
Type string // "none", "basic", "bearer", "api-key"
Username string // For basic auth
Password string // For basic auth
Token string // For bearer auth
ApiKey string // For API key auth
HeaderName string // Custom header name for API key
}
AuthConfig represents authentication options for HTTP MCP servers
type Client ¶
type Client struct {
// Name is a friendly name for this MCP server connection
Name string
// contains filtered or unexported fields
}
Client represents an MCP client that can connect to MCP servers. It is a wrapper around the MCPClient interface for backward compatibility.
func CreateStdioClient ¶
CreateStdioClient creates a new stdio-based MCP client (for backward compatibility).
func NewClient ¶
func NewClient(config ClientConfig) *Client
NewClient creates a new MCP client with the given configuration. This function supports both stdio and HTTP-based MCP servers.
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, toolName string, arguments map[string]interface{}) (string, error)
CallTool calls a tool on the MCP server and returns the result as a string. The arguments should be a map of parameter names to values that will be passed to the tool.
func (*Client) Close ¶
Close closes the connection to the MCP server.
func (*Client) Connect ¶
Connect establishes a connection to the MCP server. This delegates to the appropriate implementation (stdio or HTTP).
type ClientConfig ¶
type ClientConfig struct {
// Common fields
Name string
// For stdio-based clients
Command string
Args []string
Env []string
// For HTTP-based clients
URL string
Auth *AuthConfig
OAuthConfig *OAuthConfig
Timeout int
UseStreaming bool // Whether to use streaming HTTP for better performance
SkipVerify bool // Whether to skip TLS certificate verification for HTTPS connections
Headers map[string]string // Custom headers to include in HTTP requests
}
ClientConfig contains all configuration options for MCP clients
type Config ¶
type Config struct {
// Servers is a list of MCP server configurations
Servers []ServerConfig `yaml:"servers,omitempty"`
}
Config represents the complete MCP client configuration file
func LoadConfig ¶
LoadConfig loads the MCP configuration from the given path and applies environment variable overrides If path is empty, the default config path is used If the file doesn't exist, it creates a default configuration file
func (*Config) Save ¶
Save saves the configuration to the given path using atomic write
type FunctionDefinition ¶
type FunctionDefinition interface {
// Schema returns a representation of the function schema
Schema() any
}
FunctionDefinition is an interface representing generic function schema definitions This allows the MCP package to create schemas without directly depending on gollm
type MCPClient ¶
type MCPClient interface {
// Name returns the name of this client
Name() string
// Connect establishes a connection to the MCP server
Connect(ctx context.Context) error
// Close closes the connection to the MCP server
Close() error
// ListTools lists all available tools from the MCP server
ListTools(ctx context.Context) ([]Tool, error)
// CallTool calls a tool on the MCP server and returns the result as a string
CallTool(ctx context.Context, toolName string, arguments map[string]interface{}) (string, error)
// contains filtered or unexported methods
}
MCPClient defines the common interface for all MCP client implementations
func NewHTTPClient ¶
func NewHTTPClient(config ClientConfig) MCPClient
NewHTTPClient creates a new HTTP-based MCP client
func NewMCPClient ¶
func NewMCPClient(config ClientConfig) (MCPClient, error)
NewMCPClient creates a new MCP client with the appropriate implementation based on the config
func NewStdioClient ¶
func NewStdioClient(config ClientConfig) MCPClient
NewStdioClient creates a new stdio-based MCP client
type MCPStatus ¶
type MCPStatus struct {
ServerInfoList []ServerConnectionInfo
TotalServers int
ConnectedCount int
FailedCount int
TotalTools int
ClientEnabled bool
}
MCPStatus represents the overall status of MCP servers and tools
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles MCP client connections and tool discovery
func InitializeManager ¶
InitializeManager creates and initializes the MCP manager with configuration loaded from default paths
func NewManager ¶
NewManager creates a new MCP manager with the given configuration
func (*Manager) ConnectAll ¶
ConnectAll connects to all configured MCP servers
func (*Manager) DiscoverAndConnectServers ¶
DiscoverAndConnectServers connects to all configured servers with a timeout and stabilization delay
func (*Manager) GetClient ¶
GetClient returns a connected MCP client by name
func (*Manager) GetStatus ¶
GetStatus returns status of all MCP servers and their tools
func (*Manager) ListAvailableTools ¶
ListAvailableTools returns tools from all connected servers For retries and more robust handling, use RefreshToolDiscovery
func (*Manager) ListClients ¶
ListClients returns a list of all connected MCP clients
func (*Manager) LogConfig ¶
LogConfig logs the MCP configuration summary If mcpConfigPath is empty, uses the Manager's existing config
func (*Manager) RefreshToolDiscovery ¶
RefreshToolDiscovery discovers tools from all servers with retries
func (*Manager) RegisterTools ¶
func (m *Manager) RegisterTools(ctx context.Context, registerCallback func(serverName string, tool Tool) error) error
RegisterTools discovers and registers tools from all MCP servers using the provided callback The callback function is responsible for creating and registering tool wrappers
func (*Manager) RegisterWithToolSystem ¶
func (m *Manager) RegisterWithToolSystem(ctx context.Context, registerCallback func(serverName string, tool Tool) error) error
RegisterWithToolSystem connects to MCP servers and registers discovered tools with an external tool system using the provided callback function. This simplifies integration with kubectl-qyai's tool system.
type OAuthConfig ¶
type OAuthConfig struct {
ClientID string
ClientSecret string
TokenURL string
AuthURL string
Scopes []string
RedirectURL string
}
OAuthConfig represents OAuth configuration for HTTP MCP servers
type RetryConfig ¶
type RetryConfig struct {
MaxRetries int
BaseDelay time.Duration
MaxDelay time.Duration
Multiplier float64
Description string
}
RetryConfig defines retry behavior for MCP operations
func DefaultRetryConfig ¶
func DefaultRetryConfig(description string) RetryConfig
DefaultRetryConfig returns a sensible default retry configuration
type SchemaBuilder ¶
type SchemaBuilder func(tool *Tool) (FunctionDefinition, error)
SchemaBuilder is a function that builds a function definition from a tool
type SchemaProperty ¶
type SchemaProperty interface {
// Property returns a representation of the schema property
Property() any
}
SchemaProperty is an interface representing generic schema properties
type ServerConfig ¶
type ServerConfig struct {
// Name is a friendly name for this MCP server
Name string `yaml:"name"`
// Command is the command to execute for stdio-based MCP servers
Command string `yaml:"command"`
// Args are the arguments to pass to the command
Args []string `yaml:"args,omitempty"`
// Env are the environment variables to set for the command
Env map[string]string `yaml:"env,omitempty"`
// URL is the URL for HTTP-based MCP servers
URL string `yaml:"url,omitempty"`
// Auth is the authentication configuration for HTTP-based MCP servers
Auth *AuthConfig `yaml:"auth,omitempty"`
// OAuthConfig is the OAuth configuration for HTTP-based MCP servers
OAuthConfig *OAuthConfig `yaml:"oauth,omitempty"`
// Timeout is the timeout in seconds for HTTP requests
Timeout int `yaml:"timeout,omitempty"`
// UseStreaming enables streaming HTTP for better performance
UseStreaming bool `yaml:"use_streaming,omitempty"`
// SkipVerify skips TLS certificate verification for HTTPS connections
SkipVerify bool `yaml:"skip_verify,omitempty"`
}
ServerConfig represents the configuration for a single MCP server
type ServerConnectionInfo ¶
type ServerConnectionInfo struct {
Name string
Command string
IsLegacy bool
IsConnected bool
AvailableTools []Tool
}
ServerConnectionInfo holds connection status for a single MCP server
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Server string `json:"server,omitempty"`
InputSchema *gollm.Schema `json:"inputSchema,omitempty"`
}
Tool represents an MCP tool with optional server information.
func (Tool) AsBasicTool ¶
AsBasicTool returns the tool without server information (for client.ListTools compatibility).
func (Tool) IsFromServer ¶
IsFromServer checks if the tool belongs to a specific server.
func (Tool) String ¶
String returns a human-readable representation of the tool.
Source Files
¶
- client.go
- config.go
- constants.go
- http_client.go
- interfaces.go
- manager.go
- stdio_client.go
- utils.go