Back to MCP Catalog

DuckDB MCP Server

DatabasesPython
Interact with DuckDB databases through SQL queries
Available Tools

query

Execute any SQL query on the DuckDB database

query

DuckDB MCP Server provides a seamless interface for interacting with DuckDB databases through the Model Context Protocol. It enables AI assistants to execute SQL queries, create tables, inspect schemas, and perform data analysis directly on DuckDB databases. With this server, you can leverage DuckDB's powerful analytical capabilities for local data processing without needing complex setup or infrastructure. The server supports both read-write and read-only modes, making it suitable for both data exploration and modification scenarios.

Overview

DuckDB MCP Server enables AI assistants to interact with DuckDB databases through SQL queries. DuckDB is an in-process analytical database system designed for local data analysis, making it perfect for working with CSV files, Parquet files, and other data sources without requiring a separate database server.

Installation

Prerequisites

  • Python 3.10 or higher
  • pip or uv package manager

Installing via pip

pip install mcp-server-duckdb

Installing via uv

uv pip install mcp-server-duckdb

Configuration

The server requires a path to a DuckDB database file and offers optional parameters for customizing behavior.

Required Parameters

  • db-path: Path to the DuckDB database file
    • The server will automatically create the database file and parent directories if they don't exist
    • If using read-only mode and the database doesn't exist, the server will fail to start

Optional Parameters

  • --readonly: Run server in read-only mode (default: false)

    • Prevents any write operations to the database
    • If the database file doesn't exist, it won't be created
    • Provides security by ensuring the database remains unaltered
  • --keep-connection: Re-use a single DuckDB connection (default: false)

    • Maintains one connection for the entire server lifetime
    • Enables TEMP objects and slightly faster queries
    • May hold an exclusive lock on the database file

Usage Examples

Basic Usage

To start the server with a new or existing database:

mcp-server-duckdb /path/to/your/database.db

Read-Only Mode

To start the server in read-only mode:

mcp-server-duckdb /path/to/your/database.db --readonly

With Connection Reuse

To start the server with a persistent connection:

mcp-server-duckdb /path/to/your/database.db --keep-connection

Working with the Database

Once the server is running, you can use the query tool to interact with the database. Here are some example operations:

  1. Create a table:

    CREATE TABLE users (id INTEGER, name VARCHAR, email VARCHAR);
    
  2. Insert data:

    INSERT INTO users VALUES (1, 'John Doe', 'john@example.com');
    
  3. Query data:

    SELECT * FROM users WHERE id = 1;
    
  4. Get schema information:

    PRAGMA table_info(users);
    
  5. Load data from CSV:

    CREATE TABLE data AS SELECT * FROM read_csv_auto('/path/to/file.csv');
    

The server will return query results as text, or success messages for operations like CREATE and INSERT.

Related MCPs

Milvus Vector Database
DatabasesPython

Connect to Milvus vector database for semantic search and vector operations

MotherDuck DuckDB
DatabasesPython

SQL analytics with DuckDB and MotherDuck for AI assistants

Alibaba Cloud Tablestore
DatabasesJava, Python

Connect to Alibaba Cloud Tablestore for vector search and RAG applications

About Model Context Protocol

Model Context Protocol (MCP) allows AI models to access external tools and services, extending their capabilities beyond their training data.

Generate Cursor Documentation

Save time on coding by generating custom documentation and prompts for Cursor IDE.