Documentation
¶
Overview ¶
Package transport provides transport implementations for MCP protocol.
Index ¶
- func BuildEnv(configEnv map[string]string) []string
- func ExpandEnv(s string) string
- func ExpandEnvMap(m map[string]string) map[string]string
- func ExpandEnvSlice(s []string) []string
- func ParseAndDispatchNotification(data []byte, handler NotificationHandler) bool
- type HTTPConfig
- type HTTPTransport
- func (t *HTTPTransport) Close() error
- func (t *HTTPTransport) IsAlive() bool
- func (t *HTTPTransport) Send(ctx context.Context, req *JSONRPCRequest) (*JSONRPCResponse, error)
- func (t *HTTPTransport) SendNotification(ctx context.Context, notif *JSONRPCNotification) error
- func (t *HTTPTransport) SetNotificationHandler(_ NotificationHandler)
- func (t *HTTPTransport) Start(ctx context.Context) error
- type JSONRPCError
- type JSONRPCNotification
- type JSONRPCRequest
- type JSONRPCResponse
- type NotificationHandler
- type SSEConfig
- type SSETransport
- func (t *SSETransport) Close() error
- func (t *SSETransport) IsAlive() bool
- func (t *SSETransport) Send(ctx context.Context, req *JSONRPCRequest) (*JSONRPCResponse, error)
- func (t *SSETransport) SendNotification(ctx context.Context, notif *JSONRPCNotification) error
- func (t *SSETransport) SetNotificationHandler(handler NotificationHandler)
- func (t *SSETransport) Start(ctx context.Context) error
- type STDIOConfig
- type STDIOTransport
- func (t *STDIOTransport) Close() error
- func (t *STDIOTransport) IsAlive() bool
- func (t *STDIOTransport) Send(ctx context.Context, req *JSONRPCRequest) (*JSONRPCResponse, error)
- func (t *STDIOTransport) SendNotification(ctx context.Context, notif *JSONRPCNotification) error
- func (t *STDIOTransport) SetNotificationHandler(handler NotificationHandler)
- func (t *STDIOTransport) Start(ctx context.Context) error
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildEnv ¶
BuildEnv creates an environment slice by merging the current environment with additional variables from configEnv.
func ExpandEnv ¶
ExpandEnv expands environment variables in a string. Supports ${VAR} and ${VAR:-default} syntax.
func ExpandEnvMap ¶
ExpandEnvMap expands environment variables in each value of a map.
func ExpandEnvSlice ¶
ExpandEnvSlice expands environment variables in each string of a slice.
func ParseAndDispatchNotification ¶
func ParseAndDispatchNotification(data []byte, handler NotificationHandler) bool
ParseAndDispatchNotification parses a JSON message and dispatches it to the handler if it's a notification. Returns true if it was a notification, false otherwise.
Types ¶
type HTTPConfig ¶
HTTPConfig contains configuration for HTTP transport
type HTTPTransport ¶
type HTTPTransport struct {
// contains filtered or unexported fields
}
HTTPTransport implements Transport for HTTP-based MCP servers.
func NewHTTPTransport ¶
func NewHTTPTransport(config HTTPConfig) *HTTPTransport
NewHTTPTransport creates a new HTTP transport
func (*HTTPTransport) IsAlive ¶
func (t *HTTPTransport) IsAlive() bool
IsAlive returns true if the transport is connected
func (*HTTPTransport) Send ¶
func (t *HTTPTransport) Send(ctx context.Context, req *JSONRPCRequest) (*JSONRPCResponse, error)
Send sends a request and waits for response
func (*HTTPTransport) SendNotification ¶
func (t *HTTPTransport) SendNotification(ctx context.Context, notif *JSONRPCNotification) error
SendNotification sends a notification (no response expected)
func (*HTTPTransport) SetNotificationHandler ¶
func (t *HTTPTransport) SetNotificationHandler(_ NotificationHandler)
SetNotificationHandler is a no-op for HTTP transport (stateless, no server-push)
type JSONRPCError ¶
type JSONRPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
JSONRPCError represents a JSON-RPC 2.0 error
type JSONRPCNotification ¶
type JSONRPCNotification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
JSONRPCNotification represents a JSON-RPC 2.0 notification (no ID)
type JSONRPCRequest ¶
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"`
ID uint64 `json:"id"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
JSONRPCRequest represents a JSON-RPC 2.0 request
type JSONRPCResponse ¶
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"`
ID uint64 `json:"id,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *JSONRPCError `json:"error,omitempty"`
}
JSONRPCResponse represents a JSON-RPC 2.0 response
type NotificationHandler ¶
NotificationHandler handles incoming notifications from the MCP server
type SSETransport ¶
type SSETransport struct {
// contains filtered or unexported fields
}
SSETransport implements Transport for SSE-based MCP servers. This implements the deprecated SSE transport for backward compatibility.
func NewSSETransport ¶
func NewSSETransport(config SSEConfig) *SSETransport
NewSSETransport creates a new SSE transport
func (*SSETransport) IsAlive ¶
func (t *SSETransport) IsAlive() bool
IsAlive returns true if the transport is connected
func (*SSETransport) Send ¶
func (t *SSETransport) Send(ctx context.Context, req *JSONRPCRequest) (*JSONRPCResponse, error)
Send sends a request and waits for response
func (*SSETransport) SendNotification ¶
func (t *SSETransport) SendNotification(ctx context.Context, notif *JSONRPCNotification) error
SendNotification sends a notification (no response expected)
func (*SSETransport) SetNotificationHandler ¶
func (t *SSETransport) SetNotificationHandler(handler NotificationHandler)
SetNotificationHandler sets the handler for incoming notifications
type STDIOConfig ¶
STDIOConfig contains configuration for STDIO transport
type STDIOTransport ¶
type STDIOTransport struct {
// contains filtered or unexported fields
}
STDIOTransport implements Transport for STDIO-based MCP servers. It spawns a subprocess and communicates via stdin/stdout.
func NewSTDIOTransport ¶
func NewSTDIOTransport(config STDIOConfig) *STDIOTransport
NewSTDIOTransport creates a new STDIO transport
func (*STDIOTransport) Close ¶
func (t *STDIOTransport) Close() error
Close terminates the subprocess and cleans up
func (*STDIOTransport) IsAlive ¶
func (t *STDIOTransport) IsAlive() bool
IsAlive returns true if the transport is connected
func (*STDIOTransport) Send ¶
func (t *STDIOTransport) Send(ctx context.Context, req *JSONRPCRequest) (*JSONRPCResponse, error)
Send sends a request and waits for response
func (*STDIOTransport) SendNotification ¶
func (t *STDIOTransport) SendNotification(ctx context.Context, notif *JSONRPCNotification) error
SendNotification sends a notification (no response expected)
func (*STDIOTransport) SetNotificationHandler ¶
func (t *STDIOTransport) SetNotificationHandler(handler NotificationHandler)
SetNotificationHandler sets the handler for incoming notifications
type Transport ¶
type Transport interface {
// Start initializes and starts the transport connection.
Start(ctx context.Context) error
// Send sends a JSON-RPC request and waits for a response.
// The context can be used to cancel the request.
Send(ctx context.Context, req *JSONRPCRequest) (*JSONRPCResponse, error)
// SendNotification sends a JSON-RPC notification (no response expected).
SendNotification(ctx context.Context, notif *JSONRPCNotification) error
// Close closes the transport connection and releases resources.
Close() error
// IsAlive returns true if the transport connection is still active.
IsAlive() bool
// SetNotificationHandler sets a handler for incoming notifications from the server.
SetNotificationHandler(handler NotificationHandler)
}
Transport defines the interface for MCP transport implementations. All transports must be able to send JSON-RPC requests and receive responses.