Overview
View Sourceerlang_wasm_tools
Load WebAssembly components and call them as tools from Erlang, Elixir and MCP
Quick start | Documentation | Features | Changelog | Contributing
[!WARNING] Early development: this project is not production ready. 0.1.0 is its first release: the API, the defaults and the error terms may change between 0.x releases, and erlang_wasm, the runtime underneath, is young too. Pin an exact version, and check Features before you rely on something.
Why wasm_tools?
- No glue code: you call a component's functions with ordinary Erlang values. wasm_tools reads their names and types from the component, and refuses a value that does not fit before the component runs.
- Reusability: a component is a standard WebAssembly component, with nothing specific to Erlang or MCP in it. You build it in Rust, Python or JavaScript, and the same file runs here and in wasmtime.
- Security: each call runs in a fresh instance, in a process of its own, with a deadline and limits on work, memory and heap. A component reaches only the directories, variables and hosts you grant it.
- MCP when you want it: the same tools can be exposed to AI agents through barrel_mcp, with no MCP code in the component.
Architecture
your Erlang or Elixir code MCP clients (AI agents)
| |
| barrel_mcp
| |
| wasm_tools_mcp
| |
+----------- wasm_tools ------------+
names, calls, registries,
capabilities, limits, JSON
|
erlang_wasm
a WebAssembly runtime written in Erlang
|
your WebAssembly componentswasm_tools runs on erlang_wasm: no native runtime, no port, no NIF. Architecture maps each box to its module.
Installation
rebar3:
{deps, [{wasm_tools, "~> 0.1", {pkg, erlang_wasm_tools}}]}.Mix:
{:wasm_tools, "~> 0.1", hex: :erlang_wasm_tools}wasm_tools needs Erlang/OTP 29 or later. Add barrel_mcp (4.9 or later) as
well if you expose tools through MCP. The OTP application is wasm_tools; the
Hex package is erlang_wasm_tools, so it is not mistaken for the Bytecode
Alliance wasm-tools CLI.
Using wasm_tools
Start the application and load a component. This repository and the Hex package ship a calculator built from Rust; Write your first component shows how.
{ok, _} = application:ensure_all_started(wasm_tools),
{ok, Calc} = wasm_tools:load({file, "test/fixtures/component/calculator.component.wasm"}).Call one of its functions with Erlang values:
wasm_tools:call(Calc, <<"add">>, #{<<"a">> => 20, <<"b">> => 22}).
%% => {ok, 42}A value that does not fit the function's type is refused, by name, before the component runs:
{error, #{class := argument, ctx := #{path := Path}}} =
wasm_tools:call(Calc, <<"add">>, #{<<"a">> => 1 bsl 40, <<"b">> => 1}),
Path.
%% => [<<"a">>]Each function has a JSON Schema, for an agent or a form:
{ok, #{input := Input}} = wasm_tools:schema(Calc, <<"add">>),
maps:get(<<"required">>, Input).
%% => [<<"a">>, <<"b">>]With barrel_mcp running, one call exposes the calculator to MCP clients, as the
tools calculator_add and calculator_multiply (MCP shows a whole server):
{ok, Exposed} = wasm_tools_mcp:register(Calc, #{namespace => <<"calculator">>}).When you are done, unload it:
ok = wasm_tools:unload(Calc).When to use it
Use wasm_tools when you want to:
- call a component's functions without writing their types;
- run each call in a fresh instance with a deadline, a cancel and limits on fuel, memory and heap;
- grant a component a directory, some variables or some hosts by name, and nothing else;
- give a component functions of your application (host interfaces);
- manage many components together, bound how many calls run at once, and count them;
- expose components to MCP clients.
Use erlang_wasm's wasm_component directly when you need the instance itself:
resources that live across calls, streams, or control over instantiation.
Documentation
| to | read |
|---|---|
| call a component in five minutes | Quick start |
| build a component | Write your first component |
| call one component | Call a component |
| manage many, in your supervision tree | Registries |
| decide what a component may reach | Capabilities and security |
| give it functions of your application | Host interfaces |
| know who owns what, and what stops when | Lifecycle |
| expose tools to AI agents | MCP |
| use it from Elixir | Elixir |
| watch it in production | Observability |
| send and receive JSON | JSON mapping |
| know what is supported, and with which toolchains | Features |
| know what a call costs | Benchmarks |
| see whole programs | the examples in the repository: examples/erlang/ and examples/elixir/ |
| change the library | Architecture, Contributing |
The published documentation is on HexDocs.
Supported API
You call four modules. Their documented functions, types and callbacks are the supported API:
| module | use it to |
|---|---|
wasm_tools | inspect, load and call components, manage registries, get schemas, check arguments, and ask what an http grant decides (authorize/2) |
wasm_tools_host | implement a host interface (the behaviour) |
wasm_tools_json | get JSON Schemas, and convert JSON to native values and back |
wasm_tools_mcp | expose tools to MCP clients (register/2, unregister/1) |
wasm_tools_component, wasm_tools_call, wasm_tools_policy and
wasm_tools_registry are internal, and so is any function without
documentation. Their pages explain options the API takes, such as the
capabilities and limits in wasm_tools_policy, but do not call them: they can
change in any release.
Contributing
Contributing gives the checks every change passes and the rules a review holds you to; Architecture tells you where the code for each part lives.
License
Apache-2.0, in the LICENSE file.