-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtool_reboot_device.go
More file actions
63 lines (52 loc) · 1.46 KB
/
tool_reboot_device.go
File metadata and controls
63 lines (52 loc) · 1.46 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
60
61
62
63
//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 registerRebootDevice(s *server.MCPServer) {
tool := mcp.NewTool("reboot_device",
mcp.WithDescription(
"Reboot the Android device. Supports normal reboot, "+
"bootloader, and recovery modes via 'svc power reboot'.",
),
mcp.WithString("mode",
mcp.Description("Reboot mode: empty for normal, 'bootloader', or 'recovery'"),
mcp.Enum("", "bootloader", "recovery"),
),
mcp.WithDestructiveHintAnnotation(true),
mcp.WithIdempotentHintAnnotation(false),
)
s.AddTool(tool, handleRebootDevice)
}
func handleRebootDevice(
ctx context.Context,
request mcp.CallToolRequest,
) (*mcp.CallToolResult, error) {
logger.Tracef(ctx, "handleRebootDevice")
defer func() { logger.Tracef(ctx, "/handleRebootDevice") }()
mode := request.GetString("mode", "")
var cmd string
switch mode {
case "":
cmd = "svc power reboot"
case "bootloader", "recovery":
cmd = fmt.Sprintf("svc power reboot %s", mode)
default:
return mcp.NewToolResultError(fmt.Sprintf("unsupported reboot mode: %s", mode)), nil
}
out, err := shellExec(cmd)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("reboot: %v", err)), nil
}
if out == "" {
out = fmt.Sprintf("reboot initiated (mode: %s)", mode)
if mode == "" {
out = "reboot initiated"
}
}
return mcp.NewToolResultText(out), nil
}