使用说明
MCP - SQL Query API
API FastAPI để truy vấn PostgreSQL database bằng ngôn ngữ tự nhiên.
🚀 Cài đặt
1. Copy các file example
cp .env.example .env
cp docker-compose.example.yml docker-compose.yml
2. Chỉnh sửa file .env với thông tin của bạn
OPENAI_API_KEY=your-openai-api-key
DATABASE_URL=postgresql://user:password@host:port/database
# Hoặc cấu hình riêng:
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=your-username
POSTGRES_PASSWORD=your-password
POSTGRES_DB=your-database
3. Chạy với Docker
docker-compose up -d
4. Chạy local (không dùng Docker)
pip install -r requirements.txt
python run.py
📖 API Endpoints
- GET
/- Welcome message - GET
/api/v1/health- Health check - POST
/api/v1/query- Query database
🧪 Test API
Request:
curl -X POST "http://localhost:8000/api/v1/query" \
-H "Content-Type: application/json" \
-d '{"question": "Có bao nhiêu bảng trong database?"}'
Response:
{
"answer": "Database có 5 bảng: users, products, orders, categories, reviews",
"question": "Có bao nhiêu bảng trong database?"
}
📝 License
MIT