ExMCP.Server.Legacy (ex_mcp v0.9.2)

View Source

Legacy handler-based server implementation.

This module provides compatibility for the old handler-based server API that uses the ExMCP.Server.Handler behaviour. It's primarily used for testing and legacy code that hasn't been migrated to the DSL-based approach.

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.start_link(transport: :test, handler: MyHandler)

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts a legacy handler-based server.

Types

handler_module()

@type handler_module() :: module()

state()

@type state() :: %{
  handler_module: handler_module(),
  handler_state: any(),
  transport: any(),
  transport_state: any(),
  protocol_version: String.t() | nil
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts a legacy handler-based server.

Options

  • :handler - Module implementing ExMCP.Server.Handler behaviour (required)
  • :transport - Transport type (:test, :stdio, :http, etc.)
  • Other options are passed to the transport and handler