ExMCP.Transport.Beam (ex_mcp v0.1.0)

View Source

BEAM message passing transport for MCP.

This transport uses native Erlang message passing for communication between MCP clients and servers running on the same BEAM VM or distributed across Erlang nodes.

Benefits:

  • Zero serialization overhead for local connections
  • Built-in supervision and fault tolerance
  • Native distributed support (connect to remote BEAM nodes)
  • Better performance for Elixir-based MCP tools
  • Maintains supervision tree integrity

Supports both:

  • Local connections (same VM): Uses direct process references
  • Distributed connections (remote nodes): Uses {name, node} tuples

Summary

Functions

Discovers BEAM transport servers across the cluster.

Discovers BEAM transport servers on the current node.

Registers a server on the current node for discovery.

Starts a BEAM transport server that can accept connections.

Types

distributed_config()

@type distributed_config() :: [{:target, {atom(), node()}}]

local_config()

@type local_config() :: [{:target, pid()}]

server_config()

@type server_config() :: [name: atom(), node: node() | nil]

t()

@type t() :: %ExMCP.Transport.Beam{
  client_pid: pid(),
  connection_ref: reference() | nil,
  mode: :local | :distributed,
  node_monitor: reference() | nil,
  target: pid() | {atom(), node()}
}

Functions

discover_cluster_servers()

@spec discover_cluster_servers() :: [map()]

Discovers BEAM transport servers across the cluster.

discover_local_servers()

@spec discover_local_servers() :: [map()]

Discovers BEAM transport servers on the current node.

register_server(name, server_info)

@spec register_server(atom(), map()) :: :ok

Registers a server on the current node for discovery.

This allows the server to be found by clients using ExMCP.Discovery functions.

start_server(name, handler_module, opts \\ [])

@spec start_server(atom(), module(), keyword()) :: {:ok, pid()} | {:error, any()}

Starts a BEAM transport server that can accept connections.

This creates a named process that MCP clients can connect to using the BEAM transport.