From 0928e675046fa5b4d4f2b030e7054cf91e864c41 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 2 Mar 2026 14:17:57 +0200 Subject: mcp: depend on SlashCommandSyncer interface instead of concrete type (task 410) --- internal/mcp/server.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'internal/mcp/server.go') diff --git a/internal/mcp/server.go b/internal/mcp/server.go index 83f75e8..17df79f 100644 --- a/internal/mcp/server.go +++ b/internal/mcp/server.go @@ -13,9 +13,15 @@ import ( "codeberg.org/snonux/hexai/internal" "codeberg.org/snonux/hexai/internal/promptstore" - "codeberg.org/snonux/hexai/internal/slashcommands" ) +// SlashCommandSyncer is the minimal sync contract the MCP server depends on. +type SlashCommandSyncer interface { + SyncCreate(prompt *promptstore.Prompt) error + SyncUpdate(prompt *promptstore.Prompt) error + Delete(promptName string) error +} + // Server implements an MCP server over stdio using JSON-RPC 2.0. // Follows the same pattern as the LSP server with dispatch table and thread safety. type Server struct { @@ -24,7 +30,7 @@ type Server struct { outMu sync.Mutex logger *log.Logger store promptstore.PromptStore - syncer *slashcommands.Syncer + syncer SlashCommandSyncer initialized bool mu sync.RWMutex @@ -34,7 +40,7 @@ type Server struct { // NewServer creates a new MCP server with the given store and I/O streams. // The store provides access to prompts; logger is used for debugging. -func NewServer(r io.Reader, w io.Writer, logger *log.Logger, store promptstore.PromptStore, syncer *slashcommands.Syncer) *Server { +func NewServer(r io.Reader, w io.Writer, logger *log.Logger, store promptstore.PromptStore, syncer SlashCommandSyncer) *Server { s := &Server{ in: bufio.NewReader(r), out: w, @@ -360,7 +366,7 @@ func (s *Server) handlePromptsCreate(req Request) { // Sync to slash commands if enabled if s.syncer != nil { - if err := s.syncer.Sync(prompt, slashcommands.OpCreate); err != nil { + if err := s.syncer.SyncCreate(prompt); err != nil { s.logger.Printf("slash command sync failed: %v", err) } } @@ -467,7 +473,7 @@ func (s *Server) handlePromptsUpdate(req Request) { // Sync to slash commands if enabled if s.syncer != nil { - if err := s.syncer.Sync(existing, slashcommands.OpUpdate); err != nil { + if err := s.syncer.SyncUpdate(existing); err != nil { s.logger.Printf("slash command sync failed: %v", err) } } @@ -742,7 +748,7 @@ func (s *Server) callCreatePromptTool(id any, args map[string]interface{}) { // Sync to slash commands if enabled if s.syncer != nil { - if err := s.syncer.Sync(prompt, slashcommands.OpCreate); err != nil { + if err := s.syncer.SyncCreate(prompt); err != nil { s.logger.Printf("slash command sync failed: %v", err) } } @@ -789,7 +795,7 @@ func (s *Server) callUpdatePromptTool(id any, args map[string]interface{}) { // Sync to slash commands if enabled if s.syncer != nil { - if err := s.syncer.Sync(existing, slashcommands.OpUpdate); err != nil { + if err := s.syncer.SyncUpdate(existing); err != nil { s.logger.Printf("slash command sync failed: %v", err) } } -- cgit v1.2.3