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
Visit Server

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured