pub struct SessionBuilder<'a> { /* private fields */ }Expand description
Builder for creating sessions with fluent API
§Example
use composio_sdk::ComposioClient;
let client = ComposioClient::builder()
.api_key("your-api-key")
.build()?;
let session = client
.create_session("user_123")
.toolkits(vec!["github", "gmail"])
.manage_connections(true)
.send()
.await?;Implementations§
Source§impl<'a> SessionBuilder<'a>
impl<'a> SessionBuilder<'a>
Sourcepub fn new(client: &'a ComposioClient, user_id: String) -> Self
pub fn new(client: &'a ComposioClient, user_id: String) -> Self
Create a new session builder
The builder inherits the toolkit version configuration from the client.
You can override this configuration using the .toolkit_versions() method.
§Arguments
client- Reference to the ComposioClientuser_id- User identifier for session isolation
Sourcepub fn toolkits(self, toolkits: Vec<impl Into<String>>) -> Self
pub fn toolkits(self, toolkits: Vec<impl Into<String>>) -> Self
Enable specific toolkits for this session
By default, all toolkits are accessible via COMPOSIO_SEARCH_TOOLS. Use this method to restrict the session to specific toolkits.
§Arguments
toolkits- Vector of toolkit slugs to enable (e.g., “github”, “gmail”)
§Example
let session = client
.create_session("user_123")
.toolkits(vec!["github", "gmail", "slack"])
.send()
.await?;Sourcepub fn disable_toolkits(self, toolkits: Vec<impl Into<String>>) -> Self
pub fn disable_toolkits(self, toolkits: Vec<impl Into<String>>) -> Self
Sourcepub fn auth_config(
self,
toolkit: impl Into<String>,
auth_config_id: impl Into<String>,
) -> Self
pub fn auth_config( self, toolkit: impl Into<String>, auth_config_id: impl Into<String>, ) -> Self
Override the default auth config for a specific toolkit
Use this to specify a custom auth configuration (e.g., your own OAuth app) instead of Composio’s managed authentication.
§Arguments
toolkit- Toolkit slug (e.g., “github”)auth_config_id- Auth config ID (e.g., “ac_your_config”)
§Example
let session = client
.create_session("user_123")
.auth_config("github", "ac_custom_github_oauth")
.send()
.await?;Sourcepub fn connected_account(
self,
toolkit: impl Into<String>,
connected_account_id: impl Into<String>,
) -> Self
pub fn connected_account( self, toolkit: impl Into<String>, connected_account_id: impl Into<String>, ) -> Self
Select a specific connected account for a toolkit
Use this when a user has multiple connected accounts for the same toolkit (e.g., work and personal email) and you want to specify which one to use.
§Arguments
toolkit- Toolkit slug (e.g., “gmail”)connected_account_id- Connected account ID (e.g., “ca_work_gmail”)
§Example
let session = client
.create_session("user_123")
.connected_account("gmail", "ca_work_gmail")
.send()
.await?;Sourcepub fn manage_connections(self, enabled: bool) -> Self
pub fn manage_connections(self, enabled: bool) -> Self
Enable or disable automatic connection management
When enabled (default), the agent will automatically prompt users with Connect Links during chat when authentication is needed.
§Arguments
enabled- Whether to enable automatic connection management
§Example
// Disable in-chat authentication (use manual auth flow instead)
let session = client
.create_session("user_123")
.manage_connections(false)
.send()
.await?;Sourcepub fn tools(
self,
toolkit: impl Into<String>,
tools: Vec<impl Into<String>>,
) -> Self
pub fn tools( self, toolkit: impl Into<String>, tools: Vec<impl Into<String>>, ) -> Self
Configure per-toolkit tool filtering
Use this to enable or disable specific tools within a toolkit.
§Arguments
toolkit- Toolkit slug (e.g., “github”)tools- Vector of tool slugs to enable
§Example
let session = client
.create_session("user_123")
.tools("github", vec!["GITHUB_CREATE_ISSUE", "GITHUB_GET_REPOS"])
.send()
.await?;Configure tag-based tool filtering
Tags are MCP annotation hints that categorize tools by behavior:
readOnlyHint: Read-only tools (safe, no modifications)destructiveHint: Tools that modify or delete dataidempotentHint: Tools that can be safely retriedopenWorldHint: Tools that interact with external world
§Arguments
enabled- Tags that tools must have (at least one)disabled- Tags that tools must NOT have (any)
§Example
// Only allow read-only tools, exclude destructive ones
let session = client
.create_session("user_123")
.tags(
Some(vec![TagType::ReadOnlyHint]),
Some(vec![TagType::DestructiveHint])
)
.send()
.await?;Sourcepub fn workbench(
self,
proxy_execution: Option<bool>,
auto_offload_threshold: Option<u32>,
) -> Self
pub fn workbench( self, proxy_execution: Option<bool>, auto_offload_threshold: Option<u32>, ) -> Self
Configure workbench settings
The workbench is a persistent Python sandbox for complex operations.
§Arguments
proxy_execution- Whether to enable proxy executionauto_offload_threshold- Threshold for automatic offloading
§Example
let session = client
.create_session("user_123")
.workbench(Some(true), Some(1000))
.send()
.await?;Sourcepub fn toolkit_versions(self, versions: ToolkitVersionParam) -> Self
pub fn toolkit_versions(self, versions: ToolkitVersionParam) -> Self
Override toolkit version configuration for this session
By default, sessions inherit the toolkit version configuration from the client. Use this method to override the configuration for a specific session.
§Arguments
versions- Toolkit version configuration
§Example
// Override client config for this session
let mut versions = HashMap::new();
versions.insert("github".to_string(), ToolkitVersion::Specific("20250906_01".to_string()));
let session = client
.create_session("user_123")
.toolkit_versions(ToolkitVersionParam::Versions(versions))
.send()
.await?;Sourcepub fn experimental(self, user_timezone: Option<String>) -> Self
pub fn experimental(self, user_timezone: Option<String>) -> Self
Configure experimental features for this session
Note: These features are experimental and may be modified or removed in future versions.
§Arguments
user_timezone- IANA timezone identifier (e.g., “America/New_York”, “Europe/London”) for timezone-aware assistive prompts
§Example
let session = client
.create_session("user_123")
.experimental(Some("America/New_York".to_string()))
.send()
.await?;Sourcepub async fn send(self) -> Result<Session, ComposioError>
pub async fn send(self) -> Result<Session, ComposioError>
Send the session creation request
This consumes the builder and creates the session on the Composio API.
§Errors
Returns an error if:
- The API request fails
- The response cannot be parsed
- Authentication is invalid
§Example
let session = client
.create_session("user_123")
.toolkits(vec!["github"])
.send()
.await?;
println!("Session ID: {}", session.session_id());
println!("MCP URL: {}", session.mcp_url());