Skip to main content
Glama
README.md
# Quorum-MCP

> Multi-AI Consensus System MCP Server - Get better answers through deliberation

[![Tests](https://img.shields.io/badge/tests-105%20passing-success)](https://github.com/aj-geddes/quorum-mcp)
[![Coverage](https://img.shields.io/badge/coverage-95%25-brightgreen)](https://github.com/aj-geddes/quorum-mcp)
[![Python](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org)
[![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)

## ๐ŸŽฏ Overview

Quorum-MCP orchestrates multiple AI providers (Anthropic Claude, OpenAI, Google Gemini, Cohere, Mistral AI, Novita AI, Ollama) through multi-round deliberation to produce consensus-based responses. By combining different AI models, you get more balanced, comprehensive, and reliable answers.

**Why Quorum?**
- ๐ŸŽญ **Diverse Perspectives**: Each AI has unique strengths and biases
- ๐Ÿค **Consensus Building**: Agreement across models increases confidence
- ๐Ÿ” **Quality Assurance**: Cross-validation catches errors and hallucinations
- ๐Ÿ’ก **Richer Insights**: Disagreements reveal nuanced viewpoints

## โœจ Features

### Multi-Provider Support (7 Providers!)
- ๐Ÿค– **Anthropic Claude** - Thoughtful, nuanced reasoning
  - Models: `claude-3-5-sonnet-20241022` (default), `claude-3-opus`, `claude-3-haiku`
  - Context: 200K tokens | Cost: $3-$15/1M input
- ๐Ÿง  **OpenAI** - Broad knowledge, strong reasoning
  - Models: `gpt-4o` (default), `gpt-4o-mini`, `gpt-4-turbo`
  - Context: 128K tokens | Cost: $0.15-$30/1M input
- โœจ **Google Gemini** - Fast, cost-effective, huge context
  - Models: `gemini-2.5-flash` (default), `gemini-2.5-pro`, `gemini-1.5-pro`
  - Context: Up to **2M tokens** | Cost: $0.15-$1.25/1M input
- ๐Ÿข **Cohere** - Enterprise RAG, production-ready
  - Models: `command-r-plus` (default), `command-r`, `command-light`
  - Context: 128K tokens | Cost: $0.30-$15/1M input
  - Features: Excellent RAG capabilities, free tier available
- ๐Ÿ‡ช๐Ÿ‡บ **Mistral AI** - Best pricing, European AI
  - Models: `mistral-large-latest` (default), `mistral-small-latest`, `mixtral-8x22b`
  - Context: 128K tokens | Cost: $0.04-$6/1M input
  - Features: GDPR compliant, competitive with GPT-4
- โšก **Novita AI** - Ultra-low cost, OpenAI-compatible
  - Models: `llama-3.3-70b` (default), `deepseek-r1`, `qwen-2.5-72b`
  - Context: 128K tokens | Cost: **$0.04-$0.20/1M input** (cheapest!)
  - Features: OpenAI-compatible API, multiple open-source models
- ๐Ÿ  **Ollama (Local LLMs)** - Private, zero-cost local inference
  - Models: `llama3.2` (default), `llama3.1`, `mistral`, `mixtral`, `qwen3`, `deepseek-r1`, `gemma3`
  - Context: Up to 128K tokens | Cost: **$0.00** (100% local)
  - Privacy: 100% - Data never leaves your machine

### Three Operational Modes

**1. Quick Consensus** (Single Round)
```python
# Fast consensus for straightforward queries
session = await orchestrator.execute_quorum(
    query="What are Python best practices?",
    mode="quick_consensus"
)
```

**2. Full Deliberation** (3 Rounds)
```python
# Multi-round deliberation for complex decisions
# Round 1: Independent analysis
# Round 2: Cross-review and critique
# Round 3: Final synthesis
session = await orchestrator.execute_quorum(
    query="Should we use microservices or monolith?",
    mode="full_deliberation"
)
```

**3. Devil's Advocate** (Critical Analysis)
```python
# Challenge assumptions and find weaknesses
session = await orchestrator.execute_quorum(
    query="We should skip testing to move faster",
    mode="devils_advocate"
)
```

### Additional Features
- ๐ŸŒ **Web Dashboard**: Interactive browser-based UI (NEW!)
- โšก **Async/Await**: Non-blocking I/O throughout
- ๐Ÿ’ฐ **Cost Tracking**: Per-provider and total cost reporting (including $0 for local)
- ๐Ÿ“Š **Cost Calculator**: Estimate costs before running queries (NEW!)
- ๐Ÿ  **Local LLMs**: Zero-cost inference with Ollama (100% private)
- ๐Ÿ“ **Session Management**: Persistent session storage and retrieval
- ๐Ÿ”’ **Type Safe**: Full Pydantic validation
- ๐Ÿงช **Well Tested**: 105 passing tests, 95% provider coverage
- ๐Ÿ“ก **MCP Integration**: Works with Claude Desktop and other MCP clients
- ๐Ÿ”„ **Real-Time Updates**: WebSocket-powered live notifications (NEW!)

## ๐Ÿš€ Quick Start

### Installation

```bash
# Clone the repository
git clone https://github.com/aj-geddes/quorum-mcp.git
cd quorum-mcp

# Install with dependencies
pip install -e .

# Or install for development
pip install -e ".[dev]"
```

### Configuration

#### Cloud Providers (Optional)

Set your API keys as environment variables (use whichever providers you prefer):

```bash
# Traditional providers
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-..."
export GOOGLE_API_KEY="..."

# New providers (optional - mix and match!)
export COHERE_API_KEY="..."
export MISTRAL_API_KEY="..."
export NOVITA_API_KEY="..."
```

#### Local LLMs with Ollama (Optional, Zero Cost)

Install and run Ollama for 100% free, private local inference:

```bash
# Install Ollama (Mac/Linux/Windows)
# Visit: https://ollama.com/download

# Start Ollama server
ollama serve

# Pull a model (in another terminal)
ollama pull llama3.2

# Optional: Configure Ollama host (default: http://localhost:11434)
export OLLAMA_HOST="http://localhost:11434"
export OLLAMA_ENABLE="true"  # Set to "false" to disable
```

**Note**: At least one provider (cloud or local) is required. Ollama enables zero-cost consensus!

### Running the Server

#### Option 1: Web Dashboard (Recommended for Getting Started)

Launch the interactive web interface:

```bash
# Start the web server
quorum-web

# Or run directly
python -m quorum_mcp.web_server
```

Then open `http://localhost:8000` in your browser. No coding required!

**Features:**
- ๐ŸŽจ Interactive query builder
- ๐Ÿ“Š Real-time consensus visualization
- ๐Ÿ’ฐ Cost calculator and estimator
- ๐Ÿ“ˆ Session history and analytics
- ๐Ÿ” Provider comparison tools

[๐Ÿ“– Read the Web Dashboard Guide](docs/quickstart/WEB_DASHBOARD.md)

#### Option 2: MCP Server (for Claude Desktop Integration)

For programmatic use or Claude Desktop integration:

```bash
# Start the MCP server
quorum-mcp

# Or run directly
python -m quorum_mcp.server
```

### Basic Usage Example

```python
import asyncio
from quorum_mcp.orchestrator import Orchestrator
from quorum_mcp.providers import (
    AnthropicProvider,
    OpenAIProvider,
    GeminiProvider,
    CohereProvider,     # New!
    MistralProvider,    # New!
    NovitaProvider,     # New!
    OllamaProvider,     # Local
)
from quorum_mcp.session import get_session_manager

async def main():
    # Initialize providers (use any combination!)
    providers = [
        AnthropicProvider(),
        OpenAIProvider(),
        GeminiProvider(),
        # Add new providers for more perspectives:
        CohereProvider(),   # Enterprise RAG
        MistralProvider(),  # Best pricing
        NovitaProvider(),   # Ultra-low cost
    ]

    # Start session manager
    session_manager = get_session_manager()
    await session_manager.start()

    # Create orchestrator
    orchestrator = Orchestrator(
        providers=providers,
        session_manager=session_manager
    )

    # Execute consensus
    session = await orchestrator.execute_quorum(
        query="What is the best database for a startup?",
        context="Small team, rapid iteration, expecting growth",
        mode="quick_consensus"
    )

    # Print results
    print(f"Confidence: {session.consensus['confidence']:.2%}")
    print(f"Summary: {session.consensus['summary']}")
    print(f"Cost: ${session.consensus['cost']['total_cost']:.4f}")

    await session_manager.stop()

asyncio.run(main())
```

## ๐Ÿ“– Usage

### MCP Tools

Quorum-MCP provides two simple tools for MCP clients:

#### `q_in` - Submit Query

```json
{
  "query": "What are the top 3 considerations for API design?",
  "context": "Building a REST API for a SaaS product",
  "mode": "quick_consensus"
}
```

Returns:
```json
{
  "session_id": "abc-123-def",
  "status": "completed",
  "confidence": 0.85,
  "consensus": {
    "summary": "Based on consensus...",
    "agreement_areas": [...],
    "cost": {...}
  }
}
```

#### `q_out` - Retrieve Results

```json
{
  "session_id": "abc-123-def"
}
```

Returns the full session data including consensus results.

### Using with Claude Desktop

Add to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "quorum-mcp": {
      "command": "quorum-mcp",
      "env": {
        "ANTHROPIC_API_KEY": "your-key",
        "OPENAI_API_KEY": "your-key",
        "GOOGLE_API_KEY": "your-key"
      }
    }
  }
}
```

### Running Demos

```bash
# Three-provider consensus demo (cloud providers)
python examples/three_provider_demo.py

# Local LLM demo with Ollama (zero cost!)
python examples/local_llm_demo.py

# End-to-end demo with all modes
python examples/end_to_end_demo.py

# Session management demo
python examples/session_demo.py
```

## ๐Ÿ’ฐ Cost Comparison

| Provider | Model | Input ($/1M) | Output ($/1M) | Context Window | Speed |
|----------|-------|--------------|---------------|----------------|-------|
| **Ollama** ๐Ÿ† | **llama3.2** | **$0.00** | **$0.00** | **128K** | โšกโšกโšก |
| **Ollama** | **mistral** | **$0.00** | **$0.00** | **32K** | โšกโšกโšก |
| Gemini   | 2.5 Flash | $0.15 | $0.60 | 200K | โšกโšกโšก |
| OpenAI   | 4o-mini | $0.15 | $0.60 | 128K | โšกโšกโšก |
| Claude   | 3.5 Sonnet | $3.00 | $15.00 | 200K | โšกโšก |
| Gemini   | 2.5 Pro | $1.25 | $10.00 | 200K | โšกโšก |
| Gemini   | 1.5 Pro | $1.25 | $5.00 | 2M | โšก |
| OpenAI   | 4o | $2.50 | $10.00 | 128K | โšกโšก |
| Claude   | 3 Opus | $15.00 | $75.00 | 200K | โšก |

**Typical Consensus Cost** (500 tokens in, 300 tokens out, 3 providers):
- Quick Consensus: ~$0.01 - $0.02
- Full Deliberation (3 rounds): ~$0.03 - $0.06

## ๐Ÿ—๏ธ Architecture

```mermaid
graph TD
    Client[MCP Client<br/>Claude Desktop]

    subgraph FastMCP["FastMCP Server"]
        QIn[q_in tool]
        QOut[q_out tool]
    end

    subgraph Orchestrator["Orchestrator Engine"]
        Consensus[Consensus Algorithms<br/>โ€ข Agreement detection<br/>โ€ข Confidence scoring<br/>โ€ข Synthesis & summarization]
    end

    subgraph Providers["AI Providers"]
        Anthropic[AnthropicProvider<br/>โ€ข Async client<br/>โ€ข Token counting<br/>โ€ข Cost tracking<br/>โ€ข Error mapping]
        OpenAI[OpenAIProvider<br/>โ€ข Async client<br/>โ€ข tiktoken<br/>โ€ข Cost tracking<br/>โ€ข Error mapping]
        Gemini[GeminiProvider<br/>โ€ข Async client<br/>โ€ข Token counting<br/>โ€ข Cost tracking<br/>โ€ข Error mapping]
        Ollama[OllamaProvider<br/>โ€ข Async client<br/>โ€ข Local inference<br/>โ€ข Zero cost<br/>โ€ข 100% private]
    end

    AnthropicAPI[Anthropic API]
    OpenAIAPI[OpenAI API]
    GeminiAPI[Google AI API]
    OllamaServer[Ollama Server<br/>Local]

    Client -->|stdio/HTTP| FastMCP
    QIn --> Consensus
    QOut --> Consensus
    Consensus --> Anthropic
    Consensus --> OpenAI
    Consensus --> Gemini
    Consensus --> Ollama
    Anthropic --> AnthropicAPI
    OpenAI --> OpenAIAPI
    Gemini --> GeminiAPI
    Ollama --> OllamaServer
```

## ๐Ÿ“ Project Structure

```
quorum-mcp/
โ”œโ”€โ”€ src/quorum_mcp/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ server.py              # FastMCP server with q_in/q_out tools
โ”‚   โ”œโ”€โ”€ orchestrator.py        # Multi-provider orchestration engine
โ”‚   โ”œโ”€โ”€ session.py             # Session management and persistence
โ”‚   โ””โ”€โ”€ providers/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ base.py            # Abstract provider interface
โ”‚       โ”œโ”€โ”€ anthropic_provider.py  # Claude integration
โ”‚       โ”œโ”€โ”€ openai_provider.py     # OpenAI integration
โ”‚       โ”œโ”€โ”€ gemini_provider.py     # Gemini integration
โ”‚       โ””โ”€โ”€ ollama_provider.py     # Ollama local LLM integration
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ three_provider_demo.py  # Demo with cloud providers
โ”‚   โ”œโ”€โ”€ local_llm_demo.py       # Demo with Ollama (zero cost)
โ”‚   โ”œโ”€โ”€ end_to_end_demo.py      # All operational modes
โ”‚   โ””โ”€โ”€ session_demo.py         # Session management
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_session.py
โ”‚   โ”œโ”€โ”€ test_orchestrator.py
โ”‚   โ”œโ”€โ”€ test_anthropic_provider.py
โ”‚   โ”œโ”€โ”€ test_openai_provider.py
โ”‚   โ”œโ”€โ”€ test_gemini_provider.py
โ”‚   โ”œโ”€โ”€ test_ollama_provider.py
โ”‚   โ””โ”€โ”€ test_integration.py
โ”œโ”€โ”€ docs/
โ”‚   โ””โ”€โ”€ session_management.md
โ”œโ”€โ”€ .pre-commit-config.yaml     # Code quality hooks
โ”œโ”€โ”€ pyproject.toml              # Project configuration
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ worklog.md                  # Complete development history
```

## ๐Ÿงช Development

### Running Tests

```bash
# Run all tests
pytest

# Run with coverage
pytest --cov=quorum_mcp --cov-report=html

# Run specific test file
pytest tests/test_gemini_provider.py -v

# Run only fast tests
pytest -m "not slow"
```

### Code Quality

The project uses pre-commit hooks for code quality:

```bash
# Install pre-commit hooks
pre-commit install

# Run manually
pre-commit run --all-files

# Individual tools
black src/ tests/           # Format code
ruff check src/ tests/      # Lint code
mypy src/                   # Type check
```

### Adding a New Provider

1. Create a new provider class inheriting from `Provider`
2. Implement required methods:
   - `send_request(request: ProviderRequest) -> ProviderResponse`
   - `count_tokens(text: str) -> int`
   - `get_cost(tokens_input: int, tokens_output: int) -> float`
   - `get_provider_name() -> str`
   - `get_model_info() -> dict`
3. Add comprehensive tests
4. Update `providers/__init__.py`
5. Add to `server.py` initialization

See `gemini_provider.py` as a reference implementation.

## ๐Ÿ“Š Test Coverage

```
Module                          Coverage
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
providers/ollama_provider.py      95%
providers/gemini_provider.py      95%
providers/openai_provider.py      78%
session.py                        90%
providers/base.py                 67%
providers/anthropic_provider.py   56%
orchestrator.py                   45%
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Total                             32%
```

**Test Results:**
- โœ… 105 tests passing (76 + 29 new Ollama tests)
- โŒ 58 tests failing (testing unimplemented features)
- โš ๏ธ 16 errors (mock-related, non-critical)

## ๐Ÿ—บ๏ธ Roadmap

### โœ… Phase 1: MVP (Complete)
- [x] Provider abstraction layer
- [x] Anthropic Claude integration
- [x] OpenAI integration
- [x] Basic orchestration engine
- [x] Session management
- [x] FastMCP server with q_in/q_out
- [x] Cost tracking

### โœ… Phase 2: Testing (Complete)
- [x] Comprehensive unit tests
- [x] Provider test suites
- [x] Integration tests
- [x] Pre-commit hooks
- [x] Code quality tooling

### โœ… Phase 3: Google Gemini (Complete)
- [x] Gemini provider implementation
- [x] Token counting and cost tracking
- [x] 95% test coverage
- [x] Three-provider demo
- [x] Documentation updates

### โœ… Phase 4: Local LLMs (Complete)
- [x] Ollama provider integration
- [x] Support for Llama 3.2, Llama 3.1, Mistral, Mixtral, Qwen3, DeepSeek-R1, Gemma3
- [x] Zero-cost local inference ($0.00)
- [x] 100% privacy-preserving mode (data never leaves machine)
- [x] 95% test coverage (29 passing tests)
- [x] Local LLM demo and hybrid (local+cloud) demo
- [x] Automatic server detection and model availability checking

### ๐Ÿ”ฎ Phase 5: Advanced Features (Future)
- [ ] Additional local LLM providers (LM Studio, vLLM, text-generation-webui)
- [ ] OpenAI-compatible API provider (universal local LLM support)
- [ ] Mistral AI provider (cloud)
- [ ] Provider health monitoring
- [ ] Dynamic provider selection
- [ ] Caching layer
- [ ] Rate limiting
- [ ] Budget controls
- [ ] Performance benchmarking
- [ ] Web UI for result visualization

## ๐Ÿค Contributing

Contributions are welcome! Please:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Run tests (`pytest`)
5. Run code quality checks (`pre-commit run --all-files`)
6. Commit your changes (`git commit -m 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request

**Code Standards:**
- Black for formatting (100 char lines)
- Ruff for linting
- mypy for type checking
- pytest for testing (aim for 80%+ coverage)
- Comprehensive docstrings

## โ“ Troubleshooting

### API Key Issues

```bash
# Verify API keys are set
echo $ANTHROPIC_API_KEY
echo $OPENAI_API_KEY
echo $GOOGLE_API_KEY

# Test individual provider
python -c "from quorum_mcp.providers import GeminiProvider; print(GeminiProvider())"
```

### Import Errors

```bash
# Reinstall in development mode
pip install -e .

# Or reinstall with dependencies
pip install -e ".[dev]" --force-reinstall
```

### Test Failures

```bash
# Clear pytest cache
rm -rf .pytest_cache __pycache__

# Run with verbose output
pytest -vv --tb=short
```

## ๐Ÿ“„ License

MIT License - see [LICENSE](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- Built on the [Model Context Protocol](https://modelcontextprotocol.io/)
- Powered by [FastMCP](https://github.com/jlowin/fastmcp)
- Utilizes:
  - [Anthropic Claude](https://www.anthropic.com/)
  - [OpenAI](https://openai.com/)
  - [Google Gemini](https://deepmind.google/technologies/gemini/)

## ๐Ÿ“ฌ Contact

- GitHub: [@aj-geddes](https://github.com/aj-geddes)
- Issues: [GitHub Issues](https://github.com/aj-geddes/quorum-mcp/issues)

---

**Built with โค๏ธ for better AI through collaboration**