clap
A Rust framework that bridges clap command-line applications with the Model Context Protocol (MCP)
claude mcp add --transport stdio gakonst-clap-mcp cargo run --bin <your-binary-name> \ --env RUST_LOG="info"
How to use
clap-mcp enables converting any Clap-based CLI into an MCP server. By deriving McpMode on your CLI, every subcommand becomes an MCP tool automatically, and you can choose to run the CLI as a normal command or expose its functionality over MCP via an HTTP server or stdio channel. To use it, add clap-mcp to your Rust project and annotate your CLI struct with the McpMode derive, then launch your binary in MCP mode (via the --mcp flag). The macro will map each Clap subcommand argument to an MCP tool parameter, preserving types and defaults. This means tools like add, multiply, or any custom subcommands become independently accessible as MCP tools without writing extra glue code. When running in MCP mode, you can opt to serve over HTTP on a port with --mcp-port, or fall back to stdio for local inter-process communication.
How to install
Prerequisites:
- Rust toolchain (rustc, cargo)
- A Rust project configured to use Clap and clap-mcp
-
Install Rust (if not already installed):
- On Linux/macOS: curl --proto "=https" -sSf https://sh.rustup.rs | sh
- On Windows: follow Rust installer instructions at https://www.rust-lang.org/tools/install
-
Create or update your Cargo.toml to include clap-mcp: [dependencies] clap = "4" # or your existing Clap version clap-mcp = "0.1"
-
Build and run your project in MCP mode:
- Build: cargo build
- Run in MCP mode (example): cargo run --bin <your-binary-name> -- --mcp
-
If you want HTTP-based MCP, pass the port: cargo run --bin <your-binary-name> -- --mcp --mcp-port 8080
-
Verify the MCP server is listening by connecting an MCP client or hitting the HTTP endpoint if enabled.
Notes:
- Replace <your-binary-name> with the actual binary name defined in your Cargo.toml or your project’s build setup.
- The clap-mcp derive macro automatically exposes each subcommand as an MCP tool, so no extra wiring is required.
Additional notes
Tips and considerations:
- If you run in HTTP mode, ensure the port you choose is not blocked by a firewall and is accessible to MCP clients.
- When debugging, enable logging via RUST_LOG=info to trace MCP interactions.
- The MCP tools preserve CLI argument types; long/short flags, positional args, and subcommand structures map directly to tool parameters.
- If your CLI uses complex clap validators or custom value parsers, they should generally carry over to MCP tool parameters as long as types are compatible.
- For environment-specific configurations, you can inject environment variables into your MCP server process as needed (e.g., database URLs, API keys) and read them in your CLI as usual.
Related MCP Servers
goose
an open source, extensible AI agent that goes beyond code suggestions - install, execute, edit, and test with any LLM
cunzhi
告别AI提前终止烦恼,助力AI更加持久
probe
AI-friendly semantic code search engine for large codebases. Combines ripgrep speed with tree-sitter AST parsing. Powers AI coding assistants with precise, context-aware code understanding.
mcp-center
A centralized platform for managing and connecting MCP servers. MCP Center provides a high-performance proxy service that enables seamless communication between MCP clients and multiple MCP servers.
backlog -rust
MCP server for Backlog, project management service.
perplexity-web-api
🔍 Perplexity AI MCP without API key