命令行AI聊天助手

一个基于Model Context Protocol (MCP)和本地LLM (Ollama)构建的强大命令行AI聊天助手,支持智能、上下文感知的对话,无需依赖付费API。

  • by Kuldeepkolage
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Kuldeepkolage/MCP-Chat-Assistant

使用说明

🚀 MCP聊天助手

⚡ 一个强大的命令行AI聊天机器人,使用 模型上下文协议(MCP) 和 当地LLM(Ollama) --实现智能、上下文感知的对话,而无需依赖付费API。


✨ 特性

  • 🤖 交互式人工智能聊天机器人(基于CLI)
  • 🧠 上下文感知对话处理(RAG风格提示)
  • 📄 使用文档检索 @filename
  • ⚙️ 基于命令的执行使用 /commands
  • 🔌 通过MCP(模型上下文协议)可扩展的工具架构
  • 💻 完全运行 离线 使用Ollama(无API成本)

🧑‍💻 技术栈

  • 语言: python
  • 架构: 模型上下文协议(MCP)
  • LLM Ollama(calla3-本地推理)
  • CLI框架: 提示工具包
  • 环境管理: python dotenv
  • 包管理器(可选): 紫外线

📸 演示

> what's 1+1?
2
> Tell me about @report.pdf
The report.pdf document contains information about...
> /summarize deposition.md
📦 Prerequisites
Python 3.9+
Ollama installed → https://ollama.com
⚙️ Setup
1️⃣ Configure Environment Variables

Create a .env file in the root directory:

CLAUDE_MODEL=llama3
2️⃣ Install Dependencies
Option 1: Using uv (Recommended)
pip install uv
uv venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
uv pip install -e .
uv run main.py
Option 2: Without uv
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install python-dotenv prompt-toolkit "mcp[cli]==1.8.0" ollama
python main.py
🧠 Usage
💬 Basic Chat
> Hello
📄 Document Retrieval

Use @filename to include document context:

> Tell me about @deposition.md
⚙️ Commands

Execute MCP-defined commands:

> /summarize deposition.md
🏗️ Project Structure
MCP-Chat-Assistant/
│
├── core/
│   ├── chat.py          # Core chat logic
│   ├── claude.py        # LLM interface (Ollama-based)
│   ├── cli.py           # CLI controller
│   ├── cli_chat.py      # CLI + MCP integration
│   └── tools.py         # MCP tool management
│
├── mcp_client.py        # MCP client (tool + resource access)
├── mcp_server.py        # MCP server (documents + tools)
├── main.py              # Entry point
├── .env                 # Environment config
└── README.md
⚠️ Note on Tool Execution

This project fully implements the MCP architecture, including tools and resources.

However:

🔹 Ollama (local LLM) does not support native tool-calling
🔹 Tool execution logic is preserved but currently disabled
🔹 System still supports context-based document retrieval (RAG)

👉 This architecture can be extended with OpenAI/Anthropic APIs for full tool execution.

🚀 Future Improvements
🧠 Persistent memory (chat history storage)
🌐 Web UI (React / Next.js frontend)
🔊 Voice input/output integration
☁️ Hybrid mode (local + API-based LLM)
🧩 Advanced MCP tool execution with function-calling LLMs
🎯 Learning Outcomes
Deep understanding of Model Context Protocol (MCP)
Building AI systems with client-server architecture
Implementing RAG (Retrieval-Augmented Generation)
Integrating local LLMs (Ollama) into applications
Handling real-world limitations of LLM tool usage
👨‍💻 Author

Kuldeep Kolage
🔗 GitHub: https://github.com/Kuldeepkolage

⭐ Support

If you found this project helpful:

⭐ Star this repository
🍴 Fork it
🚀 Build and improve on top of it

💡 This project demonstrates how modern AI systems can be built using local models, structured protocols, and scalable architecture — without relying on paid APIs.


---