Documentation
¶
Index ¶
- Constants
- Variables
- func FindHeaderValue(headers http.Header, target string) *string
- func IsAuthRequiredProbeError(err error) bool
- func IsTimeoutProbeError(err error) bool
- func NewProbeTimeoutError(timeout time.Duration, cause error) error
- func NewSharedConnectionTransport(base mcp.Transport) mcp.Transport
- func SessionIDFromHeaders(headers http.Header) *string
- type ChannelStdioRuntimeInfoProvider
- type ChannelTransportFactory
- type ForwardingConnection
- type ForwardingTransport
- type ProbeState
- type ProbeTimeoutError
- type SessionTerminatingTransport
- type StdioRuntimeInfo
- type StdioRuntimeInfoProvider
- type TransportBuildParams
- type TransportProvider
Constants ¶
const ( HeaderSessionID = "Mcp-Session-Id" HeaderLastEventID = "Last-Event-ID" HeaderProtocolVersion = "Mcp-Protocol-Version" )
Variables ¶
var Module = fx.Module( "mcpclient", fx.Provide( NewProbeState, newMcpClient, newStdioCommandTransportFactoryProvider, newChannelStdioRuntimeInfoProvider, newChannelTransportFactory, fx.Annotate(newStreamableTransportProvider, fx.ResultTags(`group:"mcp_transport_providers"`)), fx.Annotate(newInjectableTransportProvider, fx.ResultTags(`group:"mcp_transport_providers"`)), fx.Annotate(newStdioTransportProvider, fx.ResultTags(`group:"mcp_transport_providers"`)), ), fx.Invoke(probeMcpServer), )
Functions ¶
func FindHeaderValue ¶
FindHeaderValue returns the value of a header in case-insensitive fashion. Nil is returned when the header is absent or the map is empty.
func IsAuthRequiredProbeError ¶
IsAuthRequiredProbeError reports whether a probe error indicates that the target MCP server is reachable but requires OAuth or other request authentication before initialize succeeds.
func IsTimeoutProbeError ¶
func NewSharedConnectionTransport ¶
NewSharedConnectionTransport returns a transport wrapper that reuses the same underlying connection across Connect calls.
func SessionIDFromHeaders ¶
SessionIDFromHeaders searches the provided headers map for the MCP session identifier and returns it when present.
Types ¶
type ChannelStdioRuntimeInfoProvider ¶
type ChannelStdioRuntimeInfoProvider interface {
StdioRuntimeInfo(channel types.Channel) (StdioRuntimeInfo, bool)
}
ChannelStdioRuntimeInfoProvider exposes stdio process details per channel.
type ChannelTransportFactory ¶
type ChannelTransportFactory struct {
// contains filtered or unexported fields
}
ChannelTransportFactory builds and caches MCP transports for configured channel bindings.
A connector request can arrive on any logical tunnel-service channel. The dispatcher asks this factory for the binding-specific transport, and the factory keeps one cached transport/HTTP client per channel so session headers, proxy selection, mTLS config, and raw-HTTP logging remain stable across requests for that channel.
func (*ChannelTransportFactory) Build ¶
func (f *ChannelTransportFactory) Build(binding config.MCPChannelBinding) (mcp.Transport, error)
Build returns a cached transport for the requested binding. Concurrent first use of the same channel is collapsed with singleflight so duplicate connector traffic cannot race into multiple stdio child processes or independent HTTP transport wrappers.
func (*ChannelTransportFactory) HTTPClientForBinding ¶
func (f *ChannelTransportFactory) HTTPClientForBinding(binding config.MCPChannelBinding) (*http.Client, error)
HTTPClientForBinding returns the HTTP client used for streamable MCP transports for a binding.
type ForwardingConnection ¶
type ForwardingConnection interface {
// Write writes a new message to the connection.
//
// Write may be called concurrently, as calls or responses may occur
// concurrently in user code.
//
// It returns the HTTP status code from the server response, the
// response headers, and an error (if any) encountered while writing
// or processing the response.
Write(context.Context, http.Header, jsonrpc.Message) (int, http.Header, error)
Read(ctx context.Context) (jsonrpc.Message, error)
// Close closes the connection. It is implicitly called whenever a Read or
// Write fails.
//
// Close may be called multiple times, potentially concurrently.
Close() error
}
ForwardingConnection extends mcp.Connection with helpers that return the response headers collected from the underlying HTTP transport.
type ForwardingTransport ¶
type ForwardingTransport interface {
Connect(ctx context.Context) (ForwardingConnection, error)
}
ForwardingTransport decorates an mcp.Transport so callers can attach per-request headers and capture the response headers returned by the MCP server.
func NewForwardingTransport ¶
func NewForwardingTransport(base mcp.Transport) ForwardingTransport
NewForwardingTransport wraps the provided transport with header-forwarding capabilities.
func NewSerializedForwardingTransport ¶
func NewSerializedForwardingTransport(base ForwardingTransport) ForwardingTransport
NewSerializedForwardingTransport wraps a ForwardingTransport so only one request lifecycle is active on the shared underlying connection at a time.
Some MCP transports multiplex poorly when several connector calls write to the same long-lived connection and then each reader waits for its own response. The wrapper holds a lifecycle lock from Write through any streamed notifications until the matching final JSON-RPC response, an error, or Close. Notifications without ids release immediately after the write because no response is legal.
type ProbeState ¶
type ProbeState struct {
// contains filtered or unexported fields
}
ProbeState tracks the result of the one-time startup probe against the main MCP channel.
func (*ProbeState) IsDone ¶
func (p *ProbeState) IsDone() bool
IsDone reports whether the probe has completed.
func (*ProbeState) Set ¶
func (p *ProbeState) Set(err error)
Set records the probe result and signals waiters.
func (*ProbeState) WaitUntilDone ¶
func (p *ProbeState) WaitUntilDone(ctx context.Context) error
WaitUntilDone blocks until the startup probe records a result or ctx is canceled.
type ProbeTimeoutError ¶
ProbeTimeoutError reports that the startup probe did not complete before the deadline.
func (*ProbeTimeoutError) Error ¶
func (e *ProbeTimeoutError) Error() string
func (*ProbeTimeoutError) Unwrap ¶
func (e *ProbeTimeoutError) Unwrap() error
type SessionTerminatingTransport ¶
type SessionTerminatingTransport interface {
TerminateSession(ctx context.Context, headers http.Header) (int, http.Header, error)
}
SessionTerminatingTransport can explicitly close an MCP Streamable HTTP session and report the upstream HTTP response returned by the MCP server.
type StdioRuntimeInfo ¶
type StdioRuntimeInfo struct {
PID int `json:"pid,omitempty"`
Command string `json:"command,omitempty"`
}
StdioRuntimeInfo describes the active stdio MCP process details.
type StdioRuntimeInfoProvider ¶
type StdioRuntimeInfoProvider interface {
StdioRuntimeInfo() StdioRuntimeInfo
}
StdioRuntimeInfoProvider exposes runtime details for stdio transport.
type TransportBuildParams ¶
type TransportBuildParams struct {
Config *config.MCPConfig
Binding config.MCPChannelBinding
HTTPClient *http.Client
}
TransportBuildParams carries shared dependencies for transport construction.
type TransportProvider ¶
type TransportProvider interface {
Kind() config.MCPTransportKind
Build(TransportBuildParams) (mcp.Transport, error)
}
TransportProvider constructs an MCP transport for a specific transport kind.