Documentation
¶
Overview ¶
Package transparent provides MCP ping functionality for transparent proxies.
Package transparent provides a transparent HTTP proxy implementation that forwards requests to a destination without modifying them.
Package transparent provides a transparent HTTP proxy implementation that forwards requests to a destination without modifying them.
Package transparent provides a transparent HTTP proxy implementation that forwards requests to a destination without modifying them.
Index ¶
- Constants
- func NewMCPPinger(targetURL string) healthcheck.MCPPinger
- func NewMCPPingerWithTimeout(targetURL string, timeout time.Duration) healthcheck.MCPPinger
- type MCPPinger
- type NoOpResponseProcessor
- type Option
- type ResponseProcessor
- type SSEResponseProcessor
- type TransparentProxy
- func (p *TransparentProxy) CloseListener() error
- func (*TransparentProxy) ForwardResponseToClients(_ context.Context, _ jsonrpc2.Message) error
- func (*TransparentProxy) GetMessageChannel() chan jsonrpc2.Message
- func (p *TransparentProxy) IsRunning() (bool, error)
- func (*TransparentProxy) SendMessageToDestination(_ jsonrpc2.Message) error
- func (p *TransparentProxy) Start(ctx context.Context) error
- func (p *TransparentProxy) Stop(ctx context.Context) error
Constants ¶
const ( // DefaultHealthCheckInterval is the default interval for health checks DefaultHealthCheckInterval = 10 * time.Second // DefaultHealthCheckRetryDelay is the default delay between retry attempts DefaultHealthCheckRetryDelay = 5 * time.Second // HealthCheckIntervalEnvVar is the environment variable name for configuring health check interval. // This is primarily useful for testing with shorter intervals. HealthCheckIntervalEnvVar = "TOOLHIVE_HEALTH_CHECK_INTERVAL" )
const ( // DefaultPingerTimeout is the default timeout for health check pings DefaultPingerTimeout = 5 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func NewMCPPinger ¶ added in v0.0.46
func NewMCPPinger(targetURL string) healthcheck.MCPPinger
NewMCPPinger creates a new MCP pinger for transparent proxies
func NewMCPPingerWithTimeout ¶ added in v0.7.0
func NewMCPPingerWithTimeout(targetURL string, timeout time.Duration) healthcheck.MCPPinger
NewMCPPingerWithTimeout creates a new MCP pinger with a custom timeout
Types ¶
type MCPPinger ¶ added in v0.0.46
type MCPPinger struct {
// contains filtered or unexported fields
}
MCPPinger implements healthcheck.MCPPinger for transparent proxies
type NoOpResponseProcessor ¶ added in v0.6.17
type NoOpResponseProcessor struct{}
NoOpResponseProcessor is a processor that does nothing. Used for transports that don't require response processing (e.g., streamable-http).
func (*NoOpResponseProcessor) ProcessResponse ¶ added in v0.6.17
func (*NoOpResponseProcessor) ProcessResponse(_ *http.Response) error
ProcessResponse is a no-op implementation.
func (*NoOpResponseProcessor) ShouldProcess ¶ added in v0.6.17
func (*NoOpResponseProcessor) ShouldProcess(_ *http.Response) bool
ShouldProcess always returns false for no-op processor.
type Option ¶ added in v0.7.0
type Option func(*TransparentProxy)
Option is a functional option for configuring TransparentProxy
func WithRemoteBasePath ¶ added in v0.11.2
WithRemoteBasePath sets the base path prefix from the remote URL. When set, incoming request paths are rewritten to include this prefix before forwarding to the remote server.
type ResponseProcessor ¶ added in v0.6.17
type ResponseProcessor interface {
// ProcessResponse modifies an HTTP response based on transport-specific logic.
// Returns error if processing fails.
ProcessResponse(resp *http.Response) error
// ShouldProcess returns true if this processor should handle the given response.
ShouldProcess(resp *http.Response) bool
}
ResponseProcessor defines the interface for processing and modifying HTTP responses based on transport-specific requirements.
type SSEResponseProcessor ¶ added in v0.6.17
type SSEResponseProcessor struct {
// contains filtered or unexported fields
}
SSEResponseProcessor handles SSE-specific response processing including: - Session ID extraction from SSE streams - Endpoint URL rewriting for path-based routing
func NewSSEResponseProcessor ¶ added in v0.6.17
func NewSSEResponseProcessor( proxy *TransparentProxy, endpointPrefix string, trustProxyHeaders bool, ) *SSEResponseProcessor
NewSSEResponseProcessor creates a new SSE response processor.
func (*SSEResponseProcessor) ProcessResponse ¶ added in v0.6.17
func (s *SSEResponseProcessor) ProcessResponse(resp *http.Response) error
ProcessResponse modifies SSE responses to: 1. Extract session IDs from endpoint events for session tracking 2. Rewrite endpoint URLs when X-Forwarded-Prefix or endpointPrefix is configured
SSE Event Format:
event: endpoint data: /sse?sessionId=abc
Only "event: endpoint" events have their data field rewritten. Other events (e.g., "event: message") are passed through unchanged.
func (*SSEResponseProcessor) ShouldProcess ¶ added in v0.6.17
func (*SSEResponseProcessor) ShouldProcess(resp *http.Response) bool
ShouldProcess returns true if the response is an SSE stream.
type TransparentProxy ¶
type TransparentProxy struct {
// contains filtered or unexported fields
}
TransparentProxy implements the Proxy interface as a transparent HTTP proxy that forwards requests to a destination. It's used by the SSE transport to forward requests to the container's HTTP server.
func NewTransparentProxy ¶
func NewTransparentProxy( host string, port int, targetURI string, prometheusHandler http.Handler, authInfoHandler http.Handler, prefixHandlers map[string]http.Handler, enableHealthCheck bool, isRemote bool, transportType string, onHealthCheckFailed types.HealthCheckFailedCallback, onUnauthorizedResponse types.UnauthorizedResponseCallback, endpointPrefix string, trustProxyHeaders bool, middlewares ...types.NamedMiddleware, ) *TransparentProxy
NewTransparentProxy creates a new transparent proxy with optional middlewares. The endpointPrefix parameter specifies an explicit prefix to prepend to SSE endpoint URLs. The trustProxyHeaders parameter indicates whether to trust X-Forwarded-* headers from reverse proxies. The prefixHandlers parameter is a map of path prefixes to HTTP handlers mounted before the catch-all proxy handler.
func NewTransparentProxyWithOptions ¶ added in v0.11.2
func NewTransparentProxyWithOptions( host string, port int, targetURI string, prometheusHandler http.Handler, authInfoHandler http.Handler, prefixHandlers map[string]http.Handler, enableHealthCheck bool, isRemote bool, transportType string, onHealthCheckFailed types.HealthCheckFailedCallback, onUnauthorizedResponse types.UnauthorizedResponseCallback, endpointPrefix string, trustProxyHeaders bool, middlewares []types.NamedMiddleware, options ...Option, ) *TransparentProxy
NewTransparentProxyWithOptions creates a new transparent proxy with optional configuration.
func (*TransparentProxy) CloseListener ¶ added in v0.2.1
func (p *TransparentProxy) CloseListener() error
CloseListener closes the listener for the transparent proxy.
func (*TransparentProxy) ForwardResponseToClients ¶
ForwardResponseToClients forwards a response from the destination to clients. This is not used in the TransparentProxy implementation as it forwards HTTP requests directly.
func (*TransparentProxy) GetMessageChannel ¶
func (*TransparentProxy) GetMessageChannel() chan jsonrpc2.Message
GetMessageChannel returns the channel for messages to/from the destination. This is not used in the TransparentProxy implementation as it forwards HTTP requests directly.
func (*TransparentProxy) IsRunning ¶
func (p *TransparentProxy) IsRunning() (bool, error)
IsRunning checks if the proxy is running.
func (*TransparentProxy) SendMessageToDestination ¶
func (*TransparentProxy) SendMessageToDestination(_ jsonrpc2.Message) error
SendMessageToDestination sends a message to the destination. This is not used in the TransparentProxy implementation as it forwards HTTP requests directly.