MCP Server with SSE in Elixir
Build fast MCP server applications with an Elixir SSE implementation to stream events effortlessly and spin up production-ready servers quickly.
npx -y @kEND/mcp_sseOverview
MCP Server with SSE in Elixir provides a lightweight implementation of a Model Context Protocol (MCP) server that uses Server-Sent Events (SSE) to stream real-time model context and events to clients. Built in Elixir, it leverages the BEAM’s concurrency and supervision model to keep long-lived streaming connections stable and efficient, making it well suited for low-latency event delivery from backend model services to dashboards, agents, or other consumers.
This project is useful when you need a production-ready, simple-to-integrate server that exposes streaming endpoints for model context or incremental updates. It is designed to be embedded into an Elixir application (Plug / Cowboy / Phoenix) and supports standard SSE clients (EventSource in browsers, curl -N, or custom consumers). Use it to stream JSON-encoded events, keep connections alive with heartbeats, and manage client subscriptions with a minimal operational footprint.
Features
- SSE-based streaming for real-time event delivery
- Designed to integrate with Plug / Cowboy or Phoenix endpoints
- JSON payloads for events (compatible with typical model context formats)
- Connection keep-alive and heartbeat support to prevent idle timeouts
- Lightweight and fault-tolerant: fits into Elixir supervision trees
- Example client usage (curl, EventSource) and simple integration patterns
- CORS-friendly configuration options (for browser-based clients)
Installation / Configuration
Add the library to your mix.exs dependencies (GitHub source):
[
]
end
Fetch dependencies and compile:
Example configuration (config/config.exs). Adjust keys according to your app’s needs — the library reads options like mount path, heartbeat interval, and CORS settings:
config :mcp_sse, McpSse,
path: , # mount path for the MCP endpoints
heartbeat_ms: 15_000Common Issues & Solutions
OpenAI and Anthropic APIs cannot connect to the MCP server even after bypassing the protocol version check with a wildcard. MCP inspector / Cursor AI still work, so the server is reachable but the API clients fail to establish usable connections.
I ran into this too! The real issue for me was TLS/SNI and streaming/HTTP semantics rather than the protocol-version check. MCP was presenting a self-signed cert without the public hostname in the SAN and it didn't support HTTP/1.1 chunked transfer/keep-alive used by OpenAI/Anthropic streaming clients. I solved it by issuing a proper cert with the server hostname in the SAN, enabling SNI on the TLS listener, and switching the MCP proxy to support HTTP/1.1 chunked transfer and keep-alive. I also ensured the proxy forwards the Authorization header and rewrites Host to the upstream name. After that both SDKs connected and streaming completions worked.
When installing the MCP, the server crashes with a Plug.Conn.NotSentError from Bandit because an SSE handler returns without sending a response. The pipeline complains that a response was neither set nor sent before the connection handler finishes.
I ran into this too! The problem was that my SSE plug never started a chunked response, so Bandit rejected the connection when the plug returned. Fix: set the Content-Type to text/event-stream and call Plug.Conn.send_chunked(conn, 200) immediately, then stream events with Plug.Conn.chunk/2 (I spawn a separate process to push chunks so the plug won’t block). Also return the conn and call Plug.Conn.halt(conn) so the pipeline doesn’t try to send another response. After switching to send_chunked + chunk and halting, the error disappeared.