-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtool_dump_service.go
More file actions
53 lines (44 loc) · 1.38 KB
/
tool_dump_service.go
File metadata and controls
53 lines (44 loc) · 1.38 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
//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 registerDumpService(s *server.MCPServer) {
tool := mcp.NewTool("dump_service",
mcp.WithDescription(
"Dump the state of an Android system service using 'dumpsys'. "+
"Returns the full text dump. Common services: activity, window, "+
"power, battery, wifi, connectivity, meminfo, cpuinfo, package, "+
"notification, alarm, audio, display, input.",
),
mcp.WithString("service",
mcp.Required(),
mcp.Description("Service name (e.g. 'activity', 'battery', 'meminfo')"),
),
mcp.WithReadOnlyHintAnnotation(true),
mcp.WithDestructiveHintAnnotation(false),
mcp.WithIdempotentHintAnnotation(true),
)
s.AddTool(tool, handleDumpService)
}
func handleDumpService(
ctx context.Context,
request mcp.CallToolRequest,
) (*mcp.CallToolResult, error) {
logger.Tracef(ctx, "handleDumpService")
defer func() { logger.Tracef(ctx, "/handleDumpService") }()
service, err := request.RequireString("service")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
cmd := fmt.Sprintf("dumpsys %s", shellQuote(service))
out, err := shellExec(cmd)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("dumpsys: %v", err)), nil
}
return mcp.NewToolResultText(out), nil
}