Hermes.Server.Supervisor (hermes_mcp v0.10.0)
Supervisor for MCP server processes.
This supervisor manages the lifecycle of an MCP server, including:
- The Base server process that handles MCP protocol
- The transport layer (STDIO, StreamableHTTP, or SSE)
- Session supervisors for StreamableHTTP transport
The supervision strategy is :one_for_all
, meaning if any child
process crashes, all processes are restarted to maintain consistency.
Conditional Startup
The supervisor intelligently handles startup based on transport type:
- STDIO transport: Always starts
- StreamableHTTP/SSE transport: Conditional startup based on:
- Explicit
:start
option in transport config (highest priority) HERMES_MCP_SERVER
environment variable presentPHX_SERVER
environment variable present, for phoenix apps using releases- Phoenix
:serve_endpoints
internalr runtime config (usage withmix phx.server
) - Default:
true
(starts by default in production releases)
- Explicit
This ensures MCP servers start correctly in all environments:
- Mix releases: Use
PHX_SERVER=true
orHERMES_MCP_SERVER=true
- Development: Use
mix phx.server
- Tests/Tasks: Servers don't start unless explicitly configured
Configuration Examples
# Force start with transport option (highest priority)
{MyServer, transport: {:streamable_http, start: true}}
# Control via environment variables (works in releases)
PHX_SERVER=true ./my_app start
Supervision Tree
For STDIO transport:
Supervisor
├── Base Server
└── STDIO Transport
For StreamableHTTP transport:
Supervisor
├── Session.Supervisor
├── Base Server
└── StreamableHTTP Transport
Summary
Functions
Returns a specification to start this module under a supervisor.
Starts the server supervisor.
Types
@type sse() :: {:sse, keyword()}
@type start_option() :: {:transport, transport()} | {:name, Supervisor.name()}
@type stream_http() :: {:streamable_http, keyword()}
@type transport() :: :stdio | stream_http() | sse() | StubTransport
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec start_link(server :: module(), init_arg :: term(), [start_option()]) :: Supervisor.on_start()
Starts the server supervisor.
Parameters
server
- The module implementingHermes.Server.Behaviour
init_arg
- Argument passed to the server'sinit/1
callbackopts
- Options including::transport
- Transport configuration (required):name
- Supervisor name (optional, defaults to registered name):registry
- The custom registry to use to manage processes names (defaults toHermes.Server.Registry
)
Examples
# Start with STDIO transport
Hermes.Server.Supervisor.start_link(MyServer, [], transport: :stdio)
# Start with StreamableHTTP transport
Hermes.Server.Supervisor.start_link(MyServer, [],
transport: {:streamable_http, port: 8080}
)