yaacov

cli2mcp -- Turn any CLI into an MCP Server

Community yaacov
Updated

An educational Python library that bridges the gap between traditional command-line tools and the Model Context Protocol (MCP).

cli2mcp -- Turn any CLI into an MCP Server

An educational Python library that bridges the gap between traditionalcommand-line tools and the Model Context Protocol (MCP).

cli2mcp scans a CLI tool's --help output, extracts its arguments andsubcommands, and generates a JSON descriptor file. It can then serve thatfile as a fully functional MCP server -- letting AI assistants call the CLItool through a standard protocol.

Quick start

uv sync

1. Scan a CLI tool

uv run cli2mcp scan curl

This runs curl --help, parses the output, and writes curl.tools.json.

For tools with subcommands (like git):

uv run cli2mcp scan git -o git.tools.json

Each subcommand becomes its own MCP tool.

2. Serve as an MCP server

uv run cli2mcp serve curl.tools.json

This starts an MCP server (stdio transport) that exposes every entry inthe JSON file as a callable tool.

3. Connect to an AI assistant

Add the server to your assistant's MCP configuration.

{
  "mcpServers": {
    "curl": {
      "command": "cli2mcp",
      "args": ["serve", "curl.tools.json"]
    }
  }
}

How it works

                                        MCP client
                                            |
cli2mcp scan curl   -->  curl.tools.json    |
                              |             |
                         cli2mcp serve  <---+
                              |
                         subprocess.run(["curl", ...])

The JSON schema

The generated file looks like this:

{
  "command": "curl",
  "tools": [
    {
      "name": "curl",
      "description": "transfer a URL",
      "args": [
        {
          "name": "url",
          "description": "URL to transfer",
          "type": "string",
          "required": true
        },
        {
          "name": "--output",
          "description": "Write output to file instead of stdout",
          "type": "string",
          "required": false
        }
      ]
    }
  ]
}
  • command -- the base CLI binary to run.
  • tools -- one entry per tool (or per subcommand).
  • args -- each argument has a name, description, type (always"string"), and required flag.
  • Argument names starting with -- are flags; others are positional.
  • You can hand-edit this file to add, remove, or rename tools.

How arguments map back to CLI commands

When the MCP server receives a tool call like:

{"name": "git_commit", "arguments": {"message": "fix bug", "all": "true"}}

It reconstructs the CLI command:

git commit --message "fix bug" --all true

Flags (names starting with --) are emitted as --flag value.Positional arguments are appended at the end.

Supported help styles

Different CLI frameworks produce different --help formats.cli2mcp auto-detects the style and uses the right parser:

Style Frameworks Flag format
GNU argparse, click, GNU --flag description (one line)
Cobra kubectl, oc, docker, gh --flag=default: + next line
Plain curl, busybox flags listed without section headers

Requirements

  • Python 3.10+
  • uv (recommended) or pip
  • mcp[cli] (the official MCP Python SDK, installed automatically)

MCP Server · Populars

MCP Server · New

    WJZ-P

    Douyin Upload MCP Skill

    MCP Server

    Community WJZ-P
    pwno-io

    pwno-mcp

    MCP for Pwn

    Community pwno-io
    antoinebou12

    UML-MCP: Diagram Generation via MCP

    UML-MCP Server is a UML diagram generation tool based on MCP (Model Context Protocol), which can help users generate various types of UML diagrams through natural language description or directly writing PlantUML and Mermaid and Kroki https://uml-mcp.vercel.app/docs

    Community antoinebou12
    JeremyVyska

    BC Code Intelligence MCP Server

    BC Code Intelligence MCP Server - Persona-driven workflow orchestration for Business Central development. Provides 16+ MCP tools, layered knowledge system, and intelligent BC pattern analysis through Model Context Protocol.

    Community JeremyVyska
    noimank

    FNewsCrawler (该项目已放弃维护)

    一个专门为大模型设计的财经信息MCP(Model Context Protocol)服务,通过高效的爬虫技术从各大财经网站(同花顺、东方财富等)获取实时资讯,为AI模型提供准确、及时的财经数据支持。

    Community noimank