This page exposes your tools to MCP clients, such as AI agents and editors, through barrel_mcp. The component needs no MCP code: an MCP call runs exactly as a native call does, in a fresh instance with the component's limits and capabilities. You need this page when a model should be able to call your components.

Add barrel_mcp

wasm_tools does not depend on barrel_mcp: add it yourself, 4.9 or later, and start it with your application.

{deps, [{wasm_tools, "~> 0.1", {pkg, erlang_wasm_tools}},
        {barrel_mcp, "~> 4.9"}]}.
{ok, _} = application:ensure_all_started(barrel_mcp),
{ok, _} = barrel_mcp:start_http_stream(#{port => 9090}).

Expose a registry's tools

{ok, Reg} = wasm_tools:start_link(#{name => my_tools}),
Meta = #{<<"add">> => #{title => <<"Add">>,
                        description => <<"Add two integers">>,
                        annotations => #{read_only => true, idempotent => true}}},
{ok, Calc} = wasm_tools:load({file, "calculator.component.wasm"}, #{meta => Meta}),
{ok, _} = wasm_tools:add(Reg, Calc, #{namespace => <<"calc">>}),
{ok, Exposed} = wasm_tools_mcp:register(Reg, #{tools => [<<"calc_add">>]}).
  • The tools belong to the registry: wasm_tools:remove/2 takes them out of MCP before it returns, and when the registry stops barrel_mcp drops them.
  • wasm_tools_mcp:unregister(Exposed) takes them out of MCP and leaves them in the registry.
  • tools is all by default. scope registers them for the barrel_mcp listeners started with that scope only.

Expose one component

{ok, Exposed} = wasm_tools_mcp:register(Calc, #{namespace => <<"calc">>}).

A component registered directly needs a namespace, and its tools belong to the process that registers them.

What clients see

MCPcomes from
namethe tool's name in the registry, or Namespace_Name
inputSchema, outputSchemathe component's types (JSON mapping)
title, descriptionthe meta you gave at load; never the component itself
annotationsmeta's read_only, destructive, idempotent, open_world; openWorldHint is true when the component may reach the network

A name barrel_mcp already has, a native tool of your application for instance, is never replaced: register/2 answers {error, #{kind := name_conflict}} and registers nothing.

What a call answers

the callMCP result
returns a valuestructuredContent {"result": V}, and the same JSON as text
returns a WIT errisError: true, the error value as JSON text
has an argument that does not fitisError: true, the reason
traps, runs out of a limit, passes its deadlineisError: true, a short reason
is cancelled by the clientstopped at once

barrel_mcp's own timeout is set past the tool's deadline, so the tool answers with its own timeout error first.

Who may call

barrel_mcp's auth providers decide who sees and who may call each tool (visible/4, applied to tools/call too since 4.9.0). A tool that one listener should serve and another not goes in a scope.

Notes

  • barrel_mcp must be started before register/2; without it the answer is {error, #{kind := barrel_mcp_not_started}}, and without barrel_mcp in the release {error, #{kind := barrel_mcp_unavailable}}.
  • A type with no JSON form (an option of an option) cannot be exposed: register/2 refuses the whole batch and names the export.