Skip to main content

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 build;
47pub mod cli;
48pub mod deploy;
49pub mod dev;
50pub mod error;
51pub mod executor;
52pub mod formatter;
53pub mod install;
54pub mod new;
55pub mod path_security;
56pub mod prelude;
57pub mod transport;
58
59use clap::Parser;
60
61// Clean re-exports (no more "New" suffixes!)
62pub use cli::{
63    BuildArgs, Cli, Commands, CompletionCommands, Connection, DeployArgs, DevArgs, InstallArgs,
64    InstallTarget, LogLevel, NewArgs, OutputFormat, ProjectTemplate, PromptCommands, RefType,
65    ResourceCommands, SamplingCommands, ServerCommands, ToolCommands, TransportKind, WasmPlatform,
66};
67pub use error::{CliError, CliResult, ErrorCategory};
68pub use executor::CommandExecutor;
69pub use formatter::Formatter;
70
71/// Run the CLI application
72///
73/// This is the main entry point for the TurboMCP CLI library. It provides complete
74/// MCP protocol coverage with rich output formatting and comprehensive error handling.
75///
76/// Returns a `CliResult` that the caller can handle appropriately. This allows
77/// the caller to control error formatting, exit codes, and runtime configuration.
78///
79/// # Example
80///
81/// ```rust,no_run
82/// use turbomcp_cli::prelude::*;
83///
84/// #[tokio::main]
85/// async fn main() {
86///     if let Err(e) = turbomcp_cli::run().await {
87///         eprintln!("Error: {}", e);
88///         std::process::exit(1);
89///     }
90/// }
91/// ```
92pub async fn run() -> CliResult<()> {
93    let cli = Cli::parse();
94    let executor = CommandExecutor::new(cli.format.clone(), !cli.no_color, cli.verbose);
95    executor.execute(cli.command).await
96}