How to Configure OpenAI Agents SDK ClickHouse MCP Server
You set up an openai agents sdk clickhouse mcp server by linking an agent to a dedicated database user. First, you register the server tool in your agent app and supply database login keys. Most teams start by sharing one broad admin login for fast testing. When that role is too broad, the agent can read private tables or run heavy queries. How to set up an openai agents sdk clickhouse mcp server The setup connects two parts that talk over the Model Context Protocol. Your agent app runs the O
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.
You set up an openai agents sdk clickhouse mcp server by linking an agent to a dedicated database user. First, you register the server tool in your agent app and supply database login keys. Most teams start by sharing one broad admin login for fast testing. When that role is too broad, the agent can read private tables or run heavy queries.
How to set up an openai agents sdk clickhouse mcp server
The setup connects two parts that talk over the Model Context Protocol. Your agent app runs the OpenAI Agents SDK and decides when it needs data. The MCP server takes tool calls from the agent and turns them into SQL queries. Then the server sends those queries to your ClickHouse cluster and returns the rows.
To keep this setup safe, you must build a dedicated database user in ClickHouse. ClickHouse manages users, roles, row policies, settings profiles, and quotas as SQL access items. You need an admin account with access management rights turned on to create new users. A database user can only grant rights that they already hold themselves.
When you create the user for the MCP server, you set the login method. You also define which host addresses can log in with that user account. Next, you attach default roles and user settings to limit what the account can do. This stops the agent from logging in from unknown servers or using admin rights.
Scoping table and column rights in ClickHouse
After you create the user, you must restrict which tables and columns it can read. Giving an agent read rights on an entire database exposes sensitive customer fields. Instead, you can grant read rights on single columns within a specific table. When you grant select rights on two columns, the user can query only those two columns.
If the agent tries to query a third column, the database blocks the query. A wildcard query for all columns also fails and returns no data at all. That wildcard query only works if the table holds just the allowed columns. Since version 24.10, you can also grant select rights across tables that share a name prefix. This helps when your analytics tables follow a clear naming pattern.
You can also add row policies and quotas to the role for extra safety. Row policies filter which rows the agent user can read during a query. Quotas cap how much compute time or memory the user can spend in a window. These native controls stop a bad agent prompt from scanning your entire cluster at once.
ClickHouse Access Management + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native database roles solve and what they miss
Native database roles and column grants solve the first part of agent security. They decide who can log in and which tables or columns the account can touch. They also block the MCP server from dropping tables or changing records if you grant read-only rights. Every team running an agent against analytics data should set up these database rules first.
Still, native database settings leave an operational gap during live agent runs. The database checks permissions at login and checks table grants when a query starts. It does not know which human or agent task triggered a specific SQL statement. All queries from the MCP server arrive under the exact same shared service account.
Also, column grants are all or nothing for the columns you allow. If an agent needs a table with user emails or phone numbers, raw data comes back. The database does not rewrite matched fields like card numbers or national IDs in query results. You also cannot require a human to approve a risky query before it runs.
Add runtime guardrails and masking beside ClickHouse
Database grants and network rules control who can reach ClickHouse. Even so, an allowed client or agent can send an alter mutation that deletes rows or read raw personal data. In practice, hoop.dev runs beside the server as a sidecar for your ClickHouse and checks native TCP queries with no change to your drivers.
With hoop.dev ClickHouse support, guardrails refuse banned queries before they run, and data masking rewrites matched string columns in results. The audit trail logs which entity types were masked and how many without storing raw values. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
Why does a wildcard select fail for my restricted ClickHouse agent user?
When you grant read rights on specific columns only, ClickHouse blocks wildcard select queries. The agent must name the allowed columns directly in its SQL statement to get data.
How do I stop the MCP server from connecting from unknown machines?
When you create the ClickHouse user with SQL, set the allowed host rule on the account. This limits logins to the specific network addresses where your MCP server runs.
Can ClickHouse column grants hide sensitive text inside an allowed column?
No, native column grants only allow or block access to the entire column. To rewrite emails, phone numbers, or card numbers in results, you need dynamic data masking in flight.
Related guides
In this post