Documentation
¶
Overview ¶
Package command provides functions for creating and executing command handlers.
This package defines the core functionality for translating MCP tool calls into shell command executions, providing the bridge between the MCP protocol and the underlying operating system commands.
Package command provides functions for creating and executing command handlers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandHandler ¶
type CommandHandler struct {
// contains filtered or unexported fields
}
CommandHandler encapsulates the configuration and behavior needed to handle tool commands.
func NewCommandHandler ¶
func NewCommandHandler(tool config.Tool, params map[string]common.ParamConfig, shell string, logger *log.Logger) (*CommandHandler, error)
NewCommandHandler creates a new CommandHandler instance.
Parameters:
- tool: The tool definition containing command, constraints, and output configuration
- params: Map of parameter names to their type configurations
- shell: The shell to use for command execution
- logger: Logger for detailed execution information (required)
Returns:
- A new CommandHandler instance and nil if successful
- nil and an error if constraint compilation fails or if a required parameter is missing
func (*CommandHandler) ExecuteCommand ¶ added in v0.0.10
func (h *CommandHandler) ExecuteCommand(params map[string]interface{}) (string, error)
ExecuteCommand handles the direct execution of a command without going through the MCP server. This is used by the "exe" command to execute a tool directly from the command line.
Parameters:
- params: Map of parameter names to their values
Returns:
- The command output as a string
- An error if command execution fails
func (*CommandHandler) GetMCPHandler ¶
func (h *CommandHandler) GetMCPHandler() func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
GetMCPHandler returns a function that handles MCP tool calls by executing shell commands.
This is the function that should be registered with the MCP server.
Returns:
- A function that handles MCP tool calls
type Runner ¶
type Runner interface {
Run(ctx context.Context, shell string, command string, args []string, env []string, params map[string]interface{}) (string, error)
}
Runner is an interface for running commands
func NewRunner ¶
func NewRunner(runnerType RunnerType, options RunnerOptions, logger *log.Logger) (Runner, error)
NewRunner creates a new Runner based on the given type
type RunnerExec ¶
type RunnerExec struct {
// contains filtered or unexported fields
}
RunnerExec implements the Runner interface
func NewRunnerExec ¶
func NewRunnerExec(options RunnerOptions, logger *log.Logger) (*RunnerExec, error)
NewRunnerExec creates a new ExecRunner with the provided logger If logger is nil, a default logger is created
type RunnerExecOptions ¶
type RunnerExecOptions struct {
Shell string `json:"shell"`
}
RunnerExecOptions is the options for the RunnerExec
func NewRunnerExecOptions ¶
func NewRunnerExecOptions(options RunnerOptions) (RunnerExecOptions, error)
NewRunnerExecOptions creates a new RunnerExecOptions from a RunnerOptions
type RunnerFirejail ¶
type RunnerFirejail struct {
// contains filtered or unexported fields
}
RunnerFirejail implements the Runner interface using firejail on Linux
func NewRunnerFirejail ¶
func NewRunnerFirejail(options RunnerOptions, logger *log.Logger) (*RunnerFirejail, error)
NewRunnerFirejail creates a new RunnerFirejail with the provided logger If logger is nil, a default logger is created
type RunnerFirejailOptions ¶
type RunnerFirejailOptions struct {
Shell string `json:"shell"`
AllowNetworking bool `json:"allow_networking"`
AllowUserFolders bool `json:"allow_user_folders"`
AllowReadFolders []string `json:"allow_read_folders"`
AllowWriteFolders []string `json:"allow_write_folders"`
CustomProfile string `json:"custom_profile"`
}
RunnerFirejailOptions is the options for the RunnerFirejail
func NewRunnerFirejailOptions ¶
func NewRunnerFirejailOptions(options RunnerOptions) (RunnerFirejailOptions, error)
NewRunnerFirejailOptions creates a new RunnerFirejailOptions from a RunnerOptions
type RunnerOptions ¶
type RunnerOptions map[string]interface{}
RunnerOptions is a map of options for the runner
func (RunnerOptions) ToJSON ¶
func (ro RunnerOptions) ToJSON() (string, error)
type RunnerSandboxExec ¶
type RunnerSandboxExec struct {
// contains filtered or unexported fields
}
RunnerSandboxExec implements the Runner interface using macOS sandbox-exec
func NewRunnerSandboxExec ¶
func NewRunnerSandboxExec(options RunnerOptions, logger *log.Logger) (*RunnerSandboxExec, error)
NewRunnerSandboxExec creates a new RunnerSandboxExec with the provided logger If logger is nil, a default logger is created
type RunnerSandboxExecOptions ¶
type RunnerSandboxExecOptions struct {
Shell string `json:"shell"`
AllowNetworking bool `json:"allow_networking"`
AllowUserFolders bool `json:"allow_user_folders"`
AllowReadFolders []string `json:"allow_read_folders"`
AllowWriteFolders []string `json:"allow_write_folders"`
CustomProfile string `json:"custom_profile"`
}
RunnerSandboxExecOptions is the options for the RunnerSandboxExec
func NewRunnerSandboxExecOptions ¶
func NewRunnerSandboxExecOptions(options RunnerOptions) (RunnerSandboxExecOptions, error)
NewRunnerSandboxExecOptions creates a new RunnerSandboxExecOptions from a RunnerOptions
type RunnerType ¶
type RunnerType string
const ( RunnerTypeExec RunnerType = "exec" RunnerTypeSandboxExec RunnerType = "sandbox-exec" RunnerTypeFirejail RunnerType = "firejail" )