Documentation
¶
Overview ¶
Package mcpserver implements `dol mcp`, the stdio MCP server agents use to acquire capacity (brief §8), and the Core it shares with the human CLI (`dol status`, `dol leases`, `dol release`).
Index ¶
- Constants
- func NewServer(core *Core) *mcp.Server
- func ProjectDir() string
- func ProjectName(dir string) string
- func RewriteKubeconfigServer(kubeconfig []byte, server string) ([]byte, error)
- func Run(ctx context.Context, core *Core) error
- type AcquireInput
- type CleanupReport
- type ComposeDownInput
- type ComposeUpInput
- type ComposeUpResult
- type Core
- func (c *Core) Acquire(ctx context.Context, in AcquireInput) (*v1.AcquireResult, error)
- func (c *Core) CleanupDeadSessions(ctx context.Context) CleanupReport
- func (c *Core) Close()
- func (c *Core) ComposeDown(ctx context.Context, in ComposeDownInput) (*v1.ActionResult, error)
- func (c *Core) ComposeUp(ctx context.Context, in ComposeUpInput) (*ComposeUpResult, error)
- func (c *Core) Forward(ctx context.Context, in ForwardInput) (*ForwardResult, error)
- func (c *Core) HeartbeatOnce(ctx context.Context) HeartbeatReport
- func (c *Core) KindCreate(ctx context.Context, in KindCreateInput) (*KindCreateResult, error)
- func (c *Core) KindDelete(ctx context.Context, in KindDeleteInput) (*v1.ActionResult, error)
- func (c *Core) KindLoad(ctx context.Context, in KindLoadInput) (*v1.ActionResult, error)
- func (c *Core) List(ctx context.Context, in ListInput) (*v1.ListResult, error)
- func (c *Core) LocalContext() string
- func (c *Core) Owner() string
- func (c *Core) Pin(ctx context.Context, in PinInput) (*v1.ActionResult, error)
- func (c *Core) Release(ctx context.Context, id string, keepSyncDir bool) (*v1.ReleaseResult, error)
- func (c *Core) Remove(ctx context.Context, in RemoveInput) (*v1.ActionResult, error)
- func (c *Core) Resize(ctx context.Context, in ResizeInput) (*v1.ActionResult, error)
- func (c *Core) Session() string
- func (c *Core) Start(ctx context.Context) error
- func (c *Core) Status(ctx context.Context, o StatusOptions) *v1.StatusResult
- func (c *Core) Stop(ctx context.Context, in TargetInput) (*v1.ActionResult, error)
- func (c *Core) Sync(ctx context.Context, in SyncInput) (*SyncResult, error)
- func (c *Core) Unforward(ctx context.Context, in UnforwardInput) (*v1.ActionResult, error)
- type Empty
- type ForwardInput
- type ForwardResult
- type Forwarder
- type HeartbeatReport
- type KindCreateInput
- type KindCreateResult
- type KindDeleteInput
- type KindLoadInput
- type ListInput
- type NodeAPI
- type Options
- type PinInput
- type ReleaseInput
- type RemoveInput
- type ResizeInput
- type StatusOptions
- type SyncInput
- type SyncResult
- type TargetInput
- type ToolError
- type UnforwardInput
- type WorkspaceAPI
Constants ¶
const Instructions = `` /* 888-byte string literal not displayed */
Instructions are sent to the client at initialization; they summarize rules/agent.md.
const ProxyDir = "proxy"
ProxyDir is the state subdirectory holding per-lease proxy sockets.
Variables ¶
This section is empty.
Functions ¶
func ProjectDir ¶
func ProjectDir() string
ProjectDir returns $CLAUDE_PROJECT_DIR (set by Claude Code for MCP servers, docs/compat.md §6) or the working directory.
func ProjectName ¶
ProjectName is the label-safe basename of dir.
func RewriteKubeconfigServer ¶
RewriteKubeconfigServer sets clusters[*].cluster.server, preserving the rest of the document.
Types ¶
type AcquireInput ¶
type AcquireInput struct {
Workload string `json:"workload" jsonschema:"what will run: container, compose, kind or build"`
EstMemoryGB float64 `json:"est_memory_gb" jsonschema:"total memory the workload will need in GB; estimate generously"`
EstDiskGB float64 `json:"est_disk_gb,omitempty" jsonschema:"disk the workload will need in GB (images, volumes); optional"`
Project string `json:"project,omitempty" jsonschema:"project label; defaults to the project directory name"`
Prefer string `json:"prefer,omitempty" jsonschema:"remote or local; overrides the configured preference"`
Pinned bool `json:"pinned,omitempty" jsonschema:"keep the lease after this session ends; only if the user asks"`
TTLMinutes int `json:"ttl_minutes,omitempty" jsonschema:"hard lifetime in minutes; 0 = node default"`
AllowWake bool `json:"allow_wake,omitempty" jsonschema:"allow Wake-on-LAN of a sleeping node (not implemented yet)"`
}
AcquireInput is the input of dol_acquire (brief §8).
type CleanupReport ¶
type CleanupReport struct {
DeadSessions []string
TornDown map[string]v1.Inventory // local lease → removed
Forgotten []string // remote lease records the node no longer has
Errors []string
}
CleanupReport says what CleanupDeadSessions did.
func (CleanupReport) String ¶
func (r CleanupReport) String() string
type ComposeDownInput ¶
type ComposeDownInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire"`
ProjectName string `json:"project_name" jsonschema:"compose project started with dol_compose_up"`
Volumes bool `json:"volumes,omitempty" jsonschema:"also remove the project's volumes"`
}
ComposeDownInput is the input of dol_compose_down.
type ComposeUpInput ¶
type ComposeUpInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire"`
Files []string `` /* 127-byte string literal not displayed */
ProjectName string `json:"project_name,omitempty" jsonschema:"compose project name; default the directory name"`
Sync *bool `json:"sync,omitempty" jsonschema:"sync the project directory to the node first (default true)"`
Detach *bool `json:"detach,omitempty" jsonschema:"run in the background (default true)"`
ExtraArgs []string `json:"extra_args,omitempty" jsonschema:"extra arguments for 'compose up', e.g. [\"--build\", \"--wait\", \"web\"]"`
AllowExternalMounts bool `json:"allow_external_mounts,omitempty" jsonschema:"keep bind mounts outside the project dir as node paths instead of failing"`
ProjectDir string `json:"project_dir,omitempty" jsonschema:"directory containing the compose files; default the project directory"`
}
ComposeUpInput is the input of dol_compose_up.
type ComposeUpResult ¶
type ComposeUpResult struct {
v1.PlacementInfo
Project string `json:"project"`
RenderedFile string `json:"rendered_file"`
RemoteDir string `json:"remote_dir,omitempty"`
Ports []compose.Port `json:"ports"`
Output string `json:"output"`
}
ComposeUpResult is the output of dol_compose_up.
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core is the client logic behind every MCP tool and CLI command.
func NewCore ¶
NewCore builds a Core. It resolves the local docker context (running `docker context ls/show` when local.docker_context is auto) but does not register a session or start background work; see Start.
func (*Core) Acquire ¶
func (c *Core) Acquire(ctx context.Context, in AcquireInput) (*v1.AcquireResult, error)
Acquire places a workload and records the lease.
func (*Core) CleanupDeadSessions ¶
func (c *Core) CleanupDeadSessions(ctx context.Context) CleanupReport
CleanupDeadSessions tears down LOCAL leases whose owning session is dead (PID gone or start time changed, or no session record), except pinned leases that have not reached their expiry. Remote lease records of dead sessions are only forgotten once the node confirms the lease is gone; the node's reaper owns remote cleanup.
func (*Core) Close ¶
func (c *Core) Close()
Close stops background work and child processes and unregisters the session. Remote leases are NOT released: the node's reaper removes them after heartbeat_grace_s unless they are pinned (ADR-0021). Local leases of this session are torn down by the next `dol mcp` that starts.
func (*Core) ComposeDown ¶
func (c *Core) ComposeDown(ctx context.Context, in ComposeDownInput) (*v1.ActionResult, error)
ComposeDown brings down a compose project registered on the lease.
func (*Core) ComposeUp ¶
func (c *Core) ComposeUp(ctx context.Context, in ComposeUpInput) (*ComposeUpResult, error)
ComposeUp renders, rewrites, labels, syncs and starts a compose project.
func (*Core) Forward ¶
func (c *Core) Forward(ctx context.Context, in ForwardInput) (*ForwardResult, error)
Forward opens an SSH tunnel localhost:<local> → node <remote_host>:<remote_port>.
func (*Core) HeartbeatOnce ¶
func (c *Core) HeartbeatOnce(ctx context.Context) HeartbeatReport
HeartbeatOnce heartbeats every active remote lease of this session, in parallel. 404/410 marks the lease lost; transport errors are logged and retried next round (a node that is briefly unreachable must not lose leases on the client side; the node's grace period decides).
func (*Core) KindCreate ¶
func (c *Core) KindCreate(ctx context.Context, in KindCreateInput) (*KindCreateResult, error)
KindCreate creates a kind cluster on the lease's host and writes a kubeconfig usable from this machine.
func (*Core) KindDelete ¶
func (c *Core) KindDelete(ctx context.Context, in KindDeleteInput) (*v1.ActionResult, error)
KindDelete deletes a kind cluster, its tunnel and kubeconfig.
func (*Core) KindLoad ¶
func (c *Core) KindLoad(ctx context.Context, in KindLoadInput) (*v1.ActionResult, error)
KindLoad loads images (present on the lease's host) into a kind cluster.
func (*Core) LocalContext ¶
LocalContext returns the docker context used for local placement.
func (*Core) Release ¶
Release tears down a lease (remote via the node, local via label-scoped docker commands), closes its forwards and deletes its kubeconfigs.
func (*Core) Remove ¶
func (c *Core) Remove(ctx context.Context, in RemoveInput) (*v1.ActionResult, error)
Remove removes an owned container/network/volume or brings down a registered compose project.
func (*Core) Resize ¶
func (c *Core) Resize(ctx context.Context, in ResizeInput) (*v1.ActionResult, error)
Resize changes a lease's memory estimate.
func (*Core) Start ¶
Start registers the session, cleans up local leases of dead sessions (in the background) and starts the heartbeat loop. Call Close when done.
func (*Core) Status ¶
func (c *Core) Status(ctx context.Context, o StatusOptions) *v1.StatusResult
Status checks every node (fresh health + capacity, in parallel, bounded by health_timeout_ms) and local Docker, and lists leases.
func (*Core) Stop ¶
func (c *Core) Stop(ctx context.Context, in TargetInput) (*v1.ActionResult, error)
Stop stops an owned container or registered compose project.
func (*Core) Unforward ¶
func (c *Core) Unforward(ctx context.Context, in UnforwardInput) (*v1.ActionResult, error)
Unforward closes a tunnel.
type ForwardInput ¶
type ForwardInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire"`
RemotePort int `json:"remote_port" jsonschema:"port the service is published on, on the node (e.g. 8080 for -p 127.0.0.1:8080:80)"`
LocalPort int `json:"local_port,omitempty" jsonschema:"preferred local port; default = remote_port, or a free one if busy"`
RemoteHost string `json:"remote_host,omitempty" jsonschema:"host as seen from the node; default 127.0.0.1"`
}
ForwardInput is the input of dol_forward.
type ForwardResult ¶
type ForwardResult struct {
v1.PlacementInfo
LocalPort int `json:"local_port"`
URL string `json:"url"`
}
ForwardResult is the output of dol_forward.
type Forwarder ¶
type Forwarder interface {
// CloseLease closes every forward of the lease and returns the local
// ports that were closed.
CloseLease(ctx context.Context, l v1.ClientLease) ([]int, error)
// CloseAll closes every forward owned by this process.
CloseAll()
}
Forwarder is the hook for SSH port forwards (internal/tunnel, milestone M4). Core calls it on release and on shutdown.
type HeartbeatReport ¶
type HeartbeatReport struct {
OK, Lost, Failed []string
}
HeartbeatReport says what one heartbeat round did.
type KindCreateInput ¶
type KindCreateInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire (workload kind)"`
Name string `json:"name" jsonschema:"short cluster name, e.g. e2e (lowercase, digits, -; max 16)"`
ConfigYAML string `` /* 126-byte string literal not displayed */
AccessMode string `json:"access_mode,omitempty" jsonschema:"tunnel (default, API server via ssh tunnel) or lan"`
}
KindCreateInput is the input of dol_kind_create.
type KindCreateResult ¶
type KindCreateResult struct {
v1.PlacementInfo
Cluster string `json:"cluster"`
Kubeconfig string `json:"kubeconfig"`
APIServer string `json:"api_server"`
AccessMode string `json:"access_mode"`
PortMappings []v1.PortMapping `json:"port_mappings"`
}
KindCreateResult is the output of dol_kind_create.
type KindDeleteInput ¶
type KindDeleteInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire"`
Cluster string `json:"cluster" jsonschema:"short cluster name given to dol_kind_create"`
}
KindDeleteInput is the input of dol_kind_delete.
type KindLoadInput ¶
type KindLoadInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire"`
Cluster string `json:"cluster" jsonschema:"short cluster name given to dol_kind_create"`
Images []string `json:"images" jsonschema:"image tags already built with the lease's docker prefix"`
}
KindLoadInput is the input of dol_kind_load.
type ListInput ¶
type ListInput struct {
LeaseID string `json:"lease_id,omitempty" jsonschema:"only this lease; default: every lease of this session"`
AllSessions bool `json:"all_sessions,omitempty" jsonschema:"include leases of other Claude Code sessions of this user"`
}
ListInput is the input of dol_list.
type NodeAPI ¶
type NodeAPI interface {
placement.NodeAPI
Capacity(ctx context.Context) (*v1.Capacity, error)
GetLease(ctx context.Context, id string) (*v1.Lease, error)
Heartbeat(ctx context.Context, id string) (*v1.HeartbeatResponse, error)
PatchLease(ctx context.Context, id string, p v1.LeasePatch) (*v1.Lease, error)
ReleaseLease(ctx context.Context, id string, keepSyncDir bool) (*v1.ReleaseResponse, error)
}
NodeAPI is the subset of *nodeclient.Client the client side uses.
type Options ¶
type Options struct {
Config *config.ClientConfig
Store *state.Store
// Docker runs the docker CLI; default dockerx.ExecRunner.
Docker dockerx.Runner
// NodeAPI builds the node API client; default nodeclient.NewSSH.
NodeAPI func(n config.NodeRef) NodeAPI
// ProjectDir defaults to $CLAUDE_PROJECT_DIR, then the working directory.
ProjectDir string
// Session defaults to a new v1.NewSessionID().
Session string
// LocalContext overrides local.docker_context / auto-detection.
LocalContext string
ClientArch string // default runtime.GOARCH
Forwarder Forwarder
// SSH configures every ssh invocation (node API, tunnels, rsync). Its
// ConnectTimeout defaults to policy.health_timeout_ms.
SSH sshx.Options
// Tunnels manages ssh -L forwards; default tunnel.NewManager(SSH).
Tunnels *tunnel.Manager
// KindBinary is the local kind binary for local kind fallback; default "kind".
KindBinary string
// Rsync overrides rsync binary detection.
Rsync string
Logger *slog.Logger
Now func() time.Time
}
Options configure a Core. Zero values pick production defaults.
type PinInput ¶
type PinInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire"`
Pinned bool `json:"pinned" jsonschema:"true keeps the lease after this session ends; false makes it session-bound again"`
TTLMinutes int `json:"ttl_minutes,omitempty" jsonschema:"optional hard expiry in minutes for a pinned lease"`
}
PinInput is the input of dol_pin.
type ReleaseInput ¶
type ReleaseInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire, e.g. l-abcdefghij"`
KeepSyncDir bool `json:"keep_sync_dir,omitempty" jsonschema:"keep the synced workspace directory on the node"`
}
ReleaseInput is the input of dol_release.
type RemoveInput ¶
type RemoveInput struct {
TargetInput
Volumes bool `json:"volumes,omitempty" jsonschema:"also remove the container's anonymous volumes / the compose project's volumes"`
}
RemoveInput is the input of dol_remove.
type ResizeInput ¶
type ResizeInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire"`
EstMemoryGB float64 `json:"est_memory_gb" jsonschema:"new total memory estimate in GB"`
}
ResizeInput is the input of dol_resize.
type StatusOptions ¶
type StatusOptions struct {
// AllSessions lists leases of every session (the CLI) instead of only
// this session's (the MCP tool).
AllSessions bool
}
StatusOptions tune Status.
type SyncInput ¶
type SyncInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire"`
Path string `json:"path,omitempty" jsonschema:"directory to sync; default the project directory"`
}
SyncInput is the input of dol_sync.
type SyncResult ¶
type SyncResult struct {
v1.PlacementInfo
LocalPath string `json:"local_path"`
RemotePath string `json:"remote_path"`
Millis int64 `json:"ms"`
}
SyncResult is the output of dol_sync.
type TargetInput ¶
type TargetInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire, e.g. l-abcdefghij"`
Target string `json:"target" jsonschema:"container name or id, or a compose project registered on the lease"`
}
TargetInput selects a resource of a lease.
type ToolError ¶
ToolError is a tool-level failure: the result has isError=true and its text says what happened, why, and what to do next.
type UnforwardInput ¶
type UnforwardInput struct {
LeaseID string `json:"lease_id" jsonschema:"lease id from dol_acquire"`
LocalPort int `json:"local_port" jsonschema:"local port returned by dol_forward"`
}
UnforwardInput is the input of dol_unforward.
type WorkspaceAPI ¶
type WorkspaceAPI interface {
KindCreate(ctx context.Context, id string, req v1.KindCreateRequest) (*v1.KindCreateResponse, error)
KindLoad(ctx context.Context, id, name string, images []string) (*v1.KindLoadResponse, error)
KindDelete(ctx context.Context, id, name string) error
RegisterCompose(ctx context.Context, id, project string) error
RegisterSyncDir(ctx context.Context, id, path string) error
}
WorkspaceAPI is the part of the node API used by M4/M5 tools.