Efficient MCP server for DuckDB database interaction with SQL query execution in read-only or writable modes
mcp-server-duckdb is an implementation of a Model Context Protocol (MCP) server that integrates with DuckDB, enabling database operations through the standardized MCP tools. DuckDB serves as a fast, embeddable SQL library designed for local data analysis. This server acts as a bridge between MCP clients and the DuckDB database, facilitating query execution, table creation, and schema inspection. By leveraging MCP, AI applications can seamlessly interact with various data sources, enhancing their capabilities in data-driven decision-making processes.
mcp-server-duckdb offers robust integration capabilities by providing a unified query function that encompasses all database interaction tools such as querying, table creation, and schema inspection. This approach simplifies the process for AI applications like Claude Desktop, Continue, and Cursor by abstracting away the complexities of direct SQL execution.
The server supports a single tool for executing SQL queries:
CREATE TABLE, INSERT INTO, UPDATE, and DELETE.An optional configuration allows running the server in read-only mode, which enforces DuckDB's native readonly protection. This ensures that write operations (CREATE, INSERT, UPDATE, DELETE) cannot be performed by the Language Model (LLM), thereby maintaining data integrity.
The architecture of mcp-server-duckdb revolves around the integration with MCP clients and DuckDB. Here's a deeper look at how the protocol works:
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[mcp-server-duckdb]
C --> D[DuckDB Database]
style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#c6d5ed
style D fill:#e8f5e8
This architecture ensures seamless interaction between AI applications and underlying database systems, leveraging the power of MCP for standardized data access.
For a quick installation, use Smithery:
npx -y @smithery/cli install mcp-server-duckdb --client claude
This command will set up the server and integrate it directly with the specified MCP client (Claude Desktop).
Alternatively, you can install mcp-server-duckdb manually:
pip install mcp-server-duckdb
Ensure you have Python version 3.6 or later installed.
Consider a scenario where an AI application needs to analyze sales data:
Query Execution:
mcp-server-duckdb."SELECT * FROM sales_data WHERE date >= '2023-01-01'".Result Handling:
mcp-server-duckdb processes the query and returns the results to the application.In a model training context:
Data Fetching:
"SELECT * FROM customers WHERE age > 25".Training Process:
| MCP Client | Resources | Tools | Prompts | Status |
|---|---|---|---|---|
| Claude Desktop | ✅ | ✅ | ✅ | Full Support |
| Continue | ✅ | ✅ | ✅ | Full Support |
| Cursor | ❌ | ✅ | ❌ | Tools Only |
To ensure optimal performance and compatibility, the server is designed to work seamlessly with various AI clients. The provided matrix helps in selecting the appropriate integration methods based on client requirements.
{
"mcpServers": {
"duckdb": {
"command": "uvx",
"args": ["mcp-server-duckdb", "--db-path", "~/mcp-server-duckdb/data/data.db"]
}
}
}
To run the server in read-only mode, use the --readonly flag:
npx -y mcp-server-duckdb --readonly --db-path ~/mcp-server-duckdb/data/data.db
This ensures that DuckDB enforces its readonly protection.
Use the MCP Inspector for advanced debugging:
npx @modelcontextprotocol/inspector uv --directory ~/codes/mcp-server-duckdb run mcp-server-duckdb --db-path ~/mcp-server-duckdb/data/data.db
The inspector provides detailed logs and insights into request/response handling, tool execution, and server state.
Why use mcp-server-duckdb in read-only mode?
How does the MCP protocol enhance AI applications?
Can I integrate multiple databases with a single MCP server?
What are the security benefits of using read-only mode?
How does the MCP client compatibility matrix affect my choice of clients?
Contributions are welcome! Developers can contribute by:
Pull requests are encouraged in the following repositories:
Explore more about Model Context Protocol and its ecosystem:
graph TD;
A[Model Context Protocol] --> B[Claude Desktop]
A --> C[Continue]
A --> D[Cursor]
By integrating mcp-server-duckdb into your AI application, you can leverage the power of DuckDB for local data analysis while keeping the flexibility and standardization provided by MCP.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration