DuckDB MCP Server

DuckDB MCP Server

Enables AI assistants and IDEs to execute SQL queries on local DuckDB databases, in-memory databases, or cloud-stored databases with support for flexible connections and configurable result limits.

Category
访问服务器

README

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

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.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选