ExMCP.TransportManager (ex_mcp v0.9.2)

View Source

Transport abstraction layer with fallback mechanisms.

Provides a unified interface for transport selection and automatic fallback when primary transports fail. Supports configuration-based transport priority and health checking.

Features

  • Smart transport selection: Automatically choose best available transport
  • Fallback mechanisms: Try multiple transports in priority order
  • Health checking: Verify transport availability before use
  • Configuration-driven: Define transport priorities via config
  • Error recovery: Handle transport failures gracefully

Example

opts = [
  transports: [
    {ExMCP.Transport.HTTP, [url: "http://localhost:8080"]},
    {ExMCP.Transport.Stdio, [command: "my-server"]},
    {ExMCP.Transport.SSE, [url: "http://localhost:8080/events"]}
  ],
  fallback_strategy: :sequential,
  health_check_timeout: 5_000
]

{:ok, {transport_mod, transport_state}} = TransportManager.connect(opts)

Summary

Functions

Connects using the best available transport from the provided list.

Gets the default transport configuration for common scenarios.

Checks if a transport module is available and healthy.

Types

connect_result()

@type connect_result() :: {:ok, {module(), any()}} | {:error, any()}

fallback_strategy()

@type fallback_strategy() :: :sequential | :parallel | :fastest

transport_spec()

@type transport_spec() :: {module(), keyword()}

Functions

connect(opts)

@spec connect(keyword()) :: connect_result()

Connects using the best available transport from the provided list.

Options

  • :transports - List of {transport_module, opts} tuples in priority order
  • :fallback_strategy - How to handle fallbacks (:sequential, :parallel, :fastest)
  • :health_check_timeout - Timeout for transport health checks (default: 5000ms)
  • :max_retries - Maximum retries per transport (default: 2)
  • :retry_interval - Interval between retries (default: 1000ms)

default_config(atom)

@spec default_config(atom()) :: keyword()

Gets the default transport configuration for common scenarios.

health_check(transport_mod, transport_opts, timeout \\ 5000)

@spec health_check(module(), keyword(), timeout()) :: :ok | {:error, any()}

Checks if a transport module is available and healthy.