ModelFit-MCP
Hardware-Aware Hugging Face Discovery, Memory Fitting, Empirical Benchmarking & Swappable Local Model Gateway for AI Agents.
ModelFit-MCP connects AI agents (Claude Desktop, Cursor, custom autonomous agents) to Hugging Face with built-in hardware awareness. It profiles host specs (CPU, RAM, GPU, VRAM), calculates exact model memory footprints, filters out models that would trigger CUDA Out of Memory (OOM) errors, and spins up a swappable local gateway so models can be changed dynamically without modifying application code.
Key Features
- Zero OOM Crashes: Automatically evaluates parameter count, precision (
fp32,fp16,int8,int4), and 25% activation headroom before suggesting or loading models. - Empirical Accuracy & Latency Benchmarking: Automatically runs test evaluations across candidate models that satisfy hardware specs to rank them by real-world inference speed and confidence.
- High-Speed Ensembles: Discovers ultra-lightweight models that consume $\le 35%$ of hardware headroom and aggregates them via
weighted_average,majority_vote, ortop_confidencestrategies. - Swappable Architecture: Your client code interacts with an abstract gateway (
gateway.predict()orPOST /predict). Models can be upgraded or hot-swapped without touching your application code. - Memory Purging: Unloads old weights and triggers
torch.cuda.empty_cache()on every swap to prevent VRAM memory leaks. - Multi-Modal: Normalizes outputs across
image-classification,object-detection,text-generation, andzero-shot-image-classification. - Cross-Language Ready: First-class support for Python, Flutter/Dart, Node.js, and cURL.
System Architecture
flowchart TD
User["Your App / AI Agent\n(Plant App, Flutter, Web, CLI)"] -->|predict / ensemble| Gateway["Local Model Gateway\n(In-Process or http://127.0.0.1:7860)"]
subgraph Engine["ModelFit-MCP Engine"]
Gateway --> ActiveModel["Active Model(s)\n(MobileNet / ViT / ResNet)"]
MCP["MCP Server / CLI\n(modelfit)"] -.->|Hot Swap + Memory Purge| ActiveModel
Profiler["hardware.py\n(VRAM & RAM Profiler)"] --> HFFilter["hf_client.py\n(Sizing & Ranking)"]
HFFilter --> Evaluator["evaluator.py\n(Benchmarking & Latency)"]
HFFilter --> Ensemble["ensemble.py\n(Multi-Model Aggregator)"]
Evaluator --> MCP
Ensemble --> MCP
end
Quickstart
1. Installation
git clone https://github.com/DumboDhruvi/ModelFit-MCP.git
cd ModelFit-MCP
pip install -e .
2. CLI Usage
Inspect your hardware headroom:
modelfit specs
Search Hugging Face models guaranteed to fit your machine:
modelfit search "plant disease" --task image-classification
Benchmark multiple candidate models on your hardware:
modelfit benchmark "nateraw/food,google/vit-base-patch16-224" --samples "sample1.jpg,sample2.jpg"
Run ensemble inference across lightweight models:
modelfit ensemble "model-a,model-b" --input "sample.jpg" --strategy weighted_average
Start the local micro-API daemon:
modelfit serve --port 7860
Hot-swap models on the fly:
modelfit swap "google/vit-base-patch16-224" --task image-classification
MCP Server Tools (Claude Desktop & Cursor)
Add ModelFit to your claude_desktop_config.json:
{
"mcpServers": {
"modelfit": {
"command": "modelfit-server"
}
}
}
Available MCP Tools:
| Tool | Description |
|---|---|
get_hardware_specs |
Detect host CPU, RAM, and GPU/VRAM headroom. |
search_compatible_models |
Search Hugging Face models strictly filtered by hardware fit. |
recommend_and_scaffold |
1-shot model search, hardware check, and code scaffolding. |
benchmark_models |
Run live accuracy and latency benchmarking on candidate models. |
find_ensemble_models |
Find ultra-fast models suitable for low-latency ensembling. |
ensemble_predict |
Execute ensemble prediction combining multiple models. |
swap_active_model |
Hot-swap the active model with VRAM-safe memory purging. |
get_active_model_status |
Inspect currently loaded model and target device. |
get_integration_code |
Get drop-in Python inference code. |
Integration Modes
Mode A: In-Process Python Adapter (Zero Latency)
from modelfit.adapter import gateway
# 1. Load initial model
gateway.load_model("linkanjarad/mobilenet_v2_1.0_224-plant-disease-identification")
# 2. Abstract prediction
results = gateway.predict("leaf.jpg")
print(results[0].label, results[0].score)
# 3. Hot-swap later with ZERO code changes below
gateway.load_model("google/vit-base-patch16-224")
results = gateway.predict("leaf.jpg")
Mode B: High-Speed Ensemble Inference
from modelfit.ensemble import EnsembleGateway
ensemble = EnsembleGateway()
candidates = ensemble.find_ensemble_candidates("plant disease", max_models=3)
model_ids = [m["model_id"] for m in candidates]
predictions = ensemble.predict_ensemble(
input_data="leaf.jpg",
model_ids=model_ids,
strategy="weighted_average"
)
for p in predictions:
print(f"{p.label}: {p.score:.2f} (votes: {p.votes})")
Mode C: Local Micro-API (Flutter, Node.js, Web, cURL)
Start the background daemon:
modelfit serve --port 7860
Query or swap over HTTP:
# Predict
curl -X POST http://127.0.0.1:7860/predict \
-H "Content-Type: application/json" \
-d '{"input": "leaf_sample.jpg"}'
# Hot-Swap
curl -X POST http://127.0.0.1:7860/swap \
-H "Content-Type: application/json" \
-d '{"model_id": "google/vit-base-patch16-224", "task": "image-classification"}'
See examples/flutter_integration_example.dart for a complete Flutter service.
Testing
Run the full test suite:
python3 -m unittest discover tests -v
All tests complete in under 2 seconds.
License
MIT License. See LICENSE for details.
Release files for modelfit-mcp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| modelfit_mcp-0.1.0.tar.gz | 24.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| modelfit_mcp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 45.6 kB
Release files / modelfit_mcp-0.1.0.tar.gz
| Download URL | modelfit_mcp-0.1.0.tar.gz |
|---|---|
| Size | 24.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b530f7dd034d362315aaf8b22dd95f2149cdbc6cf0c5029e1f8815aa421af72f
|
|
BLAKE2b-256 checksum How to use checksums |
ea3ea0f47995fae6c1a2a5249d4ccc27c4bb45d5cdb4a01a12e14db5ee9d4a6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.
Transparency logRelease files / modelfit_mcp-0.1.0-py3-none-any.whl
| Download URL | modelfit_mcp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 21.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfece8aa704a88712735604332899ad344476d720546cf833ba0916bfd088030
|
|
BLAKE2b-256 checksum How to use checksums |
9d5af4f00cb918142b367d2fae6ac72016acc208ddeec407e9684423e911f5bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.
Transparency log