turbomcp_cli/
lib.rs

1//! # `TurboMCP` CLI - Comprehensive Edition
2//!
3//! Complete MCP (Model Context Protocol) command-line interface with comprehensive features.
4//!
5//! ## Features
6//!
7//! - **Complete MCP Coverage**: All protocol operations (tools, resources, prompts, completions, sampling, etc.)
8//! - **Multiple Transports**: STDIO, HTTP SSE, WebSocket, TCP, Unix sockets with auto-detection
9//! - **Rich Output**: Human-readable, JSON, YAML, and table formats with colored output
10//! - **Robust Error Handling**: Detailed errors with actionable suggestions
11
12#![allow(clippy::result_large_err)]
13#![allow(clippy::collapsible_if)]
14#![allow(clippy::option_as_ref_deref)]
15#![allow(clippy::needless_return)]
16//! - **Production Ready**: Built on turbomcp-client and turbomcp-transport
17//! - **Enterprise Features**: Connection presets, configuration files, verbose logging
18//!
19//! ## Quick Start
20//!
21//! ```bash
22//! # List tools from a server
23//! turbomcp-cli tools list --url http://localhost:8080/mcp
24//!
25//! # Call a tool with arguments
26//! turbomcp-cli tools call calculate --arguments '{"a": 5, "b": 3}'
27//!
28//! # Get server info in table format
29//! turbomcp-cli server info --format table
30//!
31//! # List resources from STDIO server
32//! turbomcp-cli resources list --command "./my-server"
33//! ```
34//!
35//! ## Architecture
36//!
37//! The CLI uses a layered architecture:
38//! - **Command Layer** (`cli_new`): Clap-based argument parsing
39//! - **Execution Layer** (`executor`): Command execution using turbomcp-client
40//! - **Transport Layer** (`transport`): Auto-detection and factory pattern
41//! - **Output Layer** (`formatter`): Rich, multi-format output
42//!
43//! All MCP operations are delegated to `turbomcp-client` for reliability.
44
45// Core modules
46pub mod cli;
47pub mod error;
48pub mod executor;
49pub mod formatter;
50pub mod prelude;
51pub mod transport;
52
53// Legacy modules removed in 2.0 - all functionality is now in the new architecture
54// If you were using the legacy API (tools-list, tools-call, schema-export):
55// - Use the new hierarchical commands: tools list, tools call, tools schema
56// - Use `#[tokio::main]` instead of `run_cli()`
57// - Import from `cli` module instead of `cli_new`
58
59use clap::Parser;
60
61// Clean re-exports (no more "New" suffixes!)
62pub use cli::{
63    Cli, Commands, CompletionCommands, Connection, LogLevel, OutputFormat, PromptCommands, RefType,
64    ResourceCommands, SamplingCommands, ServerCommands, ToolCommands, TransportKind,
65};
66pub use error::{CliError, CliResult, ErrorCategory};
67pub use executor::CommandExecutor;
68pub use formatter::Formatter;
69
70/// Run the CLI application
71///
72/// This is the main entry point for the TurboMCP CLI library. It provides complete
73/// MCP protocol coverage with rich output formatting and comprehensive error handling.
74///
75/// Returns a `CliResult` that the caller can handle appropriately. This allows
76/// the caller to control error formatting, exit codes, and runtime configuration.
77///
78/// # Example
79///
80/// ```rust,no_run
81/// use turbomcp_cli::prelude::*;
82///
83/// #[tokio::main]
84/// async fn main() {
85///     if let Err(e) = turbomcp_cli::run().await {
86///         eprintln!("Error: {}", e);
87///         std::process::exit(1);
88///     }
89/// }
90/// ```
91pub async fn run() -> CliResult<()> {
92    let cli = Cli::parse();
93    let executor = CommandExecutor::new(cli.format.clone(), !cli.no_color, cli.verbose);
94    executor.execute(cli.command).await
95}