Composio Rust SDK
A minimal, type-safe Rust SDK for the Composio Tool Router REST API.
Features
- ๐ฆ Type-Safe: Compile-time validation with Rust's type system
- โก Async/Await: Built on tokio for high-performance async operations
- ๐ Automatic Retries: Exponential backoff for transient failures
- ๐ฆ Minimal Footprint: ~2 MB memory overhead
- ๐ก๏ธ Error Handling: Comprehensive error types with actionable messages
- ๐ง Session Management: User-scoped sessions for data isolation
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
Quick Start
use ;
async
Core Concepts
Sessions
Sessions provide user-scoped access to tools and manage authentication:
// Create a session with specific toolkits
let session = client
.create_session
.toolkits
.send
.await?;
// Disable specific toolkits
let session = client
.create_session
.disable_toolkits
.send
.await?;
Tool Execution
Execute tools within a session:
// Execute a regular tool
let result = session
.execute_tool
.await?;
// Execute a meta tool
let search_result = session
.execute_meta_tool
.await?;
Error Handling
The SDK provides comprehensive error handling:
use ComposioError;
match session.execute_tool.await
Configuration
Customize client behavior:
use Duration;
let client = builder
.api_key
.base_url
.timeout
.max_retries
.initial_retry_delay
.max_retry_delay
.build?;
Authentication
In-Chat Authentication (Default)
The agent automatically prompts users with Connect Links during conversation:
let session = client
.create_session
.toolkits
.manage_connections // Default: true
.send
.await?;
// Agent will automatically handle authentication when needed
Manual Authentication
Pre-authenticate users before they start chatting:
// Create auth link
let link = session
.create_auth_link
.await?;
println!;
// Check connection status
let toolkits = session.list_toolkits.send.await?;
for toolkit in toolkits.items
Toolkit Management
List and filter available toolkits:
// List all toolkits
let toolkits = session.list_toolkits.send.await?;
// Filter by connection status
let connected = session
.list_toolkits
.is_connected
.send
.await?;
// Search toolkits
let results = session
.list_toolkits
.search
.send
.await?;
Meta Tools
The SDK supports all 5 meta tools:
use MetaToolSlug;
// Search for tools
let search = session.execute_meta_tool.await?;
// Execute multiple tools in parallel
let multi = session.execute_meta_tool.await?;
// Manage connections
let manage = session.execute_meta_tool.await?;
// Remote workbench (Python sandbox)
let workbench = session.execute_meta_tool.await?;
// Remote bash
let bash = session.execute_meta_tool.await?;
Examples
See the examples/ directory for complete working examples:
basic_usage.rs- Session creation and tool executionmeta_tools.rs- Using meta toolserror_handling.rs- Error handling patternsauthentication.rs- Authentication flowstoolkit_listing.rs- Listing and filtering toolkits
Run an example:
Requirements
- Rust 1.70 or later
- Tokio runtime
- Composio API key (get one here)
Memory Footprint
The SDK is designed for minimal memory usage:
- Library size: 2.45 MB (release build)
- Runtime overhead: 112 bytes (client) + 296 bytes (session builder)
- Initialization time: ~200 ยตs (client creation)
- Text section: 28 KiB (SDK code only, excluding dependencies)
Performance Characteristics
- Zero-copy deserialization where possible
- Efficient Arc-based sharing for client references
- Minimal stack allocation
- Suitable for resource-constrained environments
Optimization Options
For production builds, add to your Cargo.toml:
[]
= true # Link-time optimization (15-20% size reduction)
= 1 # Better optimization
= true # Strip debug symbols
See MEMORY_FOOTPRINT_REPORT.md for detailed analysis.
API Coverage
This SDK focuses on the Tool Router API:
- โ Session creation and retrieval
- โ Tool execution (regular and meta tools)
- โ Toolkit listing and filtering
- โ Authentication link creation
- โ Meta tools schema retrieval
- โ Automatic retry with exponential backoff
- โ Comprehensive error handling
Roadmap
Future enhancements:
- Direct tool execution (non-session)
- Triggers support
- Connected accounts management
- Auth configs management
- File upload/download
- Workbench mount operations
Note: Wizard instruction generation requires the Composio Skills repository for development. This feature is not available in the published crate but can be enabled by cloning the Skills repository to vendor/skills during development.
Documentation
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Support
Acknowledgments
This SDK is built for ZeroClaw, a lightweight Rust AI assistant, and follows the design patterns from the official Composio Python SDK.