Documentation
¶
Index ¶
- Constants
- func ReadSSEEvents(ctx context.Context, reader io.Reader, handler func(SSEEvent)) error
- type EventSource
- type Proxy
- func NewProxy(serverURL string, callbackPort int, headers map[string]string, ...) (*Proxy, error)
- func NewProxyWithOptions(serverURL string, callbackPort int, headers map[string]string, ...) (*Proxy, error)
- func NewProxyWithTransport(serverURL string, callbackPort int, headers map[string]string, ...) (*Proxy, error)
- type SSEEvent
- type SSETransport
- func (t *SSETransport) Close() error
- func (t *SSETransport) Connect(ctx context.Context) error
- func (t *SSETransport) Send(ctx context.Context, message []byte) error
- func (t *SSETransport) SessionID() string
- func (t *SSETransport) SetOnError(handler func(err error))
- func (t *SSETransport) SetOnMessage(handler func(event string, data []byte))
- type SSETransportConfig
- type StreamableHTTPTransport
- func (t *StreamableHTTPTransport) Close() error
- func (t *StreamableHTTPTransport) Connect(ctx context.Context) error
- func (t *StreamableHTTPTransport) Send(ctx context.Context, message []byte) error
- func (t *StreamableHTTPTransport) SessionID() string
- func (t *StreamableHTTPTransport) SetOnError(handler func(err error))
- func (t *StreamableHTTPTransport) SetOnMessage(handler func(event string, data []byte))
- type StreamableHTTPTransportConfig
- type Transport
- type TransportMode
- type UnauthorizedError
Constants ¶
const ( // HeaderMCPMethod mirrors the JSON-RPC `method` field. Required on all // requests from 2026-07-28 onwards. HeaderMCPMethod = "Mcp-Method" // HeaderMCPName mirrors `params.name` or `params.uri`. Required for // tools/call, prompts/get and resources/read. HeaderMCPName = "Mcp-Name" // MetaKeyProtocolVersion is the _meta key carrying the protocol version on // every request in the modern (per-request metadata) era. MetaKeyProtocolVersion = "io.modelcontextprotocol/protocolVersion" // ProtocolVersion20260728 is the first revision that drops the initialize // handshake and requires the standard request metadata headers. ProtocolVersion20260728 = "2026-07-28" )
Request metadata mirroring for the Streamable HTTP transport.
Since MCP 2026-07-28 the transport mirrors selected JSON-RPC body fields into HTTP headers so intermediaries can route without parsing the body. Servers MUST reject a request whose headers disagree with its body, so the values here are always derived from the message actually being sent rather than from transport-level state.
const ( // MCPProtocolVersion is the protocol version assumed until the local // client's own traffic tells us otherwise. It is the last revision that // used the initialize handshake, so it is the safe assumption for a client // that has not declared a version yet. MCPProtocolVersion = "2025-11-25" // HeaderMCPSessionID is the session ID header name. HeaderMCPSessionID = "Mcp-Session-Id" // HeaderMCPProtocolVersion is the protocol version header name. HeaderMCPProtocolVersion = "Mcp-Protocol-Version" )
const HeaderWWWAuthenticate = "WWW-Authenticate"
HeaderWWWAuthenticate is the response header name carrying the Bearer challenge that points at the Protected Resource Metadata document (RFC 9728 §5.1).
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EventSource ¶
type EventSource struct {
// Callbacks
OnOpen func()
OnMessage func(event string, data []byte)
OnError func(err error)
// contains filtered or unexported fields
}
EventSource provides a client for Server-Sent Events (SSE)
func NewEventSource ¶
func NewEventSource(request *http.Request, client *http.Client) *EventSource
NewEventSource creates a new SSE client
func (*EventSource) Connect ¶
func (es *EventSource) Connect() error
Connect establishes the SSE connection
func (*EventSource) IsConnected ¶ added in v0.3.0
func (es *EventSource) IsConnected() bool
IsConnected reports whether the stream is currently open. readEvents clears this when the stream ends, so it is written from another goroutine.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy handles the bidirectional communication between stdio (MCP client) and the remote server
func NewProxy ¶
func NewProxy(serverURL string, callbackPort int, headers map[string]string, serverURLHash string) (*Proxy, error)
NewProxy creates a new MCP proxy
func NewProxyWithOptions ¶ added in v0.2.0
func NewProxyWithOptions(serverURL string, callbackPort int, headers map[string]string, serverURLHash string, mode TransportMode, httpProxyURL string) (*Proxy, error)
NewProxyWithOptions creates a new MCP proxy with full configuration including HTTP proxy support
func NewProxyWithTransport ¶ added in v0.2.0
func NewProxyWithTransport(serverURL string, callbackPort int, headers map[string]string, serverURLHash string, mode TransportMode) (*Proxy, error)
NewProxyWithTransport creates a new MCP proxy with a specified transport mode
func (*Proxy) GetCommandEndpoint ¶
GetCommandEndpoint returns the command endpoint URL (for backward compatibility in tests).
func (*Proxy) SetCommandEndpoint ¶
SetCommandEndpoint sets the command endpoint URL (for backward compatibility in tests).
type SSETransport ¶ added in v0.2.0
type SSETransport struct {
// contains filtered or unexported fields
}
SSETransport implements the legacy SSE transport (MCP 2024-11-05). It uses two endpoints: GET for SSE stream, POST for sending messages.
func NewSSETransport ¶ added in v0.2.0
func NewSSETransport(cfg SSETransportConfig) *SSETransport
NewSSETransport creates a new legacy SSE transport.
func (*SSETransport) Close ¶ added in v0.2.0
func (t *SSETransport) Close() error
func (*SSETransport) Connect ¶ added in v0.2.0
func (t *SSETransport) Connect(ctx context.Context) error
func (*SSETransport) Send ¶ added in v0.2.0
func (t *SSETransport) Send(ctx context.Context, message []byte) error
func (*SSETransport) SessionID ¶ added in v0.2.0
func (t *SSETransport) SessionID() string
func (*SSETransport) SetOnError ¶ added in v0.2.0
func (t *SSETransport) SetOnError(handler func(err error))
func (*SSETransport) SetOnMessage ¶ added in v0.2.0
func (t *SSETransport) SetOnMessage(handler func(event string, data []byte))
type SSETransportConfig ¶ added in v0.2.0
type SSETransportConfig struct {
ServerURL string
Client *http.Client
Headers map[string]string
GetAuthToken func() string
}
SSETransportConfig holds configuration for creating an SSETransport.
type StreamableHTTPTransport ¶ added in v0.2.0
type StreamableHTTPTransport struct {
// contains filtered or unexported fields
}
StreamableHTTPTransport implements the Streamable HTTP transport (MCP 2025-11-25). It uses a single endpoint for both POST (sending messages) and GET (receiving notifications).
func NewStreamableHTTPTransport ¶ added in v0.2.0
func NewStreamableHTTPTransport(cfg StreamableHTTPTransportConfig) *StreamableHTTPTransport
NewStreamableHTTPTransport creates a new Streamable HTTP transport.
func (*StreamableHTTPTransport) Close ¶ added in v0.2.0
func (t *StreamableHTTPTransport) Close() error
func (*StreamableHTTPTransport) Connect ¶ added in v0.2.0
func (t *StreamableHTTPTransport) Connect(ctx context.Context) error
func (*StreamableHTTPTransport) Send ¶ added in v0.2.0
func (t *StreamableHTTPTransport) Send(ctx context.Context, message []byte) error
func (*StreamableHTTPTransport) SessionID ¶ added in v0.2.0
func (t *StreamableHTTPTransport) SessionID() string
func (*StreamableHTTPTransport) SetOnError ¶ added in v0.2.0
func (t *StreamableHTTPTransport) SetOnError(handler func(err error))
func (*StreamableHTTPTransport) SetOnMessage ¶ added in v0.2.0
func (t *StreamableHTTPTransport) SetOnMessage(handler func(event string, data []byte))
type StreamableHTTPTransportConfig ¶ added in v0.2.0
type StreamableHTTPTransportConfig struct {
Endpoint string
Client *http.Client
Headers map[string]string
GetAuthToken func() string
// SkipNotificationStream suppresses the GET notification stream outright.
// Set it only when the server cannot serve any revision that has one;
// otherwise leave it false and let the transport decide from the client's
// declared revision, since that is what determines whether the stream
// exists for this connection.
SkipNotificationStream bool
}
StreamableHTTPTransportConfig holds configuration for creating a StreamableHTTPTransport.
type Transport ¶ added in v0.2.0
type Transport interface {
// Connect establishes the connection to the remote MCP server.
Connect(ctx context.Context) error
// Send sends a JSON-RPC message to the remote server.
Send(ctx context.Context, message []byte) error
// SetOnMessage sets the callback for messages received from the server.
SetOnMessage(handler func(event string, data []byte))
// SetOnError sets the callback for transport-level errors.
SetOnError(handler func(err error))
// Close terminates the transport connection.
Close() error
// SessionID returns the current session ID, if any.
SessionID() string
}
Transport defines the interface for MCP transport implementations. Both the legacy SSE transport and the new Streamable HTTP transport implement this interface.
type TransportMode ¶ added in v0.2.0
type TransportMode string
TransportMode specifies which transport to use.
const ( TransportModeAuto TransportMode = "auto" TransportModeStreamableHTTP TransportMode = "streamable-http" TransportModeSSE TransportMode = "sse" )
type UnauthorizedError ¶ added in v0.2.2
type UnauthorizedError struct {
}
UnauthorizedError signals an HTTP 401 from the MCP server and carries the WWW-Authenticate header so callers can locate the Protected Resource Metadata document per RFC 9728 §5.1.
func (*UnauthorizedError) Error ¶ added in v0.2.2
func (e *UnauthorizedError) Error() string