sidecar

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

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(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() error

Close stops accepting, shuts the registered sidecars down, 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) PushRules

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

PushRules sends each connected sidecar its scoped rule snapshot and records the acked version. It waits for every push to complete.

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
	Protocols    []string
	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 monotonic version and rules scoped to the adapter.
	RuleSnapshot(adapter string) (version uint64, rules []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