[hypequery](https://hypequery.com/) › ClickHouse MCP Server for Claude, Cursor and Codex | hypequery
Index for agents: https://hypequery.com/llms.txt
Canonical page: https://hypequery.com/clickhouse-mcp

> A ClickHouse MCP server with tenant-scoped dataset tools in place of a SQL tool. Setup for Claude Desktop, Claude Code, Cursor and Codex.

[Open sourceApache 2.0](https://github.com/hypequery/hypequery)

ClickHouse MCP

# A ClickHouse MCP server with tenant-scoped dataset tools

The official ClickHouse MCP servers give an agent a read-only SQL tool. @hypequery/mcp gives it four tools over the datasets you define in TypeScript or Python: it picks dimensions and measures, the server writes the SQL, and every query is held to one tenant. Claude, Cursor, Codex and other MCP clients connect over stdio or HTTP, and ClickHouse credentials stay in your server.

[Start with MCP ](https://hypequery.com/docs/mcp/quickstart)[Read the safety model](https://hypequery.com/docs/mcp/safety)

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.

1. Step 1

   ### Install the packages

   In your project folder. You need Node.js 20 or newer.

   terminal

   ```
   npm install @hypequery/clickhouse @hypequery/datasets @hypequery/serve @hypequery/mcp
   npm install -D @hypequery/cli
   ```

2. Step 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.ts

   ```
   // analytics/api.ts
   import { createQueryBuilder } from '@hypequery/clickhouse';
   import { dataset, dimension, measure } from '@hypequery/datasets';
   import { initServe } from '@hypequery/serve';

   // Reads CLICKHOUSE_URL, _USERNAME, _PASSWORD and _DATABASE from .env
   const db = createQueryBuilder({
     url: process.env.CLICKHOUSE_URL!,
     username: process.env.CLICKHOUSE_USERNAME!,
     password: process.env.CLICKHOUSE_PASSWORD!,
     database: process.env.CLICKHOUSE_DATABASE!,
   });

   const Orders = dataset('orders', {
     source: 'orders',
     description: 'One row per order.',
     dimensions: {
       status: dimension.string({ label: 'Status', description: 'completed, refunded or pending' }),
       country: dimension.string({ label: 'Country' }),
     },
     measures: {
       revenue: measure.sum('amount', { label: 'Revenue' }),
       orders: measure.count('id', { label: 'Orders' }),
     },
   });

   const { serve } = initServe({ context: () => ({ db }) });

   export const api = serve({ queryBuilder: db, datasets: { orders: Orders } });
   ```

3. Step 3

   ### Connect your agent

   Claude Code shown here; run it from your project folder. `npx hypequery mcp --self-test` checks the setup first.

   terminal

   ```
   claude mcp add hypequery -- sh -c "cd '$PWD' && npx hypequery mcp"
   claude mcp list
   ```

   Using 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.json

   ```
   {
     "mcpServers": {
       "hypequery": {
         "command": "sh",
         "args": ["-c", "cd /absolute/path/to/your-project && npx hypequery mcp"]
       }
     }
   }
   ```

4. Step 4

   ### Ask a question

   The agent calls list_datasets, get_dataset_schema and query_dataset, and answers from the rows hypequery returns.

   prompt

   ```
   What was revenue by country for completed orders?
   ```

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.

Which ClickHouse MCP server

## Official ClickHouse MCP servers and hypequery compared

ClickHouse maintains two MCP servers. Both hand the agent SQL. hypequery hands it named datasets and metrics instead, so the questions it can answer are the ones you defined, for one tenant at a time.

|                      | mcp-clickhouse (open source)                                  | ClickHouse Cloud remote MCP                                                        | hypequery MCP                                                       |
| -------------------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
| What the agent sends | SQL through run_query                                         | SELECT statements through run_select_query                                         | Dataset, dimensions, measures and filters; no SQL tool              |
| Tools                | run_query, list_databases, list_tables, run_chdb_select_query | run_select_query, list_databases, list_tables, plus organization and service tools | list_datasets, get_dataset_schema, query_metric, query_dataset      |
| Writes               | Read-only by default; writes and drops can be switched on     | All queries read-only                                                              | Read-only: queries come from dataset definitions                    |
| Tenant scope         | The ClickHouse user’s grants                                  | The ClickHouse user’s grants                                                       | Tenant key per dataset; unscoped queries are refused                |
| Where it runs        | Your machine or server (Python)                               | Hosted by ClickHouse Cloud                                                         | Your backend (TypeScript or Python), stdio or HTTP                  |
| Best for             | Exploring a database you own                                  | Exploring a ClickHouse Cloud service                                               | Agents that answer business questions, including for your customers |

ClickHouse columns checked on 2026-11-18 against the mcp-clickhouse README and the ClickHouse Cloud remote MCP guide, both linked in the sources below.

## 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

one-governed-contract.ts

```
import { dataset, dimension, measure } from '@hypequery/datasets';

export const Orders = dataset('orders', {
  source: 'orders',
  tenantKey: 'tenant_id',
  timeKey: 'created_at',
  dimensions: {
    region: dimension.string(),
    status: dimension.string(),
  },
  measures: {
    revenue: measure.sum('amount', {
      description: 'Total completed order revenue',
    }),
    orderCount: measure.count('id'),
  },
});
```

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 four tools over stdio or HTTP: list_datasets, get_dataset_schema, query_metric and query_dataset. 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

mcp-server.ts

```
// analytics/api.ts
import { initServe } from '@hypequery/serve';
import { db } from './client';
import { Orders } from './datasets';

const { serve } = initServe({ context: () => ({ db }) });

export const api = serve({
  queryBuilder: db,
  datasets: { orders: Orders },
});

// Expose the same datasets to Claude, Cursor, or any MCP client.
// The tenant comes from how you start the server, never from the model:
//   npx hypequery mcp --tenant acme
```

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.

Client setup

## Connect Claude Desktop, Claude Code, Cursor or Codex

Each client launches the same command, `npx hypequery mcp`, from your project folder. Add `--tenant <id>` if any dataset is tenant-scoped. Run `npx hypequery mcp --self-test` first to check which datasets it will serve.

Desktop clients start servers from their own working directory, so every entry changes into your project first and uses an absolute path. For a Python API, run `hypequery mcp app:api --print-config` and paste the entry it prints. The clients guide in the docs covers Windows and the config-file server.

Claude Code

### Add it from your project folder

terminal

```
claude mcp add hypequery -- sh -c "cd '$PWD' && npx hypequery mcp"
claude mcp list
```

The shell expands $PWD, so Claude Code stores an absolute path.

Claude Desktop

### Edit claude_desktop_config.json

claude_desktop_config.json

```
{
  "mcpServers": {
    "hypequery": {
      "command": "sh",
      "args": ["-c", "cd /absolute/path/to/your-project && npx hypequery mcp"]
    }
  }
}
```

Settings → Developer → Edit Config. On macOS the file is \~/Library/Application Support/Claude/claude_desktop_config.json. Quit and reopen Claude afterwards.

Cursor

### Add .cursor/mcp.json to the project

.cursor/mcp.json

```
{
  "mcpServers": {
    "hypequery": {
      "type": "stdio",
      "command": "sh",
      "args": ["-c", "cd '${workspaceFolder}' && npx hypequery mcp"]
    }
  }
}
```

Cursor fills in ${workspaceFolder} with the folder you opened.

Codex

### Register it with codex mcp add

terminal

```
codex mcp add hypequery -- sh -c "cd '$PWD' && npx hypequery mcp"
codex mcp list
```

Run it from your project folder. Codex writes the entry to \~/.codex/config.toml, which the CLI, the IDE extension and the ChatGPT desktop app share.

Where teams usually get stuck

## Questions teams ask

### Is there an official ClickHouse MCP server?

Yes, two. ClickHouse maintains mcp-clickhouse, an open-source Python server with a run_query tool that is read-only by default, and ClickHouse Cloud hosts a remote MCP server at mcp.clickhouse.cloud with a SELECT-only run_select_query tool. hypequery is the option for agents that should call named datasets and metrics, scoped to one tenant, 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.

Sources

- [mcp-clickhouse README (ClickHouse, checked 2026-11-18)](https://github.com/ClickHouse/mcp-clickhouse)
- [ClickHouse Cloud remote MCP server guide (checked 2026-11-18)](https://clickhouse.com/docs/products/cloud/features/ai-ml/mcp/remote-mcp)

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](https://hypequery.com/examples).

[Example · TypeScript](https://hypequery.com/examples/in-app-analytics-agent)

### [A tenant-safe analytics agent in your Next.js app with the AI SDK](https://hypequery.com/examples/in-app-analytics-agent)

[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.](https://hypequery.com/examples/in-app-analytics-agent)

[Next.jsReactAI SDKMCPAI agentsMulti-tenantEmbedded analyticsSaaS analytics](https://hypequery.com/examples/in-app-analytics-agent)

[Open example](https://hypequery.com/examples/in-app-analytics-agent)

[Example · TypeScript](https://hypequery.com/examples/mcp-agent-analytics)

### [A governed ClickHouse MCP server: agents query the semantic layer, not the database](https://hypequery.com/examples/mcp-agent-analytics)

[Give Claude Code, Cursor or any MCP client ClickHouse analytics through four governed tools: only published datasets, no SQL, one tenant per server.](https://hypequery.com/examples/mcp-agent-analytics)

[Node.jsMCPClickHouseAI agentsMulti-tenantSemantic layer](https://hypequery.com/examples/mcp-agent-analytics)

[Open example](https://hypequery.com/examples/mcp-agent-analytics)

[Example · Python](https://hypequery.com/examples/mcp-agent-analytics-python)

### [A governed ClickHouse MCP server in Python: agents query datasets, not SQL](https://hypequery.com/examples/mcp-agent-analytics-python)

[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.](https://hypequery.com/examples/mcp-agent-analytics-python)

[PythonMCPAI agentsMulti-tenantSemantic layer](https://hypequery.com/examples/mcp-agent-analytics-python)

[Open example](https://hypequery.com/examples/mcp-agent-analytics-python)

Further reading

## Go deeper where it actually helps

### [MCP client setup](https://hypequery.com/docs/mcp/clients)

[Claude Code, Claude Desktop, Cursor and Python entries, Windows paths and the config-file server.](https://hypequery.com/docs/mcp/clients)

[Open guide](https://hypequery.com/docs/mcp/clients)

### [Official ClickHouse MCP vs governed MCP](https://hypequery.com/blog/clickhouse-mcp-servers-compared)

[What the official mcp-clickhouse server, the ClickHouse Cloud remote MCP server and a governed MCP server each expose to agents.](https://hypequery.com/blog/clickhouse-mcp-servers-compared)

[Open guide](https://hypequery.com/blog/clickhouse-mcp-servers-compared)

### [ClickHouse MCP in Claude Code](https://hypequery.com/blog/clickhouse-mcp-claude-code)

[Set up a governed ClickHouse MCP server in Claude Code, step by step, with verification and troubleshooting.](https://hypequery.com/blog/clickhouse-mcp-claude-code)

[Open guide](https://hypequery.com/blog/clickhouse-mcp-claude-code)

### [ClickHouse MCP in Cursor](https://hypequery.com/blog/clickhouse-mcp-cursor)

[Add the server to .cursor/mcp.json for one project or every project.](https://hypequery.com/blog/clickhouse-mcp-cursor)

[Open guide](https://hypequery.com/blog/clickhouse-mcp-cursor)

### [ClickHouse MCP in Codex](https://hypequery.com/blog/clickhouse-mcp-codex)

[Register the server with codex mcp add or \~/.codex/config.toml.](https://hypequery.com/blog/clickhouse-mcp-codex)

[Open guide](https://hypequery.com/blog/clickhouse-mcp-codex)

### [AI analytics chat with the Vercel AI SDK](https://hypequery.com/blog/clickhouse-ai-chat-vercel-ai-sdk)

[Use the same MCP tools inside your own product, with streamText and useChat.](https://hypequery.com/blog/clickhouse-ai-chat-vercel-ai-sdk)

[Open guide](https://hypequery.com/blog/clickhouse-ai-chat-vercel-ai-sdk)

### [MCP quick start](https://hypequery.com/docs/mcp/quickstart)

[Expose your first dataset from TypeScript or Python, then share it over HTTP.](https://hypequery.com/docs/mcp/quickstart)

[Open guide](https://hypequery.com/docs/mcp/quickstart)

### [Take it to production](https://hypequery.com/docs/mcp/quickstart#take-it-to-production)

[Per-user auth so each caller sees only their tenant, OAuth for Claude and ChatGPT, HTTPS and hosting.](https://hypequery.com/docs/mcp/quickstart#take-it-to-production)

[Open guide](https://hypequery.com/docs/mcp/quickstart#take-it-to-production)

### [MCP tool catalog](https://hypequery.com/docs/mcp/tools)

[See exactly what agents can discover and execute.](https://hypequery.com/docs/mcp/tools)

[Open guide](https://hypequery.com/docs/mcp/tools)

### [MCP safety model](https://hypequery.com/docs/mcp/safety)

[Credentials, SQL visibility, limits, and tenant isolation.](https://hypequery.com/docs/mcp/safety)

[Open guide](https://hypequery.com/docs/mcp/safety)

### [AI tool generation](https://hypequery.com/docs/datasets/tool-generation)

[Generate tool schemas from the same semantic catalog.](https://hypequery.com/docs/datasets/tool-generation)

[Open guide](https://hypequery.com/docs/datasets/tool-generation)

Related pillars

[ClickHouse with TypeScript and Python](https://hypequery.com/clickhouse)[ClickHouse Semantic Layer](https://hypequery.com/clickhouse-semantic-layer)[ClickHouse AI chat](https://hypequery.com/clickhouse-ai)[Multi-Tenant Analytics](https://hypequery.com/clickhouse-multi-tenant-analytics)[ClickHouse React](https://hypequery.com/clickhouse-react)[MCP for Python backends](https://hypequery.com/clickhouse-python-mcp)[AI semantic layer](https://hypequery.com/semantic-layer/ai-agents)[Analytics MCP server](https://hypequery.com/semantic-layer/analytics-mcp-server)

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?

[Open the MCP quickstart ](https://hypequery.com/docs/mcp/quickstart)[Review safety](https://hypequery.com/docs/mcp/safety)
