ClickHouse MCP
A ClickHouse MCP server that gives agents trusted analytics, not a database console
@hypequery/mcp turns the datasets you define in TypeScript or Python into Model Context Protocol tools. Claude, Cursor, and other MCP clients can discover and query the analytics you approve, while SQL and ClickHouse credentials stay inside your server.
Agent surface
Datasets and measures
Database access
No raw SQL
Works with
Claude, Cursor, MCP clients
Quickstart
Run a ClickHouse MCP server in five minutes
Point it at a ClickHouse table you already have. The agent gets the dimensions and measures you define as tools, not a SQL console.
Step 1
Install the packages
In your project folder. You need Node.js 20 or newer.
terminalStep 2
Define what the agent may query
Save this as analytics/api.ts, with your ClickHouse settings in .env. The dataset names the table, the columns an agent can group and filter by, and the measures it can ask for. Swap in your own table.
analytics/api.tsStep 3
Connect your agent
Claude Code shown here; run it from your project folder.
npx hypequery mcp --self-testchecks the setup first.terminalUsing Claude Desktop? Open Settings → Developer → Edit Config, add this entry with your project's absolute path, then fully quit and reopen Claude so it starts the server.
claude_desktop_config.jsonStep 4
Ask a question
The agent calls list_datasets, get_dataset_schema and query_dataset, and answers from the rows hypequery returns.
prompt
Using Python? The same four steps with hypequery mcp app:api are in the MCP quickstart. Add --http to serve it over HTTP for your team.
Raw SQL gives an agent too much authority
Prompt instructions are not an access-control layer. A general SQL tool lets the model choose tables, columns, joins, and result size at runtime.
Analytics meaning drifts between humans and agents
If every agent writes its own revenue query, it will disagree with the backend and dashboard sooner or later.
Multi-tenant data needs trusted scope
Tenant identity must come from the host process, never from a prompt or caller-supplied filter that can widen access.
One governed contract
Publish the analytics definitions your product already trusts
Define dimensions, measures, relationships, and tenant rules once, in TypeScript or Python. The MCP server turns that catalog into a small, discoverable tool surface.
- Agents discover only the datasets you register, with the descriptions you write
- Fields, filters, ordering, and limits are validated before execution
- Measure definitions stay identical across backend, React, and MCP
- SQL is hidden by default and credentials never enter the model context
- Tenant-scoped datasets fail closed without trusted server scope
Semantic contract
Define what the agent is allowed to understand
The dataset is ordinary code that can be reviewed, tested, and versioned with the rest of your application. Descriptions reach the agent through the schema tool.
MCP server
Serve your datasets, then expose them over MCP
@hypequery/mcp exposes list_datasets, get_dataset_schema, and query_dataset tools over stdio or HTTP. The agent never writes or receives SQL.
hypequery mcp serves the datasets your Serve API already registers, and hypequery mcp app:api does the same for a Python API. Add --http to serve them at a URL, behind a shared key, your app's auth or OAuth.
Because MCP queries go through the same dataset definitions as the rest of your application, validation and the meaning of each measure do not fork into an agent-only implementation.
@hypequery/mcp
One Serve API, one MCP command
Over stdio the server runs as one trusted tenant; over HTTP each caller's tenant comes from their verified credential. Tenant-scoped datasets refuse to run without one, and the model never chooses its own tenant.
Where teams usually get stuck
Questions teams ask
Is there an official ClickHouse MCP server?
Yes. ClickHouse maintains mcp-clickhouse, which gives agents a read-only SQL tool, and ClickHouse Cloud offers a remote MCP server. A governed server like this one is the alternative when agents should call named datasets and metrics instead of writing SQL.
Semantic layer for AI agents
Datasets give humans, APIs, dashboards, and agents one definition for business metrics.
How do I keep an AI agent to one tenant’s data?
The server accepts tenant identity from trusted host configuration and rejects unscoped tenant datasets.
Can Claude or Cursor query ClickHouse?
Yes, through an MCP server. With this one, Claude, Cursor, Codex and other MCP clients discover approved datasets and measures without learning your schema or credentials.
Examples
Runnable examples
Every example runs against the same seeded ClickHouse dataset. Scaffold one with npx @hypequery/cli create <slug> -y, or browse the full list.
Example · TypeScript
A tenant-safe analytics agent in your Next.js app with the AI SDK
Ship an analytics agent in your product: AI SDK chat with hypequery's tools, from Cloud or your own backend, and every answer stays in one customer.
Open example
Example · TypeScript
A governed ClickHouse MCP server: agents query the semantic layer, not the database
Give Claude Code, Cursor or any MCP client ClickHouse analytics through four governed tools: only published datasets, no SQL, one tenant per server.
Open example
Example · Python
A governed ClickHouse MCP server in Python: agents query datasets, not SQL
Give Claude Code, Cursor or Claude Desktop ClickHouse analytics from Python: a fixed set of query tools over published datasets, tenant fixed by env, no SQL.
Open example
Further reading
Go deeper where it actually helps
Official ClickHouse MCP vs governed MCP
What the official mcp-clickhouse server, the ClickHouse Cloud remote MCP server and a governed MCP server each expose to agents.
Open guide
ClickHouse MCP in Claude Code
Set up a governed ClickHouse MCP server in Claude Code, step by step, with verification and troubleshooting.
Open guide
ClickHouse MCP in Cursor
Add the server to .cursor/mcp.json for one project or every project.
Open guide
ClickHouse MCP in Codex
Register the server with codex mcp add or ~/.codex/config.toml.
Open guide
AI analytics chat with the Vercel AI SDK
Use the same MCP tools inside your own product, with streamText and useChat.
Open guide
MCP quick start
Expose your first dataset from TypeScript or Python, then share it over HTTP.
Open guide
Take it to production
Per-user auth so each caller sees only their tenant, OAuth for Claude and ChatGPT, HTTPS and hosting.
Open guide
MCP tool catalog
See exactly what agents can discover and execute.
Open guide
MCP safety model
Credentials, SQL visibility, limits, and tenant isolation.
Open guide
AI tool generation
Generate tool schemas from the same semantic catalog.
Open guide
Next step
Give one approved dataset to your first agent
Install @hypequery/mcp, register a dataset with Serve, then connect hypequery mcp to your MCP client.
Open source, and it runs in your own backend. Want it hosted?