The OpenTrustEval MCP (Model Context Protocol) Server provides secure, high-speed bidirectional communication for the OpenTrustEval trust scoring system. It enables external applications to interact with the trust scoring engine programmatically through REST APIs and WebSocket connections.
- JWT Authentication: Secure token-based authentication
- API Key Support: Multiple API key management
- Data Encryption: End-to-end encryption for sensitive data
- Rate Limiting: Configurable rate limiting per client
- SSL/TLS Support: Secure HTTPS communication
- CORS Protection: Configurable cross-origin resource sharing
- REST API: Standard HTTP REST endpoints
- WebSocket: Real-time bidirectional communication
- Async Support: Full async/await support
- Batch Processing: Efficient batch operations
- Trust Score Calculation: Advanced trust scoring methods
- File Upload: Multi-format file upload support
- Cleanlab Comparison: Benchmarking against industry standards
- Quality Assessment: Comprehensive data quality evaluation
- Batch Processing: Process multiple datasets efficiently
- Health Checks: Server health monitoring
- Metrics: Prometheus metrics integration
- Logging: Comprehensive logging system
- Performance: High-performance async processing
- Python 3.8+
- OpenTrustEval system installed
- pip package manager
# Clone the repository
git clone https://github.com/your-repo/OpenTrustEval.git
cd OpenTrustEval
# Install MCP server dependencies
pip install -r mcp_server/requirements.txt
# Install OpenTrustEval dependencies
pip install -r requirements.txt# Generate environment template
cd mcp_server
python config.py
# Copy and edit environment file
cp .env.template .env
# Edit .env with your configuration# Generate self-signed certificate for development
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
# Update .env file
SSL_CERT_PATH=cert.pem
SSL_KEY_PATH=key.pem# Basic startup
python mcp_server/server.py
# With custom configuration
python mcp_server/server.py --host 0.0.0.0 --port 8000 --ssl
# Using environment variables
SERVER_HOST=0.0.0.0 SERVER_PORT=8000 python mcp_server/server.py# Check server health
curl http://localhost:8000/health
# View API documentation
open http://localhost:8000/docsfrom mcp_server.client import SyncMCPOpenTrustEvalClient
# Create client
client = SyncMCPOpenTrustEvalClient("http://localhost:8000")
# Login
login_result = client.login("admin", "admin123")
# Calculate trust score
result = client.calculate_trust_score("path/to/dataset.csv")
print(f"Trust Score: {result['trust_score']}")POST /auth/login
Content-Type: application/json
{
"username": "admin",
"password": "admin123"
}Response:
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"user_id": "admin"
}POST /api/v1/trust-score
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"dataset_path": "path/to/dataset.csv",
"method": "ensemble",
"features": ["feature1", "feature2"],
"metadata": {"source": "api", "version": "1.0"}
}Response:
{
"request_id": "uuid-string",
"trust_score": 0.85,
"method": "ensemble",
"component_scores": {
"data_quality": 0.9,
"statistical_robustness": 0.8,
"anomaly_detection": 0.85
},
"quality_metrics": {
"missing_values_ratio": 0.02,
"duplicate_rows_ratio": 0.01,
"outlier_ratio": 0.05
},
"processing_time": 2.34,
"timestamp": "2024-01-01T12:00:00Z"
}POST /api/v1/upload
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"file_data": "base64-encoded-file-content",
"file_name": "dataset.csv",
"file_type": ".csv",
"metadata": {"description": "Customer data", "version": "1.0"}
}Response:
{
"request_id": "uuid-string",
"file_path": "./uploads/dataset.csv",
"file_size": 1024000,
"file_hash": "sha256-hash",
"upload_time": 1.23,
"status": "success"
}POST /api/v1/cleanlab-compare
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"dataset_path": "path/to/dataset.csv",
"cleanlab_option": 1,
"comparison_method": "Side-by-Side",
"data_format": "CSV"
}Response:
{
"request_id": "uuid-string",
"our_score": 0.85,
"cleanlab_score": 0.82,
"comparison_analysis": {
"score_difference": 0.03,
"score_ratio": 1.037,
"percentage_difference": 3.66
},
"statistical_test": {
"t_statistic": 2.45,
"p_value": 0.015,
"significant": true
},
"processing_time": 5.67
}POST /api/v1/batch-process
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"dataset_paths": [
"dataset1.csv",
"dataset2.csv",
"dataset3.csv"
],
"operation": "trust_score"
}Response:
{
"request_id": "uuid-string",
"operation": "trust_score",
"total_datasets": 3,
"successful": 2,
"failed": 1,
"results": [
{
"dataset": "dataset1.csv",
"trust_score": 0.85,
"status": "success"
},
{
"dataset": "dataset2.csv",
"trust_score": 0.78,
"status": "success"
},
{
"dataset": "dataset3.csv",
"status": "error",
"error": "File not found"
}
],
"timestamp": "2024-01-01T12:00:00Z"
}// Connect to WebSocket
const ws = new WebSocket('ws://localhost:8000/ws/client-id-123');{
"type": "trust_score_request",
"request_id": "uuid-string",
"dataset_path": "path/to/dataset.csv",
"method": "ensemble"
}{
"type": "trust_score_response",
"request_id": "uuid-string",
"trust_score": 0.85,
"method": "ensemble",
"component_scores": {...},
"timestamp": "2024-01-01T12:00:00Z"
}trust_score_request: Calculate trust scorefile_upload_request: Upload filecleanlab_comparison_request: Run Cleanlab comparison
import asyncio
from mcp_server.client import MCPOpenTrustEvalClient
async def main():
async with MCPOpenTrustEvalClient("http://localhost:8000") as client:
# Login
await client.login("admin", "admin123")
# Calculate trust score
result = await client.calculate_trust_score("dataset.csv")
print(f"Trust Score: {result['trust_score']}")
# Upload file
upload_result = await client.upload_file("data.csv")
print(f"Uploaded: {upload_result['file_path']}")
# WebSocket communication
client_id = await client.connect_websocket()
ws_result = await client.websocket_trust_score("dataset.csv")
print(f"WebSocket result: {ws_result}")
asyncio.run(main())from mcp_server.client import SyncMCPOpenTrustEvalClient
# Create client
client = SyncMCPOpenTrustEvalClient("http://localhost:8000")
# Login
client.login("admin", "admin123")
# Calculate trust score
result = client.calculate_trust_score("dataset.csv")
print(f"Trust Score: {result['trust_score']}")
# Batch processing
batch_result = client.batch_process(
["dataset1.csv", "dataset2.csv"],
"trust_score"
)
print(f"Batch results: {batch_result}")# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key
JWT_ALGORITHM=HS256
JWT_EXPIRY_HOURS=24
ENCRYPTION_KEY=your-encryption-key
# Rate Limiting
RATE_LIMIT_REQUESTS=1000
RATE_LIMIT_WINDOW=60
# File Upload
MAX_FILE_SIZE=104857600
UPLOAD_DIR=./uploads# Server Settings
SERVER_HOST=0.0.0.0
SERVER_PORT=8000
SERVER_WORKERS=1
# SSL Configuration
SSL_CERT_PATH=cert.pem
SSL_KEY_PATH=key.pem
# CORS
ALLOWED_ORIGINS=["*"]# Timeouts
TRUST_SCORE_TIMEOUT=300
CLEANLAB_TIMEOUT=600
# WebSocket
WEBSOCKET_MAX_CONNECTIONS=1000
WEBSOCKET_HEARTBEAT_INTERVAL=30# Validate configuration
python mcp_server/config.py
# Generate environment template
python mcp_server/config.py# Login to get JWT token
response = await client.login("username", "password")
token = response["token"]
# Use token in requests
headers = {"Authorization": f"Bearer {token}"}# Set API key
client = MCPOpenTrustEvalClient(
"http://localhost:8000",
api_key="your-api-key"
)# Enable encryption
client = MCPOpenTrustEvalClient(
"http://localhost:8000",
encryption_key="your-encryption-key"
)
# Data is automatically encrypted/decrypted- Default: 1000 requests per minute per client
- Configurable: Via environment variables
- Per-client: Based on user ID or IP address
# Enable SSL
python mcp_server/server.py --ssl
# With custom certificates
SSL_CERT_PATH=cert.pem SSL_KEY_PATH=key.pem python mcp_server/server.pycurl http://localhost:8000/healthResponse:
{
"status": "healthy",
"timestamp": "2024-01-01T12:00:00Z",
"version": "1.0.0",
"services": {
"trust_scoring": "active",
"file_upload": "active",
"cleanlab": "active",
"database": "active"
}
}# Enable metrics
ENABLE_METRICS=true METRICS_PORT=8001 python mcp_server/server.py
# Access metrics
curl http://localhost:8001/metrics# Configure logging level
LOG_LEVEL=DEBUG python mcp_server/server.py
# Log file
tail -f mcp_server.log# Run tests
pytest mcp_server/tests/
# With coverage
pytest --cov=mcp_server mcp_server/tests/# Test server endpoints
python mcp_server/test_integration.py
# Test client library
python mcp_server/test_client.py# Install locust
pip install locust
# Run load test
locust -f mcp_server/locustfile.py --host=http://localhost:8000# Dockerfile
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["python", "mcp_server/server.py"]# Build and run
docker build -t opentrusteval-mcp .
docker run -p 8000:8000 opentrusteval-mcp# Using gunicorn
pip install gunicorn
gunicorn mcp_server.server:app -w 4 -k uvicorn.workers.UvicornWorker
# Using systemd
sudo systemctl enable opentrusteval-mcp
sudo systemctl start opentrusteval-mcp# Nginx configuration
upstream mcp_backend {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
}
server {
listen 80;
server_name mcp.yourdomain.com;
location / {
proxy_pass http://mcp_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /ws/ {
proxy_pass http://mcp_backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}# Check if server is running
netstat -tlnp | grep 8000
# Check logs
tail -f mcp_server.log# Check JWT token
python -c "import jwt; print(jwt.decode('your-token', 'your-secret', algorithms=['HS256']))"
# Verify API key
curl -H "X-API-Key: your-key" http://localhost:8000/health# Check file size limits
ls -lh your-file.csv
# Check upload directory permissions
ls -la ./uploads/# Monitor server resources
htop
iotop
# Check rate limiting
curl -H "X-RateLimit-Remaining: 0" http://localhost:8000/api/v1/trust-score# Enable debug mode
DEBUG=true python mcp_server/server.py
# Verbose logging
LOG_LEVEL=DEBUG python mcp_server/server.py- Documentation: Check this README first
- API Docs: Visit http://localhost:8000/docs
- Issues: Report on GitHub
- Discussions: Use GitHub Discussions
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- API: http://localhost:8000
- Docs: http://localhost:8000/docs
- Health: http://localhost:8000/health
- Metrics: http://localhost:8001/metrics (if enabled)
# Start server
python mcp_server/server.py
# Start with SSL
python mcp_server/server.py --ssl
# Test client
python mcp_server/client.py
# Validate config
python mcp_server/config.py# Generate template
python mcp_server/config.py
# Copy and edit
cp .env.template .env
# Edit .env file# Quick start
from mcp_server.client import SyncMCPOpenTrustEvalClient
client = SyncMCPOpenTrustEvalClient("http://localhost:8000")
result = client.calculate_trust_score("dataset.csv")