wasm_tools_mcp (wasm_tools v0.1.0)
View SourceExpose tools to MCP clients through barrel_mcp.
The same tools you call from Erlang can be called by an MCP client, with no MCP
code in the component and no second execution path: an MCP call runs exactly as
wasm_tools:start_call/4 does, in a runner of its own, with the component's
limits and capabilities.
{ok, Reg} = wasm_tools:start_link(#{}),
{ok, _} = wasm_tools:add(Reg, Calc, #{namespace => <<"calc">>}),
{ok, Exposed} = wasm_tools_mcp:register(Reg, #{tools => [<<"calc_add">>]}),
...
ok = wasm_tools_mcp:unregister(Exposed).barrel_mcp (4.9 or later) must be in your release and started; wasm_tools does not depend on it otherwise.
- Who owns a tool. Tools registered from a registry belong to the registry
process:
wasm_tools:remove/2takes them out of MCP before it returns, and when the registry stops barrel_mcp drops them. Tools registered from a component belong to the process that registers them and need anamespace. - Names. A registry's tools keep their names. A component's are named as a
registry names them (
Namespace_Name). A name barrel_mcp already has, a native tool of your application for instance, is refused, never replaced.scoperegisters the tools for that barrel_mcp listener scope only. - Definitions. Input and output schemas come from the component's types
(
wasm_tools_json).title,descriptionandannotations(read_only,destructive,idempotent,open_world) come from themetayou gave at load, never from the component;openWorldHintis set when the component may reach the network. barrel_mcp's own timeout is set past the tool's deadline, so the tool's deadline answers first. - Results. A value is
structuredContent{"result": V}, with the same JSON as text. A WITerr, an argument that does not fit, a trap, an exhausted limit, a deadline or a cancel is a tool error (isError: true). - Cancel. A client's cancel stops the call at once: the handler watches for
barrel_mcp's
{cancel, RequestId}while it waits. - Who may call. barrel_mcp checks an auth provider's
visible/4ontools/calltoo (its default since 4.9.0).
Summary
Functions
Register tools with barrel_mcp.
Take tools out of MCP. Only the tools the owner registered are removed.
Types
Functions
-spec register(wasm_tools:target(), map()) -> {ok, exposed()} | {error, error()}.
Register tools with barrel_mcp.
For a registry: #{tools => [Name] | all} (all by default), scope.
For a component: #{namespace := Namespace}, exports (as for
wasm_tools:add/3), scope.
-spec unregister(exposed()) -> ok.
Take tools out of MCP. Only the tools the owner registered are removed.