MCP CLI 客户端
一个简单的命令行程序,用于运行 LLM 提示并实现 模型上下文协议 (MCP) 客户端。
您可以通过终端方便地使用任何 MCP 兼容服务器。
这作为 Claude 桌面客户端的替代方案。此外,您还可以通过 llama 使用 OpenAI、Groq 或本地 LLM 模型。

安装
-
通过 pip 安装:
pip install mcp-client-cli -
创建一个
~/.llm/config.json文件来配置您的 LLM 和 MCP 服务器:{ "systemPrompt": "You are an AI assistant helping a software engineer...", "llm": { "provider": "openai", "model": "gpt-4", "api_key": "your-openai-api-key", "temperature": 0.7, "base_url": "https://api.openai.com/v1" // 可选,用于 OpenRouter 或其他提供者 }, "mcpServers": { "fetch": { "command": "uvx", "args": ["mcp-server-fetch"], "requires_confirmation": ["fetch"], "enabled": true, // 可选,默认为 true "exclude_tools": [] // 可选,排除的工具名称列表 }, "brave-search": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-brave-search"], "env": { "BRAVE_API_KEY": "your-brave-api-key" }, "requires_confirmation": ["brave_web_search"] }, "youtube": { "command": "uvx", "args": ["--from", "git+https://github.com/adhikasp/mcp-youtube", "mcp-youtube"] } } }注意:
- 查看 CONFIG.md 获取配置格式的完整文档
- 使用
requires_confirmation指定在执行前需要用户确认的工具 - LLM API 密钥也可以通过环境变量
LLM_API_KEY或OPENAI_API_KEY设置 - 配置文件可以放置在
~/.llm/config.json或$PWD/.llm/config.json - 如果您喜欢切换配置,可以用
//注释 JSON 配置文件
-
运行 CLI:
llm "What is the capital city of North Sumatra?"
使用
基本用法
$ llm What is the capital city of North Sumatra?
The capital city of North Sumatra is Medan.
您可以省略引号,但要注意 bash 特殊字符如 &、|、; 可能会被您的 shell 解释。
您还可以从其他命令或文件中管道输入:
$ echo "What is the capital city of North Sumatra?" | llm
The capital city of North Sumatra is Medan.
$ echo "Given a location, tell me its capital city." > instructions.txt
$ cat instruction.txt | llm "West Java"
The capital city of West Java is Bandung.
图像输入
您可以将图像文件管道输入以使用多模态 LLM 分析它们:
$ cat image.jpg | llm "What do you see in this image?"
[LLM 将分析并描述图像]
$ cat screenshot.png | llm "Is there any error in this screenshot?"
[LLM 将分析截图并指出任何错误]
使用提示模板
您可以使用 p 前缀后跟模板名称及其参数来使用预定义的提示模板:
# 列出可用的提示模板
$ llm --list-prompts
# 使用模板
$ llm p review # 审查 git 变更
$ llm p commit # 生成提交信息
$ llm p yt url=https://youtube.com/... # 总结 YouTube 视频
触发工具
$ llm What is the top article on hackernews today?
================================== Ai Message ==================================
Tool Calls:
brave_web_search (call_eXmFQizLUp8TKBgPtgFo71et)
Call ID: call_eXmFQizLUp8TKBgPtgFo71et
Args:
query: site:news.ycombinator.com
count: 1
Brave Search MCP 服务器在 stdio 上运行
# 如果工具需要确认,您将被提示:
Confirm tool call? [y/n]: y
================================== Ai Message ==================================
Tool Calls:
fetch (call_xH32S0QKqMfudgN1ZGV6vH1P)
Call ID: call_xH32S0QKqMfudgN1ZGV6vH1P
Args:
url: https://news.ycombinator.com/
================================= Tool Message =================================
Name: fetch
[TextContent(type='text', text='Contents [REDACTED]]
================================== Ai Message ==================================
今天 Hacker News 上的顶级文章是:
### [Why pipes sometimes get "stuck": buffering](https://jvns.ca)
- **Points:** 31
- **Posted by:** tanelpoder
- **Posted:** 1 hour ago
您可以在 [Hacker News](https://news.ycombinator.com/) 上查看完整文章列表
要绕过工具确认要求,使用 --no-confirmations 标志:
$ llm --no-confirmations "What is the top article on hackernews today?"
要在 bash 脚本中使用,添加 --no-intermediates,这样它不会打印中间消息,只打印最终消息。
$ llm --no-intermediates "What is the time in Tokyo right now?"
继续
在您的消息前添加 c 前缀以继续上次对话。
$ llm asldkfjasdfkl
It seems like your message might have been a typo or an error. Could you please clarify or provide more details about what you need help with?
$ llm c what did i say previously?
You previously typed "asldkfjasdfkl," which appears to be a random string of characters. If you meant to ask something specific or if you have a question, please let me know!
剪贴板支持
您可以使用 cb 命令使用剪贴板内容:
# 复制文本到剪贴板后
$ llm cb
[LLM 将处理剪贴板文本]
$ llm cb "What language is this code written in?"
[LLM 将用您的问题分析剪贴板文本]
# 复制图像到剪贴板后
$ llm cb "What do you see in this image?"
[LLM 将分析剪贴板图像]
# 可以与继续结合使用
$ llm cb c "Tell me more about what you see"
[LLM 将继续关于剪贴板内容的对话]
剪贴板功能在以下环境中工作:
- 原生 Windows/macOS/Linux 环境
- Windows: 使用 PowerShell
- macOS: 使用
pbpaste处理文本,pngpaste处理图像(可选) - Linux: 使用
xclip(需要剪贴板支持)
- Windows 子系统 for Linux (WSL)
- 通过 PowerShell 访问 Windows 剪贴板
- 支持文本和图像
- 确保您可以从 WSL 访问
powershell.exe
剪贴板支持所需的工具:
- Windows: PowerShell(内置)
- macOS:
pbpaste(内置)用于文本pngpaste(可选)用于图像:brew install pngpaste
- Linux:
xclip:sudo apt install xclip或等效命令
CLI 会自动检测剪贴板内容是文本还是图像,并适当处理。
其他选项
$ llm --list-tools # 列出所有可用工具
$ llm --list-prompts # 列出可用的提示模板
$ llm --no-tools # 不使用任何工具运行
$ llm --force-refresh # 强制刷新工具能力缓存
$ llm --text-only # 输出原始文本,不进行 Markdown 格式化
$ llm --show-memories # 显示用户记忆
$ llm --model gpt-4 # 覆盖配置中指定的模型
贡献
欢迎提交问题和拉取请求以改进或修复错误。