mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-19 05:39:31 +08:00
- Move MobileAction struct from uixt package to uixt/option package - Delete uixt/driver_action.go file as MobileAction is now in option package - Update all import statements across the codebase to use option.MobileAction - Update ActionTool interface to use option.MobileAction in ConvertActionToCallToolRequest method - Maintain backward compatibility while improving package organization - Clean up code structure by consolidating action-related types in option package Files affected: - server/uixt.go: Updated imports and type references - step.go: Updated imports and ActionResult struct - step_ui.go: Updated all MobileAction references to option.MobileAction - uixt/mcp_server.go: Updated ActionTool interface and removed detailed comments - uixt/mcp_server_test.go: Updated all test cases to use option.MobileAction - uixt/mcp_tools_*.go: Updated ConvertActionToCallToolRequest method signatures - uixt/option/action.go: Added MobileAction struct definition - uixt/sdk.go: Updated ExecuteAction method signature
157 lines
4.6 KiB
Go
157 lines
4.6 KiB
Go
package uixt
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/httprunner/httprunner/v5/uixt/option"
|
|
"github.com/httprunner/httprunner/v5/uixt/types"
|
|
"github.com/mark3labs/mcp-go/mcp"
|
|
"github.com/mark3labs/mcp-go/server"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// ToolPressButton implements the press_button tool call.
|
|
type ToolPressButton struct{}
|
|
|
|
func (t *ToolPressButton) Name() option.ActionName {
|
|
return option.ACTION_PressButton
|
|
}
|
|
|
|
func (t *ToolPressButton) Description() string {
|
|
return "Press a button on the device"
|
|
}
|
|
|
|
func (t *ToolPressButton) Options() []mcp.ToolOption {
|
|
unifiedReq := &option.ActionOptions{}
|
|
return unifiedReq.GetMCPOptions(option.ACTION_PressButton)
|
|
}
|
|
|
|
func (t *ToolPressButton) Implement() server.ToolHandlerFunc {
|
|
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
driverExt, err := setupXTDriver(ctx, request.Params.Arguments)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("setup driver failed: %w", err)
|
|
}
|
|
|
|
unifiedReq, err := parseActionOptions(request.Params.Arguments)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Press button action logic
|
|
log.Info().Str("button", string(unifiedReq.Button)).Msg("pressing button")
|
|
err = driverExt.PressButton(types.DeviceButton(unifiedReq.Button))
|
|
if err != nil {
|
|
return mcp.NewToolResultError(fmt.Sprintf("Press button failed: %s", err.Error())), nil
|
|
}
|
|
|
|
return mcp.NewToolResultText(fmt.Sprintf("Successfully pressed button: %s", unifiedReq.Button)), nil
|
|
}
|
|
}
|
|
|
|
func (t *ToolPressButton) ConvertActionToCallToolRequest(action option.MobileAction) (mcp.CallToolRequest, error) {
|
|
if button, ok := action.Params.(string); ok {
|
|
arguments := map[string]any{
|
|
"button": button,
|
|
}
|
|
return buildMCPCallToolRequest(t.Name(), arguments), nil
|
|
}
|
|
return mcp.CallToolRequest{}, fmt.Errorf("invalid press button params: %v", action.Params)
|
|
}
|
|
|
|
func (t *ToolPressButton) ReturnSchema() map[string]string {
|
|
return map[string]string{
|
|
"message": "string: Success message confirming the button press operation",
|
|
"button": "string: Name of the button that was pressed",
|
|
}
|
|
}
|
|
|
|
// ToolHome implements the home tool call.
|
|
type ToolHome struct{}
|
|
|
|
func (t *ToolHome) Name() option.ActionName {
|
|
return option.ACTION_Home
|
|
}
|
|
|
|
func (t *ToolHome) Description() string {
|
|
return "Press the home button on the device"
|
|
}
|
|
|
|
func (t *ToolHome) Options() []mcp.ToolOption {
|
|
unifiedReq := &option.ActionOptions{}
|
|
return unifiedReq.GetMCPOptions(option.ACTION_Home)
|
|
}
|
|
|
|
func (t *ToolHome) Implement() server.ToolHandlerFunc {
|
|
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
driverExt, err := setupXTDriver(ctx, request.Params.Arguments)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("setup driver failed: %w", err)
|
|
}
|
|
|
|
// Home action logic
|
|
log.Info().Msg("pressing home button")
|
|
err = driverExt.Home()
|
|
if err != nil {
|
|
return mcp.NewToolResultError(fmt.Sprintf("Home button press failed: %s", err.Error())), nil
|
|
}
|
|
|
|
return mcp.NewToolResultText("Successfully pressed home button"), nil
|
|
}
|
|
}
|
|
|
|
func (t *ToolHome) ConvertActionToCallToolRequest(action option.MobileAction) (mcp.CallToolRequest, error) {
|
|
return buildMCPCallToolRequest(t.Name(), map[string]any{}), nil
|
|
}
|
|
|
|
func (t *ToolHome) ReturnSchema() map[string]string {
|
|
return map[string]string{
|
|
"message": "string: Success message confirming home button was pressed",
|
|
}
|
|
}
|
|
|
|
// ToolBack implements the back tool call.
|
|
type ToolBack struct{}
|
|
|
|
func (t *ToolBack) Name() option.ActionName {
|
|
return option.ACTION_Back
|
|
}
|
|
|
|
func (t *ToolBack) Description() string {
|
|
return "Press the back button on the device"
|
|
}
|
|
|
|
func (t *ToolBack) Options() []mcp.ToolOption {
|
|
unifiedReq := &option.ActionOptions{}
|
|
return unifiedReq.GetMCPOptions(option.ACTION_Back)
|
|
}
|
|
|
|
func (t *ToolBack) Implement() server.ToolHandlerFunc {
|
|
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
driverExt, err := setupXTDriver(ctx, request.Params.Arguments)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("setup driver failed: %w", err)
|
|
}
|
|
|
|
// Back action logic
|
|
log.Info().Msg("pressing back button")
|
|
err = driverExt.Back()
|
|
if err != nil {
|
|
return mcp.NewToolResultError(fmt.Sprintf("Back button press failed: %s", err.Error())), nil
|
|
}
|
|
|
|
return mcp.NewToolResultText("Successfully pressed back button"), nil
|
|
}
|
|
}
|
|
|
|
func (t *ToolBack) ConvertActionToCallToolRequest(action option.MobileAction) (mcp.CallToolRequest, error) {
|
|
return buildMCPCallToolRequest(t.Name(), map[string]any{}), nil
|
|
}
|
|
|
|
func (t *ToolBack) ReturnSchema() map[string]string {
|
|
return map[string]string{
|
|
"message": "string: Success message confirming back button was pressed",
|
|
}
|
|
}
|