FTL SDK Rust Macros
Procedural macros for reducing boilerplate in FTL tool components written in Rust.
Overview
This crate provides the tools!
macro for defining multiple tool handler functions with minimal boilerplate. The macro:
- Supports multiple tools in a single component
- Automatically derives JSON schemas from your input types (requires
JsonSchema
derive) - Supports both synchronous and asynchronous functions
- Generates the complete HTTP handler with routing
- Handles all the boilerplate for you
Usage
Basic Tool Handler
The tools!
macro simplifies creating tool handlers:
use ;
use Deserialize;
use JsonSchema;
tools!
Complete Example
Here's a more complete example showing how the macro works with multiple tools:
use ;
use Deserialize;
use JsonSchema;
tools!
// The macro generates the HTTP handler with routing automatically!
Generated Code
The tools!
macro generates:
- A
handle_tool_component
async function that returns metadata for all tools on GET - Path-based routing (e.g.,
/add
,/subtract
) for POST requests - Automatic JSON deserialization of request bodies
- Error handling with proper HTTP status codes
- Correct Content-Type headers
- Full Spin HTTP component integration
Important: Input Validation
Just like with the TypeScript SDK, tools should NOT validate inputs themselves. The FTL gateway handles all input validation against your tool's JSON Schema before invoking your handler. This means:
- Your handler can assume all inputs match the schema
- Focus on business logic, not validation
- The gateway enforces all JSON Schema constraints
Response Macros
The SDK provides convenient macros for creating responses:
tools!
Async Support
The tools!
macro fully supports async functions:
tools!
License
Apache-2.0
Release Process
See RELEASE_ORDER.md for release instructions.
Selective CI
This package now uses selective CI - only relevant tests run for each package.