mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 06:23:52 +08:00
feat: add mcp tool ToolGetForegroundApp
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2506081916
|
v5.0.0-beta-2506081925
|
||||||
|
|||||||
@@ -96,12 +96,13 @@ func (s *MCPServer4XTDriver) registerTools() {
|
|||||||
s.registerTool(&ToolBack{}) // Back
|
s.registerTool(&ToolBack{}) // Back
|
||||||
|
|
||||||
// App Tools
|
// App Tools
|
||||||
s.registerTool(&ToolListPackages{}) // ListPackages
|
s.registerTool(&ToolListPackages{}) // ListPackages
|
||||||
s.registerTool(&ToolLaunchApp{}) // LaunchApp
|
s.registerTool(&ToolLaunchApp{}) // LaunchApp
|
||||||
s.registerTool(&ToolTerminateApp{}) // TerminateApp
|
s.registerTool(&ToolTerminateApp{}) // TerminateApp
|
||||||
s.registerTool(&ToolAppInstall{}) // AppInstall
|
s.registerTool(&ToolAppInstall{}) // AppInstall
|
||||||
s.registerTool(&ToolAppUninstall{}) // AppUninstall
|
s.registerTool(&ToolAppUninstall{}) // AppUninstall
|
||||||
s.registerTool(&ToolAppClear{}) // AppClear
|
s.registerTool(&ToolAppClear{}) // AppClear
|
||||||
|
s.registerTool(&ToolGetForegroundApp{}) // GetForegroundApp
|
||||||
|
|
||||||
// Screen Tools
|
// Screen Tools
|
||||||
s.registerTool(&ToolScreenShot{})
|
s.registerTool(&ToolScreenShot{})
|
||||||
|
|||||||
@@ -340,3 +340,50 @@ func (t *ToolAppClear) ConvertActionToCallToolRequest(action option.MobileAction
|
|||||||
}
|
}
|
||||||
return mcp.CallToolRequest{}, fmt.Errorf("invalid app clear params: %v", action.Params)
|
return mcp.CallToolRequest{}, fmt.Errorf("invalid app clear params: %v", action.Params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToolGetForegroundApp implements the get_foreground_app tool call.
|
||||||
|
type ToolGetForegroundApp struct {
|
||||||
|
// Return data fields - these define the structure of data returned by this tool
|
||||||
|
PackageName string `json:"packageName" desc:"Package name of the foreground app"`
|
||||||
|
AppName string `json:"appName" desc:"Name of the foreground app"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *ToolGetForegroundApp) Name() option.ActionName {
|
||||||
|
return option.ACTION_GetForegroundApp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *ToolGetForegroundApp) Description() string {
|
||||||
|
return "Get information about the currently running foreground app"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *ToolGetForegroundApp) Options() []mcp.ToolOption {
|
||||||
|
unifiedReq := &option.ActionOptions{}
|
||||||
|
return unifiedReq.GetMCPOptions(option.ACTION_GetForegroundApp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *ToolGetForegroundApp) 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get foreground app info
|
||||||
|
appInfo, err := driverExt.ForegroundInfo()
|
||||||
|
if err != nil {
|
||||||
|
return NewMCPErrorResponse(fmt.Sprintf("Get foreground app failed: %s", err.Error())), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
message := fmt.Sprintf("Current foreground app: %s (%s)", appInfo.AppName, appInfo.PackageName)
|
||||||
|
returnData := ToolGetForegroundApp{
|
||||||
|
PackageName: appInfo.PackageName,
|
||||||
|
AppName: appInfo.AppName,
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewMCPSuccessResponse(message, &returnData), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *ToolGetForegroundApp) ConvertActionToCallToolRequest(action option.MobileAction) (mcp.CallToolRequest, error) {
|
||||||
|
return buildMCPCallToolRequest(t.Name(), map[string]any{}), nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -645,6 +645,9 @@ func (o *ActionOptions) validateActionSpecificFields(actionType ActionName) erro
|
|||||||
ACTION_AppInstall: func() error {
|
ACTION_AppInstall: func() error {
|
||||||
return o.requireFields("appUrl", o.AppUrl != "")
|
return o.requireFields("appUrl", o.AppUrl != "")
|
||||||
},
|
},
|
||||||
|
ACTION_GetForegroundApp: func() error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
ACTION_TapByOCR: func() error {
|
ACTION_TapByOCR: func() error {
|
||||||
return o.requireFields("text", o.Text != "")
|
return o.requireFields("text", o.Text != "")
|
||||||
},
|
},
|
||||||
@@ -752,6 +755,7 @@ func (o *ActionOptions) GetMCPOptions(actionType ActionName) []mcp.ToolOption {
|
|||||||
ACTION_AppInstall: {"platform", "serial", "appUrl", "packageName"},
|
ACTION_AppInstall: {"platform", "serial", "appUrl", "packageName"},
|
||||||
ACTION_AppUninstall: {"platform", "serial", "packageName"},
|
ACTION_AppUninstall: {"platform", "serial", "packageName"},
|
||||||
ACTION_AppClear: {"platform", "serial", "packageName"},
|
ACTION_AppClear: {"platform", "serial", "packageName"},
|
||||||
|
ACTION_GetForegroundApp: {"platform", "serial"},
|
||||||
ACTION_PressButton: {"platform", "serial", "button"},
|
ACTION_PressButton: {"platform", "serial", "button"},
|
||||||
ACTION_SwipeToTapApp: {"platform", "serial", "appName", "ignoreNotFoundError", "maxRetryTimes", "index"},
|
ACTION_SwipeToTapApp: {"platform", "serial", "appName", "ignoreNotFoundError", "maxRetryTimes", "index"},
|
||||||
ACTION_SwipeToTapText: {"platform", "serial", "text", "ignoreNotFoundError", "maxRetryTimes", "index", "regex"},
|
ACTION_SwipeToTapText: {"platform", "serial", "text", "ignoreNotFoundError", "maxRetryTimes", "index", "regex"},
|
||||||
|
|||||||
Reference in New Issue
Block a user