command

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: May 14, 2025 License: MIT Imports: 15 Imported by: 0

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

func (*RunnerExec) Run

func (r *RunnerExec) Run(ctx context.Context, shell string, command string, args []string, env []string, params map[string]interface{}) (string, error)

Run executes a command with the given shell and returns the output It implements the Runner interface

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

func (*RunnerFirejail) Run

func (r *RunnerFirejail) Run(ctx context.Context, shell string, command string, args []string, env []string, params map[string]interface{}) (string, error)

Run executes a command inside the firejail sandbox and returns the output It implements the Runner interface

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

func (*RunnerSandboxExec) Run

func (r *RunnerSandboxExec) Run(ctx context.Context, shell string, command string, args []string, env []string, params map[string]interface{}) (string, error)

Run executes a command inside the macOS sandbox and returns the output It implements the Runner interface

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"
)

Jump to

Keyboard shortcuts

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