Documentation
¶
Index ¶
- type Caller
- type Error
- type Message
- type ProgressCaller
- type ProgressHandler
- type SSETransport
- func (t *SSETransport) Call(ctx context.Context, msg *Message) (*Message, error)
- func (t *SSETransport) CallWithProgress(ctx context.Context, msg *Message, handler ProgressHandler) (*Message, error)
- func (t *SSETransport) Close() error
- func (t *SSETransport) Connect(ctx context.Context) error
- func (t *SSETransport) Receive() <-chan *Message
- func (t *SSETransport) Send(ctx context.Context, msg *Message) error
- func (t *SSETransport) SetHeader(key, value string)
- type StdioTransport
- func (t *StdioTransport) Call(ctx context.Context, msg *Message) (*Message, error)
- func (t *StdioTransport) CallWithProgress(ctx context.Context, msg *Message, handler ProgressHandler) (*Message, error)
- func (t *StdioTransport) Close() error
- func (t *StdioTransport) Connect(ctx context.Context) error
- func (t *StdioTransport) Receive() <-chan *Message
- func (t *StdioTransport) Send(ctx context.Context, msg *Message) error
- type StreamableHTTPTransport
- func (t *StreamableHTTPTransport) Call(ctx context.Context, msg *Message) (*Message, error)
- func (t *StreamableHTTPTransport) Close() error
- func (t *StreamableHTTPTransport) Connect(ctx context.Context) error
- func (t *StreamableHTTPTransport) Do(ctx context.Context, msg *Message) (*Message, error)
- func (t *StreamableHTTPTransport) Receive() <-chan *Message
- func (t *StreamableHTTPTransport) Send(ctx context.Context, msg *Message) error
- func (t *StreamableHTTPTransport) SessionID() string
- func (t *StreamableHTTPTransport) SetHeader(key, value string)
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Caller ¶ added in v0.1.0
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
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) Receive ¶
func (t *SSETransport) Receive() <-chan *Message
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
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) Receive ¶
func (t *StdioTransport) Receive() <-chan *Message
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) 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) Receive ¶ added in v0.1.0
func (t *StreamableHTTPTransport) Receive() <-chan *Message
func (*StreamableHTTPTransport) Send ¶ added in v0.1.0
func (t *StreamableHTTPTransport) Send(ctx context.Context, msg *Message) error
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)