Open sourceApache 2.0

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.

  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.

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

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.

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.

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?

Get early access to hypequery cloud.

Cloud hosts the same model you run in your backend, with a managed API and MCP server, versions, and rollback. We're letting teams in a few at a time. Join the waitlist and we'll reach out when your project can go live.

How do you want to build your analytics layer? (Optional)
What features do you most need? (Optional)

Pick as many as you like.

Only your email is required. All other questions are optional.