Metadata-Version: 2.4
Name: ensemble-mcp
Version: 0.1.0b4
Summary: MCP server providing vector memory, drift detection, model routing, skills discovery, session management, and codebase indexing for AI-assisted development pipelines.
Project-URL: Homepage, https://github.com/LynkByte/ensemble
Project-URL: Repository, https://github.com/LynkByte/ensemble
Project-URL: Documentation, https://github.com/LynkByte/ensemble/tree/main/docs
Project-URL: Issues, https://github.com/LynkByte/ensemble/issues
Project-URL: Changelog, https://github.com/LynkByte/ensemble/blob/main/CHANGELOG.md
Author-email: Sanjaya De Silva <sanjaya@example.com>
License: MIT License
        
        Copyright (c) 2026 Sanjaya De Silva
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: agent,ai,codebase-indexing,drift-detection,embeddings,mcp,model-routing,onnx,orchestration,vector-memory
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: aiohttp>=3.9
Requires-Dist: mcp>=1.0
Requires-Dist: numpy>=2.4.4
Requires-Dist: onnxruntime>=1.17
Requires-Dist: rich>=15.0.0
Requires-Dist: tokenizers>=0.15
Provides-Extra: dev
Requires-Dist: build>=1.0; extra == 'dev'
Requires-Dist: mypy>=1.20.1; extra == 'dev'
Requires-Dist: pytest-aiohttp>=1.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=1.3.0; extra == 'dev'
Requires-Dist: pytest-cov>=7.1.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Description-Content-Type: text/markdown

# ensemble-mcp

A Python MCP (Model Context Protocol) server that provides **vector memory**, **drift detection**, **model routing**, **skills discovery**, **session management**, **codebase indexing**, and **context compression** for AI-assisted development pipelines.

All intelligence is local — zero LLM/API calls. Uses ONNX Runtime embeddings (~5ms), numpy cosine similarity, and SQLite storage.

---

## Features

| Feature | What It Does |
|---------|-------------|
| **Pattern Memory** | Semantic vector search over stored pipeline patterns (MiniLM-L6-v2, 384-dim) |
| **Drift Detection** | Cosine similarity between task description and code changes |
| **Model Routing** | Recommend model tier (best/mid/cheapest) per agent and task complexity |
| **Skills Discovery** | Scan `.ai/skills/`, `.claude/skills/`, `.cursor/rules/` etc. with semantic search |
| **Skill Intelligence** | Auto-detect recurring patterns and suggest converting them to reusable skills |
| **Session Management** | Pipeline checkpoint save/load with optimistic versioning |
| **Codebase Indexing** | File-level index with exports, imports, roles — incremental via mtime |
| **Context Compression** | Compress verbose text into token-efficient form, rule-based |
| **Prompt Caching** | Order and prepare prompt sections for optimal LLM cache hit rates |
| **Codebase Snapshots** | Generate compact project baseline summaries from the codebase index |
| **Auto-Installer** | Detect AI tools and register the MCP server in their configs |
| **Web Dashboard** | Local browser UI at `localhost:8787` for visualizing patterns, skills, projects, drift, and sessions |

## Quick Start

### Install from source

```bash
git clone https://github.com/LynkByte/ensemble.git
cd ensemble
pip install -e ".[dev]"
```

### Install via uvx (after PyPI publish)

```bash
uvx ensemble-mcp
```

### Run the server

```bash
# Start the MCP server (stdio protocol)
ensemble-mcp

# Or explicitly
ensemble-mcp serve
```

### Other CLI commands

```bash
# Auto-detect AI tools and register the MCP server
ensemble-mcp install

# Remove MCP server registration from AI tool configs
ensemble-mcp uninstall

# Copy agent files to a project (no MCP registration needed)
ensemble-mcp add-agents --tools opencode

# Copy skill files to a project (no MCP registration needed)
ensemble-mcp add-skills --tools opencode
```

### Web Dashboard

A local-only browser dashboard for visualizing patterns, skills, projects, drift history, and sessions.

```bash
# Start the dashboard (opens browser to http://localhost:8787)
ensemble-mcp web

# Custom port
ensemble-mcp web --port 9000

# Start without auto-opening the browser
ensemble-mcp web --no-open

# Specify a reports directory (auto-detected from ./reports or git root otherwise)
ensemble-mcp web --reports-dir /path/to/reports
```

The dashboard reads directly from the same SQLite database the MCP server writes to (WAL mode, no contention). It binds to `127.0.0.1` only — never exposed to the network, no authentication needed.

#### Dashboard Pages

| Page | What It Shows |
|------|--------------|
| **Overview** | Summary cards (patterns, skills, projects, drift checks), drift score trend chart, recent activity |
| **Patterns** | All stored patterns with match counts, project filtering, search |
| **Skills** | Pending skill suggestions with confidence scores, stale skill detection |
| **Projects** | Indexed projects with language breakdown pie charts, file role bar charts, export counts |
| **Drift** | Drift check history with scores, verdicts, flagged files, project filtering |
| **Sessions** | Session list with lifecycle status, click-through to step-by-step detail |

#### API Endpoints

All endpoints return the standard `ok/data/error/meta` envelope:

| Endpoint | Description |
|----------|-------------|
| `GET /api/summary` | Aggregate counts and recent activity |
| `GET /api/patterns` | Paginated pattern list (filter by `project`) |
| `GET /api/patterns/:id` | Single pattern detail with embedding metadata |
| `GET /api/skills` | Skill suggestions (filter by `project`, `status`) |
| `GET /api/skills/stale` | Skills not matched within threshold days |
| `GET /api/projects` | Indexed projects with file/export counts |
| `GET /api/projects/:path` | Project detail with language and role breakdown |
| `GET /api/drift` | Drift history (filter by `project`, `from`, `to`) |
| `GET /api/sessions` | Paginated session list (filter by `project`, `status`) |
| `GET /api/sessions/:id` | Session detail with steps |
| `GET /api/health` | Server health, version, DB size |

## MCP Client Configuration

### OpenCode

Add to `~/.config/opencode/config.json` or project `config.json`:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "ensemble": {
      "type": "local",
      "command": ["uvx", "ensemble-mcp"]
    }
  }
}
```

Or for a local development install:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "ensemble": {
      "type": "local",
      "command": ["/path/to/venv/bin/ensemble-mcp"]
    }
  }
}
```

### Claude Code

Add to `~/.claude/claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "ensemble": {
      "command": "uvx",
      "args": ["ensemble-mcp"]
    }
  }
}
```

### GitHub Copilot (VS Code)

Add to `.vscode/mcp.json`:

```json
{
  "servers": {
    "ensemble": {
      "command": "uvx",
      "args": ["ensemble-mcp"]
    }
  }
}
```

### Cursor

Add to `~/.cursor/mcp.json`:

```json
{
  "mcpServers": {
    "ensemble": {
      "command": "uvx",
      "args": ["ensemble-mcp"]
    }
  }
}
```

### Windsurf

Add to `~/.windsurf/mcp.json`:

```json
{
  "mcpServers": {
    "ensemble": {
      "command": "uvx",
      "args": ["ensemble-mcp"]
    }
  }
}
```

### Auto-Install

Instead of manual configuration, run the installer to auto-detect installed AI tools and register the server:

```bash
# Detect tools and register (interactive)
ensemble-mcp install

# Register specific tools only
ensemble-mcp install --tools opencode,cursor

# Preview without making changes
ensemble-mcp install --dry-run

# Non-interactive
ensemble-mcp install --yes
```

The installer automatically detects how `ensemble-mcp` is available on your system and registers the appropriate command:

| Priority | Detection | Registered Command |
|----------|-----------|-------------------|
| 1st | `ensemble-mcp` on PATH (pip/pipx install) | `ensemble-mcp` |
| 2nd | `uvx` on PATH | `uvx ensemble-mcp` |
| 3rd | Neither found | `/path/to/python -m ensemble_mcp` (current interpreter) |

## 19 MCP Tools

### Patterns (semantic memory)

| Tool | Description |
|------|-------------|
| `patterns_search` | Semantic search over stored patterns |
| `patterns_store` | Store a new pattern with embedding |
| `patterns_prune` | Remove old/unused patterns |

### Drift Detection

| Tool | Description |
|------|-------------|
| `drift_check` | Cosine similarity between task and changes (0-1 score) |

### Model Routing

| Tool | Description |
|------|-------------|
| `model_recommend` | Recommend model tier for agent + task complexity |

### Skills

| Tool | Description |
|------|-------------|
| `skills_discover` | Scan skill directories with optional semantic search |
| `skills_suggest` | Detect recurring patterns, propose as reusable skills |
| `skills_generate` | Accept, dismiss, or defer a skill suggestion |

### Session

| Tool | Description |
|------|-------------|
| `session_save` | Save pipeline checkpoint with optimistic versioning |
| `session_load` | Load latest or specific checkpoint |
| `session_search` | Search sessions by semantic similarity |

### Codebase Indexer

| Tool | Description |
|------|-------------|
| `project_index` | Build/refresh file-level codebase index |
| `project_query` | Query index by language, path, or text |
| `project_dependencies` | Get import/dependency graph for a file |
| `project_snapshot` | Generate compact project baseline summary (cached) |

### Context Compression

| Tool | Description |
|------|-------------|
| `context_compress` | Compress verbose text into terse, token-efficient form while preserving technical content |
| `context_prepare` | Order prompt sections for optimal LLM cache hit rates (static → project → task) |

### Utility

| Tool | Description |
|------|-------------|
| `health` | Server health check |
| `reset` | Reset all data (destructive, requires confirmation) |

## Response Envelope

Every tool returns a standardized envelope:

```json
{
  "ok": true,
  "data": { "matches": [...] },
  "error": null,
  "meta": {
    "duration_ms": 12,
    "source": "sqlite",
    "confidence": "exact"
  }
}
```

Confidence indicators: `exact` (direct data), `partial` (mixed sources), `estimated` (heuristic).

## Architecture

```
ensemble-mcp/
  src/ensemble_mcp/
    server.py             # MCP server + tool registration
    config/               # Settings, defaults
    contracts/            # Response envelope, error taxonomy
    memory/               # ONNX embeddings, SQLite vector store, cosine similarity
    security/             # Secret redaction, trust boundaries
    state/                # Session/step lifecycle, idempotency, locks
    tools/                # 19 MCP tool implementations + call-recording utility
    installer/            # AI tool detection + MCP registration
    dashboard/            # Web dashboard (aiohttp server, JSON API, SPA frontend)
    compress/             # Rule-based text compression engine
    cli/                  # Startup banner
    data/                 # Bundled agent and skill files
```

### Technology Stack

| Component | Choice |
|-----------|--------|
| Language | Python 3.11+ |
| Distribution | `uvx` (zero-hassle cross-platform) |
| MCP Framework | `mcp` (official Python SDK) |
| Embeddings | ONNX Runtime + MiniLM-L6-v2 (~22MB, 384-dim) |
| Vector Storage | SQLite + numpy cosine similarity |
| Tokenizer | HuggingFace `tokenizers` (for MiniLM input) |
| Package Size | ~90MB (including ONNX + model) |

### Local Storage

| Path | Contents |
|------|----------|
| `~/.cache/ensemble-mcp/data.db` | SQLite database (WAL mode) |
| `~/.cache/ensemble-mcp/models/` | ONNX MiniLM-L6-v2 model (~22MB) |
| `~/.config/ensemble-mcp/config.toml` | Global user configuration |

## Configuration

Layered config with deterministic merge order:

1. Package defaults (built-in)
2. Global config (`~/.config/ensemble-mcp/config.toml`)
3. Project config (`.ensemble-mcp.toml`)
4. Environment variables (`ENSEMBLE_MCP_*`)

```toml
# ~/.config/ensemble-mcp/config.toml
drift_threshold_aligned = 0.25
default_top_k = 5
cluster_similarity_threshold = 0.8
```

## Development

```bash
# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
python -m pytest tests/ -v

# Lint
ruff check src/ tests/

# Format
ruff format src/ tests/

# Type check
mypy src/

# Build package
python -m build
```

### Docker

```bash
docker build -t ensemble-mcp .
docker run --rm -v ~/.cache/ensemble-mcp:/home/app/.cache/ensemble-mcp ensemble-mcp
```

## Eval Framework

Benchmark harness for measuring tool effectiveness:

```bash
# Run eval benchmarks
python evals/runner.py

# Or via pytest
python -m pytest evals/ -v
```

## Supported AI Tools

| AI Tool | Config Format | Auto-Install |
|---------|--------------|--------------|
| OpenCode | JSON | Yes |
| Claude Code | JSON | Yes |
| GitHub Copilot (VS Code) | JSON | Yes |
| Cursor | JSON | Yes |
| Windsurf | JSON | Yes |
| Devin CLI | JSON | Yes |

## License

[MIT](LICENSE)
