-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtool_get_network_info.go
More file actions
47 lines (38 loc) · 1.12 KB
/
tool_get_network_info.go
File metadata and controls
47 lines (38 loc) · 1.12 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
//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 registerGetNetworkInfo(s *server.MCPServer) {
tool := mcp.NewTool("get_network_info",
mcp.WithDescription(
"Get active network connectivity information including network type, "+
"transport, and link properties from 'dumpsys connectivity'.",
),
mcp.WithReadOnlyHintAnnotation(true),
mcp.WithDestructiveHintAnnotation(false),
mcp.WithIdempotentHintAnnotation(true),
)
s.AddTool(tool, handleGetNetworkInfo)
}
func handleGetNetworkInfo(
ctx context.Context,
_ mcp.CallToolRequest,
) (*mcp.CallToolResult, error) {
logger.Tracef(ctx, "handleGetNetworkInfo")
defer func() { logger.Tracef(ctx, "/handleGetNetworkInfo") }()
out, err := shellExec("dumpsys connectivity | grep -A 5 'Active default network' | head -20")
if err != nil {
if out == "" {
return mcp.NewToolResultError(fmt.Sprintf("dumpsys connectivity: %v", err)), nil
}
}
if out == "" {
out = "no active network"
}
return mcp.NewToolResultText(out), nil
}