summaryrefslogtreecommitdiff
path: root/internal/mcp/server.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-02 14:17:57 +0200
committerPaul Buetow <paul@buetow.org>2026-03-02 14:17:57 +0200
commit0928e675046fa5b4d4f2b030e7054cf91e864c41 (patch)
tree9f207876442ef3c0c7cf9517aa6072532f645ff8 /internal/mcp/server.go
parente3ca5e372ce41c5c916c6d833813299cd8a48afa (diff)
mcp: depend on SlashCommandSyncer interface instead of concrete type (task 410)
Diffstat (limited to 'internal/mcp/server.go')
-rw-r--r--internal/mcp/server.go20
1 files changed, 13 insertions, 7 deletions
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)
}
}