mcpserver

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package mcpserver provides the MCP server for remote agent orchestration. It supports two backends: K8s+Redis (original) and OpenShell (new).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	CreateSandbox(ctx context.Context, opts SandboxOpts) (name string, err error)
	DeleteSandbox(ctx context.Context, name string) error
	ListSandboxes(ctx context.Context) ([]SandboxStatus, error)
	ExecStream(ctx context.Context, name string, command []string) (ExecResult, error)
	IdleCount(ctx context.Context) (int, error)
}

Backend abstracts the compute layer for sandbox lifecycle and task execution. Implementations: K8sBackend (Redis + K8s Deployments), compose.Backend (agent-compose).

type ExecResult

type ExecResult struct {
	ExitCode int
	Output   string
}

ExecResult holds the output of a completed exec.

type Journal

type Journal struct {
	// contains filtered or unexported fields
}

Journal appends task events to a JSONL file and replays on startup.

func NewJournal

func NewJournal(path string) (*Journal, error)

NewJournal opens or creates a JSONL task journal. Replays existing events to rebuild in-memory state.

func (*Journal) Close

func (j *Journal) Close() error

Close closes the journal file.

func (*Journal) Record

func (j *Journal) Record(ev TaskEvent) error

Record appends a task event to the journal file.

func (*Journal) Tasks

func (j *Journal) Tasks() map[string]*TaskState

Tasks returns a snapshot of all known task states.

type K8sBackend

type K8sBackend struct {
	// contains filtered or unexported fields
}

K8sBackend implements Backend using Redis + K8s Deployments. This is the original backend; it stays operational until the OpenShell backend proves the full workflow end-to-end.

func NewK8sBackend

func NewK8sBackend(cfg K8sConfig) (*K8sBackend, error)

NewK8sBackend creates a K8s backend from config.

func (*K8sBackend) CreateSandbox

func (b *K8sBackend) CreateSandbox(ctx context.Context, opts SandboxOpts) (string, error)

func (*K8sBackend) DeleteSandbox

func (b *K8sBackend) DeleteSandbox(ctx context.Context, name string) error

func (*K8sBackend) ExecStream

func (b *K8sBackend) ExecStream(_ context.Context, _ string, _ []string) (ExecResult, error)

func (*K8sBackend) IdleCount

func (b *K8sBackend) IdleCount(ctx context.Context) (int, error)

func (*K8sBackend) ListSandboxes

func (b *K8sBackend) ListSandboxes(ctx context.Context) ([]SandboxStatus, error)

func (*K8sBackend) Redis

func (b *K8sBackend) Redis() *redis.Client

Redis returns the underlying Redis client for task-level operations (createTask, getTask, etc.) that haven't been migrated to the journal yet.

func (*K8sBackend) TeamID

func (b *K8sBackend) TeamID() string

TeamID returns the team identifier for scoping Redis keys.

type K8sConfig

type K8sConfig struct {
	RedisURL   string
	Kubeconfig string
	Namespace  string
	TeamID     string
	MaxAgents  int
}

K8sConfig holds connection settings for the K8s+Redis backend.

type Options

type Options struct {
	// Backend selection: "openshell" or "k8s" (default: "k8s")
	Backend string
	// ExternalBackend allows the caller to inject a pre-built Backend,
	// avoiding import cycles. When set, Backend field is ignored.
	ExternalBackend Backend
	// OpenShell config (used when Backend=="openshell" and ExternalBackend is nil)
	GatewayEndpoint string
	GatewayInsecure bool
	OpenShellBinary string
	Image           string
	WarmPool        int
	// K8s config (backward compat)
	RedisURL   string
	Kubeconfig string
	Namespace  string
	TeamID     string
	// Coordination
	Coordinator coordination.Coordinator
	// Shared
	JournalPath string
	MaxAgents   int
	MaxCost     float64
	GithubToken string
	GithubRepo  string
}

Options configures the MCP server.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool manages a warm pool of pre-created sandboxes.

func NewPool

func NewPool(backend Backend, warmSize int) *Pool

NewPool creates a pool manager.

func (*Pool) EnsureCapacity

func (p *Pool) EnsureCapacity(ctx context.Context, count int) error

EnsureCapacity verifies at least count idle sandboxes exist.

func (*Pool) WarmUp

func (p *Pool) WarmUp(ctx context.Context) error

WarmUp pre-creates sandboxes to reach the warm pool size.

type PoolBackend

type PoolBackend interface {
	ClaimIdle() string
	Release(name string)
}

PoolBackend is an optional interface for backends that support idle pool management.

type SandboxOpts

type SandboxOpts struct {
	Image  string
	Mode   string // "worker" or "session"
	Env    map[string]string
	Labels map[string]string
	NoKeep bool
}

SandboxOpts configures a new sandbox.

type SandboxStatus

type SandboxStatus struct {
	Name   string
	Status string // "running", "ready", "stopped", "dead"
	Idle   bool
}

SandboxStatus describes a sandbox returned by ListSandboxes.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server holds all state for the MCP server.

func NewServer

func NewServer(opts Options) (*Server, error)

NewServer creates a Server with the configured backend.

func (*Server) Register

func (s *Server) Register(srv *mcplib.MCPServer)

Register warms the pool and adds the remote-agent tools to srv.

func (*Server) Serve

func (s *Server) Serve() error

Serve registers all MCP tools and starts the stdio server. Blocks until done.

type TaskEvent

type TaskEvent struct {
	TaskID    string `json:"task_id"`
	State     string `json:"state"`
	Prompt    string `json:"prompt,omitempty"`
	Provider  string `json:"provider,omitempty"`
	Sandbox   string `json:"sandbox,omitempty"`
	Result    string `json:"result,omitempty"`
	Error     string `json:"error,omitempty"`
	Timestamp string `json:"ts"`
}

TaskEvent is one line in the task journal.

type TaskResult

type TaskResult struct {
	Type         string `json:"type"`
	Summary      string `json:"summary"`
	FullText     string `json:"full_text,omitempty"`
	Branch       string `json:"branch,omitempty"`
	Commit       string `json:"commit,omitempty"`
	FilesChanged int    `json:"files_changed,omitempty"`
	Tokens       int    `json:"tokens_used,omitempty"`
	Duration     int    `json:"duration_seconds,omitempty"`
}

TaskResult is the structured JSON returned by task execution.

type TaskState

type TaskState struct {
	TaskID   string
	State    string
	Prompt   string
	Provider string
	Sandbox  string
	Result   string
	Error    string
}

TaskState is the latest known state of a task (collapsed from events).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL