transport

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Caller added in v0.1.0

type Caller interface {
	Call(ctx context.Context, msg *Message) (*Message, error)
	Close() error
}

Caller is a synchronous request-response abstraction over any MCP transport. Call sends msg and waits for the matching response. For notifications (no ID), it sends and returns immediately with (nil, nil).

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

Error is an MCP protocol error.

type Message

type Message struct {
	JSONRPC string `json:"jsonrpc"`
	ID      any    `json:"id,omitempty"`
	Method  string `json:"method,omitempty"`
	Params  any    `json:"params,omitempty"`
	Result  any    `json:"result,omitempty"`
	Error   *Error `json:"error,omitempty"`
}

Message is an MCP protocol message.

type ProgressCaller added in v0.1.0

type ProgressCaller interface {
	Caller
	CallWithProgress(ctx context.Context, msg *Message, handler ProgressHandler) (*Message, error)
}

ProgressCaller extends Caller with the ability to relay upstream progress notifications while a request is in flight.

type ProgressHandler added in v0.1.0

type ProgressHandler func(notification *Message)

ProgressHandler is called for each notifications/progress message received from an upstream while waiting for a request response.

type SSETransport

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

SSETransport implements MCP transport over Server-Sent Events (legacy protocol). Inbound messages arrive via a long-lived GET SSE stream; outbound messages are sent via POST to a separate endpoint.

func NewSSETransport

func NewSSETransport(streamURL, postURL string, client *http.Client) *SSETransport

NewSSETransport creates a new SSE transport. streamURL is the GET endpoint that delivers the SSE event stream. postURL is the POST endpoint for sending JSON-RPC messages.

func (*SSETransport) Call added in v0.1.0

func (t *SSETransport) Call(ctx context.Context, msg *Message) (*Message, error)

Call implements Caller. For notifications (msg.ID == nil) it sends and returns immediately. For requests it posts the message and waits on the SSE stream for the matching reply.

func (*SSETransport) CallWithProgress added in v0.1.0

func (t *SSETransport) CallWithProgress(ctx context.Context, msg *Message, handler ProgressHandler) (*Message, error)

CallWithProgress implements ProgressCaller. It behaves like Call but invokes handler for each notifications/progress message received while waiting.

func (*SSETransport) Close

func (t *SSETransport) Close() error

func (*SSETransport) Connect

func (t *SSETransport) Connect(ctx context.Context) error

func (*SSETransport) Receive

func (t *SSETransport) Receive() <-chan *Message

func (*SSETransport) Send

func (t *SSETransport) Send(ctx context.Context, msg *Message) error

func (*SSETransport) SetHeader added in v0.1.0

func (t *SSETransport) SetHeader(key, value string)

SetHeader sets a persistent header applied to all outbound HTTP requests.

type StdioTransport

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

StdioTransport implements MCP transport over stdio (local process).

func NewStdioTransport

func NewStdioTransport(command string, args, env []string) *StdioTransport

NewStdioTransport creates a new stdio transport.

func (*StdioTransport) Call added in v0.1.0

func (t *StdioTransport) Call(ctx context.Context, msg *Message) (*Message, error)

Call implements Caller. For notifications (msg.ID == nil) it sends and returns immediately. For requests it sends and waits for the reply whose ID matches the request, skipping any intervening notifications.

func (*StdioTransport) CallWithProgress added in v0.1.0

func (t *StdioTransport) CallWithProgress(ctx context.Context, msg *Message, handler ProgressHandler) (*Message, error)

CallWithProgress implements ProgressCaller. It behaves like Call but invokes handler for each notifications/progress message received while waiting.

func (*StdioTransport) Close

func (t *StdioTransport) Close() error

func (*StdioTransport) Connect

func (t *StdioTransport) Connect(ctx context.Context) error

func (*StdioTransport) Receive

func (t *StdioTransport) Receive() <-chan *Message

func (*StdioTransport) Send

func (t *StdioTransport) Send(ctx context.Context, msg *Message) error

type StreamableHTTPTransport added in v0.1.0

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

StreamableHTTPTransport implements a minimal MCP transport over HTTP.

func NewStreamableHTTPTransport added in v0.1.0

func NewStreamableHTTPTransport(url string, client *http.Client) *StreamableHTTPTransport

func (*StreamableHTTPTransport) Call added in v0.1.0

Call implements Caller by delegating to Do.

func (*StreamableHTTPTransport) Close added in v0.1.0

func (t *StreamableHTTPTransport) Close() error

func (*StreamableHTTPTransport) Connect added in v0.1.0

func (t *StreamableHTTPTransport) Connect(ctx context.Context) error

func (*StreamableHTTPTransport) Do added in v0.1.0

func (*StreamableHTTPTransport) Receive added in v0.1.0

func (t *StreamableHTTPTransport) Receive() <-chan *Message

func (*StreamableHTTPTransport) Send added in v0.1.0

func (*StreamableHTTPTransport) SessionID added in v0.1.0

func (t *StreamableHTTPTransport) SessionID() string

func (*StreamableHTTPTransport) SetHeader added in v0.1.0

func (t *StreamableHTTPTransport) SetHeader(key, value string)

type Transport

type Transport interface {
	Connect(ctx context.Context) error
	Close() error
	Send(ctx context.Context, msg *Message) error
	Receive() <-chan *Message
}

Transport defines the MCP transport interface.

Jump to

Keyboard shortcuts

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