How to Configure LangChain ClickHouse MCP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a langchain clickhouse mcp server, link your agent to the server tool. Next, assign a scoped database user with read rules for the server session. Many teams start by giving the agent a broad database login. That shortcut lets the model read every table and run heavy queries. When an agent holds wide rights, one bad prompt can pull private records. It can also overload your cluster with slow scans. How the langchain clickhouse mcp server workflow operates In a standard setup, the ag

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To set up a langchain clickhouse mcp server, link your agent to the server tool. Next, assign a scoped database user with read rules for the server session. Many teams start by giving the agent a broad database login. That shortcut lets the model read every table and run heavy queries. When an agent holds wide rights, one bad prompt can pull private records. It can also overload your cluster with slow scans.

How the langchain clickhouse mcp server workflow operates

In a standard setup, the agent pairs a chat model with one or more tools. The model reads the user prompt and picks which tool to call. When you attach the server, the agent converts natural language questions into database queries. It sends those queries through the server to your cluster and reads the results.

ClickHouse manages users, roles, row policies, settings profiles, and quotas as access entities. You create and change these entities with SQL statements. To turn on SQL access control, you set a storage directory on the server. You also need at least one admin user with access management rights turned on. A user can only grant the rights that they hold themselves.

Creating a new user takes the create user right. That statement sets the login method, allowed client hosts, default roles, and user settings. For an agent tool, admins often grant read rights on specific columns only. If a user only has rights on two columns, queries for other columns fail. A query that selects all columns also fails and returns no data at all. That query only works if the table holds just the allowed columns. Since version 24.10, a trailing asterisk grants rights by table name prefix.

What native setup solves and what keeps the session active

Native roles and column grants stop an agent from reading restricted tables. Host rules and quotas also cap where the tool logs in from. These database rules decide who can log in and which objects they can touch. They work well as a base layer for static apps.

Still, static database roles leave big gaps open during live agent runs. The database checks permissions at login and object check time, not per prompt intent. Once the server logs in with a shared user, every agent task shares those rights. If a column holds emails, phone numbers, card numbers, or national IDs, queries return them. Column grants are all or nothing for each column you allow.

ClickHouse Access Management + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You must either block a whole column or send raw values to the model. Native roles cannot rewrite matched fields in results while keeping the rest of the column. They also cannot pause a risky statement in flight for human approval. Also, the database log only shows the shared tool user, not the end user. Teams cannot tie a specific model prompt to a single query in the audit log.

Scoping database roles and query rules for agent tools

To lower risk with native tools, start with a dedicated database role for the agent. Never reuse an admin login or an app writer login for model queries. Grant select rights only on the exact tables and columns the agent needs. Avoid broad wildcard grants unless every matching table is safe for model reads.

Attach a settings profile and a quota to the agent user. These limits help stop a bad model loop from using all cluster memory. Set host rules so the user can only log in from your agent host. Even with these steps, teams still need controls that inspect each statement in flight. Masking that rewrites matched fields in results keeps emails and card numbers out of prompts. Per-statement checks and clear user logs close the gap between static roles and live agents.

Check ClickHouse queries and result columns on the wire

ClickHouse users and row policies decide who connects. They do not check each statement on the wire or redact sensitive string columns in query results. With hoop.dev, you run an open-source proxy, a sidecar for your ClickHouse. It reads ClickHouse's native TCP protocol before queries run while ClickHouse stays in charge of login and grants.

Multi-statement queries and table mutations are split and checked by hoop.dev guardrails. Banned actions are refused with a native ClickHouse error. On returned rows, hoop.dev data masking rewrites String and FixedString columns that match your rules. The audit trail logs each query, table, and verdict. See the MIT-licensed source on GitHub.

Frequently asked questions

Why does a select all query fail for a restricted ClickHouse user?

When you grant select on specific columns only, ClickHouse blocks full table star queries. The query returns no data unless the table contains only those exact granted columns.

How do you turn on SQL access control in ClickHouse?

You configure the access control path directory in the server settings first. You also enable access management for at least one initial admin user.

Why are static database roles not enough for LangChain agent tools?

Static roles check who logs in and which tables or columns they can read. They cannot rewrite sensitive fields in results or block single bad queries in flight.

The query runs. The emails stay hidden.