You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.3 KiB
92 lines
2.3 KiB
package mcp
|
|
|
|
import (
|
|
"context"
|
|
"yunyan/comm"
|
|
"yunyan/lego/core"
|
|
"yunyan/lego/core/cbase"
|
|
"yunyan/lego/sys/log"
|
|
"yunyan/lego/sys/mysql"
|
|
"yunyan/pb"
|
|
"yunyan/utils"
|
|
|
|
"github.com/mark3labs/mcp-go/mcp"
|
|
)
|
|
|
|
// 查询用户任务工具
|
|
type tool_get_user_tasks struct {
|
|
cbase.ModuleCompBase
|
|
module *Mcp
|
|
}
|
|
|
|
func (this *tool_get_user_tasks) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
|
this.ModuleCompBase.Init(service, module, comp, opt)
|
|
this.module = module.(*Mcp)
|
|
return
|
|
}
|
|
|
|
func (this *tool_get_user_tasks) Start() (err error) {
|
|
err = this.ModuleCompBase.Start()
|
|
this.module.AddTool(ToolGroup_GLOBAL, this.Tool(), this.Handl)
|
|
return
|
|
}
|
|
|
|
func (this *tool_get_user_tasks) Tool() mcp.Tool {
|
|
return mcp.NewTool("get_user_tasks",
|
|
mcp.WithDescription("查询用户的提醒任务列表,可以按状态筛选"),
|
|
mcp.WithString("uid",
|
|
mcp.Description("用户ID"),
|
|
mcp.Required(),
|
|
),
|
|
mcp.WithNumber("status",
|
|
mcp.Description("按状态筛选: -1=全部, 0=进行中, 2=已完成, 3=已取消"),
|
|
mcp.DefaultNumber(-1),
|
|
),
|
|
mcp.WithNumber("limit",
|
|
mcp.Description("返回数量限制 (默认20)"),
|
|
mcp.DefaultNumber(20),
|
|
),
|
|
)
|
|
}
|
|
|
|
func (this *tool_get_user_tasks) Handl(ctx context.Context, request mcp.CallToolRequest) (result *mcp.CallToolResult, err error) {
|
|
this.module.Debug("tool_get_user_tasks",
|
|
log.Field{Key: "request.Params.Arguments", Value: request.GetRawArguments()},
|
|
)
|
|
|
|
uid, err := request.RequireString("uid")
|
|
if err != nil {
|
|
return mcp.NewToolResultError("uid is required"), nil
|
|
}
|
|
status := request.GetInt("status", -1)
|
|
limit := request.GetInt("limit", 20)
|
|
if limit <= 0 || limit > 100 {
|
|
limit = 20
|
|
}
|
|
|
|
var tasks []*pb.DBTask
|
|
tx := mysql.Table(comm.TableAllhelpTask).Where("uid = ?", uid)
|
|
if status >= 0 {
|
|
tx = tx.Where("status = ?", status)
|
|
}
|
|
if dbErr := tx.Order("create_time DESC").Limit(limit).Find(&tasks).Error; dbErr != nil {
|
|
this.module.Errorln("get_user_tasks error:", dbErr)
|
|
return mcp.NewToolResultError("查询任务失败"), nil
|
|
}
|
|
|
|
text := utils.ToString(map[string]interface{}{
|
|
"result": "success",
|
|
"total": len(tasks),
|
|
"tasks": tasks,
|
|
})
|
|
|
|
result = &mcp.CallToolResult{
|
|
Content: []mcp.Content{
|
|
mcp.TextContent{
|
|
Type: "text",
|
|
Text: text,
|
|
},
|
|
},
|
|
}
|
|
return
|
|
}
|
|
|