Skip to content

About

Local-first AI agent that routes queries between Ollama (local) and Groq (cloud) based on PII. LangGraph, MCP, Presidio. Test project, not actively maintained.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hybrid MCP Hub

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.

Features

  • 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

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                     Streamlit UI (app.py)                       │
└─────────────────────────┬───────────────────────────────────────┘
                          │
┌─────────────────────────▼───────────────────────────────────────┐
│                  LangGraph Orchestration                         │
│  ┌──────────────┐  ┌──────────┐  ┌───────────────────────────┐  │
│  │Privacy Scanner│─▶│  Router  │─▶│ Local Agent │ Cloud Agent │  │
│  └──────────────┘  └──────────┘  └───────────────────────────┘  │
└─────────────────────────┬───────────────────────────────────────┘
                          │
┌─────────────────────────▼───────────────────────────────────────┐
│                    Tool Adapters (tools.py)                      │
└─────────────────────────┬───────────────────────────────────────┘
                          │
┌─────────────────────────▼───────────────────────────────────────┐
│                  FastMCP Server (server.py)                      │
│                        SQLite Hub                                │
└─────────────────────────────────────────────────────────────────┘

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/certainly-param/hybrid-mcp-hub.git
    cd hybrid-mcp-hub
  2. Install dependencies:

    # Using uv (recommended)
    uv sync
    
    # Or using pip
    pip install -e .
  3. Set up environment variables:

    cp .env.example .env
    # Edit .env and add your GROQ_API_KEY (free at console.groq.com)
  4. 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

Usage

Run the Streamlit App

# Using uv
uv run streamlit run app.py

# Or using Python directly
python -m streamlit run app.py

Then open your browser to http://localhost:8501

Routing Modes

  1. Dynamic (Privacy-Based): Default mode. Routes to local model when PII is detected, otherwise uses Groq cloud for better responses.

  2. Always Local: Forces all queries through the local Llama 3.2:1b model. Maximum privacy, fast inference.

  3. Always Cloud: Forces all queries through Groq (Llama 3.3 70B). Best response quality.

Example Queries

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"

Project Structure

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

Testing

Run the test suite:

# Using uv
uv run pytest tests/ -v

# Or using pytest directly
pytest tests/ -v

Configuration

Environment Variables

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

Privacy Threshold

The privacy threshold (default: 0.1) determines when to route to local. Queries with a privacy score above this threshold are processed locally.

How It Works

Privacy Analysis

  1. User input is analyzed by Microsoft Presidio for PII entities
  2. Detected entities are classified:
    • High Risk (score 1.0): Credit cards, SSN
    • Medium Risk (score 0.5): Names, emails, phone numbers
  3. The highest risk level determines the privacy score

Routing Decision

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

Rehydration Loop

When using cloud with PII (strict cloud mode):

  1. PII is replaced with placeholders: John Smith → <PERSON_1>
  2. Cloud processes the anonymized text
  3. Response is rehydrated: <PERSON_1> → John Smith

Security

  • 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

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests: pytest tests/ -v
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Acknowledgments


GitHub Repo stars

Star this repo — certainly-param/hybrid-mcp-hub

Made when I was 🥱 a lot.

About

Local-first AI agent that routes queries between Ollama (local) and Groq (cloud) based on PII. LangGraph, MCP, Presidio. Test project, not actively maintained.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages