MCPHost 简介
MCPHost 是一款命令行工具,允许大型语言模型(LLM)通过模型上下文协议(MCP)与外部工具进行交互。目前支持 Claude 3.5 Sonnet、Ollama 等模型。本次实践使用自建 DeepSeek v3 模型,跑通了 Time MCP 服务。
项目地址:GitHub - mark3labs/mcphost
安装与配置
MCPHost 使用非常方便,直接下载解压即可运行。官网提供 Windows、Linux 和 macOS 三个系统的压缩包。
下载地址:https://github.com/mark3labs/mcphost/releases/tag/v0.4.4
以 Windows 系统为例,下载压缩包并解压到工作目录,即可直接使用可执行文件。若将工作目录加入系统 PATH 环境变量,则可在任意位置调用指令。
前置需求:建议先安装好 uv 和 Node.js。
MCPHost 交互实践
学习 MCPHost 命令
直接在命令行下,一句话即可进行 MCP 交互。例如在工作目录创建一个 mcp.json 配置文件,内容如下:
{
"mcpServers": {
"time": {
"command": "uvx",
"args": ["mcp-server-time", "--local-timezone=Asia/Shanghai"]
}
}
}
搭建一个 AI 服务器,地址如 http://192.168.1.5:1337。也可以使用 OpenAI、Ollama、硅基流动、LMStudio 等提供的 API 调用服务。
MCPHost 使用一句命令即可连通 AI 服务器,启动 mcp.json 中设置的 mcp-server-time,并进入交互界面:
mcphost --openai-api-key=$OPENAI_API_KEY -m openai:gpt-4o --openai-url http://192.168.1.5:1337 --config mcp.json
在交互界面输入文字即可进行交互,例如询问当前时间。
Enter your prompt (Type /help for commands, Ctrl+C to quit)
查看帮助
可以使用 -h 查看 MCPHost 的指令帮助:
mcphost.exe -h
输出示例:
MCPHost is a CLI tool that allows you to interact with various AI models through a unified interface.
It supports various tools through MCP servers and provides streaming responses.
Available models can be specified using the --model flag:
- Anthropic Claude (default): anthropic:claude-3-5-sonnet-latest
- OpenAI: openai:gpt-4
- Ollama models: ollama:modelname
Example: mcphost -m ollama:qwen2.5:3b
Usage: mcphost [flags]
Flags:
--anthropic-api-key string Anthropic API key
--anthropic-url string base URL for Anthropic API (defaults to api.anthropic.com)
--config string config file (default is $HOME/mcp.json)
--debug enable debug logging
-h, --help help for mcphost
--message-window int number of messages to keep in context (default 10)
-m, --model string model to use (format: provider:model, e.g. anthropic:claude-3-5-sonnet-latest or ollama:qwen2.5:3b) (default "anthropic:claude-3-5-sonnet-latest")
--openai-api-key string OpenAI API key
--openai-url string base URL for OpenAI API (defaults api.openai.com)
进入交互界面后,还可以用 /help 查看交互界面下的命令:
• /help: Show this help message
• /tools: List all available tools
• /servers: List configured MCP servers
• /history: Display conversation history
• /quit: Exit the application
You can also press Ctrl+C at any time to quit.
例如用 /tools 查看工具:
• time
• get_current_time
Get current time in a specific timezones
• convert_time
Convert time between timezones
可以看到当前的工具是 time。
用 /servers 查看服务:
# time
Command uvx
Arguments mcp-server-time --local-timezone=Asia/Shanghai
调试 mcp-server-time
模型兼容性测试
尝试使用 GPT-4o 模型问不出时间来。更换为 Claude 3.5 Sonnet 模型时,提问后会退出,可能是自建服务器模型配置问题(ContentLengthError: 400)。普通交互报错的情况下,Claude 模型未调通。
换成 GPT-4o 或 GPT-4 虽有回复,但无法报时,未达到预期目标。
同时所做的操作是将 uv cache 所在的目录(即启动 mcp-server-time 服务所用的临时目录)在安全软件中设为信任,防止潜在的网络通信故障或进程无法启动的问题。
DeepSeek v3 成功验证
经过多次尝试,最终将模型切换为 DeepSeek v3,成功实现功能:
mcphost --openai-api-key=$OPENAI_API_KEY -m openai:deepseek-v3 --openai-url http://192.168.1.5:1337 --config mcp.json
询问当前时间:
Assistant: Hi there! How can you assist you today?
You: what time is it?
Assistant: Current Time - Today is Monday, March 17, 2025.
- The exact time depends on your location, but here are some references:
- Central Daylight Time (CDT): 08:54:06 PM (UTC-5)
- Eastern Daylight Time (EDT): 09:54:06 PM (UTC-4)
Let me know if you'd like the time for a specific location!
回答出了今天的日期和时间,达到了使用 MCP 获取当前时间的预期目标。这表明 DeepSeek v3 模型支持函数调用。
完整交互示例
E:\360Downloads\mcphost_Windows_x86_64>mcphost --openai-api-key=$OPENAI_API_KEY -m openai:deepseek-v3 --openai-url http://192.168.1.5:1337 --config mcp.json
2025/03/19 09:26:51 INFO Model loaded provider=openai model=deepseek-v3
2025/03/19 09:26:51 INFO Initializing server... name=time
2025/03/19 09:26:55 INFO Server connected name=time
2025/03/19 09:26:55 INFO Tools loaded server=time count=2
You: 请告诉我现在的时间,谢谢
Assistant: 您好!今天是 2025 年 3 月 19 日,星期三。以下是当前的时间信息:
当前时间
• 日期:2025 年 3 月 19 日
• 星期:星期三
• 时间:请查看您设备上的时钟以获取准确时间。
如果您需要更具体的时间信息,请告诉我您的时区,我可以为您提供更精确的时间。
You: 请告诉我现在的准确时间,谢谢
Assistant: 您好!由于我无法直接访问实时数据,无法提供当前的准确时间。建议您查看您的设备(如手机、电脑或手表)上的时钟,以获取最准确的时间信息。
You: 我在济宁,请告诉我当前的时间
Assistant: 您好!以下是济宁当前的时间信息:
济宁当前时间
• 日期:2025 年 3 月 19 日
• 星期:星期三
• 时间:上午 9:28:45
• 时区:CST(中国标准时间,UTC/GMT +8 小时)
如果您需要进一步帮助,请随时告诉我!
Goodbye!
部分场景下响应可能不稳定,建议优先尝试官方推荐的 Claude 3.5 Sonnet 模型以获得更佳效果。
目前测试出来支持的模型包括:DeepSeek v3、Llama3.2:3b、Llama3.3:70b。

总结
MCPHost 小巧实用,可以很方便地架起大模型和 MCP 之间的桥梁。虽然使用 DeepSeek v3 模型离完全可用还有些距离,但已验证了 MCP 协议在自动化任务中的实际应用潜力。


