ExMCP.Server (ex_mcp v1.0.0-rc.1)
View SourcePublic server-side helpers for running MCP servers.
Server implementations should use ExMCP.Server.Handler directly. For a
declarative handler DSL, combine it with ExMCP.Server.DSL:
defmodule MyServer do
use ExMCP.Server.Handler
use ExMCP.Server.DSL
tool "echo", "Echo input" do
param :message, :string, required: true
run fn %{message: message}, state ->
{:ok, %{text: message}, state}
end
end
endUse ExMCP.Server.HandlerServer.start_link/1 when you need a transport-aware
process for a handler module.
Summary
Functions
Sends a cancellation notification to the server.
Sends a sampling/createMessage request to the connected client.
Gets the list of pending request IDs on the server.
Lists roots available from the connected client.
Sends a progress notification to the client.
Sends a progress notification with a total to the client.
Notifies subscribed clients that the prompts list has changed.
Sends a resource update notification for subscribed clients.
Notifies subscribed clients that the resource list has changed.
Notifies the client that the server's roots have changed.
Notifies subscribed clients that the tools list has changed.
Sends a ping request to the connected client.
Sends a log message through the server.
Functions
@spec cancel_request(GenServer.server(), ExMCP.Types.request_id(), String.t() | nil) :: :ok
Sends a cancellation notification to the server.
@spec create_message(GenServer.server(), map()) :: {:ok, map()} | {:error, term()}
Sends a sampling/createMessage request to the connected client.
@spec get_pending_requests(GenServer.server()) :: [ExMCP.Types.request_id()]
Gets the list of pending request IDs on the server.
@spec list_roots(GenServer.server(), timeout()) :: {:ok, %{roots: [map()]}} | {:error, any()}
Lists roots available from the connected client.
@spec notify_progress(GenServer.server(), any(), number()) :: :ok
Sends a progress notification to the client.
@spec notify_progress(GenServer.server(), any(), number(), number()) :: :ok
Sends a progress notification with a total to the client.
@spec notify_prompts_changed(GenServer.server()) :: :ok
Notifies subscribed clients that the prompts list has changed.
@spec notify_resource_update(GenServer.server(), String.t()) :: :ok
Sends a resource update notification for subscribed clients.
@spec notify_resources_changed(GenServer.server()) :: :ok
Notifies subscribed clients that the resource list has changed.
@spec notify_roots_changed(GenServer.server()) :: :ok
Notifies the client that the server's roots have changed.
@spec notify_tools_changed(GenServer.server()) :: :ok
Notifies subscribed clients that the tools list has changed.
@spec ping(GenServer.server(), timeout()) :: {:ok, map()} | {:error, any()}
Sends a ping request to the connected client.
@spec send_log_message(GenServer.server(), atom() | String.t(), String.t(), map()) :: :ok
Sends a log message through the server.