MCP-CLI
 
Rust中的MCP CLI客户端——无运行时依赖的跨平台MCP服务器交互
一个CLI,用于使用惰性后台守护进程从模型上下文协议(MCP)服务器中发现、检查和执行工具。适用于Linux、macOS和 视窗 (通过命名管道)。
这只是一个纯粹的实验。我不打算严重依赖它。使用原件https://github.com/philschmid/mcp-cli.
______________________________________________________________________
快速开始
# Install from source
git clone https://github.com/gtrak/mcp-cli-rs.git
cd mcp-cli-rs
cargo build --release
# Create config at ~/.config/mcp/mcp_servers.toml
cat > ~/.config/mcp/mcp_servers.toml # Server details (transport, tools count)
mcp info # Tool schema (parameters, description)
# Examples
mcp info filesystem
mcp info filesystem read_file
mcp info fetch fetch_urlcall --执行工具
# With JSON argument
mcp call ''
mcp call ''
# Examples
mcp call filesystem read_file '{"path": "/etc/hosts"}'
mcp call filesystem/read_file '{"path": "/etc/hosts"}'
# With arguments from stdin
echo '{"url": "https://example.com"}' | mcp call fetch fetch_url
# Flag-style arguments (auto-converted to JSON)
mcp call fetch fetch_url --url https://example.com
mcp call filesystem read_file --path /etc/hosts --limit 100search --按图案查找工具
mcp search "*file*" # Find tools with "file" in the name
mcp search "read*" # Glob pattern matchingdaemon --连接缓存
mcp daemon # Start daemon (runs in foreground)
mcp daemon --ttl 300 # Start with custom 5-minute TTL
mcp shutdown # Stop running daemon守护进程模式:
--no-daemon:直接模式,无缓存(速度较慢但更简单)--auto-daemon:如果需要,生成守护进程(默认,推荐)--require-daemon:如果守护进程未运行,则失败
______________________________________________________________________
发展
设置
git clone https://github.com/gary/mcp-cli-rs.git
cd mcp-cli-rs构建
cargo build # Debug build
cargo build --release # Optimized release build测试
# Run library tests
cargo test --lib
# Run integration tests
cargo test --test '*'
# Run all tests
cargo test项目结构
src/
├── cli/ # CLI parsing and command dispatch
├── client/ # MCP client implementations (stdio, HTTP)
├── config/ # Configuration loading and types
├── daemon/ # Daemon lifecycle and management
├── error/ # Error types and handling
├── format/ # Output formatting (text, JSON)
├── ipc/ # Inter-process communication (sockets/pipes)
├── server/ # MCP server protocol handling
├── shutdown/ # Graceful shutdown handling
└── transport/ # Transport abstractions______________________________________________________________________
故障排除
“守护进程未运行”
启动守护进程:
mcp daemon
# Or use direct mode:
mcp --no-daemon list“找不到配置文件”
创建配置文件:
mkdir -p ~/.config/mcp
cat > ~/.config/mcp/mcp_servers.toml `
- 验证服务器是否正在运行: `mcp info `
### “连接被拒绝”或“没有这样的文件或目录”
- 验证MCP服务器包是否已安装(例如。, `npx @modelcontextprotocol/server-filesystem`)
- 检查配置中的命令路径
- 对于HTTP服务器,请验证URL是否可访问: `curl http://localhost:3000/mcp`
### Windows特定
在Windows上,命名管道要求守护进程正在运行:
Start daemon first
mcp daemon
Then use in another terminal
mcp list
### 获取调试输出
Enable debug logging
RUST_LOG=debug mcp list
Check daemon logs
cat ~/.cache/mcp-cli/daemon.log
______________________________________________________________________
## 许可证
MIT许可证-请参阅 [许可证](LICENSE) 了解详情。
______________________________________________________________________
## 另见
- [模型上下文协议](https://modelcontextprotocol.io/) --MCP规范
- [原始MCP CLI](https://github.com/f/modelcontextprotocol) --基于Bun的实现激发了这次重写