
ClickHouse
io.github.alyiox由 GitHub 帳號 alyiox 發布v0.11.0更新於 Oct 24, 2026
Read-only MCP server for ClickHouse metadata, parameterized queries, and plan analysis.
概覽
一個在本機執行、預設唯讀的 ClickHouse MCP 伺服器,讓助理檢視資料庫結構、執行參數化 SELECT/SHOW 查詢並分析執行計畫。
- 可以做什麼
- 列出已設定的連線設定檔及其寫入狀態,並以資源形式提供相同資料。每次呼叫執行一條唯讀 SELECT、WITH...SELECT 或 SHOW 語句,支援具名參數與可選資料庫,結果以內嵌 CSV 或快照 URI 回傳。以 EXPLAIN 的 plan、pipeline、syntax 變體分析唯讀 SELECT,不回傳結果列。透過查詢 ClickHouse 系統表探索資料庫、資料表、欄位、大小與鍵資訊。視需要取回已儲存的查詢快照 CSV,用於較大量匯出。當某個設定檔啟用寫入時,可透過獨立的寫入工具執行 DDL/DML。
- 適用情境
- 適合助理需要探索 ClickHouse 資料庫、依據其中資料回答問題或檢視查詢計畫,同時希望維持預設唯讀的情境。也適合需要從同一部署連線多個 ClickHouse 執行個體的情況。
- 執行需求
- 透過 uvx 在本機執行(需要 Python 3.13+),並需要可連線的 ClickHouse 執行個體。連線資訊來自 MCP_CLICKHOUSE_DSN 環境變數、各設定檔的 MCP_CLICKHOUSE_PROFILES_ _ 變數,或使用者層級的 config.json;皆未設定時會退回本機預設 DSN。列數與逾時上限可依設定檔調整。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 ClickHouse,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
MCP ClickHouse Tool
[CI] [PyPI] [Python 3.13+] [License: MIT]
A read-only-by-default Model Context Protocol (MCP) server for ClickHouse that provides schema discovery, read-only queries, execution-plan analysis, opt-in writes, and profile-based access to multiple servers from a single toolset deployment.
Read-only is enforced by the engine, not by SQL text matching: the query tools' clients carry ClickHouse's readonly=1, so writes, external table functions and query-level SETTINGS are refused by the server being queried. Writes live behind a separate tool that is not registered at all until a profile asks for it.
Requirements: Python 3.13+, a running ClickHouse instance, and connection details via environment variables or a config file.
Quick start
Set a DSN and run the server with MCP Inspector:
Configuration
A profile is one ClickHouse connection: a DSN plus the row and timeout caps that apply to it. A profile named default always exists; every tool takes an optional profile to reach another, and list_profiles reports what is configured.
Settings come from three sources, merged field by field, later winning:
- the user-scoped
config.json— any number of profiles; MCP_CLICKHOUSE_PROFILES_<NAME>_<FIELD>environment variables — any number of profiles;- flat
MCP_CLICKHOUSE_<FIELD>environment variables — thedefaultprofile only.
Because the merge is per field rather than per profile, a config.json can carry the full set while a flat MCP_CLICKHOUSE_DSN repoints the default profile at a local server, leaving its other fields intact. With none of the three present, default falls back to http://default:@localhost:8123/default.
Each setting has one field name, spelled three ways — MCP_CLICKHOUSE_<FIELD>, MCP_CLICKHOUSE_PROFILES_<NAME>_<FIELD>, or the field lowercased as a JSON key:
Caps are per profile. A value above its ceiling is clamped at startup; a value that is not an integer falls back to the default, and a value that is not a boolean leaves ALLOW_WRITE off.
Single connection: flat environment variables are the shortest path.
Multiple connections: use the user-scoped config.json, which keeps credentials out of the host's process environment.
- Unix-like:
~/.config/mcp-clickhousex/config.json - Windows:
%USERPROFILE%\.config\mcp-clickhousex\config.json
Nothing stops one profile from both reading and writing, but a separate write-enabled profile is the shape worth copying: it gives the writes their own DSN, so the credentials behind them can be scoped to what they actually need while the read profiles stay on a login whose grants stop at SELECT.
Profile names are case-insensitive and must be alphanumeric — no underscores or hyphens, since the structured env form splits on _ (MCP_CLICKHOUSE_PROFILES_WAREHOUSE_DSN is profile warehouse, field DSN). A name that breaks the rule is skipped, as is a config.json that is missing, unreadable, or not shaped {"profiles": {…}}; the server starts on whatever sources remain rather than failing.
DSN syntax: scheme://user:password@host:port/database. An https:// or clickhouses:// scheme enables TLS, and query-string parameters reach the driver (?connect_timeout=10) — except readonly, which the server always applies last, from the profile's ALLOW_WRITE.
URL-reserved characters in the username or password must be percent-encoded — # → %23, ? → %3F, / → %2F, @ → %40, % → %25. Username admin@org with password p#ss? becomes http://admin%40org:p%23ss%3F@host:8123/database.
Tools and resources
All tools accept an optional profile; when omitted, the default profile is used.
Tools
types—EXPLAINvariants:plan(indexes),pipeline,syntax. Defaults toplanandpipeline.parameters— Named parameters for driver placeholders,%(name)sor{name:Type}.database— Session default database for unqualified names; otherwise qualify asdb.table.
Catalog discovery has no dedicated tool: list databases, tables and columns — and read sizes (total_rows, total_bytes) and keys (primary_key, sorting_key, partition_key) — with run_query over system.databases, system.tables and system.columns, which take ordinary WHERE predicates where SHOW takes only LIKE. SHOW earns its place for DDL a listing cannot give you — SHOW CREATE TABLE/VIEW/DICTIONARY for codecs, TTLs and the full column list.
Results are RFC 4180 CSV: the first row is the header, the rest are data. NULL is written as \N, ClickHouse's own CSV null representation, so it stays distinct from the empty string.
A plan's Indexes section is not authoritative about a table's keys: it names only the key columns the query used, so a query that skips the leading key column reports a shorter key than the table has. Confirm from system.tables, which answers in a few dozen tokens where SHOW CREATE TABLE spends several hundred to say the same thing.
The row caps that applied to a call arrive with its result as truncated and row_limit.
Resources
Security
Every client this server opens carries ClickHouse's own readonly=1, so the engine — not just the server's SQL checks — refuses:
- writes of any kind (
INSERT, DDL,ALTER … UPDATE,SYSTEM,GRANT); - the external table functions
url(),s3(),remote(),mysql()and friends, so a query cannot reach a host outside the configured profile; - query-level
SETTINGS, so the row and time caps cannot be raised by the SQL an agent supplies, andINTO OUTFILEis refused.
readonly=2 is deliberately not used: it permits SETTINGS changes, which would make those caps advisory. The tradeoff is that benign per-query tuning (SETTINGS max_threads = …) is refused too.
On top of that, run_query accepts SELECT / WITH … SELECT / SHOW and analyze_query only the first two, one statement per call. Interactive queries enforce a tight row cap (default 500, hard ceiling 1 000); for larger extracts use snapshot=true (default 10 000, hard ceiling 50 000).
Writes are opt-in, and invisible until then. run_command runs on a client carrying readonly=0, so it executes arbitrary DDL and DML — and, with readonly lifted, the external table functions come back too. Unless at least one configured profile sets ALLOW_WRITE (default false), the tool is not registered at all: it never appears in tools/list, so a read-only deployment spends no context on it and offers no write surface an agent could be talked into. Once any profile opts in, the tool is advertised server-wide and is still refused at call time on profiles that remain locked; list_profiles reports allow_write per profile so an agent can pick a writable one.
ALLOW_WRITE is a soft, application-level guard, not a security boundary — it constrains this server, not the database. For a genuine read-only guarantee, connect with a login whose ClickHouse grants stop at SELECT, and keep write-enabled profiles pointed at credentials scoped to only what they need. run_command carries destructive and openWorld tool annotations so hosts can gate it behind confirmation, but honoring those annotations is the host's choice. ClickHouse has no transaction to roll back in here: a statement that lands, stays.
Use environment variables or the config file for connection credentials — never commit secrets.
MCP host examples
Snippets use uvx mcp-clickhousex (no clone required; ensure uv is on your PATH). Replace connection details as needed; the env block is unnecessary when the DSN already comes from config.json or the environment.
Claude Code and Cursor read the same mcpServers shape:
Codex, OpenCode and GitHub Copilot
Codex (TOML):
OpenCode:
GitHub Copilot:
Tests
Tests require a running ClickHouse instance; the suite creates a sample table in the default database, seeds it, and drops it after.
The harness locates the instance through MCP_TEST_CLICKHOUSE_DSN, falling back to http://admin:password123@localhost:8123/default. Set it to point tests at another server without touching your production MCP_CLICKHOUSE_DSN.
The suite configures two profiles on that one instance — a read-only default and a write-enabled writable — so both halves of the write gate are exercised: run_command is advertised because a profile opts in, and is still refused against the profile that does not.
Contributing
Open issues or PRs; follow existing style and add tests where appropriate.
License
來源:README.md,提交 c97c319
工具
0版本歷史
3- v0.11.0最新Sep 20, 2026
- v0.10.0Sep 17, 2026
- v0.9.0Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分

