Add CLI-to-MCP bridge with auto-discovery from --help#39
Merged
Conversation
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>
There was a problem hiding this comment.
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::Cliand wire it through client connection and server listing output. - Implement
CliTransportto serve MCP methods (initialize,tools/list,tools/call) by spawning the configured CLI per call. - Add
cli_discoverymodule 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.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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