Documentation
¶
Overview ¶
Package unix provides a Unix Domain Socket implementation of the MCP transport.
This package implements the Transport interface using Unix Domain Sockets, suitable for high-performance local inter-process communication between processes running on the same machine.
Index ¶
Constants ¶
const DefaultShutdownTimeout = 10 * time.Second
DefaultShutdownTimeout is the default timeout for graceful shutdown. This is used when closing connections to avoid abruptly terminating active communications.
const DefaultSocketPermissions = 0600
DefaultSocketPermissions is the default file permissions for the socket file. 0600 means the socket is readable and writable only by the owner.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Transport ¶
type Transport struct {
transport.BaseTransport
// contains filtered or unexported fields
}
Transport implements the transport.Transport interface for Unix Domain Sockets. It supports both server and client modes for local inter-process communication.
func NewTransport ¶
func NewTransport(socketPath string, options ...UnixSocketOption) *Transport
NewTransport creates a new Unix Domain Socket transport.
Parameters:
- socketPath: The path to the Unix domain socket file. Using an absolute path or a path with "./" or "../" prefix creates a server-mode transport. Otherwise, it creates a client-mode transport.
- options: Optional configuration settings (permissions, buffer size, etc.)
Example:
// Server mode
serverTransport := unix.NewTransport("/tmp/mcp.sock")
// Client mode
clientTransport := unix.NewTransport("mcp.sock")
// With options
transport := unix.NewTransport("/tmp/mcp.sock",
unix.WithPermissions(0644),
unix.WithBufferSize(8192))
func (*Transport) Initialize ¶
Initialize initializes the transport. For client mode, it establishes the connection. For server mode, it ensures the directory for the socket exists.
func (*Transport) Receive ¶
Receive receives a message (client mode only). This method is used in client mode to receive responses from the server. In server mode, this method returns an error as server-side message handling is done via the message handler callback.
func (*Transport) Send ¶
Send sends a message. For client mode, it sends the message to the server. For server mode, it broadcasts the message to all connected clients.
type UnixSocketOption ¶
type UnixSocketOption func(*Transport)
UnixSocketOption is a function that configures a Transport These options allow customizing the behavior of the Unix Domain Socket transport.
func WithBufferSize ¶
func WithBufferSize(size int) UnixSocketOption
WithBufferSize sets the buffer size for socket IO operations. Larger buffer sizes can improve performance for larger messages.
func WithPermissions ¶
func WithPermissions(perm os.FileMode) UnixSocketOption
WithPermissions sets the file permissions for the socket file. This option is used to control who can connect to the socket.