How to Configure CrewAI ClickHouse MCP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a crewai clickhouse mcp server, link your agent tool to a restricted database user. Then limit that user to specific tables and columns in ClickHouse. Teams often build multi-agent workflows that query analytics tables for fast answers. Many builders start by giving the agent a broad admin database account. That shortcut lets an agent read private columns or run heavy queries across every table. A safe setup pairs your tool link with strict database roles from day one. Setting up a c

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 crewai clickhouse mcp server, link your agent tool to a restricted database user. Then limit that user to specific tables and columns in ClickHouse. Teams often build multi-agent workflows that query analytics tables for fast answers. Many builders start by giving the agent a broad admin database account. That shortcut lets an agent read private columns or run heavy queries across every table. A safe setup pairs your tool link with strict database roles from day one.

Setting up a crewai clickhouse mcp server with native roles

A CrewAI agent reaches external data through tools that speak the Model Context Protocol. The MCP server sits between the agent runtime and your ClickHouse cluster. When an agent needs data, it sends a tool call to the MCP server. The server translates that call into a SQL query and runs it on ClickHouse. It then sends the rows back to the agent context window.

Your first defense lives inside ClickHouse access control. ClickHouse manages users, roles, row policies, settings profiles, and quotas as SQL entities. Before you create an agent role, turn on SQL-driven access control on the server. This setup needs a storage path and an admin user with management rights. Note that a user can only grant privileges that they hold themselves.

Next, create a dedicated database user for the MCP server. Set the login method, allowed client hosts, default roles, and user settings. Do not give this account broad read rights across the whole database. Instead, grant select rights only on the exact columns the agent needs. When you grant select on specific columns, ClickHouse blocks queries on other columns. It also refuses wildcard select queries unless the table holds only the granted columns. If your agent needs several tables with one prefix, grant select using a trailing asterisk.

Why static database roles leave an operational gap

Native ClickHouse roles and column grants solve a big part of the access puzzle. They decide which account can log in and which columns that account can touch. Quotas and settings profiles also help cap total resource use for that user. For static apps with fixed queries, native database controls often work well.

AI agents change this model because they write their own SQL in flight. Native roles check who logs in at the start of a session. They do not inspect what each generated statement tries to do before it runs. Even with column grants, an allowed column might hold emails, phone numbers, or card numbers. If an agent pulls those rows, raw personal data enters the model prompt. Static database grants cannot rewrite matched fields in results on the fly.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Hardening agent queries in production

Teams also face an audit gap when many agents share one MCP server login. In ClickHouse logs, every query comes from the same service user account. You cannot tell which agent task or human user triggered a slow scan. When a bad prompt causes a runaway join, teams must dig through app logs.

To close these gaps, treat agent database traffic as untrusted runtime input. Keep your ClickHouse user locked to read-only roles and strict column lists. Test your agent against views or sample tables before pointing it at live data. Combine tight database grants with controls that inspect queries and mask sensitive fields in results.

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

How should I scope ClickHouse permissions for a CrewAI agent?

Create a dedicated ClickHouse user and grant select rights only on needed columns. This stops the agent from running wildcard queries or reading restricted columns in the table.

What happens if an agent runs a wildcard query on a restricted table?

When a user only has column-level select grants, ClickHouse refuses wildcard select statements. The query returns no data unless the table contains only the granted columns.

Why are read-only database roles not enough for AI agents?

Read-only roles cannot hide emails, phone numbers, or national IDs inside allowed columns. They also share one login across tasks, which hides who ran each query.

The query runs. The emails stay hidden.