From 79570135003efb3c097b86e73fd92bb75949329e Mon Sep 17 00:00:00 2001 From: Snider Date: Tue, 24 Mar 2026 21:16:10 +0000 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20mcp.Register=20for=20core.WithServi?= =?UTF-8?q?ce=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) +} -- 2.45.3 From 4ae003e6d85381c3427b4195e0d607a1dafeb34a Mon Sep 17 00:00:00 2001 From: Snider Date: Tue, 24 Mar 2026 21:24:15 +0000 Subject: [PATCH 2/3] feat: MCP registers mcp/serve commands in OnStartup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Service stores Core ref, registers transport commands during lifecycle. Commands use Service methods directly — no external wiring. Co-Authored-By: Virgil --- pkg/mcp/mcp.go | 1 + pkg/mcp/register.go | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/pkg/mcp/mcp.go b/pkg/mcp/mcp.go index 114cf40..56f5fef 100644 --- a/pkg/mcp/mcp.go +++ b/pkg/mcp/mcp.go @@ -39,6 +39,7 @@ type Service struct { wsMu sync.Mutex // Protects wsServer and wsAddr stdioMode bool // True when running via stdio transport tools []ToolRecord // Parallel tool registry for REST bridge + coreRef any // *core.Core — stored by Register, used by OnStartup } // Options configures a Service. diff --git a/pkg/mcp/register.go b/pkg/mcp/register.go index c7a61a7..8616af6 100644 --- a/pkg/mcp/register.go +++ b/pkg/mcp/register.go @@ -6,11 +6,12 @@ import ( "context" core "dappco.re/go/core" + "forge.lthn.ai/core/go-log" ) // 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. +// Creates the MCP service, discovers subsystems from other Core services, +// and wires notifiers. // // core.New( // core.WithService(agentic.Register), @@ -38,13 +39,40 @@ func Register(c *core.Core) core.Result { return core.Result{Value: err, OK: false} } + svc.coreRef = c + 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. +// OnStartup implements core.Startable — registers MCP transport commands. func (s *Service) OnStartup(ctx context.Context) error { + c, ok := s.coreRef.(*core.Core) + if !ok || c == nil { + return nil + } + + c.Command("mcp", core.Command{ + Description: "Start the MCP server on stdio", + Action: func(opts core.Options) core.Result { + s.logger.Info("MCP stdio server starting") + if err := s.ServeStdio(ctx); err != nil { + return core.Result{Value: err, OK: false} + } + return core.Result{OK: true} + }, + }) + + c.Command("serve", core.Command{ + Description: "Start as a persistent HTTP daemon", + Action: func(opts core.Options) core.Result { + log.Default().Info("MCP HTTP server starting") + if err := s.Run(ctx); err != nil { + return core.Result{Value: err, OK: false} + } + return core.Result{OK: true} + }, + }) + return nil } -- 2.45.3 From 3d62d2f5315f277052e0a2da9d0b364c83f641a4 Mon Sep 17 00:00:00 2001 From: Snider Date: Tue, 24 Mar 2026 21:39:52 +0000 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20migrate=20module=20path=20forge.lth?= =?UTF-8?q?n.ai/core/mcp=20=E2=86=92=20dappco.re/go/mcp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Virgil --- cmd/core-mcp/main.go | 2 +- cmd/mcpcmd/cmd_mcp.go | 6 +++--- go.mod | 2 +- pkg/mcp/brain/brain.go | 2 +- pkg/mcp/brain/provider.go | 2 +- pkg/mcp/brain/tools.go | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/core-mcp/main.go b/cmd/core-mcp/main.go index 44aeaf4..157c4ba 100644 --- a/cmd/core-mcp/main.go +++ b/cmd/core-mcp/main.go @@ -2,7 +2,7 @@ package main import ( "forge.lthn.ai/core/cli/pkg/cli" - mcpcmd "forge.lthn.ai/core/mcp/cmd/mcpcmd" + mcpcmd "dappco.re/go/mcp/cmd/mcpcmd" ) func main() { diff --git a/cmd/mcpcmd/cmd_mcp.go b/cmd/mcpcmd/cmd_mcp.go index 3c2c1c0..866ce2e 100644 --- a/cmd/mcpcmd/cmd_mcp.go +++ b/cmd/mcpcmd/cmd_mcp.go @@ -11,9 +11,9 @@ import ( "syscall" "forge.lthn.ai/core/cli/pkg/cli" - "forge.lthn.ai/core/mcp/pkg/mcp" - "forge.lthn.ai/core/mcp/pkg/mcp/agentic" - "forge.lthn.ai/core/mcp/pkg/mcp/brain" + "dappco.re/go/mcp/pkg/mcp" + "dappco.re/go/mcp/pkg/mcp/agentic" + "dappco.re/go/mcp/pkg/mcp/brain" ) var workspaceFlag string diff --git a/go.mod b/go.mod index 8960f2b..224239a 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module forge.lthn.ai/core/mcp +module dappco.re/go/mcp go 1.26.0 diff --git a/pkg/mcp/brain/brain.go b/pkg/mcp/brain/brain.go index 1037d0a..97ef5b8 100644 --- a/pkg/mcp/brain/brain.go +++ b/pkg/mcp/brain/brain.go @@ -8,7 +8,7 @@ import ( "context" coreerr "forge.lthn.ai/core/go-log" - "forge.lthn.ai/core/mcp/pkg/mcp/ide" + "dappco.re/go/mcp/pkg/mcp/ide" "github.com/modelcontextprotocol/go-sdk/mcp" ) diff --git a/pkg/mcp/brain/provider.go b/pkg/mcp/brain/provider.go index 1a02cb1..170819f 100644 --- a/pkg/mcp/brain/provider.go +++ b/pkg/mcp/brain/provider.go @@ -8,7 +8,7 @@ import ( "forge.lthn.ai/core/api" "forge.lthn.ai/core/api/pkg/provider" "forge.lthn.ai/core/go-ws" - "forge.lthn.ai/core/mcp/pkg/mcp/ide" + "dappco.re/go/mcp/pkg/mcp/ide" "github.com/gin-gonic/gin" ) diff --git a/pkg/mcp/brain/tools.go b/pkg/mcp/brain/tools.go index f0d68b9..6ad0930 100644 --- a/pkg/mcp/brain/tools.go +++ b/pkg/mcp/brain/tools.go @@ -7,7 +7,7 @@ import ( "time" coreerr "forge.lthn.ai/core/go-log" - "forge.lthn.ai/core/mcp/pkg/mcp/ide" + "dappco.re/go/mcp/pkg/mcp/ide" "github.com/modelcontextprotocol/go-sdk/mcp" ) -- 2.45.3