-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtool_query_content.go
More file actions
78 lines (66 loc) · 1.96 KB
/
Copy pathtool_query_content.go
File metadata and controls
78 lines (66 loc) · 1.96 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
//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 registerQueryContent(s *server.MCPServer) {
tool := mcp.NewTool("query_content",
mcp.WithDescription(
"Query a content provider URI using 'content query'. "+
"Returns rows from the specified content URI, optionally filtered by a WHERE clause.",
),
mcp.WithString("uri",
mcp.Required(),
mcp.Description("Content provider URI (e.g. content://settings/system)"),
),
mcp.WithString("projection",
mcp.Description("Columns to select (comma-separated, e.g. 'name:value')"),
),
mcp.WithString("where",
mcp.Description("WHERE clause (e.g. \"name='screen_brightness'\")"),
),
mcp.WithString("sort",
mcp.Description("ORDER BY clause"),
),
mcp.WithReadOnlyHintAnnotation(true),
mcp.WithDestructiveHintAnnotation(false),
mcp.WithIdempotentHintAnnotation(true),
)
s.AddTool(tool, handleQueryContent)
}
func handleQueryContent(
ctx context.Context,
request mcp.CallToolRequest,
) (*mcp.CallToolResult, error) {
logger.Tracef(ctx, "handleQueryContent")
defer func() { logger.Tracef(ctx, "/handleQueryContent") }()
uri, err := request.RequireString("uri")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
projection := request.GetString("projection", "")
where := request.GetString("where", "")
sort := request.GetString("sort", "")
cmd := fmt.Sprintf("content query --uri %s", shellQuote(uri))
if projection != "" {
cmd += fmt.Sprintf(" --projection %s", shellQuote(projection))
}
if where != "" {
cmd += fmt.Sprintf(" --where %s", shellQuote(where))
}
if sort != "" {
cmd += fmt.Sprintf(" --sort %s", shellQuote(sort))
}
out, err := shellExec(cmd)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("content query: %v", err)), nil
}
if out == "" {
out = "no results"
}
return mcp.NewToolResultText(out), nil
}