ExMCP.Server.HandlerServer (ex_mcp v1.0.0-rc.0)
View SourceTransport-aware process for ExMCP.Server.Handler modules.
This module runs a handler module behind the MCP transports that need a server process, including the in-memory test transport.
Usage
# Handler module implementing ExMCP.Server.Handler
defmodule MyHandler do
use ExMCP.Server.Handler
@impl true
def handle_initialize(params, state) do
{:ok, %{
protocolVersion: "2025-03-26",
serverInfo: %{name: "test-server", version: "1.0.0"},
capabilities: %{tools: %{}}
}, state}
end
@impl true
def handle_list_tools(_cursor, state) do
tools = [
%{
name: "ping",
description: "Simple ping tool",
inputSchema: %{type: "object", properties: %{}}
}
]
{:ok, tools, nil, state}
end
end
# Start the server
{:ok, server} = ExMCP.Server.HandlerServer.start_link(transport: :test, handler: MyHandler)
Summary
Functions
Returns a specification to start this module under a supervisor.
Starts a handler-based server.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec start_link(keyword()) :: GenServer.on_start()
Starts a handler-based server.
Options
:handler- Module implementingExMCP.Server.Handlerbehaviour (required):transport- Transport type (:test,:stdio,:http, etc.):handler_args- Optional term passed tohandler.init/1(default:[])- Other options are passed to the transport