mcp2cli-runtime-api-tooling

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

mcp2cli — Runtime API to CLI

mcp2cli — 运行时API转CLI

Skill by ara.so — Devtools Skills collection.
mcp2cli dynamically converts MCP servers, OpenAPI specs, and GraphQL endpoints into CLIs at runtime, eliminating the need for code generation and reducing token waste by 96-99% when used with AI agents. It introspects APIs, generates subcommands, handles authentication (including OAuth), and caches schemas intelligently.
ara.so开发的Skill — Devtools Skills系列工具。
mcp2cli可在运行时动态将MCP服务器、OpenAPI规范和GraphQL端点转换为CLI,无需代码生成,与AI agent配合使用时可减少96-99%的令牌浪费。它能自动识别API、生成子命令、处理认证(包括OAuth)并智能缓存架构。

Installation

安装

bash
undefined
bash
undefined

Run directly without installing

无需安装直接运行

uvx mcp2cli --help
uvx mcp2cli --help

Or install globally

或全局安装

uv tool install mcp2cli
uv tool install mcp2cli

Install as an AI agent skill

作为AI agent skill安装

npx skills add knowsuchagency/mcp2cli --skill mcp2cli
undefined
npx skills add knowsuchagency/mcp2cli --skill mcp2cli
undefined

Core Concepts

核心概念

mcp2cli operates in four modes:
  • MCP HTTP/SSE: Connect to MCP servers over HTTP with SSE or streamable HTTP transport
  • MCP stdio: Launch and communicate with MCP servers via stdin/stdout
  • OpenAPI: Convert REST APIs with OpenAPI specs into CLIs
  • GraphQL: Introspect GraphQL endpoints and generate query/mutation commands
All modes support authentication, caching, and can be "baked" into named configurations for reuse.
mcp2cli支持四种运行模式:
  • MCP HTTP/SSE:通过HTTP(搭配SSE或流式HTTP传输)连接MCP服务器
  • MCP stdio:通过标准输入/输出启动并与MCP服务器通信
  • OpenAPI:将带有OpenAPI规范的REST API转换为CLI
  • GraphQL:自动识别GraphQL端点并生成查询/变更命令
所有模式均支持认证、缓存,且可“固化”为命名配置以便重复使用。

MCP HTTP/SSE Mode

MCP HTTP/SSE模式

bash
undefined
bash
undefined

List available tools from an MCP server

列出MCP服务器中的可用工具

mcp2cli --mcp https://mcp.example.com/sse --list
mcp2cli --mcp https://mcp.example.com/sse --list

Call a specific tool

调用指定工具

mcp2cli --mcp https://mcp.example.com/sse search --query "rust packages"
mcp2cli --mcp https://mcp.example.com/sse search --query "rust packages"

With authentication

带认证调用

mcp2cli --mcp https://mcp.example.com/sse
--auth-header "x-api-key:env:MCP_API_KEY"
query --sql "SELECT * FROM users LIMIT 10"
mcp2cli --mcp https://mcp.example.com/sse
--auth-header "x-api-key:env:MCP_API_KEY"
query --sql "SELECT * FROM users LIMIT 10"

Force specific transport (skip auto-detection)

强制使用指定传输方式(跳过自动检测)

mcp2cli --mcp https://mcp.example.com/sse --transport sse --list
mcp2cli --mcp https://mcp.example.com/sse --transport sse --list

Search for tools by name or description

按名称或描述搜索工具

mcp2cli --mcp https://mcp.example.com/sse --search "database"
undefined
mcp2cli --mcp https://mcp.example.com/sse --search "database"
undefined

MCP stdio Mode

MCP stdio模式

bash
undefined
bash
undefined

Launch an MCP server and list its tools

启动MCP服务器并列出其工具

mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp" --list
mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp" --list

Call a tool with arguments

带参数调用工具

mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp"
read-file --path /tmp/data.json
mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp"
read-file --path /tmp/data.json

Pass environment variables to the server process

向服务器进程传递环境变量

mcp2cli --mcp-stdio "node mcp-server.js"
--env "DATABASE_URL=env:DATABASE_URL"
--env "LOG_LEVEL=debug"
fetch-records --limit 50
undefined
mcp2cli --mcp-stdio "node mcp-server.js"
--env "DATABASE_URL=env:DATABASE_URL"
--env "LOG_LEVEL=debug"
fetch-records --limit 50
undefined

OpenAPI Mode

OpenAPI模式

bash
undefined
bash
undefined

List all endpoints from a remote spec

列出远程规范中的所有端点

Call an endpoint with parameters

带参数调用端点

mcp2cli --spec https://api.example.com/openapi.json
--base-url https://api.example.com
list-pets --status available --limit 20
mcp2cli --spec https://api.example.com/openapi.json
--base-url https://api.example.com
list-pets --status available --limit 20

Use a local spec file

使用本地规范文件

mcp2cli --spec ./openapi.yaml --base-url http://localhost:8000 --list
mcp2cli --spec ./openapi.yaml --base-url http://localhost:8000 --list

With authentication

带认证调用

mcp2cli --spec ./api-spec.json
--base-url https://api.example.com
--auth-header "Authorization:Bearer env:API_TOKEN"
create-item --name "Test Item" --price 99.99
mcp2cli --spec ./api-spec.json
--base-url https://api.example.com
--auth-header "Authorization:Bearer env:API_TOKEN"
create-item --name "Test Item" --price 99.99

POST with JSON body from stdin

通过标准输入传递JSON请求体

echo '{"name": "Fido", "species": "dog", "age": 3}' |
mcp2cli --spec ./spec.json create-pet --stdin
echo '{"name": "Fido", "species": "dog", "age": 3}' |
mcp2cli --spec ./spec.json create-pet --stdin

Pretty-print JSON output

格式化输出JSON

mcp2cli --spec ./spec.json --pretty list-users
undefined
mcp2cli --spec ./spec.json --pretty list-users
undefined

GraphQL Mode

GraphQL模式

bash
undefined
bash
undefined

List all queries and mutations

列出所有查询和变更命令

mcp2cli --graphql https://api.example.com/graphql --list
mcp2cli --graphql https://api.example.com/graphql --list

Execute a query

执行查询

mcp2cli --graphql https://api.example.com/graphql
users --limit 10
mcp2cli --graphql https://api.example.com/graphql
users --limit 10

Execute a mutation

执行变更

mcp2cli --graphql https://api.example.com/graphql
create-user --name "Alice" --email "alice@example.com" --role "admin"
mcp2cli --graphql https://api.example.com/graphql
create-user --name "Alice" --email "alice@example.com" --role "admin"

Override auto-generated field selection

覆盖自动生成的字段选择

mcp2cli --graphql https://api.example.com/graphql
users --fields "id name email createdAt"
mcp2cli --graphql https://api.example.com/graphql
users --fields "id name email createdAt"

With authentication

带认证调用

mcp2cli --graphql https://api.example.com/graphql
--auth-header "Authorization:Bearer env:GRAPHQL_TOKEN"
list-repositories --owner "knowsuchagency"
undefined
mcp2cli --graphql https://api.example.com/graphql
--auth-header "Authorization:Bearer env:GRAPHQL_TOKEN"
list-repositories --owner "knowsuchagency"
undefined

OAuth Authentication

OAuth认证

mcp2cli supports OAuth flows across all modes with automatic token caching and refresh.
bash
undefined
mcp2cli在所有模式下均支持OAuth流程,可自动缓存和刷新令牌。
bash
undefined

Authorization code + PKCE (opens browser)

授权码+PKCE流程(打开浏览器)

mcp2cli --mcp https://mcp.example.com/sse --oauth --list
mcp2cli --mcp https://mcp.example.com/sse --oauth --list

Client credentials flow (machine-to-machine)

客户端凭证流程(机器对机器)

mcp2cli --spec https://api.example.com/openapi.json
--oauth-client-id "env:OAUTH_CLIENT_ID"
--oauth-client-secret "env:OAUTH_CLIENT_SECRET"
list-resources
mcp2cli --spec https://api.example.com/openapi.json
--oauth-client-id "env:OAUTH_CLIENT_ID"
--oauth-client-secret "env:OAUTH_CLIENT_SECRET"
list-resources

With specific scopes

带指定权限范围

mcp2cli --graphql https://api.example.com/graphql
--oauth --oauth-scope "read:users write:posts"
create-post --title "Hello" --body "World"
mcp2cli --graphql https://api.example.com/graphql
--oauth --oauth-scope "read:users write:posts"
create-post --title "Hello" --body "World"

Local spec with OAuth requires --base-url for discovery

本地规范文件搭配OAuth需指定--base-url用于发现

mcp2cli --spec ./openapi.json
--base-url https://api.example.com
--oauth --list

Tokens are cached in `~/.cache/mcp2cli/oauth/` and automatically refreshed when expired.
mcp2cli --spec ./openapi.json
--base-url https://api.example.com
--oauth --list

令牌缓存于`~/.cache/mcp2cli/oauth/`,过期时会自动刷新。

Bake Mode — Named Configurations

固化模式 — 命名配置

Save connection settings and filters to avoid repeating flags.
bash
undefined
保存连接设置和过滤规则,避免重复输入参数。
bash
undefined

Create a baked configuration from OpenAPI spec

基于OpenAPI规范创建固化配置

mcp2cli bake create petstore
--spec https://api.example.com/openapi.json
--auth-header "Authorization:Bearer env:PETSTORE_TOKEN"
--exclude "delete-,update-"
--methods GET,POST
--cache-ttl 7200
mcp2cli bake create petstore
--spec https://api.example.com/openapi.json
--auth-header "Authorization:Bearer env:PETSTORE_TOKEN"
--exclude "delete-,update-"
--methods GET,POST
--cache-ttl 7200

Create from MCP stdio server

基于MCP stdio服务器创建固化配置

mcp2cli bake create github
--mcp-stdio "npx @modelcontextprotocol/server-github"
--env "GITHUB_TOKEN=env:GITHUB_TOKEN"
--include "search-,list-"
--exclude "delete-*"
mcp2cli bake create github
--mcp-stdio "npx @modelcontextprotocol/server-github"
--env "GITHUB_TOKEN=env:GITHUB_TOKEN"
--include "search-,list-"
--exclude "delete-*"

Create from MCP HTTP server with OAuth

基于带OAuth的MCP HTTP服务器创建固化配置

mcp2cli bake create analytics
--mcp https://analytics.example.com/mcp
--oauth --oauth-client-id "env:ANALYTICS_CLIENT_ID"
--oauth-client-secret "env:ANALYTICS_CLIENT_SECRET"
mcp2cli bake create analytics
--mcp https://analytics.example.com/mcp
--oauth --oauth-client-id "env:ANALYTICS_CLIENT_ID"
--oauth-client-secret "env:ANALYTICS_CLIENT_SECRET"

Use a baked tool with @ prefix

使用@前缀调用固化工具

mcp2cli @petstore --list mcp2cli @petstore list-pets --limit 10 mcp2cli @github search-repositories --query "rust mcp" mcp2cli @analytics query-metrics --start-date "2026-01-01"
mcp2cli @petstore --list mcp2cli @petstore list-pets --limit 10 mcp2cli @github search-repositories --query "rust mcp" mcp2cli @analytics query-metrics --start-date "2026-01-01"

Manage baked tools

管理固化工具

mcp2cli bake list mcp2cli bake show petstore mcp2cli bake update petstore --cache-ttl 3600 mcp2cli bake remove petstore
mcp2cli bake list mcp2cli bake show petstore mcp2cli bake update petstore --cache-ttl 3600 mcp2cli bake remove petstore

Install wrapper script to ~/.local/bin

安装包装脚本到~/.local/bin

mcp2cli bake install petstore
mcp2cli bake install petstore

Now you can run: petstore --list

现在可直接运行:petstore --list

Install to custom directory

安装到自定义目录

mcp2cli bake install github --dir ./scripts/

Configurations are stored in `~/.config/mcp2cli/baked.json`.
mcp2cli bake install github --dir ./scripts/

配置存储于`~/.config/mcp2cli/baked.json`。

Filtering and Discovery

过滤与发现

bash
undefined
bash
undefined

Include only specific tools (glob patterns)

仅包含指定工具(通配符模式)

mcp2cli bake create myapi
--spec ./spec.json
--include "list-,get-,search-*"
mcp2cli bake create myapi
--spec ./spec.json
--include "list-,get-,search-*"

Exclude specific tools

排除指定工具

mcp2cli bake create myapi
--spec ./spec.json
--exclude "delete-,admin-"
mcp2cli bake create myapi
--spec ./spec.json
--exclude "delete-,admin-"

Filter by HTTP methods (OpenAPI only)

按HTTP方法过滤(仅OpenAPI模式)

mcp2cli bake create readonly-api
--spec ./spec.json
--methods GET
mcp2cli bake create readonly-api
--spec ./spec.json
--methods GET

Search tools by name or description

按名称或描述搜索工具

mcp2cli @myapi --search "user" mcp2cli --spec ./spec.json --search "database query"
undefined
mcp2cli @myapi --search "user" mcp2cli --spec ./spec.json --search "database query"
undefined

Usage-Aware Tool Ranking

基于使用情况的工具排序

mcp2cli tracks tool usage locally and ranks output to reduce token costs.
bash
undefined
mcp2cli会本地跟踪工具使用情况,并对输出排序以降低令牌成本。
bash
undefined

List tools sorted by call frequency (default when usage data exists)

按调用频率排序列出工具(有使用数据时默认)

mcp2cli @myapi --list
mcp2cli @myapi --list

Top 10 most-used tools, compact format (~20 tokens vs ~1400)

显示使用最多的前10个工具,紧凑格式(约20令牌 vs 约1400令牌)

mcp2cli @myapi --list --top 10 --compact
mcp2cli @myapi --list --top 10 --compact

Sort by most recently used

按最近使用时间排序

mcp2cli @myapi --list --sort recent
mcp2cli @myapi --list --sort recent

Alphabetical sort

按字母排序

mcp2cli @myapi --list --sort alpha
mcp2cli @myapi --list --sort alpha

Show full descriptions (unwrapped)

显示完整描述(不折叠)

mcp2cli @myapi --list --verbose

Usage data is stored in `~/.cache/mcp2cli/usage.json`.
mcp2cli @myapi --list --verbose

使用数据存储于`~/.cache/mcp2cli/usage.json`。

Output Control

输出控制

bash
undefined
bash
undefined

Pretty-print JSON (auto-enabled for TTY)

格式化输出JSON(终端环境下自动启用)

mcp2cli @myapi list-records --pretty
mcp2cli @myapi list-records --pretty

Raw response body (no JSON parsing)

原始响应体(不解析JSON)

mcp2cli @myapi get-binary-data --raw > output.bin
mcp2cli @myapi get-binary-data --raw > output.bin

Limit output to first N records

限制输出前N条记录

mcp2cli @myapi list-users --head 5
mcp2cli @myapi list-users --head 5

TOON format — token-efficient encoding (40-60% fewer tokens)

TOON格式 — 高效令牌编码(令牌减少40-60%)

mcp2cli @myapi list-tags --toon
mcp2cli @myapi list-tags --toon

Pipe-friendly (compact JSON when not a TTY)

管道友好(非终端环境下输出紧凑JSON)

mcp2cli @myapi list-users | jq '.[] | select(.active == true) | .email'
undefined
mcp2cli @myapi list-users | jq '.[] | select(.active == true) | .email'
undefined

Caching

缓存

Specs and MCP tool lists are cached with a 1-hour TTL by default.
bash
undefined
规范文件和MCP工具列表默认缓存1小时。
bash
undefined

Force refresh (bypass cache)

强制刷新(绕过缓存)

mcp2cli --spec https://api.example.com/openapi.json --refresh --list
mcp2cli --spec https://api.example.com/openapi.json --refresh --list

Custom TTL in seconds

自定义缓存有效期(秒)

mcp2cli --mcp https://mcp.example.com/sse --cache-ttl 86400 --list
mcp2cli --mcp https://mcp.example.com/sse --cache-ttl 86400 --list

Custom cache key

自定义缓存键

mcp2cli --spec https://api.example.com/openapi.json
--cache-key my-api-prod --list
mcp2cli --spec https://api.example.com/openapi.json
--cache-key my-api-prod --list

Override cache directory

覆盖缓存目录

MCP2CLI_CACHE_DIR=/tmp/my-cache mcp2cli --spec ./spec.json --list

Local file specs are never cached.
MCP2CLI_CACHE_DIR=/tmp/my-cache mcp2cli --spec ./spec.json --list

本地文件规范不会被缓存。

Secrets Management

密钥管理

Avoid passing secrets in CLI arguments (visible in process lists) using
env:
or
file:
prefixes.
bash
undefined
避免在CLI参数中传递密钥(会显示在进程列表中),使用
env:
file:
前缀。
bash
undefined

Read from environment variable

从环境变量读取

mcp2cli --mcp https://mcp.example.com/sse
--auth-header "Authorization:env:MCP_TOKEN"
--list
mcp2cli --mcp https://mcp.example.com/sse
--auth-header "Authorization:env:MCP_TOKEN"
--list

Read from file

从文件读取

mcp2cli --mcp https://mcp.example.com/sse
--oauth-client-secret "file:/run/secrets/oauth_secret"
--oauth-client-id "env:OAUTH_CLIENT_ID"
--list
mcp2cli --mcp https://mcp.example.com/sse
--oauth-client-secret "file:/run/secrets/oauth_secret"
--oauth-client-id "env:OAUTH_CLIENT_ID"
--list

Works with secret managers that inject env vars

与注入环境变量的密钥管理器配合使用

vault kv get -field=token secret/mcp |
MCP_TOKEN=$(cat) mcp2cli --mcp https://mcp.example.com/sse
--auth-header "Authorization:env:MCP_TOKEN"
search --query "logs"
undefined
vault kv get -field=token secret/mcp |
MCP_TOKEN=$(cat) mcp2cli --mcp https://mcp.example.com/sse
--auth-header "Authorization:env:MCP_TOKEN"
search --query "logs"
undefined

Common Patterns

常见模式

Create a Project-Specific CLI Wrapper

创建项目专属CLI包装器

python
#!/usr/bin/env python3
"""Project-specific API wrapper using mcp2cli."""

import subprocess
import sys
import os

def main():
    """Run mcp2cli with project defaults."""
    cmd = [
        "mcp2cli",
        "--spec", "https://api.myproject.com/openapi.json",
        "--auth-header", f"Authorization:Bearer {os.environ['PROJECT_API_KEY']}",
        "--cache-ttl", "3600",
        *sys.argv[1:]
    ]
    subprocess.run(cmd, check=True)

if __name__ == "__main__":
    main()
python
#!/usr/bin/env python3
"""使用mcp2cli的项目专属API包装器。"""

import subprocess
import sys
import os

def main():
    """使用项目默认配置运行mcp2cli。"""
    cmd = [
        "mcp2cli",
        "--spec", "https://api.myproject.com/openapi.json",
        "--auth-header", f"Authorization:Bearer {os.environ['PROJECT_API_KEY']}",
        "--cache-ttl", "3600",
        *sys.argv[1:]
    ]
    subprocess.run(cmd, check=True)

if __name__ == "__main__":
    main()

Batch Operations with Shell

Shell批量操作

bash
#!/bin/bash
bash
#!/bin/bash

Batch create resources from CSV

从CSV批量创建资源

while IFS=, read -r name email role; do echo "Creating user: $name" mcp2cli @myapi create-user
--name "$name"
--email "$email"
--role "$role" done < users.csv
undefined
while IFS=, read -r name email role; do echo "创建用户: $name" mcp2cli @myapi create-user
--name "$name"
--email "$email"
--role "$role" done < users.csv
undefined

Combine with jq for Processing

结合jq处理数据

bash
undefined
bash
undefined

Extract specific fields and transform

提取指定字段并转换

mcp2cli @analytics get-metrics --period "2026-05" |
jq '[.data[] | {date: .timestamp, value: .metric_value}]' |
mcp2cli @warehouse import-timeseries --stdin
undefined
mcp2cli @analytics get-metrics --period "2026-05" |
jq '[.data[] | {date: .timestamp, value: .metric_value}]' |
mcp2cli @warehouse import-timeseries --stdin
undefined

Create a Skill from an API

基于API创建Skill

If you're building AI agent skills for APIs, use mcp2cli to generate the skill:
bash
undefined
如果您正在为API构建AI agent技能,可使用mcp2cli生成技能:
bash
undefined

Generate a skill from an OpenAPI spec

基于OpenAPI规范生成技能

mcp2cli --spec https://api.example.com/openapi.json --list > API_COMMANDS.txt
mcp2cli --spec https://api.example.com/openapi.json --list > API_COMMANDS.txt

Use the command list as reference in your SKILL.md

在SKILL.md中引用命令列表

Document the baked configuration approach for the skill

记录针对该技能的固化配置方法

undefined
undefined

Configuration Locations

配置位置

  • Baked configs:
    ~/.config/mcp2cli/baked.json
    (override with
    MCP2CLI_CONFIG_DIR
    )
  • Cache:
    ~/.cache/mcp2cli/
    (override with
    MCP2CLI_CACHE_DIR
    )
  • OAuth tokens:
    ~/.cache/mcp2cli/oauth/
  • Usage tracking:
    ~/.cache/mcp2cli/usage.json
  • 固化配置:
    ~/.config/mcp2cli/baked.json
    (可通过
    MCP2CLI_CONFIG_DIR
    覆盖)
  • 缓存:
    ~/.cache/mcp2cli/
    (可通过
    MCP2CLI_CACHE_DIR
    覆盖)
  • OAuth令牌:
    ~/.cache/mcp2cli/oauth/
  • 使用情况跟踪:
    ~/.cache/mcp2cli/usage.json

Troubleshooting

故障排查

OAuth flow fails to open browser

OAuth流程无法打开浏览器

bash
undefined
bash
undefined

Ensure DISPLAY is set (Linux) or browser is available

确保DISPLAY已设置(Linux)或浏览器可用

echo $DISPLAY
echo $DISPLAY

Use client credentials flow instead if available

若可用,改用客户端凭证流程

mcp2cli --spec ./spec.json
--oauth-client-id "env:CLIENT_ID"
--oauth-client-secret "env:CLIENT_SECRET"
--list
undefined
mcp2cli --spec ./spec.json
--oauth-client-id "env:CLIENT_ID"
--oauth-client-secret "env:CLIENT_SECRET"
--list
undefined

MCP transport auto-detection issues

MCP传输方式自动检测问题

bash
undefined
bash
undefined

Force specific transport

强制使用指定传输方式

mcp2cli --mcp https://mcp.example.com/sse --transport sse --list
mcp2cli --mcp https://mcp.example.com/sse --transport sse --list

Try streamable HTTP if SSE fails

若SSE失败,尝试流式HTTP

mcp2cli --mcp https://mcp.example.com/sse --transport streamable --list
undefined
mcp2cli --mcp https://mcp.example.com/sse --transport streamable --list
undefined

Cache not refreshing

缓存未刷新

bash
undefined
bash
undefined

Force refresh

强制刷新

mcp2cli @myapi --refresh --list
mcp2cli @myapi --refresh --list

Clear cache manually

手动清除缓存

rm -rf ~/.cache/mcp2cli/
rm -rf ~/.cache/mcp2cli/

Check cache TTL

检查缓存有效期

mcp2cli bake show myapi # inspect cache-ttl setting
undefined
mcp2cli bake show myapi # 查看cache-ttl设置
undefined

Secrets not loading from environment

密钥无法从环境变量加载

bash
undefined
bash
undefined

Verify environment variable is set

验证环境变量已设置

echo $MY_API_KEY
echo $MY_API_KEY

Use explicit env: prefix

使用明确的env:前缀

mcp2cli --mcp https://mcp.example.com/sse
--auth-header "x-api-key:env:MY_API_KEY"
--list
mcp2cli --mcp https://mcp.example.com/sse
--auth-header "x-api-key:env:MY_API_KEY"
--list

Debug with verbose output (if added in future versions)

未来版本可使用 verbose 输出调试

Currently: check that env var name matches exactly

当前:检查环境变量名称是否完全匹配

undefined
undefined

OpenAPI spec with relative servers

包含相对服务器地址的OpenAPI规范

bash
undefined
bash
undefined

Provide explicit base URL

提供明确的基础URL

mcp2cli --spec ./openapi.json --base-url https://api.example.com --list
undefined
mcp2cli --spec ./openapi.json --base-url https://api.example.com --list
undefined

GraphQL field selection too shallow

GraphQL字段选择过浅

bash
undefined
bash
undefined

Override auto-generated fields

覆盖自动生成的字段

mcp2cli --graphql https://api.example.com/graphql
users --fields "id name email profile { avatar bio } posts { id title }"
undefined
mcp2cli --graphql https://api.example.com/graphql
users --fields "id name email profile { avatar bio } posts { id title }"
undefined

Large response truncation

大响应被截断

bash
undefined
bash
undefined

Limit output size

限制输出大小

mcp2cli @myapi list-all-records --head 100 > sample.json
mcp2cli @myapi list-all-records --head 100 > sample.json

Use raw mode for binary data

针对二进制数据使用原始模式

mcp2cli @myapi download-file --file-id 123 --raw > output.pdf
undefined
mcp2cli @myapi download-file --file-id 123 --raw > output.pdf
undefined

Token Efficiency Analysis

令牌效率分析

When using mcp2cli with AI agents:
  • Traditional approach: Send full tool schemas every turn (~1,400 tokens for 96 tools)
  • mcp2cli approach:
    --list --compact
    (~20 tokens for tool names)
  • Savings: 96-99% reduction in tool schema tokens
  • Use
    --top N
    to further reduce token costs by showing only frequently-used tools
  • Use
    --toon
    output format for 40-60% smaller responses on large uniform arrays
与AI agent配合使用mcp2cli时:
  • 传统方式:每次交互发送完整工具架构(96个工具约1400令牌)
  • mcp2cli方式:
    --list --compact
    (仅工具名称约20令牌)
  • 节省:工具架构令牌减少96-99%
  • 使用
    --top N
    仅显示常用工具,进一步降低令牌成本
  • 针对大型统一数组,使用
    --toon
    输出格式可减少40-60%的令牌

Development Integration

开发集成

python
undefined
python
undefined

Use mcp2cli programmatically via subprocess

通过subprocess以编程方式调用mcp2cli

import subprocess import json
def call_api(tool: str, **kwargs): """Call mcp2cli and parse JSON response.""" args = ["mcp2cli", "@myapi", tool] for k, v in kwargs.items(): args.extend([f"--{k.replace('_', '-')}", str(v)])
result = subprocess.run(args, capture_output=True, text=True, check=True)
return json.loads(result.stdout)
import subprocess import json
def call_api(tool: str, **kwargs): """调用mcp2cli并解析JSON响应。""" args = ["mcp2cli", "@myapi", tool] for k, v in kwargs.items(): args.extend([f"--{k.replace('_', '-')}", str(v)])
result = subprocess.run(args, capture_output=True, text=True, check=True)
return json.loads(result.stdout)

Use it

使用示例

users = call_api("list-users", status="active", limit=50) for user in users: print(f"{user['name']} <{user['email']}>")
undefined
users = call_api("list-users", status="active", limit=50) for user in users: print(f"{user['name']} <{user['email']}>")
undefined

Real-World Example: GitHub MCP Server

实际案例:GitHub MCP服务器

bash
undefined
bash
undefined

Set up GitHub MCP server as a baked tool

将GitHub MCP服务器设置为固化工具

mcp2cli bake create github
--mcp-stdio "npx @modelcontextprotocol/server-github"
--env "GITHUB_TOKEN=env:GITHUB_TOKEN"
mcp2cli bake create github
--mcp-stdio "npx @modelcontextprotocol/server-github"
--env "GITHUB_TOKEN=env:GITHUB_TOKEN"

List all available GitHub operations

列出所有可用的GitHub操作

mcp2cli @github --list --compact
mcp2cli @github --list --compact

Search repositories

搜索仓库

mcp2cli @github search-repositories --query "mcp server" --limit 20 --pretty
mcp2cli @github search-repositories --query "mcp server" --limit 20 --pretty

Get repository details

获取仓库详情

mcp2cli @github get-repository --owner "knowsuchagency" --repo "mcp2cli"
mcp2cli @github get-repository --owner "knowsuchagency" --repo "mcp2cli"

Create an issue

创建Issue

mcp2cli @github create-issue
--owner "myorg"
--repo "myrepo"
--title "Feature request"
--body "Add support for X"
mcp2cli @github create-issue
--owner "myorg"
--repo "myrepo"
--title "Feature request"
--body "Add support for X"

Install as a standalone command

安装为独立命令

mcp2cli bake install github
mcp2cli bake install github

Now run: github search-repositories --query "rust"

现在可直接运行:github search-repositories --query "rust"


For complete documentation and token savings analysis, see the [full writeup](https://www.orangecountyai.com/blog/mcp2cli-one-cli-for-every-api-zero-wasted-tokens).

完整文档和令牌节省分析,请查看[详细文章](https://www.orangecountyai.com/blog/mcp2cli-one-cli-for-every-api-zero-wasted-tokens)。