common

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 13, 2025 License: MIT Imports: 12 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

func CheckExecutableExists

func CheckExecutableExists(executableName string) bool

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

func CheckOSMatches(requiredOS string) bool

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 ProcessTemplate

func ProcessTemplate(text string, args map[string]interface{}) (string, error)

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 ProcessTemplateListFlexible

func ProcessTemplateListFlexible(list []string, args map[string]interface{}) []string

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.

func SetLogger

func SetLogger(logger *Logger)

SetLogger sets the global application logger

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

const (
	// LogLevelNone disables logging
	LogLevelNone LogLevel = iota
	// LogLevelError logs only errors
	LogLevelError
	// LogLevelInfo logs information and errors
	LogLevelInfo
	// LogLevelDebug logs detailed debug information
	LogLevelDebug
)

func LogLevelFromString

func LogLevelFromString(level string) LogLevel

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

func NewLogger(prefix string, filePath string, level LogLevel, truncate bool) (*Logger, error)

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

func (*Logger) Close

func (l *Logger) Close() error

Close closes the log file if it's open

func (*Logger) Debug

func (l *Logger) Debug(format string, v ...interface{})

Debug logs a message at debug level

func (*Logger) Error

func (l *Logger) Error(format string, v ...interface{})

Error logs a message at error level

func (*Logger) FilePath

func (l *Logger) FilePath() string

FilePath returns the current log file path

func (*Logger) Info

func (l *Logger) Info(format string, v ...interface{})

Info logs a message at info level

func (*Logger) Level

func (l *Logger) Level() LogLevel

Level returns the current log level

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel)

SetLevel changes the current log level

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"`
}

ParamConfig defines the configuration for a single parameter in a tool.

Jump to

Keyboard shortcuts

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