A Local-First AI agent that intelligently routes user tasks between a local model (Ollama/Llama 3.2:1b) and a cloud model (Groq/Llama 3.3 70B) based on privacy constraints. Uses the Model Context Protocol (MCP) to standardize tool access (SQLite) across both environments.
About this project — I built this mainly to test some stuff and have fun (LangGraph, MCP, Presidio, Groq vs Ollama). It works, but I’m not planning to develop it further or maintain it. Use it as a reference or fork it if you like.
- Privacy-Aware Routing: Automatically detects PII (Personal Identifiable Information) and routes sensitive queries to the local model
- Dual Model Support: Seamlessly switches between Llama 3.2:1b (local) and Llama 3.3 70B via Groq (cloud)
- MCP Integration: Standardized database access through FastMCP protocol
- PII Detection: Uses Microsoft Presidio for comprehensive PII analysis
- Rehydration Loop: Anonymizes data for cloud processing, then restores original values in responses
- Context Pruning: Automatically manages context window for local model's limitations
- Streamlit UI: Modern web interface with routing mode controls and status indicators
┌─────────────────────────────────────────────────────────────────┐
│ Streamlit UI (app.py) │
└─────────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────────┐
│ LangGraph Orchestration │
│ ┌──────────────┐ ┌──────────┐ ┌───────────────────────────┐ │
│ │Privacy Scanner│─▶│ Router │─▶│ Local Agent │ Cloud Agent │ │
│ └──────────────┘ └──────────┘ └───────────────────────────┘ │
└─────────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────────┐
│ Tool Adapters (tools.py) │
└─────────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────────┐
│ FastMCP Server (server.py) │
│ SQLite Hub │
└─────────────────────────────────────────────────────────────────┘
- Python 3.11+
- uv (recommended) or pip
- Ollama installed and running
- Groq API key (FREE at https://console.groq.com/keys)
-
Clone the repository:
git clone https://github.com/certainly-param/hybrid-mcp-hub.git cd hybrid-mcp-hub -
Install dependencies:
# Using uv (recommended) uv sync # Or using pip pip install -e .
-
Set up environment variables:
cp .env.example .env # Edit .env and add your GROQ_API_KEY (free at console.groq.com) -
Start Ollama and pull the model:
# Start Ollama service ollama serve # In another terminal, pull the Llama3.2:1b model (small, fast, free) ollama pull llama3.2:1b
# Using uv
uv run streamlit run app.py
# Or using Python directly
python -m streamlit run app.pyThen open your browser to http://localhost:8501
-
Dynamic (Privacy-Based): Default mode. Routes to local model when PII is detected, otherwise uses Groq cloud for better responses.
-
Always Local: Forces all queries through the local Llama 3.2:1b model. Maximum privacy, fast inference.
-
Always Cloud: Forces all queries through Groq (Llama 3.3 70B). Best response quality.
Cloud-routed (no PII):
- "What are all the pending transactions?"
- "Show me the total amount of completed transactions"
- "What is the average transaction amount?"
Local-routed (PII detected):
- "Check the balance for John Smith"
- "My email is john@example.com, what transactions do I have?"
- "My SSN is 123-45-6789, verify my account"
hybrid-mcp-hub/
├── .env # Environment variables (API keys)
├── .env.example # Environment template
├── pyproject.toml # Dependencies and project config
├── README.md # This file
├── app.py # Streamlit UI
├── data/
│ └── hybrid_hub.db # SQLite database (auto-created)
├── src/
│ ├── __init__.py
│ ├── config.py # Configuration and settings
│ ├── server.py # FastMCP SQLite server
│ ├── privacy.py # PII detection and anonymization
│ ├── tools.py # LangChain tool adapters
│ ├── graph.py # LangGraph orchestration
│ └── utils.py # Logging and helpers
└── tests/
├── __init__.py
└── test_routing.py # Test suite
Run the test suite:
# Using uv
uv run pytest tests/ -v
# Or using pytest directly
pytest tests/ -v| Variable | Description | Default |
|---|---|---|
GROQ_API_KEY |
Groq API key (free at console.groq.com) | Required |
OLLAMA_BASE_URL |
Ollama server URL | http://localhost:11434 |
LOCAL_MODEL |
Local model name | llama3.2:1b |
CLOUD_MODEL |
Cloud model name | llama-3.3-70b-versatile |
The privacy threshold (default: 0.1) determines when to route to local. Queries with a privacy score above this threshold are processed locally.
- User input is analyzed by Microsoft Presidio for PII entities
- Detected entities are classified:
- High Risk (score 1.0): Credit cards, SSN
- Medium Risk (score 0.5): Names, emails, phone numbers
- The highest risk level determines the privacy score
IF routing_mode == "strict_local":
route to local
ELIF routing_mode == "strict_cloud":
route to cloud
ELIF privacy_score > threshold:
route to local
ELSE:
route to cloud
When using cloud with PII (strict cloud mode):
- PII is replaced with placeholders:
John Smith→<PERSON_1> - Cloud processes the anonymized text
- Response is rehydrated:
<PERSON_1>→John Smith
- SQL Injection Prevention: Only SELECT queries allowed
- PII Protection: Sensitive data can be kept local
- API Key Security: Stored in environment variables
- Query Logging: All database queries are logged
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
pytest tests/ -v - Submit a pull request
MIT License - see LICENSE file for details.
- FastMCP - MCP server framework
- LangGraph - Agent orchestration
- Microsoft Presidio - PII detection
- Ollama - Local LLM runtime
- Groq - Ultra-fast cloud inference
Star this repo — certainly-param/hybrid-mcp-hub
Made when I was 🥱 a lot.