# `MCP.Server`
[🔗](https://github.com/JohnSmall/mcp-elixir-sdk/blob/v1.0.1/lib/mcp/server.ex#L1)

MCP server implementation.

A GenServer that handles incoming MCP client requests via a pluggable
transport. Routes requests to a handler module implementing the
`MCP.Server.Handler` behaviour.

## Usage

    defmodule MyHandler do
      @behaviour MCP.Server.Handler

      @impl true
      def init(_opts), do: {:ok, %{}}

      @impl true
      def handle_list_tools(_cursor, state) do
        tools = [%{"name" => "echo", "description" => "Echoes input"}]
        {:ok, tools, nil, state}
      end

      @impl true
      def handle_call_tool("echo", %{"message" => msg}, state) do
        {:ok, [%{"type" => "text", "text" => msg}], state}
      end
    end

    {:ok, server} = MCP.Server.start_link(
      transport: {MCP.Transport.Stdio, mode: :server},
      handler: {MyHandler, []},
      server_info: %{name: "my_server", version: "1.0.0"}
    )

## Options

  * `:transport` — `{module, opts}` transport spec. The server starts the
    transport in its init, setting itself as the owner.
  * `:handler` — `{module, opts}` handler spec. The module must implement
    `MCP.Server.Handler`.
  * `:server_info` — `%Implementation{}` or map with `:name` and `:version`.
  * `:instructions` — optional string instructions for the client.
  * `:request_timeout` — default timeout in ms for server-initiated
    requests (default: 30_000).

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `client_capabilities`

Returns the client capabilities from initialization.

# `client_info`

Returns the client info from initialization.

# `close`

Closes the server and its transport.

# `log`

Sends a log message notification to the client.

Respects the log level set by the client via `logging/setLevel`.
Messages below the current level are silently dropped.

# `notify_prompts_changed`

Sends a `notifications/prompts/list_changed` notification to the client.

# `notify_resource_updated`

Sends a `notifications/resources/updated` notification for a specific URI.

# `notify_resources_changed`

Sends a `notifications/resources/list_changed` notification to the client.

# `notify_tools_changed`

Sends a `notifications/tools/list_changed` notification to the client.

# `request_elicitation`

Sends an `elicitation/create` request to the client.

Returns `{:ok, result}` or `{:error, reason}`.
Requires the client to have declared elicitation capability.

# `request_roots`

Sends a `roots/list` request to the client.

Returns `{:ok, result}` or `{:error, reason}`.
Requires the client to have declared roots capability.

# `request_sampling`

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

Returns `{:ok, result}` or `{:error, reason}`.
Requires the client to have declared sampling capability.

# `send_progress`

Sends a progress notification to the client.

# `start_link`

Starts the server GenServer and its transport.

# `status`

Returns the current server status.

# `transport`

Returns the transport pid (useful for testing with MockTransport).

---

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