barrel_mcp_agent (barrel_mcp v2.0.2)

View Source

Multi-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

opts/0

-type opts() :: #{separator => binary(), timeout => timeout()}.

Functions

call_tool(NsName, Args)

-spec call_tool(binary(), map()) -> {ok, map()} | {error, term()}.

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 parsed ServerId.
  • Any error returned by barrel_mcp_client:call_tool/4.

call_tool(NsName, Args, Opts)

-spec call_tool(binary(), map(), opts()) -> {ok, map()} | {error, term()}.

list_tools()

-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).

list_tools(Opts)

-spec list_tools(opts()) -> [map()].

to_anthropic()

-spec to_anthropic() -> [map()].

Aggregated tools in Anthropic Messages API format.

to_anthropic(Opts)

-spec to_anthropic(opts()) -> [map()].

to_openai()

-spec to_openai() -> [map()].

Aggregated tools in OpenAI Chat Completions tool format.

to_openai(Opts)

-spec to_openai(opts()) -> [map()].