mcp2cli-api-to-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesemcp2cli
mcp2cli
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。
Installation
安装
bash
undefinedbash
undefinedRun directly without installing
无需安装直接运行
uvx mcp2cli --help
uvx mcp2cli --help
Or install globally
或全局安装
uv tool install mcp2cli
uv tool install mcp2cli
Install as a skill for AI agents
作为AI Agent的Skill安装
npx skills add knowsuchagency/mcp2cli --skill mcp2cli
undefinednpx skills add knowsuchagency/mcp2cli --skill mcp2cli
undefinedCore 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 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、客户端凭证)
- 密钥管理(环境变量、文件)
- 使用情况追踪与智能工具排序
MCP HTTP Mode
MCP HTTP模式
Connect to MCP servers over HTTP with automatic transport negotiation:
bash
undefined通过HTTP连接MCP服务器,自动协商传输方式:
bash
undefinedList available tools
列出可用工具
mcp2cli --mcp https://mcp.example.com/sse --list
mcp2cli --mcp https://mcp.example.com/sse --list
Call a tool
调用工具
mcp2cli --mcp https://mcp.example.com/sse search --query "rust async"
mcp2cli --mcp https://mcp.example.com/sse search --query "rust async"
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"
--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"
--auth-header "x-api-key:env:MCP_API_KEY"
query --sql "SELECT * FROM users LIMIT 10"
Force specific transport (skip auto-negotiation)
强制指定传输方式(跳过自动协商)
mcp2cli --mcp https://mcp.example.com/sse --transport sse --list
mcp2cli --mcp https://mcp.example.com/sse --transport sse --list
Search tools by name or description
按名称或描述搜索工具
mcp2cli --mcp https://mcp.example.com/sse --search "database"
undefinedmcp2cli --mcp https://mcp.example.com/sse --search "database"
undefinedMCP stdio Mode
MCP stdio模式
Launch local MCP servers and communicate via stdio:
bash
undefined启动本地MCP服务器并通过标准输入输出通信:
bash
undefinedList tools from filesystem MCP server
列出文件系统MCP服务器的工具
mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp" --list
mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp" --list
Read a file
读取文件
mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp"
read-file --path /tmp/data.json
read-file --path /tmp/data.json
mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp"
read-file --path /tmp/data.json
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"
--env DATABASE_URL=env:DATABASE_URL
--env DEBUG=1
search --query "test"
undefinedmcp2cli --mcp-stdio "node ./custom-server.js"
--env DATABASE_URL=env:DATABASE_URL
--env DEBUG=1
search --query "test"
--env DATABASE_URL=env:DATABASE_URL
--env DEBUG=1
search --query "test"
undefinedOpenAPI Mode
OpenAPI模式
Generate CLI from OpenAPI specifications:
bash
undefined从OpenAPI规范生成CLI:
bash
undefinedRemote spec
远程规范
mcp2cli --spec https://petstore3.swagger.io/api/v3/openapi.json --list
mcp2cli --spec https://petstore3.swagger.io/api/v3/openapi.json --list
Local spec with base URL override
本地规范并覆盖基础URL
mcp2cli --spec ./openapi.yaml --base-url https://api.example.com --list
mcp2cli --spec ./openapi.yaml --base-url https://api.example.com --list
Call an endpoint
调用端点
mcp2cli --spec ./openapi.json --base-url https://api.example.com
list-pets --status available --limit 20
list-pets --status available --limit 20
mcp2cli --spec ./openapi.json --base-url https://api.example.com
list-pets --status available --limit 20
list-pets --status available --limit 20
POST with JSON body from stdin
通过标准输入传递JSON请求体的POST请求
echo '{"name": "Fido", "species": "dog"}' |
mcp2cli --spec ./openapi.json create-pet --stdin
mcp2cli --spec ./openapi.json create-pet --stdin
echo '{"name": "Fido", "species": "dog"}' |
mcp2cli --spec ./openapi.json create-pet --stdin
mcp2cli --spec ./openapi.json create-pet --stdin
With authentication
带认证
mcp2cli --spec ./openapi.json
--auth-header "Authorization:Bearer env:API_TOKEN"
create-item --name "New Item"
--auth-header "Authorization:Bearer env:API_TOKEN"
create-item --name "New Item"
undefinedmcp2cli --spec ./openapi.json
--auth-header "Authorization:Bearer env:API_TOKEN"
create-item --name "New Item"
--auth-header "Authorization:Bearer env:API_TOKEN"
create-item --name "New Item"
undefinedGraphQL Mode
GraphQL模式
Query GraphQL endpoints with automatic introspection:
bash
undefined通过自动自省查询GraphQL端点:
bash
undefinedList all queries and mutations
列出所有查询和变更操作
mcp2cli --graphql https://api.example.com/graphql --list
mcp2cli --graphql https://api.example.com/graphql --list
Execute a query (auto-generates selection set)
执行查询(自动生成选择集)
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"
create-user --name "Alice" --email "alice@example.com"
mcp2cli --graphql https://api.example.com/graphql
create-user --name "Alice" --email "alice@example.com"
create-user --name "Alice" --email "alice@example.com"
Override selection set fields
覆盖选择集字段
mcp2cli --graphql https://api.example.com/graphql
users --fields "id name email createdAt"
users --fields "id name email createdAt"
mcp2cli --graphql https://api.example.com/graphql
users --fields "id name email createdAt"
users --fields "id name email createdAt"
With authentication
带认证
mcp2cli --graphql https://api.example.com/graphql
--auth-header "Authorization:Bearer env:GRAPHQL_TOKEN"
users
--auth-header "Authorization:Bearer env:GRAPHQL_TOKEN"
users
undefinedmcp2cli --graphql https://api.example.com/graphql
--auth-header "Authorization:Bearer env:GRAPHQL_TOKEN"
users
--auth-header "Authorization:Bearer env:GRAPHQL_TOKEN"
users
undefinedOAuth Authentication
OAuth认证
All modes support OAuth 2.0 flows:
bash
undefined所有模式均支持OAuth 2.0流程:
bash
undefinedAuthorization code + PKCE (opens browser)
授权码+PKCE(打开浏览器)
mcp2cli --mcp https://mcp.example.com/sse --oauth --list
mcp2cli --spec https://api.example.com/openapi.json --oauth list-users
mcp2cli --graphql https://api.example.com/graphql --oauth users
mcp2cli --mcp https://mcp.example.com/sse --oauth --list
mcp2cli --spec https://api.example.com/openapi.json --oauth list-users
mcp2cli --graphql https://api.example.com/graphql --oauth users
Client credentials (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
--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
--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:users"
users
--oauth --oauth-scope "read:users write:users"
users
mcp2cli --graphql https://api.example.com/graphql
--oauth --oauth-scope "read:users write:users"
users
--oauth --oauth-scope "read:users write:users"
users
Local spec — provide base URL for OAuth discovery
本地规范——提供OAuth发现的基础URL
Tokens are cached in `~/.cache/mcp2cli/oauth/` and automatically refreshed.
Token会缓存到`~/.cache/mcp2cli/oauth/`并自动刷新。Secret Management
密钥管理
Avoid passing secrets as CLI arguments:
bash
undefined避免通过CLI参数传递密钥:
bash
undefinedRead from environment variable
从环境变量读取
Read from file
从文件读取
mcp2cli --spec ./openapi.json
--oauth-client-secret "file:/run/secrets/client_secret"
--oauth-client-id "file:/run/secrets/client_id"
--list
--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
--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"
MY_TOKEN=$(cat) mcp2cli --mcp https://mcp.example.com/sse
--auth-header "Authorization:env:MY_TOKEN"
search --query "data"
undefinedvault 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"
MY_TOKEN=$(cat) mcp2cli --mcp https://mcp.example.com/sse
--auth-header "Authorization:env:MY_TOKEN"
search --query "data"
undefinedBake Mode — Save Connection Settings
Bake模式——保存连接设置
Create reusable named configurations:
bash
undefined创建可复用的命名配置:
bash
undefinedCreate 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
--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
--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-*"
--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-*"
--mcp-stdio "npx @modelcontextprotocol/server-github"
--env GITHUB_TOKEN=env:GITHUB_TOKEN
--include "search-,list-"
--exclude "delete-*"
Create baked tool from GraphQL endpoint
从GraphQL端点创建预配置工具
mcp2cli bake create hasura
--graphql https://hasura.example.com/v1/graphql
--auth-header "x-hasura-admin-secret:env:HASURA_SECRET"
--graphql https://hasura.example.com/v1/graphql
--auth-header "x-hasura-admin-secret:env:HASURA_SECRET"
mcp2cli bake create hasura
--graphql https://hasura.example.com/v1/graphql
--auth-header "x-hasura-admin-secret:env:HASURA_SECRET"
--graphql https://hasura.example.com/v1/graphql
--auth-header "x-hasura-admin-secret:env:HASURA_SECRET"
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/
undefinedmcp2cli bake install petstore --dir ./scripts/
undefinedFiltering Options
过滤选项
bash
undefinedbash
undefinedInclude only specific tool patterns
仅包含特定工具模式
mcp2cli bake create myapi
--spec ./openapi.json
--include "list-,get-,search-*"
--spec ./openapi.json
--include "list-,get-,search-*"
mcp2cli bake create myapi
--spec ./openapi.json
--include "list-,get-,search-*"
--spec ./openapi.json
--include "list-,get-,search-*"
Exclude dangerous operations
排除危险操作
mcp2cli bake create myapi
--spec ./openapi.json
--exclude "delete-,destroy-"
--spec ./openapi.json
--exclude "delete-,destroy-"
mcp2cli bake create myapi
--spec ./openapi.json
--exclude "delete-,destroy-"
--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
--spec ./openapi.json
--methods GET,POST
undefinedmcp2cli bake create myapi
--spec ./openapi.json
--methods GET,POST
--spec ./openapi.json
--methods GET,POST
undefinedUsage-Aware Tool Ranking
基于使用情况的工具排序
Reduce token costs with intelligent tool ranking:
bash
undefined通过智能工具排序降低token成本:
bash
undefinedDefault list (sorted by usage frequency when available)
默认列表(可用时按使用频率排序)
mcp2cli @myapi --list
mcp2cli @myapi --list
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
Alphabetical sort
按字母顺序排序
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`。Output Control
输出控制
bash
undefinedbash
undefinedPretty-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)
mcp2cli --mcp https://mcp.example.com/sse --toon list-large-dataset
mcp2cli --mcp https://mcp.example.com/sse --toon list-large-dataset
Pipe-friendly output
便于管道处理的输出
mcp2cli --spec ./openapi.json list-users | jq '.[] | .email'
undefinedmcp2cli --spec ./openapi.json list-users | jq '.[] | .email'
undefinedCaching
缓存
Control spec and tool list caching:
bash
undefined控制规范和工具列表的缓存:
bash
undefinedForce 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 (7 days)
自定义TTL(7天)
mcp2cli --spec https://api.example.com/openapi.json --cache-ttl 604800 --list
mcp2cli --spec https://api.example.com/openapi.json --cache-ttl 604800 --list
Custom cache key
自定义缓存键
mcp2cli --spec https://api.example.com/openapi.json --cache-key prod-api --list
mcp2cli --spec https://api.example.com/openapi.json --cache-key prod-api --list
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小时)Common Patterns
常见模式
Create a Skill from an API
从API创建Skill
bash
undefinedbash
undefinedGenerate a skill configuration for an OpenAPI service
为OpenAPI服务生成Skill配置
mcp2cli --spec https://api.example.com/openapi.json --list
mcp2cli --spec https://api.example.com/openapi.json --list
Create baked tool for easier access
创建预配置工具以便访问
mcp2cli bake create myservice
--spec https://api.example.com/openapi.json
--auth-header "Authorization:Bearer env:MYSERVICE_TOKEN"
--spec https://api.example.com/openapi.json
--auth-header "Authorization:Bearer env:MYSERVICE_TOKEN"
mcp2cli bake create myservice
--spec https://api.example.com/openapi.json
--auth-header "Authorization:Bearer env:MYSERVICE_TOKEN"
--spec https://api.example.com/openapi.json
--auth-header "Authorization:Bearer env:MYSERVICE_TOKEN"
Use in skill workflows
在Skill工作流中使用
mcp2cli @myservice list-resources --format json | jq '.[] | select(.active == true)'
undefinedmcp2cli @myservice list-resources --format json | jq '.[] | select(.active == true)'
undefinedMulti-Environment Setup
多环境配置
bash
undefinedbash
undefinedDevelopment environment
开发环境
mcp2cli bake create myapi-dev
--spec https://dev-api.example.com/openapi.json
--auth-header "Authorization:Bearer env:DEV_TOKEN"
--spec https://dev-api.example.com/openapi.json
--auth-header "Authorization:Bearer env:DEV_TOKEN"
mcp2cli bake create myapi-dev
--spec https://dev-api.example.com/openapi.json
--auth-header "Authorization:Bearer env:DEV_TOKEN"
--spec https://dev-api.example.com/openapi.json
--auth-header "Authorization:Bearer env:DEV_TOKEN"
Production environment
生产环境
mcp2cli bake create myapi-prod
--spec https://api.example.com/openapi.json
--auth-header "Authorization:Bearer env:PROD_TOKEN"
--spec https://api.example.com/openapi.json
--auth-header "Authorization:Bearer env:PROD_TOKEN"
mcp2cli bake create myapi-prod
--spec https://api.example.com/openapi.json
--auth-header "Authorization:Bearer env:PROD_TOKEN"
--spec https://api.example.com/openapi.json
--auth-header "Authorization:Bearer env:PROD_TOKEN"
Use environment-specific tools
使用环境专属工具
mcp2cli @myapi-dev test-endpoint --data "test"
mcp2cli @myapi-prod get-metrics --period "24h"
undefinedmcp2cli @myapi-dev test-endpoint --data "test"
mcp2cli @myapi-prod get-metrics --period "24h"
undefinedChaining with MCP Servers
与MCP服务器链式调用
bash
undefinedbash
undefinedUse 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)
read-file --path /etc/myapp/config.json)
echo "$CONFIG" | jq -r '.api_endpoint' |
xargs -I {} mcp2cli --spec {}/openapi.json --list
xargs -I {} mcp2cli --spec {}/openapi.json --list
undefinedCONFIG=$(mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /etc"
read-file --path /etc/myapp/config.json)
read-file --path /etc/myapp/config.json)
echo "$CONFIG" | jq -r '.api_endpoint' |
xargs -I {} mcp2cli --spec {}/openapi.json --list
xargs -I {} mcp2cli --spec {}/openapi.json --list
undefinedFiltering Large Tool Lists
过滤大型工具列表
bash
undefinedbash
undefinedSearch 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
undefinedmcp2cli @myapi --list --top 20 --compact
undefinedPython 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())Troubleshooting
故障排除
OAuth Flow Fails
OAuth流程失败
bash
undefinedbash
undefinedClear cached tokens
清除缓存的token
rm -rf ~/.cache/mcp2cli/oauth/
rm -rf ~/.cache/mcp2cli/oauth/
Retry with verbose output
启用详细输出重试
mcp2cli --spec ./openapi.json --oauth --list --verbose
undefinedmcp2cli --spec ./openapi.json --oauth --list --verbose
undefinedMCP Server Connection Issues
MCP服务器连接问题
bash
undefinedbash
undefinedTest transport explicitly
显式测试传输方式
mcp2cli --mcp https://mcp.example.com/sse --transport sse --list
mcp2cli --mcp https://mcp.example.com/sse --transport streamable --list
mcp2cli --mcp https://mcp.example.com/sse --transport sse --list
mcp2cli --mcp https://mcp.example.com/sse --transport streamable --list
Check server logs if using stdio
如果使用stdio,检查服务器日志
mcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp"
--env DEBUG=*
--list
--env DEBUG=*
--list
undefinedmcp2cli --mcp-stdio "npx @modelcontextprotocol/server-filesystem /tmp"
--env DEBUG=*
--list
--env DEBUG=*
--list
undefinedCache Issues
缓存问题
bash
undefinedbash
undefinedForce refresh
强制刷新
mcp2cli --spec ./openapi.json --refresh --list
mcp2cli --spec ./openapi.json --refresh --list
Clear all cache
清除所有缓存
rm -rf ~/.cache/mcp2cli/
rm -rf ~/.cache/mcp2cli/
Use temporary cache location
使用临时缓存位置
MCP2CLI_CACHE_DIR=/tmp/test-cache mcp2cli --spec ./openapi.json --list
undefinedMCP2CLI_CACHE_DIR=/tmp/test-cache mcp2cli --spec ./openapi.json --list
undefinedTool Not Found After Baking
预配置工具创建后找不到
bash
undefinedbash
undefinedCheck baked tool exists
检查预配置工具是否存在
mcp2cli bake list
mcp2cli bake list
Verify configuration
验证配置
mcp2cli bake show myapi
mcp2cli bake show myapi
Recreate with explicit filters
使用显式过滤重新创建
mcp2cli bake update myapi --include "*"
undefinedmcp2cli bake update myapi --include "*"
undefinedLarge Response Truncation
大响应被截断
bash
undefinedbash
undefinedUse --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
undefinedmcp2cli @myapi list-all --toon
undefinedConfiguration
配置
Configuration directory:
Cache directory:
~/.config/mcp2cli/~/.cache/mcp2cli/Override with environment variables:
- : Configuration directory
MCP2CLI_CONFIG_DIR - : Cache directory
MCP2CLI_CACHE_DIR
Baked tools are stored in
Usage tracking in
OAuth tokens in
~/.config/mcp2cli/baked.json~/.cache/mcp2cli/usage.json~/.cache/mcp2cli/oauth/配置目录:
缓存目录:
~/.config/mcp2cli/~/.cache/mcp2cli/可通过环境变量覆盖:
- : 配置目录
MCP2CLI_CONFIG_DIR - : 缓存目录
MCP2CLI_CACHE_DIR
预配置工具存储于
使用情况追踪存储于
OAuth token存储于
~/.config/mcp2cli/baked.json~/.cache/mcp2cli/usage.json~/.cache/mcp2cli/oauth/