io.github.0xmortuex/duckdb-mcp
Points DuckDB at local data folders so an agent can run read-only SQL over CSV, Parquet, JSON and NDJSON files — listing files, describing columns and types, profiling columns (null %, distinct counts, min/max, common values), sampling rows, executing single SELECT queries with joins across files, and explaining query plans. Access is confined to allowed directories with external access and extension loading disabled, results are row-capped and time-limited.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@io.github.0xmortuex/duckdb-mcp List my data files and describe the largest one"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
duckdb-mcp
Let your AI agent run SQL over your local CSV, Parquet and JSON files, without giving it the keys to your disk.
duckdb-mcp is an MCP server that points DuckDB at the data files in folders you choose. The agent lists the files, looks at their columns, profiles them and runs SQL. It is built to be safe by default:
Read-only. One SELECT-type statement per call.
INSERT,CREATE,COPY,ATTACH,INSTALL/LOAD,EXPORT,SETandPRAGMAare rejected before they run.Confined to the folders you allow. DuckDB's own
allowed_directoriesis set, external access is switched off and the configuration is locked, soread_csv('C:/Windows/win.ini'),../traversal, junction/symlink escapes, URLs and extension downloads all fail. This is tested, not assumed.Bounded. Results stop at 1000 rows (with a clear TRUNCATED notice) and every query has a 30 second limit. Results are streamed, so
SELECT *on a million-row file returns instantly.Nothing to set up. DuckDB runs in memory inside the server process. No database file, no service, no network.
What it looks like
Real output from a stdio session against a small orders.csv:
> describe_file orders.csv
File: orders.csv (csv, 180 B)
Rows: 5 Columns: 5
| column | type |
| --- | --- |
| order_id | BIGINT |
| customer | VARCHAR |
| country | VARCHAR |
| amount | DOUBLE |
| placed_at | DATE |
> query "SELECT country, count(*) AS orders, round(sum(amount),2) AS revenue FROM 'orders.csv' GROUP BY 1 ORDER BY 3 DESC"
| country | orders | revenue |
| --- | --- | --- |
| US | 2 | 380.0 |
| UK | 2 | 135.75 |
| FI | 1 | NULL |
3 rows, 3 columns.
> query "SELECT * FROM read_csv('C:/Users/me/secret.csv')" (a file outside the allowed folders)
Error: Permission Error: Cannot access file "C:/Users/me/secret.csv" - file system operations are disabled by configuration
File access is limited to the allowed folders: C:/Users/me/data. Call list_files to see the queryable files.
> query "COPY (SELECT 1) TO 'x.csv'"
Error: COPY statements are blocked: this server is read-only. Allowed: SELECT / WITH / VALUES / FROM, DESCRIBE, SUMMARIZE, SHOW and EXPLAIN.Related MCP server: mcp-sql-analyst
Install
You need uv. Replace the path with the folder that holds your data.
Claude Code
claude mcp add duckdb -- uvx duckdb-mcp --dir "C:\Users\me\data"Claude Desktop (claude_desktop_config.json)
{
"mcpServers": {
"duckdb": {
"command": "uvx",
"args": ["duckdb-mcp", "--dir", "C:\\Users\\me\\data"]
}
}
}Or with pip: pip install duckdb-mcp, then run duckdb-mcp --dir PATH.
Choosing the folders
Option | Meaning |
| A folder whose data files may be queried. Repeat it for several folders. |
| Same thing as an environment variable, separated by |
(nothing) | The server's current working directory. |
| Row cap per result (default 1000). |
| Seconds a query may run (default 30). |
Subfolders are included. Files are named relative to their folder, or by absolute path.
Tools
Tool | What it does |
| Data files in the allowed folders, with type and size. Optional glob |
| Column names and types, the row count and sample rows of one file. |
| Per column: type, null %, approximate distinct count, min, max, average, median and the three most common values. |
| The first N rows, or a random sample. |
| One read-only SQL statement. Output as a markdown table (default), CSV or JSON. |
| The execution plan, optionally with run-time statistics ( |
Supported files: .csv, .tsv, .parquet, .json, .ndjson, .jsonl, and .gz of the text
formats. In SQL, name a file as FROM 'sales.csv', read_csv('sales.csv'),
read_parquet('2024/*.parquet') or read_json_auto('events.ndjson'). Joins across files work:
SELECT * FROM 'a.csv' JOIN 'b.parquet' USING (id).
Excel (.xlsx) is not supported: DuckDB's Excel reader is an extension that has to be downloaded,
and this server deliberately turns extension loading off. Export the sheet to CSV first.
Try asking
"What data files do I have? Describe the biggest one."
"Profile
orders.csvand tell me which columns have data quality problems.""Which five customers spent the most last quarter?"
"Join
users.parquetwithevents.ndjsonand show daily active users for March.""Is the
statuscolumn ever empty? How many distinct values does it have?""Explain why this query is slow" (it will use
explain_query).
Security
What is enforced, and by what:
Threat | Defence |
Reading files outside the allowed folders ( | DuckDB |
Network access ( |
|
Undoing the above from SQL | The statement gate rejects |
Writing files ( | DuckDB still allows writes inside allowed folders, so the statement gate only accepts one SELECT-type statement, and an |
Changing or creating objects ( | Same gate. |
A runaway query | Interrupted after |
Flooding the model's context | Row cap, and cells longer than 200 characters are shortened. |
What it does not do:
It cannot stop a query from using CPU and memory up to the time limit (DuckDB's memory spill goes to a private temp folder).
An allowed folder is readable in full. Do not allow a folder that holds secrets.
For convenience, a quoted literal that names an existing data file in an allowed folder is replaced by that file's full path before the query runs. So
WHERE name = 'orders.csv'compares against the full path whenorders.csvexists. If you need the plain text, build it:'orders' || '.csv'. Reads are always enforced by DuckDB, whatever the rewrite does.There are no per-user accounts; whoever can talk to the server can query the allowed folders.
Development
uv sync --extra test
uv run ruff check src tests && uv run mypy --strict src
uv run pytest testsTests use real files and real DuckDB: the sandbox suite attempts the escapes listed above, a 1,000,000-row CSV/Parquet test checks streaming and the row cap (and measures peak memory in a child process), and a stdio test launches the installed server and talks MCP to it.
Want to know how it works? duckdb-mcp-the-hard-way builds a minimal version step by step.
License
MIT
Available Tools
6 toolsdescribe_fileA
Show a file's schema (column names and types), its row count and a few sample rows.
path is relative to an allowed folder (as list_files shows it) or absolute inside
one. Column types are DuckDB's auto-detected types, which is what SQL will see. The
row count of a CSV/JSON file needs a full scan; Parquet answers from metadata.
Use this before writing a query, to get exact column names.
Inputs: path (required), sample_rows. Returns: result
explain_queryA
Show DuckDB's execution plan for a SELECT query without returning its rows.
Useful to check whether a filter is pushed down into a Parquet scan, or why a query is
slow. With analyze=true the query is actually executed and per-operator timings and
row counts are included (still read-only, still time-limited). Same SQL rules and file
naming as query.
Inputs: sql (required), analyze. Returns: result
list_filesA
List the data files you can query (CSV, TSV, Parquet, JSON, NDJSON, optionally .gz).
Shows each file's path relative to its allowed folder, its type and size. Use this
first: those paths can be used directly in SQL, e.g. SELECT * FROM 'sales.csv'.
Optional pattern is a case-insensitive glob on the path, e.g. '2024' or 'logs/*.json'.
At most 500 files are shown.
Inputs: pattern. Returns: result
profile_fileA
Profile each column of a file in one pass: type, null %, approximate distinct count, min, max, average, median and the three most common values.
Use it to spot data-quality problems (many nulls, constant columns, odd ranges)
before analysing. columns limits it to named columns; otherwise the first 50
columns are profiled. On a very large file this scans everything and can hit the
time limit - then profile fewer columns.
Inputs: path (required), columns. Returns: result
queryA
Run one read-only SQL statement (DuckDB dialect) over the data files.
Reference files by name: SELECT * FROM 'sales.csv', or read_csv('sales.csv'), read_parquet('dir/*.parquet'), read_json_auto('events.ndjson'). Paths are relative to the allowed folders (see list_files) or absolute inside them. Allowed: SELECT, WITH, VALUES, FROM-first queries, DESCRIBE, SUMMARIZE, SHOW and EXPLAIN. Anything that writes or reaches outside the allowed folders (INSERT, CREATE, COPY, ATTACH, INSTALL, SET, PRAGMA, files elsewhere on disk, URLs) is rejected.
Output is a markdown table by default; format='csv' or 'json' is more compact for big results. Results stop at the server's row cap (default 1000) with a TRUNCATED notice; pass a smaller max_rows to see less. Queries have a time limit. Prefer aggregation (GROUP BY, COUNT, SUM) over fetching raw rows. Use describe_file first for column names.
Inputs: sql (required), format, max_rows. Returns: result
sample_fileA
Show a few rows of a file: the first rows (mode='head') or a random sample
(mode='random', scans the whole file). Cheaper than describe_file when you only
want to see the data. rows is 1 to 100.
Inputs: path (required), mode, rows. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a distinct role: list_files (discovery), describe_file (schema), profile_file (column statistics), sample_file (row preview), query (SQL), explain_query (plan). The main overlap is that describe_file also returns sample rows and profile_file touches type metadata, but descriptions draw clear boundaries (cheaper sampling, stats vs. schema).
Five of six names follow a clean verb_noun pattern (list_files, describe_file, profile_file, sample_file, explain_query). The bare 'query' is the sole deviation but is unambiguous in context.
Six tools is well-scoped for a read-only DuckDB query server, each mapping to a distinct step in the analysis workflow. Nothing feels padded or missing.
The read-only analytical lifecycle is fully covered: discover files, inspect schema, sample rows, profile columns, run SQL, and explain plans. No write operations exist, consistent with the explicit read-only design, so there are no dead ends.
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
The all-in-one data stack for agents. Upload files, run SQL, evolve tables, and render charts.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables MCP clients like Claude Desktop, Claude Code and Cursor to safely explore local CSV, Excel, Parquet and SQLite files by running guarded read-only DuckDB SQL over a sandboxed data directory. It also supports data profiling, chart generation as image content, and exporting query results, without ever allowing writes or access outside the configured folder.MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI assistants to explore and analyse local CSV, Parquet or JSON files through validated read-only SELECT queries, with schema discovery, profiling and query-plan tools. Results are capped, timed, PII-masked and audit-logged inside a locked DuckDB sandbox that cannot write, reach the network or read other files.MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to query SQLite databases and Excel/CSV files read-only, with PII masking, bounded row limits, query timeouts, and audit logging.1MIT
- AlicenseNot gradedqualityCmaintenanceEnables an AI agent to run read-only SQL over local CSV, Parquet, and JSON files through MCP tools, with directory sandboxing, statement gating, timeouts, and query timeouts that keep access confined to permitted folders. Results are shaped for small context windows with row caps, truncation notices, and markdown/CSV/JSON output.MIT