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 providers::Provider;pub use providers::OpenAIProvider;pub use providers::AnthropicProvider;pub use utils::logging::setup as setup_logging;pub use utils::logging::setup_from_env as setup_logging_from_env;pub use utils::logging::get_verbosity;pub use utils::logging::set_verbosity;pub use utils::logging::truncate_message;pub use utils::logging::LogLevel;pub use utils::logging::Verbosity;pub use utils::logging::WithLogger;pub use utils::logging::ENV_COMPOSIO_LOGGING_LEVEL;pub use utils::logging::ENV_COMPOSIO_LOG_VERBOSITY;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::AuthConfigCreateParams;pub use models::AuthConfigData;pub use models::AuthConfigListParams;pub use models::AuthConfigUpdateParams;pub use models::ConnectedAccountCreateParams;pub use models::AuthConfigReference;pub use models::ConnectionData;pub use models::ConnectedAccountListParams;pub use models::ToolProxyParams;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::AuthConfigCreateResponse;pub use models::AuthConfigListResponse;pub use models::AuthConfigRetrieveResponse;pub use models::AuthConfigInfo;pub use models::ConnectedAccountCreateResponse;pub use models::ConnectedAccountListResponse;pub use models::ConnectedAccountDetail;pub use models::ConnectedAccountRetrieveResponse;pub use models::ConnectedAccountUpdateStatusResponse;pub use models::ToolProxyResponse;pub use models::TriggerInstanceUpsertResponse;pub use models::MetaToolSlug;pub use models::TagType;pub use models::AuthScheme;pub use models::ToolkitVersion;pub use models::ToolkitVersions;pub use models::ToolkitVersionParam;pub use models::TOOLKIT_LATEST_VERSION;pub use models::webhook_events::ConnectionExpiredEvent;pub use models::webhook_events::ConnectionState;pub use models::webhook_events::ConnectionStatus;pub use models::webhook_events::SingleConnectedAccountDetailedResponse;pub use models::webhook_events::WebhookConnectionMetadata;pub use models::webhook_events::WebhookEvent;pub use models::webhook_events::WebhookEventType;pub use models::webhook_events::is_connection_expired_event;pub use models::modifiers::AfterExecute;pub use models::modifiers::BeforeExecute;pub use models::modifiers::SchemaModifier;pub use models::modifiers::BeforeExecuteMeta;pub use models::modifiers::AfterExecuteMeta;pub use models::modifiers::Modifier;pub use models::modifiers::Modifiers;pub use models::modifiers::ToolExecuteParams;pub use models::modifiers::CustomAuthParams;pub use models::modifiers::CustomConnectionData;pub use models::custom_tools::CustomTool;pub use models::custom_tools::CustomToolsRegistry;pub use models::custom_tools::ExecuteRequestFn;pub use models::triggers::TriggerEvent;pub use models::triggers::TriggerMetadata;pub use models::triggers::TriggerConnectedAccount;pub use models::triggers::TriggerType;pub use models::triggers::TriggerInstance;pub use models::triggers::WebhookVersion;pub use models::connected_accounts::ConnectionRequest;pub use models::connected_accounts::ConnectionStatus as ConnectedAccountStatus;pub use models::connected_accounts::AuthScheme as ConnectedAccountAuthScheme;pub use models::connected_accounts::AUTH_SCHEME as auth_scheme;pub use wizard::Impact;pub use wizard::InstructionValidator;pub use wizard::Rule;pub use wizard::SkillsExtractor;pub use wizard::ValidationResult;pub use wizard::WizardInstructionGenerator;pub use skills_integration::SkillsCopyResult;pub use skills_integration::SkillsError;pub use skills_integration::SkillsValidation;
Modules§
- client
- Client implementation for the Composio API HTTP client for Composio API
- config
- Configuration types for the SDK Configuration for Composio SDK
- error
- Error types and error handling utilities
- meta_
tools - Meta tools - Native Rust implementations Meta Tools Module
- models
- Data models for API requests and responses Data models for Composio API
- providers
- Provider system for framework-specific tool formatting Provider system for framework-specific tool formatting
- retry
- Retry logic and exponential backoff utilities
- session
- Session management and tool execution Session management for Tool Router
- skills_
integration - Skills integration for copying and managing Composio Skills Skills Integration Module
- utils
- Utility functions for the SDK Utility functions for the Composio SDK
- wizard
- Wizard instruction generation from Composio Skills Wizard instruction generation module
Constants§
Functions§
- version
- Get SDK version information