barrel_mcp_clients (barrel_mcp v2.0.2)
View SourceFederation registry for connected MCP clients.
Lets a host application keep one supervised barrel_mcp_client per remote MCP server, looked up by an opaque ServerId the host chooses (typically a binary name like <<"github">>). Tool-name namespacing across servers is the host's policy and is not enforced here.
This module is a tiny gen_server whose only job is to own the lookup ETS table (so the table outlives any single caller) and to serialize registration so two callers cannot race on the same ServerId. Lookups go directly to ETS without crossing the process boundary.
Summary
Functions
Snapshot the registry as [{ServerId, Pid}]. ETS-backed.
Start a supervised barrel_mcp_client worker registered as ServerId. Fails with {already_registered, Pid} if a worker already holds that id.
Start the registry. Called by barrel_mcp_sup; you don't normally call this directly.
Stop the client worker registered as ServerId. Returns {error, not_found} if no worker holds that id.
Look up a worker pid by its ServerId. Returns undefined if none is registered. ETS-backed; safe to call from any process.
Functions
Snapshot the registry as [{ServerId, Pid}]. ETS-backed.
-spec start_client(term(), barrel_mcp_client:connect_spec()) -> {ok, pid()} | {error, term()}.
Start a supervised barrel_mcp_client worker registered as ServerId. Fails with {already_registered, Pid} if a worker already holds that id.
Example:
{ok, _} = barrel_mcp_clients:start_client(<<"github">>, #{
transport => {http, <<"https://mcp.github.example/">>},
auth => {bearer, GhToken}
}).
Start the registry. Called by barrel_mcp_sup; you don't normally call this directly.
-spec stop_client(term()) -> ok | {error, not_found}.
Stop the client worker registered as ServerId. Returns {error, not_found} if no worker holds that id.
Look up a worker pid by its ServerId. Returns undefined if none is registered. ETS-backed; safe to call from any process.