Skip to main content

run

Function run 

Source
pub async fn run(
    source: ServerSource,
    name: Option<String>,
    output_dir: Option<PathBuf>,
    dry_run: bool,
    output_format: OutputFormat,
) -> Result<ExitCode>
Expand description

Runs the generate command.

Generates progressive loading TypeScript files from an MCP server.

This command performs the following steps:

  1. Builds ServerConfig from CLI arguments or loads from ~/.claude/mcp.json
  2. Introspects the MCP server to discover tools
  3. Generates TypeScript files (one per tool) using progressive loading pattern
  4. Exports VFS to ~/.claude/servers/{server-id}/ directory

§Arguments

  • source - Resolved server-selection source: either a ~/.claude/mcp.json name or CLI transport flags with timeout overrides. Timeout overrides only exist on the Flags arm — a Config source always uses the mcp.json entry’s own connectTimeoutSecs/discoverTimeoutSecs, so there is no “ignored override” state to document.
  • name - Custom server name for directory (default: server_id)
  • output_dir - Custom output directory (default: ~/.claude/servers/)
  • dry_run - When true, preview files without writing to disk
  • output_format - Output format (json, text, pretty)

§Errors

Returns an error if:

  • Server configuration is invalid
  • Server not found in mcp.json (when using –from-config)
  • Server connection fails
  • Tool introspection fails
  • Code generation fails
  • File export fails (skipped in dry-run mode)

§Examples

use mcp_execution_cli::commands::common::{ServerSource, TransportArgs};
use mcp_execution_cli::commands::generate;
use mcp_execution_core::cli::OutputFormat;
use std::path::PathBuf;

// Generate from a stdio transport
let exit_code = generate::run(
    ServerSource::Flags {
        transport: TransportArgs::Stdio {
            command: "github-mcp-server".to_string(),
            args: vec![],
            env: vec![],
            cwd: None,
        },
        connect_timeout_secs: None,
        discover_timeout_secs: None,
    },
    None,
    None,
    false,
    OutputFormat::Pretty
).await?;

// Generate with custom output directory and name override
let exit_code = generate::run(
    ServerSource::Flags {
        transport: TransportArgs::Http {
            url: "https://api.example.com/mcp/".to_string(),
            headers: vec!["Authorization=Bearer token".to_string()],
        },
        connect_timeout_secs: Some(10),
        discover_timeout_secs: Some(30),
    },
    Some("my-custom-name".to_string()),
    Some(PathBuf::from("/tmp/generated")),
    false,
    OutputFormat::Json
).await?;