feat: add ServiceRuntime to MCP Service + use s.Core()

MCP Service now embeds *core.ServiceRuntime[McpOptions] like all v0.8.0
services. OnStartup uses s.Core() instead of casting coreRef.

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-03-26 08:03:22 +00:00
parent 96f46e53cb
commit 66527165d0
2 changed files with 14 additions and 4 deletions

View file

@ -14,6 +14,7 @@ import (
"strings"
"sync"
core "dappco.re/go/core"
"forge.lthn.ai/core/go-io"
"forge.lthn.ai/core/go-log"
"forge.lthn.ai/core/go-process"
@ -27,6 +28,8 @@ import (
// svc, err := mcp.New(mcp.Options{WorkspaceRoot: "/home/user/project"})
// defer svc.Shutdown(ctx)
type Service struct {
*core.ServiceRuntime[McpOptions] // Core access via s.Core()
server *mcp.Server
workspaceRoot string // Root directory for file operations (empty = unrestricted)
medium io.Medium // Filesystem medium for sandboxed operations
@ -39,9 +42,12 @@ 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
coreRef any // Deprecated: use s.Core() via ServiceRuntime
}
// McpOptions configures the MCP service runtime.
type McpOptions struct{}
// Options configures a Service.
//
// svc, err := mcp.New(mcp.Options{

View file

@ -39,15 +39,19 @@ func Register(c *core.Core) core.Result {
return core.Result{Value: err, OK: false}
}
svc.coreRef = c
svc.ServiceRuntime = core.NewServiceRuntime(c, McpOptions{})
svc.coreRef = c // kept until all methods migrate to s.Core()
return core.Result{Value: svc, OK: true}
}
// OnStartup implements core.Startable — registers MCP transport commands.
//
// core-agent mcp — start MCP server on stdio
// core-agent serve — start MCP server on HTTP
func (s *Service) OnStartup(ctx context.Context) core.Result {
c, ok := s.coreRef.(*core.Core)
if !ok || c == nil {
c := s.Core()
if c == nil {
return core.Result{OK: true}
}