Rust quick start
Scaffold
Section titled “Scaffold”act-build init rust my-componentcd my-componentjust initact-build init carries the templates inside the binary — there is no copier, uvx, or Python
toolchain involved. Pass --http / --fs to have it declare those capabilities in act.toml
for you.
The template sets up Cargo.toml with a current act-sdk, a wit/ directory tracking act:tools (and act:sessions for stateful components) over act:core, a rust-toolchain.toml pinning nightly + wasm32-wasip2, and a justfile with build / test / publish recipes.
Write a tool
Section titled “Write a tool”src/lib.rs:
use act_sdk::prelude::*;
#[act_component]mod component { use super::*;
#[act_tool(description = "Reverse a string", read_only)] fn reverse( /// Text to reverse text: String, ) -> ActResult<String> { Ok(text.chars().rev().collect()) }}The #[act_component] macro generates the WIT tool-provider export. The #[act_tool] macro derives the JSON Schema from the function signature, collects std:* metadata (read_only, idempotent, destructive, timeout_ms), and registers the function with the component’s dispatcher.
just buildThis runs:
cargo build --release→target/wasm32-wasip2/release/<name>.wasmact-build pack <name>.wasm→ embeds theact:componentcustom section (CBOR-encoded metadata) and the contents ofskill/as an Agent Skill tar.
Verify
Section titled “Verify”act info target/wasm32-wasip2/release/component_my_component.wasm --toolsShould print your component name, version, and the reverse tool with its auto-derived schema.
just test # e2e suite: pytest driving the component over MCPact call <wasm> reverse --args '{"text":"hello"}'What act-sdk gives you
Section titled “What act-sdk gives you”| Macro / type | Purpose |
|---|---|
#[act_component] | Wraps a module as the act:tools/tool-provider export |
#[act_tool(…)] | Registers a fn as a tool, emits JSON Schema from the signature + doc comments |
ActError / ActResult | Return errors with a std:* kind and localized message |
Json<T> | Opt into JSON encoding (default is CBOR, per ACT-SPEC) |
Content { mime, data } | Return raw bytes with an explicit MIME type |
#[session_open] / #[session_close] | Mark the session lifecycle hooks of a stateful component |
ActContext / SessionRegistry | Per-call context and per-session state |
Agent Skills need no macro: act-build pack embeds a skill/ directory automatically. See
Agent Skills.
- Declare capabilities —
wasi:filesystem,wasi:http - Agent Skills —
SKILL.mdembedded in the component - Testing — the
just testpattern: pytest + a real MCP client