mirror of
https://github.com/hanzoai/runtime.git
synced 2026-10-30 18:23:13 +00:00
- 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
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
// Copyright 2025 Hanzo Industries Inc.
|
|
// SPDX-License-Identifier: AGPL-3.0
|
|
|
|
package tools
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/hanzoai/runtime/cli/apiclient"
|
|
"github.com/mark3labs/mcp-go/mcp"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type ListFilesArgs struct {
|
|
Id *string `json:"id,omitempty"`
|
|
Path *string `json:"path,omitempty"`
|
|
}
|
|
|
|
func GetListFilesTool() mcp.Tool {
|
|
return mcp.NewTool("list_files",
|
|
mcp.WithDescription("List files in a directory in the Runtime sandbox."),
|
|
mcp.WithString("path", mcp.Description("Path to the directory to list files from (defaults to current directory).")),
|
|
mcp.WithString("id", mcp.Required(), mcp.Description("ID of the sandbox to list the files from.")),
|
|
)
|
|
}
|
|
|
|
func ListFiles(ctx context.Context, request mcp.CallToolRequest, args ListFilesArgs) (*mcp.CallToolResult, error) {
|
|
apiClient, err := apiclient.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")
|
|
}
|
|
|
|
// Get directory path from request arguments (optional)
|
|
dirPath := "."
|
|
if args.Path != nil && *args.Path != "" {
|
|
dirPath = *args.Path
|
|
}
|
|
|
|
// List files
|
|
files, _, err := apiClient.ToolboxAPI.ListFiles(ctx, *args.Id).Path(dirPath).Execute()
|
|
if err != nil {
|
|
return &mcp.CallToolResult{IsError: true}, fmt.Errorf("error listing files: %v", err)
|
|
}
|
|
|
|
// Convert files to JSON
|
|
filesJSON, err := json.MarshalIndent(files, "", " ")
|
|
if err != nil {
|
|
return &mcp.CallToolResult{IsError: true}, fmt.Errorf("error marshaling files: %v", err)
|
|
}
|
|
|
|
log.Infof("Listed files in directory: %s", dirPath)
|
|
|
|
return mcp.NewToolResultText(string(filesJSON)), nil
|
|
}
|