我的cli更漂亮
一个CLI工具,将MCP(模型上下文协议)服务器作为本地命令行工具公开。
为什么?
MCP服务器允许AI代理与外部系统交互,但将许多服务器加载到代理的上下文中会降低性能。此工具提供了一种不同的方法:
- 可发现的:代理可以通过以下方式探索可用的服务器和工具
--help - 轻量级:只加载您调用的工具,而不是整个MCP生态系统
- 熟悉的:任何代理(或人类)都可以使用的标准CLI界面
快速开始
# Clone and install
git clone https://github.com/pablozaiden/my-cli-prettier.git
cd my-cli-prettier
bun install
# Initialize config with example servers
bun start -- config --action init
# List available servers
bun start -- server list
# Explore a server's tools
bun start -- everything help
# Call a tool
bun start -- everything echo --message "Hello MCP!"安装
先决条件
从源代码运行
bun install
bun start -- 编译为二进制
npm run compile
./out/mcp 配置
配置存储在 ~/.my-cli-prettier/config.json:
{
"servers": {
"memory": {
"transport": "stdio",
"command": "bunx",
"args": ["-y", "@modelcontextprotocol/server-memory"],
"description": "Simple key-value memory store"
},
"fetch": {
"transport": "stdio",
"command": "bunx",
"args": ["-y", "@modelcontextprotocol/server-fetch"],
"description": "Fetch and convert web content"
}
},
"settings": {
"cacheEnabled": true,
"cacheTtlMs": 14400000
}
}服务器类型
Stdio服务器 -本地流程:
{
"transport": "stdio",
"command": "bunx",
"args": ["-y", "@modelcontextprotocol/server-memory"],
"env": { "API_KEY": "$MY_API_KEY" },
"description": "Optional description",
"enabled": true
}HTTP服务器 -远程端点:
{
"transport": "http",
"url": "https://example.com/mcp",
"headers": { "Authorization": "Bearer $TOKEN" },
"description": "Optional description"
}格式中的环境变量 $VAR_NAME 自动解决。
用法
管理服务器
# List enabled servers
mcp server list
# List all servers including disabled
mcp server list --all
# Add a stdio-based server (local process)
mcp server add stdio --name memory --command bunx --args "-y @modelcontextprotocol/server-memory" --description "Memory store"
# Add an HTTP-based server (remote endpoint)
mcp server add http --name api --url "https://api.example.com/mcp" --description "Remote API"
# Disable a server (keeps configuration)
mcp server disable --name memory
# Enable a server
mcp server enable --name memory
# Remove a server completely
mcp server remove --name memory
# Open config file in your editor
mcp server edit输出 server list:
Enabled servers: 5
✓ memory - Simple key-value memory store
stdio: bunx -y @modelcontextprotocol/server-memory
✓ filesystem - File system operations
stdio: bunx -y @modelcontextprotocol/server-filesystem /Users/me
✓ everything - Demo server with sample tools for testing
stdio: bunx -y @modelcontextprotocol/server-everything
✓ fetch - Fetch and convert web content for LLM usage
stdio: bunx -y @modelcontextprotocol/server-fetch
✓ time - Time and timezone conversion capabilities
stdio: bunx -y @anthropic-ai/server-time使用 --json 用于机器可读输出。
探索服务器工具
mcp help例子:
mcp everything help调用工具
mcp [options]示例:
# Echo a message
mcp everything echo --message "Hello!"
# Sum two numbers
mcp everything get-sum --a 10 --b 20
# List files
mcp filesystem list_directory --path "/Users/me/projects"
# Fetch a web page
mcp fetch fetch --url "https://example.com"
# Get current time
mcp time get_current_time获取工具帮助
mcp help管理配置
# Show current config
mcp config
# Initialize example config
mcp server init
# Clear tool cache
mcp config --action cache-clear缓存
默认情况下,工具定义缓存4小时,以避免每次命令都重新连接到服务器。缓存存储在 ~/.my-cli-prettier/cache/.
要从服务器刷新工具,请清除缓存:
mcp config --action cache-clear示例服务器
默认配置包括这些服务器(所有服务器仅与 bunx):
| 服务器 | 描述 |
|---|---|
memory | 知识图谱/键值存储 |
filesystem | 文件系统操作 |
everything | 带有13个示例工具的演示服务器 |
fetch | Web内容获取和转换 |
time | 时间和时区转换 |
对于AI代理
该工具旨在让AI代理轻松发现:
# Agent discovers available servers
mcp server list
# Agent explores a server
mcp filesystem help
# Agent gets help on a specific tool
mcp filesystem read_text_file help
# Agent calls the tool
mcp filesystem read_text_file --path "/path/to/file.txt"默认情况下,返回数据时所有输出都是JSON,这使得以编程方式解析变得容易。
构建于
许可证
麻省理工学院
