transport

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectFunc

type ConnectFunc func(ctx context.Context, name string, cfg types.ServerConfig) (Upstream, error)

ConnectFunc creates an Upstream from a ServerConfig. This allows injecting mock connections in tests.

func NewConnectFunc

func NewConnectFunc(_ *auth.TokenStore) ConnectFunc

NewConnectFunc returns a ConnectFunc. Without the mcp_go_client_oauth build tag, this falls back to DefaultConnect (no OAuth support).

type HTTPUpstream

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

HTTPUpstream connects to an upstream MCP server via HTTP (streamable HTTP or SSE) using the go-sdk.

func NewHTTPUpstream

func NewHTTPUpstream(ctx context.Context, name string, cfg types.ServerConfig) (*HTTPUpstream, error)

NewHTTPUpstream creates and connects to an upstream HTTP MCP server (streamable HTTP).

func NewSSEUpstream

func NewSSEUpstream(ctx context.Context, name string, cfg types.ServerConfig) (*HTTPUpstream, error)

NewSSEUpstream creates and connects to an upstream SSE MCP server.

func (*HTTPUpstream) Alive

func (h *HTTPUpstream) Alive() bool

func (*HTTPUpstream) CallTool

func (h *HTTPUpstream) CallTool(ctx context.Context, toolName string, args json.RawMessage) (json.RawMessage, error)

func (*HTTPUpstream) Close

func (h *HTTPUpstream) Close() error

func (*HTTPUpstream) ListTools

func (h *HTTPUpstream) ListTools(ctx context.Context) ([]types.ToolEntry, error)

type Manager

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

Manager manages connections to upstream MCP servers. It maintains a pool of active connections and reaps idle ones.

func NewManager

func NewManager(configs map[string]types.ServerConfig, idleTimeout, callTimeout time.Duration, connect ConnectFunc) *Manager

NewManager creates a new transport manager and starts the idle reaper. callTimeout is optional — if zero, tool calls use the caller's context deadline only.

func (*Manager) CallTool

func (m *Manager) CallTool(ctx context.Context, serverName, toolName string, args json.RawMessage) (json.RawMessage, error)

CallTool is a convenience method that gets the upstream for a server and invokes the named tool. If the call fails, it evicts the stale connection and retries once with a fresh connection.

func (*Manager) Close

func (m *Manager) Close() error

Close shuts down all pooled connections and stops the reaper. Safe to call multiple times.

func (*Manager) GetUpstream

func (m *Manager) GetUpstream(ctx context.Context, serverName string) (Upstream, error)

GetUpstream returns a pooled connection for the named server, creating one if necessary or if the existing connection is no longer alive.

func (*Manager) ListToolsAll

func (m *Manager) ListToolsAll(ctx context.Context) (map[string][]types.ToolEntry, error)

ListToolsAll lists tools from all configured servers concurrently. A failure from one server does not prevent results from other servers. Each server gets a 30-second timeout.

type StdioUpstream

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

StdioUpstream connects to an upstream MCP server via stdio using the go-sdk.

func NewStdioUpstream

func NewStdioUpstream(ctx context.Context, name string, cfg types.ServerConfig) (*StdioUpstream, error)

NewStdioUpstream creates and connects to an upstream stdio MCP server.

func (*StdioUpstream) Alive

func (s *StdioUpstream) Alive() bool

func (*StdioUpstream) CallTool

func (s *StdioUpstream) CallTool(ctx context.Context, toolName string, args json.RawMessage) (json.RawMessage, error)

func (*StdioUpstream) Close

func (s *StdioUpstream) Close() error

func (*StdioUpstream) ListTools

func (s *StdioUpstream) ListTools(ctx context.Context) ([]types.ToolEntry, error)

type Upstream

type Upstream interface {
	// ListTools returns all tools from this upstream.
	ListTools(ctx context.Context) ([]types.ToolEntry, error)
	// CallTool invokes a tool on this upstream and returns the raw JSON result.
	CallTool(ctx context.Context, toolName string, args json.RawMessage) (json.RawMessage, error)
	// Close shuts down the connection.
	Close() error
	// Alive checks if the connection is still usable.
	Alive() bool
}

Upstream represents a connection to an upstream MCP server.

func DefaultConnect

func DefaultConnect(ctx context.Context, name string, cfg types.ServerConfig) (Upstream, error)

DefaultConnect creates real upstream connections (stdio or HTTP).

Jump to

Keyboard shortcuts

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