-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtool_post_notification.go
More file actions
73 lines (61 loc) · 1.78 KB
/
tool_post_notification.go
File metadata and controls
73 lines (61 loc) · 1.78 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
//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 registerPostNotification(s *server.MCPServer) {
tool := mcp.NewTool("post_notification",
mcp.WithDescription(
"Post a notification using 'cmd notification post'. "+
"Creates a basic notification with the specified tag, title, and text.",
),
mcp.WithString("tag",
mcp.Required(),
mcp.Description("Notification tag (used as identifier)"),
),
mcp.WithString("title",
mcp.Required(),
mcp.Description("Notification title"),
),
mcp.WithString("text",
mcp.Required(),
mcp.Description("Notification body text"),
),
mcp.WithDestructiveHintAnnotation(true),
mcp.WithIdempotentHintAnnotation(true),
)
s.AddTool(tool, handlePostNotification)
}
func handlePostNotification(
ctx context.Context,
request mcp.CallToolRequest,
) (*mcp.CallToolResult, error) {
logger.Tracef(ctx, "handlePostNotification")
defer func() { logger.Tracef(ctx, "/handlePostNotification") }()
tag, err := request.RequireString("tag")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
title, err := request.RequireString("title")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
text, err := request.RequireString("text")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
cmd := fmt.Sprintf("cmd notification post -S bigtext -t %s %s %s",
shellQuote(title), shellQuote(tag), shellQuote(text))
out, err := shellExec(cmd)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("post notification: %v", err)), nil
}
if out == "" {
out = fmt.Sprintf("notification posted with tag %q", tag)
}
return mcp.NewToolResultText(out), nil
}