barrel_mcp_clients (barrel_mcp v3.0.0)
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.
The registry is the supervision tree: barrel_mcp_client_sup holds one barrel_mcp_client_shell per ServerId, and the shell holds the client. A restart keeps the id bound to the new pid, and there is no second table to fall out of step with it.
Summary
Functions
Snapshot the registry as [{ServerId, Pid}].
Start a supervised barrel_mcp_client worker registered as ServerId. Fails with {already_registered, Pid} if a worker already holds that id, and {restarting, ServerId} while its shell is still retrying a failed restart of it.
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 running, including while a restart is pending.
Functions
Snapshot the registry as [{ServerId, Pid}].
-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, and {restarting, ServerId} while its shell is still retrying a failed restart of it.
Example:
{ok, _} = barrel_mcp_clients:start_client(<<"github">>, #{
transport => {http, <<"https://mcp.github.example/">>},
auth => {bearer, GhToken}
}).
-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 running, including while a restart is pending.