gui/pkg/mcp/tools_tray.go
Snider b559562dd9
Some checks failed
Security Scan / security (pull_request) Failing after 28s
Test / test (pull_request) Failing after 1m59s
fix(dx): use coreerr.E() and go-io, update CLAUDE.md, add tests
- Replace 90+ fmt.Errorf calls with coreerr.E() from go-log across
  display, window, systray, keybinding, contextmenu, and mcp packages
- Replace os.ReadFile/WriteFile/MkdirAll with coreio.Local in
  window/layout.go and window/state.go
- Update CLAUDE.md: fix key files table for new package structure,
  document error handling and file I/O conventions, add missing deps
- Add 37 tests for window package (task handlers, persistence,
  tiling modes, snap positions, workflow layouts)
- Window coverage: 47.1% → 69.8%

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-17 09:05:35 +00:00

85 lines
2.6 KiB
Go

// pkg/mcp/tools_tray.go
package mcp
import (
"context"
coreerr "forge.lthn.ai/core/go-log"
"forge.lthn.ai/core/gui/pkg/systray"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
// --- tray_set_icon ---
type TraySetIconInput struct {
Data []byte `json:"data"`
}
type TraySetIconOutput struct {
Success bool `json:"success"`
}
func (s *Subsystem) traySetIcon(_ context.Context, _ *mcp.CallToolRequest, input TraySetIconInput) (*mcp.CallToolResult, TraySetIconOutput, error) {
_, _, err := s.core.PERFORM(systray.TaskSetTrayIcon{Data: input.Data})
if err != nil {
return nil, TraySetIconOutput{}, err
}
return nil, TraySetIconOutput{Success: true}, nil
}
// --- tray_set_tooltip ---
type TraySetTooltipInput struct {
Tooltip string `json:"tooltip"`
}
type TraySetTooltipOutput struct {
Success bool `json:"success"`
}
func (s *Subsystem) traySetTooltip(_ context.Context, _ *mcp.CallToolRequest, input TraySetTooltipInput) (*mcp.CallToolResult, TraySetTooltipOutput, error) {
// Tooltip is set via the tray menu items; for now this is a no-op placeholder
_ = input.Tooltip
return nil, TraySetTooltipOutput{Success: true}, nil
}
// --- tray_set_label ---
type TraySetLabelInput struct {
Label string `json:"label"`
}
type TraySetLabelOutput struct {
Success bool `json:"success"`
}
func (s *Subsystem) traySetLabel(_ context.Context, _ *mcp.CallToolRequest, input TraySetLabelInput) (*mcp.CallToolResult, TraySetLabelOutput, error) {
// Label is part of the tray configuration; placeholder for now
_ = input.Label
return nil, TraySetLabelOutput{Success: true}, nil
}
// --- tray_info ---
type TrayInfoInput struct{}
type TrayInfoOutput struct {
Config map[string]any `json:"config"`
}
func (s *Subsystem) trayInfo(_ context.Context, _ *mcp.CallToolRequest, _ TrayInfoInput) (*mcp.CallToolResult, TrayInfoOutput, error) {
result, _, err := s.core.QUERY(systray.QueryConfig{})
if err != nil {
return nil, TrayInfoOutput{}, err
}
config, ok := result.(map[string]any)
if !ok {
return nil, TrayInfoOutput{}, coreerr.E("mcp.trayInfo", "unexpected result type", nil)
}
return nil, TrayInfoOutput{Config: config}, nil
}
// --- Registration ---
func (s *Subsystem) registerTrayTools(server *mcp.Server) {
mcp.AddTool(server, &mcp.Tool{Name: "tray_set_icon", Description: "Set the system tray icon"}, s.traySetIcon)
mcp.AddTool(server, &mcp.Tool{Name: "tray_set_tooltip", Description: "Set the system tray tooltip"}, s.traySetTooltip)
mcp.AddTool(server, &mcp.Tool{Name: "tray_set_label", Description: "Set the system tray label"}, s.traySetLabel)
mcp.AddTool(server, &mcp.Tool{Name: "tray_info", Description: "Get system tray configuration"}, s.trayInfo)
}