diff --git a/pkg/mcp/mcp.go b/pkg/mcp/mcp.go index b5ae8a9..d6bee82 100644 --- a/pkg/mcp/mcp.go +++ b/pkg/mcp/mcp.go @@ -123,11 +123,8 @@ func New(opts Options) (*Service, error) { if sn, ok := sub.(SubsystemWithNotifier); ok { sn.SetNotifier(s) } - // Wire channel callback for subsystems that use func-based notification - type channelWirer interface { - OnChannel(func(ctx context.Context, channel string, data any)) - } - if cw, ok := sub.(channelWirer); ok { + // Wire channel callback for subsystems that use func-based notification. + if cw, ok := sub.(SubsystemWithChannelCallback); ok { svc := s // capture for closure cw.OnChannel(func(ctx context.Context, channel string, data any) { svc.ChannelSend(ctx, channel, data) diff --git a/pkg/mcp/subsystem.go b/pkg/mcp/subsystem.go index d643603..3a26ac6 100644 --- a/pkg/mcp/subsystem.go +++ b/pkg/mcp/subsystem.go @@ -63,3 +63,14 @@ type SubsystemWithNotifier interface { Subsystem SetNotifier(n Notifier) } + +// SubsystemWithChannelCallback extends Subsystem for implementations that +// expose an OnChannel callback instead of a Notifier interface. +// +// brain.OnChannel(func(ctx context.Context, channel string, data any) { +// mcpService.ChannelSend(ctx, channel, data) +// }) +type SubsystemWithChannelCallback interface { + Subsystem + OnChannel(func(ctx context.Context, channel string, data any)) +}