akbarkhawaja/mcp-datasource-server
If you are the rightful owner of mcp-datasource-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 MCP Datasource Server is a secure, production-ready server that provides readonly access to MySQL databases, designed for integration with Claude Desktop and deployment on Vercel.
MCP Datasource Server
A secure, production-ready Model Context Protocol (MCP) server that provides readonly access to MySQL databases. Designed for integration with Claude Desktop and public deployment on Vercel.
Features
- 🔐 Security-First: Readonly database access with comprehensive query validation
- 🚀 Vercel Ready: Optimized for serverless deployment
- 🖥️ Claude Desktop: Local integration support
- ⚡ Rate Limited: Built-in protection against abuse
- 🛡️ Input Validation: SQL injection prevention and query sanitization
- 🎯 Production Ready: Monitoring, logging, and error handling
Quick Start
Local Development (Claude Desktop)
-
Setup Environment:
cp .env.example .env # Edit .env with your local database credentials -
Install Dependencies:
npm install -
Build:
npm run build -
Configure Claude Desktop (
%APPDATA%\\Claude\\claude_desktop_config.json):{ "mcpServers": { "datasource-server": { "command": "wsl", "args": [ "-e", "bash", "-c", "cd /path/to/mcp-datasource-server && node dist/mcp-clean-claude.js" ] } } }
Production Deployment (Vercel)
-
Setup GCP Cloud SQL:
- Create staging/production database
- Configure readonly user
- Whitelist Vercel IPs
-
Deploy to Vercel:
npm install -g vercel vercel login # Set environment variables vercel env add PUBLIC_DB_HOST vercel env add PUBLIC_DB_USER vercel env add PUBLIC_DB_PASSWORD vercel env add PUBLIC_DB_NAME vercel env add PUBLIC_API_KEY # Deploy vercel --prod -
Users can then add to their Claude Desktop:
{ "mcpServers": { "public-datasource": { "command": "curl", "args": [ "-X", "POST", "https://your-deployment.vercel.app/api/mcp/tools/call", "-H", "Content-Type: application/json", "-H", "X-API-Key: your-api-key" ] } } }
Available Tools
- health_check: Check server and database status
- query_mysql: Execute safe readonly MySQL queries (SELECT, SHOW, DESCRIBE only)
Security Features
- ✅ Readonly database user
- ✅ Query validation and sanitization
- ✅ SQL injection prevention
- ✅ Rate limiting (10 requests/minute per IP)
- ✅ Result size limits (max 100 rows)
- ✅ API key authentication (optional)
- ✅ Input validation with Joi schemas
API Endpoints
GET /api/health- Health checkPOST /api/mcp/tools/list- List available toolsPOST /api/mcp/tools/call- Execute tool calls
Development
# Build
npm run build
# Type checking
npm run typecheck
# Lint
npm run lint
# Local development with Vercel
npm run dev
# Local MCP server (for Claude Desktop)
npm run local
Environment Variables
Local Development
GCS_DB_HOST- Local MySQL hostGCS_DB_USER- Local MySQL userGCS_DB_PASSWORD- Local MySQL passwordGCS_DB_NAME- Local MySQL databaseGCS_DB_PORT- Local MySQL port (default: 3306)
Production/Staging
PUBLIC_DB_HOST- Database host (GCP Cloud SQL)PUBLIC_DB_USER- Readonly database userPUBLIC_DB_PASSWORD- Database passwordPUBLIC_DB_NAME- Database namePUBLIC_DB_PORT- Database port (default: 3306)PUBLIC_API_KEY- API key for access control (optional)
Architecture
├── api/
│ └── mcp.ts # Vercel API endpoint
├── src/
│ ├── database/
│ │ ├── index.ts # Database manager
│ │ └── mysql.ts # MySQL connection handler
│ ├── security/
│ │ ├── inputValidator.ts # Input validation with Joi
│ │ └── queryValidator.ts # SQL query validation
│ ├── tools/
│ │ └── mysql.ts # MySQL MCP tools
│ ├── types/
│ │ └── index.ts # TypeScript type definitions
│ ├── utils/
│ │ └── logger.ts # Logging utilities
│ ├── mcp-clean-claude.ts # Local Claude Desktop server
│ └── mcp-vercel-public.ts # Vercel production server
├── package.json
├── tsconfig.json
└── vercel.json
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License - see LICENSE file for details