Skip to content

Add CLI-to-MCP bridge with auto-discovery from --help#39

Merged
avelino merged 3 commits into
mainfrom
avelino/issue-38
Mar 29, 2026
Merged

Add CLI-to-MCP bridge with auto-discovery from --help#39
avelino merged 3 commits into
mainfrom
avelino/issue-38

Conversation

@avelino
Copy link
Copy Markdown
Owner

@avelino avelino commented Mar 29, 2026

CLI tools can't be used by AI agents that only speak MCP. Teams end up writing custom MCP server wrappers for each CLI, which is pure boilerplate.

New "cli" server type in config that wraps any CLI binary as an MCP server. Parses --help output to discover subcommands and flags automatically, generates tool definitions with typed inputSchema. Each tool call spawns the CLI process independently. Supports cli_help for non-standard help flags, cli_only for whitelisting safe commands, and cli_depth to control discovery recursion.

Closes #38

CLI tools can't be used by AI agents that only speak MCP. Teams end up
writing custom MCP server wrappers for each CLI, which is pure boilerplate.

New "cli" server type in config that wraps any CLI binary as an MCP server.
Parses --help output to discover subcommands and flags automatically, generates
tool definitions with typed inputSchema. Each tool call spawns the CLI process
independently. Supports cli_help for non-standard help flags, cli_only for
whitelisting safe commands, and cli_depth to control discovery recursion.

Closes #38

Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
…arguments)

Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new cli backend type so arbitrary CLI binaries can be exposed as MCP tool providers, with automatic tool generation by parsing the CLI’s --help output. This fits into the existing ServerConfig + Transport abstraction alongside stdio and http, and is surfaced both in direct CLI usage (mcp <server> ...) and proxy mode (mcp serve).

Changes:

  • Introduce ServerConfig::Cli and wire it through client connection and server listing output.
  • Implement CliTransport to serve MCP methods (initialize, tools/list, tools/call) by spawning the configured CLI per call.
  • Add cli_discovery module with regex-based parsing of subcommands/flags plus docs covering CLI-as-MCP usage.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/transport/mod.rs Exposes the new cli transport module.
src/transport/cli.rs Implements MCP-over-CLI transport (list + call) by spawning processes.
src/cli_discovery.rs Implements auto-discovery by parsing --help output into Tool schemas.
src/config.rs Adds ServerConfig::Cli + parsing defaults/validation for cli_* fields.
src/client.rs Connects ServerConfig::Cli via CliTransport.
src/output.rs Includes CLI servers in servers output (json/text).
src/main.rs Registers new cli_discovery module.
docs/guides/cli-as-mcp.md New guide documenting discovery, calling, and config options.
docs/reference/config-file.md Documents the new CLI server config variant and type detection.
docs/why-mcp-over-cli-for-teams.md New rationale doc referencing CLI-as-MCP approach.
docs/SUMMARY.md Adds new docs pages to the book summary.
README.md Mentions the new server type and shows CLI-as-MCP example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/transport/cli.rs
Comment thread src/transport/cli.rs Outdated
Comment thread src/transport/cli.rs
Comment thread src/transport/cli.rs Outdated
Comment thread src/cli_discovery.rs
Comment thread docs/guides/cli-as-mcp.md Outdated
Comment thread src/cli_discovery.rs Outdated
Comment thread src/transport/cli.rs Outdated
Comment thread src/transport/cli.rs
Comment thread docs/guides/cli-as-mcp.md Outdated
Copilot review flagged security and robustness gaps in the CLI-to-MCP bridge: tool execution had no allowlist check, params weren't validated, commands could hang forever, and path parsing was Unix-only.

Added tool name allowlist enforcement at execution time, proper JSON-RPC error responses for invalid params, MCP_TIMEOUT-based timeouts on both help discovery and tool calls, cross-platform path handling via std::path::Path, and explicit --flag=false emission for boolean overrides. Docs now accurately describe cli_depth and preset tools behavior.

Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
@avelino avelino merged commit 8788cb7 into main Mar 29, 2026
5 checks passed
@avelino avelino deleted the avelino/issue-38 branch March 29, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support CLI tools as MCP servers (auto-discovery via --help)

2 participants