Files
runtime/apps/cli/mcp/tools/delete_file.go
zeekay ea80dc3638 feat: Add new Dockerfiles and improve containerization
- Add main Dockerfile for production builds
- Add Dockerfile.runtime for secure code execution
- Add Dockerfile.runtime.fixed with improved configuration
- Include .dockerignore for build optimization
- Add integration documentation and publishing guides
- Update API and CLI components for better runtime support
- Enhance sandbox and container management features
2025-08-16 23:03:39 -05:00

56 lines
1.7 KiB
Go

// Copyright 2025 Hanzo Industries Inc.
// SPDX-License-Identifier: AGPL-3.0
package tools
import (
"context"
"fmt"
"github.com/hanzoai/apiclient"
apiclient_cli "github.com/hanzoai/runtime/cli/apiclient"
"github.com/mark3labs/mcp-go/mcp"
log "github.com/sirupsen/logrus"
)
type DeleteFileArgs struct {
Id *string `json:"id,omitempty"`
FilePath *string `json:"filePath,omitempty"`
}
func GetDeleteFileTool() mcp.Tool {
return mcp.NewTool("delete_file",
mcp.WithDescription("Delete a file or directory in the Runtime sandbox."),
mcp.WithString("filePath", mcp.Required(), mcp.Description("Path to the file or directory to delete.")),
mcp.WithString("id", mcp.Required(), mcp.Description("ID of the sandbox to delete the file in.")),
)
}
func DeleteFile(ctx context.Context, request mcp.CallToolRequest, args DeleteFileArgs) (*mcp.CallToolResult, error) {
apiClient, err := apiclient_cli.GetApiClient(nil, runtimeMCPHeaders)
if err != nil {
return &mcp.CallToolResult{IsError: true}, err
}
if args.Id == nil || *args.Id == "" {
return &mcp.CallToolResult{IsError: true}, fmt.Errorf("sandbox ID is required")
}
if args.FilePath == nil || *args.FilePath == "" {
return &mcp.CallToolResult{IsError: true}, fmt.Errorf("filePath parameter is required")
}
// Execute delete command
execResponse, _, err := apiClient.ToolboxAPI.ExecuteCommand(ctx, *args.Id).
ExecuteRequest(*apiclient.NewExecuteRequest(fmt.Sprintf("rm -rf %s", *args.FilePath))).
Execute()
if err != nil {
return &mcp.CallToolResult{IsError: true}, fmt.Errorf("error deleting file: %v", err)
}
log.Infof("Deleted file: %s", *args.FilePath)
return mcp.NewToolResultText(fmt.Sprintf("Deleted file: %s\nOutput: %s", *args.FilePath, execResponse.Result)), nil
}