config

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package config provides configuration loading and handling functionality.

It defines the data structures for representing the application's configuration, which is loaded from YAML files, and includes utilities for parsing and processing these configurations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMCPTool added in v0.0.10

func CreateMCPTool(config MCPToolConfig) mcp.Tool

CreateMCPTool creates an MCP tool from a tool configuration.

Parameters:

  • config: The tool configuration from which to create the MCP tool

Returns:

  • An mcp.Tool object ready to be registered with the MCP server

func ResolveConfigPath

func ResolveConfigPath(configPath string, logger *common.Logger) (string, func(), error)

ResolveConfigPath tries to resolve the configuration file path. If the path is a URL, it downloads the file to a temporary location. If the path is a directory, it returns all YAML files in that directory. The function returns the local path(s) to the configuration file(s) and a cleanup function that should be deferred to remove any temporary files.

func ResolveMultipleConfigPaths added in v0.1.6

func ResolveMultipleConfigPaths(configPaths []string, logger *common.Logger) (string, func(), error)

ResolveMultipleConfigPaths tries to resolve multiple configuration file paths. It handles each path individually (URLs, directories, local files) and then merges all configurations into a single temporary file. Returns the local path to the merged configuration file and a cleanup function.

Types

type MCPConfig

type MCPConfig struct {
	// Description is a text shown to AI clients that explains what this server does
	Description string `yaml:"description,omitempty"`

	// Run contains runtime configuration
	Run MCPRunConfig `yaml:"run,omitempty"`

	// Tools is a list of tool definitions that will be provided to clients
	Tools []MCPToolConfig `yaml:"tools"`
}

MCPConfig represents the MCP server configuration section.

type MCPRunConfig

type MCPRunConfig struct {
	// Shell is the shell to use for executing commands (e.g., bash, sh, zsh)
	Shell string `yaml:"shell,omitempty"`
}

MCPRunConfig represents run-specific configuration options.

type MCPToolConfig added in v0.0.14

type MCPToolConfig struct {
	// Name is the unique identifier for the tool
	Name string `yaml:"name"`

	// Description explains what the tool does (shown to AI clients)
	Description string `yaml:"description"`

	// Params defines the parameters that the tool accepts
	Params map[string]common.ParamConfig `yaml:"params"`

	// Constraints are expressions that limit when the tool can be executed
	Constraints []string `yaml:"constraints,omitempty"`

	// Run specifies how to execute the tool
	Run MCPToolRunConfig `yaml:"run"`

	// Output specifies how to format the tool's output
	Output common.OutputConfig `yaml:"output,omitempty"`
}

MCPToolConfig represents a single tool configuration.

type MCPToolRequirements added in v0.0.14

type MCPToolRequirements struct {
	// OS is the operating system that the prerequisite tool must be installed on
	OS string `yaml:"os,omitempty"`

	// Executables is a list of executable names that must be present in the system
	Executables []string `yaml:"executables"`
}

MCPToolRequirements represents a prerequisite tool configuration. If these prerequisites are not met, the tool will not even be shown as available to the client. This allows for tools to be conditionally shown based on the user's system.

type MCPToolRunConfig added in v0.0.14

type MCPToolRunConfig struct {
	// Command is a template for the shell command to execute
	Command string `yaml:"command"`

	// Env is a list of environment variable names to pass from the parent process
	Env []string `yaml:"env,omitempty"`

	// Runners is a list of possible runner configurations
	Runners []MCPToolRunner `yaml:"runners,omitempty"`
}

MCPToolRunConfig represents the run configuration for a tool.

type MCPToolRunner added in v0.1.0

type MCPToolRunner struct {
	// Name is the identifier for this runner (e.g., "osx", "linux")
	Name string `yaml:"name"`

	// Requirements are the prerequisites for this runner to be used
	Requirements MCPToolRequirements `yaml:"requirements,omitempty"`

	// Options for the runner
	Options map[string]interface{} `yaml:"options,omitempty"`
}

MCPToolRunner represents a specific execution environment for a tool.

type Tool

type Tool struct {
	// MCPTool is the MCP client-facing tool definition
	MCPTool mcp.Tool

	// Config is the original tool configuration
	Config MCPToolConfig

	// SelectedRunner is the runner that will be used to execute the tool command
	// This is set during validation when a suitable runner is found
	SelectedRunner *MCPToolRunner
}

Tool holds an MCP tool and its associated handling information.

func (*Tool) GetEffectiveCommand added in v0.1.0

func (t *Tool) GetEffectiveCommand() string

GetEffectiveCommand returns the command template that should be used. Since the command is now always defined at the MCPToolRunConfig level, we simply return it directly.

func (*Tool) GetEffectiveOptions added in v0.1.0

func (t *Tool) GetEffectiveOptions() map[string]interface{}

GetEffectiveOptions returns the runner options from the selected runner.

func (*Tool) GetEffectiveRunner added in v0.1.0

func (t *Tool) GetEffectiveRunner() string

GetEffectiveRunner returns the runner type that should be used.

type ToolsConfig added in v0.1.6

type ToolsConfig struct {
	// Prompts is a prompt configuration that will be provided to clients
	Prompts common.PromptsConfig `yaml:"prompts,omitempty"`

	// MCP contains the configuration specific to the MCP server and tools
	MCP MCPConfig `yaml:"mcp"`
}

ToolsConfig represents the top-level configuration structure for the application.

func LoadAndMergeConfigs added in v0.1.6

func LoadAndMergeConfigs(filepaths []string) (*ToolsConfig, error)

LoadAndMergeConfigs loads multiple configuration files and merges them into a single configuration. The merging strategy is: - Prompts are concatenated from all files - MCP description from the first file is used (others are ignored) - MCP run config from the first file is used (others are ignored) - Tools from all files are combined

Parameters:

  • filepaths: List of paths to YAML configuration files

Returns:

  • A pointer to the merged Config structure
  • An error if loading or merging fails

func NewConfigFromFile

func NewConfigFromFile(filepath string) (*ToolsConfig, error)

NewConfigFromFile loads the configuration from a YAML file at the specified path. The file path should already be resolved (use ResolveConfigPath for URL/directory resolution).

Parameters:

  • filepath: Path to the YAML configuration file (should be absolute and resolved)

Returns:

  • A pointer to the loaded Config structure
  • An error if loading or parsing fails

func (*ToolsConfig) GetTools added in v0.1.6

func (c *ToolsConfig) GetTools() []Tool

GetTools converts the configuration's tool definitions into a list of executable ToolDefinition objects ready to be registered with the MCP server.

Returns:

  • A slice of ToolDefinition objects

func (*ToolsConfig) ToYAML added in v0.1.6

func (c *ToolsConfig) ToYAML() ([]byte, error)

ToYAML serializes the configuration back to YAML format.

Returns:

  • YAML data as bytes
  • An error if serialization fails

Jump to

Keyboard shortcuts

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