FastAPI MCP Server
A production-ready Model Context Protocol server built with FastAPI, featuring JWT authentication, PostgreSQL database support, Redis caching, and comprehensive health monitoring for building secure async API applications.
README
MCP Server
एक production-ready Model Context Protocol (MCP) server जो FastAPI framework का उपयोग करके बनाई गई है।
विशेषताएं (Features)
- 🚀 FastAPI Framework: High-performance async API server
- 🔒 Security: JWT authentication और secure coding practices
- 🗄️ Database: PostgreSQL के साथ asyncpg
- 📦 Caching: Redis integration
- 🐳 Docker Ready: Production-ready containerization
- 📊 Health Checks: Built-in health monitoring
- 🔧 Development Ready: Comprehensive testing और development tools
आवश्यकताएं (Requirements)
- Python 3.11+
- PostgreSQL 13+
- Redis 6+
- Docker (optional)
इंस्टॉलेशन (Installation)
1. Repository Clone करें
git clone <repository-url>
cd mcp-server
2. Virtual Environment बनाएं
python -m venv venv
source venv/bin/activate # Linux/Mac
# या
venv\\Scripts\\activate # Windows
3. Dependencies Install करें
pip install -r requirements.txt
4. Environment Variables सेट करें
.env file बनाएं:
# Database
DATABASE_URL=postgresql://username:password@localhost:5432/mcp_db
# Redis
REDIS_URL=redis://localhost:6379/0
# Security
SECRET_KEY=your-secret-key-here
JWT_ALGORITHM=HS256
JWT_EXPIRE_MINUTES=30
# Server
HOST=0.0.0.0
PORT=8000
DEBUG=false
Usage
Development Mode
uvicorn main:app --reload --host 0.0.0.0 --port 8000
Production Mode
uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4
Docker के साथ
# Build करें
docker build -t mcp-server .
# Run करें
docker run -p 8000:8000 --env-file .env mcp-server
API Documentation
Base URL
http://localhost:8000
Interactive Documentation
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Main Endpoints
Health Check
GET /health
Server की health status check करता है।
API Endpoints
GET /api/v1/status
POST /api/v1/connect
GET /api/v1/tools
POST /api/v1/tools/{tool_name}/call
Development
Code Quality
# Format code
black .
# Sort imports
isort .
# Lint code
flake8 .
# Type checking
mypy .
Testing
# सभी tests run करें
pytest
# Coverage के साथ
pytest --cov=src tests/
# Specific test file
pytest tests/test_main.py
Project Structure
mcp-server/
├── src/ # Source code
│ ├── main.py # FastAPI application
│ ├── models/ # Pydantic models
│ ├── routes/ # API routes
│ ├── services/ # Business logic
│ ├── database/ # Database configuration
│ └── utils/ # Utility functions
├── tests/ # Test files
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose (optional)
├── .env.example # Environment variables template
├── .gitignore # Git ignore patterns
├── .dockerignore # Docker ignore patterns
└── README.md # This file
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection URL | Required |
REDIS_URL |
Redis connection URL | redis://localhost:6379/0 |
SECRET_KEY |
JWT secret key | Required |
JWT_ALGORITHM |
JWT algorithm | HS256 |
JWT_EXPIRE_MINUTES |
JWT expiration time | 30 |
HOST |
Server host | 0.0.0.0 |
PORT |
Server port | 8000 |
DEBUG |
Debug mode | false |
Database Setup
-- PostgreSQL database बनाएं
CREATE DATABASE mcp_db;
-- User बनाएं (optional)
CREATE USER mcp_user WITH PASSWORD 'secure_password';
GRANT ALL PRIVILEGES ON DATABASE mcp_db TO mcp_user;
Redis Setup
# Redis start करें
redis-server
# या Docker के साथ
docker run -d -p 6379:6379 redis:alpine
Security Features
- JWT-based authentication
- Password hashing with bcrypt
- CORS protection
- Rate limiting
- Input validation
- SQL injection protection
- XSS protection
Monitoring
Health Checks
# Server health check
curl http://localhost:8000/health
# Database connection check
curl http://localhost:8000/health/db
# Redis connection check
curl http://localhost:8000/health/redis
Logging
Logs /logs/ directory में store होते हैं। Production में proper logging configuration set करें।
Deployment
Docker Deployment
# Production image build करें
docker build -t mcp-server:latest .
# Docker Compose के साथ
docker-compose up -d
Manual Deployment
# Gunicorn के साथ
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker
Contributing
- Fork करें
- Feature branch बनाएं (
git checkout -b feature/amazing-feature) - Commit करें (
git commit -m 'Add amazing feature') - Push करें (
git push origin feature/amazing-feature) - Pull Request open करें
License
यह project MIT license के under है।
Support
समस्याओं के लिए GitHub Issues create करें या documentation पढ़ें।
Changelog
v1.0.0
- Initial release
- FastAPI integration
- JWT authentication
- Redis caching
- Docker support
- Comprehensive documentation
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.