A simple CLI to run LLM prompt and implement MCP client.
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 |
以下内容由 AI 翻译,如有问题请 点此提交 issue 反馈
MCP 命令行客户端
一款简易的命令行程序,用于执行 LLM 提示并实现 模型上下文协议(MCP) 客户端。
您可以从终端的便利性中使用任何 MCP 兼容服务器。
此程序可作为 Claude 桌面客户端的替代方案。此外,您还可以使用任何 LLM 提供商,如 OpenAI、Groq,或者通过 llama 使用本地 LLM 模型。

使用方法
基本用法
$ 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.
odal
图像输入
您可以将图像文件管道传输以利用多模态大型语言模型对其进行分析:
$ cat image.jpg | llm "What do you see in this image?"
[LLM will analyze and describe the image]
$ cat screenshot.png | llm "Is there any error in this screenshot?"
[LLM will analyze the screenshot and point out any errors]
使用提示模板
您可以通过使用 p 前缀,后跟模板名称及其参数来使用预定义的提示模板:
# List available prompt templates
$ llm --list-prompts
# Use a template
$ llm p review # Review git changes
$ llm p commit # Generate commit message
$ llm p yt url=https://youtube.com/... # Summarize YouTube video
触发工具操作
$ 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 Server running on stdio
# If the tool requires confirmation, you'll be prompted:
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 ==================================
The top article on Hacker News today is:
### [Why pipes sometimes get "stuck": buffering](https://jvns.ca)
- **Points:** 31
- **Posted by:** tanelpoder
- **Posted:** 1 hour ago
You can view the full list of articles on [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 命令来调用剪贴板中的内容:
# After copying text to clipboard
$ llm cb
[LLM will process the clipboard text]
$ llm cb "What language is this code written in?"
[LLM will analyze the clipboard text with your question]
# After copying an image to clipboard
$ llm cb "What do you see in this image?"
[LLM will analyze the clipboard image]
# You can combine it with continuation
$ llm cb c "Tell me more about what you see"
[LLM will continue the conversation about the clipboard content]
剪贴板功能适用于以下环境:
- 原生 Windows/macOS/Linux 环境
- Windows:使用 PowerShell
- macOS:文本使用
pbpaste,图片使用pngpaste(可选) - Linux:使用
xclip(剪贴板支持必需)
- Windows 的 Linux 子系统(WSL)
- 通过 PowerShell 访问 Windows 剪贴板
- 支持文本和图片
- 确保在 WSL 中可以访问
powershell.exe
剪贴板支持所需工具:
- Windows:PowerShell(内置)
- macOS:
- 文本:
pbpaste(内置) - 图片:
pngpaste(可选),通过brew install pngpaste安装
- 文本:
- Linux:
xclip:通过sudo apt install xclip或相应命令安装
命令行界面会自动检测剪贴板内容是文本还是图片,并相应地处理。
额外选项
$ llm --list-tools # List all available tools
$ llm --list-prompts # List available prompt templates
$ llm --no-tools # Run without any tools
$ llm --force-refresh # Force refresh tool capabilities cache
$ llm --text-only # Output raw text without markdown formatting
$ llm --show-memories # Show user memories
$ llm --model gpt-4 # Override the model specified in config
设置指南
-
克隆仓库:
pip install git+https://github.com/adhikasp/mcp-client-cli.git -
创建一个
~/.llm/config.json文件以配置您的 LLM 和 MCP 服务器:{ "systemPrompt": "你是一名正在协助软件工程师的 AI 助手...", "llm": { "provider": "openai", "model": "gpt-4", "api_key": "你的 OpenAI API 密钥", "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": "你的 Brave API 密钥" }, "requires_confirmation": ["brave_web_search"] }, "youtube": { "command": "uvx", "args": ["--from", "git+https://github.com/adhikasp/mcp-youtube", "mcp-youtube"] } } }注意:
- 使用
requires_confirmation指定在执行之前需要用户确认的工具 - LLM API 密钥也可以通过环境变量
LLM_API_KEY或OPENAI_API_KEY设置 - 配置文件可以放在
~/.llm/config.json或$PWD/.llm/config.json - 如果您想切换配置,可以在 JSON 配置文件中使用
//添加注释
- 使用
-
运行命令行界面:
llm "北苏门答腊的首府是哪里?"
贡献指南
欢迎提交问题和拉取请求以进行改进或修复错误。