types

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package types provides common types and interfaces for the transport package used in communication between the client and MCP server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidProxyMode added in v0.1.3

func IsValidProxyMode(mode string) bool

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 middleware functions to apply to the transport.
	// These are applied in order, with the first middleware being the outermost wrapper.
	Middlewares []MiddlewareFunction

	// 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

	// 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) (Middleware, error)

MiddlewareFactory is a function that creates a Middleware instance based on the provided configuration.

type MiddlewareFunction added in v0.2.4

type MiddlewareFunction func(http.Handler) http.Handler

MiddlewareFunction is a function that wraps an http.Handler with additional functionality.

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.

const (
	// ProxyModeSSE is the proxy mode for SSE.
	ProxyModeSSE ProxyMode = "sse"
	// ProxyModeStreamableHTTP is the proxy mode for streamable HTTP.
	ProxyModeStreamableHTTP ProxyMode = "streamable-http"
)

func (ProxyMode) String added in v0.1.3

func (p ProxyMode) String() string

type Transport

type Transport interface {
	// Mode returns the transport mode.
	Mode() TransportType

	// ProxyPort returns the port used by the transport.
	ProxyPort() int

	// Setup prepares the transport for use.
	// The runtime parameter provides access to container operations.
	// The permissionProfile is used to configure container permissions.
	// The k8sPodTemplatePatch is a JSON string to patch the Kubernetes pod template.
	Setup(ctx context.Context, runtime rt.Deployer, containerName string, image string, cmdArgs []string,
		envVars, labels map[string]string, permissionProfile *permissions.Profile, k8sPodTemplatePatch string,
		isolateNetwork bool, ignoreConfig *ignore.Config) error

	// 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.

Jump to

Keyboard shortcuts

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