Skip to content

Commit 5bd00ad

Browse files
committed
feat: handle JSON marshal errors and add logging when queue is full
1 parent 8563a03 commit 5bd00ad

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

server/sse.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"log"
78
"net/http"
89
"net/http/httptest"
910
"net/url"
@@ -364,7 +365,11 @@ func (s *SSEServer) handleMessage(w http.ResponseWriter, r *http.Request) {
364365

365366
// Only send response if there is one (not for notifications)
366367
if response != nil {
367-
eventData, _ := json.Marshal(response)
368+
eventData, err := json.Marshal(response)
369+
if err != nil {
370+
s.writeJSONRPCError(w, nil, mcp.INTERNAL_ERROR, "Fail to marshal response")
371+
return
372+
}
368373

369374
// Queue the event for sending via SSE
370375
select {
@@ -373,7 +378,8 @@ func (s *SSEServer) handleMessage(w http.ResponseWriter, r *http.Request) {
373378
case <-session.done:
374379
// Session is closed, don't try to queue
375380
default:
376-
// Queue is full, could log this
381+
// Queue is full, log this situation
382+
log.Printf("Event queue full for session %s", sessionID)
377383
}
378384
}
379385
}()

0 commit comments

Comments
 (0)