gui/pkg/mcp/tools_notification.go
Claude 479537d12c
feat(gui): theme override, clipboard images, notifications, tray, layout helpers
Pass from codex implementing RFC spec gaps: theme_set IPC + state,
clipboard image read/write + MCP exposure, interactive notifications
and clearing, real tray tooltip/label/menu/message tasks, layout
heuristics (layout_suggest, layout_beside_editor, screen_find_space,
window_arrange_pair), dialog_message, focus_set, screen_work_area.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-14 14:18:05 +01:00

123 lines
4.7 KiB
Go

// pkg/mcp/tools_notification.go
package mcp
import (
"context"
coreerr "forge.lthn.ai/core/go-log"
"forge.lthn.ai/core/gui/pkg/notification"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
// --- notification_show ---
type NotificationShowInput struct {
Title string `json:"title"`
Message string `json:"message"`
Subtitle string `json:"subtitle,omitempty"`
}
type NotificationShowOutput struct {
Success bool `json:"success"`
}
func (s *Subsystem) notificationShow(_ context.Context, _ *mcp.CallToolRequest, input NotificationShowInput) (*mcp.CallToolResult, NotificationShowOutput, error) {
_, _, err := s.core.PERFORM(notification.TaskSend{Options: notification.NotificationOptions{
Title: input.Title,
Message: input.Message,
Subtitle: input.Subtitle,
}})
if err != nil {
return nil, NotificationShowOutput{}, err
}
return nil, NotificationShowOutput{Success: true}, nil
}
// --- notification_with_actions ---
type NotificationWithActionsInput struct {
Title string `json:"title"`
Message string `json:"message"`
Subtitle string `json:"subtitle,omitempty"`
Actions []notification.NotificationAction `json:"actions"`
}
type NotificationWithActionsOutput struct {
Success bool `json:"success"`
}
func (s *Subsystem) notificationWithActions(_ context.Context, _ *mcp.CallToolRequest, input NotificationWithActionsInput) (*mcp.CallToolResult, NotificationWithActionsOutput, error) {
_, _, err := s.core.PERFORM(notification.TaskSend{Options: notification.NotificationOptions{
Title: input.Title,
Message: input.Message,
Subtitle: input.Subtitle,
Actions: input.Actions,
}})
if err != nil {
return nil, NotificationWithActionsOutput{}, err
}
return nil, NotificationWithActionsOutput{Success: true}, nil
}
// --- notification_permission_request ---
type NotificationPermissionRequestInput struct{}
type NotificationPermissionRequestOutput struct {
Granted bool `json:"granted"`
}
func (s *Subsystem) notificationPermissionRequest(_ context.Context, _ *mcp.CallToolRequest, _ NotificationPermissionRequestInput) (*mcp.CallToolResult, NotificationPermissionRequestOutput, error) {
result, _, err := s.core.PERFORM(notification.TaskRequestPermission{})
if err != nil {
return nil, NotificationPermissionRequestOutput{}, err
}
granted, ok := result.(bool)
if !ok {
return nil, NotificationPermissionRequestOutput{}, coreerr.E("mcp.notificationPermissionRequest", "unexpected result type", nil)
}
return nil, NotificationPermissionRequestOutput{Granted: granted}, nil
}
// --- notification_permission_check ---
type NotificationPermissionCheckInput struct{}
type NotificationPermissionCheckOutput struct {
Granted bool `json:"granted"`
}
func (s *Subsystem) notificationPermissionCheck(_ context.Context, _ *mcp.CallToolRequest, _ NotificationPermissionCheckInput) (*mcp.CallToolResult, NotificationPermissionCheckOutput, error) {
result, _, err := s.core.QUERY(notification.QueryPermission{})
if err != nil {
return nil, NotificationPermissionCheckOutput{}, err
}
status, ok := result.(notification.PermissionStatus)
if !ok {
return nil, NotificationPermissionCheckOutput{}, coreerr.E("mcp.notificationPermissionCheck", "unexpected result type", nil)
}
return nil, NotificationPermissionCheckOutput{Granted: status.Granted}, nil
}
// --- notification_clear ---
type NotificationClearInput struct {
ID string `json:"id,omitempty"`
}
type NotificationClearOutput struct {
Success bool `json:"success"`
}
func (s *Subsystem) notificationClear(_ context.Context, _ *mcp.CallToolRequest, input NotificationClearInput) (*mcp.CallToolResult, NotificationClearOutput, error) {
_, _, err := s.core.PERFORM(notification.TaskClear{ID: input.ID})
if err != nil {
return nil, NotificationClearOutput{}, err
}
return nil, NotificationClearOutput{Success: true}, nil
}
// --- Registration ---
func (s *Subsystem) registerNotificationTools(server *mcp.Server) {
mcp.AddTool(server, &mcp.Tool{Name: "notification_show", Description: "Show a desktop notification"}, s.notificationShow)
mcp.AddTool(server, &mcp.Tool{Name: "notification_with_actions", Description: "Show a desktop notification with action buttons"}, s.notificationWithActions)
mcp.AddTool(server, &mcp.Tool{Name: "notification_permission_request", Description: "Request notification permission"}, s.notificationPermissionRequest)
mcp.AddTool(server, &mcp.Tool{Name: "notification_permission_check", Description: "Check notification permission status"}, s.notificationPermissionCheck)
mcp.AddTool(server, &mcp.Tool{Name: "notification_clear", Description: "Clear a notification by ID or clear all notifications"}, s.notificationClear)
}