Skip to content

Latest commit

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

ML Lab MCP

A comprehensive MCP (Model Context Protocol) server for ML model training, fine-tuning, and experimentation. Transform your AI assistant into a full ML engineering environment.

Features

Unified Credential Management

  • Encrypted vault for API keys (Lambda Labs, RunPod, Mistral, OpenAI, Together AI, etc.)
  • PBKDF2 key derivation with AES encryption
  • Never stores credentials in plaintext

Dataset Management

  • Register datasets from local files OR client-provided content (JSONL, CSV, Parquet)
  • Upload datasets directly without server filesystem access
  • Automatic schema inference and statistics
  • Train/val/test splitting
  • Template-based transformations

Experiment Tracking

  • SQLite-backed experiment storage
  • Version control and comparison
  • Fork experiments with config modifications
  • Full metrics history

Multi-Backend Training

  • Local: transformers + peft + trl for local GPU training
  • Mistral API: Native fine-tuning for Mistral models
  • Together AI: Hosted fine-tuning service
  • OpenAI: GPT model fine-tuning

Cloud GPU Provisioning

  • Lambda Labs: H100, A100 instances
  • RunPod: Spot and on-demand GPUs
  • Automatic price comparison across providers
  • Smart routing based on cost and availability

Remote VPS Support

  • Use any SSH-accessible machine (Hetzner, Hostinger, OVH, home server, university cluster)
  • Automatic environment setup
  • Dataset sync via rsync
  • Training runs in tmux (persistent across disconnects)
  • Amortized hourly cost calculation from monthly fees

Cost Estimation

  • Pre-training cost estimates across all providers
  • Real-time pricing queries
  • Time estimates based on model and dataset size

Ollama Integration

  • Deploy fine-tuned GGUF models to Ollama
  • Pull models from Ollama registry
  • Chat/inference testing directly from MCP
  • Model management (list, delete, copy)

Open WebUI Integration

  • Create model presets with system prompts
  • Knowledge base management (RAG)
  • Chat through Open WebUI (applies configs + knowledge)
  • Seamless Ollama ↔ Open WebUI workflow

Installation

pip install ml-lab-mcp
# With training dependencies
pip install ml-lab-mcp[training]
# With cloud provider support
pip install ml-lab-mcp[cloud]
# Everything
pip install ml-lab-mcp[training,cloud,dev]

Quick Start

1. Initialize and Create Vault

ml-lab init
ml-lab vault create

2. Add Provider Credentials

ml-lab vault unlock
ml-lab vault add --provider lambda_labs --api-key YOUR_KEY
ml-lab vault add --provider mistral --api-key YOUR_KEY

3. Configure with Claude Code / Claude Desktop

Add to your MCP configuration:

{
"mcpServers": {
"ml-lab": {
"command": "ml-lab",
"args": ["serve"]
}
}
}

MCP Tools

Credentials

ToolDescription
creds_create_vaultCreate encrypted credential vault
creds_unlockUnlock vault with password
creds_addAdd provider credentials
creds_listList configured providers
creds_testVerify credentials work (Lambda Labs, GCP, OpenAI supported)

Datasets

ToolDescription
dataset_registerRegister a dataset from a local file
dataset_register_contentRegister a dataset from client-provided content (CSV, JSON, JSONL, Parquet)
dataset_listList all datasets
dataset_inspectView schema and statistics
dataset_previewPreview samples
dataset_splitCreate train/val/test splits
dataset_transformApply template transformations

Experiments

ToolDescription
experiment_createCreate new experiment
experiment_listList experiments
experiment_getGet experiment details
experiment_compareCompare multiple experiments
experiment_forkFork with modifications

Training

ToolDescription
train_estimateEstimate cost/time across providers
train_launchStart training run
train_statusCheck run status
train_stopStop training

Infrastructure

ToolDescription
infra_list_gpusList available GPUs with pricing
infra_provisionProvision cloud instance
infra_terminateTerminate instance

Remote VPS

ToolDescription
vps_registerRegister a VPS (host, user, key, GPU info, monthly cost)
vps_listList all registered VPS machines
vps_statusCheck VPS status (online, GPU, running jobs)
vps_unregisterRemove a VPS from registry
vps_setupInstall training dependencies on VPS
vps_syncSync dataset to VPS
vps_runRun command on VPS
vps_logsGet training logs from VPS

Ollama

ToolDescription
ollama_statusCheck Ollama status (running, version, GPU)
ollama_listList models in Ollama
ollama_pullPull model from registry
ollama_deployDeploy GGUF to Ollama
ollama_chatChat with a model
ollama_deleteDelete a model

Open WebUI

ToolDescription
owui_statusCheck Open WebUI connection
owui_list_modelsList model configurations
owui_create_modelCreate model preset (system prompt, params)
owui_delete_modelDelete model configuration
owui_list_knowledgeList knowledge bases
owui_create_knowledgeCreate knowledge base
owui_add_knowledge_fileAdd file to knowledge base
owui_chatChat through Open WebUI

Security

ToolDescription
security_audit_logView recent audit log entries
security_audit_summaryGet audit activity summary
security_tailscale_statusCheck Tailscale VPN connection
security_ssh_key_rotateRotate SSH key for a VPS
creds_expiry_checkCheck credential expiry status
creds_rotateRotate credentials for a provider

Codex Integration (Executor LLM)

ToolDescription
codex_statusCheck if Codex CLI is available
codex_analyze_errorHave Codex analyze errors and suggest fixes
codex_generate_training_scriptGenerate training script from experiment config
codex_fix_codeHave Codex fix issues in training code
codex_optimize_configOptimize training config for quality/speed/memory
codex_debug_trainingDebug training issues from logs
codex_runRun arbitrary task with Codex

Architecture: Separation of intelligence vs execution:

  • Planner LLM (Claude): Reasoning, architecture, tradeoffs
  • Executor LLM (Codex): Precise code edits + CLI work
  • World tools (ML Lab): Data, training, infra, deployment

Deep Thinking Analysis (Ollama Reasoning Models)

ToolDescription
thinking_analyzeRun deep analysis with reasoning models (DeepSeek R1, QwQ)
thinking_scheduleSchedule automated analysis (after training, daily, weekly)
thinking_reportsList and retrieve analysis reports

Analysis Types:

  • training - Analyze loss curves, convergence, hyperparameters
  • experiment - Compare experiments, suggest improvements
  • activity - Review audit logs for patterns/anomalies
  • cost - Cost efficiency analysis and recommendations
  • dataset - Data quality and training suitability

Schedule Frequencies:

  • after_training - Auto-analyze when training completes
  • hourly / daily / weekly - Periodic reviews

Reports stored in ~/.cache/ml-lab/reports/ for historical reference.

Example Workflow

User: Fine-tune Llama 3.1 8B on my customer support data
Claude: I'll help you fine-tune Llama 3.1 8B. Let me first check your data.
[Uses dataset_register to load ./support_data.jsonl]
Found 15,000 samples. Let me estimate the costs:
[Uses train_estimate]
| Provider | Time | Cost | Availability |
|---------------|--------|--------|--------------|
| vps:hetzner-01| ~4h | $0.28* | Idle |
| Local (4090) | ~12h | $0 | Ready |
| Lambda H100 | ~2h | $5.50 | 3 available |
| Together API | ~4h | $12 | Queued |
*amortized from $200/mo
Which would you prefer?
User: Use Lambda Labs
Claude: [Uses experiment_create, then train_launch with backend=lambda]
Training started! Run ID: abc123
I'll monitor progress and let you know when it completes.

Architecture

src/ml_lab/
├── server.py # MCP server entry point (61 tools)
├── credentials.py # Encrypted credential vault
├── cli.py # Command-line interface
├── backends/
│ ├── base.py # Training backend interface
│ ├── local.py # Local GPU training
│ ├── mistral_api.py # Mistral fine-tuning API
│ ├── together_api.py # Together AI API
│ ├── openai_api.py # OpenAI fine-tuning API
│ └── vertex_api.py # Google Vertex AI (Gemini)
├── cloud/
│ ├── base.py # Cloud provider interface
│ ├── lambda_labs.py # Lambda Labs integration
│ ├── runpod.py # RunPod integration
│ ├── modal_provider.py # Modal integration
│ └── remote_vps.py # Generic SSH VPS support (+ Tailscale)
├── storage/
│ ├── datasets.py # Dataset management
│ └── experiments.py # Experiment tracking
├── inference/
│ ├── ollama.py # Ollama integration
│ ├── openwebui.py # Open WebUI integration
│ └── thinking.py # Deep thinking analysis (DeepSeek R1, QwQ)
├── integrations/
│ └── codex.py # Codex CLI integration (executor LLM)
├── security/
│ └── audit.py # Audit logging
└── evals/
└── benchmarks.py # Evaluation suite

Security

  • Credentials encrypted with Fernet (AES-128-CBC)
  • PBKDF2-SHA256 key derivation (480,000 iterations)
  • Vault file permissions set to 600 (owner read/write only)
  • API keys never logged or transmitted unencrypted
  • Audit logging: All sensitive operations logged to ~/.cache/ml-lab/audit.log
  • Credential expiry: Automatic tracking with rotation reminders
  • Tailscale support: Optional VPN requirement for VPS connections
  • SSH key rotation: Automated rotation with rollback on failure

Supported Providers

Compute Providers

  • Lambda Labs (H100, A100, A10)
  • RunPod (H100, A100, RTX 4090)
  • Modal (serverless GPU functions)

Fine-Tuning APIs

  • Mistral AI (Mistral, Mixtral, Codestral)
  • Together AI (Llama, Mistral, Qwen)
  • OpenAI (GPT-4o, GPT-3.5)
  • Google Vertex AI (Gemini 1.5 Pro, Gemini 1.5 Flash)

Model Hubs

  • Hugging Face Hub
  • Replicate
  • Ollama (local GGUF models)

Contributing

Contributions welcome! Please read CONTRIBUTING.md for guidelines.

License

PolyForm Noncommercial 1.0.0 - free for personal use, contact for commercial licensing.

See LICENSE for details.

About

A comprehensive MCP (Model Context Protocol) server for ML model training, fine-tuning, and experimentation. Transform your AI assistant into a full ML engineering environment.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages