Skip to content

Latest commit

 

History

History

examples

README.md

iFlow CLI SDK Examples

This directory contains several examples demonstrating different ways to use the iFlow CLI SDK for Rust.

Simple Query Examples

query.rs

Demonstrates the simplest way to interact with iFlow using the query convenience function.

cargo run --example query

This example shows how to send a single query to iFlow and receive a complete response.

query_with_config.rs

Demonstrates how to use the query_with_config function with custom configuration options.

cargo run --example query_with_config

This example shows how to configure the timeout and other options for a query.

Bidirectional Communication Examples

basic_client.rs

Demonstrates full bidirectional communication with iFlow, handling multiple message types.

cargo run --example basic_client

This example shows how to:

  • Establish a connection with iFlow
  • Send messages
  • Handle different message types (Assistant, ToolCall, Plan, etc.)
  • Process streaming responses

websocket_client.rs

Shows how to use WebSocket communication instead of stdio.

cargo run --example websocket_client

This example demonstrates:

  • Connecting to iFlow via WebSocket
  • Configuring WebSocket-specific options
  • Handling the same message types as the basic client

Advanced Features Examples

mcp_example.rs

Demonstrates how to configure MCP servers for extended capabilities.

cargo run --example mcp_example

This example shows:

  • Configuring MCP servers with commands and environment variables
  • Using filesystem MCP server for directory listing
  • Handling MCP-related tool calls

permission_modes.rs

Demonstrates how to control tool call permissions.

cargo run --example permission_modes

This example shows:

  • Different permission modes (Auto, Manual, Selective)
  • How to handle tool call requests
  • Implementing custom permission logic

test_response.rs

Tests response handling with detailed output.

cargo run --example test_response

logging_example.rs

Shows how to use the built-in logging functionality.

cargo run --example logging_example

This example demonstrates:

  • Configuring logging options
  • Writing logs to files
  • Using different log levels

Usage Tips

  1. Make sure iFlow CLI is installed and available in your PATH, or use the auto-start feature
  2. For WebSocket examples, ensure iFlow is running with WebSocket support
  3. Most examples use LocalSet for proper async runtime compatibility
  4. All examples follow the pattern of connecting, sending messages, handling responses, and disconnecting

Running Examples

To run any example, use:

cargo run --example <example_name>

Replace <example_name> with the name of the example you want to run (without the .rs extension).