refactor(mcp): expose notification method constants
This commit is contained in:
parent
5edaa7ead1
commit
6e1a7d7d2a
3 changed files with 25 additions and 22 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue