duckdb_analytics_mcp
Provides read-only SQL analytics on local CSV, Parquet, and JSON datasets using DuckDB, with pagination, security guardrails, and health monitoring.
README
DuckDB Analytics MCP
Read-only MCP server for querying local datasets (.csv, .parquet, .json, .jsonl) through DuckDB with explicit SQL guardrails, pagination, timeouts, and optional bearer-token auth.
What This Server Provides
- MCP transports:
stdioandstreamable-http - Tool responses in either
markdownorjson - Dataset catalog + schema resources
- Read-only SQL execution over a registered
sourcetable alias - Guardrails for query size, statement shape, and banned SQL keywords
- Optional auth with required scope enforcement
Supported Dataset Formats
Files are discovered recursively under DATASET_DIR.
.csv.parquet.json.jsonl
Setup
git clone https://github.com/pypi-ahmad/duckdb-analytics-mcp.git
cd duckdb-analytics-mcp
uv python pin 3.12.10
uv sync --dev
cp .env.example .env
Configuration
Runtime is configured through environment variables (loaded from .env by default).
| Variable | Default | Description |
|---|---|---|
SERVER_NAME |
duckdb_analytics_mcp |
MCP server name |
LOG_LEVEL |
INFO |
Log level (DEBUG/INFO/WARNING/ERROR/CRITICAL) |
HOST |
127.0.0.1 |
Bind host for HTTP transport |
PORT |
8000 |
Bind port for HTTP transport |
TRANSPORT |
streamable-http |
Default transport (stdio or streamable-http) |
DATASET_DIR |
data |
Dataset root; relative paths resolve from project root |
DEFAULT_LIMIT |
25 |
Default page size |
MAX_LIMIT |
200 |
Upper bound for list/query page size |
MAX_QUERY_CHARS |
4000 |
Max SQL length |
QUERY_TIMEOUT_SECONDS |
20 |
Timeout for describe/query operations |
MAX_SAMPLE_ROWS |
25 |
Max rows returned for dataset samples |
DUCKDB_THREADS |
4 |
DuckDB execution threads |
DUCKDB_MEMORY_LIMIT |
1GB |
DuckDB memory limit |
STATIC_BEARER_TOKEN |
unset | Enables token verification when auth URLs are also set |
AUTH_ISSUER_URL |
unset | Auth issuer URL (required with STATIC_BEARER_TOKEN) |
AUTH_RESOURCE_SERVER_URL |
unset | Resource server URL (required with STATIC_BEARER_TOKEN) |
AUTH_REQUIRED_SCOPE |
analytics.read |
Required access scope |
Auth note:
- If
STATIC_BEARER_TOKENis set, bothAUTH_ISSUER_URLandAUTH_RESOURCE_SERVER_URLmust also be set.
Run
Streamable HTTP
uv run duckdb-analytics-mcp run --transport streamable-http
Endpoint: http://127.0.0.1:8000/mcp
stdio
uv run duckdb-analytics-mcp run --transport stdio
MCP Client Integration
Generic stdio server config
{
"command": "uv",
"args": ["run", "duckdb-analytics-mcp", "run", "--transport", "stdio"],
"cwd": "/path/to/duckdb-analytics-mcp",
"env": {
"DATASET_DIR": "data"
}
}
Generic streamable-http config
Use base URL:
http://127.0.0.1:8000/mcp
Tool Reference
duckdb_analytics_health
Returns server and catalog health metadata.
Parameters:
response_format(markdownorjson, defaultmarkdown)
duckdb_analytics_list_datasets
Lists datasets with pagination.
Parameters:
limit(default25)offset(default0)response_format(markdownorjson, defaultmarkdown)
duckdb_analytics_describe_dataset
Returns dataset metadata, schema, row count, and sample rows.
Parameters:
dataset(relative catalog name, for examplesales/orders.csv)sample_rows(default10, bounded byMAX_SAMPLE_ROWS)response_format(markdownorjson, defaultmarkdown)
duckdb_analytics_query_dataset
Runs guarded read-only SQL against the dataset using the table alias source.
Parameters:
dataset(relative catalog name)sql(must start withSELECTorWITH)limit(default25, bounded byMAX_LIMIT)offset(default0)response_format(markdownorjson, defaultmarkdown)
Error Behavior
describe/queryreturn tool-level errors for invalid dataset names, SQL guard violations, and timeout conditions.- In
jsonmode, tool errors are returned as{ "error": "..." }. - In
markdownmode, tool errors are returned asError: ....
Resource Reference
dataset://catalog— full dataset catalogdataset://schema/{dataset_name}— schema + sample rows for one dataset
SQL Safety Model
duckdb_analytics_query_dataset enforces:
- single statement only
- no SQL comments (
--,/* ... */) - query must start with
SELECTorWITH - banned keywords (for example
INSERT,UPDATE,DELETE,DROP,ALTER,CREATE,PRAGMA,COPY,INSTALL,LOAD)
CLI Commands
uv run duckdb-analytics-mcp --help
uv run duckdb-analytics-mcp run --help
uv run duckdb-analytics-mcp doctor
doctor prints deployment-readiness JSON, including health and dataset counts.
Docker
docker build -t duckdb-analytics-mcp:latest .
docker run --rm -p 8000:8000 \
-e HOST=0.0.0.0 \
-e PORT=8000 \
-e TRANSPORT=streamable-http \
duckdb-analytics-mcp:latest
Or with compose:
docker compose up --build
Development Verification
uv run ruff check .
uv run mypy src
uv run pytest -q
Troubleshooting
Dataset '<name>' not found:- Run
duckdb_analytics_list_datasetsfirst and use an exact dataset name from catalog.
- Run
Operation timed out after ... seconds:- Simplify query, lower scan volume, or increase
QUERY_TIMEOUT_SECONDS.
- Simplify query, lower scan volume, or increase
- Empty catalog:
- Confirm files exist under
DATASET_DIRand use supported suffixes.
- Confirm files exist under
- Auth startup error:
- If
STATIC_BEARER_TOKENis set, also setAUTH_ISSUER_URLandAUTH_RESOURCE_SERVER_URL.
- If
Project Structure
src/duckdb_analytics_mcp/
cli.py
config.py
server.py
service.py
catalog.py
security.py
formatter.py
data/
tests/
notebooks/
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。