stream

package
v0.0.0-...-0d9909e Latest Latest
Warning

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

Go to latest
Published: May 5, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package stream provides implementations for streaming message creation

Package stream provides implementations for streaming message creation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPClientOption

type HTTPClientOption func(*HTTPClientTransport)

HTTPClientOption allows for customizing the HTTP client transport

func WithDebug

func WithDebug(debug bool) HTTPClientOption

WithDebug enables debug logging

func WithHTTPClient

func WithHTTPClient(client *http.Client) HTTPClientOption

WithHTTPClient sets a custom HTTP client

func WithRequestTimeout

func WithRequestTimeout(timeout time.Duration) HTTPClientOption

WithRequestTimeout sets the request timeout

type HTTPClientTransport

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

HTTPClientTransport implements an HTTP client transport with support for standard POST requests and Server-Sent Events (SSE) streaming.

func NewHTTPClientTransport

func NewHTTPClientTransport(baseURL string, options ...HTTPClientOption) *HTTPClientTransport

NewHTTPClientTransport creates a new HTTP client transport.

func (*HTTPClientTransport) Close

func (t *HTTPClientTransport) Close() error

Close closes the transport and cleans up all active streams

func (*HTTPClientTransport) Connect

func (t *HTTPClientTransport) Connect(ctx context.Context, handler spec.MessageHandler) error

Connect establishes a connection and registers the message handler.

func (*HTTPClientTransport) ConnectToDefaultSSE

func (t *HTTPClientTransport) ConnectToDefaultSSE() error

ConnectToDefaultSSE establishes a connection to the server's default SSE endpoint This maintains a permanent connection and receives server-initiated events

func (*HTTPClientTransport) DisconnectDefaultSSE

func (t *HTTPClientTransport) DisconnectDefaultSSE()

DisconnectDefaultSSE disconnects from the server's default SSE endpoint

func (*HTTPClientTransport) GetSessionID

func (t *HTTPClientTransport) GetSessionID() string

GetSessionID returns the current session ID

func (*HTTPClientTransport) Send

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

Send sends raw message data over the transport.

func (*HTTPClientTransport) SendMessage

func (t *HTTPClientTransport) SendMessage(ctx context.Context, message *spec.JSONRPCMessage) (*spec.JSONRPCMessage, error)

SendMessage sends a JSON-RPC message via HTTP POST and returns the response. For streaming requests, sets up an SSE connection.

type StreamingTransport

type StreamingTransport struct {

	// Extension points for concrete implementations
	Connector       func(ctx context.Context, handler spec.MessageHandler) error
	MessageSender   func(ctx context.Context, message *spec.JSONRPCMessage) (*spec.JSONRPCMessage, error)
	RawSender       func(message []byte) error
	Closer          func() error
	StreamResponder func(ctx context.Context, requestID string, results chan *spec.CreateMessageResult)
	// contains filtered or unexported fields
}

StreamingTransport implements the McpClientTransport interface with built-in support for streaming message creation. It can be extended or wrapped to provide actual transport functionality like HTTP, WebSockets, etc.

func NewStreamingTransport

func NewStreamingTransport(debug bool) *StreamingTransport

NewStreamingTransport creates a new streaming transport instance.

func (*StreamingTransport) Close

func (t *StreamingTransport) Close() error

Close closes the transport.

func (*StreamingTransport) Connect

func (t *StreamingTransport) Connect(ctx context.Context, handler spec.MessageHandler) error

Connect establishes a connection and registers the message handler.

func (*StreamingTransport) Send

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

Send sends raw message data over the transport.

func (*StreamingTransport) SendMessage

func (t *StreamingTransport) SendMessage(ctx context.Context, message *spec.JSONRPCMessage) (*spec.JSONRPCMessage, error)

SendMessage sends a JSON-RPC message and returns the response.

func (*StreamingTransport) SendStreamingResult

func (t *StreamingTransport) SendStreamingResult(requestID string, content string, isFinal bool) error

SendStreamingResult sends a streaming result through the transport This is a helper method that can be used by implementations to send streaming results

Jump to

Keyboard shortcuts

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