Skip to main content
Glama
boettiger-lab

DuckDB MCP Server

DuckDB MCP Server

An MCP server implementation that provides SQL analytics capabilities for local DuckDB databases to AI Assistants and IDEs.

Note: This project is based on the excellent mcp-server-motherduck implementation by MotherDuck. We've adapted it to focus on local DuckDB usage.

Features

  • Local database support: query data from local DuckDB databases or in-memory databases

  • Cloud storage integration: access data stored in Amazon S3 or other cloud storage

  • SQL analytics: use DuckDB's powerful SQL dialect to query data directly from your AI Assistant or IDE

  • Flexible connections: support for file-based, in-memory, and S3-backed databases

Related MCP server: motherduck-mcp

Components

Prompts

The server provides one prompt:

  • duckdb-initial-prompt: A prompt to initialize a connection to DuckDB and start working with it

Tools

The server offers one tool:

  • query: Execute a SQL query on the DuckDB database

    • Inputs:

      • query (string, required): The SQL query to execute

All interactions with DuckDB are done through writing SQL queries.

Result Limiting: Query results are automatically limited to prevent using up too much context:

  • Maximum 1024 rows by default (configurable with --max-rows)

  • Maximum 50,000 characters by default (configurable with --max-chars)

  • Truncated responses include a note about truncation

Command Line Parameters

The MCP server supports the following parameters:

Parameter

Type

Default

Description

--transport

Choice

stdio

Transport type. Options: stdio, sse, stream

--port

Integer

8000

Port to listen on for sse and stream transport mode

--host

String

127.0.0.1

Host to bind the MCP server for sse and stream transport mode

--db-path

String

:memory:

Path to local DuckDB database file or S3 URL (e.g., s3://bucket/path/to/db.duckdb). Use :memory: for in-memory database

--read-only

Flag

False

Flag for connecting to DuckDB in read-only mode. Uses short-lived connections to enable concurrent access

--home-dir

String

None

Home directory for DuckDB (uses HOME env var by default)

--json-response

Flag

False

Enable JSON responses for HTTP stream. Only supported for stream transport

--max-rows

Integer

1024

Maximum number of rows to return from queries.

--max-chars

Integer

50000

Maximum number of characters in query results.

--query-timeout

Integer

-1

Query execution timeout in seconds. Set to -1 to disable timeout (default).

Quick Usage Examples

# Connect to in-memory database
uvx mcp-server-duckdb --db-path :memory:

# Connect to local DuckDB file
uvx mcp-server-duckdb --db-path /path/to/local.db

# Connect to local DuckDB file in read-only mode
uvx mcp-server-duckdb --db-path /path/to/local.db --read-only

# Customize result truncation limits
uvx mcp-server-duckdb --db-path /path/to/local.db --max-rows 2048 --max-chars 100000

# Enable query timeout (5 minutes)
uvx mcp-server-duckdb --db-path /path/to/local.db --query-timeout 300

Getting Started

General Prerequisites

  • uv installed, you can install it using pip install uv or brew install uv

If you plan to use the MCP with Claude Desktop or any other MCP compatible client, the client needs to be installed.

Prerequisites for DuckDB

  • No prerequisites. The MCP server can create an in-memory database on-the-fly

  • Or connect to an existing local DuckDB database file, or one stored on remote object storage (e.g., AWS S3).

Usage with Cursor

  1. Install Cursor from cursor.com/downloads if you haven't already

  2. Open Cursor:

  • To set it up globally for the first time, go to Settings->MCP and click on "+ Add new global MCP server".

  • This will open a mcp.json file to which you add the following configuration:

{
  "mcpServers": {
    "duckdb": {
      "command": "uvx",
      "args": [
        "mcp-server-duckdb",
        "--db-path",
        ":memory:"
      ]
    }
  }
}

Usage with VS Code

Add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing Ctrl + Shift + P and typing Preferences: Open User Settings (JSON).

{
  "mcp": {
    "servers": {
      "duckdb": {
        "command": "uvx",
        "args": [
          "mcp-server-duckdb",
          "--db-path",
          ":memory:"
        ]
      }
    }
  }
}

Optionally, you can add it to a file called .vscode/mcp.json in your workspace. This will allow you to share the configuration with others.

{
  "servers": {
    "duckdb": {
      "command": "uvx",
      "args": [
        "mcp-server-duckdb",
        "--db-path",
        ":memory:"
      ]
    }
  }
}

Usage with Claude Desktop

  1. Install Claude Desktop from claude.ai/download if you haven't already

  2. Open the Claude Desktop configuration file:

  • To quickly access it or create it the first time, open the Claude Desktop app, select Settings, and click on the "Developer" tab, finally click on the "Edit Config" button.

  • Add the following configuration to your claude_desktop_config.json:

{
  "mcpServers": {
    "duckdb": {
      "command": "uvx",
      "args": [
        "mcp-server-duckdb",
        "--db-path",
        ":memory:"
      ]
    }
  }
}

Usage with Claude Code

Claude Code supports MCP servers through CLI commands or JSON configuration. Here are two ways to set it up:

Option 1: Using CLI Commands

Add the DuckDB MCP server directly using the Claude Code CLI:

claude mcp add duckdb uvx mcp-server-duckdb -- --db-path :memory:

Option 2: Using JSON Configuration

Add the server using a JSON configuration:

claude mcp add-json duckdb '{
  "command": "uvx",
  "args": [
    "mcp-server-duckdb",
    "--db-path",
    ":memory:"
  ]
}'

Scoping Options:

  • Use --local (default) for project-specific configuration

  • Use --project to share the configuration with your team via .mcp.json

  • Use --user to make the server available across all your projects

Connect to local DuckDB

To connect to a local DuckDB, specify the path to your local DuckDB database file or use :memory: for an in-memory database.

In-memory database:

{
  "mcpServers": {
    "duckdb": {
      "command": "uvx",
      "args": [
        "mcp-server-duckdb",
        "--db-path",
        ":memory:"
      ]
    }
  }
}

Local DuckDB file:

{
  "mcpServers": {
    "duckdb": {
      "command": "uvx",
      "args": [
        "mcp-server-duckdb",
        "--db-path",
        "/path/to/your/local.db"
      ]
    }
  }
}

Local DuckDB file in readonly mode:

{
  "mcpServers": {
    "duckdb": {
      "command": "uvx",
      "args": [
        "mcp-server-duckdb",
        "--db-path",
        "/path/to/your/local.db",
        "--read-only"
      ]
    }
  }
}

Note: readonly mode for local file-backed DuckDB connections also makes use of short lived connections. Each time the query MCP tool is used a temporary, readonly connection is created + query is executed + connection is closed. This feature was motivated by a workflow where DBT was used for modeling data within duckdb and then an MCP client (Windsurf/Cline/Claude/Cursor) was used for exploring the database. The short lived connections allow each tool to run and then release their connection, allowing the next tool to connect.

Connect to DuckDB on S3

You can connect to DuckDB databases stored on Amazon S3 by providing an S3 URL as the database path. The server will automatically configure the necessary S3 credentials from your environment variables.

{
  "mcpServers": {
    "duckdb": {
      "command": "uvx",
      "args": [
        "mcp-server-duckdb",
        "--db-path",
        "s3://your-bucket/path/to/database.duckdb"
      ],
      "env": {
        "AWS_ACCESS_KEY_ID": "<your_key>",
        "AWS_SECRET_ACCESS_KEY": "<your_secret>",
        "AWS_DEFAULT_REGION": "<your_region>"
      }
    }
  }
}

Note: For S3 connections:

  • AWS credentials must be provided via environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and optionally AWS_DEFAULT_REGION)

  • For temporary credentials (AWS SSO), set the AWS_SESSION_TOKEN environment variable (and optionally AWS_DEFAULT_REGION) to automatically use DuckDB's credential_chain provider.

  • The S3 database is attached to an in-memory DuckDB instance

  • The httpfs extension is automatically installed and configured for S3 access

  • Both read and write operations are supported

Example Queries

Once configured, you can ask Claude to run queries like:

  • "Create a new table in my DuckDB database"

  • "Query data from my local CSV file"

  • "Analyze data stored in Amazon S3"

  • "Show me the schema of my database"

Running in SSE mode

The server can run in SSE mode in two ways:

Direct SSE mode

Run the server directly in SSE mode using the --transport sse flag:

uvx mcp-server-duckdb --transport sse --port 8000 --db-path :memory:

This will start the server listening on the specified port (default 8000) and you can point your clients directly to this endpoint.

Using supergateway

Alternatively, you can run SSE mode using supergateway:

npx -y supergateway --stdio "uvx mcp-server-duckdb --db-path :memory:"

Both methods allow you to point your clients such as Claude Desktop, Cursor to the SSE endpoint.

Development configuration

To run the server from a local development environment, use the following configuration:

 {
  "mcpServers": {
    "duckdb": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/your/local/mcp-server-duckdb",
        "run",
        "mcp-server-duckdb",
        "--db-path",
        ":memory:"
      ]
    }
  }
}

Troubleshooting

  • For local file access problems, ensure the --home-dir parameter is set correctly

  • Check that the uvx command is available in your PATH

  • If you encounter spawn uvx ENOENT errors, try specifying the full path to uvx (output of which uvx)

Acknowledgments

This project is based on the mcp-server-motherduck implementation created by MotherDuck. We are grateful for their excellent work in creating the original MCP server for DuckDB integration.

License

This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.

Available Tools

1 tool
queryC

Use this to execute a query on the DuckDB database

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYesSQL query to execute that is a dialect of DuckDB SQL

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions execution but doesn't describe whether queries are read-only or mutating, what permissions are required, error handling, or result formats. This leaves significant behavioral gaps for a database query tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's appropriately sized for a single-parameter tool and gets straight to the point without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a database query tool with no annotations and no output schema, the description is insufficient. It doesn't address critical context like query types supported, result formats, error conditions, or security implications, leaving the agent with incomplete understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the input schema already documents the single 'query' parameter thoroughly. The description adds no additional parameter semantics beyond what's in the schema, meeting the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('execute a query') and target resource ('DuckDB database'), providing a specific verb+resource combination. However, with no sibling tools mentioned, there's no opportunity to distinguish from alternatives, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or contextual constraints. It simply states what the tool does without any usage context or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 1 tool updatev1.0.0
    • First observedquery

TDQS

B3/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool, there is no possibility of ambiguity or overlap between tools. The single tool 'query' has a clear and distinct purpose for executing queries on the DuckDB database.

Naming Consistency5/5

Since there is only one tool, naming consistency is inherently perfect. The tool name 'query' follows a simple, clear pattern with no deviations or mixed conventions to evaluate.

Tool Count2/5

A single tool for a database server is too few for the apparent scope, as it lacks basic operations like creating tables, inserting data, or managing connections. This minimal set will likely cause agent failures in handling typical database workflows.

Completeness1/5

The tool surface is severely incomplete for a database server. It only provides query execution, missing essential CRUD operations (e.g., create, read, update, delete), schema management, and other database functionalities, leading to significant gaps in coverage.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI agents to query and explore databases including SQLite, PostgreSQL, MySQL, and SQL Server through a secure, read-only workflow. It provides tools for listing connections, inspecting table schemas, and executing SELECT statements directly within VS Code.
    1
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables executing SQL queries on DuckDB databases locally or on MotherDuck cloud, with support for multiple databases, read-only mode, and Claude Desktop integration.
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    Enables AI assistants to connect to and interact with PostgreSQL, MySQL, SQLite, and MongoDB databases through natural language, supporting schema exploration, query execution, data export, and more.
    13
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Query local CSV, Parquet, JSON and TSV files with real SQL via DuckDB. Gives your AI coding tool ground-truth data access instead of hallucinated answers.
    4
    MIT