cllm-mcp
用于从bash调用MCP(模型上下文协议)服务器的CLI工具。通过将工具调用卸载到命令行,使用守护进程模式进行批处理操作,减少LLM令牌的使用。
主要特点:
- 从bash直接调用MCP工具(消除80-95%的上下文开销)
- Daemon模式,批处理操作加速10-60倍
- CLLM式层次结构的配置管理
- 零外部依赖(仅限Python stdlib)
建筑
┌─────────────────┐
│ LLM / Agent │
└────────┬────────┘
│ calls bash script
▼
┌─────────────────┐
│ cllm-mcp CLI │
│ (command) │
└────────┬────────┘
│ invokes
▼
┌─────────────────┐
│ MCP Client │ ◄─── Core Implementation
└────────┬────────┘
│ JSON-RPC over stdio
▼
┌─────────────────┐
│ MCP Server │ (filesystem, github, etc.)
└─────────────────┘快速开始
基本用法
# List tools
cllm-mcp list-tools "npx -y @modelcontextprotocol/server-filesystem /tmp"
# Call a tool
cllm-mcp call-tool "npx -y @modelcontextprotocol/server-filesystem /tmp" \
read_file '{"path": "/tmp/test.txt"}'
# Interactive REPL
cllm-mcp interactive "npx -y @modelcontextprotocol/server-filesystem /tmp"
# Daemon mode (for batch operations)
cllm-mcp daemon start
cllm-mcp call-tool filesystem read_file '{"path": "/tmp/file.txt"}'
cllm-mcp daemon stop智能守护程序检测
命令在运行时自动检测和使用守护进程,并优雅地回退到直接模式。
配置
在中配置服务器 .cllm/mcp-config.json:
cllm-mcp config list # List configured servers
cllm-mcp config validate # Validate configuration
cllm-mcp config show # Display full configuration安装
# Clone and install
git clone
cd cllm-mcp
uv sync
# Run via uv or from installed location
uv run cllm-mcp --help
# or
cllm-mcp --help用法示例
直接服务器调用
# List tools
cllm-mcp list-tools "npx -y @modelcontextprotocol/server-filesystem /tmp"
# Call a tool
cllm-mcp call-tool "npx -y @modelcontextprotocol/server-filesystem /tmp" \
read_file '{"path": "/tmp/test.txt"}'基于配置(推荐)
创建 .cllm/mcp-config.json:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
"autoStart": true
},
"github": {
"command": "npx",
"args": ["@modelcontextprotocol/server-github"],
"env": {"GITHUB_TOKEN": "${GITHUB_TOKEN}"},
"autoStart": true
}
}
}然后按名称引用:
cllm-mcp list-tools filesystem
cllm-mcp call-tool filesystem read_file '{"path": "/tmp/test.txt"}'
cllm-mcp interactive filesystem使用Daemon进行批处理操作
cllm-mcp daemon start
# Multiple operations run fast (10-60x speedup)
for i in {1..100}; do
cllm-mcp call-tool filesystem read_file '{"path": "/tmp/file'$i'.txt"}'
done
cllm-mcp daemon stop与LLM集成
LLM可以将MCP操作委托给bash,将上下文减少80-95%。系统提示示例:
You have access to MCP servers via bash commands:
cllm-mcp list-tools # List available tools
cllm-mcp call-tool # Execute tool with JSON args
Example:
cllm-mcp call-tool filesystem read_file '{"path": "/tmp/file.txt"}'
cllm-mcp call-tool github create_issue '{"owner": "user", "repo": "repo", "title": "..."}'
All results are returned as JSON.通用MCP服务器
要配置的常用服务器:
- 文件系统:
npx -y @modelcontextprotocol/server-filesystem /tmp - GitHub:
npx @modelcontextprotocol/server-github(要求GITHUB_TOKEN) - SQLite:
npx @modelcontextprotocol/server-sqlite /path/to/db.sqlite - 勇敢的搜寻:
npx @modelcontextprotocol/server-brave-search(要求BRAVE_API_KEY) - 时间:
uvx mcp-server-time
使用 cllm-mcp list-tools 查看可用工具。
配置
存储于 .cllm/mcp-config.json (按顺序搜索: --config arg → CLLM_MCP_CONFIG env → ./mcp-config.json → ./.cllm/mcp-config.json → ~/.cllm/mcp-config.json).
架构:
{
"mcpServers": {
"server_name": {
"command": "npx",
"args": ["@modelcontextprotocol/server-name", "arg1"],
"env": {"API_KEY": "value"},
"autoStart": true,
"optional": false
}
}
}- 命令 (必填):可执行(例如。,
npx,python,uvx) - 参数 (必需):命令参数为数组
- 环境:环境变量
- 自动启动:守护进程启动时自动启动
- 可选的:如果服务器发生故障,不要让守护进程失败
高级用法
错误处理
返回退出代码 0 关于成功, 1 在向stderr发送消息时出错:
if ! output=$(cllm-mcp call-tool filesystem read_file '{"path": "/tmp/file.txt"}' 2>&1); then
echo "Error: $output" >&2
exit 1
fi使用jq进行处理
使用JSON处理的链操作:
# List files and process each
cllm-mcp daemon start
cllm-mcp call-tool filesystem list_directory '{"path": "/tmp"}' \
| jq -r '.contents[].name' \
| while read file; do
cllm-mcp call-tool filesystem read_file "{\"path\": \"/tmp/$file\"}"
done
cllm-mcp daemon stop守护程序模式
Daemon使服务器保持运行 10-60倍加速 批量操作。自动检测:无需标记。
cllm-mcp daemon start # Start once
cllm-mcp call-tool fs read_file '{...' # Auto-detects daemon
cllm-mcp daemon stop # Stop when done管理层:
cllm-mcp daemon start # Start background daemon
cllm-mcp daemon start --foreground # Start in foreground (debug)
cllm-mcp daemon status # Check if running
cllm-mcp daemon restart # Restart
cllm-mcp daemon stop # Stop配置:
- 服务器与
autoStart: true自动初始化 - 使用
optional: true忽略该服务器的启动失败 - 自定义插座:
cllm-mcp daemon start --socket /path/to/socket
项目结构
cllm_mcp/
├── main.py # Command dispatcher
├── client.py # Client implementation
├── config.py # Configuration management
├── daemon.py # Daemon commands
├── daemon_server.py # Daemon server
├── daemon_lifecycle.py # Daemon lifecycle
├── daemon_utils.py # Daemon utilities
├── json_rpc_client.py # JSON-RPC communication
├── socket_utils.py # Socket utilities
└── env_expansion.py # Environment variable expansion
docs/
├── decisions/ # Architecture Decision Records (ADR 0001-0008)
├── MIGRATION.md # Legacy command migration guide
└── testing/ # Test documentation
tests/ # Comprehensive test suite (100+ tests)
examples/ # Example scripts测试
uv run pytest # All tests
uv run pytest -m unit # Fast unit tests
uv run pytest -m daemon # Daemon tests
uv run pytest --cov # With coverage贡献
- 分叉存储库
- 创建要素分支
- 为您的更改添加测试
- 确保测试通过
- 提交拉取请求
看 贡献.md 了解详情。
体系结构决策
看 docs/decisions/ 对于ADR:
- ADR-0001:Vibe决策格式
- ADR-0002:
uv包管理器 - ADR-0003:统一的守护进程/客户端命令
- ADR-0004:CLLM样式配置
- ADR-0005:自动初始化服务器
- ADR-0006:工具调用示例
- ADR-0007:现代化的入口点
- ADR-0008:环境变量支持
资源
______________________________________________________________________
许可证:MIT 状态:积极维护 python: 3.7+
