ExMCP.ServiceRegistry behaviour (ex_mcp v0.9.0)

View Source

Pluggable service registry behaviour for ExMCP.Native service discovery.

By default, uses ExMCP.ServiceRegistry.Local which wraps Elixir's built-in Registry module — zero external dependencies required.

For distributed clusters, configure the Horde adapter:

# config/config.exs
config :ex_mcp, :service_registry, ExMCP.ServiceRegistry.Horde

Implementing a Custom Adapter

Implement all callbacks defined in this module:

defmodule MyApp.CustomRegistry do
  @behaviour ExMCP.ServiceRegistry

  @impl true
  def child_specs(_opts), do: [...]

  @impl true
  def register(name, metadata), do: ...

  # ... etc
end

Summary

Callbacks

Returns child specs for the registry processes to be started under the supervision tree.

Lists all registered services as {name, pid, metadata} tuples.

Looks up the process registered under name.

Registers the calling process under name with the given metadata.

Unregisters the calling process from name.

Functions

Returns the configured service registry adapter.

Callbacks

child_specs(opts)

@callback child_specs(opts :: keyword()) :: [Supervisor.child_spec() | {module(), term()}]

Returns child specs for the registry processes to be started under the supervision tree.

list()

@callback list() :: [{atom(), pid(), map()}]

Lists all registered services as {name, pid, metadata} tuples.

lookup(name)

@callback lookup(name :: atom()) :: {:ok, pid()} | {:error, :not_found}

Looks up the process registered under name.

register(name, metadata)

@callback register(name :: atom(), metadata :: map()) :: :ok | {:error, term()}

Registers the calling process under name with the given metadata.

unregister(name)

@callback unregister(name :: atom()) :: :ok

Unregisters the calling process from name.

Functions

adapter()

@spec adapter() :: module()

Returns the configured service registry adapter.

Defaults to ExMCP.ServiceRegistry.Local.