Documentation
¶
Index ¶
- Constants
- Variables
- type AuthProvider
- type Config
- type Connection
- func (c *Connection) Close() error
- func (c *Connection) Connect(ctx context.Context) error
- func (c *Connection) ExecuteTool(ctx context.Context, toolName string, args map[string]any) (*Message, error)
- func (c *Connection) FetchTools(ctx context.Context) error
- func (c *Connection) GetTools() []ToolInfo
- func (c *Connection) Port() int
- type HTTPTransport
- type Manager
- func (m *Manager) Close() error
- func (m *Manager) Connect(ctx context.Context) error
- func (m *Manager) ExecuteTool(ctx context.Context, toolName string, args map[string]any) (*Message, error)
- func (m *Manager) ExecuteToolOn(ctx context.Context, upstreamName, toolName string, args map[string]any) (*Message, error)
- func (m *Manager) GetAllTools() map[string][]ToolInfo
- func (m *Manager) GetConnection(name string) (*Connection, error)
- type Message
- type RPCError
- type Strategy
- type ToolInfo
- type Transport
Constants ¶
const (
ProtocolVersion = "2026-07-28"
)
MCP protocol details this client speaks. There is no handshake in 2026-07-28: every request carries the version, capabilities and client identity in _meta, and repeats the method (and target name) in headers so gateways can route without parsing the body.
Variables ¶
var ( ErrNotFound = errors.New("not found (404)") ErrMethodNotAllowed = errors.New("method not allowed (405)") )
Transport errors.
Functions ¶
This section is empty.
Types ¶
type AuthProvider ¶
type AuthProvider interface {
// GetAccessToken returns the current access token.
GetAccessToken(ctx context.Context) (string, error)
// RefreshToken refreshes the access token.
RefreshToken(ctx context.Context) error
}
AuthProvider provides OAuth tokens for authenticated requests.
type Config ¶
type Config struct {
ServerURL string
Headers map[string]string
AuthProvider AuthProvider
}
Config holds transport configuration.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection represents a connection to a single upstream MCP server.
func NewConnection ¶
func NewConnection(config *types.UpstreamConfig, cacheDir string, callbackPort int) (*Connection, error)
NewConnection creates a new upstream connection.
func (*Connection) Connect ¶
func (c *Connection) Connect(ctx context.Context) error
Connect establishes the connection to the upstream server.
func (*Connection) ExecuteTool ¶
func (c *Connection) ExecuteTool(ctx context.Context, toolName string, args map[string]any) (*Message, error)
ExecuteTool executes a tool on the upstream server.
func (*Connection) FetchTools ¶
func (c *Connection) FetchTools(ctx context.Context) error
FetchTools fetches the list of tools from the upstream server.
func (*Connection) GetTools ¶
func (c *Connection) GetTools() []ToolInfo
GetTools returns the list of tools from this upstream.
func (*Connection) Port ¶
func (c *Connection) Port() int
Port returns the OAuth callback port (needed for auth provider access).
type HTTPTransport ¶
type HTTPTransport struct {
// contains filtered or unexported fields
}
HTTPTransport implements the Streamable HTTP transport for MCP.
func NewHTTPTransport ¶
func NewHTTPTransport(cfg *Config) *HTTPTransport
NewHTTPTransport creates a new HTTP transport.
func (*HTTPTransport) Close ¶
func (t *HTTPTransport) Close() error
Close closes the HTTP transport.
func (*HTTPTransport) SendReceive ¶
SendReceive sends a JSON-RPC message via HTTP POST and returns the response.
The 2026-07-28 framing (version header plus matching _meta, and the routing headers) is not understood by every upstream: servers on older revisions validate MCP-Protocol-Version against an allowlist and answer 400. When that happens the request is retried once without any of it, and the connection stays in that mode for its lifetime.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages connections to multiple upstream MCP servers.
func NewManager ¶
func NewManager(config *types.ProxyConfig) *Manager
NewManager creates a new upstream manager.
func (*Manager) ExecuteTool ¶
func (m *Manager) ExecuteTool(ctx context.Context, toolName string, args map[string]any) (*Message, error)
ExecuteTool executes a tool on the appropriate upstream. The toolName should be in the format "upstream:tool" or just "tool" for single upstream.
func (*Manager) ExecuteToolOn ¶ added in v0.59.93
func (m *Manager) ExecuteToolOn(ctx context.Context, upstreamName, toolName string, args map[string]any) (*Message, error)
ExecuteToolOn runs a tool on a named upstream.
Callers that already know which upstream a tool came from must use this rather than ExecuteTool: passing the unprefixed name back through parseToolName leaves it guessing, and with more than one upstream configured it cannot, so every call fails as ambiguous.
func (*Manager) GetAllTools ¶
GetAllTools returns all tools from all upstreams.
func (*Manager) GetConnection ¶
func (m *Manager) GetConnection(name string) (*Connection, error)
GetConnection returns the connection for a specific upstream by name.
type Message ¶
type Message struct {
JSONRPC string `json:"jsonrpc"`
ID any `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
// Name is the tool, prompt or resource this request targets, sent as the
// Mcp-Name header. Not part of the JSON-RPC body.
Name string `json:"-"`
}
Message represents a JSON-RPC 2.0 message.
func (*Message) IsNotification ¶
IsNotification returns true if the message is a notification.
func (*Message) IsResponse ¶
IsResponse returns true if the message is a response.
type RPCError ¶
type RPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
RPCError represents a JSON-RPC error.
type Strategy ¶
type Strategy string
Strategy names an upstream transport. Streamable HTTP is the only one left; the sse values are kept so an existing config still parses, and the caller warns before falling back to HTTP.
type ToolInfo ¶
type ToolInfo struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"inputSchema,omitempty"`
}
ToolInfo holds information about a tool from an upstream server.
type Transport ¶
type Transport interface {
// Start initialises the transport connection.
Start(ctx context.Context) error
// SendReceive sends a JSON-RPC message and waits for the response.
// This is a synchronous request/response operation.
SendReceive(ctx context.Context, msg *Message) (*Message, error)
// Close closes the transport connection.
Close() error
}
Transport defines the interface for MCP transports.