gui/pkg/mcp/tools_keybinding.go
Claude 18a455b460
Some checks failed
Security Scan / security (push) Failing after 25s
refactor: migrate entire gui to Core v0.8.0 API
- 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>
2026-03-31 16:14:19 +01:00

62 lines
2 KiB
Go

// pkg/mcp/tools_keybinding.go
package mcp
import (
"context"
core "dappco.re/go/core"
"forge.lthn.ai/core/gui/pkg/keybinding"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
// --- keybinding_add ---
type KeybindingAddInput struct {
Accelerator string `json:"accelerator"`
Description string `json:"description,omitempty"`
}
type KeybindingAddOutput struct {
Success bool `json:"success"`
}
func (s *Subsystem) keybindingAdd(_ context.Context, _ *mcp.CallToolRequest, input KeybindingAddInput) (*mcp.CallToolResult, KeybindingAddOutput, error) {
r := s.core.Action("keybinding.add").Run(context.Background(), core.NewOptions(
core.Option{Key: "task", Value: keybinding.TaskAdd{Accelerator: input.Accelerator, Description: input.Description}},
))
if !r.OK {
if e, ok := r.Value.(error); ok {
return nil, KeybindingAddOutput{}, e
}
return nil, KeybindingAddOutput{}, nil
}
return nil, KeybindingAddOutput{Success: true}, nil
}
// --- keybinding_remove ---
type KeybindingRemoveInput struct {
Accelerator string `json:"accelerator"`
}
type KeybindingRemoveOutput struct {
Success bool `json:"success"`
}
func (s *Subsystem) keybindingRemove(_ context.Context, _ *mcp.CallToolRequest, input KeybindingRemoveInput) (*mcp.CallToolResult, KeybindingRemoveOutput, error) {
r := s.core.Action("keybinding.remove").Run(context.Background(), core.NewOptions(
core.Option{Key: "task", Value: keybinding.TaskRemove{Accelerator: input.Accelerator}},
))
if !r.OK {
if e, ok := r.Value.(error); ok {
return nil, KeybindingRemoveOutput{}, e
}
return nil, KeybindingRemoveOutput{}, nil
}
return nil, KeybindingRemoveOutput{Success: true}, nil
}
// --- Registration ---
func (s *Subsystem) registerKeybindingTools(server *mcp.Server) {
mcp.AddTool(server, &mcp.Tool{Name: "keybinding_add", Description: "Register a keyboard shortcut"}, s.keybindingAdd)
mcp.AddTool(server, &mcp.Tool{Name: "keybinding_remove", Description: "Unregister a keyboard shortcut"}, s.keybindingRemove)
}