AI Assistant MCP Server

AI Assistant MCP Server

MCP server providing tools to chat with an AI agent, fetch weather data, and monitor agent status via the Model Context Protocol.

Category
访问服务器

README

AI Assistant MCP Server

MCP (Model Context Protocol) Server cho AI Assistant, được xây dựng với FastMCP và quản lý bằng uv.

🚀 Tính năng

  • FastMCP: Framework hiện đại cho MCP server
  • Tools: Các công cụ để tương tác với AI agent backend
  • Weather Tool: Lấy thông tin thời tiết thời gian thực 🌤️
  • Resources: Truy cập thông tin agent và conversations
  • Prompts: Các prompt templates có sẵn
  • Async Support: Hoàn toàn asynchronous
  • Type Safe: Type hints đầy đủ

📋 Yêu cầu

  • Python 3.10+
  • uv (Python package manager)
  • Backend API đang chạy (port 8000)

🛠️ Cài đặt với UV

1. Cài đặt UV (nếu chưa có)

# Windows PowerShell
irm https://astral.sh/uv/install.ps1 | iex

2. Tạo virtual environment và cài đặt dependencies

cd MCP
uv venv
.venv\Scripts\activate
uv pip install -e .

hoặc cài đặt trực tiếp:

uv pip install fastmcp python-dotenv pydantic httpx aiofiles

3. Cấu hình environment variables

copy .env.example .env

Cập nhật file .env:

BACKEND_API_URL=http://localhost:8000
OPENAI_API_KEY=your_key_here
WEATHER_API_KEY=your_openweathermap_key_here  # Optional - for weather tool

Note: Weather tool hoạt động ngay cả khi không có WEATHER_API_KEY. Nó sẽ tự động dùng wttr.in (miễn phí). API key chỉ cần thiết nếu muốn độ chính xác cao hơn.

🚀 Chạy MCP Server

Với UV (khuyên dùng)

uv run server.py

hoặc

.venv\Scripts\activate
python server.py

Development mode

uv run server.py --reload

📡 MCP Server Capabilities

Tools (Công cụ)

  1. chat_with_agent

    • Gửi tin nhắn đến AI agent
    • Tham số: message, conversation_id (optional), user_id (optional)
  2. get_conversation_history

    • Lấy lịch sử hội thoại
    • Tham số: conversation_id
  3. get_agent_status

    • Lấy trạng thái hiện tại của agent
    • Không cần tham số
  4. get_agent_graph

    • Lấy cấu trúc LangGraph workflow
    • Không cần tham số
  5. delete_conversation

    • Xóa một hội thoại
    • Tham số: conversation_id
  6. health_check

    • Kiểm tra sức khỏe backend API
    • Không cần tham số
  7. get_current_weather 🌤️

    • Lấy thông tin thời tiết hiện tại cho một thành phố
    • Tham số: city (bắt buộc), country_code (optional), units (optional)
    • Ví dụ: get_current_weather("Hanoi", "VN", "metric")
  8. get_weather_forecast 🌦️

    • Lấy dự báo thời tiết 1-5 ngày
    • Tham số: city (bắt buộc), country_code (optional), days (1-5), units (optional)
    • Ví dụ: get_weather_forecast("Ho Chi Minh", "VN", 3)

Resources (Tài nguyên)

  1. agent://info

    • Thông tin chi tiết về agent
  2. agent://status

    • Trạng thái hoạt động của agent
  3. conversations://list

    • Danh sách các hội thoại (placeholder)

Prompts (Prompt Templates)

  1. casual_chat - Trò chuyện thông thường
  2. technical_help - Hỗ trợ kỹ thuật
  3. creative_writing - Viết sáng tạo
  4. code_review - Review code

💡 Ví dụ sử dụng

Từ MCP Client

# Sử dụng tool chat_with_agent
result = await client.call_tool(
    "chat_with_agent",
    arguments={
        "message": "What is LangGraph?",
        "user_id": "user_123"
    }
)

# Lấy thông tin thời tiết 🌤️
weather = await client.call_tool(
    "get_current_weather",
    arguments={
        "city": "Hanoi",
        "country_code": "VN",
        "units": "metric"
    }
)

# Lấy thông tin agent
info = await client.read_resource("agent://info")

# Sử dụng prompt
messages = await client.get_prompt("technical_help")

Demo Weather Tool

# Chạy demo thời tiết
python3 demo_weather.py

# Hoặc chế độ tương tác
python3 demo_weather.py interactive

# Test
python3 tests/test_weather_tools.py

Cấu hình trong Claude Desktop

Thêm vào claude_desktop_config.json:

{
  "mcpServers": {
    "ai-assistant": {
      "command": "uv",
      "args": [
        "--directory",
        "F:\\UIT\\SE347\\Seminar\\MCP",
        "run",
        "server.py"
      ],
      "env": {
        "BACKEND_API_URL": "http://localhost:8000"
      }
    }
  }
}

Cấu hình trong Cline (VS Code)

Thêm vào settings:

{
  "mcp.servers": {
    "ai-assistant": {
      "command": "uv",
      "args": [
        "--directory",
        "F:\\UIT\\SE347\\Seminar\\MCP",
        "run",
        "server.py"
      ],
      "env": {
        "BACKEND_API_URL": "http://localhost:8000"
      }
    }
  }
}

🧪 Testing

Test với MCP Inspector

# Cài đặt MCP Inspector
npm install -g @modelcontextprotocol/inspector

# Chạy inspector
mcp-inspector uv --directory F:\UIT\SE347\Seminar\MCP run server.py

Test với curl

# Test backend trước
curl http://localhost:8000/health

# Rồi mới chạy MCP server
uv run server.py

📁 Cấu trúc Project

MCP/
├── server.py                    # Main MCP server file
├── pyproject.toml               # Project configuration (uv/pip)
├── .env                         # Environment variables
├── .env.example                 # Example env file
├── README.md                    # Documentation (this file)
├── WEATHER_SETUP.md             # 🌤️ Weather tool detailed guide
├── QUICKSTART_VI.md             # 🌤️ Vietnamese quick start
├── INSTALL.md                   # Installation guide
├── WEATHER_SUMMARY.md           # 🌤️ Weather tool summary
├── demo_weather.py              # 🌤️ Weather demo script
├── src/
│   └── mcp_server/
│       ├── tools/
│       │   ├── chat_tools.py    # Chat tools
│       │   ├── agent_tools.py   # Agent tools
│       │   └── weather_tools.py # 🌤️ Weather tools
│       ├── resources/           # MCP resources
│       ├── prompts/             # Prompt templates
│       ├── core/                # Core configuration
│       └── utils/               # Utilities
├── tests/
│   ├── test_chat_tools.py
│   └── test_weather_tools.py    # 🌤️ Weather tests
└── .gitignore

🔧 Phát triển thêm

Thêm Tool mới

@mcp.tool()
async def your_new_tool(param: str) -> Dict[str, Any]:
    """
    Description of your tool.
    
    Args:
        param: Parameter description
        
    Returns:
        Result description
    """
    # Your implementation
    return {"result": "data"}

Thêm Resource mới

@mcp.resource("custom://resource")
async def your_resource() -> str:
    """
    Get custom resource data.
    """
    return "Resource content"

Thêm Prompt mới

@mcp.prompt()
async def your_prompt() -> List[Dict[str, str]]:
    """
    Custom prompt template.
    """
    return [
        {
            "role": "user",
            "content": "Your prompt content"
        }
    ]

📚 Tài liệu

General:

Weather Tool Documentation:

Weather API:

🐛 Troubleshooting

Lỗi "Backend is not healthy"

  • Đảm bảo Backend API đang chạy trên port 8000
  • Check: curl http://localhost:8000/health

Lỗi import fastmcp

uv pip install fastmcp

Lỗi connection refused

  • Kiểm tra BACKEND_API_URL trong .env
  • Đảm bảo không có firewall block

UV command not found

# Reinstall UV
irm https://astral.sh/uv/install.ps1 | iex

📝 License

MIT License

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选