From 555f9ec61426429ee71a0d86fd37a88c8eb1a85a Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 14:43:06 +0000 Subject: [PATCH] refactor(mcp): expose channel callback subsystem contract Make the func-based channel wiring contract explicit instead of relying on an anonymous interface inside New(). This keeps the extension point discoverable and aligned with the repository's AX-style API clarity. Co-Authored-By: Virgil --- pkg/mcp/mcp.go | 7 ++----- pkg/mcp/subsystem.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) 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)) +}