fusion
Enables LLMs to perform analytical SQL queries on PostgreSQL/MySQL databases via DuckDB, with tools for querying, aggregation, and materialized views.
README
Fusion
DuckDB-powered in-memory analytics engine with LLM tool support.
Fusion connects to PostgreSQL/MySQL databases via Warp REST API, loads data into DuckDB for fast columnar analytics, and exposes 10 tools for LLMs through MCP and OpenAI Function Calling.
Features
- 10 LLM Tools —
list_sources,describe_table,query_data,search_data,aggregate_data,create_view,list_views,refresh_view,load_table,cache_stats - Dual Format — Tool definitions in both MCP (Model Context Protocol) and OpenAI Function Calling format
- 3 Access Layers — MCP Server (stdio), REST API (FastAPI/HTTP), Python SDK
- Query Pushdown — Routes queries directly to source databases when possible, avoiding unnecessary data transfer
- Lazy Loading — Only fetches table data from sources when actually referenced in queries
- SQL Guardrails — Blocks destructive SQL (DROP, DELETE, INSERT) to protect data integrity
- LRU Cache — Query result caching with configurable TTL for millisecond response times
- Materialized Views — Pre-computed aggregation tables with scheduled auto-refresh
- Cross-Source Federation — JOIN across multiple databases (PostgreSQL + MySQL) in a single query
- Auto-Discovery — Automatically discovers all databases and tables from Warp
Architecture
┌─────────────────────────────────────────────────────────────────────────────┐
│ 1. Data Source Layer │
│ ┌──────────────┐ REST ┌─────────────────┐ │
│ │ PostgreSQL │ ──────────► │ │ │
│ │ MySQL │ │ WarpConnector │ auto-discovery │
│ └──────────────┘ │ (query pushdown) │ pagination, schema │
│ Warp REST API └────────┬────────┘ │
└────────────────────────────────────────┼──────────────────────────────────┘
│
┌─────────────────────────────────────────▼──────────────────────────────────┐
│ 2. DuckDB Core Layer │
│ ┌──────────────────────────────────────────────────────────────────────┐ │
│ │ OLAPEngine │ │
│ │ • DuckDB (in-memory, columnar) • QueryCache (LRU + TTL) │ │
│ │ • SchemaCatalog (multi-source) • MaterializedViewManager │ │
│ │ • FetchStrategy (lazy load) • SQLGuardrails (SELECT only) │ │
│ └──────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────┬──────────────────────────────────┘
│
┌─────────────────────────────────────────▼──────────────────────────────────┐
│ 3. LLM Tool Layer │
│ ┌─────────────┐ ┌──────────────────┐ ┌─────────────────┐ │
│ │ ToolExecutor│ │ 10 tools │ │ MCP / REST / SDK│ │
│ │ (dispatch) │─►│ query_data, etc. │─►│ → LLM → Result │ │
│ └─────────────┘ └──────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
Installation
pip install -e .
Optional dependencies:
pip install -e ".[mcp]" # MCP Server support
pip install -e ".[rest]" # REST API (FastAPI + uvicorn)
pip install -e ".[dev]" # Development (pytest, ruff, mypy)
pip install -e ".[all]" # Everything
Quick Start
Python SDK
from fusion import OLAPEngine
engine = OLAPEngine(memory_limit="4GB")
engine.connect_source("mydb", {
"type": "warp",
"base_url": "http://localhost:8000",
"database": "mydb",
})
executor = engine.get_tool_executor()
# Discover available data
sources = executor.list_sources()
# Run an analytical query (auto-loads referenced tables)
result = executor.query_data("SELECT * FROM mydb.orders LIMIT 10")
# Aggregate data
agg = executor.aggregate_data(
table="mydb.orders",
group_by="status",
agg_column="amount",
agg_func="SUM",
)
# Create a materialized view
executor.create_view(
name="daily_revenue",
sql="SELECT status, SUM(amount) as total FROM mydb.orders GROUP BY status",
refresh="hourly",
)
MCP Server (Claude Desktop / Cursor)
fusion-mcp --warp-url http://localhost:8000 --database mydb
Configure in claude_desktop_config.json:
{
"mcpServers": {
"fusion": {
"command": "fusion-mcp",
"args": ["--warp-url", "http://localhost:8000", "--database", "mydb"]
}
}
}
Auto-discover all databases:
fusion-mcp --warp-url http://localhost:8000 --auto-discover
REST API
fusion-rest --warp-url http://localhost:8000 --auto-discover --port 9000
Swagger UI at http://localhost:9000/docs. Key endpoints:
| Endpoint | Method | Description |
|---|---|---|
/sources |
GET | List connected sources and tables |
/tables/{source.table}/schema |
GET | Table schema details |
/query |
POST | Execute analytical SQL query |
/search |
POST | Filter search on a table |
/aggregate |
POST | GROUP BY aggregation |
/views |
GET/POST | List or create materialized views |
/views/{name}/refresh |
POST | Refresh a materialized view |
/tables/{source.table}/load |
POST | Explicitly load a table |
/cache/stats |
GET | Cache statistics |
/tools/{tool_name} |
POST | Generic tool dispatch |
OpenAI Function Calling
from fusion import get_openai_tools, OLAPEngine
engine = OLAPEngine()
engine.connect_source("mydb", {"type": "warp", "base_url": "http://localhost:8000"})
executor = engine.get_tool_executor()
# Get tool definitions for OpenAI Chat Completions API
tools = get_openai_tools()
# When the LLM makes a tool call:
result = executor.execute("query_data", {"sql": "SELECT ..."})
Tools
| Tool | Description |
|---|---|
list_sources |
Connected sources and tables with row counts |
describe_table |
Table schema (columns, types, row count) |
query_data |
Run analytical SQL on DuckDB (SELECT only, max 100 rows) |
search_data |
Filter search on a table (exact match or LIKE with %) |
aggregate_data |
GROUP BY aggregation (SUM, AVG, COUNT, MIN, MAX) |
create_view |
Create a materialized view from a SELECT query |
list_views |
List materialized views with refresh schedule |
refresh_view |
Manually refresh a materialized view |
load_table |
Explicitly load a table from source into DuckDB |
cache_stats |
Query cache hit rate, entry count, memory usage |
Warp Setup
Fusion uses Warp as its data source gateway:
git clone https://github.com/yasinyaman/warp.git
cd warp
docker compose up -d
Warp provides a REST API that federates access to PostgreSQL and MySQL databases.
Project Structure
fusion/
├── __init__.py # Public API exports
├── engine.py # OLAPEngine — main orchestration
├── cache.py # QueryCache (LRU + TTL)
├── catalog.py # SchemaCatalog — multi-source metadata
├── guardrails.py # SQLGuardrails — blocks destructive SQL
├── result.py # QueryResult — format conversions
├── strategy.py # FetchStrategy — smart table loading
├── exceptions.py # Custom exception hierarchy
├── connectors/
│ ├── base.py # BaseConnector (abstract)
│ └── warp.py # WarpConnector (Warp REST API)
├── tools/
│ ├── definitions.py # 10 tool schemas (OpenAI + MCP)
│ ├── executor.py # ToolExecutor — routes tool calls
│ ├── mcp_server.py # MCP Server (stdio transport)
│ └── rest_server.py # REST API Server (FastAPI)
└── views/
└── materialized.py # MaterializedViewManager
Development
pip install -e ".[all]"
pytest tests/ -v # 236 tests
ruff check fusion/ # Lint
python -m demo.demo # Demo with synthetic data
Requirements
- Python 3.10+
- DuckDB 1.2+
- Warp (data source gateway)
License
Apache 2.0 — see LICENSE for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。