mcp_stdio_proxy/client/
cli.rs

1// MCP-Proxy CLI 实现
2//
3// CLI 主入口,负责命令分发到各个实现模块
4
5use anyhow::{Result, bail};
6
7// 导出 CLI 特定类型
8// 注意: ConvertArgs 等通用参数类型已由 client/mod.rs 统一导出
9pub use crate::client::support::args::{Cli, Commands};
10
11/// 运行 CLI 主逻辑
12///
13/// 根据命令类型分发到对应的实现模块:
14/// - Convert -> cli_impl/convert_cmd.rs
15/// - Check/Detect -> cli_impl/check.rs
16/// - Proxy -> proxy_server.rs
17pub async fn run_cli(cli: Cli) -> Result<()> {
18    match cli.command {
19        Some(Commands::Convert(args)) => {
20            crate::client::cli_impl::run_convert_command(args, cli.verbose, cli.quiet).await
21        }
22        Some(Commands::Check(args)) => {
23            crate::client::cli_impl::run_check_command(args, cli.verbose, cli.quiet).await
24        }
25        Some(Commands::Detect(args)) => {
26            crate::client::cli_impl::run_detect_command(args, cli.verbose, cli.quiet).await
27        }
28        Some(Commands::Proxy(args)) => {
29            super::proxy_server::run_proxy_command(args, cli.verbose, cli.quiet).await
30        }
31        None => {
32            // 直接 URL 模式(向后兼容)
33            if let Some(url) = cli.url {
34                let args = crate::client::support::args::ConvertArgs {
35                    url: Some(url),
36                    config: None,
37                    config_file: None,
38                    name: None,
39                    protocol: None,
40                    auth: None,
41                    header: vec![],
42                    retries: 0,    // 无限重试
43                    allow_tools: None,
44                    deny_tools: None,
45                    ping_interval: 30,  // 默认 30 秒 ping 一次
46                    ping_timeout: 10,   // 默认 10 秒超时
47                    logging: crate::client::support::LoggingArgs {
48                        diagnostic: true,   // 默认启用诊断模式
49                        log_dir: None,      // 默认无日志目录(将在 init_logging 中自动设置)
50                        log_file: None,     // 默认无日志文件
51                        otlp_endpoint: None, // 默认不启用 OTLP 追踪
52                        service_name: "mcp-proxy".to_string(),
53                    },
54                };
55                crate::client::cli_impl::run_convert_command(args, cli.verbose, cli.quiet).await
56            } else {
57                bail!("请提供 URL 或使用子命令")
58            }
59        }
60    }
61}