ExMCP.Transport.Beam.ServiceRegistry (ex_mcp v0.10.0)

View Source

Distributed service registry for BEAM transport clustering.

Manages registration, discovery, and lifecycle of MCP services across the cluster. Supports multiple discovery strategies and provides efficient lookup and filtering capabilities.

Features

  • Multiple Strategies: Local registry, distributed registry, DNS, Consul
  • Efficient Lookups: Fast service discovery with flexible filtering
  • Circuit Breakers: Track and manage service failures
  • Health Tracking: Monitor service health and availability
  • Atomic Operations: Consistent state management across nodes

Discovery Strategies

  • :local_registry - ETS-based local registry (single node)
  • :distributed_registry - Distributed ETS with automatic synchronization
  • :dns - DNS-based service discovery
  • :consul - Consul service registry integration

Summary

Functions

Returns a specification to start this module under a supervisor.

Discovers services matching the given filters.

Gets a specific service by ID.

Gets registry statistics.

Records a failure for a service's circuit breaker.

Records a success for a service's circuit breaker.

Registers a service in the registry.

Removes all services from a specific node.

Starts the service registry with the given strategy.

Stops the service registry.

Unregisters a service from the registry.

Updates an existing service registration.

Types

service_entry()

@type service_entry() :: %{
  id: String.t(),
  name: String.t(),
  version: String.t() | nil,
  capabilities: [String.t()] | nil,
  node: atom(),
  pid: pid(),
  metadata: map(),
  health_check: map() | nil,
  circuit_breaker: ExMCP.Transport.Beam.CircuitBreaker.t() | nil,
  registered_at: integer(),
  last_seen: integer()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

discover(registry, filters \\ %{})

@spec discover(GenServer.server(), map()) ::
  {:ok, [service_entry()]} | {:error, term()}

Discovers services matching the given filters.

get(registry, service_id)

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

Gets a specific service by ID.

get_stats(registry)

@spec get_stats(GenServer.server()) :: map()

Gets registry statistics.

record_failure(registry, service_id)

@spec record_failure(GenServer.server(), String.t()) :: :ok

Records a failure for a service's circuit breaker.

record_success(registry, service_id)

@spec record_success(GenServer.server(), String.t()) :: :ok

Records a success for a service's circuit breaker.

register(registry, service_info)

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

Registers a service in the registry.

remove_node_services(registry, node_name)

@spec remove_node_services(GenServer.server(), atom()) :: :ok

Removes all services from a specific node.

start_link(config)

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

Starts the service registry with the given strategy.

stop(registry)

@spec stop(GenServer.server()) :: :ok

Stops the service registry.

unregister(registry, service_id)

@spec unregister(GenServer.server(), String.t()) :: :ok

Unregisters a service from the registry.

update(registry, service_id, service_info)

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

Updates an existing service registration.