feat: add uixt tool list_packages

This commit is contained in:
lilong.129
2025-05-21 16:24:54 +08:00
parent 044eb07a35
commit 495443a2c4
7 changed files with 49 additions and 1 deletions

View File

@@ -1 +1 @@
v5.0.0-beta-2505202311 v5.0.0-beta-2505211624

View File

@@ -101,6 +101,14 @@ func (ums *MCPServer4XTDriver) addTools() {
ums.tools = append(ums.tools, selectDeviceTool) ums.tools = append(ums.tools, selectDeviceTool)
ums.handlerMap[selectDeviceTool.Name] = ums.handleSelectDevice ums.handlerMap[selectDeviceTool.Name] = ums.handleSelectDevice
// ListPackages Tool
listPackagesTool := mcp.NewTool("list_packages",
mcp.WithDescription("List all the apps/packages on the device."),
)
ums.mcpServer.AddTool(listPackagesTool, ums.handleListPackages)
ums.tools = append(ums.tools, listPackagesTool)
ums.handlerMap[listPackagesTool.Name] = ums.handleListPackages
// TapXY Tool // TapXY Tool
tapParams := append( tapParams := append(
[]mcp.ToolOption{mcp.WithDescription("Taps on the device screen at the given coordinates.")}, []mcp.ToolOption{mcp.WithDescription("Taps on the device screen at the given coordinates.")},
@@ -181,6 +189,20 @@ func (ums *MCPServer4XTDriver) handleSelectDevice(ctx context.Context, request m
return mcp.NewToolResultText(fmt.Sprintf("Selected device: %s", uuid)), nil return mcp.NewToolResultText(fmt.Sprintf("Selected device: %s", uuid)), nil
} }
// handleListPackages handles the list_packages tool call.
func (ums *MCPServer4XTDriver) handleListPackages(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
driverExt, err := ums.setupXTDriver(ctx, request.Params.Arguments)
if err != nil {
return nil, err
}
apps, err := driverExt.IDriver.GetDevice().ListPackages()
if err != nil {
return nil, err
}
return mcp.NewToolResultText(fmt.Sprintf("Device packages: %v", apps)), nil
}
// handleTapXY handles the tap_xy tool call. // handleTapXY handles the tap_xy tool call.
func (ums *MCPServer4XTDriver) handleTapXY(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { func (ums *MCPServer4XTDriver) handleTapXY(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
driverExt, err := ums.setupXTDriver(ctx, request.Params.Arguments) driverExt, err := ums.setupXTDriver(ctx, request.Params.Arguments)

View File

@@ -303,6 +303,10 @@ func (dev *AndroidDevice) GetCurrentWindow() (windowInfo types.WindowInfo, err e
return types.WindowInfo{}, errors.New("failed to extract current window") return types.WindowInfo{}, errors.New("failed to extract current window")
} }
func (dev *AndroidDevice) ListPackages() ([]string, error) {
return dev.Device.ListPackages()
}
func (dev *AndroidDevice) GetPackageInfo(packageName string) (types.AppInfo, error) { func (dev *AndroidDevice) GetPackageInfo(packageName string) (types.AppInfo, error) {
appInfo := types.AppInfo{ appInfo := types.AppInfo{
Name: packageName, Name: packageName,

View File

@@ -57,6 +57,10 @@ func (dev *BrowserDevice) Uninstall(packageName string) error {
return errors.New("not support") return errors.New("not support")
} }
func (dev *BrowserDevice) ListPackages() ([]string, error) {
return nil, errors.New("not support")
}
func (dev *BrowserDevice) GetPackageInfo(packageName string) (types.AppInfo, error) { func (dev *BrowserDevice) GetPackageInfo(packageName string) (types.AppInfo, error) {
return types.AppInfo{}, errors.New("not support") return types.AppInfo{}, errors.New("not support")
} }

View File

@@ -18,6 +18,8 @@ type IDevice interface {
Install(appPath string, opts ...option.InstallOption) error Install(appPath string, opts ...option.InstallOption) error
Uninstall(packageName string) error Uninstall(packageName string) error
ListPackages() ([]string, error)
GetPackageInfo(packageName string) (types.AppInfo, error) GetPackageInfo(packageName string) (types.AppInfo, error)
ScreenShot() (*bytes.Buffer, error) ScreenShot() (*bytes.Buffer, error)
// TODO: remove? // TODO: remove?

View File

@@ -95,6 +95,10 @@ func (dev *HarmonyDevice) Uninstall(packageName string) error {
return nil return nil
} }
func (dev *HarmonyDevice) ListPackages() ([]string, error) {
return nil, errors.New("not implemented")
}
func (dev *HarmonyDevice) GetPackageInfo(packageName string) (types.AppInfo, error) { func (dev *HarmonyDevice) GetPackageInfo(packageName string) (types.AppInfo, error) {
log.Warn().Msg("get package info not implemented for harmony device, skip") log.Warn().Msg("get package info not implemented for harmony device, skip")
return types.AppInfo{}, nil return types.AppInfo{}, nil

View File

@@ -317,6 +317,18 @@ func (dev *IOSDevice) GetDeviceInfo() (*DeviceDetail, error) {
return detail, err return detail, err
} }
func (dev *IOSDevice) ListPackages() ([]string, error) {
apps, err := dev.ListApps(ApplicationTypeAny)
if err != nil {
return nil, err
}
var packages []string
for _, app := range apps {
packages = append(packages, app.CFBundleIdentifier)
}
return packages, nil
}
func (dev *IOSDevice) ListApps(appType ApplicationType) (apps []installationproxy.AppInfo, err error) { func (dev *IOSDevice) ListApps(appType ApplicationType) (apps []installationproxy.AppInfo, err error) {
svc, _ := installationproxy.New(dev.DeviceEntry) svc, _ := installationproxy.New(dev.DeviceEntry)
defer svc.Close() defer svc.Close()