Skip to content
DuckDB community extension

duckdb_mcp

Model Context Protocol (MCP) extension for DuckDB that enables seamless integration between SQL databases and MCP servers. Provides both client capabilities for accessing remote MCP resources via SQL and server capabilities for exposing database content as MCP resources.

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL duckdb_mcp FROM community;
LOAD duckdb_mcp FROM community;

Try it in a temporary SQL session with duckdb_mcp already loaded. Queries run in this tab; examples using files or services need their own setup.

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

Connect to an MCP server using stdio transport

SQL
-- Load the MCP extension

-- Connect to an MCP server using stdio transport
ATTACH 'python3' AS data_server (
    TYPE mcp, 
    TRANSPORT 'stdio', 
    ARGS '["path/to/server.py"]'
);

-- Access remote data via MCP protocol
SELECT * FROM read_csv('mcp://data_server/file:///data.csv');
SELECT * FROM read_json('mcp://data_server/api://endpoint');

-- List available resources on the server
SELECT mcp_list_resources('data_server');

-- Execute tools on the MCP server
SELECT mcp_call_tool('data_server', 'process_data', '{"table": "sales"}');

-- Server mode: Start an MCP server to expose database content
SELECT mcp_server_start('stdio', 'localhost', 0, '{}');
-- or mcp_server_start('stdio')

-- Publish database tables as MCP resources
CREATE TABLE products AS SELECT 'Widget' as name, 10.99 as price;
SELECT mcp_publish_table('products', 'data://tables/products', 'json');

Provided by teaguesterling. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

DuckDB MCP Extension bridges SQL databases with the Model Context Protocol (MCP), enabling bidirectional integration between DuckDB and MCP servers. The extension operates in dual modes: as an MCP client for accessing remote resources and as an MCP server for exposing database content.

MCP Client Capabilities: Connect to MCP servers using multiple transport protocols (stdio, TCP, WebSocket) and access remote resources directly in SQL queries. Use the mcp:// URI scheme with standard DuckDB functions like read_csv(), read_parquet(), and read_json() to seamlessly query remote data sources. Execute remote tools with mcp_call_tool() and discover available resources with mcp_list_resources().

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
teaguesterling/duckdb_mcp
License
Apache-2.0
Maintainers
teaguesterling
Written in
C++
Build source
6b2b1dc899e1
Build definition
Community descriptor