barrel_mcp_agent (barrel_mcp v2.0.2)
View SourceMulti-server tool aggregator for agent hosts.
Sits on top of barrel_mcp_clients and turns the set of connected MCP clients into a single namespaced tool catalog the host can hand to an LLM, plus a router that dispatches a model's tool call back to the right MCP server.
Tool names are namespaced as <<"ServerId<Sep>ToolName">>. The default separator is <<":">>; override with the separator option on every call. Hosts that allow : in tool names should pick a separator that does not appear in any registered tool.
Typical agent loop:
Tools = barrel_mcp_agent:to_anthropic(),
%% ... ask the model with Tools, receive a tool_use block ...
{Name, Args} = barrel_mcp_tool_format:from_anthropic_call(Block),
{ok, Result} = barrel_mcp_agent:call_tool(Name, Args).
Summary
Functions
Route a model's tool call back to the right MCP server. NamespacedName is <<"ServerId<Sep>ToolName">>; the ServerId prefix selects the client and the ToolName suffix is forwarded. Errors
Return every tool from every registered client, with each tool's <<"name">> rewritten to <<"ServerId<Sep>ToolName">>. Servers that error out are skipped (with a logger:warning).
Aggregated tools in Anthropic Messages API format.
Aggregated tools in OpenAI Chat Completions tool format.
Types
Functions
Route a model's tool call back to the right MCP server. NamespacedName is <<"ServerId<Sep>ToolName">>; the ServerId prefix selects the client and the ToolName suffix is forwarded. Errors:
{error, no_separator}— the name does not contain the configured separator.{error, unknown_server}— no client is registered under the parsedServerId.- Any error returned by
barrel_mcp_client:call_tool/4.
-spec list_tools() -> [map()].
Return every tool from every registered client, with each tool's <<"name">> rewritten to <<"ServerId<Sep>ToolName">>. Servers that error out are skipped (with a logger:warning).
-spec to_anthropic() -> [map()].
Aggregated tools in Anthropic Messages API format.
-spec to_openai() -> [map()].
Aggregated tools in OpenAI Chat Completions tool format.