Skill by
ara.so — MCP Skills collection.
mcp2cli converts any MCP server, OpenAPI specification, or GraphQL endpoint into a CLI at runtime without code generation. It dramatically reduces token consumption by replacing repeated tool schema transmissions with simple CLI calls — saving 96-99% of tokens on every LLM turn.
由
ara.so开发的Skill — MCP Skills集合。
mcp2cli可在无需代码生成的情况下,在运行时将任意MCP服务器、OpenAPI规范或GraphQL端点转换为CLI。它通过用简单的CLI调用替代重复的工具架构传输,大幅减少token消耗——在每次LLM交互中节省96-99%的token。
Run directly without installing
无需安装直接运行
Install as a skill for AI agents
作为AI Agent的Skill安装
npx skills add knowsuchagency/mcp2cli --skill mcp2cli
npx skills add knowsuchagency/mcp2cli --skill mcp2cli
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 local MCP servers via stdio
- OpenAPI: Generate CLI from OpenAPI 3.x specs (JSON or YAML)
- GraphQL: Introspect and query GraphQL endpoints
All modes support:
- Dynamic command generation (no codegen step)
- Automatic caching with configurable TTL
- OAuth 2.0 flows (authorization code + PKCE, client credentials)
- Secret management (env vars, files)
- Usage tracking and intelligent tool ranking
mcp2cli支持四种运行模式:
- MCP HTTP/SSE:通过HTTP连接MCP服务器,支持SSE或可流式传输的HTTP传输
- MCP stdio:启动本地MCP服务器并通过标准输入输出(stdio)通信
- OpenAPI:从OpenAPI 3.x规范(JSON或YAML)生成CLI
- GraphQL:自动自省(introspect)并查询GraphQL端点
所有模式均支持:
- 动态命令生成(无需代码生成步骤)
- 可配置TTL的自动缓存
- OAuth 2.0流程(授权码+PKCE、客户端凭证)
- 密钥管理(环境变量、文件)
- 使用情况追踪与智能工具排序
Connect to MCP servers over HTTP with automatic transport negotiation:
List available tools
列出可用工具
Force specific transport (skip auto-negotiation)
强制指定传输方式(跳过自动协商)
Search tools by name or description
按名称或描述搜索工具
MCP stdio Mode
MCP stdio模式
Launch local MCP servers and communicate via stdio:
List tools from filesystem MCP server
列出文件系统MCP服务器的工具
mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp" --list
mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp" --list
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
向服务器传递环境变量
mcp2cli --mcp-stdio "node ./custom-server.js"
--env DATABASE_URL=env:DATABASE_URL
--env DEBUG=1
search --query "test"
mcp2cli --mcp-stdio "node ./custom-server.js"
--env DATABASE_URL=env:DATABASE_URL
--env DEBUG=1
search --query "test"
Generate CLI from OpenAPI specifications:
Local spec with base URL override
本地规范并覆盖基础URL
POST with JSON body from stdin
通过标准输入传递JSON请求体的POST请求
echo '{"name": "Fido", "species": "dog"}' |
mcp2cli --spec ./openapi.json create-pet --stdin
echo '{"name": "Fido", "species": "dog"}' |
mcp2cli --spec ./openapi.json create-pet --stdin
mcp2cli --spec ./openapi.json
--auth-header "Authorization:Bearer env:API_TOKEN"
create-item --name "New Item"
mcp2cli --spec ./openapi.json
--auth-header "Authorization:Bearer env:API_TOKEN"
create-item --name "New Item"
Query GraphQL endpoints with automatic introspection:
List all queries and mutations
列出所有查询和变更操作
Execute a query (auto-generates selection set)
执行查询(自动生成选择集)
Override selection set fields
覆盖选择集字段
OAuth Authentication
OAuth认证
All modes support OAuth 2.0 flows:
Authorization code + PKCE (opens browser)
授权码+PKCE(打开浏览器)
Client credentials (machine-to-machine)
客户端凭证(机器对机器)
With specific scopes
指定权限范围
Local spec — provide base URL for OAuth discovery
本地规范——提供OAuth发现的基础URL
mcp2cli --spec ./openapi.json
--base-url
https://api.example.com
--oauth
--list
Tokens are cached in `~/.cache/mcp2cli/oauth/` and automatically refreshed.
mcp2cli --spec ./openapi.json
--base-url
https://api.example.com
--oauth
--list
Token会缓存到`~/.cache/mcp2cli/oauth/`并自动刷新。
Avoid passing secrets as CLI arguments:
Read from environment variable
从环境变量读取
mcp2cli --spec ./openapi.json
--oauth-client-secret "file:/run/secrets/client_secret"
--oauth-client-id "file:/run/secrets/client_id"
--list
mcp2cli --spec ./openapi.json
--oauth-client-secret "file:/run/secrets/client_secret"
--oauth-client-id "file:/run/secrets/client_id"
--list
Works with secret managers
与密钥管理器配合使用
vault kv get -field=token secret/api |
MY_TOKEN=$(cat) mcp2cli --mcp
https://mcp.example.com/sse
--auth-header "Authorization:env:MY_TOKEN"
search --query "data"
vault kv get -field=token secret/api |
MY_TOKEN=$(cat) mcp2cli --mcp
https://mcp.example.com/sse
--auth-header "Authorization:env:MY_TOKEN"
search --query "data"
Bake Mode — Save Connection Settings
Bake模式——保存连接设置
Create reusable named configurations:
Create baked tool 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 baked tool 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 baked tool from GraphQL endpoint
从GraphQL端点创建预配置工具
Use baked tool with @ prefix
使用@前缀调用预配置工具
mcp2cli @petstore --list
mcp2cli @petstore list-pets --limit 5
mcp2cli @github search-repos --query "mcp server"
mcp2cli @hasura users --limit 10
mcp2cli @petstore --list
mcp2cli @petstore list-pets --limit 5
mcp2cli @github search-repos --query "mcp server"
mcp2cli @hasura users --limit 10
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 as standalone script
安装为独立脚本
mcp2cli bake install petstore
mcp2cli bake install petstore
Creates ~/.local/bin/petstore wrapper
创建~/.local/bin/petstore包装器
Install to custom directory
安装到自定义目录
mcp2cli bake install petstore --dir ./scripts/
mcp2cli bake install petstore --dir ./scripts/
Include only specific tool patterns
仅包含特定工具模式
mcp2cli bake create myapi
--spec ./openapi.json
--include "list-,get-,search-*"
mcp2cli bake create myapi
--spec ./openapi.json
--include "list-,get-,search-*"
Exclude dangerous operations
排除危险操作
mcp2cli bake create myapi
--spec ./openapi.json
--exclude "delete-,destroy-"
mcp2cli bake create myapi
--spec ./openapi.json
--exclude "delete-,destroy-"
Limit to specific HTTP methods (OpenAPI only)
限制为特定HTTP方法(仅OpenAPI)
mcp2cli bake create myapi
--spec ./openapi.json
--methods GET,POST
mcp2cli bake create myapi
--spec ./openapi.json
--methods GET,POST
Usage-Aware Tool Ranking
基于使用情况的工具排序
Reduce token costs with intelligent tool ranking:
Default list (sorted by usage frequency when available)
默认列表(可用时按使用频率排序)
Top 10 most-used tools, compact output (~20 tokens)
前10个最常用工具,精简输出(约20个token)
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
mcp2cli @myapi --list --sort alpha
mcp2cli @myapi --list --sort alpha
Show full descriptions
显示完整描述
mcp2cli @myapi --list --verbose
Usage data is tracked locally in `~/.cache/mcp2cli/usage.json`.
mcp2cli @myapi --list --verbose
使用数据会在本地追踪并存储于`~/.cache/mcp2cli/usage.json`。
Pretty-print JSON (auto-enabled for TTY)
格式化输出JSON(终端环境自动启用)
mcp2cli --spec ./openapi.json --pretty list-users
mcp2cli --spec ./openapi.json --pretty list-users
Raw response body (no JSON parsing)
原始响应体(不解析JSON)
mcp2cli --spec ./openapi.json --raw get-binary-data
mcp2cli --spec ./openapi.json --raw get-binary-data
Limit output to first N records
限制输出前N条记录
mcp2cli --spec ./openapi.json list-logs --head 20
mcp2cli --spec ./openapi.json list-logs --head 20
TOON output (40-60% fewer tokens for LLMs)
TOON输出(LLM使用时可减少40-60%的token)
Pipe-friendly output
便于管道处理的输出
mcp2cli --spec ./openapi.json list-users | jq '.[] | .email'
mcp2cli --spec ./openapi.json list-users | jq '.[] | .email'
Control spec and tool list caching:
Force refresh (bypass cache)
强制刷新(绕过缓存)
Custom TTL (7 days)
自定义TTL(7天)
Override cache directory
覆盖缓存目录
MCP2CLI_CACHE_DIR=/tmp/my-cache mcp2cli --spec ./openapi.json --list
Default cache location: `~/.cache/mcp2cli/`
Default TTL: 3600 seconds (1 hour)
MCP2CLI_CACHE_DIR=/tmp/my-cache mcp2cli --spec ./openapi.json --list
默认缓存位置:`~/.cache/mcp2cli/`
默认TTL:3600秒(1小时)
Create a Skill from an API
从API创建Skill
Generate a skill configuration for an OpenAPI service
为OpenAPI服务生成Skill配置
Create baked tool for easier access
创建预配置工具以便访问
Use in skill workflows
在Skill工作流中使用
mcp2cli @myservice list-resources --format json | jq '.[] | select(.active == true)'
mcp2cli @myservice list-resources --format json | jq '.[] | select(.active == true)'
Multi-Environment Setup
多环境配置
Development environment
开发环境
Production environment
生产环境
Use environment-specific tools
使用环境专属工具
mcp2cli @myapi-dev test-endpoint --data "test"
mcp2cli @myapi-prod get-metrics --period "24h"
mcp2cli @myapi-dev test-endpoint --data "test"
mcp2cli @myapi-prod get-metrics --period "24h"
Chaining with MCP Servers
与MCP服务器链式调用
Use filesystem MCP to read config, then call API
使用文件系统MCP读取配置,然后调用API
CONFIG=$(mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /etc"
read-file --path /etc/myapp/config.json)
echo "$CONFIG" | jq -r '.api_endpoint' |
xargs -I {} mcp2cli --spec {}/openapi.json --list
CONFIG=$(mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /etc"
read-file --path /etc/myapp/config.json)
echo "$CONFIG" | jq -r '.api_endpoint' |
xargs -I {} mcp2cli --spec {}/openapi.json --list
Filtering Large Tool Lists
过滤大型工具列表
Search tools related to users
搜索与用户相关的工具
mcp2cli @myapi --search "user"
mcp2cli @myapi --search "user"
List only creation operations
仅列出创建类操作
mcp2cli @myapi --list | grep "^create-"
mcp2cli @myapi --list | grep "^create-"
Get compact list of top tools for LLM context
获取精简的常用工具列表用于LLM上下文
mcp2cli @myapi --list --top 20 --compact
mcp2cli @myapi --list --top 20 --compact
Python API Usage
Python API使用
While mcp2cli is primarily a CLI tool, you can use its components programmatically:
python
from mcp2cli.openapi import load_spec
from mcp2cli.client import make_request
import asyncio
async def call_api():
# Load OpenAPI spec
spec = await load_spec("https://api.example.com/openapi.json")
# Make request
response = await make_request(
spec=spec,
operation_id="listPets",
params={"limit": 10},
auth_headers={"Authorization": "Bearer token"}
)
return response
result = asyncio.run(call_api())
虽然mcp2cli主要是CLI工具,但你也可以通过编程方式使用其组件:
python
from mcp2cli.openapi import load_spec
from mcp2cli.client import make_request
import asyncio
async def call_api():
# 加载OpenAPI规范
spec = await load_spec("https://api.example.com/openapi.json")
# 发起请求
response = await make_request(
spec=spec,
operation_id="listPets",
params={"limit": 10},
auth_headers={"Authorization": "Bearer token"}
)
return response
result = asyncio.run(call_api())
OAuth Flow Fails
OAuth流程失败
Clear cached tokens
清除缓存的token
rm -rf ~/.cache/mcp2cli/oauth/
rm -rf ~/.cache/mcp2cli/oauth/
Retry with verbose output
启用详细输出重试
mcp2cli --spec ./openapi.json --oauth --list --verbose
mcp2cli --spec ./openapi.json --oauth --list --verbose
MCP Server Connection Issues
MCP服务器连接问题
Test transport explicitly
显式测试传输方式
Check server logs if using stdio
如果使用stdio,检查服务器日志
mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp"
--env DEBUG=*
--list
mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp"
--env DEBUG=*
--list
mcp2cli --spec ./openapi.json --refresh --list
mcp2cli --spec ./openapi.json --refresh --list
Use temporary cache location
使用临时缓存位置
MCP2CLI_CACHE_DIR=/tmp/test-cache mcp2cli --spec ./openapi.json --list
MCP2CLI_CACHE_DIR=/tmp/test-cache mcp2cli --spec ./openapi.json --list
Tool Not Found After Baking
预配置工具创建后找不到
Check baked tool exists
检查预配置工具是否存在
Recreate with explicit filters
使用显式过滤重新创建
mcp2cli bake update myapi --include "*"
mcp2cli bake update myapi --include "*"
Large Response Truncation
大响应被截断
Use --head to limit records
使用--head限制记录数
mcp2cli @myapi list-all --head 100
mcp2cli @myapi list-all --head 100
Use --raw to get full response
使用--raw获取完整响应
mcp2cli @myapi list-all --raw > output.json
mcp2cli @myapi list-all --raw > output.json
Use TOON for token efficiency
使用TOON提升token效率
mcp2cli @myapi list-all --toon
mcp2cli @myapi list-all --toon
Configuration directory:
Cache directory:
Override with environment variables:
- : Configuration directory
- : Cache directory
Baked tools are stored in
~/.config/mcp2cli/baked.json
Usage tracking in
~/.cache/mcp2cli/usage.json
OAuth tokens in
可通过环境变量覆盖:
预配置工具存储于
~/.config/mcp2cli/baked.json
使用情况追踪存储于
~/.cache/mcp2cli/usage.json
OAuth token存储于