transparent

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

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

View Source
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
)
View Source
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

func (*MCPPinger) Ping added in v0.0.46

func (p *MCPPinger) Ping(ctx context.Context) (time.Duration, error)

Ping performs a simple HTTP health check for SSE transport servers For SSE transport, we don't send MCP ping requests because that would require establishing an SSE session first. Instead, we do a simple HTTP GET to check if the server is responding.

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

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 (*TransparentProxy) CloseListener added in v0.2.1

func (p *TransparentProxy) CloseListener() error

CloseListener closes the listener for the transparent proxy.

func (*TransparentProxy) ForwardResponseToClients

func (*TransparentProxy) ForwardResponseToClients(_ context.Context, _ jsonrpc2.Message) error

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(_ context.Context) (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.

func (*TransparentProxy) Start

func (p *TransparentProxy) Start(ctx context.Context) error

Start starts the transparent proxy. nolint:gocyclo // This function handles multiple startup scenarios and is complex by design

func (*TransparentProxy) Stop

func (p *TransparentProxy) Stop(ctx context.Context) error

Stop stops the transparent proxy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL