sidecar

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const AnnotationDisconnected = "sidecar_disconnected"

AnnotationDisconnected is the Flow.Annotations key sectool sets when it finalizes a flow left open by a sidecar that disconnected without resume.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Socket            string
	HeartbeatInterval time.Duration
	HeartbeatTimeout  time.Duration
	NativeProxyPort   int      // proxy listen port; excluded from sidecar early_claim ranges
	ReservedNames     []string // built-in adapter names sidecars may not reuse
	// ScopeCheck gates dial_upstream destinations; nil allows any host.
	ScopeCheck func(host string) (allowed bool, reason string)
	// DialTimeout bounds each dial_upstream connection attempt.
	DialTimeout time.Duration
	// NativeHTTPSend originates an outbound HTTP request through the in-process
	// proxy on a sidecar's behalf; nil disables native origination.
	NativeHTTPSend func(ctx context.Context, p wire.SidecarSendParams, invokedBy string) (wire.SidecarSendResult, *wire.Error)
}

Config configures the sidecar Manager and listener.

type CoreService

type CoreService interface {
	// CoreInvoke dispatches a core MCP tool by name.
	CoreInvoke(ctx context.Context, tool string, params json.RawMessage) (content string, isErr bool, err error)
	// CoreToolNames lists core tool names for registration-time collision checks.
	CoreToolNames() []string
}

CoreService dispatches core MCP tools and reports their names.

type FlowSink

type FlowSink interface {
	Store(*types.Flow) string
	Complete(flowID string, resp *types.Message, completedAt time.Time, annotations map[string]any) bool
	SetInvokedBy(flowID, invokedBy string) bool
	Get(flowID string) (*types.Flow, bool)
	ShouldCapture(*types.Flow) bool
}

FlowSink persists sidecar-emitted flows into sectool's unified history. Satisfied by *proxy.HistoryStore.

type Listener

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

Listener accepts sidecar connections on the local socket and hands each to the Manager. Its lifecycle is owned by the native proxy backend.

func NewListener

func NewListener(ctx context.Context, cfg Config, mgr *Manager) (*Listener, error)

NewListener binds the local socket: a Unix domain socket on unix, loopback TCP on Windows. Call Serve to start accepting.

func (*Listener) Addr

func (l *Listener) Addr() string

Addr returns the bound socket address.

func (*Listener) Close

func (l *Listener) Close(ctx context.Context) error

Close stops accepting, shuts the registered sidecars down bounded by ctx, and releases the socket.

func (*Listener) Serve

func (l *Listener) Serve() error

Serve accepts connections until Close. Returns nil on clean shutdown.

type Liveness

type Liveness struct {
	LastPongRecv time.Time
}

Liveness tracks heartbeat responses.

type Manager

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

Manager owns the registry of connected sidecars: registration, conflict resolution, heartbeat, reconnect/resume, and shutdown.

func NewManager

func NewManager(cfg Config, registry *protocol.Registry, flows FlowSink, coreInvoke CoreService, rules RuleSource) *Manager

NewManager creates a Manager. registry dispatches connections to sidecar adapters, flows sinks push_flow, coreInvoke backs core_invoke, and rules supplies sync_rules snapshots.

func (*Manager) AdapterTools

func (m *Manager) AdapterTools() map[string][]wire.MCPTool

AdapterTools returns each healthy adapter's MCP tools keyed by adapter name, as a single consistent snapshot.

func (*Manager) Count

func (m *Manager) Count() int

Count returns the number of registered sidecars.

func (*Manager) Get

func (m *Manager) Get(name string) (*Record, bool)

Get returns the record for an adapter name.

func (*Manager) HandleConn

func (m *Manager) HandleConn(ctx context.Context, conn net.Conn)

HandleConn drives one accepted sidecar connection until it closes.

func (*Manager) HasAdapter

func (m *Manager) HasAdapter(name string) bool

HasAdapter reports whether a healthy adapter is registered under name.

func (*Manager) InvokeTool

func (m *Manager) InvokeTool(ctx context.Context, name string, args json.RawMessage) (wire.InvokeToolResult, *wire.Error)

InvokeTool delegates a sidecar-registered tool call to its owning adapter and returns the tool's result.

func (*Manager) IsReplaySource added in v0.2.0

func (m *Manager) IsReplaySource(flowID string) bool

IsReplaySource reports whether flowID is currently being replayed, so the routing sink can file a result pushed for it into replay history.

func (*Manager) PushRules

func (m *Manager) PushRules(ctx context.Context)

PushRules sends every connected sidecar its current rule snapshot, waiting for each to ack.

func (*Manager) SetToolsChangedHook

func (m *Manager) SetToolsChangedHook(fn func())

SetToolsChangedHook registers a callback invoked when the set of connected adapters changes, so the MCP server can recompose the advertised tool list.

func (*Manager) Shutdown

func (m *Manager) Shutdown(ctx context.Context)

Shutdown requests a graceful close of every sidecar and waits briefly.

func (*Manager) SidecarSend

func (m *Manager) SidecarSend(ctx context.Context, adapter string, p wire.SidecarSendParams) (wire.SidecarSendResult, *wire.Error)

SidecarSend routes a replay or origination to the named adapter. For replay (FlowID set) it fetches the source flow and passes it inline.

type Record

type Record struct {
	Name         string
	ProtoVersion wire.ProtocolVersion
	Capabilities wire.Capabilities
	MCPTools     []wire.MCPTool // tool definitions the sidecar provides
	InstanceID   string
	// contains filtered or unexported fields
}

Record is the registry entry for one connected sidecar adapter.

func (*Record) Healthy

func (r *Record) Healthy() bool

Healthy reports whether the sidecar is answering heartbeats. An unhealthy sidecar must not claim new connections.

type RuleSource

type RuleSource interface {
	// RuleSnapshot returns the rules scoped to the adapter, in apply order.
	RuleSnapshot(adapter string) []wire.Rule
}

RuleSource returns the current rule snapshot for a named adapter.

Jump to

Keyboard shortcuts

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