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

Public 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
    end

Use `ExMCP.Server.HandlerServer.start_link/1` when you need a transport-aware
process for a handler module.

> #### Deprecated API {: .warning}
>
> `ExMCP.Server.Tools` (and `Tools.Simplified`) are deprecated, retained
> throughout 1.x, and planned for removal in **2.0.0**. Prefer
> `ExMCP.Server.DSL` for new code.

> #### Protocol-deprecated features {: .warning}
>
> MCP 2026-07-28 deprecated Roots, Sampling, and protocol Logging. ExMCP
> retains their public APIs throughout 1.x for legacy and 2026-07-28
> compatibility. New implementations should pass directories through tool
> parameters, resource URIs, or server configuration; call LLM provider APIs
> directly; and use stderr or OpenTelemetry for operational logs.

# `cancel_request`

```elixir
@spec cancel_request(GenServer.server(), ExMCP.Types.request_id(), String.t() | nil) ::
  :ok
```

Sends a cancellation notification to the server.

# `create_message`

```elixir
@spec create_message(GenServer.server(), map()) :: {:ok, map()} | {:error, term()}
```

Sends a `sampling/createMessage` request to the connected client.

MCP Sampling is deprecated as of 2026-07-28. This API remains available
throughout ExMCP 1.x for compatibility. New implementations should integrate
directly with an LLM provider API.

# `get_pending_requests`

```elixir
@spec get_pending_requests(GenServer.server()) :: [ExMCP.Types.request_id()]
```

Gets the list of pending request IDs on the server.

# `list_roots`

```elixir
@spec list_roots(GenServer.server(), timeout()) ::
  {:ok, %{roots: [map()]}} | {:error, any()}
```

Lists roots available from the connected client.

MCP Roots is deprecated as of 2026-07-28. This API remains available
throughout ExMCP 1.x for compatibility. New implementations should pass
directories or files via tool parameters, resource URIs, or server
configuration.

# `notify_progress`

```elixir
@spec notify_progress(GenServer.server(), any(), number()) :: :ok
```

Sends a progress notification to the client.

# `notify_progress`

```elixir
@spec notify_progress(GenServer.server(), any(), number(), number()) :: :ok
```

Sends a progress notification with a total to the client.

# `notify_prompts_changed`

```elixir
@spec notify_prompts_changed(GenServer.server()) :: :ok
```

Notifies subscribed clients that the prompts list has changed.

# `notify_resource_update`

```elixir
@spec notify_resource_update(String.t()) :: %{
  subscribers: non_neg_integer(),
  delivered: non_neg_integer()
}
```

Sends a resource update to streamable-HTTP clients subscribed to `uri`.

# `notify_resource_update`

```elixir
@spec notify_resource_update(GenServer.server(), String.t()) :: :ok
```

Sends a resource update notification for subscribed clients.

# `notify_resources_changed`

```elixir
@spec notify_resources_changed(GenServer.server()) :: :ok
```

Notifies subscribed clients that the resource list has changed.

# `notify_roots_changed`

```elixir
@spec notify_roots_changed(GenServer.server()) :: :ok
```

Notifies the client that the server's roots have changed.

MCP Roots is deprecated as of 2026-07-28 and retained throughout ExMCP 1.x.
Prefer explicit tool parameters, resource URIs, or server configuration for
new implementations.

# `notify_tools_changed`

```elixir
@spec notify_tools_changed(GenServer.server()) :: :ok
```

Notifies subscribed clients that the tools list has changed.

# `ping`

```elixir
@spec ping(GenServer.server(), timeout()) :: {:ok, map()} | {:error, any()}
```

Sends a ping request to the connected client.

# `send_log_message`

```elixir
@spec send_log_message(GenServer.server(), atom() | String.t(), String.t(), map()) ::
  :ok
```

Sends a log message through the server.

MCP protocol Logging is deprecated as of 2026-07-28. This API remains
available throughout ExMCP 1.x for compatibility. Prefer stderr on stdio or
OpenTelemetry for new observability integrations.

---

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