Files
go-cart-actor/pkg/order/mcp/mcp.go
T
mats aa8b2bdedc
Build and Publish / BuildAndDeployAmd64 (push) Failing after 5s
Build and Publish / BuildAndDeployArm64 (push) Failing after 6s
all the refactor
2026-06-28 17:51:52 +02:00

48 lines
1.6 KiB
Go

// Package mcp is the MCP edge for the order: a Model Context Protocol server
// exposing the order grain as tools so an agent can inspect order state and
// drive the order lifecycle (cancel, fulfill, complete, return, refund, etc.).
//
// Transport/dispatch and the schema/result helpers live in platform/mcp; this
// package only defines the order-specific tools and wires them to the grain
// pool. Mounted by cmd/order under /mcp.
package mcp
import (
"context"
"net/http"
"git.k6n.net/mats/go-cart-actor/pkg/actor"
"git.k6n.net/mats/go-cart-actor/pkg/order"
pmcp "git.k6n.net/mats/platform/mcp"
"google.golang.org/protobuf/proto"
)
const (
serverName = "orders"
serverVersion = "0.1.0"
)
// OrderApplier is the minimal grain-pool interface the order MCP needs: read an
// order's current state (Get) and apply a mutation (Apply). The
// SimpleGrainPool[order.OrderGrain] in cmd/order satisfies it directly.
type OrderApplier interface {
Get(ctx context.Context, id uint64) (*order.OrderGrain, error)
Apply(ctx context.Context, id uint64, mutation ...proto.Message) (*actor.MutationResult[order.OrderGrain], error)
}
// Server is the MCP edge over the order grain pool.
type Server struct {
applier OrderApplier
mcp *pmcp.Server
}
// New builds an MCP server exposing the order grain as tools.
func New(applier OrderApplier) *Server {
s := &Server{applier: applier}
s.mcp = pmcp.NewServer(pmcp.Info{Name: serverName, Version: serverVersion}, s.buildTools()...)
return s
}
// Handler returns the streamable-HTTP handler to mount (e.g. at /mcp).
func (s *Server) Handler() http.Handler { return s.mcp.Handler() }