[hypequery](https://hypequery.com/) › ClickHouse MCP Server for Python Backends | hypequery
Index for agents: https://hypequery.com/llms.txt
Canonical page: https://hypequery.com/clickhouse-python-mcp

> Give Claude, Cursor and other MCP clients your Python-defined ClickHouse datasets. Python keeps the SQL, auth and tenant; agents see only allowed endpoints.

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

Python MCP

# Give AI agents your Python ClickHouse datasets, not a SQL console

Define datasets in Python and run `hypequery mcp app:api`. Agents get exactly the endpoints the caller may call, so Claude and Cursor query governed measures while SQL, credentials, and the tenant stay in your Python process.

[Set up MCP for Python ](https://hypequery.com/docs/mcp/quickstart)[Read the safety model](https://hypequery.com/docs/mcp/safety)

Agent surface

Authorized endpoints only

SQL and credentials

Stay in Python

Works with

Claude, Cursor, MCP clients

## A SQL tool hands the model your database

Generic ClickHouse MCP servers let the agent pick tables, joins, and result sizes. A prompt is not a permission system.

## Agents invent their own revenue

When the agent writes its own query, its number disagrees with your dashboard. The agent has to use the same definition as your dashboard.

## Python teams were left out

Most semantic-layer MCP servers expect a Node or YAML project. Your analytics already live in a Python service.

Client contract

## Publish what agents may call

Install dataset endpoints with a client profile and add the client-contract route. The contract lists only the endpoints the calling principal may call, with each one’s fields, operators, and limits.

- Agents see only endpoints the API key’s principal is allowed to call
- The tenant comes from that principal on the Python side; the agent cannot choose it
- Fields, filters, and limits are validated by Python before any SQL runs
- Every tool call runs through `Api.handle`, so auth, endpoint policy and rate limits apply exactly as they do over HTTP

api.py

### Dataset endpoints plus live discovery

analytics/api.py

```
from hypequery.serve import (
    EndpointPolicy, add_client_contract_endpoint, add_dataset_endpoint,
    create_api,
)

policy = EndpointPolicy(
    tenant="required", required_scopes=frozenset({"analytics:read"})
)
api = create_api(auth=authenticate)

add_dataset_endpoint(
    api,
    "/v1/orders",
    dataset=orders,
    client=client,
    policy=policy,
    client_profile=profile,
)
# The authorized catalog hypequery mcp serves to agents
add_client_contract_endpoint(api, "/v1/client-contract", policy=policy)
```

The same endpoints your React app calls. No separate agent backend.

MCP server

## Run hypequery mcp on your API

The Python CLI serves your API's authorized client contract to agents, over stdio or, with --http, at a URL. No Node process and no separate agent backend.

`app:api` is the `Api` from `create_api`. Each tool call goes through it in the same process, so authentication, endpoint policy, rate limits and tenant resolution are the ones an HTTP caller meets.

API already deployed? `hypequery mcp --client-contract-url` bridges it over HTTPS instead, with the same tools. Agents get `list_datasets`, `get_dataset_schema`, and `query_dataset`, and never write or receive SQL.

terminal

### Serve it to an agent

terminal

```
pip install "hypequery[mcp]"

# The credential the server calls your API with: one principal, one tenant
export HYPEQUERY_API_KEY=…

# Check the setup without calling any query tool
hypequery mcp app:api --self-test

# Print the entry for Claude Desktop or Cursor
hypequery mcp app:api --print-config

# Or serve it at a URL for your team, behind a shared key.
# Keep the key: clients send it as "Authorization: Bearer <key>".
export HYPEQUERY_MCP_KEY=$(openssl rand -hex 32)
hypequery mcp app:api --http
```

Paste the printed entry into Claude Desktop or Cursor, or connect a client to the --http URL.

Where teams usually get stuck

## Questions teams ask

### ClickHouse MCP server for Python

Use your existing Python service as the MCP backend instead of exposing ClickHouse directly.

### Semantic layer for AI agents in Python

Agents query named measures and dimensions from your datasets, so their numbers match your product.

### Multi-tenant MCP

Over stdio the server acts as one principal and its tenant. Over HTTP with your app’s auth or OAuth, each caller’s tenant comes from their own credential.

### Native Python MCP server

Yes: `hypequery mcp app:api` runs in your Python process. Python keeps ownership of SQL, auth, and tenancy.

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 · 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 quick start](https://hypequery.com/docs/mcp/quickstart)

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

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

### [React and MCP clients](https://hypequery.com/docs/python/client-endpoints)

[Declare client endpoints and export the contract.](https://hypequery.com/docs/python/client-endpoints)

[Open guide](https://hypequery.com/docs/python/client-endpoints)

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

[Every way to run the MCP server, and when to use each.](https://hypequery.com/docs/mcp/overview)

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

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

[Exactly what agents can discover and run.](https://hypequery.com/docs/mcp/tools)

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

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

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

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

Related pillars

[ClickHouse semantic layer](https://hypequery.com/clickhouse-semantic-layer)[ClickHouse with Python](https://hypequery.com/clickhouse-python)[ClickHouse MCP](https://hypequery.com/clickhouse-mcp)[ClickHouse with FastAPI](https://hypequery.com/clickhouse-fastapi)[ClickHouse with Pydantic AI](https://hypequery.com/clickhouse-pydantic)[Python multi-tenancy](https://hypequery.com/clickhouse-python-multi-tenant)[Python semantic layer](https://hypequery.com/python-semantic-layer)[AI semantic layer](https://hypequery.com/semantic-layer/ai-agents)

Next step

## Connect one dataset to your first agent

Add a client contract route to your API, then run `hypequery mcp app:api --self-test`.

Open source, and it runs in your own backend. Want it hosted?

[Open the MCP quickstart ](https://hypequery.com/docs/mcp/quickstart)[Configure a client](https://hypequery.com/docs/mcp/clients)
