Documentation
¶
Overview ¶
Package types provides common types and interfaces for the transport package used in communication between the client and MCP server.
Index ¶
- Variables
- func GetSupportedProviderNames() []string
- func IsValidProxyMode(mode string) bool
- type Config
- type Middleware
- type MiddlewareConfig
- type MiddlewareFactory
- type MiddlewareFunction
- type MiddlewareRunner
- type NamedMiddleware
- type Proxy
- type ProxyMode
- type RunnerConfig
- type Transport
- type TransportType
- type TunnelProvider
Constants ¶
This section is empty.
Variables ¶
var SupportedTunnelProviders = map[string]TunnelProvider{ "ngrok": &ngrok.TunnelProvider{}, }
SupportedTunnelProviders maps provider names to their implementations.
Functions ¶
func GetSupportedProviderNames ¶ added in v0.2.6
func GetSupportedProviderNames() []string
GetSupportedProviderNames returns a list of supported tunnel provider names.
func IsValidProxyMode ¶ added in v0.1.3
IsValidProxyMode returns true if the given mode is a valid ProxyMode.
Types ¶
type Config ¶
type Config struct {
// Type is the type of transport to use.
Type TransportType
// ProxyPort is the port to use for network transports (host port).
ProxyPort int
// TargetPort is the port that the container will expose (container port).
// This is only applicable to SSE transport.
TargetPort int
// TargetHost is the host to forward traffic to.
// This is only applicable to SSE transport.
TargetHost string
// Host is the host to use for network transports.
Host string
// Deployer is the container runtime to use.
// This is used for container operations like creating, starting, and attaching.
Deployer rt.Deployer
// Debug indicates whether debug mode is enabled.
// If debug mode is enabled, containers will not be removed when stopped.
Debug bool
// Middlewares is a list of named middleware to apply to the transport.
// These are applied in order, with the first middleware being the outermost wrapper.
Middlewares []NamedMiddleware
// PrometheusHandler is an optional HTTP handler for Prometheus metrics endpoint.
// If provided, it will be exposed at /metrics on the transport's HTTP server.
PrometheusHandler http.Handler
// AuthInfoHandler is an optional HTTP handler for authentication information endpoint.
// If provided, it will be exposed at /.well-known/oauth-protected-resource on the transport's HTTP server.
AuthInfoHandler http.Handler
// TrustProxyHeaders indicates whether to trust X-Forwarded-* headers from reverse proxies
TrustProxyHeaders bool
// ProxyMode is the proxy mode for stdio transport ("sse" or "streamable-http")
ProxyMode ProxyMode
}
Config contains configuration options for a transport.
type Middleware ¶
type Middleware interface {
// Handler returns the middleware function used by the proxy.
Handler() MiddlewareFunction
// Close cleans up any resources used by the middleware.
Close() error
}
Middleware defines a middleware interceptor and a close method.
type MiddlewareConfig ¶ added in v0.2.4
type MiddlewareConfig struct {
// Type is a string representing the middleware type.
Type string `json:"type"`
// Parameters is a JSON object containing the middleware parameters.
// It is stored as a raw message to allow flexible parameter types.
Parameters json.RawMessage `json:"parameters" swaggertype:"object"`
}
MiddlewareConfig represents the configuration for a middleware. This is stored in the run config, and is used to instantiate the middleware.
func NewMiddlewareConfig ¶ added in v0.2.4
func NewMiddlewareConfig(middlewareType string, parameters any) (*MiddlewareConfig, error)
NewMiddlewareConfig creates a new MiddlewareConfig with the given type and parameters. The parameters are marshaled to JSON and stored in the Parameters field.
type MiddlewareFactory ¶ added in v0.2.4
type MiddlewareFactory func(config *MiddlewareConfig, runner MiddlewareRunner) error
MiddlewareFactory is a function that creates a Middleware instance based on the provided configuration and configures the runner with the middleware and any additional handlers it provides.
type MiddlewareFunction ¶ added in v0.2.4
MiddlewareFunction is a function that wraps an http.Handler with additional functionality.
type MiddlewareRunner ¶ added in v0.2.8
type MiddlewareRunner interface {
// AddMiddleware adds a middleware instance to the runner's middleware chain with a name for logging
AddMiddleware(name string, middleware Middleware)
// SetAuthInfoHandler sets the authentication info handler (used by auth middleware)
SetAuthInfoHandler(handler http.Handler)
// SetPrometheusHandler sets the Prometheus metrics handler (used by telemetry middleware)
SetPrometheusHandler(handler http.Handler)
// GetConfig returns a config interface for middleware to access runner configuration
GetConfig() RunnerConfig
}
MiddlewareRunner defines the interface that middleware can use to interact with the runner. This unified interface replaces the ad-hoc interfaces defined in each middleware package.
type NamedMiddleware ¶ added in v0.3.9
type NamedMiddleware struct {
Name string
Function MiddlewareFunction
}
NamedMiddleware pairs a middleware function with its name for logging purposes.
type Proxy ¶
type Proxy interface {
// Start starts the proxy.
Start(ctx context.Context) error
// Stop stops the proxy.
Stop(ctx context.Context) error
// GetMessageChannel returns the channel for messages to/from the destination.
GetMessageChannel() chan jsonrpc2.Message
// SendMessageToDestination sends a message to the destination.
SendMessageToDestination(msg jsonrpc2.Message) error
// ForwardResponseToClients forwards a response from the destination to clients.
ForwardResponseToClients(ctx context.Context, msg jsonrpc2.Message) error
}
Proxy defines the interface for proxying messages between clients and destinations.
type ProxyMode ¶ added in v0.1.3
type ProxyMode string
ProxyMode represents the proxy mode for stdio transport.
type RunnerConfig ¶ added in v0.2.8
type RunnerConfig interface {
GetPort() int
}
RunnerConfig defines the config interface needed by middleware to access runner configuration
type Transport ¶
type Transport interface {
// Mode returns the transport mode.
Mode() TransportType
// ProxyPort returns the port used by the transport.
ProxyPort() int
// Start initializes the transport and begins processing messages.
// The transport is responsible for container operations like attaching to stdin/stdout if needed.
Start(ctx context.Context) error
// Stop gracefully shuts down the transport.
Stop(ctx context.Context) error
// IsRunning checks if the transport is currently running.
IsRunning(ctx context.Context) (bool, error)
}
Transport defines the interface for MCP transport implementations. It provides methods for handling communication between the client and server.
type TransportType ¶
type TransportType string
TransportType represents the type of transport to use.
const ( // TransportTypeStdio represents the stdio transport. TransportTypeStdio TransportType = "stdio" // TransportTypeSSE represents the SSE transport. TransportTypeSSE TransportType = "sse" // TransportTypeStreamableHTTP represents the streamable HTTP transport. TransportTypeStreamableHTTP TransportType = "streamable-http" // TransportTypeInspector represents the transport mode for MCP Inspector. TransportTypeInspector TransportType = "inspector" )
func ParseTransportType ¶
func ParseTransportType(s string) (TransportType, error)
ParseTransportType parses a string into a transport type.
func (TransportType) String ¶
func (t TransportType) String() string
String returns the string representation of the transport type.