summaryrefslogtreecommitdiff
path: root/internal/mcp/server.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-23 09:04:17 +0200
committerPaul Buetow <paul@buetow.org>2026-03-23 09:04:17 +0200
commit462184dff3eef32f01f06634305da1355ac1bec2 (patch)
tree026ffaaeacfe152957298c985e1df77ff661b723 /internal/mcp/server.go
parent667f2d3384643aa877de2eefcbad3923965bad09 (diff)
chore: bump version to v0.25.9v0.25.9
Code quality fixes from audit: - Log silently discarded errors in status sinks and stats.Update call sites - Fix json.Marshal errors silently ignored in LSP handlers - Replace time.Sleep in tests with channel signaling (mcp) and fake clock (stats) - Make context cancellation work in production time.Sleep sites (handlers_document, cmdentry) - Remove init()-based provider registration from llm package; use explicit RegisterAllProviders() - Add WaitGroup goroutine tracking to MCP server Run() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/mcp/server.go')
-rw-r--r--internal/mcp/server.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/internal/mcp/server.go b/internal/mcp/server.go
index 645c0cf..f8042ac 100644
--- a/internal/mcp/server.go
+++ b/internal/mcp/server.go
@@ -32,6 +32,7 @@ type Server struct {
syncer SlashCommandSyncer
initialized bool
mu sync.RWMutex
+ inflight sync.WaitGroup // tracks handler goroutines; Run waits before returning
// Dispatch table for JSON-RPC methods
handlers map[string]func(Request)
@@ -66,14 +67,16 @@ func NewServer(r io.Reader, w io.Writer, logger *log.Logger, store promptstore.P
}
// Run starts the server main loop, reading and dispatching requests.
-// Returns on EOF or fatal error.
+// Returns on EOF or fatal error, after waiting for all in-flight handlers.
func (s *Server) Run() error {
for {
body, err := s.readMessage()
if errors.Is(err, io.EOF) {
+ s.inflight.Wait() // drain handlers before signalling callers
return nil
}
if err != nil {
+ s.inflight.Wait()
return fmt.Errorf("read message: %w", err)
}
@@ -89,8 +92,12 @@ func (s *Server) Run() error {
continue
}
- // Dispatch request
- go s.handle(req)
+ // Dispatch request in a goroutine, tracked so Run can wait on completion.
+ s.inflight.Add(1)
+ go func(r Request) {
+ defer s.inflight.Done()
+ s.handle(r)
+ }(req)
}
}