From 66527165d05647dd151a678ea3faca0b20266e7e Mon Sep 17 00:00:00 2001 From: Snider Date: Thu, 26 Mar 2026 08:03:22 +0000 Subject: [PATCH] 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 --- pkg/mcp/mcp.go | 8 +++++++- pkg/mcp/register.go | 10 +++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/mcp/mcp.go b/pkg/mcp/mcp.go index 56f5fef..b619188 100644 --- a/pkg/mcp/mcp.go +++ b/pkg/mcp/mcp.go @@ -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{ diff --git a/pkg/mcp/register.go b/pkg/mcp/register.go index 062c71d..6b81d82 100644 --- a/pkg/mcp/register.go +++ b/pkg/mcp/register.go @@ -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} }