streamable

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 15 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client implements streamable-http transport consumer (MCP 2025-03-26 spec). Handshake: POST /mcp -> obtains session id header. Stream : GET /mcp with same header and Accept: application/x-ndjson keeps receiving messages. Messages : subsequent POST /mcp with header carry requests/notifications.

func New

func New(ctx context.Context, endpointURL string, opts ...Option) (*Client, error)

New initialises Client and establishes streaming connection.

func (*Client) Notify

func (c *Client) Notify(ctx context.Context, n *jsonrpc.Notification) error

Notify sends JSON-RPC notification.

func (*Client) Send

func (c *Client) Send(ctx context.Context, r *jsonrpc.Request) (*jsonrpc.Response, error)

Send sends JSON-RPC request and waits for response.

func (*Client) SessionID added in v0.15.0

func (c *Client) SessionID() string

SessionID returns the currently configured or negotiated session id.

type Option

type Option func(*Client)

Option mutates Client.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient allows custom http.Client.

func WithHandler

func WithHandler(handler transport.Handler) Option

WithHandler sets the handler for the SSE sseClient

func WithHandshakeTimeout

func WithHandshakeTimeout(duration time.Duration) Option

WithHandshakeTimeout overrides default handshake timeout.

func WithListener

func WithListener(listener jsonrpc.Listener) Option

WithListener sets a listener that observes low-level transport messages.

func WithProtocolVersion

func WithProtocolVersion(version string) Option

WithProtocolVersion sets the MCP protocol version header (MCP-Protocol-Version) to be included on all HTTP requests made by the client (handshake, POSTs, and GET stream).

func WithSessionHeaderName

func WithSessionHeaderName(name string) Option

WithSessionHeaderName sets a custom HTTP header name used to carry the session id. Defaults to "Mcp-Session-Id".

func WithSessionID added in v0.15.0

func WithSessionID(id string) Option

WithSessionID sets an explicit session id for the client. When set, the client immediately applies the session header to POST requests and uses the same header on GET stream requests, allowing reconnects without a handshake. It also starts the background stream loop.

type Transport

type Transport struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Transport implements client side sender for the streaming HTTP transport. It expects that the endpoint supplied via handshake is capable of accepting a POST request with a JSON payload and will synchronously return any response payload.

func (*Transport) SendData

func (t *Transport) SendData(ctx context.Context, data []byte) error

SendData forwards JSON-RPC message data to the server using HTTP POST.

Jump to

Keyboard shortcuts

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