-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtool_bugreport.go
More file actions
54 lines (43 loc) · 1.32 KB
/
Copy pathtool_bugreport.go
File metadata and controls
54 lines (43 loc) · 1.32 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
//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"
)
const defaultBugreportPath = "/data/local/tmp/bugreport.zip"
func registerBugreport(s *server.MCPServer) {
tool := mcp.NewTool("bugreport",
mcp.WithDescription(
"Generate a bug report archive using 'bugreportz'. "+
"The report is saved to a file on the device. "+
"This operation can take several minutes.",
),
mcp.WithString("path",
mcp.Description("Output path on device (default: /data/local/tmp/bugreport.zip)"),
),
mcp.WithReadOnlyHintAnnotation(true),
mcp.WithDestructiveHintAnnotation(false),
mcp.WithIdempotentHintAnnotation(false),
)
s.AddTool(tool, handleBugreport)
}
func handleBugreport(
ctx context.Context,
request mcp.CallToolRequest,
) (*mcp.CallToolResult, error) {
logger.Tracef(ctx, "handleBugreport")
defer func() { logger.Tracef(ctx, "/handleBugreport") }()
path := request.GetString("path", defaultBugreportPath)
cmd := fmt.Sprintf("bugreportz -o %s", shellQuote(path))
out, err := shellExec(cmd)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("bugreport: %v", err)), nil
}
if out == "" {
out = fmt.Sprintf("bugreport saved to %s", path)
}
return mcp.NewToolResultText(out), nil
}