Skip to main content
Glama

FastAPI MCP Server

by Pritrj
README.md5.75 kB
# 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 करें ```bash git clone <repository-url> cd mcp-server ``` ### 2. Virtual Environment बनाएं ```bash python -m venv venv source venv/bin/activate # Linux/Mac # या venv\\Scripts\\activate # Windows ``` ### 3. Dependencies Install करें ```bash pip install -r requirements.txt ``` ### 4. Environment Variables सेट करें `.env` file बनाएं: ```env # 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 ```bash uvicorn main:app --reload --host 0.0.0.0 --port 8000 ``` ### Production Mode ```bash uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4 ``` ### Docker के साथ ```bash # 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 ```http GET /health ``` Server की health status check करता है। #### API Endpoints ```http GET /api/v1/status POST /api/v1/connect GET /api/v1/tools POST /api/v1/tools/{tool_name}/call ``` ## Development ### Code Quality ```bash # Format code black . # Sort imports isort . # Lint code flake8 . # Type checking mypy . ``` ### Testing ```bash # सभी 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 ```sql -- 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 ```bash # 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 ```bash # 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 ```bash # Production image build करें docker build -t mcp-server:latest . # Docker Compose के साथ docker-compose up -d ``` ### Manual Deployment ```bash # Gunicorn के साथ gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker ``` ## Contributing 1. Fork करें 2. Feature branch बनाएं (`git checkout -b feature/amazing-feature`) 3. Commit करें (`git commit -m 'Add amazing feature'`) 4. Push करें (`git push origin feature/amazing-feature`) 5. 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

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Pritrj/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server