DuckDB database integration with schema inspection and query capabilities
mcp-server-duckdb
- A Powerful MCP Server for Local Data AnalysisThis document details mcp-server-duckdb
, a crucial component for bridging the gap between Large Language Models (LLMs) and the power of local data analysis using DuckDB. By implementing a Model Context Protocol (MCP) server, this tool enables seamless interaction between LLMs and DuckDB databases, opening up a world of possibilities for AI-driven data exploration and manipulation.
mcp-server-duckdb
acts as a translator, allowing LLMs to understand and interact with data stored in DuckDB. This is achieved through the Model Context Protocol (MCP), a standardized communication framework for LLMs and external tools. The server exposes a query
tool that allows LLMs to execute arbitrary SQL queries against the DuckDB database. This empowers LLMs to:
The server's architecture is intentionally streamlined, focusing on providing a robust and flexible interface for LLM interaction.
The current implementation does not define any custom resources. This reflects a design choice to prioritize the core functionality of SQL query execution.
Similarly, no custom prompts are implemented. The server relies on the LLM's ability to generate appropriate SQL based on user instructions.
query
PowerhouseThe heart of the server is the query
tool, which provides a single, unified endpoint for all database interactions.
query
).CREATE TABLE
, INSERT
).Rationale for a Unified query
Function:
Instead of providing separate, specialized functions for different database operations (e.g., select
, create_table
), mcp-server-duckdb
leverages the advanced SQL generation capabilities of modern LLMs. This approach offers several advantages:
SELECT
, CREATE TABLE
, JOIN
, and more, without requiring pre-defined endpoints.Read-Only Mode for Enhanced Security:
The server supports a crucial --readonly
mode, which enforces DuckDB's native read-only protection. When enabled:
read_only=True
, preventing any write operations.The server's behavior is controlled through command-line parameters:
--db-path
--readonly
mode, the server will fail to start if the database file does not exist.--readonly
CREATE
, INSERT
, UPDATE
, DELETE
).The recommended installation method is through Smithery, which simplifies the process:
npx -y @smithery/cli install mcp-server-duckdb --client claude
To integrate mcp-server-duckdb
with Claude Desktop, configure the MCP server in the claude_desktop_config.json
file:
Location: ~/Library/Application Support/Claude/claude_desktop_config.json
Location: %APPDATA%/Claude/claude_desktop_config.json
{ "mcpServers": { "duckdb": { "command": "uvx", "args": [ "mcp-server-duckdb", "--db-path", "~/mcp-server-duckdb/data/data.db" ] } } }
Important: Replace ~/mcp-server-duckdb/data/data.db
with the actual path to your DuckDB database file.
uv
package managerDebugging MCP servers can be challenging due to their stdio-based communication. The MCP Inspector is highly recommended for a streamlined debugging experience.
Install the inspector using npm:
npx @modelcontextprotocol/inspector uv --directory ~/codes/mcp-server-duckdb run mcp-server-duckdb --db-path ~/mcp-server-duckdb/data/data.db
Open the provided URL in your browser to access the debugging interface.
The inspector provides valuable insights into:
By leveraging the MCP Inspector, developers can efficiently identify and resolve issues, ensuring the smooth operation of mcp-server-duckdb
.
๐ โ๏ธ Biomedical research server providing access to PubMed, ClinicalTrials.gov, and MyVariant.info.
๐ MCP server that provides SQL analysis, linting, and dialect conversion using [SQLGlot](https://github.com/tobymao/sqlglot)
๐ ๐ All-in-one MCP server for Postgres development and operations, with tools for performance analysis, tuning, and health checks
Supabase MCP Server with support for SQL query execution and database exploration tools