-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtool_move_task_to_front.go
More file actions
59 lines (49 loc) · 1.44 KB
/
tool_move_task_to_front.go
File metadata and controls
59 lines (49 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//go:build linux
package main
import (
"context"
"fmt"
"github.com/facebookincubator/go-belt/tool/logger"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
)
func registerMoveTaskToFront(s *server.MCPServer) {
tool := mcp.NewTool("move_task_to_front",
mcp.WithDescription(
"Bring a task to the foreground using 'am task lock' or 'am stack movetask'. "+
"Requires the task ID (from list_recent_tasks).",
),
mcp.WithNumber("task_id",
mcp.Required(),
mcp.Description("Task ID to bring to front"),
),
mcp.WithDestructiveHintAnnotation(true),
mcp.WithIdempotentHintAnnotation(true),
)
s.AddTool(tool, handleMoveTaskToFront)
}
func handleMoveTaskToFront(
ctx context.Context,
request mcp.CallToolRequest,
) (*mcp.CallToolResult, error) {
logger.Tracef(ctx, "handleMoveTaskToFront")
defer func() { logger.Tracef(ctx, "/handleMoveTaskToFront") }()
taskID, err := request.RequireInt("task_id")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
cmd := fmt.Sprintf("am task lock %d", taskID)
out, err := shellExec(cmd)
if err != nil {
// Fallback: try am stack movetask.
fallbackCmd := fmt.Sprintf("am stack movetask %d 0", taskID)
out, err = shellExec(fallbackCmd)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("move task to front: %v", err)), nil
}
}
if out == "" {
out = fmt.Sprintf("task %d moved to front", taskID)
}
return mcp.NewToolResultText(out), nil
}