← All lessons

A Gateway Is Only One of Three Boundaries

One URL, and the problem behind it

Analysts want to ask their AI assistant questions about the warehouse. The obvious way to get there is for each of them to set up their own connection: install an MCP server for ClickHouse, paste in a database password, maybe add the dbt MCP server too.

That works for one person. For a team it produces two problems.

The first is credentials. Every laptop now holds a database password, and every agent session can read it. Offboarding means hunting down copies.

The second is quieter. Each assistant builds its own memory of what the marts mean: which table has one row per order, which join is the right one, what “active” means. Those memories drift apart. Two analysts ask the same question and get two different numbers, and neither is obviously wrong.

I’ve been designing a pilot to fix both, using uBixGate, my open-source MCP gateway, in front of the official ClickHouse and dbt MCP servers. The first thing I had to get straight was what the gateway can and can’t do. It turned out to be one of three boundaries, and each one belongs somewhere different.

 Claude Code ---+
 OpenCode ------+--> gateway (one URL)          boundary 1: who are you, which tools
 Cursor --------+         |
                +---------+----------+
                |                    |
         ClickHouse MCP          dbt MCP
                |
         ClickHouse                boundary 2: what may a query touch
         (read-only role)

 Shared context repo (AGENTS.md)   boundary 3: what does the data mean
 loaded by each client, never seen by the gateway

Boundary 1: the gateway decides who you are and which tools you may call

Each analyst adds one server, and nothing else:

claude mcp add --transport http analytics https://mcp.example.com/mcp

No database password, no dbt token. For every tool call the gateway checks the caller’s token from the identity provider, checks the call against a deny-by-default rule list, reads the upstream’s credential from Vault at that moment, forwards the call and writes one audit line with the person’s name. The agent never holds the credential.

The policy is where the groups come in. Analysts get the read tools; data engineering gets everything on dbt, including build:

policy:
  rules:
    - name: analysts-clickhouse-read
      effect: allow
      when: { groups: [analysts] }
      server: ch
      tools: [list_databases, list_tables, run_query]

    - name: analysts-dbt-read
      effect: allow
      when: { groups: [analysts] }
      server: dbt
      tools: [get_mart_models, get_all_models, get_node_details, get_lineage]

    - name: dataeng-dbt
      effect: allow
      when: { groups: [data-eng] }
      server: dbt
      tools: ["*"]
    # Anything else, for anyone else: denied by default.

The dbt MCP server’s own README warns that its CLI tools can change models and warehouse objects, so analysts don’t get run or build at all. That’s a decision a gateway is good at: which tools, for whom.

Boundary 2: the database decides what a query can touch

Here’s the part I had to be honest with myself about. run_query takes one argument: a SQL string. A gateway can allow that tool or deny it. It can’t usefully read the SQL, and it shouldn’t try. Parsing SQL to decide what’s safe is a losing game.

So the gateway’s job ends at “this person may run queries”. What the query can reach is the database’s job, and the database is very good at it:

CREATE ROLE IF NOT EXISTS mcp_reader;
GRANT SELECT ON marts_sales.* TO mcp_reader;
-- No grants on raw, staging or system databases.

CREATE SETTINGS PROFILE IF NOT EXISTS mcp_profile
  SETTINGS readonly = 1, max_execution_time = 30, max_result_rows = 100000
  TO mcp_reader;

Two details matter. The limits live in the database’s settings profile, not only in the MCP server’s config, so changing an MCP setting can’t lift them. And because the user can only see the marts, listing tables only shows the marts, which keeps raw data out of the model’s context as well as out of its queries.

The trade-off I chose for the pilot is a single shared read-only credential. The ClickHouse MCP server connects as one configured database user, so even a per-person token from the gateway identifies the person to the MCP server, not to ClickHouse. Real per-person database identity needs something that maps each caller to their own database user. Until then, the gateway’s audit log is the record of who ran what.

Boundary 3: a shared repo decides what the data means

The drift problem isn’t a security problem, so a gateway doesn’t touch it. Memory lives inside each AI client. The gateway never sees it.

The fix is boring, which is why it works: one repository of shared context. An AGENTS.md holds the mart list and grain, the join rules, the metric definitions and a set of known-good example queries. A CLAUDE.md just imports it, and a Cursor rules file points to it. Changes go in by pull request, reviewed by someone on the data team. Analysts turn off personal memory for this work.

Part of it shouldn’t be written by hand at all. Column meanings already live in the dbt docs, and the dbt MCP server serves them live. So the shared file can stay short and say “ask the dbt tools for lineage and column meaning before guessing”.

That’s what makes two analysts get the same answer to the same question: not the model, and not the gateway, but one reviewed source of truth they all load.

What none of the three solves yet

  • Prompt injection. Results come back unmodified. Text in a table, a column comment or a dbt description can steer the agent. Granting only the marts limits what it can reach, but doesn’t stop the steering.
  • Expensive queries. Anyone allowed to run queries can run any read query the grants allow. The profile limits and a per-person call limit at the gateway are the guard.
  • Data leaving the building. Query results go to the model provider. That’s a governance decision to make before the pilot, not after, and it’s a reason to keep personal data out of the granted databases.
  • The gateway itself. uBixGate is a public beta with no independent security review yet.

The pilot

Small on purpose: three to five analysts, one or two mart databases with nothing sensitive in them, two weeks. Before anyone connects, run the gateway’s own policy check for an analyst and a data engineer and confirm the answers. Review the audit log weekly: denials, slow queries, which tools people actually use, and which questions went wrong, because those are what the shared repo should learn from.

Success is three things: a new analyst working in under fifteen minutes, no database credential on any laptop, and two analysts given the same question getting the same answer.

The checklist

  1. Put identity and tool access in the gateway. Deny by default.
  2. Put data access in the database. Read-only role, grants on the marts only, limits in the profile.
  3. Put meaning in a reviewed repo, and let dbt supply what it already knows.
  4. Write down what’s still open, and pick a pilot small enough to survive it.
← All lessons