# `ExMCP.Server.Transport`
[🔗](https://github.com/azmaveth/ex_mcp/blob/v1.0.0/lib/ex_mcp/server/transport.ex#L1)

Transport configuration and lifecycle management for ExMCP servers.

This module provides unified transport startup and configuration for MCP servers,
supporting stdio, HTTP, BEAM-local, and test 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)

    # Explicitly retain the deprecated 2024-11-05 HTTP+SSE transport
    {:ok, _pid} = ExMCP.Server.Transport.start_server(MyServer, server_info, tools,
      transport: :http,
      legacy_http_sse: true,
      port: 8080
    )

# `list_transports`

```elixir
@spec list_transports() :: map()
```

Lists all available transports and their status.

# `server_info`

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

Gets information about a running server.

# `start_beam_server`

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

Starts a BEAM-local MCP server.

The BEAM transport uses Erlang message passing for high-performance local
communication between processes while preserving MCP-shaped messages.

# `start_http_server`

```elixir
@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_server`

```elixir
@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`, `:beam`, `:test`)
* `:port` - Port number for HTTP transports (default: 4000)
* `:host` - Host for HTTP transports (default: "localhost")
* `:cors_enabled` - Enable CORS for HTTP transports (default: `false`, the
  same default `ExMCP.HttpPlug` uses)
* `:legacy_http_sse` - Enable the deprecated MCP 2024-11-05 HTTP+SSE
  transport (default: `false`). Retained throughout ExMCP 1.x
* `:sse_enabled` - Deprecated rc.5 alias for `:legacy_http_sse`
* `:allowed_hosts` - Host-header allow-list passed to `ExMCP.HttpPlug`.
  Defaults to the localhost names when binding to a localhost address
  (DNS rebinding protection), otherwise `:any`
* `:allowed_origins` - Origin allow-list passed to `ExMCP.HttpPlug`.
  Defaults to localhost origins for the bound port when binding to a
  localhost address, otherwise `[]` (reject all cross-origin browsers)

## 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`

```elixir
@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`

```elixir
@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`

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

Stops a running MCP server.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
