Documentation
¶
Overview ¶
Package transport provides different transport layer implementations for the MCP protocol.
The transport package includes:
- Stdio transport for command-line applications
- WebSocket transport for web applications
- Server-Sent Events (SSE) transport for web browsers
Each transport implements the Transport interface:
type Transport interface { Start() error Stop() error }
Stdio Transport:
// Create a stdio transport t := transport.NewStdioTransport(session) // Start the transport if err := t.Start(); err != nil { log.Fatal(err) }
WebSocket Transport:
// Create a WebSocket transport with options t := transport.NewWebSocketTransport(session, transport.WithAddress(":8080"), transport.WithPath("/ws"), ) // Start the transport if err := t.Start(); err != nil { log.Fatal(err) }
SSE Transport:
// Create an SSE transport with options t := transport.NewSSETransport(session, transport.WithAddress(":8080"), transport.WithPath("/events"), ) // Start the transport if err := t.Start(); err != nil { log.Fatal(err) }
Transport Options:
Each transport type supports configuration through options:
type TransportOption func(t Transport) // Common options WithAddress(addr string) // Set the listening address WithPath(path string) // Set the endpoint path WithTLSConfig(config *tls.Config) // Configure TLS
The transport package handles all the low-level communication details, allowing the server to focus on business logic.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPTransport ¶
type HTTPTransport interface { Transport // StartHTTP starts the transport on the given address StartHTTP(addr string) error // Stop gracefully stops the transport Stop(ctx context.Context) error }
HTTPTransport extends Transport for HTTP-based transports
func NewSSETransport ¶
func NewSSETransport(session *server.Session, options ...Option) HTTPTransport
NewSSETransport creates a new SSE transport
func NewWebSocketTransport ¶
func NewWebSocketTransport(session *server.Session, options ...Option) HTTPTransport
NewWebSocketTransport creates a new WebSocket transport
type Option ¶
type Option func(*Options)
Option is a function that configures Options
func WithBufferSize ¶
WithBufferSize sets the buffer size option
type Options ¶
type Options struct { // Address is the network address to listen on (for HTTP transports) Address string // BufferSize is the size of notification channels BufferSize int }
Options represents configuration options for transports
type SSETransport ¶
type SSETransport struct {
// contains filtered or unexported fields
}
SSETransport implements a Server-Sent Events transport for MCP
func (*SSETransport) SendNotification ¶
func (t *SSETransport) SendNotification(method string, params interface{}) error
SendNotification sends a notification to all connected clients
func (*SSETransport) Start ¶
func (t *SSETransport) Start() error
Start starts the SSE transport on the default address
func (*SSETransport) StartHTTP ¶
func (t *SSETransport) StartHTTP(addr string) error
StartHTTP starts the SSE transport on the given address
type StdioTransport ¶
type StdioTransport struct {
// contains filtered or unexported fields
}
StdioTransport implements a stdio-based transport for MCP
func (*StdioTransport) SendNotification ¶
func (t *StdioTransport) SendNotification(method string, params interface{}) error
SendNotification sends a notification to the client
type Transport ¶
type Transport interface { // Start starts the transport Start() error // SendNotification sends a notification to connected clients SendNotification(method string, params interface{}) error }
Transport defines the interface that all MCP transports must implement
type WebSocketTransport ¶
type WebSocketTransport struct {
// contains filtered or unexported fields
}
WebSocketTransport implements a WebSocket-based transport for MCP
func (*WebSocketTransport) SendNotification ¶
func (t *WebSocketTransport) SendNotification(method string, params interface{}) error
SendNotification sends a notification to all connected clients
func (*WebSocketTransport) Start ¶
func (t *WebSocketTransport) Start() error
Start starts the WebSocket transport on the default address
func (*WebSocketTransport) StartHTTP ¶
func (t *WebSocketTransport) StartHTTP(addr string) error
StartHTTP starts the WebSocket transport on the given address