Documentation
¶
Overview ¶
Package common provides shared utilities and types used across the MCPShell.
Package common provides shared utilities and types used across the MCPShell.
Package common provides utility functions and shared components.
Package common provides shared utilities and types used across the MCPShell.
Index ¶
- Constants
- Variables
- func CheckExecutableExists(executableName string) bool
- func CheckOSMatches(requiredOS string) bool
- func ConvertStringToType(value string, paramType string) (interface{}, error)
- func FetchURLText(url string) ([]byte, error)
- func ProcessTemplate(text string, args map[string]interface{}) (string, error)
- func ProcessTemplateListFlexible(list []string, args map[string]interface{}) []string
- func RecoverPanic() bool
- func SetLogger(logger *Logger)
- type CompiledConstraints
- type LogLevel
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Debug(format string, v ...interface{})
- func (l *Logger) Error(format string, v ...interface{})
- func (l *Logger) FilePath() string
- func (l *Logger) Info(format string, v ...interface{})
- func (l *Logger) Level() LogLevel
- func (l *Logger) SetLevel(level LogLevel)
- type LoggingConfig
- type OutputConfig
- type ParamConfig
Constants ¶
const DownloadTimeout = 10 * time.Second
DownloadTimeout is the timeout for downloading content from a URL
Variables ¶
var SupportedContentTypes = []string{
"text/",
"application/json",
"application/xml",
"application/yaml",
"application/x-yaml",
"application/javascript",
"application/ecmascript",
"application/markdown",
"application/x-markdown",
}
List of supported text content types
Functions ¶
func CheckExecutableExists ¶
CheckExecutableExists checks if a command is available in the system PATH.
Parameters:
- executableName: The name of the executable to check
Returns:
- true if the executable exists and is accessible, false otherwise
func CheckOSMatches ¶
CheckOSMatches checks if the current operating system matches the required OS.
Parameters:
- requiredOS: The required operating system (e.g., "darwin", "linux", "windows") Can be empty to skip OS check.
Returns:
- true if the current OS matches the required OS or if requiredOS is empty, false otherwise
func ConvertStringToType ¶ added in v0.0.10
ConvertStringToType converts a string value to the appropriate type based on the parameter type. This is used when parsing command line arguments for direct tool execution.
Parameters:
- value: The string value to convert
- paramType: The parameter type ("string", "number", "integer", "boolean")
Returns:
- The converted value
- An error if the conversion fails
func FetchURLText ¶ added in v0.1.5
fetchURLContent downloads content from a URL and verifies it's a text format Returns the content as a byte slice if successful, or an error if download fails or if the content is not a supported text format.
func ProcessTemplate ¶
ProcessTemplate processes a template with the given arguments. It uses Go's template engine to substitute variables in the template.
Parameters:
- text: The template to process
- args: Map of variable names to their values
Returns:
- The processed template string with substituted variables
- An error if template processing fails
func RecoverPanic ¶
func RecoverPanic() bool
RecoverPanic recovers from a panic and logs it to the provided logger. It returns true if a panic was recovered, false otherwise.
This function should be used in deferred calls to catch panics.
Types ¶
type CompiledConstraints ¶
type CompiledConstraints struct {
// contains filtered or unexported fields
}
CompiledConstraints holds the compiled CEL programs for a tool's constraints
func NewCompiledConstraints ¶
func NewCompiledConstraints(constraints []string, paramTypes map[string]ParamConfig, logger *log.Logger) (*CompiledConstraints, error)
NewCompiledConstraints compiles a list of CEL constraint expressions paramTypes is a map of parameter names to their types logger is required for logging constraint compilation and evaluation information
func (*CompiledConstraints) Evaluate ¶
func (cc *CompiledConstraints) Evaluate(args map[string]interface{}, params map[string]ParamConfig) (bool, []string, error)
Evaluate evaluates all compiled constraints against the provided arguments and returns details about which constraints failed.
Parameters:
- args: Map of argument names to their values
- paramTypes: Map of parameter names to their type configurations
Returns:
- true if all constraints pass, false otherwise
- slice of strings containing the failed constraint expressions
- error if evaluation fails or if a required parameter is missing
type LogLevel ¶
type LogLevel int
LogLevel represents logging verbosity levels
func LogLevelFromString ¶
LogLevelFromString converts a string representation to a LogLevel
type Logger ¶
type Logger struct {
// The underlying Go logger
*log.Logger
// contains filtered or unexported fields
}
Logger provides a structured logging interface for the application
func GetLogger ¶
func GetLogger() *Logger
GetLogger returns the global application logger. If the logger hasn't been initialized yet, it returns a default stderr logger.
func NewLogger ¶
NewLogger creates a new Logger instance
Parameters:
- prefix: The prefix for all log messages
- filePath: Path to the log file (empty string disables file logging)
- level: The logging verbosity level
- truncate: If true, truncate the log file; if false, append to it
Returns:
- A new Logger instance
- An error if the log file cannot be opened
type LoggingConfig ¶
type LoggingConfig struct {
// File is the path to the log file
File string
// Level sets the logging verbosity (e.g., "info", "debug", "error")
Level string `yaml:"level,omitempty"`
}
LoggingConfig defines configuration options for application logging.
type OutputConfig ¶
type OutputConfig struct {
// Prefix is a template string that gets prepended to the command output.
// It can use the same template variables as the command itself.
Prefix string `yaml:"prefix,omitempty"`
}
OutputConfig defines how tool output should be formatted before being returned.
type ParamConfig ¶
type ParamConfig struct {
// Type specifies the parameter data type. Valid values: "string" (default), "number"/"integer", "boolean"
Type string `yaml:"type,omitempty"`
// Description provides information about the parameter's purpose
Description string `yaml:"description"`
// Required indicates whether the parameter must be provided
Required bool `yaml:"required,omitempty"`
// Default specifies a default value to use when the parameter is not provided
Default interface{} `yaml:"default,omitempty"`
}
ParamConfig defines the configuration for a single parameter in a tool.