Ollama MCP Chat 是一个桌面聊天机器人应用程序,它集成了 Ollama 的本地大语言模型(LLM)与 MCP(模型上下文协议)服务器,支持各种工具调用和可扩展功能。该程序基于 Python 和 PySide6 提供了一个图形用户界面,并允许通过 MCP 服务器自由扩展其功能。
对于希望使用 Python 创建带有图形界面的 AI 应用程序的开发者来说,这个项目可以作为非常有用的基底代码。
git clone https://github.com/your-repo/ollama-mcp-chat.git
cd ollama-mcp-chat
# 使用 pip 安装
pip install uv
# 或者使用 curl(类 Unix 系统)
curl -LsSf https://astral.sh/uv/install.sh | sh
# 或者使用 PowerShell(Windows)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# 安装依赖项
uv sync
# 安装 Ollama(详情见 https://ollama.ai)
ollama pull <model-name>
mcp_config.json 文件中添加 MCP 服务器信息{
"mcpServers": {
"weather": {
"command": "python",
"args": ["./mcp_server/mcp_server_weather.py"],
"transport": "stdio"
}
}
}
uv run main.py
ui/chat_window.py: 主图形用户界面窗口,处理聊天/历史记录/设置/服务器管理agent/chat_history.py: 管理并保存/加载聊天历史记录worker.py: 处理与 LLM 和 MCP 服务器的异步通信agent/llm_ollama.py: 集成 Ollama LLM 和 MCP 工具,处理流式响应mcp_server/mcp_manager.py: 管理并验证 MCP 服务器配置文件mcp_config.json 中添加新的 MCP 服务器信息chat_history.jsonquit、exit 或 bye 来退出MIT 许可证