ai-session 0.5.0

AI-optimized terminal session management library
Documentation
//! MCP server test for ai-session
//!
//! This example demonstrates the MCP server functionality.

use ai_session::SessionManager;
use anyhow::Result;
use serde_json::json;
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<()> {
    println!("๐Ÿ”ง Testing ai-session MCP server...");

    // Create session manager
    let session_manager = Arc::new(SessionManager::new());

    // Note: For full MCP server testing, you would need a transport layer

    // Test tool registry functionality
    println!("๐Ÿงช Testing tool registry...");

    let tools = ai_session::mcp::tools::ToolRegistry::with_builtin_tools(session_manager.clone());

    // List all available tools
    let tool_list = tools.list_tools();
    println!("โœ… Available MCP tools ({} total):", tool_list.len());

    for tool in tool_list {
        println!("   โ€ข {} - {}", tool.name, tool.description);
    }

    // Test create_session tool
    println!("๐Ÿงช Testing create_session tool...");

    let create_session_args = json!({
        "name": "mcp-test-session",
        "working_directory": "/tmp"
    });

    match tools.invoke("create_session", create_session_args) {
        Ok(result) => {
            println!("โœ… create_session tool executed successfully");
            if let Some(content) = result.content.first() {
                if let ai_session::mcp::tools::ToolContent::Text { text } = content {
                    println!("   Result: {}", text);
                }
            }
        }
        Err(e) => {
            println!("โŒ create_session tool failed: {}", e);
        }
    }

    // Test get_session_info tool if we can get session ID
    println!("๐Ÿงช Testing get_session_info tool...");

    // First get list of sessions
    let list_sessions_result = tools.invoke("list_sessions", json!({}));
    match list_sessions_result {
        Ok(result) => {
            println!("โœ… list_sessions tool executed successfully");
            if let Some(content) = result.content.first() {
                if let ai_session::mcp::tools::ToolContent::Text { text } = content {
                    println!("   Available sessions: {}", text);
                }
            }
        }
        Err(e) => {
            println!("โš ๏ธ  list_sessions tool failed: {}", e);
        }
    }

    // Test invalid tool call
    println!("๐Ÿงช Testing invalid tool call...");

    match tools.invoke("nonexistent_tool", json!({})) {
        Ok(_) => {
            println!("โŒ Unexpected success for invalid tool");
        }
        Err(e) => {
            println!("โœ… Invalid tool correctly rejected: {}", e);
        }
    }

    println!("โœ… MCP server test completed successfully!");

    Ok(())
}