Documentation
¶
Index ¶
- 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) GetAllTools() map[string][]ToolInfo
- func (m *Manager) GetConnection(name string) (*Connection, error)
- type Message
- type RPCError
- type SSETransport
- type Strategy
- type ToolInfo
- type Transport
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found (404)") ErrMethodNotAllowed = errors.New("method not allowed (405)") ErrClosed = errors.New("transport closed") )
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
Strategy Strategy
}
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.
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) 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"`
}
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 SSETransport ¶
type SSETransport struct {
// contains filtered or unexported fields
}
SSETransport implements the Server-Sent Events transport for MCP. MCP SSE protocol flow: 1. Client opens GET request to establish SSE stream 2. Server sends "endpoint" event with URL for POSTing messages 3. Client sends messages via POST to the endpoint URL 4. Server sends responses via the SSE stream
func NewSSETransport ¶
func NewSSETransport(cfg *Config) *SSETransport
NewSSETransport creates a new SSE transport.
func (*SSETransport) SendReceive ¶
SendReceive sends a JSON-RPC message via HTTP POST and waits for the response via SSE.
type Strategy ¶
type Strategy string
Strategy defines the transport selection strategy.
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.