DuckLake-MCP
README.md
# DuckLake-MCP: 100% Offline Embedded Analytics & Parquet Lakehouse MCP Server
[](https://www.python.org/downloads/)
[](https://duckdb.org/)
[](https://opensource.org/licenses/Apache-2.0)
[-purple.svg)]()
[]()
> **Architect & Author:** Chethan Raj D S (`chethanraj.d.s@gmail.com`)
> **Credentials:** IIT Delhi Executive CTO Alumnus · B.E. Electrical & Electronics Engineering (85.60%)
> **Engineering Focus:** High-Performance Vectorized Systems · In-Process Analytics · Embedded Storage Engines · Zero-Trust Architectures
---
## 1. Executive Architectural Overview
**DuckLake-MCP** is an open-source, 100% offline **Model Context Protocol (MCP)** server powered by in-process **DuckDB**. It arms AI coding agents (**Claude Code**, **Cursor**, **Windsurf**, **GitHub Copilot**, **Antigravity**) with zero-copy vectorized SQL analytics directly over local **Parquet**, **CSV**, **JSON/NDJSON**, and **SQLite** files.
### The Problem It Solves
When developers ask AI coding agents to analyze local log files, data exports, or benchmark results, agents typically:
1. **Blow Up Context Windows:** Attempting to read multi-megabyte CSVs or logs directly into prompt context, burning tokens and crashing sessions.
2. **Write Fragile Custom Scripts:** Generating unvetted Pandas or Python scripts that fail on dirty schemas or run out of memory.
3. **Depend on Cloud Infrastructure:** Requiring developers to upload proprietary data to Snowflake, BigQuery, or run heavy external Postgres containers.
**DuckLake-MCP executes vectorized SQL in milliseconds directly on local files with zero server daemons, zero external API keys, and zero cloud egress.**
```
┌─────────────────────────────────────────┐
│ AI Coding Agent (Claude Code/Cursor) │
└────────────────────┬────────────────────┘
│
JSON-RPC 2.0 over Stdio
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ DuckLake MCP Server Engine │
├───────────────────────────────┬─────────────────────────────────────────────┤
│ Vectorized SQL Executor │ Sub-50ms Statistical Profiler │
│ • Direct File-System SQL │ • Null Count & Percentage │
│ • Multi-threaded Engine │ • Distinct Cardinality Audit │
│ • Token-Budgeting Guards │ • Numerical Quartiles (p25, p50, p99) │
│ • In-Memory Lakehouse Views │ • Schema Type Introspection │
└───────────────┬───────────────┴──────────────────────┬──────────────────────┘
│ │
▼ ▼
[ Local Parquet Files ] [ Local CSV / JSON ]
(Columnar Zero-Copy) (Auto-Detected Schemas)
```
---
## 2. Flagship Offline MCP Tools
### 1. `ducklake_query_sql` (Vectorized Direct-File SQL)
* **What it does:** Executes high-speed SQL queries directly against local files (`SELECT * FROM 'logs/*.parquet' WHERE status = 500 LIMIT 20;`).
* **Token-Budget Protection:** Bounds result sets by default (`max_rows=50`) and truncates large text cells to protect the agent's context window.
### 2. `ducklake_profile_dataset` (Sub-50ms Statistical Intelligence)
* **What it does:** Returns instant dataset intelligence without loading rows into context. Computes row counts, null percentages, distinct values, min/max, and numerical quartiles (p25, median p50, p75, p99) in under 50ms.
### 3. `ducklake_discover_files` (Workspace Dataset Scanner)
* **What it does:** Recursively scans directories to discover all analyzable `.parquet`, `.csv`, `.json`, `.ndjson`, and `.sqlite` files, returning sizes, formats, and modification timestamps.
### 4. `ducklake_convert_to_parquet` (Columnar Optimization Engine)
* **What it does:** Converts large, uncompressed CSV or JSON files into compressed, columnar Parquet files with Snappy/ZSTD compression, achieving 5x-10x storage reduction and 20x query acceleration.
### 5. `ducklake_create_datamart_view` (Virtual Lakehouse Views)
* **What it does:** Registers reusable named SQL views over multi-file glob patterns (e.g., `CREATE VIEW sales AS SELECT * FROM 'data/sales_*.parquet'`).
---
## 3. Installation & IDE Integration
### Option A: Cursor IDE (`.cursor/mcp.json`)
```json
{
"mcpServers": {
"ducklake": {
"command": "python",
"args": ["-m", "ducklake.mcp.server"],
"cwd": "/path/to/target/project"
}
}
}
```
### Option B: Claude Code CLI
```bash
claude mcp add ducklake -- python -m ducklake.mcp.server
```
### Option C: Claude Desktop (`claude_desktop_config.json`)
```json
{
"mcpServers": {
"ducklake": {
"command": "python",
"args": ["-m", "ducklake.mcp.server"],
"cwd": "/absolute/path/to/ducklake-mcp"
}
}
}
```
---
## 4. Standalone CLI Usage
DuckLake can also be invoked as a fast command-line data utility:
```bash
# Query local files directly
python -m ducklake.cli query "SELECT * FROM 'data/tx.parquet' LIMIT 5;"
# Profile dataset distributions in sub-50ms
python -m ducklake.cli profile data/tx.parquet
# Convert CSV to Parquet
python -m ducklake.cli convert data/export.csv --target data/export.parquet
# Discover queryable files in directory
python -m ducklake.cli discover data/
```
---
## 5. Verification & Test Suite
The test suite runs 100% offline with zero external network access:
```bash
# Clone the repository
git clone https://github.com/Chethan-Raj-D-S/ducklake-mcp.git
cd ducklake-mcp
# Run full test suite
pytest tests/ -v
```
**Verification Results:**
```text
tests/test_engine.py::test_query_direct_csv PASSED [ 7%]
tests/test_engine.py::test_query_direct_parquet PASSED [ 15%]
tests/test_engine.py::test_query_token_bounding_truncation PASSED [ 23%]
tests/test_engine.py::test_discover_datasets PASSED [ 30%]
tests/test_engine.py::test_convert_to_parquet PASSED [ 38%]
tests/test_engine.py::test_create_datamart_view PASSED [ 46%]
tests/test_mcp_server.py::test_mcp_initialize PASSED [ 53%]
tests/test_mcp_server.py::test_mcp_tools_list PASSED [ 61%]
tests/test_mcp_server.py::test_mcp_call_query_sql PASSED [ 69%]
tests/test_mcp_server.py::test_mcp_call_profile_dataset PASSED [ 76%]
tests/test_mcp_server.py::test_mcp_call_unknown_tool PASSED [ 84%]
tests/test_profiler.py::test_profile_csv_dataset PASSED [ 92%]
tests/test_profiler.py::test_profile_parquet_dataset PASSED [100%]
============================= 13 passed in 2.70s ==============================
```
---
## 6. Directory Structure
```
ducklake-mcp/
├── pyproject.toml # Modern package spec & dependencies
├── README.md # Architectural documentation
├── SKILL.md # AI Agent instruction specification
├── LICENSE # Apache 2.0 open-source license
├── ducklake/
│ ├── __init__.py # Package exports
│ ├── cli.py # Standalone CLI entrypoint
│ ├── core/
│ │ ├── __init__.py
│ │ ├── engine.py # DuckDB vectorized SQL execution engine
│ │ ├── profiler.py # Sub-50ms dataset statistical profiler
│ │ └── models.py # Pydantic schemas for query results & profiles
│ └── mcp/
│ ├── __init__.py
│ ├── protocol.py # MCP protocol schemas
│ └── server.py # JSON-RPC 2.0 stdio MCP server
└── tests/
├── conftest.py # Mock CSV, Parquet, and JSON fixtures
├── test_engine.py # Vectorized query & conversion tests
├── test_profiler.py # Statistical profiling tests
└── test_mcp_server.py # JSON-RPC stdio protocol tests
```
---
## 7. License
Licensed under the Apache License, Version 2.0.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues