Documentation
¶
Overview ¶
Package upstream is the driven adapter for backend MCP servers: it turns a config.Backend into a live core.Upstream over the go-sdk client.
Transports: stdio spawns a subprocess (CommandTransport); http and sse dial remote endpoints (StreamableClientTransport / SSEClientTransport). Upstream auth — none, bearer, client_credentials, interactive OAuth — is assembled here from the backend's auth block; on streamable the SDK drives the OAuthHandler itself, on SSE we drive it once at connect.
Index ¶
- type Backend
- func (b *Backend) Call(ctx context.Context, tool string, args json.RawMessage) (*mcp.CallToolResult, error)
- func (b *Backend) Close() error
- func (b *Backend) Namespace() string
- func (b *Backend) Passthrough() bool
- func (b *Backend) Tools() []*mcp.Tool
- func (b *Backend) ToolsChanged() <-chan struct{}
- func (b *Backend) Wait() error
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend is a connected upstream MCP server.
func Connect ¶
func Connect(ctx context.Context, name string, cfg *config.Backend, opts *Options) (*Backend, error)
Connect dials (or spawns) the backend and discovers its tool inventory. cfg's env: references resolve here — the copy that reaches transports carries secrets; the config file never does.
func (*Backend) Call ¶
func (b *Backend) Call(ctx context.Context, tool string, args json.RawMessage) (*mcp.CallToolResult, error)
func (*Backend) Passthrough ¶
Passthrough reports whether this upstream is a federated gateway — its tool names are already qualified. Part of core.Passthrough.
func (*Backend) Tools ¶
Tools returns the current inventory. It is safe for concurrent use: a list_changed refresh swaps the whole slice under the inventory lock.
func (*Backend) ToolsChanged ¶ added in v0.0.6
func (b *Backend) ToolsChanged() <-chan struct{}
ToolsChanged carries an edge-triggered signal after the inventory refresh installed a new list. The channel is never closed; consumers tied to the backend's lifetime should also select on Wait(), as watchSession does.
type Options ¶
type Options struct {
// Tokens is the persistent upstream-token store. Nil means no stored
// grants — an oauth backend then can only authorize interactively.
Tokens *oauth.Store
// Interactive permits the oauth fetcher to open a browser and wait on a
// loopback callback (`toolhost mcp auth`); serve/discover pass false so a
// missing grant fails fast instead of surprising a terminal.
Interactive bool
// OpenURL launches the authorization URL — nil uses the platform opener.
// Tests inject a redirect-following HTTP GET.
OpenURL func(string) error
// Out is where the interactive fetcher prints the authorization URL.
Out io.Writer
// contains filtered or unexported fields
}
Options carries the cross-cutting things a connect needs that config doesn't know: where tokens persist and whether a flow may open a browser.
func (*Options) DefaultCallTimeout ¶
DefaultCallTimeout is the call_timeout for backends without their own.
func (*Options) SetDefaultCallTimeout ¶ added in v0.0.4
SetDefaultCallTimeout sets the call_timeout for backends without their own. Safe while calls are in flight.