mux

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package mux is the core of mcpmux: it connects to a set of backend MCP servers, aggregates their tools under namespaced names, and exposes them through a single proxy MCP server (over stdio or streamable HTTP).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PartitionBackends added in v0.4.0

func PartitionBackends(backends []config.Backend) (noninteractive, interactive []config.Backend)

PartitionBackends splits backends into those that connect without human interaction and those that may prompt for an interactive OAuth consent, preserving config order within each group. A daemon connects the non-interactive group synchronously (so its tools and systemd readiness are immediate) and the interactive group in the background.

func SetVersion

func SetVersion(v string)

SetVersion records the build version reported to peers.

Types

type Mux

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

Mux aggregates several backend MCP servers behind a single proxy server.

func New

func New(ctx context.Context, cfg *config.Config, log *slog.Logger) (*Mux, error)

New connects to every configured backend synchronously, aggregates their tools and returns a ready Mux. It is used by callers that want the full catalog before proceeding (e.g. the `list` command); it blocks on any interactive OAuth consent. On zero connected backends it returns an error. The caller owns Close.

func NewServer added in v0.4.0

func NewServer(cfg *config.Config, log *slog.Logger) *Mux

NewServer builds an unconnected Mux: the proxy server and its middleware, with no backends attached. Callers bring backends up with Connect / ConnectInBackground. This lets a daemon start serving (and signal systemd readiness) before interactive OAuth backends have finished authorizing.

func (*Mux) Catalog

func (m *Mux) Catalog() []ToolInfo

Catalog returns the aggregated tools across all backends, captured when each backend was registered (no additional backend round-trips).

func (*Mux) Close

func (m *Mux) Close()

Close shuts down every backend session. It first marks the Mux as closing (so supervisors treat the impending session closures as intentional and do not reconnect) and waits for any in-flight background Connect to return (the caller is expected to have cancelled the context, which aborts an in-progress connect/consent) so closing sessions cannot race the goroutine that registers them. Closing each session unblocks its supervisor's Wait; once all sessions are closed it waits for the supervisors to exit.

func (*Mux) Connect added in v0.4.0

func (m *Mux) Connect(ctx context.Context, backends []config.Backend, eager bool) int

Connect dials the given backends sequentially, registering each one's tools as it succeeds and logging+skipping failures (one bad backend must not take down the proxy). Sequential iteration keeps interactive OAuth consents to one browser window at a time. It returns the number of backends connected. Safe to call after the server has started serving: tool registration notifies connected clients via tools/list_changed.

func (*Mux) ConnectInBackground added in v0.4.0

func (m *Mux) ConnectInBackground(ctx context.Context, backends []config.Backend, eager bool)

ConnectInBackground connects the given backends in a goroutine so their interactive OAuth consents happen after the proxy is already serving, instead of blocking startup. Close waits for the goroutine to finish. A nil/empty slice is a no-op.

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(ctx context.Context, addr, path string) error

ServeHTTP binds addr and serves the proxy over streamable HTTP. It returns when ctx is cancelled or on a fatal error.

func (*Mux) ServeHTTPListener

func (m *Mux) ServeHTTPListener(ctx context.Context, ln net.Listener, path string) error

ServeHTTPListener serves the proxy over streamable HTTP on an existing listener, mounting the single MCP endpoint at path. This is the entry point for systemd socket activation, where the listening socket is supplied by the service manager. It returns when ctx is cancelled or on a fatal error.

func (*Mux) ServeStdio

func (m *Mux) ServeStdio(ctx context.Context) error

ServeStdio runs the proxy over stdin/stdout until ctx is cancelled.

type ToolInfo

type ToolInfo struct {
	Backend     string // backend name
	Name        string // namespaced name exposed to clients (<backend>__<tool>)
	Description string // tool description, as advertised by the backend
}

ToolInfo describes one aggregated tool for diagnostics.

Jump to

Keyboard shortcuts

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