74 lines
2 KiB
Go
74 lines
2 KiB
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package mcp
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// Subsystem registers additional MCP tools at startup.
|
|
// Implementations should be safe to call concurrently.
|
|
//
|
|
// type BrainSubsystem struct{}
|
|
// func (b *BrainSubsystem) Name() string { return "brain" }
|
|
// func (b *BrainSubsystem) RegisterTools(svc *Service) { ... }
|
|
type Subsystem interface {
|
|
Name() string
|
|
RegisterTools(svc *Service)
|
|
}
|
|
|
|
// SubsystemWithShutdown extends Subsystem with graceful cleanup.
|
|
//
|
|
// func (b *BrainSubsystem) Shutdown(ctx context.Context) error {
|
|
// return b.client.Close()
|
|
// }
|
|
type SubsystemWithShutdown interface {
|
|
Subsystem
|
|
Shutdown(ctx context.Context) error
|
|
}
|
|
|
|
// Notifier pushes events to connected MCP sessions.
|
|
// Implemented by *Service. Sub-packages accept this interface
|
|
// to avoid circular imports.
|
|
//
|
|
// notifier.ChannelSend(ctx, "build.complete", data)
|
|
type Notifier interface {
|
|
ChannelSend(ctx context.Context, channel string, data any)
|
|
}
|
|
|
|
var _ Notifier = (*Service)(nil)
|
|
|
|
// ChannelPush is a Core IPC message that any service can send to push
|
|
// a channel event to connected Claude Code sessions.
|
|
// The MCP service catches this in HandleIPCEvents and calls ChannelSend.
|
|
//
|
|
// c.ACTION(mcp.ChannelPush{
|
|
// Channel: "agent.status",
|
|
// Data: map[string]any{"repo": "go-io"},
|
|
// })
|
|
type ChannelPush struct {
|
|
Channel string
|
|
Data any
|
|
}
|
|
|
|
// SubsystemWithNotifier extends Subsystem for those that emit channel events.
|
|
// SetNotifier is called after New() before any tool calls.
|
|
//
|
|
// func (m *MonitorSubsystem) SetNotifier(n mcp.Notifier) {
|
|
// m.notifier = n
|
|
// }
|
|
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))
|
|
}
|