Some checks failed
Security Scan / security (push) Failing after 25s
- Import paths: forge.lthn.ai/core/go → dappco.re/go/core
- Import paths: forge.lthn.ai/core/go-log → dappco.re/go/core/log
- Import paths: forge.lthn.ai/core/go-io → dappco.re/go/core/io
- RegisterTask → c.Action("name", handler) across all 15 services
- QueryHandler signature: (any, bool, error) → core.Result
- PERFORM(task) → Action.Run(ctx, opts)
- QUERY returns single core.Result (not 3 values)
- All 17 packages build and test clean on v0.8.0-alpha.1
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
230 lines
7.5 KiB
Go
230 lines
7.5 KiB
Go
// pkg/mcp/tools_layout.go
|
|
package mcp
|
|
|
|
import (
|
|
"context"
|
|
|
|
core "dappco.re/go/core"
|
|
coreerr "dappco.re/go/core/log"
|
|
"forge.lthn.ai/core/gui/pkg/window"
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
// --- layout_save ---
|
|
|
|
type LayoutSaveInput struct {
|
|
Name string `json:"name"`
|
|
}
|
|
type LayoutSaveOutput struct {
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func (s *Subsystem) layoutSave(_ context.Context, _ *mcp.CallToolRequest, input LayoutSaveInput) (*mcp.CallToolResult, LayoutSaveOutput, error) {
|
|
r := s.core.Action("window.saveLayout").Run(context.Background(), core.NewOptions(
|
|
core.Option{Key: "task", Value: window.TaskSaveLayout{Name: input.Name}},
|
|
))
|
|
if !r.OK {
|
|
if e, ok := r.Value.(error); ok {
|
|
return nil, LayoutSaveOutput{}, e
|
|
}
|
|
return nil, LayoutSaveOutput{}, nil
|
|
}
|
|
return nil, LayoutSaveOutput{Success: true}, nil
|
|
}
|
|
|
|
// --- layout_restore ---
|
|
|
|
type LayoutRestoreInput struct {
|
|
Name string `json:"name"`
|
|
}
|
|
type LayoutRestoreOutput struct {
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func (s *Subsystem) layoutRestore(_ context.Context, _ *mcp.CallToolRequest, input LayoutRestoreInput) (*mcp.CallToolResult, LayoutRestoreOutput, error) {
|
|
r := s.core.Action("window.restoreLayout").Run(context.Background(), core.NewOptions(
|
|
core.Option{Key: "task", Value: window.TaskRestoreLayout{Name: input.Name}},
|
|
))
|
|
if !r.OK {
|
|
if e, ok := r.Value.(error); ok {
|
|
return nil, LayoutRestoreOutput{}, e
|
|
}
|
|
return nil, LayoutRestoreOutput{}, nil
|
|
}
|
|
return nil, LayoutRestoreOutput{Success: true}, nil
|
|
}
|
|
|
|
// --- layout_list ---
|
|
|
|
type LayoutListInput struct{}
|
|
type LayoutListOutput struct {
|
|
Layouts []window.LayoutInfo `json:"layouts"`
|
|
}
|
|
|
|
func (s *Subsystem) layoutList(_ context.Context, _ *mcp.CallToolRequest, _ LayoutListInput) (*mcp.CallToolResult, LayoutListOutput, error) {
|
|
r := s.core.QUERY(window.QueryLayoutList{})
|
|
if !r.OK {
|
|
if e, ok := r.Value.(error); ok {
|
|
return nil, LayoutListOutput{}, e
|
|
}
|
|
return nil, LayoutListOutput{}, nil
|
|
}
|
|
layouts, ok := r.Value.([]window.LayoutInfo)
|
|
if !ok {
|
|
return nil, LayoutListOutput{}, coreerr.E("mcp.layoutList", "unexpected result type", nil)
|
|
}
|
|
return nil, LayoutListOutput{Layouts: layouts}, nil
|
|
}
|
|
|
|
// --- layout_delete ---
|
|
|
|
type LayoutDeleteInput struct {
|
|
Name string `json:"name"`
|
|
}
|
|
type LayoutDeleteOutput struct {
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func (s *Subsystem) layoutDelete(_ context.Context, _ *mcp.CallToolRequest, input LayoutDeleteInput) (*mcp.CallToolResult, LayoutDeleteOutput, error) {
|
|
r := s.core.Action("window.deleteLayout").Run(context.Background(), core.NewOptions(
|
|
core.Option{Key: "task", Value: window.TaskDeleteLayout{Name: input.Name}},
|
|
))
|
|
if !r.OK {
|
|
if e, ok := r.Value.(error); ok {
|
|
return nil, LayoutDeleteOutput{}, e
|
|
}
|
|
return nil, LayoutDeleteOutput{}, nil
|
|
}
|
|
return nil, LayoutDeleteOutput{Success: true}, nil
|
|
}
|
|
|
|
// --- layout_get ---
|
|
|
|
type LayoutGetInput struct {
|
|
Name string `json:"name"`
|
|
}
|
|
type LayoutGetOutput struct {
|
|
Layout *window.Layout `json:"layout"`
|
|
}
|
|
|
|
func (s *Subsystem) layoutGet(_ context.Context, _ *mcp.CallToolRequest, input LayoutGetInput) (*mcp.CallToolResult, LayoutGetOutput, error) {
|
|
r := s.core.QUERY(window.QueryLayoutGet{Name: input.Name})
|
|
if !r.OK {
|
|
if e, ok := r.Value.(error); ok {
|
|
return nil, LayoutGetOutput{}, e
|
|
}
|
|
return nil, LayoutGetOutput{}, nil
|
|
}
|
|
layout, ok := r.Value.(*window.Layout)
|
|
if !ok {
|
|
return nil, LayoutGetOutput{}, coreerr.E("mcp.layoutGet", "unexpected result type", nil)
|
|
}
|
|
return nil, LayoutGetOutput{Layout: layout}, nil
|
|
}
|
|
|
|
// --- layout_tile ---
|
|
|
|
type LayoutTileInput struct {
|
|
Mode string `json:"mode"`
|
|
Windows []string `json:"windows,omitempty"`
|
|
}
|
|
type LayoutTileOutput struct {
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func (s *Subsystem) layoutTile(_ context.Context, _ *mcp.CallToolRequest, input LayoutTileInput) (*mcp.CallToolResult, LayoutTileOutput, error) {
|
|
r := s.core.Action("window.tileWindows").Run(context.Background(), core.NewOptions(
|
|
core.Option{Key: "task", Value: window.TaskTileWindows{Mode: input.Mode, Windows: input.Windows}},
|
|
))
|
|
if !r.OK {
|
|
if e, ok := r.Value.(error); ok {
|
|
return nil, LayoutTileOutput{}, e
|
|
}
|
|
return nil, LayoutTileOutput{}, nil
|
|
}
|
|
return nil, LayoutTileOutput{Success: true}, nil
|
|
}
|
|
|
|
// --- layout_snap ---
|
|
|
|
type LayoutSnapInput struct {
|
|
Name string `json:"name"`
|
|
Position string `json:"position"`
|
|
}
|
|
type LayoutSnapOutput struct {
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func (s *Subsystem) layoutSnap(_ context.Context, _ *mcp.CallToolRequest, input LayoutSnapInput) (*mcp.CallToolResult, LayoutSnapOutput, error) {
|
|
r := s.core.Action("window.snapWindow").Run(context.Background(), core.NewOptions(
|
|
core.Option{Key: "task", Value: window.TaskSnapWindow{Name: input.Name, Position: input.Position}},
|
|
))
|
|
if !r.OK {
|
|
if e, ok := r.Value.(error); ok {
|
|
return nil, LayoutSnapOutput{}, e
|
|
}
|
|
return nil, LayoutSnapOutput{}, nil
|
|
}
|
|
return nil, LayoutSnapOutput{Success: true}, nil
|
|
}
|
|
|
|
// --- layout_stack ---
|
|
|
|
type LayoutStackInput struct {
|
|
Windows []string `json:"windows,omitempty"`
|
|
OffsetX int `json:"offsetX"`
|
|
OffsetY int `json:"offsetY"`
|
|
}
|
|
type LayoutStackOutput struct {
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func (s *Subsystem) layoutStack(_ context.Context, _ *mcp.CallToolRequest, input LayoutStackInput) (*mcp.CallToolResult, LayoutStackOutput, error) {
|
|
r := s.core.Action("window.stackWindows").Run(context.Background(), core.NewOptions(
|
|
core.Option{Key: "task", Value: window.TaskStackWindows{Windows: input.Windows, OffsetX: input.OffsetX, OffsetY: input.OffsetY}},
|
|
))
|
|
if !r.OK {
|
|
if e, ok := r.Value.(error); ok {
|
|
return nil, LayoutStackOutput{}, e
|
|
}
|
|
return nil, LayoutStackOutput{}, nil
|
|
}
|
|
return nil, LayoutStackOutput{Success: true}, nil
|
|
}
|
|
|
|
// --- layout_workflow ---
|
|
|
|
type LayoutWorkflowInput struct {
|
|
Workflow string `json:"workflow"`
|
|
Windows []string `json:"windows,omitempty"`
|
|
}
|
|
type LayoutWorkflowOutput struct {
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func (s *Subsystem) layoutWorkflow(_ context.Context, _ *mcp.CallToolRequest, input LayoutWorkflowInput) (*mcp.CallToolResult, LayoutWorkflowOutput, error) {
|
|
r := s.core.Action("window.applyWorkflow").Run(context.Background(), core.NewOptions(
|
|
core.Option{Key: "task", Value: window.TaskApplyWorkflow{Workflow: input.Workflow, Windows: input.Windows}},
|
|
))
|
|
if !r.OK {
|
|
if e, ok := r.Value.(error); ok {
|
|
return nil, LayoutWorkflowOutput{}, e
|
|
}
|
|
return nil, LayoutWorkflowOutput{}, nil
|
|
}
|
|
return nil, LayoutWorkflowOutput{Success: true}, nil
|
|
}
|
|
|
|
// --- Registration ---
|
|
|
|
func (s *Subsystem) registerLayoutTools(server *mcp.Server) {
|
|
mcp.AddTool(server, &mcp.Tool{Name: "layout_save", Description: "Save the current window arrangement as a named layout"}, s.layoutSave)
|
|
mcp.AddTool(server, &mcp.Tool{Name: "layout_restore", Description: "Restore a saved window layout"}, s.layoutRestore)
|
|
mcp.AddTool(server, &mcp.Tool{Name: "layout_list", Description: "List all saved layouts"}, s.layoutList)
|
|
mcp.AddTool(server, &mcp.Tool{Name: "layout_delete", Description: "Delete a saved layout"}, s.layoutDelete)
|
|
mcp.AddTool(server, &mcp.Tool{Name: "layout_get", Description: "Get a specific layout by name"}, s.layoutGet)
|
|
mcp.AddTool(server, &mcp.Tool{Name: "layout_tile", Description: "Tile windows in a grid arrangement"}, s.layoutTile)
|
|
mcp.AddTool(server, &mcp.Tool{Name: "layout_snap", Description: "Snap a window to a screen edge or corner"}, s.layoutSnap)
|
|
mcp.AddTool(server, &mcp.Tool{Name: "layout_stack", Description: "Stack windows in a cascade pattern"}, s.layoutStack)
|
|
mcp.AddTool(server, &mcp.Tool{Name: "layout_workflow", Description: "Apply a preset workflow layout"}, s.layoutWorkflow)
|
|
}
|