-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtool_get_device_specs.go
More file actions
84 lines (73 loc) · 2.43 KB
/
tool_get_device_specs.go
File metadata and controls
84 lines (73 loc) · 2.43 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//go:build linux
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/facebookincubator/go-belt/tool/logger"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
)
// DeviceSpecs holds key device identification and version information.
type DeviceSpecs struct {
Model string `json:"model"`
Manufacturer string `json:"manufacturer"`
Brand string `json:"brand"`
Device string `json:"device"`
Product string `json:"product"`
SDKVersion string `json:"sdk_version"`
Release string `json:"android_version"`
BuildID string `json:"build_id"`
Fingerprint string `json:"fingerprint"`
Hardware string `json:"hardware"`
ABIs string `json:"supported_abis"`
SecurityPatch string `json:"security_patch"`
Serial string `json:"serial"`
}
func registerGetDeviceSpecs(s *server.MCPServer) {
tool := mcp.NewTool("get_device_specs",
mcp.WithDescription(
"Get structured device specifications: model, manufacturer, "+
"SDK version, Android version, build ID, hardware, ABIs, etc.",
),
mcp.WithReadOnlyHintAnnotation(true),
mcp.WithDestructiveHintAnnotation(false),
mcp.WithIdempotentHintAnnotation(true),
)
s.AddTool(tool, handleGetDeviceSpecs)
}
func handleGetDeviceSpecs(
ctx context.Context,
_ mcp.CallToolRequest,
) (*mcp.CallToolResult, error) {
logger.Tracef(ctx, "handleGetDeviceSpecs")
defer func() { logger.Tracef(ctx, "/handleGetDeviceSpecs") }()
specs := DeviceSpecs{
Model: getprop("ro.build.model"),
Manufacturer: getprop("ro.product.manufacturer"),
Brand: getprop("ro.product.brand"),
Device: getprop("ro.product.device"),
Product: getprop("ro.product.name"),
SDKVersion: getprop("ro.build.version.sdk"),
Release: getprop("ro.build.version.release"),
BuildID: getprop("ro.build.display.id"),
Fingerprint: getprop("ro.build.fingerprint"),
Hardware: getprop("ro.hardware"),
ABIs: getprop("ro.product.cpu.abilist"),
SecurityPatch: getprop("ro.build.version.security_patch"),
Serial: getprop("ro.serialno"),
}
data, err := json.Marshal(specs)
if err != nil {
return nil, fmt.Errorf("marshaling device specs: %w", err)
}
return mcp.NewToolResultText(string(data)), nil
}
// getprop reads a single Android system property.
func getprop(key string) string {
out, err := shellExec("getprop " + shellQuote(key))
if err != nil {
return ""
}
return out
}