TD

teaguesterling/duckdb_mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

71 stars 8 forks 质量 73 趋势 20Apache-2.0

teaguesterling/duckdb_mcp 是从 https://github.com/teaguesterling/duckdb_mcp. 导入的 MCP 服务器候选

概览

teaguesterling/duckdb_mcp 是从 https://github.com/teaguesterling/duckdb_mcp. 导入的 MCP 服务器候选

概述(AI 翻译)

这是DuckDB的模型上下文协议(MCP)扩展,实现SQL数据库与Claude等AI助手之间的无缝集成。

特色

  • 运行为MCP服务器:将你的DuckDB数据库暴露给AI助手,内置工具用于查询、描述和探索数据
  • HTTP 传输:作为 HTTP 服务器运行,为基于网页的客户端提供身份验证
  • 作为MCP客户端:连接外部MCP服务器并使用SQL查询其资源
  • 自定义工具:将参数化SQL查询发布为AI助手可以发现并调用的工具
  • 多种格式:输出结果为JSON、JSONL、Markdown(高效令牌)、CSV或纯文本

快速启动

作为 MCP 服务器(面向 AI 助手)

创建init-server.sql:

stdio transport 拥有 stdout。 JSON-RPC 是 stdout 框架的,其他内容都打印 会破坏通道。扩展会剥夺其他写作者的描述符 服务器启动时,客户端容忍在 握手(CLI为-init打印-- Loading resources from …横幅,外加一个 每语句结果表)。

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

DuckDB MCP Extension

A Model Context Protocol (MCP) extension for DuckDB that enables seamless integration between SQL databases and AI assistants like Claude.

Features

  • Run as MCP Server: Expose your DuckDB database to AI assistants with built-in tools for querying, describing, and exploring data
  • HTTP Transport: Run as an HTTP server with authentication for web-based clients
  • Act as MCP Client: Connect to external MCP servers and query their resources using SQL
  • Custom Tools: Publish parameterized SQL queries as tools that AI assistants can discover and call
  • Multiple Formats: Output results as JSON, JSONL, Markdown (token-efficient), CSV, or plain text

Quick Start

As an MCP Server (for AI Assistants)

Create init-server.sql:

LOAD 'duckdb_mcp';

CREATE TABLE products (id INT, name VARCHAR, price DECIMAL(10,2));
INSERT INTO products VALUES (1, 'Widget', 9.99), (2, 'Gadget', 24.99);

PRAGMA mcp_server_start('stdio');

stdio transport owns stdout. JSON-RPC is framed on stdout, so anything else printed there corrupts the channel. The extension takes the descriptor away from other writers when the server starts, and the client tolerates host output that arrives before the handshake (the CLI prints an -- Loading resources from … banner for -init, plus a result table per statement). For a server whose output you cannot afford to have parsed at all, put .output /dev/null as the first line of the init script.

Add to Claude Desktop configuration:

{
  "mcpServers": {
    "my-database": {
      "command": "duckdb",
      "args": ["-init", "/path/to/init-server.sql"]
    }
  }
}

Now Claude can query your database directly!

As an HTTP Server

Run DuckDB as an HTTP server that any HTTP client can connect to:

LOAD 'duckdb_mcp';

-- Start HTTP server with authentication
PRAGMA mcp_server_start('http', 'localhost', 8080, '{"auth_token": "secret"}');

Then connect via HTTP:

# Health check
curl http://localhost:8080/health

# Query with authentication
curl -X POST http://localhost:8080/mcp \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer secret" \
    -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"query","arguments":{"sql":"SELECT 1"}}}'

As an MCP Client

Windows: MCP client connections are not available — attaching to a server means spawning it over stdio, which is not implemented on Windows (#67). Use WSL. Running DuckDB as an MCP server works on Windows.

LOAD 'duckdb_mcp';

-- Connect to an MCP server
ATTACH 'python3' AS server (TYPE mcp, ARGS '["path/to/server.py"]');
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "my-database": { "command": "duckdb", "args": ["-init", "/path/to/init-server.sql"] } } }