mcp-server

Nareshtt/mcp-server

3.1

If you are the rightful owner of mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The Rathinam MCP Server is a Django backend that leverages AI to perform CRUD operations on external APIs using natural language queries.

Rathinam MCP Server - Backend

AI-powered natural language interface for CRUD operations on external APIs using Model Context Protocol (MCP).

🎯 Project Overview

This Django backend allows admins/developers to perform CRUD operations on existing APIs using natural language queries powered by AI (Claude/GPT). Instead of manually calling APIs or writing code, users can simply type commands like:

  • "Add a student named Rahul with age 25"
  • "Update all products with price less than 100 to set discount 10%"
  • "Show me all orders from last week"

The MCP server interprets these commands, determines the appropriate API calls, and executes them automatically.

📋 Prerequisites

  • Python 3.10 or higher
  • PostgreSQL 14 or higher
  • Redis (for caching and Celery)
  • Node.js 18+ (for Next.js frontend - separate project)

🚀 Installation & Setup

1. Clone the Repository

git clone <your-repo-url>
cd rathinam-mcp-backend

2. Create Virtual Environment

# Using uv (recommended)
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Or using standard venv
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Set Up PostgreSQL Database

# Create database
createdb rathinam_mcp

# Or using psql
psql -U postgres
CREATE DATABASE rathinam_mcp;
\q

5. Configure Environment Variables

# Copy the example env file
cp .env.example .env

# Edit .env and update with your values
nano .env  # or use your preferred editor

Important variables to update:

  • SECRET_KEY - Generate a secure key
  • DB_PASSWORD - Your PostgreSQL password
  • ANTHROPIC_API_KEY - Your Anthropic API key for Claude
  • CORS_ALLOWED_ORIGINS - Your Next.js frontend URL

6. Create Required Directories

mkdir -p logs media staticfiles static

7. Run Migrations

python manage.py makemigrations
python manage.py migrate

8. Create Initial Admin User

python manage.py create_initial_admin

This will create:

  • Super Admin user (username: admin, password: Admin@123)
  • Default MCP configurations
  • Default AI model (Claude Sonnet 4.5)

⚠️ IMPORTANT: Change the default password immediately!

9. Collect Static Files

python manage.py collectstatic --noinput

10. Run the Development Server

python manage.py runserver

The API will be available at http://localhost:8000

📚 API Documentation

Once the server is running, access:

🔐 Authentication

All API endpoints (except login) require JWT authentication.

Login

POST /api/v1/auth/login/
Content-Type: application/json

{
  "username": "admin",
  "password": "Admin@123"
}

# Response:
{
  "refresh": "eyJ0eXAiOiJKV1QiLCJ...",
  "access": "eyJ0eXAiOiJKV1QiLCJ...",
  "user": {
    "id": 1,
    "username": "admin",
    "email": "admin@rathinam.edu",
    "role": "SUPER_ADMIN"
  }
}

Using the Access Token

Include the token in the Authorization header:

GET /api/v1/conversations/
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJ...

Refresh Token

POST /api/v1/auth/token/refresh/
Content-Type: application/json

{
  "refresh": "eyJ0eXAiOiJKV1QiLCJ..."
}

📁 Project Structure

rathinam-mcp-backend/
├── config/                      # Main project settings
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── apps/
│   └── core/                    # Main application
│       ├── models.py           # Database models
│       ├── serializers.py      # DRF serializers
│       ├── views.py            # API views
│       ├── urls.py             # URL routing
│       ├── permissions.py      # Custom permissions
│       ├── admin.py            # Django admin config
│       └── management/
│           └── commands/
│               └── create_initial_admin.py
├── logs/                        # Application logs
├── media/                       # User uploads
├── static/                      # Static files
├── staticfiles/                 # Collected static files
├── requirements.txt
├── .env.example
├── .env
├── .gitignore
├── manage.py
└── README.md

🔑 Key API Endpoints

Authentication

  • POST /api/v1/auth/login/ - Login
  • POST /api/v1/auth/logout/ - Logout
  • POST /api/v1/auth/token/refresh/ - Refresh token
  • GET /api/v1/auth/me/ - Current user info
  • PUT /api/v1/auth/change-password/ - Change password

Conversations

  • GET /api/v1/conversations/ - List conversations
  • POST /api/v1/conversations/ - Create conversation
  • GET /api/v1/conversations/{id}/ - Get conversation
  • POST /api/v1/conversations/{id}/end/ - End conversation

Queries

  • GET /api/v1/queries/ - List queries
  • POST /api/v1/queries/ - Create query
  • GET /api/v1/queries/{id}/ - Get query details

External APIs

  • GET /api/v1/external-apis/ - List external APIs
  • POST /api/v1/external-apis/ - Add external API
  • POST /api/v1/external-apis/{id}/health-check/ - Check API health

Dashboard

  • GET /api/v1/dashboard/overview/ - Dashboard stats
  • GET /api/v1/dashboard/recent-conversations/ - Recent chats
  • GET /api/v1/dashboard/recent-queries/ - Recent queries

Monitoring

  • GET /api/v1/alerts/ - List alerts
  • POST /api/v1/alerts/{id}/acknowledge/ - Acknowledge alert
  • GET /api/v1/metrics/latest/ - Latest system metrics

🛠️ Configuration

Adding External APIs

  1. Login to admin panel: http://localhost:8000/admin/
  2. Go to External APIsAdd External API
  3. Fill in:
    • Name (e.g., "Student Management API")
    • Base URL (e.g., "https://api.yourdomain.com")
    • Auth Type (API_KEY, BEARER_TOKEN, etc.)
    • Auth Credentials (JSON format)
  4. Add API Endpoints for this API

Configuring AI Models

  1. Go to AI Models in admin panel
  2. Update the API key for Claude or add OpenAI
  3. Set one model as default
  4. Configure max_tokens and temperature

🧪 Testing

# Run tests
python manage.py test

# Run with coverage
coverage run manage.py test
coverage report

📊 Database Models

Core Models

  • AdminUser - System users (admins/developers)
  • AuditLog - Complete audit trail
  • MCPConversation - Chat sessions
  • MCPMessage - Individual chat messages
  • MCPQuery - Natural language queries
  • APICall - External API calls tracking

Configuration

  • ExternalAPI - External API configurations
  • APIEndpoint - API endpoint catalog
  • MCPConfiguration - System settings
  • AIModel - AI model configurations

Monitoring

  • SystemMetrics - Performance metrics
  • Alert - System alerts
  • UsageStatistics - User usage tracking

🔒 Security Features

  • JWT authentication with token refresh
  • Role-based access control (SUPER_ADMIN, ADMIN, DEVELOPER)
  • Account lockout after failed login attempts
  • Comprehensive audit logging
  • Encrypted sensitive data
  • CORS protection
  • HTTPS enforcement in production

🚀 Production Deployment

Using Gunicorn

gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 4

Using Docker (Coming Soon)

docker-compose up -d

Environment Variables for Production

Update your .env:

DEBUG=False
ALLOWED_HOSTS=your-domain.com,www.your-domain.com
SECRET_KEY=<generate-secure-key>
CORS_ALLOWED_ORIGINS=https://your-frontend.com

📝 Next Steps

  1. ✅ Backend setup complete
  2. 🔄 Set up MCP server integration (next phase)
  3. 🎨 Build Next.js frontend
  4. 🤖 Configure AI models and prompts
  5. 🔗 Connect to your existing CRUD APIs

🆘 Troubleshooting

Database Connection Error

# Check PostgreSQL is running
sudo systemctl status postgresql

# Verify database exists
psql -U postgres -l

Migration Issues

# Reset migrations (DANGER: loses data)
python manage.py migrate --run-syncdb

Port Already in Use

# Kill process on port 8000
lsof -ti:8000 | xargs kill -9

📞 Support

For issues and questions:

📄 License

[Your License Here]


Built with ❤️ for Rathinam College