关于 MCP Host CLI
MCP Host CLI 是一个 FastAPI 聊天服务,可将请求发送到兼容 OpenAI 的 LLM API,并支持配置 MCP 服务。它提供会话、聊天和工具审批接口,供本地使用。
主要功能
- 01提供 FastAPI 聊天接口
- 02配置 LLM 提供商和模型
- 03通过环境变量或命令行配置
- 04提供工具审批与会话接口
- 05支持可选流式响应和错误重试
适用场景
- 01搭建本地 LLM 聊天 API
- 02通过 HTTP 管理聊天会话
- 03在批准前审核工具调用
MCP 相关
服务可通过 `--servers-config` 接收 MCP 服务配置,并处理工具审批。README 未说明其连接 MCP 服务所用的协议。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
暂未收录安装方式
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
还没有获取到工具列表
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
LLM 聊天服务
用于与 LLM(OpenAI)进行聊天交互的 FastAPI 服务。
配置
通过环境变量和 CLI 参数管理配置。
环境变量
| 变量 | 说明 | 默认值 |
|---|---|---|
LLM_API_KEY | LLM 提供商的 API 密钥(可替代 --api-key-file) | - |
LLM_MODEL | 要使用的模型名称 | qwen2.5-coder:latest |
PORT | 服务运行端口 | 8000 |
LLM_PROVIDER | LLM 提供商(openai) | openai |
OPENAI_BASE_URL | OpenAI 兼容 API 的基础 URL | https://openrouter.ai/api/v1 |
.env 文件示例:
LLM_API_KEY=your-api-key
LLM_MODEL=qwen2.5-coder:latest
PORT=8000
LLM_PROVIDER=openai
CLI 参数
| 参数 | 说明 | 示例 |
|---|---|---|
--model | 要使用的 LLM 模型 | --model qwen2.5-coder:latest |
--port | 服务运行端口 | --port 8000 |
--provider | LLM 提供商(openai) | --provider openai |
--openai-base-url | OpenAI API 的基础 URL | --openai-base-url https://api.openai.com/v1 |
--api-key-file | 包含 API 密钥的文件路径 | --api-key-file /path/to/api.key |
--servers-config | 服务配置文件的路径 | --servers-config config/servers.json |
--current-directory | 工作目录 | --current-directory /projects |
--context-window-size | 上下文窗口大小 | --context-window-size 2048 |
--temperature | 温度参数 | --temperature 0.7 |
--stream | 启用流式模式 | --stream |
--retries-on-llm-error | LLM 出错时的重试次数 | --retries-on-llm-error 3 |
--debug-messages | 启用调试消息日志,写入 /tmp/llm-requester.messages.log | --debug-messages |
CLI 用法示例:
# Using environment variable
export LLM_API_KEY=your-api-key
uv run main.py --model qwen2.5-coder:latest --port 8000
# Using API key file
uv run main.py --model qwen2.5-coder:latest --port 8000 --api-key-file /path/to/api.key
API 端点
POST /user_request- 处理用户聊天请求POST /approve- 处理工具批准或拒绝GET /session_state- 获取当前会话状态POST /start_session- 创建新会话
请求/响应格式
请求(POST /user_request)
{
"input": "user message"
}
响应
{
"request_id": "uuid",
"requires_approval": true,
"tool": {
"name": "tool-name",
"arguments": {
"arg1": "value1",
"arg2": "value2"
}
},
"message": "response content",
"model": "model-name",
"role": "assistant"
}
工具批准(POST /approve)
{
"request_id": "uuid",
"approve": true
}
用法示例
import requests
# Start session
response = requests.post("http://localhost:8000/start_session", json={
"current_directory": "/projects",
"model": "qwen2.5-coder:latest"
})
# Send message
response = requests.post("http://localhost:8000/user_request", json={
"input": "Hello, how are you?"
})
# Approve tool call
response = requests.post("http://localhost:8000/approve", json={
"request_id": "12345",
"approve": true
})
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。