ExMCP.ServerManager (ex_mcp v0.1.0)

View Source

Manages multiple MCP server connections.

The ServerManager provides a centralized way to:

  • Start and stop multiple MCP servers
  • Route requests to appropriate servers
  • Monitor server health
  • Handle server lifecycle

Summary

Functions

Returns a specification to start this module under a supervisor.

Discovers and starts servers based on configuration.

Gets information about a specific server.

Lists all managed servers.

Routes a request to the appropriate server.

Starts the server manager.

Stops a running MCP server.

Types

server_spec()

@type server_spec() :: %{name: String.t(), module: module(), config: keyword()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

discover_and_start(manager \\ __MODULE__)

@spec discover_and_start(GenServer.server()) :: {:ok, [String.t()]} | {:error, any()}

Discovers and starts servers based on configuration.

get_server(manager \\ __MODULE__, name)

@spec get_server(GenServer.server(), String.t()) ::
  {:ok, map()} | {:error, :not_found}

Gets information about a specific server.

list_servers(manager \\ __MODULE__)

@spec list_servers(GenServer.server()) :: [
  %{name: String.t(), pid: pid(), status: atom()}
]

Lists all managed servers.

route_request(manager \\ __MODULE__, server_name, request)

@spec route_request(GenServer.server(), String.t(), any()) ::
  {:ok, any()} | {:error, any()}

Routes a request to the appropriate server.

start_link(opts \\ [])

Starts the server manager.

start_server(manager \\ __MODULE__, server_spec)

@spec start_server(GenServer.server(), server_spec()) ::
  {:ok, pid()} | {:error, any()}

Starts a new MCP server.

stop_server(manager \\ __MODULE__, name)

@spec stop_server(GenServer.server(), String.t()) :: :ok | {:error, :not_found}

Stops a running MCP server.