diff --git a/pkg/mcp/notify.go b/pkg/mcp/notify.go index 6ed9d78..9e46324 100644 --- a/pkg/mcp/notify.go +++ b/pkg/mcp/notify.go @@ -47,8 +47,11 @@ func (lw *lockedWriter) Close() error { return nil } // Created once when the MCP service enters stdio mode. var sharedStdout = &lockedWriter{w: os.Stdout} -const channelNotificationMethod = "notifications/claude/channel" -const loggingNotificationMethod = "notifications/message" +// Notification method names used by the MCP server. +const ( + ChannelNotificationMethod = "notifications/claude/channel" + LoggingNotificationMethod = "notifications/message" +) // Shared channel names. Keeping them central avoids drift between emitters // and the advertised claude/channel capability. @@ -171,7 +174,7 @@ func (s *Service) sendLoggingNotificationToSession(ctx context.Context, session } ctx = normalizeNotificationContext(ctx) - if err := sendSessionNotification(ctx, session, loggingNotificationMethod, &mcp.LoggingMessageParams{ + if err := sendSessionNotification(ctx, session, LoggingNotificationMethod, &mcp.LoggingMessageParams{ Level: level, Logger: logger, Data: data, @@ -209,7 +212,7 @@ func (s *Service) ChannelSendToSession(ctx context.Context, session *mcp.ServerS } ctx = normalizeNotificationContext(ctx) payload := ChannelNotification{Channel: channel, Data: data} - if err := sendSessionNotification(ctx, session, channelNotificationMethod, payload); err != nil { + if err := sendSessionNotification(ctx, session, ChannelNotificationMethod, payload); err != nil { s.debugNotify("channel: failed to send to session", "session", session.ID(), "error", err) } } @@ -239,7 +242,7 @@ func (s *Service) sendChannelNotificationToAllClients(ctx context.Context, paylo } ctx = normalizeNotificationContext(ctx) for session := range s.server.Sessions() { - if err := sendSessionNotification(ctx, session, channelNotificationMethod, payload); err != nil { + if err := sendSessionNotification(ctx, session, ChannelNotificationMethod, payload); err != nil { s.debugNotify("channel: failed to send to session", "session", session.ID(), "error", err) } } diff --git a/pkg/mcp/notify_test.go b/pkg/mcp/notify_test.go index 8b7cf3d..84b088c 100644 --- a/pkg/mcp/notify_test.go +++ b/pkg/mcp/notify_test.go @@ -162,7 +162,7 @@ func TestSendNotificationToAllClients_Good_CustomNotification(t *testing.T) { clientConn.SetDeadline(time.Now().Add(5 * time.Second)) read := readNotificationMessageUntil(t, clientConn, func(msg map[string]any) bool { - return msg["method"] == loggingNotificationMethod + return msg["method"] == LoggingNotificationMethod }) sent := make(chan struct{}) @@ -184,8 +184,8 @@ func TestSendNotificationToAllClients_Good_CustomNotification(t *testing.T) { t.Fatalf("failed to read notification: %v", res.err) } msg := res.msg - if msg["method"] != loggingNotificationMethod { - t.Fatalf("expected method %q, got %v", loggingNotificationMethod, msg["method"]) + if msg["method"] != LoggingNotificationMethod { + t.Fatalf("expected method %q, got %v", LoggingNotificationMethod, msg["method"]) } params, ok := msg["params"].(map[string]any) @@ -264,7 +264,7 @@ func TestChannelSendToSession_Good_CustomNotification(t *testing.T) { clientConn.SetDeadline(time.Now().Add(5 * time.Second)) read := readNotificationMessageUntil(t, clientConn, func(msg map[string]any) bool { - return msg["method"] == channelNotificationMethod + return msg["method"] == ChannelNotificationMethod }) sent := make(chan struct{}) @@ -286,8 +286,8 @@ func TestChannelSendToSession_Good_CustomNotification(t *testing.T) { t.Fatalf("failed to read custom notification: %v", res.err) } msg := res.msg - if msg["method"] != channelNotificationMethod { - t.Fatalf("expected method %q, got %v", channelNotificationMethod, msg["method"]) + if msg["method"] != ChannelNotificationMethod { + t.Fatalf("expected method %q, got %v", ChannelNotificationMethod, msg["method"]) } params, ok := msg["params"].(map[string]any) @@ -327,7 +327,7 @@ func TestChannelSendToClient_Good_CustomNotification(t *testing.T) { clientConn.SetDeadline(time.Now().Add(5 * time.Second)) read := readNotificationMessageUntil(t, clientConn, func(msg map[string]any) bool { - return msg["method"] == channelNotificationMethod + return msg["method"] == ChannelNotificationMethod }) sent := make(chan struct{}) @@ -349,8 +349,8 @@ func TestChannelSendToClient_Good_CustomNotification(t *testing.T) { t.Fatalf("failed to read custom notification: %v", res.err) } msg := res.msg - if msg["method"] != channelNotificationMethod { - t.Fatalf("expected method %q, got %v", channelNotificationMethod, msg["method"]) + if msg["method"] != ChannelNotificationMethod { + t.Fatalf("expected method %q, got %v", ChannelNotificationMethod, msg["method"]) } } @@ -375,7 +375,7 @@ func TestSendNotificationToClient_Good_CustomNotification(t *testing.T) { clientConn.SetDeadline(time.Now().Add(5 * time.Second)) read := readNotificationMessageUntil(t, clientConn, func(msg map[string]any) bool { - return msg["method"] == loggingNotificationMethod + return msg["method"] == LoggingNotificationMethod }) sent := make(chan struct{}) @@ -397,8 +397,8 @@ func TestSendNotificationToClient_Good_CustomNotification(t *testing.T) { t.Fatalf("failed to read notification: %v", res.err) } msg := res.msg - if msg["method"] != loggingNotificationMethod { - t.Fatalf("expected method %q, got %v", loggingNotificationMethod, msg["method"]) + if msg["method"] != LoggingNotificationMethod { + t.Fatalf("expected method %q, got %v", LoggingNotificationMethod, msg["method"]) } } @@ -512,8 +512,8 @@ func TestSendNotificationToAllClients_Good_BroadcastsToMultipleSessions(t *testi } for idx, res := range []notificationReadResult{res1, res2} { - if res.msg["method"] != loggingNotificationMethod { - t.Fatalf("session %d: expected method %q, got %v", idx+1, loggingNotificationMethod, res.msg["method"]) + if res.msg["method"] != LoggingNotificationMethod { + t.Fatalf("session %d: expected method %q, got %v", idx+1, LoggingNotificationMethod, res.msg["method"]) } params, ok := res.msg["params"].(map[string]any) diff --git a/pkg/mcp/register_test.go b/pkg/mcp/register_test.go index b130193..a1be4d8 100644 --- a/pkg/mcp/register_test.go +++ b/pkg/mcp/register_test.go @@ -116,7 +116,7 @@ func TestHandleIPCEvents_Good_ForwardsProcessActions(t *testing.T) { if !ok { t.Fatal("notification stream closed before expected message arrived") } - if msg["method"] != channelNotificationMethod { + if msg["method"] != ChannelNotificationMethod { continue } @@ -210,7 +210,7 @@ func TestHandleIPCEvents_Good_ForwardsProcessOutput(t *testing.T) { if !ok { t.Fatal("notification stream closed before expected message arrived") } - if msg["method"] != channelNotificationMethod { + if msg["method"] != ChannelNotificationMethod { continue } @@ -301,7 +301,7 @@ func TestHandleIPCEvents_Good_ForwardsTestResult(t *testing.T) { if !ok { t.Fatal("notification stream closed before expected message arrived") } - if msg["method"] != channelNotificationMethod { + if msg["method"] != ChannelNotificationMethod { continue }