gui/pkg/mcp/tools_notification.go
Claude 8d3c0fb6d2
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
feat(gui): implement chat-first UI and display primitives
- Replace provider dashboard with full chat UI (history, model selection, image attachments)
- Add chat settings/history/image queue/tool-call metadata persistence
- Add core://settings and core://store route handling in display package
- Add progressive assistant rendering, collapsible thinking/tool-call blocks
- Add markdown/code rendering with copy actions and lightbox image preview
- Add app mode detection (pkg/display/mode.go)
- Add chat backend coverage (pkg/display/chat_test.go)
- Add chat.service.ts frontend service
- AX sweep across pkg/mcp tools and pkg/window/webview/systray/notification

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

123 lines
4.7 KiB
Go

// pkg/mcp/tools_notification.go
package mcp
import (
"context"
"dappco.re/go/core/gui/pkg/notification"
coreerr "forge.lthn.ai/core/go-log"
"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)
}