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 *common.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