transport

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSessionClosed = errors.New("session closed")

Functions

This section is empty.

Types

type Discard

type Discard struct{}

Discard is a transport that discards all data. Discard reads and writes are no-ops. This is useful for testing.

func (Discard) Close

func (d Discard) Close() error

func (Discard) Receive

func (d Discard) Receive() iter.Seq[json.RawMessage]

func (Discard) Send

func (d Discard) Send(v json.RawMessage) error

type Generic

type Generic struct {
	// contains filtered or unexported fields
}

Generic is a transport for the Model Context Protocol that uses the standard input and output.

func NewGeneric

func NewGeneric(r io.Reader, w io.Writer) *Generic

NewGeneric creates a new Transport that uses the standard input and output.

func NewStdio

func NewStdio() *Generic

NewStdio creates a new Transport that uses the standard input and output.

func (*Generic) Close

func (t *Generic) Close() error

Close closes the transport's reader and writer if they implement io.Closer. It avoids closing the same resource twice if reader and writer are identical.

func (*Generic) Receive

func (t *Generic) Receive() iter.Seq[json.RawMessage]

Receive reads JSON messages from the reader.

func (*Generic) Send

func (t *Generic) Send(v json.RawMessage) error

Send writes a JSON message to the writer, followed by a newline.

type JSONReceiver

type JSONReceiver interface {
	Receive() iter.Seq[json.RawMessage]
}

type JSONSender

type JSONSender interface {
	Send(v json.RawMessage) error
}

type SSE

type SSE struct {
	// contains filtered or unexported fields
}

func NewSSE

func NewSSE(prefix string, handler SessionHandler) (*SSE, error)

func (*SSE) ServeHTTP

func (s *SSE) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SSESession

type SSESession struct {
	// contains filtered or unexported fields
}

func (*SSESession) Close

func (s *SSESession) Close() error

func (*SSESession) Receive

func (s *SSESession) Receive() iter.Seq[json.RawMessage]

func (*SSESession) Send

func (s *SSESession) Send(v json.RawMessage) error

type Session

type Session interface {
	JSONSender
	JSONReceiver
	io.Closer
}

func NewPipe

func NewPipe() (a, b Session)

NewPipe creates a pair of transports that are connected to each other. This is useful for testing.

type SessionHandler

type SessionHandler interface {
	HandleSession(context.Context, uint64, Session) error
}

type SessionHandlerFunc

type SessionHandlerFunc func(context.Context, uint64, Session) error

func (SessionHandlerFunc) HandleSession

func (f SessionHandlerFunc) HandleSession(ctx context.Context, id uint64, s Session) error

Jump to

Keyboard shortcuts

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