mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-27 18:41:33 +08:00
feat: add mcp tool finished
This commit is contained in:
@@ -1 +1 @@
|
||||
v5.0.0-beta-2505260849
|
||||
v5.0.0-beta-2505260905
|
||||
|
||||
@@ -142,7 +142,6 @@ func (s *MCPServer4XTDriver) registerTools() {
|
||||
s.registerTool(&ToolSetIme{})
|
||||
s.registerTool(&ToolGetSource{})
|
||||
s.registerTool(&ToolClosePopups{})
|
||||
s.registerTool(&ToolAIAction{})
|
||||
|
||||
// PC/Web actions
|
||||
s.registerTool(&ToolWebLoginNoneUI{})
|
||||
@@ -151,6 +150,10 @@ func (s *MCPServer4XTDriver) registerTools() {
|
||||
s.registerTool(&ToolTapBySelector{})
|
||||
s.registerTool(&ToolSecondaryClickBySelector{})
|
||||
s.registerTool(&ToolWebCloseTab{})
|
||||
|
||||
// LLM actions
|
||||
s.registerTool(&ToolAIAction{})
|
||||
s.registerTool(&ToolFinished{})
|
||||
}
|
||||
|
||||
func (s *MCPServer4XTDriver) registerTool(tool ActionTool) {
|
||||
@@ -2148,3 +2151,40 @@ func (t *ToolAIAction) ConvertActionToCallToolRequest(action MobileAction) (mcp.
|
||||
}
|
||||
return mcp.CallToolRequest{}, fmt.Errorf("invalid AI action params: %v", action.Params)
|
||||
}
|
||||
|
||||
// ToolFinished implements the finished tool call.
|
||||
type ToolFinished struct{}
|
||||
|
||||
func (t *ToolFinished) Name() option.ActionMethod {
|
||||
return option.ACTION_Finished
|
||||
}
|
||||
|
||||
func (t *ToolFinished) Description() string {
|
||||
return "Mark task as completed with a result message"
|
||||
}
|
||||
|
||||
func (t *ToolFinished) Options() []mcp.ToolOption {
|
||||
return option.NewMCPOptions(option.FinishedRequest{})
|
||||
}
|
||||
|
||||
func (t *ToolFinished) Implement() server.ToolHandlerFunc {
|
||||
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
var finishedReq option.FinishedRequest
|
||||
if err := mapToStruct(request.Params.Arguments, &finishedReq); err != nil {
|
||||
return nil, fmt.Errorf("parse parameters error: %w", err)
|
||||
}
|
||||
log.Info().Str("reason", finishedReq.Content).Msg("task finished")
|
||||
|
||||
return mcp.NewToolResultText(fmt.Sprintf("Task completed: %s", finishedReq.Content)), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t *ToolFinished) ConvertActionToCallToolRequest(action MobileAction) (mcp.CallToolRequest, error) {
|
||||
if reason, ok := action.Params.(string); ok {
|
||||
arguments := map[string]any{
|
||||
"content": reason,
|
||||
}
|
||||
return buildMCPCallToolRequest(t.Name(), arguments), nil
|
||||
}
|
||||
return mcp.CallToolRequest{}, fmt.Errorf("invalid finished params: %v", action.Params)
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ const (
|
||||
ACTION_InstallApp ActionMethod = "install_app"
|
||||
ACTION_UninstallApp ActionMethod = "uninstall_app"
|
||||
ACTION_DownloadApp ActionMethod = "download_app"
|
||||
ACTION_Finished ActionMethod = "finished"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -195,6 +195,10 @@ type AIActionRequest struct {
|
||||
Prompt string `json:"prompt" binding:"required" desc:"AI action prompt"`
|
||||
}
|
||||
|
||||
type FinishedRequest struct {
|
||||
Content string `json:"content" binding:"required" desc:"Completion message for finished reason"`
|
||||
}
|
||||
|
||||
// NewMCPOptions generates mcp.NewTool parameters from a struct type.
|
||||
// It automatically generates mcp.NewTool parameters based on the struct fields and their desc tags.
|
||||
func NewMCPOptions(t interface{}) (options []mcp.ToolOption) {
|
||||
|
||||
Reference in New Issue
Block a user