unix

package
v1.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 13 Imported by: 0

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

View Source
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.

View Source
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

func (t *Transport) Initialize() error

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

func (t *Transport) Receive() ([]byte, error)

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

func (t *Transport) Send(message []byte) error

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.

func (*Transport) Start

func (t *Transport) Start() error

Start starts the transport. For client mode, this is a no-op as the connection is established in Initialize. For server mode, it creates and binds to the Unix domain socket.

func (*Transport) Stop

func (t *Transport) Stop() error

Stop stops the transport. For client mode, it closes the connection to the server. For server mode, it closes the listener and all client connections, then removes the socket file.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL