From 79570135003efb3c097b86e73fd92bb75949329e Mon Sep 17 00:00:00 2001 From: Snider Date: Tue, 24 Mar 2026 21:16:10 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20mcp.Register=20for=20core.WithService?= =?UTF-8?q?=20=E2=80=94=20auto-discovers=20subsystems=20from=20Core?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Virgil --- pkg/mcp/register.go | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 pkg/mcp/register.go diff --git a/pkg/mcp/register.go b/pkg/mcp/register.go new file mode 100644 index 0000000..c7a61a7 --- /dev/null +++ b/pkg/mcp/register.go @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: EUPL-1.2 + +package mcp + +import ( + "context" + + core "dappco.re/go/core" +) + +// Register is the service factory for core.WithService. +// Creates the MCP service, registers subsystems from other services +// already in the Core conclave, and wires notifiers. +// +// core.New( +// core.WithService(agentic.Register), +// core.WithService(monitor.Register), +// core.WithService(brain.Register), +// core.WithService(mcp.Register), +// ) +func Register(c *core.Core) core.Result { + // Collect subsystems from registered services + var subsystems []Subsystem + for _, name := range c.Services() { + r := c.Service(name) + if !r.OK { + continue + } + if sub, ok := r.Value.(Subsystem); ok { + subsystems = append(subsystems, sub) + } + } + + svc, err := New(Options{ + Subsystems: subsystems, + }) + if err != nil { + return core.Result{Value: err, OK: false} + } + + return core.Result{Value: svc, OK: true} +} + +// OnStartup implements core.Startable — MCP is ready for tool calls. +// Transport is NOT started here — the CLI command (mcp/serve) starts +// the appropriate transport explicitly. +func (s *Service) OnStartup(ctx context.Context) error { + return nil +} + +// OnShutdown implements core.Stoppable — stops the MCP transport. +func (s *Service) OnShutdown(ctx context.Context) error { + return s.Shutdown(ctx) +}