Skip to main content

Turn any CLI tool into an MCP server

Project description

cli2mcp -- Turn any CLI into an MCP Server

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

cli2mcp scans a CLI tool's --help output, extracts its arguments and subcommands, and generates a JSON descriptor file. It can then serve that file as a fully functional MCP server -- letting AI assistants call the CLI tool 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 in the JSON file as a callable tool.

To use HTTP transport instead:

uv run cli2mcp serve curl.tools.json -t streamable-http

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cli2mcp-0.1.1.tar.gz (87.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cli2mcp-0.1.1-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file cli2mcp-0.1.1.tar.gz.

File metadata

  • Download URL: cli2mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 87.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for cli2mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f1f5e6bd68dd5278db1d0d86f5465e87e7b4e557d16a229fe127d4f39e2ddb74
MD5 7fa754aa52d9ddb7d96d4113e75d6fd4
BLAKE2b-256 bc3039ebadacbc1d42e56ab797a047bc9fa33abb23479376a8a5a1b6b6d1ab66

See more details on using hashes here.

File details

Details for the file cli2mcp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cli2mcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for cli2mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9546220891518375dfb66186b93f88f7296f8c1f3ea2b61778088e434e593128
MD5 9ab7b60e1104f019d52c3c0b828cae66
BLAKE2b-256 d7a02c14fc6643f16d1ffec09d9a2c983902d7d14816f93dc065519054b676c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page