Expand description
§Composio Rust SDK
A minimal, type-safe Rust SDK for the Composio Tool Router REST API.
This SDK enables ZeroClaw and other Rust applications to interact with external services through Composio’s Tool Router API, providing session management, tool execution, and authentication handling with a minimal memory footprint (~2 MB).
§Features
- Session Management: Create and manage Tool Router sessions for users
- Tool Execution: Execute tools and meta tools with automatic retry logic
- Type Safety: Comprehensive type definitions for all API requests and responses
- Error Handling: Detailed error types with actionable error messages
- Async/Await: Built on tokio for efficient async operations
- Memory Efficient: Minimal memory footprint suitable for resource-constrained environments
§Quick Start
use composio_sdk::{ComposioClient, MetaToolSlug};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize client with API key
let client = ComposioClient::builder()
.api_key(std::env::var("COMPOSIO_API_KEY")?)
.build()?;
// Create a session for a user
let session = client
.create_session("user_123")
.toolkits(vec!["github", "gmail"])
.manage_connections(true)
.send()
.await?;
println!("Session ID: {}", session.session_id());
println!("MCP URL: {}", session.mcp_url());
// Execute a tool
let result = session
.execute_tool(
"GITHUB_CREATE_ISSUE",
json!({
"owner": "composio",
"repo": "composio",
"title": "Test issue",
"body": "Created via Rust SDK"
})
)
.await?;
println!("Result: {:?}", result.data);
// Execute a meta tool
let search_result = session
.execute_meta_tool(
MetaToolSlug::ComposioSearchTools,
json!({
"query": "create a GitHub issue"
})
)
.await?;
println!("Search result: {:?}", search_result.data);
Ok(())
}§Session Configuration
Sessions can be configured with various options:
let session = client
.create_session("user_123")
.toolkits(vec!["github", "gmail"]) // Enable specific toolkits
.disable_toolkits(vec!["exa", "firecrawl"]) // Or disable specific toolkits
.auth_config("github", "ac_custom_config") // Use custom auth config
.connected_account("gmail", "ca_work_email") // Select specific account
.manage_connections(true) // Enable in-chat auth
.send()
.await?;§Error Handling
The SDK provides comprehensive error handling:
match session.execute_tool("INVALID_TOOL", json!({})).await {
Ok(result) => println!("Success: {:?}", result),
Err(ComposioError::ApiError { status, message, suggested_fix, .. }) => {
eprintln!("API error ({}): {}", status, message);
if let Some(fix) = suggested_fix {
eprintln!("Suggested fix: {}", fix);
}
}
Err(ComposioError::NetworkError(e)) => {
eprintln!("Network error: {}", e);
}
Err(e) => {
eprintln!("Other error: {}", e);
}
}§Configuration
Customize SDK behavior with ComposioConfig:
use composio_sdk::ComposioClient;
use std::time::Duration;
let client = ComposioClient::builder()
.api_key("your-api-key")
.base_url("https://backend.composio.dev/api/v3")
.timeout(Duration::from_secs(60))
.max_retries(5)
.build()?;Re-exports§
pub use client::ComposioClient;pub use client::ComposioClientBuilder;pub use config::ComposioConfig;pub use session::Session;pub use session::SessionBuilder;pub use error::ComposioError;pub use error::ErrorDetail;pub use models::SessionConfig;pub use models::ToolkitFilter;pub use models::ToolsConfig;pub use models::ToolFilter;pub use models::TagsConfig;pub use models::WorkbenchConfig;pub use models::ToolExecutionRequest;pub use models::MetaToolExecutionRequest;pub use models::LinkRequest;pub use models::SessionResponse;pub use models::McpInfo;pub use models::ToolSchema;pub use models::ToolExecutionResponse;pub use models::MetaToolExecutionResponse;pub use models::ToolkitListResponse;pub use models::ToolkitInfo;pub use models::ToolkitMeta;pub use models::ConnectedAccountInfo;pub use models::LinkResponse;pub use models::ErrorResponse;pub use models::MetaToolSlug;pub use models::TagType;pub use models::AuthScheme;pub use wizard::Impact;pub use wizard::InstructionValidator;pub use wizard::Rule;pub use wizard::SkillsExtractor;pub use wizard::ValidationResult;pub use wizard::WizardInstructionGenerator;