Merge pull request 'feat: mcp.Register + module path dappco.re/go/mcp' (#15) from feat/core-service-pattern into dev

This commit is contained in:
Virgil 2026-03-24 22:10:00 +00:00
commit d02853cb6c
8 changed files with 91 additions and 8 deletions

View file

@ -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() {

View file

@ -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

2
go.mod
View file

@ -1,4 +1,4 @@
module forge.lthn.ai/core/mcp
module dappco.re/go/mcp
go 1.26.0

View file

@ -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"
)

View file

@ -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"
)

View file

@ -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"
)

View file

@ -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.

82
pkg/mcp/register.go Normal file
View file

@ -0,0 +1,82 @@
// SPDX-License-Identifier: EUPL-1.2
package mcp
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, discovers subsystems from other Core services,
// 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}
}
svc.coreRef = c
return core.Result{Value: svc, OK: true}
}
// 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
}
// OnShutdown implements core.Stoppable — stops the MCP transport.
func (s *Service) OnShutdown(ctx context.Context) error {
return s.Shutdown(ctx)
}