mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-26 01:51:29 +08:00
feat: add uixt tool list_available_devices
This commit is contained in:
@@ -1 +1 @@
|
||||
v5.0.0-beta-2505202236
|
||||
v5.0.0-beta-2505202258
|
||||
|
||||
@@ -9,7 +9,9 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/danielpaulus/go-ios/ios"
|
||||
"github.com/httprunner/httprunner/v5/internal/version"
|
||||
"github.com/httprunner/httprunner/v5/pkg/gadb"
|
||||
"github.com/httprunner/httprunner/v5/uixt"
|
||||
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||
"github.com/httprunner/httprunner/v5/uixt/types"
|
||||
@@ -81,6 +83,14 @@ func (s *MCPServer4XTDriver) Start() error {
|
||||
|
||||
// addTools registers all MCP tools.
|
||||
func (ums *MCPServer4XTDriver) addTools() {
|
||||
// ListAvailableDevices Tool
|
||||
listDevicesTool := mcp.NewTool("list_available_devices",
|
||||
mcp.WithDescription("List all available devices. If there are more than one device returned, you need to let the user select one of them."),
|
||||
)
|
||||
ums.mcpServer.AddTool(listDevicesTool, ums.handleListAvailableDevices)
|
||||
ums.tools = append(ums.tools, listDevicesTool)
|
||||
ums.handlerMap[listDevicesTool.Name] = ums.handleListAvailableDevices
|
||||
|
||||
// TapXY Tool
|
||||
tapParams := append(
|
||||
[]mcp.ToolOption{mcp.WithDescription("Taps on the device screen at the given coordinates.")},
|
||||
@@ -115,6 +125,41 @@ func (ums *MCPServer4XTDriver) addTools() {
|
||||
log.Info().Str("name", screenShotTool.Name).Msg("Register tool")
|
||||
}
|
||||
|
||||
// handleListAvailableDevices handles the list_available_devices tool call.
|
||||
func (ums *MCPServer4XTDriver) handleListAvailableDevices(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
deviceList := make(map[string][]string)
|
||||
if client, err := gadb.NewClient(); err == nil {
|
||||
if androidDevices, err := client.DeviceList(); err == nil {
|
||||
serialList := make([]string, 0, len(androidDevices))
|
||||
for _, device := range androidDevices {
|
||||
serialList = append(serialList, device.Serial())
|
||||
}
|
||||
deviceList["androidDevices"] = serialList
|
||||
}
|
||||
}
|
||||
if iosDevices, err := ios.ListDevices(); err == nil {
|
||||
serialList := make([]string, 0, len(iosDevices.DeviceList))
|
||||
for _, dev := range iosDevices.DeviceList {
|
||||
device, err := uixt.NewIOSDevice(
|
||||
option.WithUDID(dev.Properties.SerialNumber))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
properties := device.Properties
|
||||
err = ios.Pair(dev)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to pair device")
|
||||
continue
|
||||
}
|
||||
serialList = append(serialList, properties.SerialNumber)
|
||||
}
|
||||
deviceList["iosDevices"] = serialList
|
||||
}
|
||||
|
||||
jsonResult, _ := json.Marshal(deviceList)
|
||||
return mcp.NewToolResultText(string(jsonResult)), nil
|
||||
}
|
||||
|
||||
// handleTapXY handles the tap_xy tool call.
|
||||
func (ums *MCPServer4XTDriver) handleTapXY(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
driverExt, err := ums.setupXTDriver(ctx, request.Params.Arguments)
|
||||
|
||||
Reference in New Issue
Block a user