“What’s the weather in Tokyo right now?”The complete source code for this tool is available on GitHub:
weather-tool source
Browse the full implementation —
lib.rs, Cargo.toml, and weather-tool.capabilities.json.Prerequisites
If you don’t have Rust yet, install it from rustup.rs:1. Create the project
Cargo.toml with:
Cargo.toml
crate-type = ["cdylib"] tells Cargo to produce a dynamic library — the format WASM components require. [workspace] stops Cargo from merging this crate into a parent workspace.2. Wire up the WIT interface
Every IronClaw tool is a WASM component that implements a WIT interface. The host provides HTTP, logging, and workspace capabilities; your tool exportsexecute, schema, and description.
Replace src/lib.rs with the following skeleton:
src/lib.rs
execute_inner is where the real logic lives — you will fill it in next.
The
wit/tool.wit file ships with IronClaw. If you are building inside the IronClaw repo (e.g. under tools-src/my-tool/), the path ../../wit/tool.wit is correct. If you are building in a standalone directory, copy wit/tool.wit from the repo root and adjust the path accordingly.If your tool uses private credentials (API keys, OAuth tokens), you still keep the same WIT interface. Secret handling is declared in
*.capabilities.json and injected by the host at runtime. Your WASM tool should not ask the model for secrets in params.3. Define the Execute Logic
The tool will receive parameters provided by the LLM in JSON format, then execute the right logic based on those parameters and return a result also in JSON format.src/lib.rs
Remember to match the action names and parameter structure in the JSON schema you will define later. The LLM relies on that schema to know what JSON to send, so if your Rust code expects
country_code but the schema calls it country, the LLM won’t know to include it and you’ll get errors at runtime.4. Implement the Actions
We will now implement the three actions:get_current, get_forecast, and get_air_quality. Each action will call the appropriate Open-Meteo API endpoint, parse the response, and return a JSON string with the relevant information.
Handling authenticated APIs
Handling authenticated APIs
If your API needs a secret (for example a bearer token), you do not inject it in these Rust functions manually.Instead you will declare them in the capabilities file and let the host inject them at runtime.Your Rust code just calls
api_get(...) with the right URL and headers, and the host adds credentials automatically for allowlisted hosts.You can still check for the presence of secrets if you want to return a custom error message when credentials are missing:Geocoding helper
Open-Meteo needs coordinates, not city names. Add a helper that calls the free geocoding API:src/lib.rs
near::agent::host::log emits a structured log line visible in ironclaw output. The host collects all log entries and flushes them after the call completes.
API helper
src/lib.rs
Get current weather
Get forecast
src/lib.rs
Get air quality
src/lib.rs
5. Define the JSON schema
TheSCHEMA constant tells the LLM exactly what JSON to send. Use oneOf because the three actions have different required fields:
src/lib.rs
6. Declare capabilities
Createweather-tool.capabilities.json next to Cargo.toml. This file is the sandbox allowlist — any host not listed here is blocked at runtime:
weather-tool.capabilities.json
get_current and get_forecast make two requests each: one to geocode the city name and one to fetch the weather data.
7. Add secrets and auth (for tools that need credentials)
This weather tool uses Open-Meteo, so it does not need a secret. If your tool calls an API that needs a token, declare that in the capabilities file so IronClaw can inject it at request time. Example capability sections (pattern used intools-src/* on the IronClaw repo):
weather-tool.capabilities.json
http.credentialsmaps a stored secret to where it should be injected (bearer, custom header, query param, or URL placeholder).secrets.allowed_nameslets the tool check secret presence withnear::agent::host::secret_exists(...).authtells IronClaw how to collect credentials.
- Use
auth.env_varif it is set in your environment. - Use OAuth if
auth.oauthis configured. - Fall back to manual token entry using
instructionsandsetup_url.
setup.required_secrets (for example OAuth client id/client secret fields), run setup as well:
8. Build and install
setup.required_secrets, run:
Try it out
Start IronClaw and ask your agent:- “What’s the weather in Buenos Aires?”
- “Give me a 5-day forecast for London, GB in imperial units.”
- “What’s the air quality at coordinates 35.6762, 139.6503?”