Documentation
¶
Overview ¶
Package httputil provides shared HTTP infrastructure for proxy support, custom TLS, and header propagation across all MCP servers.
All outbound HTTP clients (GitHub API, LLM endpoints) use this package so that proxy, CA certificate, and header-forwarding settings apply uniformly.
Index ¶
- Constants
- func DefaultClient(timeout time.Duration) *http.Client
- func HeaderCaptureMiddleware(allowList []string, next http.Handler) http.Handler
- func HeadersFromContext(ctx context.Context) http.Header
- func NewClient(cfg ProxyConfig, timeout time.Duration) (*http.Client, error)
- func NewTransport(cfg ProxyConfig) (*http.Transport, error)
- func WithHeaders(ctx context.Context, h http.Header) context.Context
- type ProxyConfig
Constants ¶
const DialTimeout = 30 * time.Second
DialTimeout is a sensible default for custom transports.
Variables ¶
This section is empty.
Functions ¶
func DefaultClient ¶
DefaultClient creates a minimal client that still honors env-based proxy and propagates context headers. Use when no explicit ProxyConfig is needed.
func HeaderCaptureMiddleware ¶
HeaderCaptureMiddleware returns an http.Handler that captures selected headers from inbound requests into the request context so that downstream MCP tool handlers can propagate them to outbound calls.
When allowList is empty, all headers are captured.
func HeadersFromContext ¶
HeadersFromContext retrieves previously stored headers. Returns nil if none.
func NewClient ¶
NewClient creates an *http.Client with proxy/TLS settings and the given timeout. Outbound requests automatically propagate context headers (see WithHeaders).
func NewTransport ¶
func NewTransport(cfg ProxyConfig) (*http.Transport, error)
NewTransport creates an *http.Transport configured with proxy, TLS, and header-propagation settings. The returned transport automatically forwards headers stored in the request context (see WithHeaders / HeadersFromContext).
Types ¶
type ProxyConfig ¶
type ProxyConfig struct {
// ProxyURL overrides the proxy. When empty, Go's default behavior applies:
// HTTP_PROXY / HTTPS_PROXY / NO_PROXY environment variables are honored.
ProxyURL string `yaml:"proxy_url"`
// CACertFile is a PEM-encoded CA bundle appended to the system pool.
// Typically used for corporate TLS-intercepting proxies.
CACertFile string `yaml:"ca_cert"`
// TLSInsecureSkipVerify disables certificate verification. Use for testing only.
TLSInsecureSkipVerify bool `yaml:"tls_insecure_skip_verify"`
// HeaderPassthrough lists HTTP header names that should be forwarded from
// incoming MCP requests to outbound calls (GitHub, LLM). Case-insensitive.
// When empty, no headers are forwarded.
HeaderPassthrough []string `yaml:"header_passthrough"`
}
ProxyConfig holds network settings shared across all HTTP clients.