ExMCP.Server.Transport (ex_mcp v0.10.0)

View Source

Transport configuration and lifecycle management for ExMCP servers.

This module provides unified transport startup and configuration for MCP servers, supporting stdio, HTTP, and Server-Sent Events (SSE) transports.

Usage

# Start with HTTP transport
{:ok, _pid} = ExMCP.Server.Transport.start_server(MyServer, server_info, tools, transport: :http, port: 4000)

# Start with stdio transport
{:ok, _pid} = ExMCP.Server.Transport.start_server(MyServer, server_info, tools, transport: :stdio)

# Start with SSE-enabled HTTP transport
{:ok, _pid} = ExMCP.Server.Transport.start_server(MyServer, server_info, tools, transport: :sse, port: 8080)

Summary

Functions

Lists all available transports and their status.

Gets information about a running server.

Starts an HTTP-based MCP server using Cowboy.

Starts a native Erlang process-based MCP server.

Starts a server with the specified transport configuration.

Starts a stdio-based MCP server.

Starts a test transport-based MCP server.

Stops a running MCP server.

Functions

list_transports()

@spec list_transports() :: map()

Lists all available transports and their status.

server_info(server)

@spec server_info(pid() | atom()) :: {:ok, map()} | {:error, term()}

Gets information about a running server.

start_http_server(module, server_info, tools, opts)

@spec start_http_server(module(), map(), list(), keyword()) ::
  {:ok, pid()} | {:error, term()}

Starts an HTTP-based MCP server using Cowboy.

The HTTP transport allows integration with web applications and provides REST-like access to MCP functionality.

start_native_server(module, server_info, tools, opts)

@spec start_native_server(module(), map(), list(), keyword()) ::
  {:ok, pid()} | {:error, term()}

Starts a native Erlang process-based MCP server.

The native transport uses Erlang message passing for high-performance local communication between processes.

start_server(module, server_info, tools, opts \\ [])

@spec start_server(module(), map(), list(), keyword()) ::
  {:ok, pid()} | {:error, term()}

Starts a server with the specified transport configuration.

Options

  • :transport - The transport type (:stdio, :http, :sse, :native, :test)
  • :port - Port number for HTTP/SSE transports (default: 4000)
  • :host - Host for HTTP/SSE transports (default: "localhost")
  • :cors_enabled - Enable CORS for HTTP transports (default: true)
  • :sse_enabled - Enable SSE for HTTP transports (default: false, true for :sse transport)

Examples

# HTTP server
ExMCP.Server.Transport.start_server(MyServer, %{name: "my-server", version: "1.0.0"}, [],
  transport: :http, port: 4000)

# Stdio server
ExMCP.Server.Transport.start_server(MyServer, %{name: "my-server", version: "1.0.0"}, [],
  transport: :stdio)

start_stdio_server(module, server_info, tools, opts)

@spec start_stdio_server(module(), map(), list(), keyword()) ::
  {:ok, pid()} | {:error, term()}

Starts a stdio-based MCP server.

The stdio transport communicates via standard input/output, making it suitable for command-line tools and scripting environments.

start_test_server(module, server_info, tools, opts)

@spec start_test_server(module(), map(), list(), keyword()) ::
  {:ok, pid()} | {:error, term()}

Starts a test transport-based MCP server.

The test transport uses in-memory communication for efficient testing without external processes or network connections.

stop_server(server)

@spec stop_server(pid() | atom()) :: :ok

Stops a running MCP server.