mcp-server-motherduck
OfficialServer Configuration
Describes the environment variables required to run the server.
| Name | Required | Description | Default |
|---|---|---|---|
| HOME | No | Your home folder path (needed by DuckDB) | |
| motherduck_token | No | Your MotherDuck access token for authenticating to MotherDuck |
Instructions
Guidance the server publishes about itself, which clients place ahead of the tool catalog so the model reads it before choosing anything.
Server Configuration
Database: In-memory (data will not persist after session ends)
Access mode: Read-write - all SQL operations are allowed
Available tools: execute_query, list_databases, list_tables, list_columns, switch_database_connection
Important Implications
Data created in this session will be lost when the session ends
To persist data, use ATTACH and COPY FROM DATABASE (see 'Persisting In-Memory Data to File' below)
You can switch to different databases using switch_database_connection
To create a new database file, use create_if_not_exists=True (only in read-write mode)
Execute SQL queries against DuckDB and MotherDuck databases using DuckDB SQL syntax.
Available Tools
execute_query: Execute SQL queries (DuckDB SQL dialect)list_databases: List all available databaseslist_tables: List tables and views in a databaselist_columns: List columns of a table or view
DuckDB SQL Quick Reference
Name Qualification
Format:
database.schema.tableor justschema.tableortableDefault schema is
main:db.table=db.main.tableUse fully qualified names when joining tables across different databases
Identifiers and Literals:
Use double quotes (
") for identifiers with spaces/special characters or case-sensitivityUse single quotes (
') for string literals
Flexible Query Structure:
Queries can start with
FROM:FROM my_table WHERE condition;SELECTwithoutFROMfor expressions:SELECT 1 + 1 AS result;Support for
CREATE TABLE AS(CTAS):CREATE TABLE new_table AS SELECT * FROM old_table;
Advanced Column Selection:
Exclude columns:
SELECT * EXCLUDE (sensitive_data) FROM users;Replace columns:
SELECT * REPLACE (UPPER(name) AS name) FROM users;Pattern matching:
SELECT COLUMNS('sales_.*') FROM sales_data;
Grouping and Ordering Shortcuts:
Group by all non-aggregated columns:
SELECT category, SUM(sales) FROM sales_data GROUP BY ALL;Order by all columns:
SELECT * FROM my_table ORDER BY ALL;
Complex Data Types:
Lists:
SELECT [1, 2, 3] AS my_list;Structs:
SELECT {'a': 1, 'b': 'text'} AS my_struct;Maps:
SELECT MAP([1,2],['one','two']) AS my_map;JSON:
json_col->>'key'(returns text) ordata->'$.user.id'(returns JSON)
Date/Time Operations:
String to timestamp:
strptime('2023-07-23', '%Y-%m-%d')::TIMESTAMPFormat timestamp:
strftime(NOW(), '%Y-%m-%d')Extract parts:
EXTRACT(YEAR FROM DATE '2023-07-23')
Schema Exploration
-- List all databases
SELECT database_name, type FROM duckdb_databases();
-- For MotherDuck: List all databases (including shared)
SELECT alias as database_name, type FROM MD_ALL_DATABASES();
-- List tables in a database
SELECT schema_name, table_name FROM duckdb_tables()
WHERE database_name = 'your_db';
-- Get column info
SELECT column_name, data_type FROM duckdb_columns()
WHERE database_name = 'your_db' AND table_name = 'your_table';
-- Quick preview with statistics
SUMMARIZE your_table;Query Best Practices
Filter early to reduce data volume before blocking operations
Use CTEs to break complex queries into manageable parts
Avoid unnecessary
ORDER BYon intermediate resultsUse
arg_max()andarg_min()for "most recent" queriesUse
QUALIFYfor filtering window function results
-- Get top 2 products by sales in each category
SELECT category, product_name, sales_amount
FROM products
QUALIFY ROW_NUMBER() OVER (PARTITION BY category ORDER BY sales_amount DESC) <= 2;Persisting In-Memory Data to File
To save an in-memory database to a persistent file:
-- Attach a new file-based database
ATTACH '/path/to/my_database.db' AS my_db;
-- Copy all data from memory to the file
COPY FROM DATABASE memory TO my_db;
-- Optionally detach when done
DETACH my_db;Capabilities
Features and capabilities supported by this server
Protocol revision2025-11-25
| Capability | Details |
|---|---|
| tools | {
"listChanged": true
} |
| logging | {} |
| prompts | {
"listChanged": false
} |
| resources | {
"subscribe": false,
"listChanged": false
} |
Tools
Functions exposed to the LLM to take actions
| Name | Description |
|---|---|
| execute_queryA | Execute a SQL query on the DuckDB or MotherDuck database. Unqualified table names resolve to current_database() and current_schema() automatically. Fully qualified names (database.schema.table) are only needed when multiple DuckDB databases are attached or when connected to MotherDuck. |
| list_databasesA | List all databases available in the connection. Useful when multiple DuckDB databases are attached or when connected to MotherDuck. |
| list_tablesB | List all tables and views in a database with their comments. If database is not specified, uses the current database. |
| list_columnsA | List all columns of a table or view with their types and comments. If database/schema are not specified, uses the current database/schema. |
| switch_database_connectionA | Switch to a different database connection. For local files, use absolute paths only. The new connection respects the server's read-only/read-write mode. For local files, the file must exist unless create_if_not_exists=True (requires read-write mode). |
Prompts
Interactive templates invoked by user choice
| Name | Description |
|---|---|
No prompts | |
Resources
Contextual data attached and managed by the client
| Name | Description |
|---|---|
No resources | |
TDQS
Scored across 5 tools
Each tool has a clearly distinct purpose: execute_query runs SQL, list_databases/tables/columns return metadata, switch_database_connection manages connections. Overlap is minimal because the listing tools target different entity levels (databases, tables, columns).
All tools use a consistent verb_noun snake_case pattern: execute_query, list_databases, list_tables, list_columns, switch_database_connection. The naming is predictable and readable.
Five tools is well-scoped for a database interface: one query executor, three metadata listers, and one connection switcher. No obvious missing core operations given the server's purpose.
The surface covers querying, schema exploration, and connection management. However, it lacks tools for database writing/DDL (e.g., create table, insert) or connection closing, which might be needed for full lifecycle management.