Documentation
¶
Overview ¶
Package transport is a drop-in compatibility shim for github.com/mark3labs/mcp-go/client/transport. It provides the transport option types and error values that ToolHive references; the actual transport is driven by the official go-sdk from the client package.
This package intentionally does not import the go-sdk: it only carries configuration and error types. The client package reads the exported accessors here to construct the underlying go-sdk transport.
Index ¶
- Variables
- type AuthorizationRequiredError
- type ClientOption
- type Error
- type HTTPHeaderFunc
- type Interface
- type SSE
- type StreamableHTTP
- func (s *StreamableHTTP) ContinuousListening() bool
- func (s *StreamableHTTP) Endpoint() string
- func (s *StreamableHTTP) GetSessionId() string
- func (s *StreamableHTTP) HTTPClient() *http.Client
- func (s *StreamableHTTP) HeaderFunc() HTTPHeaderFunc
- func (s *StreamableHTTP) Headers() map[string]string
- func (s *StreamableHTTP) Logger() *slog.Logger
- func (s *StreamableHTTP) SetSessionID(id string)
- func (s *StreamableHTTP) Timeout() time.Duration
- type StreamableHTTPCOption
- func WithContinuousListening() StreamableHTTPCOption
- func WithHTTPBasicClient(client *http.Client) StreamableHTTPCOption
- func WithHTTPHeaderFunc(headerFunc HTTPHeaderFunc) StreamableHTTPCOption
- func WithHTTPHeaders(headers map[string]string) StreamableHTTPCOption
- func WithHTTPLogger(logger *slog.Logger) StreamableHTTPCOption
- func WithHTTPTimeout(timeout time.Duration) StreamableHTTPCOption
- func WithSession(sessionID string) StreamableHTTPCOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAuthorizationRequired indicates the server requires authorization // (HTTP 401 with a WWW-Authenticate header per RFC 9728). ErrAuthorizationRequired = errors.New("authorization required") // ErrOAuthAuthorizationRequired indicates OAuth authorization is required // and no valid token is available. ErrOAuthAuthorizationRequired = errors.New("no valid token available, authorization required") ErrUnauthorized = fmt.Errorf("unauthorized (401)") // ErrLegacySSEServer indicates the server returned 4xx for the initialize // POST, which usually means it is a legacy SSE-only server. ErrLegacySSEServer = fmt.Errorf("server returned 4xx for initialize POST, likely a legacy SSE server") // ErrSessionTerminated indicates the server no longer recognizes the // current session (HTTP 404); the client must re-initialize. ErrSessionTerminated = fmt.Errorf("session terminated (404). need to re-initialize") )
These error values mirror github.com/mark3labs/mcp-go/client/transport so that ToolHive's auth-detection code (errors.Is / errors.As against these) keeps working after the import swap. The go-sdk-backed client (see the client package) maps the underlying SDK/HTTP failures onto these sentinels.
Functions ¶
This section is empty.
Types ¶
type AuthorizationRequiredError ¶
type AuthorizationRequiredError struct {
// ResourceMetadataURL is extracted from the WWW-Authenticate header per RFC 9728.
ResourceMetadataURL string
}
AuthorizationRequiredError is returned for 401 responses carrying a WWW-Authenticate header. It mirrors mcp-go's transport.AuthorizationRequiredError.
func (*AuthorizationRequiredError) Error ¶
func (*AuthorizationRequiredError) Error() string
func (*AuthorizationRequiredError) Unwrap ¶
func (*AuthorizationRequiredError) Unwrap() error
Unwrap returns ErrAuthorizationRequired so errors.Is works.
type ClientOption ¶
type ClientOption func(*SSE)
ClientOption configures an SSE transport.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient sets a custom HTTP client for the SSE transport.
func WithHeaders ¶
func WithHeaders(headers map[string]string) ClientOption
WithHeaders sets static headers for the SSE client.
type Error ¶
type Error struct {
Err error
}
Error wraps a transport-level error. It mirrors mcp-go's transport.Error so that errors.As(err, new(*transport.Error)) continues to work.
type HTTPHeaderFunc ¶
HTTPHeaderFunc returns headers to attach to each Streamable HTTP request. It mirrors mcp-go's transport.HTTPHeaderFunc and is evaluated per request, so it can return values that change over the lifetime of the connection.
type Interface ¶
type Interface interface {
// GetSessionId returns the transport-level MCP session ID, if any.
GetSessionId() string
}
Interface is the transport handle returned by client.GetTransport. It mirrors mcp-go's transport.Interface for the subset ToolHive uses (type-asserting to *StreamableHTTP and reading the session ID).
type SSE ¶
type SSE struct {
// contains filtered or unexported fields
}
SSE holds SSE (Server-Sent Events) transport configuration. It is the option target for the SSE client, mirroring mcp-go's transport package.
func NewSSE ¶
func NewSSE(endpoint string, opts ...ClientOption) *SSE
NewSSE creates an SSE transport config for the given endpoint and applies the supplied options. Used by the client package.
func (*SSE) HTTPClient ¶
HTTPClient returns the configured HTTP client, or nil to use the default.
type StreamableHTTP ¶
type StreamableHTTP struct {
// contains filtered or unexported fields
}
StreamableHTTP holds Streamable HTTP transport configuration and, once connected, the live session ID. It is both the option target (mirroring mcp-go, whose options mutate the transport struct) and the handle returned by client.GetTransport.
func NewStreamableHTTP ¶
func NewStreamableHTTP(endpoint string, opts ...StreamableHTTPCOption) *StreamableHTTP
NewStreamableHTTP creates a StreamableHTTP for the given endpoint and applies the supplied options. It is used by the client package.
func (*StreamableHTTP) ContinuousListening ¶
func (s *StreamableHTTP) ContinuousListening() bool
ContinuousListening reports whether a standalone SSE listening stream was requested.
func (*StreamableHTTP) Endpoint ¶
func (s *StreamableHTTP) Endpoint() string
Endpoint returns the configured endpoint URL.
func (*StreamableHTTP) GetSessionId ¶
func (s *StreamableHTTP) GetSessionId() string
GetSessionId returns the current MCP session ID (empty if not yet connected or if the transport is stateless).
func (*StreamableHTTP) HTTPClient ¶
func (s *StreamableHTTP) HTTPClient() *http.Client
HTTPClient returns the configured HTTP client, or nil to use the default.
func (*StreamableHTTP) HeaderFunc ¶
func (s *StreamableHTTP) HeaderFunc() HTTPHeaderFunc
HeaderFunc returns the configured per-request header function, or nil.
func (*StreamableHTTP) Headers ¶
func (s *StreamableHTTP) Headers() map[string]string
Headers returns the configured static headers.
func (*StreamableHTTP) Logger ¶
func (s *StreamableHTTP) Logger() *slog.Logger
Logger returns the configured logger, if any.
func (*StreamableHTTP) SetSessionID ¶
func (s *StreamableHTTP) SetSessionID(id string)
SetSessionID records the live session ID. Used by the client package after the underlying go-sdk session is established.
func (*StreamableHTTP) Timeout ¶
func (s *StreamableHTTP) Timeout() time.Duration
Timeout returns the configured HTTP timeout (0 if unset).
type StreamableHTTPCOption ¶
type StreamableHTTPCOption func(*StreamableHTTP)
StreamableHTTPCOption configures a StreamableHTTP transport.
func WithContinuousListening ¶
func WithContinuousListening() StreamableHTTPCOption
WithContinuousListening enables a standalone SSE stream for server-initiated messages.
func WithHTTPBasicClient ¶
func WithHTTPBasicClient(client *http.Client) StreamableHTTPCOption
WithHTTPBasicClient sets a custom HTTP client for the Streamable HTTP transport.
func WithHTTPHeaderFunc ¶
func WithHTTPHeaderFunc(headerFunc HTTPHeaderFunc) StreamableHTTPCOption
WithHTTPHeaderFunc sets a function that returns headers for each Streamable HTTP request. It mirrors mcp-go's transport.WithHTTPHeaderFunc; the function is evaluated per request, so its returned headers may vary over time.
func WithHTTPHeaders ¶
func WithHTTPHeaders(headers map[string]string) StreamableHTTPCOption
WithHTTPHeaders sets static headers sent on each request.
func WithHTTPLogger ¶
func WithHTTPLogger(logger *slog.Logger) StreamableHTTPCOption
WithHTTPLogger sets a logger for the Streamable HTTP transport.
func WithHTTPTimeout ¶
func WithHTTPTimeout(timeout time.Duration) StreamableHTTPCOption
WithHTTPTimeout sets the HTTP timeout for the Streamable HTTP transport.
func WithSession ¶
func WithSession(sessionID string) StreamableHTTPCOption
WithSession sets an initial session ID (for resuming a session).
LIMITATION (issue #156, item U2): a preset session ID is honored ONLY via the resume path — i.e. when the client skips Initialize and issues requests through Client's raw JSON-RPC resume machinery (see resume.go, exercised by resume_test.go), which sends the preset ID as the Mcp-Session-Id header on each POST. It is NOT honored by Initialize: Initialize always builds a fresh go-sdk StreamableClientTransport (see Client.buildTransport) with no preset session-ID field and performs a full initialize handshake, so the server assigns (and the client adopts) a freshly-negotiated session ID that overwrites the value set here.
This cannot be fixed in the shim alone: go-sdk's StreamableClientTransport has no SessionID/preset field in any version (verified through v1.6.1); the session ID is solely server-assigned at initialize time. Callers that need to pin a specific session ID must use the resume path (transport.WithSession + direct method calls, no Initialize), not Initialize. TODO(upstream): ask go-sdk to support a preset/client-requested session ID on StreamableClientTransport, or a Connect option that supplies one.